nova-personal-agent-server 0.0.0-stage → 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.
- package/LICENSE +201 -0
- package/README.md +30 -2
- package/bin/novapersonal-server.mjs +4 -0
- package/package.json +61 -4
- package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
- package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
- package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
- package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
- package/resources/native/codex-sandbox-probe +0 -0
- package/resources/native/project-native/nova_project_native.node +0 -0
- package/resources/native-resources-v1.json +1 -0
- package/runtime/dist/eval/demos.js +156 -0
- package/runtime/dist/eval/fixture-host.js +385 -0
- package/runtime/dist/eval/fixtures.js +319 -0
- package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
- package/runtime/dist/eval/scorecard.js +285 -0
- package/runtime/dist/eval/sim.js +43 -0
- package/runtime/dist/src/cascaded-text-provider.js +31 -0
- package/runtime/dist/src/cli.js +96 -0
- package/runtime/dist/src/composition/assembly.js +352 -0
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
- package/runtime/dist/src/composition/production-composition.js +389 -0
- package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
- package/runtime/dist/src/config/capability-registry.js +315 -0
- package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
- package/runtime/dist/src/config/coding-backends.js +8 -0
- package/runtime/dist/src/config/coding-profiles.js +98 -0
- package/runtime/dist/src/config/config.js +857 -0
- package/runtime/dist/src/config/diagnostics.js +139 -0
- package/runtime/dist/src/config/environment-contract.js +202 -0
- package/runtime/dist/src/config/self-hosted.js +23 -0
- package/runtime/dist/src/connectors/composio/client.js +195 -0
- package/runtime/dist/src/connectors/composio/google.js +208 -0
- package/runtime/dist/src/connectors/composio/index.js +334 -0
- package/runtime/dist/src/connectors/feishu/cli.js +220 -0
- package/runtime/dist/src/connectors/feishu/index.js +980 -0
- package/runtime/dist/src/connectors/macos/calendar.js +35 -0
- package/runtime/dist/src/connectors/macos/mail.js +32 -0
- package/runtime/dist/src/connectors/macos/reader.js +62 -0
- package/runtime/dist/src/conversation-voice-provider.js +41 -0
- package/runtime/dist/src/core/approval-port.js +9 -0
- package/runtime/dist/src/core/approval.js +1328 -0
- package/runtime/dist/src/core/calls.js +35 -0
- package/runtime/dist/src/core/camera-session.js +32 -0
- package/runtime/dist/src/core/causal-runtime.js +650 -0
- package/runtime/dist/src/core/clock.js +139 -0
- package/runtime/dist/src/core/context-view.js +156 -0
- package/runtime/dist/src/core/effects.js +62 -0
- package/runtime/dist/src/core/events.js +217 -0
- package/runtime/dist/src/core/executor-diagnostic.js +9 -0
- package/runtime/dist/src/core/ids.js +32 -0
- package/runtime/dist/src/core/media-store.js +104 -0
- package/runtime/dist/src/core/memory.js +296 -0
- package/runtime/dist/src/core/pending-decision.js +64 -0
- package/runtime/dist/src/core/ports.js +125 -0
- package/runtime/dist/src/core/runtime.js +1459 -0
- package/runtime/dist/src/core/schedule-tools.js +15 -0
- package/runtime/dist/src/core/sims.js +186 -0
- package/runtime/dist/src/core/slots.js +97 -0
- package/runtime/dist/src/core/source-processing-instructions.js +3 -0
- package/runtime/dist/src/core/source-processing-tools.js +12 -0
- package/runtime/dist/src/core/suggestions.js +143 -0
- package/runtime/dist/src/core/task-tools.js +22 -0
- package/runtime/dist/src/core/tool-schema.js +212 -0
- package/runtime/dist/src/core/trace.js +34 -0
- package/runtime/dist/src/core/work-tools.js +94 -0
- package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
- package/runtime/dist/src/desktop/desktop-camera.js +281 -0
- package/runtime/dist/src/desktop/desktop-control.js +140 -0
- package/runtime/dist/src/desktop/desktop-progress.js +162 -0
- package/runtime/dist/src/desktop/desktop-session.js +2106 -0
- package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
- package/runtime/dist/src/desktop/desktop-wire.js +605 -0
- package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
- package/runtime/dist/src/desktop/startup-error.js +18 -0
- package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
- package/runtime/dist/src/desktop-entry.js +106 -0
- package/runtime/dist/src/desktop.js +1092 -0
- package/runtime/dist/src/executors/acp/backends.js +105 -0
- package/runtime/dist/src/executors/acp/mcp.js +81 -0
- package/runtime/dist/src/executors/acp/preflight.js +14 -0
- package/runtime/dist/src/executors/acp/process-owner.js +112 -0
- package/runtime/dist/src/executors/acp/transport.js +760 -0
- package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
- package/runtime/dist/src/executors/agent-controller.js +244 -0
- package/runtime/dist/src/executors/autoglm.js +376 -0
- package/runtime/dist/src/executors/browser-device.js +102 -0
- package/runtime/dist/src/executors/browser.js +61 -0
- package/runtime/dist/src/executors/camera.js +101 -0
- package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
- package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
- package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
- package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
- package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
- package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
- package/runtime/dist/src/executors/codex/common.js +655 -0
- package/runtime/dist/src/executors/codex/contract.js +581 -0
- package/runtime/dist/src/executors/codex/controller.js +141 -0
- package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
- package/runtime/dist/src/executors/codex/factory.js +463 -0
- package/runtime/dist/src/executors/codex/host-config.js +238 -0
- package/runtime/dist/src/executors/codex/host.js +17 -0
- package/runtime/dist/src/executors/codex/index.js +19 -0
- package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
- package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
- package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
- package/runtime/dist/src/executors/codex/process-owner.js +398 -0
- package/runtime/dist/src/executors/codex/production-host.js +887 -0
- package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
- package/runtime/dist/src/executors/codex/protocol.js +581 -0
- package/runtime/dist/src/executors/codex/safe-json.js +87 -0
- package/runtime/dist/src/executors/codex/session-title.js +61 -0
- package/runtime/dist/src/executors/codex/shared-home.js +29 -0
- package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
- package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
- package/runtime/dist/src/executors/codex/version.js +38 -0
- package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
- package/runtime/dist/src/executors/coding/intake-model.js +103 -0
- package/runtime/dist/src/executors/coding/intake.js +824 -0
- package/runtime/dist/src/executors/coding/json-completion.js +14 -0
- package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
- package/runtime/dist/src/executors/coding/work-order.js +50 -0
- package/runtime/dist/src/executors/coding-executor.js +23 -0
- package/runtime/dist/src/executors/computer-backend.js +188 -0
- package/runtime/dist/src/executors/computer-device.js +187 -0
- package/runtime/dist/src/executors/computer-worker.js +125 -0
- package/runtime/dist/src/executors/computer.js +100 -0
- package/runtime/dist/src/executors/device-lock.js +127 -0
- package/runtime/dist/src/executors/frame-source.js +29 -0
- package/runtime/dist/src/executors/gui-evidence.js +30 -0
- package/runtime/dist/src/executors/gui-execution.js +237 -0
- package/runtime/dist/src/executors/gui-runner.js +88 -0
- package/runtime/dist/src/executors/host-executor-capability.js +12 -0
- package/runtime/dist/src/executors/index.js +13 -0
- package/runtime/dist/src/executors/mcp-client.js +198 -0
- package/runtime/dist/src/executors/mcp.js +210 -0
- package/runtime/dist/src/executors/mobile-android.js +180 -0
- package/runtime/dist/src/executors/mobile-ios.js +303 -0
- package/runtime/dist/src/executors/mobile.js +78 -0
- package/runtime/dist/src/executors/search-mcp.js +146 -0
- package/runtime/dist/src/executors/search.js +524 -0
- package/runtime/dist/src/executors/task-resources.js +38 -0
- package/runtime/dist/src/executors/vision/assess.js +296 -0
- package/runtime/dist/src/executors/vision/controller-core.js +373 -0
- package/runtime/dist/src/executors/vision/controller.js +164 -0
- package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
- package/runtime/dist/src/executors/vision.js +5 -0
- package/runtime/dist/src/executors/watcher.js +718 -0
- package/runtime/dist/src/http/bounded-response.js +37 -0
- package/runtime/dist/src/index.js +56 -0
- package/runtime/dist/src/knowledge/assembly.js +60 -0
- package/runtime/dist/src/knowledge/documents.js +520 -0
- package/runtime/dist/src/knowledge/embeddings.js +201 -0
- package/runtime/dist/src/knowledge/mcp.js +218 -0
- package/runtime/dist/src/knowledge/parse-worker.js +122 -0
- package/runtime/dist/src/knowledge/references.js +51 -0
- package/runtime/dist/src/knowledge/service.js +526 -0
- package/runtime/dist/src/knowledge/store-client.js +185 -0
- package/runtime/dist/src/knowledge/store-worker.js +843 -0
- package/runtime/dist/src/knowledge/types.js +2 -0
- package/runtime/dist/src/mcp/http-server.js +177 -0
- package/runtime/dist/src/mem0/resource.js +35 -0
- package/runtime/dist/src/mem0/store-worker.js +330 -0
- package/runtime/dist/src/memory/blackboard-session.js +205 -0
- package/runtime/dist/src/memory/blackboard-store.js +194 -0
- package/runtime/dist/src/memory/blackboard-worker.js +369 -0
- package/runtime/dist/src/memory/entry.js +39 -0
- package/runtime/dist/src/memory/factory.js +20 -0
- package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
- package/runtime/dist/src/memory/personal-memory.js +10 -0
- package/runtime/dist/src/memory/prerecall.js +20 -0
- package/runtime/dist/src/memory/provenance.js +17 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
- package/runtime/dist/src/memory/retrieval.js +235 -0
- package/runtime/dist/src/memory/sensitivity.js +261 -0
- package/runtime/dist/src/memory-ledger/models.js +98 -0
- package/runtime/dist/src/memory-ledger/store-client.js +210 -0
- package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
- package/runtime/dist/src/memory-ledger/store.js +597 -0
- package/runtime/dist/src/memory-substrate/candidates.js +16 -0
- package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
- package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
- package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
- package/runtime/dist/src/memory-substrate/migration.js +87 -0
- package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
- package/runtime/dist/src/memory-substrate/purge.js +398 -0
- package/runtime/dist/src/memory-substrate/resolution.js +32 -0
- package/runtime/dist/src/memory-substrate/resource.js +867 -0
- package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
- package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
- package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
- package/runtime/dist/src/memory-substrate/source-state.js +93 -0
- package/runtime/dist/src/memory-substrate/store.js +534 -0
- package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
- package/runtime/dist/src/memory-substrate/workspace.js +21 -0
- package/runtime/dist/src/model/jev-client.js +25 -0
- package/runtime/dist/src/model/model-adapters.js +64 -0
- package/runtime/dist/src/model/model-gateway.js +399 -0
- package/runtime/dist/src/model/model-lane.js +34 -0
- package/runtime/dist/src/model/model-purpose.js +5 -0
- package/runtime/dist/src/model/personal-writer.js +361 -0
- package/runtime/dist/src/model/proactivity.js +72 -0
- package/runtime/dist/src/model/prompting.js +279 -0
- package/runtime/dist/src/model/task-verifier.js +217 -0
- package/runtime/dist/src/model/vision-capability.js +10 -0
- package/runtime/dist/src/news/feeds.js +114 -0
- package/runtime/dist/src/news/jev-ranking.js +25 -0
- package/runtime/dist/src/news/ranking.js +26 -0
- package/runtime/dist/src/news/service.js +262 -0
- package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
- package/runtime/dist/src/notifications/adapters/nova.js +15 -0
- package/runtime/dist/src/notifications/content.js +15 -0
- package/runtime/dist/src/notifications/contracts.js +9 -0
- package/runtime/dist/src/notifications/feed.js +8 -0
- package/runtime/dist/src/notifications/service.js +412 -0
- package/runtime/dist/src/notifications/store.js +4 -0
- package/runtime/dist/src/personal-agent/app-context.js +113 -0
- package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
- package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
- package/runtime/dist/src/personal-agent/contracts.js +32 -0
- package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
- package/runtime/dist/src/personal-agent/conversations.js +187 -0
- package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2403 -0
- package/runtime/dist/src/personal-agent/intake-task.js +37 -0
- package/runtime/dist/src/personal-agent/life.js +260 -0
- package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
- package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
- package/runtime/dist/src/personal-agent/project-digests.js +242 -0
- package/runtime/dist/src/personal-agent/sampling.js +20 -0
- package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
- package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
- package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
- package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
- package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
- package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
- package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
- package/runtime/dist/src/personal-agent/source-priority.js +142 -0
- package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
- package/runtime/dist/src/personal-agent/source-walk.js +25 -0
- package/runtime/dist/src/personal-agent/sources.js +1484 -0
- package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
- package/runtime/dist/src/personal-agent/store.js +146 -0
- package/runtime/dist/src/personal-agent/task-loop.js +163 -0
- package/runtime/dist/src/personal-agent/tasks.js +920 -0
- package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
- package/runtime/dist/src/personal-agent/understanding.js +160 -0
- package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
- package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
- package/runtime/dist/src/projects/host-paths.js +133 -0
- package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
- package/runtime/dist/src/projects/project-confirmation.js +486 -0
- package/runtime/dist/src/projects/project-native-resource.js +284 -0
- package/runtime/dist/src/projects/project-node-files.js +169 -0
- package/runtime/dist/src/projects/project-root-file.js +16 -0
- package/runtime/dist/src/projects/project-state.js +504 -0
- package/runtime/dist/src/projects/project-store-files.js +1271 -0
- package/runtime/dist/src/projects/project-store.js +1345 -0
- package/runtime/dist/src/realtime/aoq.js +141 -0
- package/runtime/dist/src/realtime/bridge.js +652 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
- package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
- package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
- package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
- package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
- package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
- package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
- package/runtime/dist/src/realtime/dictation.js +28 -0
- package/runtime/dist/src/realtime/evidence.js +276 -0
- package/runtime/dist/src/realtime/floor.js +43 -0
- package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
- package/runtime/dist/src/realtime/gemini.js +517 -0
- package/runtime/dist/src/realtime/history.js +122 -0
- package/runtime/dist/src/realtime/host-delivery.js +1711 -0
- package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
- package/runtime/dist/src/realtime/memory-board.js +105 -0
- package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
- package/runtime/dist/src/realtime/playback.js +242 -0
- package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
- package/runtime/dist/src/realtime/prompt-language.js +17 -0
- package/runtime/dist/src/realtime/protocol.js +428 -0
- package/runtime/dist/src/realtime/provider-projection.js +526 -0
- package/runtime/dist/src/realtime/provider-session.js +491 -0
- package/runtime/dist/src/realtime/qwen-transport.js +144 -0
- package/runtime/dist/src/realtime/qwen.js +1377 -0
- package/runtime/dist/src/realtime/recall.js +341 -0
- package/runtime/dist/src/realtime/service-ports.js +8 -0
- package/runtime/dist/src/realtime/service-state.js +259 -0
- package/runtime/dist/src/realtime/service.js +1726 -0
- package/runtime/dist/src/realtime/session-state.js +684 -0
- package/runtime/dist/src/realtime/session.js +1976 -0
- package/runtime/dist/src/realtime/speech-prep.js +63 -0
- package/runtime/dist/src/realtime/streaming-speech.js +120 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
- package/runtime/dist/src/realtime/telemetry.js +144 -0
- package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
- package/runtime/dist/src/realtime/transport.js +8 -0
- package/runtime/dist/src/realtime/usage.js +55 -0
- package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
- package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
- package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
- package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
- package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
- package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
- package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
- package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
- package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
- package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
- package/runtime/dist/src/server/aoq-chat-server.js +497 -0
- package/runtime/dist/src/server/client-pairing.js +192 -0
- package/runtime/dist/src/server/client-protocol.js +87 -0
- package/runtime/dist/src/server/client-server.js +312 -0
- package/runtime/dist/src/server/server-config.js +72 -0
- package/runtime/dist/src/server-entry.js +135 -0
- package/runtime/dist/src/storage/bounded-json.js +63 -0
- package/runtime/dist/src/storage/native-file-lock.js +8 -0
- package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
- package/runtime/dist/src/storage/private-database.js +120 -0
- package/runtime/dist/src/text/canonical-json.js +60 -0
- package/runtime/dist/src/text/python-number.js +18 -0
- package/runtime/dist/src/text/python-text.js +92 -0
- package/runtime/dist/src/text/unicode-casefold.js +29 -0
- package/runtime/dist/src/text/unicode-normalize.js +138 -0
- package/runtime/dist/src/text/unicode-tables.js +210 -0
- package/runtime/dist/src/understanding/candidates.js +77 -0
- package/runtime/dist/src/understanding/fixture.js +7 -0
- package/runtime/dist/src/understanding/jev.js +20 -0
- package/runtime/dist/src/understanding/pipeline.js +38 -0
- package/runtime/dist/src/voicemem/store-client.js +476 -0
- package/runtime/dist/src/voicemem/store-worker.js +380 -0
- package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
- package/runtime/scripts/pair-device.mjs +109 -0
- package/src/command.mjs +48 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/** Fixed ADB operations. No model-provided shell, intents, or automatic device selection. */
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { access, realpath } from 'node:fs/promises';
|
|
5
|
+
import { delimiter, isAbsolute, join } from 'node:path';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
|
+
const exec = promisify(execFile);
|
|
9
|
+
const keyboard = 'com.android.adbkeyboard/.AdbIME';
|
|
10
|
+
const refusal = /INJECT_EVENTS|SecurityException|Permission Denial/u;
|
|
11
|
+
const failureText = /Error:|Exception occurred/u;
|
|
12
|
+
/** Resolve once at bind time so a later PATH change cannot swap the binary that receives approved writes. */
|
|
13
|
+
async function resolveAdb() {
|
|
14
|
+
for (const directory of (process.env.PATH ?? '').split(delimiter)) {
|
|
15
|
+
if (!isAbsolute(directory))
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
const candidate = join(directory, 'adb');
|
|
19
|
+
await access(candidate, constants.X_OK);
|
|
20
|
+
return await realpath(candidate);
|
|
21
|
+
}
|
|
22
|
+
catch { /* Try the next PATH entry. */ }
|
|
23
|
+
}
|
|
24
|
+
throw new Error('invalid_configuration');
|
|
25
|
+
}
|
|
26
|
+
export async function createAndroidDevice(serial, signal) {
|
|
27
|
+
if (!/^[A-Za-z0-9_.:-]{1,128}$/u.test(serial))
|
|
28
|
+
throw new Error('invalid_configuration');
|
|
29
|
+
const adb = await resolveAdb();
|
|
30
|
+
const command = async (args, write = false) => {
|
|
31
|
+
if (!write && signal.aborted)
|
|
32
|
+
throw new Error('cancelled');
|
|
33
|
+
let result;
|
|
34
|
+
try {
|
|
35
|
+
result = await exec(adb, ['-s', serial, ...args], { encoding: 'buffer', timeout: 10_000,
|
|
36
|
+
maxBuffer: 32 * 1024 * 1024, ...(write ? {} : { signal }) });
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const failure = error;
|
|
40
|
+
if (refusal.test(failure.stderr?.toString() ?? ''))
|
|
41
|
+
throw new Error('needs_user_action');
|
|
42
|
+
// A disconnected adb client cannot establish whether the remote write completed.
|
|
43
|
+
if (write)
|
|
44
|
+
throw new Error('cleanup_unknown');
|
|
45
|
+
throw new Error(signal.aborted ? 'cancelled' : 'action_failed');
|
|
46
|
+
}
|
|
47
|
+
const stderr = result.stderr.toString();
|
|
48
|
+
if (refusal.test(stderr) || failureText.test(stderr)) {
|
|
49
|
+
// adb exited 0, so the device may have applied the write despite the error text.
|
|
50
|
+
if (write)
|
|
51
|
+
throw new Error('cleanup_unknown');
|
|
52
|
+
throw new Error(refusal.test(stderr) ? 'needs_user_action' : 'action_failed');
|
|
53
|
+
}
|
|
54
|
+
return result.stdout;
|
|
55
|
+
};
|
|
56
|
+
const text = async (args, write = false) => (await command(args, write)).toString().trim();
|
|
57
|
+
const hardwareId = async () => {
|
|
58
|
+
const id = await text(['shell', 'getprop', 'ro.serialno']) || await text(['shell', 'getprop', 'ro.boot.serialno']);
|
|
59
|
+
if (!/^[\x21-\x7e]{1,128}$/u.test(id))
|
|
60
|
+
throw new Error('invalid_configuration');
|
|
61
|
+
return id;
|
|
62
|
+
};
|
|
63
|
+
if (await text(['get-state']) !== 'device')
|
|
64
|
+
throw new Error('invalid_configuration');
|
|
65
|
+
// The transport serial can be reassigned (e.g. emulator ports); writes stay bound to the hardware seen at bind.
|
|
66
|
+
const boundHardware = await hardwareId();
|
|
67
|
+
const verify = async () => {
|
|
68
|
+
if (await text(['get-state']) !== 'device' || await hardwareId() !== boundHardware)
|
|
69
|
+
throw new Error('invalid_configuration');
|
|
70
|
+
};
|
|
71
|
+
const foreground = async () => {
|
|
72
|
+
const windows = await text(['shell', 'dumpsys', 'window']);
|
|
73
|
+
const focused = windows.split('\n').find(line => line.includes('mCurrentFocus=')) ?? '';
|
|
74
|
+
const bundle = (/\b([A-Za-z][A-Za-z0-9_.]*)\/[A-Za-z0-9_.$]+/u.exec(focused))?.[1];
|
|
75
|
+
if (!bundle)
|
|
76
|
+
throw new Error('action_failed');
|
|
77
|
+
return { bundle, context: focused.trim() };
|
|
78
|
+
};
|
|
79
|
+
const capture = async () => {
|
|
80
|
+
await verify();
|
|
81
|
+
const { bundle, context } = await foreground();
|
|
82
|
+
const png = await command(['exec-out', 'screencap', '-p']);
|
|
83
|
+
if (!png.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) || png.length < 24)
|
|
84
|
+
throw new Error('action_failed');
|
|
85
|
+
if ((await foreground()).context !== context)
|
|
86
|
+
throw new Error('screen_changed');
|
|
87
|
+
return { image: `data:image/png;base64,${png.toString('base64')}`, bundle, context,
|
|
88
|
+
width: png.readUInt32BE(16), height: png.readUInt32BE(20) };
|
|
89
|
+
};
|
|
90
|
+
const initial = await capture();
|
|
91
|
+
const size = { width: initial.width, height: initial.height };
|
|
92
|
+
const stableCapture = async () => {
|
|
93
|
+
const frame = await capture();
|
|
94
|
+
if (frame.width !== initial.width || frame.height !== initial.height)
|
|
95
|
+
throw new Error('screen_changed');
|
|
96
|
+
return frame;
|
|
97
|
+
};
|
|
98
|
+
const coordinate = (value, limit) => {
|
|
99
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value >= limit)
|
|
100
|
+
throw new Error('needs_user_action');
|
|
101
|
+
return String(value);
|
|
102
|
+
};
|
|
103
|
+
return { verify, capture: stableCapture, size, perform: async (name, params) => {
|
|
104
|
+
if (signal.aborted)
|
|
105
|
+
throw new Error('cancelled');
|
|
106
|
+
await verify();
|
|
107
|
+
if (signal.aborted)
|
|
108
|
+
throw new Error('cancelled');
|
|
109
|
+
switch (name) {
|
|
110
|
+
case 'Tap':
|
|
111
|
+
await command(['shell', 'input', 'tap', coordinate(params.x, size.width), coordinate(params.y, size.height)], true);
|
|
112
|
+
break;
|
|
113
|
+
case 'Swipe':
|
|
114
|
+
await command(['shell', 'input', 'swipe', coordinate(params.fromX, size.width), coordinate(params.fromY, size.height),
|
|
115
|
+
coordinate(params.toX, size.width), coordinate(params.toY, size.height), '500'], true);
|
|
116
|
+
break;
|
|
117
|
+
case 'Home':
|
|
118
|
+
case 'Back':
|
|
119
|
+
await command(['shell', 'input', 'keyevent', name === 'Home' ? '3' : '4'], true);
|
|
120
|
+
break;
|
|
121
|
+
case 'Launch': {
|
|
122
|
+
const app = params.packageName;
|
|
123
|
+
if (typeof app !== 'string' || !/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/u.test(app))
|
|
124
|
+
throw new Error('needs_user_action');
|
|
125
|
+
const component = await text(['shell', 'cmd', 'package', 'resolve-activity', '--brief', '-a', 'android.intent.action.MAIN', '-c', 'android.intent.category.LAUNCHER', app]);
|
|
126
|
+
const activity = component.split('\n').at(-1) ?? '';
|
|
127
|
+
if (!activity.startsWith(`${app}/`) || !/^[A-Za-z0-9_.$/]+$/u.test(activity))
|
|
128
|
+
throw new Error('needs_user_action');
|
|
129
|
+
if (signal.aborted)
|
|
130
|
+
throw new Error('cancelled');
|
|
131
|
+
const result = await text(['shell', 'am', 'start', '-W', '-n', activity], true);
|
|
132
|
+
if (/Error:|Exception/u.test(result))
|
|
133
|
+
throw new Error('action_failed');
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'Type': {
|
|
137
|
+
const value = params.text;
|
|
138
|
+
if (typeof value !== 'string' || !value || value.length > 4000)
|
|
139
|
+
throw new Error('needs_user_action');
|
|
140
|
+
const previous = await text(['shell', 'settings', 'get', 'secure', 'default_input_method']);
|
|
141
|
+
if (!/^[A-Za-z0-9_.$]+\/[A-Za-z0-9_.$]+$/u.test(previous))
|
|
142
|
+
throw new Error('invalid_configuration');
|
|
143
|
+
if (!(await text(['shell', 'ime', 'list', '-s'])).split('\n').includes(keyboard))
|
|
144
|
+
throw new Error('needs_user_action');
|
|
145
|
+
try {
|
|
146
|
+
if (signal.aborted)
|
|
147
|
+
throw new Error('cancelled');
|
|
148
|
+
await command(['shell', 'ime', 'set', keyboard], true);
|
|
149
|
+
const deadline = Date.now() + 5000;
|
|
150
|
+
for (;;) {
|
|
151
|
+
const binding = (await text(['shell', 'dumpsys', 'input_method'])).split('\n')
|
|
152
|
+
.find(line => line.includes('mCurId='))?.trim().split(/\s+/u) ?? [];
|
|
153
|
+
if ([`mCurId=${keyboard}`, 'mHaveConnection=true', 'mBoundToMethod=true'].every(field => binding.includes(field)))
|
|
154
|
+
break;
|
|
155
|
+
if (Date.now() >= deadline)
|
|
156
|
+
throw new Error('needs_user_action');
|
|
157
|
+
await delay(100);
|
|
158
|
+
}
|
|
159
|
+
if (signal.aborted)
|
|
160
|
+
throw new Error('cancelled');
|
|
161
|
+
const result = await text(['shell', 'am', 'broadcast', '-p', 'com.android.adbkeyboard', '-a', 'ADB_INPUT_B64', '--es', 'msg', Buffer.from(value).toString('base64')], true);
|
|
162
|
+
if (!result.includes('Broadcast completed'))
|
|
163
|
+
throw new Error('action_failed');
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
// Restore the original keyboard even after cancellation; uncertain restoration quarantines the device.
|
|
167
|
+
try {
|
|
168
|
+
await command(['shell', 'ime', 'set', previous], true);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
throw new Error('cleanup_unknown');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default: throw new Error('needs_user_action');
|
|
177
|
+
}
|
|
178
|
+
} };
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=mobile-android.js.map
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/** Native SDK planner; Nova alone grants authority for each atomic device write. */
|
|
2
|
+
import { createAndroidDevice } from './mobile-android.js';
|
|
3
|
+
import { execFile } from 'node:child_process';
|
|
4
|
+
import { basename } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
|
+
import { z } from '@midscene/core';
|
|
8
|
+
import { actionTapParamSchema, actionScrollParamSchema } from '@midscene/core/device';
|
|
9
|
+
import { runGui, validGuiConfig, logicalSwipeDistance } from './gui-runner.js';
|
|
10
|
+
const exec = promisify(execFile);
|
|
11
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
12
|
+
export { logicalSwipeDistance } from './gui-runner.js';
|
|
13
|
+
/** Only positively acknowledged ADB refusals are safe to release; transport ambiguity wins over cancellation. */
|
|
14
|
+
export function mobileWriteFailure(error, android, stopped) {
|
|
15
|
+
const reason = error instanceof Error ? error.message : '';
|
|
16
|
+
if (android && ['action_failed', 'needs_user_action', 'cancelled', 'invalid_configuration'].includes(reason))
|
|
17
|
+
return stopped ?? reason;
|
|
18
|
+
return 'cleanup_unknown';
|
|
19
|
+
}
|
|
20
|
+
export async function runMobileIos(config, instruction, options) {
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
let code;
|
|
23
|
+
let steps = 0;
|
|
24
|
+
const stop = (reason) => {
|
|
25
|
+
code ??= reason;
|
|
26
|
+
controller.abort();
|
|
27
|
+
throw new Error(code);
|
|
28
|
+
};
|
|
29
|
+
const cancelled = () => { code ??= 'cancelled'; controller.abort(); };
|
|
30
|
+
options.signal.addEventListener('abort', cancelled, { once: true });
|
|
31
|
+
if (options.signal.aborted)
|
|
32
|
+
cancelled();
|
|
33
|
+
const check = () => { if (controller.signal.aborted)
|
|
34
|
+
throw new Error(code ?? 'cancelled'); };
|
|
35
|
+
const timer = setTimeout(() => { code ??= 'timeout'; controller.abort(); }, config.budgetMs);
|
|
36
|
+
const emit = (phase, actionName) => {
|
|
37
|
+
options.progress({ phase, steps, ...(actionName ? { actionName } : {}) });
|
|
38
|
+
};
|
|
39
|
+
let configured = false;
|
|
40
|
+
try {
|
|
41
|
+
check();
|
|
42
|
+
const settleMs = config.settleMs ?? 4000;
|
|
43
|
+
if (!Number.isSafeInteger(settleMs) || settleMs < 0 || settleMs > 30_000)
|
|
44
|
+
stop('invalid_configuration');
|
|
45
|
+
const endpoint = new URL(config.wdaUrl);
|
|
46
|
+
// Borrow only a verified simulator runner or explicit USB iproxy binding.
|
|
47
|
+
const android = config.deviceType === 'android';
|
|
48
|
+
if ((!android && (!['ios-simulator', 'ios'].includes(config.deviceType) || process.platform !== 'darwin'
|
|
49
|
+
|| !(config.deviceType === 'ios-simulator' ? /^[A-Fa-f0-9-]{36}$/u : /^(?:[A-Fa-f0-9]{40}|[A-Fa-f0-9]{8}-[A-Fa-f0-9]{16})$/u).test(config.deviceId)
|
|
50
|
+
|| endpoint.protocol !== 'http:' || !['localhost', '127.0.0.1'].includes(endpoint.hostname)
|
|
51
|
+
|| endpoint.pathname !== '/' || endpoint.username || endpoint.password || endpoint.search || endpoint.hash))
|
|
52
|
+
|| !validGuiConfig(config, instruction))
|
|
53
|
+
stop('invalid_configuration');
|
|
54
|
+
const adb = android ? await createAndroidDevice(config.deviceId, controller.signal) : undefined;
|
|
55
|
+
const ios = android ? undefined : await (async () => {
|
|
56
|
+
const port = Number(endpoint.port || 80);
|
|
57
|
+
const command = async (file, args) => {
|
|
58
|
+
check();
|
|
59
|
+
return (await exec(file, args, { timeout: 5000, signal: controller.signal, maxBuffer: 1024 * 1024 })).stdout.trim();
|
|
60
|
+
};
|
|
61
|
+
const simulator = config.deviceType === 'ios-simulator';
|
|
62
|
+
if (simulator) {
|
|
63
|
+
const listing = record(JSON.parse(await command('/usr/bin/xcrun', ['simctl', 'list', 'devices', 'booted', '-j'])));
|
|
64
|
+
const devices = Object.values(record(listing.devices)).flatMap(group => Array.isArray(group) ? group : []);
|
|
65
|
+
if (devices.filter(value => {
|
|
66
|
+
const item = record(value);
|
|
67
|
+
return item.udid === config.deviceId
|
|
68
|
+
&& item.state === 'Booted' && item.isAvailable !== false;
|
|
69
|
+
}).length !== 1)
|
|
70
|
+
stop('invalid_configuration');
|
|
71
|
+
}
|
|
72
|
+
const identity = async () => {
|
|
73
|
+
const listeners = await command('/usr/sbin/lsof', ['-nP', `-iTCP:${port}`, '-sTCP:LISTEN', '-Fp']);
|
|
74
|
+
const pids = [...new Set(listeners.split('\n').filter(line => /^p\d+$/u.test(line)).map(line => line.slice(1)))];
|
|
75
|
+
if (pids.length !== 1)
|
|
76
|
+
stop('invalid_configuration');
|
|
77
|
+
const pid = pids[0];
|
|
78
|
+
const executable = await command('/bin/ps', ['-p', pid, '-o', 'comm=']);
|
|
79
|
+
if (simulator && !['WebDriverAgentRunner-Runner', 'WebDriverAgentRunner'].includes(basename(executable)))
|
|
80
|
+
stop('invalid_configuration');
|
|
81
|
+
if (!simulator) {
|
|
82
|
+
const args = await command('/bin/ps', ['-p', pid, '-o', 'args=']);
|
|
83
|
+
if (!validIosUsbForwarder(executable, args, config.deviceId, port) || !(await command('idevice_id', ['-l'])).split('\n').includes(config.deviceId))
|
|
84
|
+
stop('invalid_configuration');
|
|
85
|
+
return `${pid}:${await command('/bin/ps', ['-p', pid, '-o', 'lstart='])}`;
|
|
86
|
+
}
|
|
87
|
+
const environment = await command('/bin/ps', ['eww', '-p', pid, '-o', 'command=']);
|
|
88
|
+
const ids = [...environment.matchAll(/(?:^|\s)SIMULATOR_UDID=([^\s]+)(?=\s|$)/gu)].map(match => match[1]);
|
|
89
|
+
if (ids.length !== 1 || ids[0] !== config.deviceId)
|
|
90
|
+
stop('invalid_configuration');
|
|
91
|
+
return `${pid}:${await command('/bin/ps', ['-p', pid, '-o', 'lstart='])}`;
|
|
92
|
+
};
|
|
93
|
+
const initialIdentity = await identity();
|
|
94
|
+
const verify = async () => { check(); if (await identity() !== initialIdentity)
|
|
95
|
+
stop('invalid_configuration'); check(); };
|
|
96
|
+
const read = async (path) => {
|
|
97
|
+
await verify();
|
|
98
|
+
const response = await fetch(new URL(path, endpoint), {
|
|
99
|
+
signal: AbortSignal.any([controller.signal, AbortSignal.timeout(Math.min(config.budgetMs, 30_000))]), redirect: 'error'
|
|
100
|
+
});
|
|
101
|
+
if (!response.ok)
|
|
102
|
+
stop('action_failed');
|
|
103
|
+
const data = record(await response.json());
|
|
104
|
+
if (record(data.value).error)
|
|
105
|
+
stop('action_failed');
|
|
106
|
+
return data;
|
|
107
|
+
};
|
|
108
|
+
const status = await read('/status');
|
|
109
|
+
const value = record(status.value);
|
|
110
|
+
const reportedId = value.udid ?? record(value.device).udid;
|
|
111
|
+
if (reportedId && reportedId !== config.deviceId)
|
|
112
|
+
stop('invalid_configuration');
|
|
113
|
+
const sessionId = status.sessionId ?? value.sessionId;
|
|
114
|
+
if (typeof sessionId !== 'string' || !/^[A-Za-z0-9_-]{1,200}$/u.test(sessionId))
|
|
115
|
+
stop('invalid_configuration');
|
|
116
|
+
// Borrow the verified session without connecting, modifying settings, or installing WDA.
|
|
117
|
+
const sessionPath = `/session/${sessionId}`;
|
|
118
|
+
const foreground = async () => {
|
|
119
|
+
const bundle = record((await read('/wda/activeAppInfo')).value).bundleId;
|
|
120
|
+
if (typeof bundle !== 'string' || !bundle || bundle.length > 300)
|
|
121
|
+
stop('action_failed');
|
|
122
|
+
return bundle;
|
|
123
|
+
};
|
|
124
|
+
const capture = async () => {
|
|
125
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
126
|
+
const bundle = await foreground();
|
|
127
|
+
const encoded = (await read(`${sessionPath}/screenshot`)).value;
|
|
128
|
+
if (typeof encoded !== 'string' || encoded.length > 40_000_000
|
|
129
|
+
|| !/^(?:iVBOR|\/9j\/)/u.test(encoded))
|
|
130
|
+
stop('action_failed');
|
|
131
|
+
const image = `data:image/${encoded.startsWith('/9j/') ? 'jpeg' : 'png'};base64,${encoded}`;
|
|
132
|
+
const rect = record((await read(`${sessionPath}/window/rect`)).value);
|
|
133
|
+
if (![rect.width, rect.height].every(n => typeof n === 'number' && Number.isFinite(n) && n > 0))
|
|
134
|
+
stop('action_failed');
|
|
135
|
+
if (await foreground() === bundle)
|
|
136
|
+
return { image, bundle, context: JSON.stringify([bundle, rect.width, rect.height]) };
|
|
137
|
+
if (attempt < 2)
|
|
138
|
+
await delay(250, undefined, { signal: controller.signal });
|
|
139
|
+
}
|
|
140
|
+
return stop('screen_changed');
|
|
141
|
+
};
|
|
142
|
+
return { verify, read, capture, sessionPath };
|
|
143
|
+
})();
|
|
144
|
+
const capture = adb ? adb.capture : ios.capture;
|
|
145
|
+
const verify = adb ? adb.verify : ios.verify;
|
|
146
|
+
let latest;
|
|
147
|
+
let planned;
|
|
148
|
+
let size = { width: 0, height: 0 };
|
|
149
|
+
const point = (input) => {
|
|
150
|
+
const coordinates = Array.isArray(input) ? input : stop('needs_user_action');
|
|
151
|
+
if (coordinates.length !== 2 || coordinates.some((n, i) => typeof n !== 'number'
|
|
152
|
+
|| !Number.isFinite(n) || n < 0 || n >= (i ? size.height : size.width)))
|
|
153
|
+
stop('needs_user_action');
|
|
154
|
+
return [Math.floor(coordinates[0]), Math.floor(coordinates[1])];
|
|
155
|
+
};
|
|
156
|
+
const write = async (name, params, path, body) => {
|
|
157
|
+
try {
|
|
158
|
+
check();
|
|
159
|
+
if (steps >= config.maxSteps)
|
|
160
|
+
stop('step_limit');
|
|
161
|
+
const baseline = planned;
|
|
162
|
+
if (!baseline)
|
|
163
|
+
stop('screen_changed');
|
|
164
|
+
const fresh = async () => {
|
|
165
|
+
const current = await capture();
|
|
166
|
+
if (current.context !== baseline.context) {
|
|
167
|
+
stop('screen_changed');
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
await fresh();
|
|
171
|
+
emit('action_pending', name);
|
|
172
|
+
const approval = options.approve(name, params);
|
|
173
|
+
// A pending approval must not keep a cancelled run alive.
|
|
174
|
+
const accepted = await new Promise((resolve, reject) => {
|
|
175
|
+
const abort = () => reject(new Error(code ?? 'cancelled'));
|
|
176
|
+
controller.signal.addEventListener('abort', abort, { once: true });
|
|
177
|
+
approval.then(resolve, reject).finally(() => controller.signal.removeEventListener('abort', abort)).catch(() => undefined);
|
|
178
|
+
if (controller.signal.aborted)
|
|
179
|
+
abort();
|
|
180
|
+
});
|
|
181
|
+
check();
|
|
182
|
+
if (!accepted)
|
|
183
|
+
stop('declined');
|
|
184
|
+
await fresh();
|
|
185
|
+
await verify();
|
|
186
|
+
check();
|
|
187
|
+
options.beforeWrite?.();
|
|
188
|
+
steps++;
|
|
189
|
+
// Cancellation cannot undo a dispatched action. Await its bounded acknowledgement, including the body.
|
|
190
|
+
let rejected = false;
|
|
191
|
+
try {
|
|
192
|
+
if (adb)
|
|
193
|
+
await adb.perform(name, record(params));
|
|
194
|
+
else {
|
|
195
|
+
const response = await fetch(new URL(`${ios.sessionPath}${path}`, endpoint), { method: 'POST', redirect: 'error',
|
|
196
|
+
headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
197
|
+
signal: AbortSignal.timeout(Math.min(config.budgetMs, 30_000)) });
|
|
198
|
+
const data = record(await response.json());
|
|
199
|
+
if (!Object.hasOwn(data, 'value'))
|
|
200
|
+
throw new Error('invalid_wda_acknowledgement');
|
|
201
|
+
rejected = !response.ok || (Boolean(record(data.value).error) || Boolean(data.error));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
code = mobileWriteFailure(error, Boolean(adb), code);
|
|
206
|
+
stop(code);
|
|
207
|
+
}
|
|
208
|
+
if (rejected)
|
|
209
|
+
stop('action_failed');
|
|
210
|
+
planned = undefined;
|
|
211
|
+
const observed = await capture();
|
|
212
|
+
options.capture?.(observed.image, steps);
|
|
213
|
+
emit('action_returned', name);
|
|
214
|
+
check();
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
const reason = error instanceof Error ? error.message : '';
|
|
218
|
+
stop(code ?? (['screen_changed', 'needs_user_action', 'invalid_configuration', 'cancelled'].includes(reason) ? reason : 'action_failed'));
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const actions = [
|
|
222
|
+
{ name: 'Tap', paramSchema: actionTapParamSchema, call: async (param) => {
|
|
223
|
+
const [x, y] = point(record(record(param).locate).center);
|
|
224
|
+
await write('Tap', { x, y }, '/wda/tap', { x, y });
|
|
225
|
+
} },
|
|
226
|
+
{ name: 'Input', description: 'Type text into the already focused field without clearing it or dismissing the keyboard.',
|
|
227
|
+
paramSchema: z.object({ value: z.string().min(1).max(4000) }).strict(), call: async (param) => {
|
|
228
|
+
const text = record(param).value; // Already validated by the action schema.
|
|
229
|
+
await write('Type', { text }, '/wda/keys', { value: Array.from(text) });
|
|
230
|
+
} },
|
|
231
|
+
{ name: 'AndroidHomeButton', description: 'Press the Home button.', call: async () => {
|
|
232
|
+
await write('Home', {}, '/wda/pressButton', { name: 'home' });
|
|
233
|
+
} },
|
|
234
|
+
{ name: 'Scroll', paramSchema: actionScrollParamSchema.extend({ scrollType: z.literal('singleAction'), distance: z.number().finite().positive(), locate: actionTapParamSchema.shape.locate }), call: async (raw, context) => {
|
|
235
|
+
const param = record(raw);
|
|
236
|
+
if (param.scrollType !== 'singleAction' || typeof param.distance !== 'number' || !Number.isFinite(param.distance)
|
|
237
|
+
|| param.distance <= 0 || typeof param.direction !== 'string')
|
|
238
|
+
stop('needs_user_action');
|
|
239
|
+
const [fromX, fromY] = point(record(param.locate).center);
|
|
240
|
+
const offset = { down: [0, -1], up: [0, 1], right: [-1, 0], left: [1, 0] }[param.direction];
|
|
241
|
+
if (!offset)
|
|
242
|
+
stop('needs_user_action');
|
|
243
|
+
const distance = config.modelFamily.startsWith('auto-glm') ? logicalSwipeDistance(param.distance, context?.uiContext?.shrunkShotToLogicalRatio ?? NaN) : param.distance;
|
|
244
|
+
const [toX, toY] = point([fromX + offset[0] * distance, fromY + offset[1] * distance]);
|
|
245
|
+
await write('Swipe', { fromX, fromY, toX, toY, durationMs: 500 }, '/actions', { actions: [{ type: 'pointer', id: 'finger1',
|
|
246
|
+
parameters: { pointerType: 'touch' }, actions: [{ type: 'pointerMove', duration: 0, x: fromX, y: fromY },
|
|
247
|
+
{ type: 'pointerDown', button: 0 }, { type: 'pause', duration: 100 },
|
|
248
|
+
{ type: 'pointerMove', duration: 500, x: toX, y: toY }, { type: 'pointerUp', button: 0 }] }] });
|
|
249
|
+
} },
|
|
250
|
+
];
|
|
251
|
+
if (android)
|
|
252
|
+
actions.push({ name: 'Launch', description: 'Launch an installed Android app by exact package name (for example com.example.app), never a URL or shell command.',
|
|
253
|
+
paramSchema: z.object({ uri: z.string().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/u) }).strict(),
|
|
254
|
+
call: async (param) => write('Launch', { packageName: record(param).uri }, '', {}) }, { name: 'AndroidBackButton', description: 'Press Android Back.', call: async () => write('Back', {}, '', {}) });
|
|
255
|
+
const guarded = { interfaceType: android ? 'android' : 'ios',
|
|
256
|
+
size: async () => {
|
|
257
|
+
if (adb) {
|
|
258
|
+
size = adb.size;
|
|
259
|
+
return size;
|
|
260
|
+
}
|
|
261
|
+
const value = record((await ios.read(`${ios.sessionPath}/window/rect`)).value);
|
|
262
|
+
const parsed = z.object({ width: z.number().finite().positive(), height: z.number().finite().positive() }).safeParse(value);
|
|
263
|
+
if (!parsed.success)
|
|
264
|
+
stop('action_failed');
|
|
265
|
+
size = parsed.data;
|
|
266
|
+
return size;
|
|
267
|
+
},
|
|
268
|
+
screenshotBase64: async () => {
|
|
269
|
+
try {
|
|
270
|
+
latest = await capture();
|
|
271
|
+
return latest.image;
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
return stop(error instanceof Error && error.message === 'screen_changed' ? 'screen_changed' : 'action_failed');
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
actionSpace: () => actions };
|
|
278
|
+
configured = true;
|
|
279
|
+
const returned = await runGui(instruction, guarded, { ...config, signal: controller.signal,
|
|
280
|
+
steps: () => steps, planning: () => { planned = latest; }, progress: options.progress, ...(options.capture ? { capture: options.capture } : {}),
|
|
281
|
+
context: android
|
|
282
|
+
? 'Use only the available actions. Launch requires an exact installed Android package name. Input appends text to the focused field. Never guess package names or execute shell commands.'
|
|
283
|
+
: 'Only Tap, Type into an already focused field, one Swipe, Home, and finish are available. Never launch apps or use other actions.' });
|
|
284
|
+
return { code: code ?? returned, steps };
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return { code: code ?? (configured ? 'model_failed' : 'invalid_configuration'), steps };
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
clearTimeout(timer);
|
|
291
|
+
options.signal.removeEventListener('abort', cancelled);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/** Only an explicit USB tunnel to this UDID/port is eligible; never borrow a default or network device. */
|
|
295
|
+
export function validIosUsbForwarder(executable, args, deviceId, port) {
|
|
296
|
+
if (basename(executable) !== 'iproxy' || /(?:^|\s)(?:-n|--network)(?:\s|$)/u.test(args))
|
|
297
|
+
return false;
|
|
298
|
+
const ids = [...args.matchAll(/(?:^|\s)(?:-u|--udid)\s+(\S+)/gu)].map(match => match[1]);
|
|
299
|
+
const sources = [...args.matchAll(/(?:^|\s)(?:-s|--source)\s+(\S+)/gu)].map(match => match[1]);
|
|
300
|
+
return ids.length === 1 && ids[0] === deviceId && sources.every(source => source === '127.0.0.1')
|
|
301
|
+
&& args.split(/\s+/u).includes(`${port}:8100`);
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=mobile-ios.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { GuiExecutionLifecycle } from './gui-execution.js';
|
|
4
|
+
export const MOBILE_DESCRIPTOR = Object.freeze({ name: 'mobile', summary: 'Operates the configured phone under user supervision. Every device action needs confirmation. Screenshots go to the configured model service.',
|
|
5
|
+
ownedChannels: Object.freeze(['mobile']) });
|
|
6
|
+
export function loadMobileConfig(env) {
|
|
7
|
+
const values = {
|
|
8
|
+
ENGINE: env.MOBILE_ENGINE,
|
|
9
|
+
DEVICE_TYPE: env.MOBILE_DEVICE_TYPE,
|
|
10
|
+
DEVICE_ID: env.MOBILE_DEVICE_ID,
|
|
11
|
+
BASE_URL: env.MOBILE_BASE_URL,
|
|
12
|
+
WDA_URL: env.MOBILE_WDA_URL,
|
|
13
|
+
MODEL: env.MOBILE_MODEL,
|
|
14
|
+
MODEL_FAMILY: env.MOBILE_MODEL_FAMILY,
|
|
15
|
+
API_KEY: env.MOBILE_API_KEY,
|
|
16
|
+
MAX_STEPS: env.MOBILE_MAX_STEPS,
|
|
17
|
+
TIMEOUT_SECONDS: env.MOBILE_TIMEOUT_SECONDS,
|
|
18
|
+
SETTLE_MS: env.MOBILE_SETTLE_MS,
|
|
19
|
+
};
|
|
20
|
+
const required = (name, fallback, max = 4096) => {
|
|
21
|
+
const value = (values[name] ?? fallback)?.trim();
|
|
22
|
+
if (!value || value.length > max || /[\x00-\x1f]/u.test(value))
|
|
23
|
+
throw new Error(`invalid_mobile_configuration:${name}`);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
const integer = (name, fallback, max, min = 1) => {
|
|
27
|
+
const value = Number(values[name] ?? fallback);
|
|
28
|
+
if (!Number.isSafeInteger(value) || value < min || value > max)
|
|
29
|
+
throw new Error(`invalid_mobile_configuration:${name}`);
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
if (required('ENGINE', 'midscene') !== 'midscene')
|
|
33
|
+
throw new Error('invalid_mobile_engine');
|
|
34
|
+
const deviceType = required('DEVICE_TYPE', 'ios-simulator');
|
|
35
|
+
if (deviceType !== 'ios' && deviceType !== 'ios-simulator' && deviceType !== 'android')
|
|
36
|
+
throw new Error('invalid_mobile_device_type');
|
|
37
|
+
const deviceId = required('DEVICE_ID', undefined, 128);
|
|
38
|
+
if (!/^[A-Za-z0-9_.:\-]+$/u.test(deviceId))
|
|
39
|
+
throw new Error('invalid_mobile_device');
|
|
40
|
+
const baseUrl = required('BASE_URL', undefined, 2048);
|
|
41
|
+
const wdaUrl = required('WDA_URL', 'http://127.0.0.1:8100', 2048);
|
|
42
|
+
for (const value of [baseUrl, wdaUrl]) {
|
|
43
|
+
const url = new URL(value);
|
|
44
|
+
const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
45
|
+
if (url.username || url.password || url.hash || url.search || (url.protocol !== 'https:' && !(url.protocol === 'http:' && local)))
|
|
46
|
+
throw new Error('invalid_mobile_endpoint');
|
|
47
|
+
if (value === wdaUrl && deviceType === 'ios-simulator' && (!local || url.protocol !== 'http:' || url.pathname !== '/'))
|
|
48
|
+
throw new Error('invalid_mobile_wda_endpoint');
|
|
49
|
+
}
|
|
50
|
+
return { deviceId, deviceType, wdaUrl, baseUrl, model: required('MODEL', undefined, 200),
|
|
51
|
+
modelFamily: required('MODEL_FAMILY', undefined, 200), apiKey: required('API_KEY'),
|
|
52
|
+
maxSteps: integer('MAX_STEPS', 30, 100), budgetMs: integer('TIMEOUT_SECONDS', 600, 1800) * 1000,
|
|
53
|
+
settleMs: integer('SETTLE_MS', 4000, 30000, 0),
|
|
54
|
+
// Share the existing phone quarantine across engines; changing engines must not bypass ownership.
|
|
55
|
+
lockRoot: join(homedir(), '.nova-audio-agent', 'autoglm-devices') };
|
|
56
|
+
}
|
|
57
|
+
export class MobileExecutor {
|
|
58
|
+
config;
|
|
59
|
+
approvals;
|
|
60
|
+
runner;
|
|
61
|
+
#execution;
|
|
62
|
+
constructor(config, approvals, runner = async (...args) => (await import('./mobile-ios.js')).runMobileIos(...args)) {
|
|
63
|
+
this.config = config;
|
|
64
|
+
this.approvals = approvals;
|
|
65
|
+
this.runner = runner;
|
|
66
|
+
this.#execution = new GuiExecutionLifecycle(config, approvals, (budgetMs, instruction, options) => runner({ ...config, budgetMs }, instruction, options), { descriptor: MOBILE_DESCRIPTOR, displayName: '手机助手', project: config.deviceType === 'android' ? 'Android' : 'iOS', title: '手机任务' });
|
|
67
|
+
}
|
|
68
|
+
get descriptor() { return this.#execution.descriptor; }
|
|
69
|
+
get manifest() { return this.#execution.manifest; }
|
|
70
|
+
controller(port) { return this.#execution.controller(port); }
|
|
71
|
+
admitRequest(op, request) { return this.#execution.admitRequest(op, request); }
|
|
72
|
+
dispatch(op, request, context) {
|
|
73
|
+
return this.#execution.dispatch(op, request, context);
|
|
74
|
+
}
|
|
75
|
+
cancelWork(workId) { this.#execution.cancelWork(workId); }
|
|
76
|
+
close() { return this.#execution.close(); }
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=mobile.js.map
|