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,376 @@
|
|
|
1
|
+
/** Optional, supervised phone executor. Device identity and credentials stay host-owned. */
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { access, mkdir, realpath } from 'node:fs/promises';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { isAbsolute, join } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { executorManifestSchema } from '../core/ports.js';
|
|
11
|
+
import { acquireDeviceLock, quarantineDeviceLock, recordDeviceProcess, releaseDeviceLock } from './device-lock.js';
|
|
12
|
+
const instructionSchema = z.string().trim().min(1).max(4000);
|
|
13
|
+
const requestSchema = z.object({ instruction: instructionSchema, run_id: z.string().uuid() }).strict();
|
|
14
|
+
const identifier = z.string().min(1).max(128);
|
|
15
|
+
const actionNames = ['Launch', 'Tap', 'Type', 'Type_Name', 'Swipe', 'Back', 'Home', 'Double Tap', 'Long Press'];
|
|
16
|
+
const terminalCodes = ['model_finished', 'model_failed', 'action_failed', 'step_limit', 'timeout', 'declined',
|
|
17
|
+
'screen_changed', 'needs_user_action', 'invalid_configuration', 'protocol_error'];
|
|
18
|
+
const envelope = { version: z.literal(1), taskId: identifier };
|
|
19
|
+
const messageSchema = z.discriminatedUnion('type', [
|
|
20
|
+
z.object({ ...envelope, type: z.literal('ready'), upstreamCommit: z.string().regex(/^[a-f0-9]{40}$/u) }).strict(),
|
|
21
|
+
z.object({ ...envelope, type: z.literal('progress'), step: z.number().int().nonnegative(),
|
|
22
|
+
phase: z.enum(['model', 'action', 'action_returned']), lastAction: z.string().max(40).optional() }).strict(),
|
|
23
|
+
z.object({ ...envelope, type: z.literal('approval'), requestId: identifier, step: z.number().int().positive(),
|
|
24
|
+
action: z.object({ _metadata: z.literal('do'), action: z.enum(actionNames) }).catchall(z.unknown()),
|
|
25
|
+
screenDigest: z.string().regex(/^[a-f0-9]{64}$/u), packageName: z.string().min(1).max(256) }).strict(),
|
|
26
|
+
z.object({ ...envelope, type: z.literal('terminal'), code: z.enum(terminalCodes), steps: z.number().int().nonnegative(),
|
|
27
|
+
message: z.string().max(2048).optional(), lastAction: z.string().max(40).optional() }).strict(),
|
|
28
|
+
]);
|
|
29
|
+
export const AUTOGLM_DESCRIPTOR = Object.freeze({ name: 'autoglm',
|
|
30
|
+
summary: 'Operates the configured phone (iOS by default) under user supervision. Every device action needs confirmation. Screenshots go to the configured model service.',
|
|
31
|
+
ownedChannels: Object.freeze(['autoglm']) });
|
|
32
|
+
/** Called only when `autoglm` is explicitly selected; no automatic install or device selection. */
|
|
33
|
+
export function loadAutoGlmConfig(env) {
|
|
34
|
+
const required = (key, limit = 4096) => {
|
|
35
|
+
const value = env[key]?.trim();
|
|
36
|
+
if (!value || value.length > limit || /[\x00-\x1f]/u.test(value))
|
|
37
|
+
throw new Error(`invalid_autoglm_configuration:${key}`);
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
const integer = (key, fallback, max) => {
|
|
41
|
+
const value = env[key] === undefined ? fallback : Number(env[key]);
|
|
42
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > max)
|
|
43
|
+
throw new Error(`invalid_autoglm_configuration:${key}`);
|
|
44
|
+
return value;
|
|
45
|
+
};
|
|
46
|
+
const python = required('AUTOGLM_PYTHON');
|
|
47
|
+
const sourcePath = required('AUTOGLM_SOURCE_PATH');
|
|
48
|
+
if (!isAbsolute(python) || !isAbsolute(sourcePath))
|
|
49
|
+
throw new Error('invalid_autoglm_paths');
|
|
50
|
+
const baseUrl = required('AUTOGLM_BASE_URL', 2048);
|
|
51
|
+
const url = new URL(baseUrl);
|
|
52
|
+
if (url.username || url.password || url.hash || url.search || (url.protocol !== 'https:'
|
|
53
|
+
&& !(url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))))
|
|
54
|
+
throw new Error('invalid_autoglm_endpoint');
|
|
55
|
+
const deviceType = env.AUTOGLM_DEVICE_TYPE ?? 'ios';
|
|
56
|
+
if (deviceType !== 'ios' && deviceType !== 'ios-simulator' && deviceType !== 'android')
|
|
57
|
+
throw new Error('invalid_autoglm_device_type');
|
|
58
|
+
const wdaUrl = deviceType !== 'android' ? (env.AUTOGLM_WDA_URL ?? 'http://127.0.0.1:8100') : undefined;
|
|
59
|
+
if (wdaUrl !== undefined) {
|
|
60
|
+
const wda = new URL(wdaUrl);
|
|
61
|
+
if (deviceType === 'ios-simulator' && (wda.protocol !== 'http:' || !['localhost', '127.0.0.1', '[::1]'].includes(wda.hostname) || wda.pathname !== '/'))
|
|
62
|
+
throw new Error('invalid_autoglm_wda_endpoint');
|
|
63
|
+
if (wda.username || wda.password || wda.hash || wda.search || (wda.protocol !== 'https:'
|
|
64
|
+
&& !(wda.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(wda.hostname))))
|
|
65
|
+
throw new Error('invalid_autoglm_wda_endpoint');
|
|
66
|
+
}
|
|
67
|
+
const deviceId = required('AUTOGLM_DEVICE_ID');
|
|
68
|
+
if (deviceId.length > 128 || !/^[A-Za-z0-9_.:\-]+$/u.test(deviceId))
|
|
69
|
+
throw new Error('invalid_autoglm_device');
|
|
70
|
+
return { python, sourcePath, deviceId, deviceType, ...(wdaUrl === undefined ? {} : { wdaUrl }), baseUrl, model: required('AUTOGLM_MODEL', 200),
|
|
71
|
+
apiKey: required('AUTOGLM_API_KEY'),
|
|
72
|
+
maxSteps: integer('AUTOGLM_MAX_STEPS', 30, 100),
|
|
73
|
+
budgetMs: integer('AUTOGLM_TIMEOUT_SECONDS', 600, 1800) * 1000,
|
|
74
|
+
lockRoot: join(homedir(), '.nova-audio-agent', 'autoglm-devices') };
|
|
75
|
+
}
|
|
76
|
+
function handoff(code, outcome, extra = {}) {
|
|
77
|
+
return { outcome, trust: 'untrusted_external', content: { code, verified: false, effects: 'unknown', ...extra } };
|
|
78
|
+
}
|
|
79
|
+
export class AutoGlmExecutor {
|
|
80
|
+
config;
|
|
81
|
+
approvals;
|
|
82
|
+
bridgePath;
|
|
83
|
+
descriptor = AUTOGLM_DESCRIPTOR;
|
|
84
|
+
manifest;
|
|
85
|
+
#reservation = null;
|
|
86
|
+
#active = null;
|
|
87
|
+
#closed = false;
|
|
88
|
+
constructor(config, approvals, bridgePath = fileURLToPath(new URL('../../../scripts/autoglm-bridge.py', import.meta.url))
|
|
89
|
+
.replace(/([/\\])app\.asar([/\\])/u, '$1app.asar.unpacked$2')) {
|
|
90
|
+
this.config = config;
|
|
91
|
+
this.approvals = approvals;
|
|
92
|
+
this.bridgePath = bridgePath;
|
|
93
|
+
this.manifest = executorManifestSchema.parse({ name: 'autoglm', display_name: 'AutoGLM', roles: [], approvals: true,
|
|
94
|
+
model_visibility: 'hidden', probe_policy: 'none', ops: [{ name: 'run', description: 'Run a supervised phone task.',
|
|
95
|
+
params: { type: 'object', properties: { instruction: { type: 'string', minLength: 1, maxLength: 4000 }, run_id: { type: 'string' } },
|
|
96
|
+
required: ['instruction', 'run_id'], additionalProperties: false }, readonly: false, confirm: false,
|
|
97
|
+
deadline_budget: config.budgetMs / 1000 + 5, verifies: [], sensitive_params: ['instruction'], sync_result: false }],
|
|
98
|
+
policy: { channel: 'autoglm', priority: 50, wake: 'surrogate', typical_latency: 10, compress_watermark: 8000, progress_via_surrogate: true } });
|
|
99
|
+
}
|
|
100
|
+
controller(port) {
|
|
101
|
+
let delegateId = null;
|
|
102
|
+
return { descriptor: AUTOGLM_DESCRIPTOR, dispatch: async (request) => {
|
|
103
|
+
if (!request.stillWanted())
|
|
104
|
+
return { code: 'superseded', accepted: false, detail: {} };
|
|
105
|
+
if (this.#closed)
|
|
106
|
+
return { code: 'runtime_rejected', accepted: false, detail: {} };
|
|
107
|
+
if (this.#reservation !== null)
|
|
108
|
+
return { code: 'busy', accepted: true, detail: {} };
|
|
109
|
+
const instruction = instructionSchema.safeParse(request.instruction);
|
|
110
|
+
if (!instruction.success)
|
|
111
|
+
return { code: 'clarification_required', accepted: true, detail: {} };
|
|
112
|
+
const runId = randomUUID();
|
|
113
|
+
this.#reservation = runId;
|
|
114
|
+
try {
|
|
115
|
+
const admission = await port.dispatch({ channel: 'autoglm', op: 'run',
|
|
116
|
+
request: { instruction: instruction.data, run_id: runId }, origin_ref: request.origin_ref,
|
|
117
|
+
stillWanted: () => {
|
|
118
|
+
const wanted = this.#reservation === runId && !this.#closed && request.stillWanted();
|
|
119
|
+
if (!wanted && this.#reservation === runId && this.#active === null)
|
|
120
|
+
this.#reservation = null;
|
|
121
|
+
return wanted;
|
|
122
|
+
} });
|
|
123
|
+
if (!admission.accepted || admission.delegate_id === null) {
|
|
124
|
+
if (this.#reservation === runId)
|
|
125
|
+
this.#reservation = null;
|
|
126
|
+
return { code: 'runtime_rejected', accepted: false, detail: {} };
|
|
127
|
+
}
|
|
128
|
+
delegateId = admission.delegate_id;
|
|
129
|
+
return { code: 'delegated', accepted: true, delegate_id: delegateId, detail: { channel: 'autoglm', op: 'run' } };
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
if (this.#reservation === runId)
|
|
133
|
+
this.#reservation = null;
|
|
134
|
+
return { code: 'runtime_rejected', accepted: false, detail: {} };
|
|
135
|
+
}
|
|
136
|
+
}, cancel: async (request) => {
|
|
137
|
+
if (!request.stillWanted())
|
|
138
|
+
return { code: 'superseded', accepted: false, detail: {} };
|
|
139
|
+
if (this.#reservation === null)
|
|
140
|
+
return { code: 'not_running', accepted: true, detail: {} };
|
|
141
|
+
if (delegateId !== null)
|
|
142
|
+
port.cancelPendingDispatch?.(delegateId);
|
|
143
|
+
this.#active?.abort.abort();
|
|
144
|
+
await this.#active?.done;
|
|
145
|
+
if (this.#active === null)
|
|
146
|
+
this.#reservation = null;
|
|
147
|
+
delegateId = null;
|
|
148
|
+
return { code: 'accepted', accepted: true, detail: {} };
|
|
149
|
+
} };
|
|
150
|
+
}
|
|
151
|
+
admitRequest(op, request) {
|
|
152
|
+
const parsed = requestSchema.safeParse(request);
|
|
153
|
+
return op === 'run' && parsed.success && parsed.data.run_id === this.#reservation && !this.#closed
|
|
154
|
+
? { ok: true, request: parsed.data, sync_result: false } : { ok: false };
|
|
155
|
+
}
|
|
156
|
+
async dispatch(op, request, context) {
|
|
157
|
+
const admission = this.admitRequest(op, request);
|
|
158
|
+
if (!admission.ok || this.#active !== null)
|
|
159
|
+
return handoff('invalid_request', 'refused');
|
|
160
|
+
const abort = new AbortController();
|
|
161
|
+
const abortFromRuntime = () => abort.abort();
|
|
162
|
+
context.signal.addEventListener('abort', abortFromRuntime, { once: true });
|
|
163
|
+
if (context.signal.aborted)
|
|
164
|
+
abort.abort();
|
|
165
|
+
const done = this.#run(admission.request.instruction, admission.request.run_id, context, abort.signal)
|
|
166
|
+
.catch(() => handoff('bridge_failed', 'unknown'));
|
|
167
|
+
this.#active = { abort, done };
|
|
168
|
+
try {
|
|
169
|
+
return await done;
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
context.signal.removeEventListener('abort', abortFromRuntime);
|
|
173
|
+
this.#active = null;
|
|
174
|
+
this.#reservation = null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async close() {
|
|
178
|
+
this.#closed = true;
|
|
179
|
+
this.#active?.abort.abort();
|
|
180
|
+
await this.#active?.done;
|
|
181
|
+
this.#reservation = null;
|
|
182
|
+
}
|
|
183
|
+
async #run(instruction, taskId, context, cancelled) {
|
|
184
|
+
if (process.platform === 'win32')
|
|
185
|
+
return handoff('unsupported_host', 'refused');
|
|
186
|
+
if (cancelled.aborted)
|
|
187
|
+
return handoff('cancelled', 'cancelled');
|
|
188
|
+
const { config } = this;
|
|
189
|
+
const budgetMs = Math.min(config.budgetMs, Math.max(0, ((context.delegate.deadline ?? Infinity) - context.clock.now()) * 1000));
|
|
190
|
+
if (budgetMs <= 0)
|
|
191
|
+
return handoff('timeout', 'unknown');
|
|
192
|
+
const deadlineSignal = AbortSignal.timeout(Math.floor(budgetMs));
|
|
193
|
+
const processStop = new AbortController();
|
|
194
|
+
const signal = AbortSignal.any([cancelled, deadlineSignal, processStop.signal]);
|
|
195
|
+
// Keep the venv executable path: resolving its symlink launches the base interpreter.
|
|
196
|
+
await access(config.python);
|
|
197
|
+
const python = config.python;
|
|
198
|
+
const sourcePath = await realpath(config.sourcePath);
|
|
199
|
+
await access(this.bridgePath);
|
|
200
|
+
await mkdir(config.lockRoot, { recursive: true, mode: 0o700 });
|
|
201
|
+
const acquired = await acquireDeviceLock(config.lockRoot, config.deviceType, config.deviceId, taskId);
|
|
202
|
+
if (!acquired.ok)
|
|
203
|
+
return handoff(acquired.reason, 'refused');
|
|
204
|
+
// ponytail: crash leaves a quarantine directory; manual recovery after checking the device/processes.
|
|
205
|
+
let treeGone = true;
|
|
206
|
+
const approval = this.approvals.forWork({ work_id: taskId, project: config.deviceType === 'android' ? 'Android' : 'iOS', title: 'AutoGLM 手机任务' });
|
|
207
|
+
let result = handoff('bridge_eof', 'unknown');
|
|
208
|
+
const observation = {};
|
|
209
|
+
// An approved write the bridge started but never acknowledged has an unconfirmed device effect.
|
|
210
|
+
const flight = { write: false };
|
|
211
|
+
try {
|
|
212
|
+
if (signal.aborted)
|
|
213
|
+
return handoff(cancelled.aborted ? 'cancelled' : 'timeout', cancelled.aborted ? 'cancelled' : 'unknown');
|
|
214
|
+
const child = spawn(python, [this.bridgePath], { shell: false, detached: true, stdio: ['pipe', 'pipe', 'pipe'],
|
|
215
|
+
env: { PATH: process.env.PATH ?? '/usr/bin:/bin', HOME: homedir(), LANG: 'en_US.UTF-8', PYTHONUNBUFFERED: '1',
|
|
216
|
+
...(config.deviceType === 'ios-simulator' && process.env.DEVELOPER_DIR ? { DEVELOPER_DIR: process.env.DEVELOPER_DIR } : {}),
|
|
217
|
+
PYTHONDONTWRITEBYTECODE: '1', AUTOGLM_API_KEY: config.apiKey, AUTOGLM_SOURCE_PATH: sourcePath } });
|
|
218
|
+
treeGone = child.pid === undefined;
|
|
219
|
+
if (child.pid !== undefined)
|
|
220
|
+
await recordDeviceProcess(acquired.lock, child.pid).catch(() => undefined);
|
|
221
|
+
let waitingForApproval = false, exited = false;
|
|
222
|
+
child.once('exit', () => {
|
|
223
|
+
exited = true;
|
|
224
|
+
if (waitingForApproval)
|
|
225
|
+
processStop.abort();
|
|
226
|
+
});
|
|
227
|
+
child.once('error', () => { exited = true; processStop.abort(); });
|
|
228
|
+
const exit = new Promise(resolve => { child.once('close', () => resolve()); child.once('error', () => resolve()); });
|
|
229
|
+
child.stdin.on('error', () => { child.stdout.destroy(new Error('bridge_input_failed')); });
|
|
230
|
+
child.stderr.on('data', () => { });
|
|
231
|
+
const terminate = () => {
|
|
232
|
+
approval.invalidate('autoglm_stopped');
|
|
233
|
+
if (child.pid !== undefined)
|
|
234
|
+
try {
|
|
235
|
+
process.kill(-child.pid, 'SIGTERM');
|
|
236
|
+
}
|
|
237
|
+
catch { /* already gone */ }
|
|
238
|
+
child.stdout.destroy(new Error('bridge_stopped'));
|
|
239
|
+
};
|
|
240
|
+
signal.addEventListener('abort', terminate, { once: true });
|
|
241
|
+
try {
|
|
242
|
+
if (signal.aborted)
|
|
243
|
+
terminate();
|
|
244
|
+
else {
|
|
245
|
+
child.stdin.write(`${JSON.stringify({ version: 1, type: 'start', taskId, instruction, deviceId: config.deviceId,
|
|
246
|
+
deviceType: config.deviceType, ...(config.wdaUrl === undefined ? {} : { wdaUrl: config.wdaUrl }),
|
|
247
|
+
maxSteps: config.maxSteps, budgetMs: Math.floor(budgetMs), baseUrl: config.baseUrl, model: config.model })}\n`);
|
|
248
|
+
result = await this.#read(child.stdout, async (value) => {
|
|
249
|
+
await new Promise((resolve, reject) => child.stdin.write(`${JSON.stringify(value)}\n`, error => error ? reject(error) : resolve()));
|
|
250
|
+
}, taskId, context, signal, approval, observation, flight, waiting => {
|
|
251
|
+
waitingForApproval = waiting;
|
|
252
|
+
if (waiting && exited)
|
|
253
|
+
processStop.abort();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
result = handoff('bridge_protocol_failed', 'unknown');
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
signal.removeEventListener('abort', terminate);
|
|
262
|
+
terminate();
|
|
263
|
+
await Promise.race([exit, delay(250)]);
|
|
264
|
+
if (child.pid !== undefined) {
|
|
265
|
+
try {
|
|
266
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
267
|
+
}
|
|
268
|
+
catch { /* already gone */ }
|
|
269
|
+
for (let retry = 0; retry < 20; retry += 1) {
|
|
270
|
+
try {
|
|
271
|
+
process.kill(-child.pid, 0);
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
if (error.code === 'ESRCH')
|
|
275
|
+
treeGone = true;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
await delay(25);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
child.stdin.destroy();
|
|
282
|
+
child.stdout.destroy();
|
|
283
|
+
child.stderr.destroy();
|
|
284
|
+
}
|
|
285
|
+
if (!treeGone || flight.write) {
|
|
286
|
+
const unknown = handoff('cleanup_unknown', 'unknown', observation);
|
|
287
|
+
return { ...unknown, content: { ...unknown.content, cleanup_required: true, ...(cancelled.aborted ? { cancel_requested: true } : {}) } };
|
|
288
|
+
}
|
|
289
|
+
if (cancelled.aborted)
|
|
290
|
+
return handoff('cancelled', 'cancelled', observation);
|
|
291
|
+
if (deadlineSignal.aborted)
|
|
292
|
+
return handoff('timeout', 'unknown', observation);
|
|
293
|
+
return { ...result, content: { ...result.content, ...observation } };
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
approval.invalidate('autoglm_finished');
|
|
297
|
+
if (treeGone && !flight.write)
|
|
298
|
+
await releaseDeviceLock(acquired.lock);
|
|
299
|
+
else
|
|
300
|
+
await quarantineDeviceLock(acquired.lock, 'cleanup_unknown');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async #read(output, send, taskId, context, signal, approval, observation, flight, waiting) {
|
|
304
|
+
let buffer = Buffer.alloc(0), total = 0, ready = false, step = 0;
|
|
305
|
+
const seen = new Set();
|
|
306
|
+
for await (const chunk of output) {
|
|
307
|
+
total += chunk.length;
|
|
308
|
+
if (total > 1024 * 1024)
|
|
309
|
+
throw new Error('protocol_limit');
|
|
310
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
311
|
+
let end;
|
|
312
|
+
while ((end = buffer.indexOf(10)) !== -1) {
|
|
313
|
+
if (end > 65536 || signal.aborted)
|
|
314
|
+
throw new Error('protocol_limit');
|
|
315
|
+
const line = new TextDecoder('utf-8', { fatal: true }).decode(buffer.subarray(0, end));
|
|
316
|
+
buffer = buffer.subarray(end + 1);
|
|
317
|
+
const message = messageSchema.parse(JSON.parse(line));
|
|
318
|
+
if (message.taskId !== taskId)
|
|
319
|
+
throw new Error('wrong_task');
|
|
320
|
+
if (message.type === 'ready') {
|
|
321
|
+
if (ready)
|
|
322
|
+
throw new Error('duplicate_ready');
|
|
323
|
+
ready = true;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
// Startup refusals may precede readiness; never accept a successful unready terminal.
|
|
327
|
+
if (!ready && !(message.type === 'terminal' && message.code === 'invalid_configuration'))
|
|
328
|
+
throw new Error('not_ready');
|
|
329
|
+
if (message.type === 'terminal') {
|
|
330
|
+
const outcome = message.code === 'model_finished' ? 'ok' : message.code === 'timeout' ? 'unknown'
|
|
331
|
+
: ['declined', 'needs_user_action', 'invalid_configuration', 'screen_changed'].includes(message.code) ? 'refused' : 'failed';
|
|
332
|
+
return handoff(message.code, outcome, { steps: message.steps,
|
|
333
|
+
...(message.message === undefined ? {} : { message: message.message.replace(/[\x00-\x1f\x7f]/gu, ' ').slice(0, 2048) }),
|
|
334
|
+
...(message.lastAction === undefined ? {} : { last_action: message.lastAction }) });
|
|
335
|
+
}
|
|
336
|
+
if (message.step < step || message.step > this.config.maxSteps)
|
|
337
|
+
throw new Error('invalid_step');
|
|
338
|
+
step = message.step;
|
|
339
|
+
if (message.type === 'progress') {
|
|
340
|
+
if (message.phase === 'action')
|
|
341
|
+
flight.write = true;
|
|
342
|
+
if (message.phase === 'action_returned') {
|
|
343
|
+
flight.write = false;
|
|
344
|
+
observation.last_returned_step = step;
|
|
345
|
+
if (message.lastAction !== undefined)
|
|
346
|
+
observation.last_action = message.lastAction;
|
|
347
|
+
}
|
|
348
|
+
context.progress({ phase: 'working', internal_activity: step, elapsed: Math.max(0, context.clock.now() - context.delegate.dispatched_at), summary: null });
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (seen.has(message.requestId))
|
|
352
|
+
throw new Error('duplicate_approval');
|
|
353
|
+
seen.add(message.requestId);
|
|
354
|
+
const scope = `${message.packageName}: ${JSON.stringify(message.action)}`;
|
|
355
|
+
if (scope.length > 1024)
|
|
356
|
+
return handoff('approval_too_large', 'refused');
|
|
357
|
+
waiting(true);
|
|
358
|
+
const resolution = await approval.offer({ kind: 'permissions', local_detail: { kind: 'permissions', scope },
|
|
359
|
+
operation_summary: `AutoGLM 手机操作:${message.action.action}`,
|
|
360
|
+
allowed_decisions: ['accept', 'decline'], executorIdentity: { executor: 'autoglm', display_name: 'AutoGLM' } }, signal);
|
|
361
|
+
waiting(false);
|
|
362
|
+
if (signal.aborted)
|
|
363
|
+
throw new Error('stopped');
|
|
364
|
+
const decision = resolution === null ? 'decline' : approval.consume(resolution);
|
|
365
|
+
if (signal.aborted)
|
|
366
|
+
throw new Error('stopped');
|
|
367
|
+
await send({ version: 1, type: 'decision', taskId, requestId: message.requestId,
|
|
368
|
+
decision: decision === 'accept' ? 'accept' : 'decline' });
|
|
369
|
+
}
|
|
370
|
+
if (buffer.length > 65536)
|
|
371
|
+
throw new Error('protocol_limit');
|
|
372
|
+
}
|
|
373
|
+
return handoff('bridge_eof', 'unknown');
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
//# sourceMappingURL=autoglm.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** Managed Playwright page: screenshot and coordinates only; never DOM selectors or user profiles. */
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { actionTapParamSchema, actionScrollParamSchema, actionKeyboardPressParamSchema } from '@midscene/core/device';
|
|
4
|
+
import { z } from '@midscene/core';
|
|
5
|
+
import { chromium, firefox, webkit } from 'playwright';
|
|
6
|
+
export function validBrowserUrl(value) {
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(value);
|
|
9
|
+
return !url.username && !url.password
|
|
10
|
+
&& (url.protocol === 'https:' || (url.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname)));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function createBrowserDevice(options) {
|
|
17
|
+
const type = { chromium, firefox, webkit }[options.engine];
|
|
18
|
+
let server;
|
|
19
|
+
const close = async () => {
|
|
20
|
+
if (!server)
|
|
21
|
+
return true;
|
|
22
|
+
const child = server.process();
|
|
23
|
+
let timer;
|
|
24
|
+
try {
|
|
25
|
+
const exit = new Promise(resolve => { if (child.exitCode !== null || child.signalCode !== null)
|
|
26
|
+
resolve();
|
|
27
|
+
else
|
|
28
|
+
child.once('exit', () => resolve()); });
|
|
29
|
+
await Promise.race([server.close().catch(() => undefined), new Promise(resolve => { timer = setTimeout(resolve, 2000); })]);
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
32
|
+
void server.kill().catch(() => undefined);
|
|
33
|
+
await Promise.race([exit, new Promise(resolve => { timer = setTimeout(resolve, 2000); })]);
|
|
34
|
+
return child.exitCode !== null || child.signalCode !== null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
try {
|
|
44
|
+
options.signal.throwIfAborted();
|
|
45
|
+
server = await type.launchServer({ headless: options.headless, host: '127.0.0.1', timeout: 30_000 });
|
|
46
|
+
const pid = server.process().pid;
|
|
47
|
+
if (!pid)
|
|
48
|
+
throw Error('invalid_configuration');
|
|
49
|
+
await options.recordProcess?.(pid);
|
|
50
|
+
options.signal.throwIfAborted();
|
|
51
|
+
const browser = await type.connect(server.wsEndpoint(), { timeout: 30_000 });
|
|
52
|
+
options.signal.throwIfAborted();
|
|
53
|
+
const context = await browser.newContext({ viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1 });
|
|
54
|
+
options.signal.throwIfAborted();
|
|
55
|
+
const page = await context.newPage();
|
|
56
|
+
options.signal.throwIfAborted();
|
|
57
|
+
page.setDefaultTimeout(30_000);
|
|
58
|
+
page.setDefaultNavigationTimeout(30_000);
|
|
59
|
+
let popup = false;
|
|
60
|
+
context.on('page', opened => { if (opened !== page)
|
|
61
|
+
popup = true; });
|
|
62
|
+
options.signal.throwIfAborted();
|
|
63
|
+
options.beforeWrite?.();
|
|
64
|
+
await page.goto(options.url, { waitUntil: 'domcontentloaded' });
|
|
65
|
+
const id = randomUUID();
|
|
66
|
+
const target = () => {
|
|
67
|
+
options.signal.throwIfAborted();
|
|
68
|
+
const viewport = page.viewportSize();
|
|
69
|
+
if (page.isClosed() || !browser.isConnected() || popup || !viewport || !validBrowserUrl(page.url()))
|
|
70
|
+
throw Error('screen_changed');
|
|
71
|
+
return Promise.resolve({ displayId: id, ...viewport, target: JSON.stringify([id, page.url(), viewport]) });
|
|
72
|
+
};
|
|
73
|
+
const check = async () => { await target(); };
|
|
74
|
+
const device = { interfaceType: 'browser', size: async () => { const { width, height } = await target(); return { width, height }; },
|
|
75
|
+
screenshotBase64: async () => { await check(); const bytes = await page.screenshot({ type: 'png', timeout: 30_000 }); await check(); return `data:image/png;base64,${bytes.toString('base64')}`; },
|
|
76
|
+
actionSpace: () => [
|
|
77
|
+
{ name: 'Tap', description: 'Click the point once.', paramSchema: actionTapParamSchema, call: async (params) => {
|
|
78
|
+
await check();
|
|
79
|
+
const { locate } = params;
|
|
80
|
+
await page.mouse.click(...locate.center);
|
|
81
|
+
} },
|
|
82
|
+
{ name: 'Input', description: 'Append text to the focused field; Tap it first.', paramSchema: z.object({ value: z.string().min(1).max(4000) }).strict(),
|
|
83
|
+
call: async (params) => { await check(); await page.keyboard.insertText(params.value); } },
|
|
84
|
+
{ name: 'KeyboardPress', description: 'Press a key in the current focus. Use Meta for macOS shortcuts.', paramSchema: actionKeyboardPressParamSchema,
|
|
85
|
+
call: async (params) => { await check(); await page.keyboard.press(params.keyName.replace(/\b(?:Command|CMD)\b/gu, 'Meta')); } },
|
|
86
|
+
{ name: 'Scroll', description: 'Scroll once by a bounded pixel distance.', paramSchema: actionScrollParamSchema,
|
|
87
|
+
call: async (params) => {
|
|
88
|
+
await check();
|
|
89
|
+
const { direction = 'down', distance = 400, locate } = params;
|
|
90
|
+
await page.mouse.move(...(locate?.center ?? [640, 400]));
|
|
91
|
+
await page.mouse.wheel(direction === 'left' ? -distance : direction === 'right' ? distance : 0, direction === 'up' ? -distance : direction === 'down' ? distance : 0);
|
|
92
|
+
} }
|
|
93
|
+
] };
|
|
94
|
+
return { device, target, id, close };
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!await close())
|
|
98
|
+
throw Error('cleanup_unknown');
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=browser-device.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { GuiExecutionLifecycle } from './gui-execution.js';
|
|
5
|
+
import { runGui, validGuiConfig } from './gui-runner.js';
|
|
6
|
+
import { guardComputerDevice, guiApproval } from './computer-device.js';
|
|
7
|
+
import { createBrowserDevice, validBrowserUrl } from './browser-device.js';
|
|
8
|
+
export const BROWSER_DESCRIPTOR = Object.freeze({ name: 'browser', summary: 'Uses a dedicated browser page with screenshot planning and Playwright coordinates. Explicit target URL, approvals and independent verification required.', ownedChannels: Object.freeze(['browser']) });
|
|
9
|
+
export function loadBrowserConfig(env) {
|
|
10
|
+
const engine = env.BROWSER_ENGINE ?? 'chromium';
|
|
11
|
+
const config = { engine, url: env.BROWSER_URL ?? '', headless: env.BROWSER_HEADLESS !== 'false',
|
|
12
|
+
baseUrl: env.BROWSER_BASE_URL ?? '', model: env.BROWSER_MODEL ?? '', modelFamily: env.BROWSER_MODEL_FAMILY ?? '', apiKey: env.BROWSER_API_KEY ?? '',
|
|
13
|
+
maxSteps: Number(env.BROWSER_MAX_STEPS ?? 30), budgetMs: Number(env.BROWSER_TIMEOUT_SECONDS ?? 600) * 1000,
|
|
14
|
+
settleMs: Number(env.BROWSER_SETTLE_MS ?? 1000), lockRoot: join(homedir(), '.nova-audio-agent', 'gui-devices') };
|
|
15
|
+
if (!['chromium', 'firefox', 'webkit'].includes(engine) || !validBrowserUrl(config.url) || !validGuiConfig(config, 'validate')
|
|
16
|
+
|| (env.BROWSER_HEADLESS !== undefined && !['true', 'false'].includes(env.BROWSER_HEADLESS)))
|
|
17
|
+
throw Error('invalid_browser_configuration');
|
|
18
|
+
return config;
|
|
19
|
+
}
|
|
20
|
+
export async function runBrowser(config, instruction, options) {
|
|
21
|
+
const result = { code: 'invalid_configuration', steps: 0 };
|
|
22
|
+
if (!validGuiConfig(config, instruction) || !validBrowserUrl(config.url))
|
|
23
|
+
return result;
|
|
24
|
+
const signal = AbortSignal.any([options.signal, AbortSignal.timeout(config.budgetMs)]);
|
|
25
|
+
let backend;
|
|
26
|
+
let guarded;
|
|
27
|
+
try {
|
|
28
|
+
if (!await guiApproval(options.approve('Navigate', { engine: config.engine, url: config.url }), signal))
|
|
29
|
+
return Object.assign(result, { code: 'declined' });
|
|
30
|
+
backend = await createBrowserDevice({ ...config, signal, ...(options.beforeWrite ? { beforeWrite: options.beforeWrite } : {}), ...(options.recordProcess ? { recordProcess: options.recordProcess } : {}) });
|
|
31
|
+
guarded = await guardComputerDevice(backend.device, backend.target, { ...options, signal, displayId: backend.id,
|
|
32
|
+
maxSteps: config.maxSteps, budgetMs: config.budgetMs, screenshotScrollDistance: config.modelFamily.startsWith('auto-glm'), progress: options.progress });
|
|
33
|
+
const code = await runGui(instruction, guarded.device, { ...config, signal, steps: guarded.steps, planning: guarded.planning,
|
|
34
|
+
progress: options.progress, ...(options.diagnostic ? { diagnostic: options.diagnostic } : {}), ...(options.capture ? { capture: options.capture } : {}), context: 'Operate only this browser page. Tap a field before Input; Input appends to current focus and omits locate. KeyboardPress omits locate. Scroll once with singleAction and a distance no larger than the viewport. Never use shell commands.' });
|
|
35
|
+
return Object.assign(result, { code: guarded.failure() ?? code, steps: guarded.steps() });
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return Object.assign(result, { code: signal.aborted ? options.signal.aborted ? 'cancelled' : 'timeout'
|
|
39
|
+
: error instanceof Error && ['screen_changed', 'cleanup_unknown'].includes(error.message) ? error.message : 'action_failed', steps: guarded?.steps() ?? 0 });
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
if (backend && !await backend.close())
|
|
43
|
+
result.code = 'cleanup_unknown';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class BrowserExecutor {
|
|
47
|
+
config;
|
|
48
|
+
#execution;
|
|
49
|
+
constructor(config, approvals, runner = runBrowser) {
|
|
50
|
+
this.config = config;
|
|
51
|
+
this.#execution = new GuiExecutionLifecycle({ ...config, deviceType: 'browser', deviceId: randomUUID() }, approvals, (budgetMs, instruction, options) => runner({ ...config, budgetMs }, instruction, options), { descriptor: BROWSER_DESCRIPTOR, displayName: '浏览器助手', project: 'Browser', title: '浏览器任务' });
|
|
52
|
+
}
|
|
53
|
+
get descriptor() { return this.#execution.descriptor; }
|
|
54
|
+
get manifest() { return this.#execution.manifest; }
|
|
55
|
+
controller(port) { return this.#execution.controller(port); }
|
|
56
|
+
admitRequest(op, request) { return this.#execution.admitRequest(op, request); }
|
|
57
|
+
dispatch(op, request, context) { return this.#execution.dispatch(op, request, context); }
|
|
58
|
+
cancelWork(workId) { this.#execution.cancelWork(workId); }
|
|
59
|
+
close() { return this.#execution.close(); }
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { handoffPolicySchema } from '../core/memory.js';
|
|
2
|
+
import { executorManifestSchema, opSpecSchema } from '../core/ports.js';
|
|
3
|
+
export const SNAPSHOT = opSpecSchema.parse({
|
|
4
|
+
name: 'snapshot',
|
|
5
|
+
description: '查看当前摄像头画面,返回带观察时间的图片引用',
|
|
6
|
+
params: {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {},
|
|
9
|
+
required: [],
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
},
|
|
12
|
+
readonly: true,
|
|
13
|
+
deadline_budget: 7,
|
|
14
|
+
verifies: ['snapshot'],
|
|
15
|
+
});
|
|
16
|
+
export const CAMERA_POLICY = handoffPolicySchema.parse({
|
|
17
|
+
channel: 'cam',
|
|
18
|
+
priority: 40,
|
|
19
|
+
wake: 'surrogate',
|
|
20
|
+
typical_latency: 0.05,
|
|
21
|
+
compress_watermark: 20,
|
|
22
|
+
});
|
|
23
|
+
export const CAMERA_MANIFEST = executorManifestSchema.parse({
|
|
24
|
+
name: 'cam',
|
|
25
|
+
display_name: 'Camera',
|
|
26
|
+
ops: [SNAPSHOT],
|
|
27
|
+
policy: CAMERA_POLICY,
|
|
28
|
+
});
|
|
29
|
+
/** A credential-free local capture failure. */
|
|
30
|
+
export class CameraError extends Error {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'CameraError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class CamAdapter {
|
|
37
|
+
manifest = CAMERA_MANIFEST;
|
|
38
|
+
#source;
|
|
39
|
+
#store;
|
|
40
|
+
constructor(source, store) {
|
|
41
|
+
this.#source = source;
|
|
42
|
+
this.#store = store;
|
|
43
|
+
}
|
|
44
|
+
async dispatch(op, request, ctx) {
|
|
45
|
+
void ctx;
|
|
46
|
+
if (op !== 'snapshot')
|
|
47
|
+
return failure('failed', 'unknown_op', op);
|
|
48
|
+
if (Object.keys(request).length > 0)
|
|
49
|
+
return failure('failed', 'invalid_params', 'snapshot');
|
|
50
|
+
let frame;
|
|
51
|
+
try {
|
|
52
|
+
frame = await this.#source.snapshot();
|
|
53
|
+
}
|
|
54
|
+
catch (cause) {
|
|
55
|
+
if (cause instanceof CameraError)
|
|
56
|
+
frame = null;
|
|
57
|
+
else
|
|
58
|
+
return failure('unknown', 'adapter_exception', 'snapshot');
|
|
59
|
+
}
|
|
60
|
+
if (frame === null) {
|
|
61
|
+
return {
|
|
62
|
+
outcome: 'unknown',
|
|
63
|
+
trust: 'untrusted_external',
|
|
64
|
+
content: {
|
|
65
|
+
error: 'capture_unavailable',
|
|
66
|
+
op: 'snapshot',
|
|
67
|
+
recheck: 'not_useful_until_capture_recovers',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const entry = this.#store.put(frame.payload, {
|
|
73
|
+
mediaType: frame.media_type,
|
|
74
|
+
width: frame.width,
|
|
75
|
+
height: frame.height,
|
|
76
|
+
capturedAt: frame.captured_at,
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
outcome: 'ok',
|
|
80
|
+
trust: 'untrusted_external',
|
|
81
|
+
content: {
|
|
82
|
+
media_ref: entry.ref,
|
|
83
|
+
digest: entry.digest,
|
|
84
|
+
media_type: entry.media_type,
|
|
85
|
+
width: entry.width,
|
|
86
|
+
height: entry.height,
|
|
87
|
+
captured_at: entry.captured_at,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (cause) {
|
|
92
|
+
if (cause instanceof RangeError)
|
|
93
|
+
return failure('failed', 'media_store_rejected', 'snapshot');
|
|
94
|
+
return failure('unknown', 'adapter_exception', 'snapshot');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function failure(outcome, error, op) {
|
|
99
|
+
return { outcome, trust: 'untrusted_external', content: { error, op } };
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=camera.js.map
|