preflite 1.0.1
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.
- package/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/adapter-spi/artifact/index.js +1 -0
- package/dist/adapter-spi/command/index.js +1 -0
- package/dist/adapter-spi/install/index.js +1 -0
- package/dist/adapter-spi/lifecycle/index.js +1 -0
- package/dist/adapter-spi/resource/index.js +1 -0
- package/dist/adapter-spi/snapshot/index.js +1 -0
- package/dist/application/agent/AgentCommandPollLoop.js +48 -0
- package/dist/application/agent/AgentRuntimeService.js +27 -0
- package/dist/application/app-package/AppPackageApplicationService.js +97 -0
- package/dist/application/artifact/ArtifactApplicationService.js +13 -0
- package/dist/application/debug/DebugApplicationService.js +117 -0
- package/dist/application/health/HealthMetricsService.js +47 -0
- package/dist/application/lease/LeaseApplicationService.js +79 -0
- package/dist/application/query/ObservationQueryService.js +48 -0
- package/dist/application/reporter/ReporterApplicationService.js +41 -0
- package/dist/application/resource/ResourceOccupationReleaseService.js +49 -0
- package/dist/application/resource/ResourceRegistryService.js +113 -0
- package/dist/application/session/SessionApplicationService.js +39 -0
- package/dist/application/task/TaskApplicationService.js +378 -0
- package/dist/client/agentAppPackageClient.js +91 -0
- package/dist/domain/agent/AgentNode.js +12 -0
- package/dist/domain/agent/AgentRuntime.js +6 -0
- package/dist/domain/artifact/ArtifactPipeline.js +6 -0
- package/dist/domain/artifact/ArtifactRef.js +12 -0
- package/dist/domain/event/AgentEvent.js +10 -0
- package/dist/domain/event/Reporter.js +6 -0
- package/dist/domain/health/HealthMetrics.js +8 -0
- package/dist/domain/lease/Lease.js +28 -0
- package/dist/domain/lease/LeaseManager.js +6 -0
- package/dist/domain/repositories/index.js +1 -0
- package/dist/domain/resource/DeviceDetails.js +23 -0
- package/dist/domain/resource/DeviceResource.js +16 -0
- package/dist/domain/resource/ResourceRegistry.js +6 -0
- package/dist/domain/runtime/interfaces.js +1 -0
- package/dist/domain/session/BaseSession.js +16 -0
- package/dist/domain/session/DebugSession.js +3 -0
- package/dist/domain/session/ExecutionSession.js +3 -0
- package/dist/domain/session/SessionManager.js +8 -0
- package/dist/domain/task/TaskRecord.js +14 -0
- package/dist/domain/task/TaskSpec.js +12 -0
- package/dist/infrastructure/adapters/AdapterRegistry.js +10 -0
- package/dist/infrastructure/adapters/BridgeAdapters.js +6 -0
- package/dist/infrastructure/adapters/android/AndroidResourceAdapter.js +51 -0
- package/dist/infrastructure/adapters/deviceDetailsProbe.js +229 -0
- package/dist/infrastructure/adapters/harmony/HarmonyResourceAdapter.js +40 -0
- package/dist/infrastructure/adapters/ios/IOSResourceAdapter.js +182 -0
- package/dist/infrastructure/adapters/real/ShellCommandAndSnapshot.js +41 -0
- package/dist/infrastructure/airtest/AirtestRuntime.js +168 -0
- package/dist/infrastructure/app-package/AppPackageUrlCache.js +191 -0
- package/dist/infrastructure/app-package/appPackageDownloadDir.js +13 -0
- package/dist/infrastructure/bootstrap/BuildRuntimeContext.js +88 -0
- package/dist/infrastructure/cache/DirCapacityWatchdog.js +150 -0
- package/dist/infrastructure/config/agentConfigFile.js +96 -0
- package/dist/infrastructure/device/DeviceAppPackageOps.js +146 -0
- package/dist/infrastructure/ios/IOSWdaWatchdog.js +207 -0
- package/dist/infrastructure/live-debug/LiveDebugSessionManager.js +74 -0
- package/dist/infrastructure/live-debug/RuntimeLiveDebugAdapters.js +19 -0
- package/dist/infrastructure/midscene/DebugRuntimeImpl.js +533 -0
- package/dist/infrastructure/midscene/MidsceneRuntimeMock.js +22 -0
- package/dist/infrastructure/midscene/MidsceneRuntimeReal.js +552 -0
- package/dist/infrastructure/midscene/executionDumpWatcher.js +219 -0
- package/dist/infrastructure/midscene/videoRecorder.js +365 -0
- package/dist/infrastructure/midscene/zipReportDir.js +36 -0
- package/dist/infrastructure/persistence/InMemoryRepositories.js +94 -0
- package/dist/infrastructure/resilience/DeliveryIdDeduper.js +26 -0
- package/dist/infrastructure/system/CommandRunner.js +128 -0
- package/dist/infrastructure/transport/http/AgentEventHttpIngestClient.js +52 -0
- package/dist/infrastructure/transport/http/CallbackOutboxStore.js +106 -0
- package/dist/infrastructure/transport/http/PlatformCallbackClient.js +113 -0
- package/dist/infrastructure/transport/http/PlatformCommandPollClient.js +89 -0
- package/dist/infrastructure/transport/http/ResilientPlatformCallbackClient.js +117 -0
- package/dist/infrastructure/transport/midscenePaths.js +28 -0
- package/dist/infrastructure/transport/ws/ResilientWsOrHttpEventPublisher.js +29 -0
- package/dist/infrastructure/transport/ws/WsClient.js +182 -0
- package/dist/infrastructure/transport/ws/WsEventPublisher.js +36 -0
- package/dist/interfaces/http/HttpServer.js +227 -0
- package/dist/interfaces/websocket/AgentWsGateway.js +227 -0
- package/dist/main.js +368 -0
- package/dist/mcp/agentHttpClient.js +82 -0
- package/dist/mcp/agentRuntime.js +184 -0
- package/dist/mcp/cli.js +36 -0
- package/dist/mcp/doctor.js +124 -0
- package/dist/mcp/evidence.js +57 -0
- package/dist/mcp/exploration/index.js +129 -0
- package/dist/mcp/exploration/sessionManager.js +122 -0
- package/dist/mcp/exploration/tools-atomic.js +34 -0
- package/dist/mcp/exploration/tools-intelligent.js +33 -0
- package/dist/mcp/exploration/tools-session.js +276 -0
- package/dist/mcp/exploration/types.js +1 -0
- package/dist/mcp/flowStepEvents.js +114 -0
- package/dist/mcp/liveViewer.js +156 -0
- package/dist/mcp/reportReader.js +157 -0
- package/dist/mcp/runManager.js +161 -0
- package/dist/mcp/runSummary.js +72 -0
- package/dist/mcp/runtimeInstall.js +44 -0
- package/dist/mcp/server.js +260 -0
- package/dist/mcp/setup.js +185 -0
- package/dist/mcp/types.js +1 -0
- package/dist/mcp/userConfig.js +45 -0
- package/dist/mcp/visual-flow/codegen.js +576 -0
- package/dist/mcp/visual-flow/index.js +14 -0
- package/dist/mcp/visual-flow/types.js +5 -0
- package/dist/mcp/visual-flow/validate.js +617 -0
- package/dist/protocol-contracts/commands/envelope.js +24 -0
- package/dist/protocol-contracts/commands/index.js +1 -0
- package/dist/protocol-contracts/dto/index.js +1 -0
- package/dist/protocol-contracts/events/index.js +1 -0
- package/dist/protocol-contracts/queries/index.js +1 -0
- package/dist/shared-kernel/enums/index.js +70 -0
- package/dist/shared-kernel/errors/index.js +21 -0
- package/dist/shared-kernel/ids/index.js +18 -0
- package/dist/shared-kernel/time/index.js +3 -0
- package/dist/shared-kernel/value-objects/index.js +1 -0
- package/dist/utils/appPackageLocalPath.js +75 -0
- package/dist/utils/deviceResourceRouting.js +24 -0
- package/dist/utils/harmonyAgentDebugDevice.js +60 -0
- package/dist/utils/harmonyHdcDeviceId.js +134 -0
- package/dist/utils/iosAgentDebugDevice.js +72 -0
- package/dist/utils/iosMjpegCapture.js +90 -0
- package/dist/utils/liveDebugForegroundParse.js +71 -0
- package/dist/utils/midscene-device-session.js +353 -0
- package/dist/utils/midscene-task-cache-env.js +15 -0
- package/dist/utils/midsceneReportConstants.js +49 -0
- package/dist/utils/seedMidsceneTaskCache.js +61 -0
- package/dist/utils/task-runners/context/androidTaskRunnerContext.js +1 -0
- package/dist/utils/task-runners/context/harmonyTaskRunnerContext.js +1 -0
- package/dist/utils/task-runners/context/iosTaskRunnerContext.js +1 -0
- package/dist/utils/task-runners/runAndroidNativeAppTask.js +29 -0
- package/dist/utils/task-runners/runHarmonyNativeAppTask.js +36 -0
- package/dist/utils/task-runners/runIosNativeAppTask.js +30 -0
- package/dist/utils/task-runners/taskAppPackage.js +20 -0
- package/dist/utils/wrapper/resolveTaskRunnerImport.js +11 -0
- package/dist/utils/wrapper/wrapAndroidTaskScript.js +38 -0
- package/dist/utils/wrapper/wrapHarmonyTaskScript.js +42 -0
- package/dist/utils/wrapper/wrapIosTaskScript.js +30 -0
- package/package.json +46 -0
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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 zifengjiang
|
|
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 implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Preflight
|
|
2
|
+
|
|
3
|
+
> **Give your coding AI a real phone to test on.**
|
|
4
|
+
|
|
5
|
+
Preflight is an MCP (Model Context Protocol) server that connects AI coding assistants (Claude Code, Cursor, Codex) to real Android, iOS, and HarmonyOS devices for interactive testing — entirely on your local machine.
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="docs/demo.gif" alt="Preflight in action" width="720">
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
### Prerequisites
|
|
14
|
+
|
|
15
|
+
| Dependency | Required for | Notes |
|
|
16
|
+
|-----------|-------------|-------|
|
|
17
|
+
| **Node.js** ≥ 20.11 | All platforms | Install via [nvm](https://github.com/nvm-sh/nvm) or [nodejs.org](https://nodejs.org/) |
|
|
18
|
+
| **adb** | Android | Ship with Android SDK / [platform-tools](https://developer.android.com/studio/releases/platform-tools). Ensure `adb` is on your `PATH`, or set `ADB_BINARY_PATH` in config. |
|
|
19
|
+
| **Xcode** + **iproxy** | iOS | Xcode from [Mac App Store](https://apps.apple.com/app/xcode/id497799835). `iproxy` ships with `brew install libimobiledevice`. |
|
|
20
|
+
| **WebDriverAgent** | iOS | [Facebook WebDriverAgent](https://github.com/facebook/WebDriverAgent) — build and deploy to your device from Xcode. Set `WDA_PROJECT_ROOT` in config to point at your local copy. |
|
|
21
|
+
| **hdc** | HarmonyOS | Ships with [DevEco Studio](https://developer.huawei.com/consumer/cn/deveco-studio/). Ensure `hdc` is on your `PATH`. |
|
|
22
|
+
| **AI model API key** | All platforms | A [Midscene](https://midscenejs.com/)-compatible vision model. Supports OpenAI, Anthropic, Doubao, and more. |
|
|
23
|
+
|
|
24
|
+
### 1. Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx preflite setup
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This downloads the runtime, compiles all assets, and registers the `Preflight` MCP server in your editor's config (`.cursor/mcp.json` or `~/.codex/config.toml`).
|
|
31
|
+
|
|
32
|
+
> Alternatively, clone the repo and run `npm run mcp:setup` if you want to hack on Preflight itself.
|
|
33
|
+
|
|
34
|
+
### 2. Configure your AI model
|
|
35
|
+
|
|
36
|
+
Create `~/.preflight/config.json`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"env": {
|
|
41
|
+
"MIDSCENE_MODEL_BASE_URL": "https://ark.cn-beijing.volces.com/api/v3",
|
|
42
|
+
"MIDSCENE_MODEL_API_KEY": "sk-xxxxxxxxxxxxxxxx",
|
|
43
|
+
"MIDSCENE_MODEL_NAME": "doubao-seed-2-0-lite-260215",
|
|
44
|
+
"MIDSCENE_MODEL_FAMILY": "doubao-seed"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Supported providers** — any of these works:
|
|
50
|
+
|
|
51
|
+
| Provider | `MIDSCENE_MODEL_BASE_URL` | `MIDSCENE_MODEL_NAME` |
|
|
52
|
+
|----------|--------------------------|-----------------------|
|
|
53
|
+
| OpenAI | `https://api.openai.com/v1` | `gpt-4o` |
|
|
54
|
+
| Anthropic | `https://api.anthropic.com/v1` | `claude-sonnet-4-20250514` |
|
|
55
|
+
| Doubao (Volcengine) | `https://ark.cn-beijing.volces.com/api/v3` | `doubao-seed-2-0-lite-260215` |
|
|
56
|
+
|
|
57
|
+
You can also set standard env vars (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc.) — Preflight picks them up automatically.
|
|
58
|
+
|
|
59
|
+
### (Optional) iOS WebDriverAgent
|
|
60
|
+
|
|
61
|
+
iOS testing requires [WebDriverAgent](https://github.com/facebook/WebDriverAgent) running on your device:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/facebook/WebDriverAgent.git
|
|
65
|
+
cd WebDriverAgent
|
|
66
|
+
./Scripts/bootstrap.sh
|
|
67
|
+
open WebDriverAgent.xcodeproj
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Build the `WebDriverAgentRunner` scheme targeting your device. Then add to `~/.preflight/config.json`:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"env": {
|
|
75
|
+
"WDA_PROJECT_ROOT": "/path/to/WebDriverAgent",
|
|
76
|
+
"WDA_SCHEME": "WebDriverAgentRunner"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 4. Restart and test
|
|
82
|
+
|
|
83
|
+
Restart your AI coding assistant. Now you can say things like:
|
|
84
|
+
|
|
85
|
+
> *"Check my devices, explore the Notes app, and write a test for creating a new note."*
|
|
86
|
+
|
|
87
|
+
The AI calls `list_devices` → `exploration_start` → explores your app naturally → generates and runs a visual-flow test on the real device.
|
|
88
|
+
|
|
89
|
+
## How It Uses Midscene
|
|
90
|
+
|
|
91
|
+
[**Midscene**](https://midscenejs.com/) is the visual AI engine that powers Preflight's ability to see and act on mobile screens. It works by feeding screenshots and structured instructions to a multimodal LLM, then parsing the model's response into concrete UI actions.
|
|
92
|
+
|
|
93
|
+
Preflight wraps Midscene in three layers:
|
|
94
|
+
|
|
95
|
+
```mermaid
|
|
96
|
+
flowchart LR
|
|
97
|
+
subgraph AI["Your AI Assistant<br/>(Claude Code / Cursor)"]
|
|
98
|
+
MCP["MCP Protocol\nstdio"]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
subgraph Preflight["Preflight MCP Server"]
|
|
102
|
+
EXP["Exploration Layer\napp exploration &\nscreen understanding"]
|
|
103
|
+
IR["Visual Flow IR\nstructured test\nstep definitions"]
|
|
104
|
+
AGENT["automation-agent\ndevice lifecycle &\ntask orchestration"]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
subgraph Midscene["Midscene SDK"]
|
|
108
|
+
MS["Midscene Agent\nscreenshot → LLM →\nUI actions"]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
subgraph Device["Mobile Device"]
|
|
112
|
+
SCREEN["Screen & UI\nElement Tree"]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
AI <-->|stdio| MCP
|
|
116
|
+
MCP --> EXP
|
|
117
|
+
MCP --> IR
|
|
118
|
+
EXP --> AGENT
|
|
119
|
+
IR --> AGENT
|
|
120
|
+
AGENT --> MS
|
|
121
|
+
MS <-->|adb / WDA / hdc| Device
|
|
122
|
+
SCREEN -.->|screenshots| MS
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**How the layers work together:**
|
|
126
|
+
|
|
127
|
+
1. **Exploration Layer** — Your AI assistant uses natural-language tools (`exploration_get_page_summary`, `exploration_ai_act`) to understand the app, navigate screens, and decide what to test.
|
|
128
|
+
2. **Visual Flow IR** — Once the flow is understood, it's captured as a structured JSON — a sequence of steps with assertions, free of fragile selectors or coordinates.
|
|
129
|
+
3. **Midscene SDK** — Each step is compiled into a Midscene plan: the SDK takes a screenshot, sends it with instructions to the vision model, and performs the returned action (tap, type, swipe, assert) on the device via adb/WDA/hdc.
|
|
130
|
+
|
|
131
|
+
This design means tests survive UI reshuffles (Midscene targets *what* to interact with, not *where*), and the AI never needs to write fragile XPath or accessibility-id selectors.
|
|
132
|
+
|
|
133
|
+
## Tools Overview
|
|
134
|
+
|
|
135
|
+
| Category | Tools |
|
|
136
|
+
|----------|-------|
|
|
137
|
+
| **Agent** | `agent_health` · `start_agent` · `stop_agent` · `doctor` · `config_status` |
|
|
138
|
+
| **Device** | `list_devices` · `install_app` |
|
|
139
|
+
| **Exploration** | `exploration_start` · `exploration_end` · `exploration_get_page_summary` · `exploration_ai_act` · `exploration_ask_about_screen` · `exploration_screenshot` · `exploration_type` · `exploration_wait` |
|
|
140
|
+
| **Visual-Flow** | `get_visual_flow_ir_rules` · `validate_visual_flow` · `run_flow` · `watch_run` · `cancel_run` · `save_report` · `read_report` |
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
[Apache 2.0](./LICENSE)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** WS 未连接时拉取平台待下发命令并 ACK */
|
|
2
|
+
export class AgentCommandPollLoop {
|
|
3
|
+
pollClient;
|
|
4
|
+
gateway;
|
|
5
|
+
wsClient;
|
|
6
|
+
health;
|
|
7
|
+
intervalMs;
|
|
8
|
+
timer = null;
|
|
9
|
+
constructor(pollClient, gateway, wsClient, health, intervalMs) {
|
|
10
|
+
this.pollClient = pollClient;
|
|
11
|
+
this.gateway = gateway;
|
|
12
|
+
this.wsClient = wsClient;
|
|
13
|
+
this.health = health;
|
|
14
|
+
this.intervalMs = intervalMs;
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
if (!this.pollClient.isEnabled())
|
|
18
|
+
return;
|
|
19
|
+
if (this.timer)
|
|
20
|
+
return;
|
|
21
|
+
this.timer = setInterval(() => void this.tick().catch(() => { }), this.intervalMs);
|
|
22
|
+
}
|
|
23
|
+
stop() {
|
|
24
|
+
if (this.timer) {
|
|
25
|
+
clearInterval(this.timer);
|
|
26
|
+
this.timer = null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async tick() {
|
|
30
|
+
if (!this.pollClient.isEnabled())
|
|
31
|
+
return;
|
|
32
|
+
if (this.wsClient.isOpen())
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
const items = await this.pollClient.fetchPending(20);
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
const result = await this.gateway.handlePollDelivery(item);
|
|
38
|
+
if (result.ok || result.duplicate) {
|
|
39
|
+
await this.pollClient.ack([item.deliveryId]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this.health.markPollOk();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
this.health.markPollError();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentNode } from "../../domain/agent/AgentNode.js";
|
|
2
|
+
import { EventType, PlatformType } from "../../shared-kernel/enums/index.js";
|
|
3
|
+
import { asAgentId } from "../../shared-kernel/ids/index.js";
|
|
4
|
+
import { nowIso } from "../../shared-kernel/time/index.js";
|
|
5
|
+
export class AgentRuntimeService {
|
|
6
|
+
agentRepository;
|
|
7
|
+
reporter;
|
|
8
|
+
constructor(agentRepository, reporter) {
|
|
9
|
+
this.agentRepository = agentRepository;
|
|
10
|
+
this.reporter = reporter;
|
|
11
|
+
}
|
|
12
|
+
async register(agentId) {
|
|
13
|
+
const node = new AgentNode(asAgentId(agentId), { supportedPlatforms: [PlatformType.HARMONY], maxConcurrentTasks: 1 }, true, nowIso());
|
|
14
|
+
await this.agentRepository.save(node);
|
|
15
|
+
await this.reporter.emit(EventType.AGENT_REGISTERED, { agentId: node.id });
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
async heartbeat() {
|
|
19
|
+
const agent = await this.agentRepository.get();
|
|
20
|
+
if (!agent)
|
|
21
|
+
return;
|
|
22
|
+
agent.lastHeartbeatAt = nowIso();
|
|
23
|
+
agent.online = true;
|
|
24
|
+
await this.agentRepository.save(agent);
|
|
25
|
+
await this.reporter.emit(EventType.HEARTBEAT, { agentId: agent.id, healthy: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { LeaseRequiredError } from "../../shared-kernel/errors/index.js";
|
|
2
|
+
import { OwnerType, PlatformType, ResourceStatus } from "../../shared-kernel/enums/index.js";
|
|
3
|
+
import { asResourceId } from "../../shared-kernel/ids/index.js";
|
|
4
|
+
import { parseDeviceTargetFromResourceId } from "../../utils/deviceResourceRouting.js";
|
|
5
|
+
import { AppPackageUrlCache } from "../../infrastructure/app-package/AppPackageUrlCache.js";
|
|
6
|
+
import { resolveAppRefToLocalFile } from "../../utils/appPackageLocalPath.js";
|
|
7
|
+
const DEFAULT_INSTALL_TIMEOUT_MS = 600_000;
|
|
8
|
+
const DEFAULT_UNINSTALL_TIMEOUT_MS = 120_000;
|
|
9
|
+
const DEFAULT_AUTO_LEASE_TTL_SECONDS = 300;
|
|
10
|
+
/**
|
|
11
|
+
* 三端安装/卸载:Android `adb`、iOS `ideviceinstaller`、鸿蒙 `hdc`。
|
|
12
|
+
* 需资源在线;无活跃租约时可按配置自动 acquire。
|
|
13
|
+
*/
|
|
14
|
+
export class AppPackageApplicationService {
|
|
15
|
+
leaseService;
|
|
16
|
+
resourceRepository;
|
|
17
|
+
ops;
|
|
18
|
+
options;
|
|
19
|
+
constructor(leaseService, resourceRepository, ops, options = {}) {
|
|
20
|
+
this.leaseService = leaseService;
|
|
21
|
+
this.resourceRepository = resourceRepository;
|
|
22
|
+
this.ops = ops;
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
installTimeout() {
|
|
26
|
+
const n = this.options.installTimeoutMs ?? DEFAULT_INSTALL_TIMEOUT_MS;
|
|
27
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : DEFAULT_INSTALL_TIMEOUT_MS;
|
|
28
|
+
}
|
|
29
|
+
uninstallTimeout() {
|
|
30
|
+
const n = this.options.uninstallTimeoutMs ?? DEFAULT_UNINSTALL_TIMEOUT_MS;
|
|
31
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : DEFAULT_UNINSTALL_TIMEOUT_MS;
|
|
32
|
+
}
|
|
33
|
+
autoLeaseTtl() {
|
|
34
|
+
const n = this.options.autoLeaseTtlSeconds ?? DEFAULT_AUTO_LEASE_TTL_SECONDS;
|
|
35
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : DEFAULT_AUTO_LEASE_TTL_SECONDS;
|
|
36
|
+
}
|
|
37
|
+
async ensureLease(resourceId) {
|
|
38
|
+
try {
|
|
39
|
+
await this.leaseService.ensureActive(resourceId);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (!(error instanceof LeaseRequiredError))
|
|
43
|
+
throw error;
|
|
44
|
+
const leaseId = `lease-app-install-${Date.now()}`;
|
|
45
|
+
await this.leaseService.acquire(leaseId, String(resourceId), `app-package-${Date.now()}`, OwnerType.PLATFORM_TASK, this.autoLeaseTtl());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async install(resourceId, appRef) {
|
|
49
|
+
const rid = asResourceId(resourceId);
|
|
50
|
+
await this.ensureLease(rid);
|
|
51
|
+
const parsed = parseDeviceTargetFromResourceId(resourceId);
|
|
52
|
+
if (!parsed) {
|
|
53
|
+
throw new Error(`invalid resourceId (expect android:|ios:|harmony: prefix): ${resourceId}`);
|
|
54
|
+
}
|
|
55
|
+
const device = await this.resourceRepository.getById(rid);
|
|
56
|
+
if (!device || device.status !== ResourceStatus.ONLINE) {
|
|
57
|
+
throw new Error(`resource not online: ${resourceId}`);
|
|
58
|
+
}
|
|
59
|
+
if (device.platform !== parsed.platform) {
|
|
60
|
+
throw new Error(`resource platform mismatch for ${resourceId}`);
|
|
61
|
+
}
|
|
62
|
+
const resolved = this.options.urlCache && AppPackageUrlCache.isHttpRef(appRef)
|
|
63
|
+
? await this.options.urlCache.resolveHttpToLocalPackage(appRef, device.platform)
|
|
64
|
+
: await resolveAppRefToLocalFile(appRef, device.platform, this.options.downloadDir);
|
|
65
|
+
try {
|
|
66
|
+
const paths = parsed.platform === PlatformType.ANDROID ? { serial: parsed.serial }
|
|
67
|
+
: parsed.platform === PlatformType.IOS ? { udid: parsed.udid }
|
|
68
|
+
: { deviceId: parsed.deviceId };
|
|
69
|
+
await this.ops.install(parsed.platform, paths, resolved.localPath, this.installTimeout());
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await resolved.cleanupTemp();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async uninstall(resourceId, bundleId) {
|
|
76
|
+
const rid = asResourceId(resourceId);
|
|
77
|
+
const id = bundleId.trim();
|
|
78
|
+
if (!id)
|
|
79
|
+
throw new Error("bundleId is empty");
|
|
80
|
+
await this.ensureLease(rid);
|
|
81
|
+
const parsed = parseDeviceTargetFromResourceId(resourceId);
|
|
82
|
+
if (!parsed) {
|
|
83
|
+
throw new Error(`invalid resourceId (expect android:|ios:|harmony: prefix): ${resourceId}`);
|
|
84
|
+
}
|
|
85
|
+
const device = await this.resourceRepository.getById(rid);
|
|
86
|
+
if (!device || device.status !== ResourceStatus.ONLINE) {
|
|
87
|
+
throw new Error(`resource not online: ${resourceId}`);
|
|
88
|
+
}
|
|
89
|
+
if (device.platform !== parsed.platform) {
|
|
90
|
+
throw new Error(`resource platform mismatch for ${resourceId}`);
|
|
91
|
+
}
|
|
92
|
+
const paths = parsed.platform === PlatformType.ANDROID ? { serial: parsed.serial }
|
|
93
|
+
: parsed.platform === PlatformType.IOS ? { udid: parsed.udid }
|
|
94
|
+
: { deviceId: parsed.deviceId };
|
|
95
|
+
await this.ops.uninstall(parsed.platform, paths, id, this.uninstallTimeout());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ArtifactRef } from "../../domain/artifact/ArtifactRef.js";
|
|
2
|
+
import { asArtifactId, asTaskId } from "../../shared-kernel/ids/index.js";
|
|
3
|
+
export class ArtifactApplicationService {
|
|
4
|
+
artifactRepository;
|
|
5
|
+
constructor(artifactRepository) {
|
|
6
|
+
this.artifactRepository = artifactRepository;
|
|
7
|
+
}
|
|
8
|
+
async saveTaskArtifacts(taskId, artifacts) {
|
|
9
|
+
const refs = artifacts.map((item, index) => new ArtifactRef(asArtifactId(`${taskId}-${index + 1}`), asTaskId(taskId), item.type, item.uri));
|
|
10
|
+
await this.artifactRepository.saveMany(refs);
|
|
11
|
+
return refs;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ArtifactType, EventType, OwnerType, SessionStatus } from "../../shared-kernel/enums/index.js";
|
|
2
|
+
import { asResourceId, asSessionId } from "../../shared-kernel/ids/index.js";
|
|
3
|
+
import { LiveDebugSessionManager } from "../../infrastructure/live-debug/LiveDebugSessionManager.js";
|
|
4
|
+
import { RuntimeLiveDebugFrameSource, RuntimeLiveDebugInputInjector, } from "../../infrastructure/live-debug/RuntimeLiveDebugAdapters.js";
|
|
5
|
+
export class DebugApplicationService {
|
|
6
|
+
leaseService;
|
|
7
|
+
sessionService;
|
|
8
|
+
debugRuntime;
|
|
9
|
+
reporter;
|
|
10
|
+
liveSessionManager;
|
|
11
|
+
constructor(leaseService, sessionService, debugRuntime, reporter) {
|
|
12
|
+
this.leaseService = leaseService;
|
|
13
|
+
this.sessionService = sessionService;
|
|
14
|
+
this.debugRuntime = debugRuntime;
|
|
15
|
+
this.reporter = reporter;
|
|
16
|
+
this.liveSessionManager = new LiveDebugSessionManager(new RuntimeLiveDebugFrameSource(this.debugRuntime), new RuntimeLiveDebugInputInjector(this.debugRuntime));
|
|
17
|
+
}
|
|
18
|
+
async createDebugSession(params) {
|
|
19
|
+
await this.leaseService.ensureActive(asResourceId(params.resourceId));
|
|
20
|
+
const session = await this.sessionService.createDebug(params.sessionId, params.resourceId, params.leaseId, params.ownerId, OwnerType.DEBUG_CLIENT);
|
|
21
|
+
await this.reporter.emit(EventType.SESSION_CHANGED, { sessionId: session.id, status: session.status });
|
|
22
|
+
}
|
|
23
|
+
async sendCommand(sessionId, command) {
|
|
24
|
+
const session = await this.sessionService.getDebug(asSessionId(sessionId));
|
|
25
|
+
if (!session) {
|
|
26
|
+
throw new Error(`debug session not found: ${sessionId}`);
|
|
27
|
+
}
|
|
28
|
+
await this.leaseService.ensureActive(session.resourceId);
|
|
29
|
+
const result = await this.debugRuntime.runCommand(session.resourceId, command);
|
|
30
|
+
await this.reporter.emit(EventType.SESSION_CHANGED, { sessionId, status: SessionStatus.RUNNING });
|
|
31
|
+
return result.output;
|
|
32
|
+
}
|
|
33
|
+
async snapshot(sessionId) {
|
|
34
|
+
const session = await this.sessionService.getDebug(asSessionId(sessionId));
|
|
35
|
+
if (!session) {
|
|
36
|
+
throw new Error(`debug session not found: ${sessionId}`);
|
|
37
|
+
}
|
|
38
|
+
await this.leaseService.ensureActive(session.resourceId);
|
|
39
|
+
const shot = await this.debugRuntime.snapshot(session.resourceId);
|
|
40
|
+
await this.reporter.emit(EventType.ARTIFACT_READY, {
|
|
41
|
+
taskId: `debug-${sessionId}`,
|
|
42
|
+
artifactId: `snapshot-${sessionId}`,
|
|
43
|
+
artifactType: ArtifactType.SCREENSHOT,
|
|
44
|
+
uri: shot.uri,
|
|
45
|
+
});
|
|
46
|
+
return shot.uri;
|
|
47
|
+
}
|
|
48
|
+
async close(sessionId) {
|
|
49
|
+
await this.liveSessionManager.stop(String(sessionId));
|
|
50
|
+
const closed = await this.sessionService.closeDebug(asSessionId(sessionId));
|
|
51
|
+
if (!closed)
|
|
52
|
+
return;
|
|
53
|
+
await this.reporter.emit(EventType.SESSION_CHANGED, { sessionId: closed.id, status: closed.status });
|
|
54
|
+
}
|
|
55
|
+
async startLiveSession(params) {
|
|
56
|
+
const session = await this.sessionService.getDebug(asSessionId(params.sessionId));
|
|
57
|
+
if (!session) {
|
|
58
|
+
throw new Error(`debug session not found: ${params.sessionId}`);
|
|
59
|
+
}
|
|
60
|
+
const resourceId = params.resourceId ? asResourceId(params.resourceId) : session.resourceId;
|
|
61
|
+
await this.leaseService.ensureActive(resourceId);
|
|
62
|
+
await this.liveSessionManager.start({
|
|
63
|
+
sessionId: params.sessionId,
|
|
64
|
+
resourceId,
|
|
65
|
+
frameIntervalMs: params.frameIntervalMs,
|
|
66
|
+
onState: async (status, message) => {
|
|
67
|
+
await this.reporter.emit(EventType.LIVE_DEBUG_SESSION_CHANGED, {
|
|
68
|
+
sessionId: params.sessionId,
|
|
69
|
+
resourceId,
|
|
70
|
+
status,
|
|
71
|
+
...(message ? { message } : {}),
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
onFrame: async (frame) => {
|
|
75
|
+
await this.reporter.emitLiveDebugFrame({
|
|
76
|
+
sessionId: params.sessionId,
|
|
77
|
+
resourceId,
|
|
78
|
+
mimeType: frame.mimeType,
|
|
79
|
+
dataBase64: frame.dataBase64,
|
|
80
|
+
sourceUri: frame.sourceUri,
|
|
81
|
+
capturedAt: new Date().toISOString(),
|
|
82
|
+
...(frame.foregroundApp ? { foregroundApp: frame.foregroundApp } : {}),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async stopLiveSession(sessionId) {
|
|
88
|
+
await this.liveSessionManager.stop(sessionId);
|
|
89
|
+
}
|
|
90
|
+
async sendLiveInput(sessionId, input) {
|
|
91
|
+
const session = await this.sessionService.getDebug(asSessionId(sessionId));
|
|
92
|
+
if (!session) {
|
|
93
|
+
throw new Error(`debug session not found: ${sessionId}`);
|
|
94
|
+
}
|
|
95
|
+
await this.leaseService.ensureActive(session.resourceId);
|
|
96
|
+
try {
|
|
97
|
+
const result = await this.liveSessionManager.sendInput(sessionId, input);
|
|
98
|
+
await this.reporter.emit(EventType.LIVE_DEBUG_INPUT_ACK, {
|
|
99
|
+
sessionId,
|
|
100
|
+
resourceId: result.resourceId,
|
|
101
|
+
ok: true,
|
|
102
|
+
action: input.action,
|
|
103
|
+
message: result.output,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
await this.reporter.emit(EventType.LIVE_DEBUG_INPUT_ACK, {
|
|
108
|
+
sessionId,
|
|
109
|
+
resourceId: session.resourceId,
|
|
110
|
+
ok: false,
|
|
111
|
+
action: input.action,
|
|
112
|
+
message: error instanceof Error ? error.message : String(error),
|
|
113
|
+
});
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|