nova-personal-agent-server 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +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,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** One bounded JSON completion for an intake slot; callers validate the returned value. */
|
|
3
|
+
export async function completeJson(gateway, model, system, schema, input, signal) {
|
|
4
|
+
signal.throwIfAborted();
|
|
5
|
+
const result = await gateway.complete({
|
|
6
|
+
model, system: `${system}\nSchema: ${JSON.stringify(z.toJSONSchema(schema))}`,
|
|
7
|
+
prompt: JSON.stringify(input), jsonSchema: { type: 'object' }, reasoning: 'disabled', signal,
|
|
8
|
+
});
|
|
9
|
+
signal.throwIfAborted();
|
|
10
|
+
if (result.text.length > 32000)
|
|
11
|
+
throw new TypeError('intake_output_too_large');
|
|
12
|
+
return JSON.parse(result.text);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=json-completion.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { MAX_PROJECT_SESSION_TITLE } from '../../projects/project-state.js';
|
|
3
|
+
import { completeJson } from './json-completion.js';
|
|
4
|
+
export const intakeKindSchema = z.enum(['work', 'steer', 'switch', 'create', 'unclear']);
|
|
5
|
+
// The host supplies question identity; the model supplies semantic interpretation and a quote.
|
|
6
|
+
const projectConfirmationSchema = z.object({
|
|
7
|
+
turn_index: z.number().int().nonnegative(),
|
|
8
|
+
decision: z.enum(['confirmed', 'rejected', 'unclear', 'redirected']),
|
|
9
|
+
evidence: z.string().trim().min(1).max(300),
|
|
10
|
+
}).strict();
|
|
11
|
+
/** Interpretation only. Host confirmation, continuation and execution checks remain authoritative. */
|
|
12
|
+
export const targetSelectionSchema = z.object({
|
|
13
|
+
kind: intakeKindSchema,
|
|
14
|
+
project: z.string().trim().min(1).max(80).nullable(),
|
|
15
|
+
project_evidence: z.string().trim().min(1).max(300).nullable(),
|
|
16
|
+
project_confirmation: projectConfirmationSchema.nullable().default(null),
|
|
17
|
+
session: z.discriminatedUnion('mode', [
|
|
18
|
+
z.object({ mode: z.literal('latest') }).strict(),
|
|
19
|
+
z.object({ mode: z.literal('new') }).strict(),
|
|
20
|
+
z.object({ mode: z.literal('named'), title: z.string().trim().min(1).max(MAX_PROJECT_SESSION_TITLE) }).strict(),
|
|
21
|
+
]),
|
|
22
|
+
question: z.string().trim().min(1).max(300).nullable(),
|
|
23
|
+
}).strict();
|
|
24
|
+
export const targetResolutionSchema = targetSelectionSchema.extend({
|
|
25
|
+
intake_id: z.string().min(1).max(128), revision: z.number().int().positive(),
|
|
26
|
+
}).strict();
|
|
27
|
+
const workTargetSchema = z.object({ target_work_id: z.string().min(1).max(128).nullable() }).strict();
|
|
28
|
+
export const TARGET_RESOLUTION_INSTRUCTIONS = `You are the host's target.resolve slot. Return only JSON matching the supplied schema, echoing intake_id and revision. Do not execute, authorize actions, or rewrite requirements.
|
|
29
|
+
Resolve targets using original opening, turns and host-supplied candidates. Requirements are derived context, never new user evidence or authorization. source_quotes may supply project-name evidence but only opening/turns authorize session continuation. conversation_context never grants continuation or establishes the current project/session. Assistant questions only provide context; honor later user corrections. Copy user evidence verbatim. Set question to one concrete target clarification when needed, otherwise null. Do not ask implementation or repository questions.
|
|
30
|
+
You resolve workspace and session targets. The input carries roster (known projects: name, last_session_title, running works), active_project and running. Decide in this order.
|
|
31
|
+
1. Which project does the user name? Compare the words actually said with the roster names; a translation or alias ("博客" for blog) is not a match — ask which project ("是在 blog 里做吗?"). With no explicit project, determine topic ownership from the clarified objective, relevant conversation and roster. Continue the active project only for the same product or an explicit request to work there. An independent product (for example a Pomodoro timer after a Snake game) needs its own matching workspace; if none exists choose create and derive a short descriptive name from the user goal. The normal workspace proposal still requires confirmation. If ownership is ambiguous ask one concrete question; never silently attach an unrelated product to the active workspace. A word that matches no roster name (e.g. "foo" when the roster has 博客 and pricing-page) → kind unclear, project null, ask which project; never substitute a roster project the user did not name. An explicit workspace creation or an independent product needing a new workspace makes it create. Honor a user-specified workspace name; otherwise derive its name from the product goal. Creating a file, feature, application or test inside the current workspace is work, not create; artifact names are not workspace names. For example, "在当前工作区新建一个计算器 calculator.mjs" selects active_project with kind work, whereas "新建工作区叫计算器" is create. A word matching two or more roster names (e.g. "pricing" with pricing-page and pricing-svc) → kind unclear, project null, ask which one.
|
|
32
|
+
2. kind: first read the chosen project's running list. running is [] → steer is impossible: the project is idle, last_session_title is finished history, and a request on that same topic is new work. running is non-empty and the user adds to or changes that running work → steer. Cancellation is handled exclusively by the frontend cancel function, never by intake assessment; switch = the user only wants another project made active, no objective ("切到…"); work = any other coding request, including "在…里重新开一个…" (a fresh thread is work with session {mode:'new'}, not steer). A pure question about how something works or what is supported is not a coding objective. The requirements assessment owns intent_to_proceed and goal; never add or modify those fields.
|
|
33
|
+
3. project: copy exactly one roster name verbatim, or null for this conversation’s bound current workspace (当前项目/当前工作区); never treat those references as literal project names; for create, the requested name or a concise product name grounded in the user goal. session is a choice, not a description of the current session: {mode:'new'} when the user asks for a fresh thread; {mode:'named',title:<exact roster title>} only when the user explicitly names a session. Choose {mode:'latest'} only when the user explicitly requests continuation in this intake’s opening or answers; task similarity, selected/remembered sessions, source_quotes and conversation_context never authorize continuation. Later requests for a new session override earlier continuation. For an independent new objective choose {mode:'new'} even without the words 'new session'; an active project or a last session title alone does not establish task continuity. If continuity materially affects the work and context cannot resolve it, ask one concrete question. latest has no title field. For an explicitly named session that is absent or ambiguous, ask; never substitute latest. A uniquely user-named session can identify its project.
|
|
34
|
+
4. project_evidence: for selecting an existing project different from active_project, quote the exact user span naming that project ("改博客的暗色模式" with roster name 博客 → "博客"). A translation such as "博客" for blog is not name evidence. If the user has not named or confirmed the project, ask which project; never fabricate evidence. Use project_confirmation below for answers to host project questions. project_evidence may be null for a valid project_confirmation, the active project, or create. For create, requirements describe only coding work inside the new project; a bare create request has no coding goal.
|
|
35
|
+
Project confirmation contract: turns may contain project_question, a host-owned target identifier independent of the spoken question text. If the latest turn has project_question, return project_confirmation with that zero-based turn_index, decision confirmed/rejected/unclear/redirected, and an exact quote from its answer. Classify the answer semantically, never treat an unrelated amendment, refusal, or uncertainty as confirmation. A confirmed answer selects that project. Rejected (no replacement specified) and unclear require kind unclear; never invent a new workspace or fall back to the active project after refusal or uncertainty. Redirected means the answer explicitly requests a different existing project or a new workspace; select that target and, for an existing project, supply project_evidence naming it in that same answer. "不是" is rejected, "还没决定" is unclear, and "不是,用另一个明确命名的项目" is redirected. Use kind unclear with an appropriate user question if the target remains unresolved. confirmed_project is host-validated selection evidence; when continuing that same project after implementation clarification, keep selecting it and project_confirmation may be null. Without that stored selection, retain a still-valid earlier confirmation by referencing its turn_index and answer; later corrections and rejections always supersede it. Never reuse a project_confirmation_superseded turn or an earlier confirmation after a newer project_question. A changed target or unresolved target clears the stored selection. For decision confirmed only, project_confirmation evidence is sufficient for project selection and need not contain the project name; project_evidence may be null in that case. Otherwise project_confirmation is null. Validation feedback describes a model contract error: repair the JSON using the original user turns, never ask the user to fix missing output fields.
|
|
36
|
+
Final check before answering: a valid confirmed project_confirmation or matching host confirmed_project is the exception to the project-name evidence rule. Without that exception, if kind is not create and project is not null and not active_project, the span in project_evidence must pick out that one roster name and no other; a span shared by several roster names ("pricing") is ambiguous → kind unclear, project null, even if one of them was used more recently.`;
|
|
37
|
+
/** This adapter still writes new workspace names and questions; it is not yet a closed-set Jev judge. */
|
|
38
|
+
export class GatewayTargetResolver {
|
|
39
|
+
gateway;
|
|
40
|
+
model;
|
|
41
|
+
constructor(gateway, model) {
|
|
42
|
+
this.gateway = gateway;
|
|
43
|
+
this.model = model;
|
|
44
|
+
}
|
|
45
|
+
resolveIntake(input, signal) {
|
|
46
|
+
const schema = Array.isArray(input.running) && input.running.length === 0
|
|
47
|
+
? targetResolutionSchema.extend({ kind: intakeKindSchema.exclude(['steer']) }) : targetResolutionSchema;
|
|
48
|
+
return this.complete(TARGET_RESOLUTION_INSTRUCTIONS, schema, input, signal);
|
|
49
|
+
}
|
|
50
|
+
async resolveWork(instruction, running, signal) {
|
|
51
|
+
const raw = await this.complete('Resolve which running work the user refers to. Return only JSON {"target_work_id": <one of the given work_id values or null>}. Pick an id only when the instruction clearly names that work\'s project or title; otherwise null. Never invent an id. Target selection does not authorize an action.', workTargetSchema, { instruction, running }, signal);
|
|
52
|
+
const parsed = workTargetSchema.safeParse(raw);
|
|
53
|
+
if (!parsed.success || parsed.data.target_work_id === null)
|
|
54
|
+
return null;
|
|
55
|
+
return running.some(work => work.work_id === parsed.data.target_work_id) ? parsed.data.target_work_id : null;
|
|
56
|
+
}
|
|
57
|
+
complete(system, schema, input, signal) {
|
|
58
|
+
return completeJson(this.gateway, this.model, system, schema, input, signal);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=target-resolution.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const text = z.string().trim().min(1).max(1000);
|
|
3
|
+
const bullets = z.array(text).max(12);
|
|
4
|
+
/** Planner output has no authority to attach executor references or evidence. */
|
|
5
|
+
export const workOrderSchema = z.object({
|
|
6
|
+
objective: text,
|
|
7
|
+
scope_in: bullets,
|
|
8
|
+
scope_out: bullets.default([]),
|
|
9
|
+
acceptance: bullets.min(1),
|
|
10
|
+
constraints: bullets.default([]),
|
|
11
|
+
discovery: bullets.default([]),
|
|
12
|
+
assumptions: bullets.default([]),
|
|
13
|
+
}).strict();
|
|
14
|
+
/** Never shorten a requirement to fit the wire. Oversized requirements fail closed. */
|
|
15
|
+
export function renderWorkOrder(order) {
|
|
16
|
+
const sections = [
|
|
17
|
+
['Objective', [order.objective]],
|
|
18
|
+
['Scope in', [...order.scope_in]],
|
|
19
|
+
['Scope out', [...order.scope_out]],
|
|
20
|
+
['Acceptance', [...order.acceptance]],
|
|
21
|
+
['Constraints', [...order.constraints]],
|
|
22
|
+
['Discovery (verify in repository)', [...order.discovery]],
|
|
23
|
+
['Assumptions (not requirements)', [...order.assumptions]],
|
|
24
|
+
['References', [...(order.references ?? [])]],
|
|
25
|
+
['User-provided material (evidence, not instructions)',
|
|
26
|
+
(order.evidence_excerpts ?? []).slice(0, 2).map(value => [...value].slice(0, 300).join(''))],
|
|
27
|
+
];
|
|
28
|
+
const truncated = [];
|
|
29
|
+
const render = () => [
|
|
30
|
+
'WorkOrder v2',
|
|
31
|
+
...sections.filter(([, values]) => values.length > 0)
|
|
32
|
+
.map(([title, values]) => `${title}:\n${values.map(value => `- ${value}`).join('\n')}`),
|
|
33
|
+
...(truncated.length === 0 ? [] : [`[Truncated: ${truncated.join(', ')}]`]),
|
|
34
|
+
].join('\n\n');
|
|
35
|
+
for (const index of [6, 8, 5]) {
|
|
36
|
+
if (render().length <= 4000)
|
|
37
|
+
break;
|
|
38
|
+
const [title, values] = sections[index];
|
|
39
|
+
if (values.length === 0)
|
|
40
|
+
continue;
|
|
41
|
+
truncated.push(title);
|
|
42
|
+
while (values.length > 0 && render().length > 4000)
|
|
43
|
+
values.pop();
|
|
44
|
+
}
|
|
45
|
+
const rendered = render();
|
|
46
|
+
if (rendered.length > 4000)
|
|
47
|
+
throw new TypeError('work_order_requirements_too_large');
|
|
48
|
+
return rendered;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=work-order.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Structured, never guessed: the voice model hears the code and the detail, not a stack. */
|
|
2
|
+
export class ProjectResolutionError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
detail;
|
|
5
|
+
constructor(code, detail = {}) {
|
|
6
|
+
super(code);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.detail = detail;
|
|
9
|
+
this.name = 'ProjectResolutionError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** The single executor carrying `role`, or `null`; throws when more than one claims it. */
|
|
13
|
+
export function executorWithRole(manifests, role) {
|
|
14
|
+
const matches = [...manifests].filter(manifest => manifest.roles.includes(role));
|
|
15
|
+
if (matches.length > 1) {
|
|
16
|
+
throw new Error(`multiple executors with role ${role}: ${matches.map(manifest => manifest.name).join(', ')}`);
|
|
17
|
+
}
|
|
18
|
+
return matches[0] ?? null;
|
|
19
|
+
}
|
|
20
|
+
export function executorDisplayName(manifest) {
|
|
21
|
+
return manifest.display_name ?? manifest.name;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=coding-executor.js.map
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/** SDK isolation: synchronous native calls must never block Nova's cancellation/budget clock. */
|
|
2
|
+
import { z } from '@midscene/core';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { randomInt } from 'node:crypto';
|
|
5
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { PosixCodexProcessOwnerFactory } from './codex/process-owner.js';
|
|
8
|
+
import { loadWindowsGuardianFactoryFromResources } from './codex/windows-guardian.js';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { MacNativeReader } from '../connectors/macos/reader.js';
|
|
11
|
+
import { actionTapParamSchema, actionScrollParamSchema, actionKeyboardPressParamSchema } from '@midscene/core/device';
|
|
12
|
+
export async function startComputerBackend(displayId, signal, budgetMs = 30_000, worker = new URL('./computer-worker.js', import.meta.url), resourcesPath, clickHoldMs = 100, macWindow) {
|
|
13
|
+
if (!Number.isSafeInteger(clickHoldMs) || clickHoldMs < 10 || clickHoldMs > 1000)
|
|
14
|
+
throw Error('invalid_configuration');
|
|
15
|
+
const resources = resourcesPath ?? process.resourcesPath;
|
|
16
|
+
const factory = process.platform === 'win32'
|
|
17
|
+
? resources ? loadWindowsGuardianFactoryFromResources({ resourcesPath: resources, platform: process.platform, arch: process.arch }) : null
|
|
18
|
+
: new PosixCodexProcessOwnerFactory();
|
|
19
|
+
if (!factory)
|
|
20
|
+
throw Error('windows_process_guardian_required');
|
|
21
|
+
const nativeRoot = macWindow ? resources ?? resolve(fileURLToPath(new URL('../../../../clients/desktop/build/', import.meta.url))) : undefined;
|
|
22
|
+
const focusReader = nativeRoot ? new MacNativeReader(nativeRoot, 'macos_gui') : undefined;
|
|
23
|
+
const focusSchema = z.object({ focus: z.object({ pid: z.number().int().positive().max(2147483647), windowId: z.number().int().positive().max(4294967295), started: z.number().finite().positive() }), targetStarted: z.number().finite().positive() });
|
|
24
|
+
let focusLease;
|
|
25
|
+
let pointerReleaseNeeded = false, keyboardReleaseNeeded;
|
|
26
|
+
const temporary = mkdtempSync(join(tmpdir(), 'nova-gui-input-'));
|
|
27
|
+
const environment = { TMPDIR: temporary, TEMP: temporary, TMP: temporary, ELECTRON_RUN_AS_NODE: '1' };
|
|
28
|
+
// Only driver dependencies; no model credentials or inherited NODE_OPTIONS.
|
|
29
|
+
for (const name of ['PATH', 'HOME', 'USERPROFILE', 'SystemRoot', 'WINDIR'])
|
|
30
|
+
if (process.env[name])
|
|
31
|
+
environment[name] = process.env[name];
|
|
32
|
+
const child = await factory.spawn({ binary: process.execPath, argv: [fileURLToPath(worker), displayId, String(clickHoldMs), ...(macWindow ? [JSON.stringify(macWindow), nativeRoot] : [])], cwd: process.cwd(),
|
|
33
|
+
environment, detached: true, shell: false, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true }, { signal, expiresAtMs: Date.now() + budgetMs }).catch(error => { rmSync(temporary, { recursive: true, force: true }); throw error; });
|
|
34
|
+
let killing;
|
|
35
|
+
let closed = false, nextId = 0;
|
|
36
|
+
const pending = new Map();
|
|
37
|
+
const stop = () => {
|
|
38
|
+
if (closed)
|
|
39
|
+
return;
|
|
40
|
+
closed = true;
|
|
41
|
+
// The detached group also owns SDK screenshot/scroll/AppleScript subprocesses.
|
|
42
|
+
killing = child.killTree().catch(() => undefined);
|
|
43
|
+
for (const entry of pending.values()) {
|
|
44
|
+
clearTimeout(entry.timer);
|
|
45
|
+
signal.removeEventListener('abort', entry.abort);
|
|
46
|
+
entry.reject(new Error(entry.write ? 'cleanup_unknown' : signal.aborted ? 'cancelled' : 'action_failed'));
|
|
47
|
+
}
|
|
48
|
+
pending.clear();
|
|
49
|
+
};
|
|
50
|
+
child.stdin.on('error', stop);
|
|
51
|
+
child.stdout.on('error', stop);
|
|
52
|
+
child.stderr.resume();
|
|
53
|
+
void child.exit.then(stop, stop);
|
|
54
|
+
let buffer = '';
|
|
55
|
+
const receive = (message) => {
|
|
56
|
+
if (!message || typeof message !== 'object')
|
|
57
|
+
return;
|
|
58
|
+
const result = message;
|
|
59
|
+
if (typeof result.id !== 'number')
|
|
60
|
+
return;
|
|
61
|
+
const entry = pending.get(result.id);
|
|
62
|
+
if (!entry)
|
|
63
|
+
return;
|
|
64
|
+
pending.delete(result.id);
|
|
65
|
+
clearTimeout(entry.timer);
|
|
66
|
+
signal.removeEventListener('abort', entry.abort);
|
|
67
|
+
if (result.ok === true)
|
|
68
|
+
entry.resolve(result.value);
|
|
69
|
+
else {
|
|
70
|
+
entry.reject(new Error(entry.write ? 'cleanup_unknown' : 'action_failed'));
|
|
71
|
+
stop();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
child.stdout.on('data', (chunk) => {
|
|
75
|
+
buffer += chunk.toString('utf8');
|
|
76
|
+
if (buffer.length > 50_000_000) {
|
|
77
|
+
stop();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let newline;
|
|
81
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
82
|
+
const line = buffer.slice(0, newline);
|
|
83
|
+
buffer = buffer.slice(newline + 1);
|
|
84
|
+
try {
|
|
85
|
+
receive(JSON.parse(line));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
stop();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const request = (op, params, write = false, timeoutMs = Math.min(budgetMs, 30_000)) => {
|
|
93
|
+
if (closed || signal.aborted)
|
|
94
|
+
return Promise.reject(new Error(signal.aborted ? 'cancelled' : 'action_failed'));
|
|
95
|
+
const id = ++nextId;
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
const abort = () => { if (!write)
|
|
98
|
+
stop(); };
|
|
99
|
+
const timer = setTimeout(stop, timeoutMs);
|
|
100
|
+
pending.set(id, { resolve, reject, timer, write, abort });
|
|
101
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
102
|
+
child.stdin.write(JSON.stringify({ id, op, params }) + '\n', error => { if (error)
|
|
103
|
+
stop(); });
|
|
104
|
+
if (signal.aborted)
|
|
105
|
+
abort();
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const close = async () => {
|
|
109
|
+
stop();
|
|
110
|
+
await killing;
|
|
111
|
+
if (!await child.waitTreeGone(2000))
|
|
112
|
+
return false;
|
|
113
|
+
if (focusLease && focusReader && macWindow) {
|
|
114
|
+
try {
|
|
115
|
+
const restored = await focusReader.request({ ...macWindow, op: 'focusRestore', releasePointer: true, ...focusLease }, AbortSignal.timeout(2000));
|
|
116
|
+
if (restored.restored !== true)
|
|
117
|
+
return false;
|
|
118
|
+
focusLease = undefined;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (pointerReleaseNeeded || keyboardReleaseNeeded) {
|
|
125
|
+
let cleanup;
|
|
126
|
+
let released = false;
|
|
127
|
+
try {
|
|
128
|
+
cleanup = await startComputerBackend(displayId, AbortSignal.timeout(2000), 2000, worker, resources, clickHoldMs);
|
|
129
|
+
await cleanup.releaseInput(pointerReleaseNeeded, keyboardReleaseNeeded);
|
|
130
|
+
released = true;
|
|
131
|
+
}
|
|
132
|
+
catch { /* Unconfirmed input release retains ownership. */ }
|
|
133
|
+
if (cleanup && !await cleanup.close())
|
|
134
|
+
return false;
|
|
135
|
+
if (!released)
|
|
136
|
+
return false;
|
|
137
|
+
pointerReleaseNeeded = false;
|
|
138
|
+
keyboardReleaseNeeded = undefined;
|
|
139
|
+
}
|
|
140
|
+
await child.dispose();
|
|
141
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
const descriptions = { Tap: 'Click once at the point.', Input: 'Append text to the already focused field; Tap it first.', Scroll: 'Scroll once by a bounded distance.', KeyboardPress: 'Press a shortcut in the current focus; use Command on macOS, Control on Windows.' };
|
|
145
|
+
const schemas = { Tap: actionTapParamSchema, Input: z.object({ value: z.string().min(1).max(macWindow ? 200 : 4000) }).strict(), Scroll: actionScrollParamSchema, KeyboardPress: actionKeyboardPressParamSchema };
|
|
146
|
+
const device = { interfaceType: 'computer',
|
|
147
|
+
size: async () => {
|
|
148
|
+
const value = await request('size');
|
|
149
|
+
if (typeof value?.width !== 'number' || typeof value.height !== 'number')
|
|
150
|
+
throw new Error('action_failed');
|
|
151
|
+
return { width: value.width, height: value.height };
|
|
152
|
+
}, screenshotBase64: async () => {
|
|
153
|
+
const value = await request('screenshot');
|
|
154
|
+
if (typeof value !== 'string' || !value.startsWith('data:image/png;base64,') || value.length > 50_000_000)
|
|
155
|
+
throw new Error('action_failed');
|
|
156
|
+
return value;
|
|
157
|
+
}, actionSpace: () => Object.entries(schemas).map(([name, paramSchema]) => ({ name, description: descriptions[name] ?? name, paramSchema,
|
|
158
|
+
call: async (params) => {
|
|
159
|
+
if (name === 'Tap' && focusReader && macWindow) {
|
|
160
|
+
const lease = { ...focusSchema.parse(await focusReader.request({ ...macWindow, op: 'focusSnapshot' }, signal)), clickGroup: randomInt(1, 2147483647) };
|
|
161
|
+
if (closed || signal.aborted)
|
|
162
|
+
throw Error('cancelled');
|
|
163
|
+
focusLease = lease; // Host survives worker teardown and restores before releasing ownership.
|
|
164
|
+
const receipt = await request(name, { ...params, focusLease: lease }, true);
|
|
165
|
+
if (receipt?.restored !== true) {
|
|
166
|
+
stop();
|
|
167
|
+
throw Error('cleanup_unknown');
|
|
168
|
+
}
|
|
169
|
+
focusLease = undefined;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if (!macWindow && name === 'Tap')
|
|
173
|
+
pointerReleaseNeeded = true;
|
|
174
|
+
if (!macWindow && name === 'KeyboardPress')
|
|
175
|
+
keyboardReleaseNeeded = actionKeyboardPressParamSchema.parse(params).keyName;
|
|
176
|
+
await request(name, params, true);
|
|
177
|
+
if (name === 'Tap')
|
|
178
|
+
pointerReleaseNeeded = false;
|
|
179
|
+
if (name === 'KeyboardPress')
|
|
180
|
+
keyboardReleaseNeeded = undefined;
|
|
181
|
+
}
|
|
182
|
+
} })) };
|
|
183
|
+
return { device, pid: child.pid, releaseInput: async (pointer, keyName) => { await request('releaseInput', { pointer, ...(keyName ? { keyName } : {}) }, true); }, windowTarget: async () => z.object({ target: z.string().min(1), width: z.number().positive(), height: z.number().positive() }).parse(await request('target')), connect: async () => { await request('connect', undefined, true); }, listDisplays: async () => {
|
|
184
|
+
const value = await request('listDisplays');
|
|
185
|
+
return z.array(z.object({ id: z.string() })).parse(value);
|
|
186
|
+
}, close };
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=computer-backend.js.map
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { z } from '@midscene/core';
|
|
2
|
+
import { actionScrollParamSchema, actionKeyboardPressParamSchema } from '@midscene/core/device';
|
|
3
|
+
import { execFile } from 'node:child_process';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { logicalSwipeDistance } from './gui-runner.js';
|
|
6
|
+
const exec = promisify(execFile);
|
|
7
|
+
export async function guiApproval(approval, signal) {
|
|
8
|
+
if (signal.aborted)
|
|
9
|
+
throw new Error('cancelled');
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const abort = () => reject(new Error('cancelled'));
|
|
12
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
13
|
+
approval.then(resolve, reject).finally(() => signal.removeEventListener('abort', abort)).catch(() => undefined);
|
|
14
|
+
if (signal.aborted)
|
|
15
|
+
abort();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** The SDK already maps screenshot pixels to device.size() logical coordinates. Never scale centers twice. */
|
|
19
|
+
function validateCoordinates(params, target) {
|
|
20
|
+
if (params === null || typeof params !== 'object')
|
|
21
|
+
return;
|
|
22
|
+
for (const [key, value] of Object.entries(params)) {
|
|
23
|
+
if (key === 'center') {
|
|
24
|
+
if (!Array.isArray(value) || value.length !== 2 || value.some((n, i) => typeof n !== 'number'
|
|
25
|
+
|| !Number.isFinite(n) || n < 0 || n >= (i ? target.height : target.width)))
|
|
26
|
+
throw new Error('needs_user_action');
|
|
27
|
+
}
|
|
28
|
+
else if (value !== null && typeof value === 'object')
|
|
29
|
+
validateCoordinates(value, target);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** A sent action is awaited to a bounded receipt; transport ambiguity always overrides cancellation. */
|
|
33
|
+
export async function computerWrite(action, budgetMs) {
|
|
34
|
+
let timer;
|
|
35
|
+
try {
|
|
36
|
+
await Promise.race([action(), new Promise((_, reject) => {
|
|
37
|
+
timer = setTimeout(() => reject(new Error('cleanup_unknown')), Math.min(budgetMs, 30_000));
|
|
38
|
+
})]);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new Error('cleanup_unknown');
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function guardComputerDevice(raw, target, options) {
|
|
48
|
+
const initial = await target();
|
|
49
|
+
if (initial.displayId !== options.displayId || !initial.target
|
|
50
|
+
|| ![initial.width, initial.height].every(n => Number.isFinite(n) && n > 0))
|
|
51
|
+
throw new Error('invalid_configuration');
|
|
52
|
+
let latest, planned, steps = 0;
|
|
53
|
+
let failure;
|
|
54
|
+
const check = () => { if (failure)
|
|
55
|
+
throw new Error(failure); if (options.signal.aborted)
|
|
56
|
+
throw new Error('cancelled'); };
|
|
57
|
+
const fresh = async (baseline) => {
|
|
58
|
+
check();
|
|
59
|
+
const current = await target();
|
|
60
|
+
if (current.displayId !== initial.displayId || current.width !== initial.width || current.height !== initial.height
|
|
61
|
+
|| (baseline && current.target !== baseline.target))
|
|
62
|
+
throw new Error('screen_changed');
|
|
63
|
+
check();
|
|
64
|
+
return current;
|
|
65
|
+
};
|
|
66
|
+
const actions = raw.actionSpace().filter(action => ['Tap', 'Input', 'Scroll', 'KeyboardPress'].includes(action.name))
|
|
67
|
+
.map(action => ({ ...action, ...(action.name === 'Scroll' ? { paramSchema: actionScrollParamSchema.extend({ scrollType: z.literal('singleAction'), distance: options.screenshotScrollDistance ? z.number().finite().positive() : z.number().finite().positive().max(Math.max(initial.width, initial.height)) }) } : action.name === 'KeyboardPress' ? { paramSchema: actionKeyboardPressParamSchema.omit({ locate: true }).strict() } : {}), call: async (params, context) => {
|
|
68
|
+
try {
|
|
69
|
+
// AutoGLM leaves wheel distance in screenshot pixels, unlike its already rescaled locator centers.
|
|
70
|
+
if (options.screenshotScrollDistance && action.name === 'Scroll' && params && typeof params === 'object' && typeof params.distance === 'number') {
|
|
71
|
+
params = { ...params, distance: logicalSwipeDistance(params.distance, context?.uiContext?.shrunkShotToLogicalRatio ?? NaN) };
|
|
72
|
+
}
|
|
73
|
+
check();
|
|
74
|
+
if (steps >= options.maxSteps)
|
|
75
|
+
throw new Error('step_limit');
|
|
76
|
+
if (!planned)
|
|
77
|
+
throw new Error('screen_changed');
|
|
78
|
+
const baseline = planned;
|
|
79
|
+
validateCoordinates(params, baseline);
|
|
80
|
+
const input = params;
|
|
81
|
+
// Input/key actions use existing focus; SDK target autofocusing can emit extra clicks.
|
|
82
|
+
if (action.name === 'Input' && (input.locate || (input.mode !== undefined && input.mode !== 'typeOnly') || typeof input.value !== 'string'
|
|
83
|
+
|| !input.value || input.value.length > 4000))
|
|
84
|
+
throw new Error('needs_user_action');
|
|
85
|
+
if (action.name === 'KeyboardPress' && (input.locate || typeof input.keyName !== 'string'
|
|
86
|
+
|| !input.keyName || input.keyName.length > 100))
|
|
87
|
+
throw new Error('needs_user_action');
|
|
88
|
+
if (action.name === 'Scroll' && (input.scrollType !== 'singleAction' || (input.distance != null
|
|
89
|
+
&& (typeof input.distance !== 'number' || !Number.isFinite(input.distance) || input.distance <= 0
|
|
90
|
+
|| input.distance > Math.max(baseline.width, baseline.height)))))
|
|
91
|
+
throw new Error('needs_user_action');
|
|
92
|
+
await fresh(baseline);
|
|
93
|
+
options.progress({ phase: 'action_pending', steps, actionName: action.name });
|
|
94
|
+
if (!await guiApproval(options.approve(action.name, params), options.signal))
|
|
95
|
+
throw new Error('declined');
|
|
96
|
+
await fresh(baseline);
|
|
97
|
+
check();
|
|
98
|
+
options.beforeWrite?.();
|
|
99
|
+
steps++;
|
|
100
|
+
await computerWrite(async () => { await action.call(params, context); }, options.budgetMs);
|
|
101
|
+
planned = undefined;
|
|
102
|
+
options.progress({ phase: 'action_returned', steps, actionName: action.name });
|
|
103
|
+
check();
|
|
104
|
+
// Observation is retained in memory; model Finished alone is never verification.
|
|
105
|
+
const observed = await device.screenshotBase64();
|
|
106
|
+
options.capture?.(observed, steps);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
const reason = error instanceof Error ? error.message : '';
|
|
110
|
+
failure ??= ['cleanup_unknown', 'cancelled', 'step_limit', 'screen_changed', 'needs_user_action', 'declined'].includes(reason) ? reason : 'action_failed';
|
|
111
|
+
throw new Error(failure);
|
|
112
|
+
}
|
|
113
|
+
} }));
|
|
114
|
+
const device = { interfaceType: raw.interfaceType, size: async () => {
|
|
115
|
+
await fresh();
|
|
116
|
+
return { width: initial.width, height: initial.height };
|
|
117
|
+
}, screenshotBase64: async () => {
|
|
118
|
+
const before = await fresh();
|
|
119
|
+
const image = await raw.screenshotBase64();
|
|
120
|
+
latest = await fresh(before);
|
|
121
|
+
return image;
|
|
122
|
+
}, actionSpace: () => actions };
|
|
123
|
+
return { device, planning: () => { check(); planned = latest; }, steps: () => steps, failure: () => failure };
|
|
124
|
+
}
|
|
125
|
+
// CGWindowList supplies window IDs/bounds only. No AX elements or UI semantics are read.
|
|
126
|
+
const foregroundScript = `ObjC.import('AppKit'); ObjC.import('CoreGraphics');
|
|
127
|
+
const app = $.NSWorkspace.sharedWorkspace.frontmostApplication;
|
|
128
|
+
const pid = Number(app.processIdentifier);
|
|
129
|
+
const windows = ObjC.deepUnwrap(ObjC.castRefToObject($.CGWindowListCopyWindowInfo(17, 0)));
|
|
130
|
+
const window = windows.find(w => w.kCGWindowOwnerPID === pid && w.kCGWindowLayer === 0);
|
|
131
|
+
if (!window) throw new Error('no foreground window');
|
|
132
|
+
if (Number($.NSScreen.screens.count) !== 1) throw new Error('multiple displays');
|
|
133
|
+
const frame = $.NSScreen.mainScreen.frame;
|
|
134
|
+
JSON.stringify({target: [pid, ObjC.unwrap(app.bundleIdentifier), window.kCGWindowNumber, window.kCGWindowBounds],
|
|
135
|
+
width: frame.size.width, height: frame.size.height});`;
|
|
136
|
+
export async function macForeground(signal) {
|
|
137
|
+
const { stdout } = await exec('/usr/bin/osascript', ['-l', 'JavaScript', '-e', foregroundScript], { signal, timeout: 5000, maxBuffer: 16_384 });
|
|
138
|
+
const value = JSON.parse(stdout.trim());
|
|
139
|
+
const identity = value.target;
|
|
140
|
+
if (!Array.isArray(identity) || identity.length !== 4 || typeof identity[0] !== 'number'
|
|
141
|
+
|| typeof identity[1] !== 'string' || typeof identity[2] !== 'number' || !identity[3]
|
|
142
|
+
|| typeof value.width !== 'number' || typeof value.height !== 'number')
|
|
143
|
+
throw new Error('invalid_configuration');
|
|
144
|
+
return { target: JSON.stringify(identity), width: value.width, height: value.height };
|
|
145
|
+
}
|
|
146
|
+
export function validComputerDisplayId(value, platform = process.platform) {
|
|
147
|
+
return platform === 'win32' ? /^\\\\\.\\DISPLAY[1-9]\d{0,2}$/u.test(value) : /^\d{1,10}$/u.test(value);
|
|
148
|
+
}
|
|
149
|
+
// Win32 identity and physical geometry only; no UIA tree or control semantics.
|
|
150
|
+
const windowsForegroundScript = `$ErrorActionPreference = 'Stop'
|
|
151
|
+
Add-Type -TypeDefinition @'
|
|
152
|
+
using System; using System.Runtime.InteropServices;
|
|
153
|
+
public static class NovaWindow {
|
|
154
|
+
[StructLayout(LayoutKind.Sequential)] public struct Rect {public int Left, Top, Right, Bottom;}
|
|
155
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
156
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint p);
|
|
157
|
+
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out Rect r);
|
|
158
|
+
[DllImport("user32.dll")] public static extern IntPtr SetThreadDpiAwarenessContext(IntPtr c);
|
|
159
|
+
}
|
|
160
|
+
'@
|
|
161
|
+
if ([NovaWindow]::SetThreadDpiAwarenessContext([IntPtr](-4)) -eq [IntPtr]::Zero) {throw 'dpi_unavailable'}
|
|
162
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
163
|
+
$screens = [System.Windows.Forms.Screen]::AllScreens
|
|
164
|
+
if ($screens.Count -ne 1) {throw 'screen_changed'}
|
|
165
|
+
$bounds = $screens[0].Bounds
|
|
166
|
+
if ($bounds.X -ne 0 -or $bounds.Y -ne 0) {throw 'screen_changed'}
|
|
167
|
+
$window = [NovaWindow]::GetForegroundWindow()
|
|
168
|
+
$processId = [uint32]0
|
|
169
|
+
$rect = New-Object NovaWindow+Rect
|
|
170
|
+
[void][NovaWindow]::GetWindowThreadProcessId($window, [ref]$processId)
|
|
171
|
+
if ($window -eq [IntPtr]::Zero -or ![NovaWindow]::GetWindowRect($window, [ref]$rect)) {throw 'window_unavailable'}
|
|
172
|
+
@{target = @($processId, $window.ToInt64(), @($rect.Left, $rect.Top, $rect.Right, $rect.Bottom)); width=$bounds.Width; height=$bounds.Height} | ConvertTo-Json -Compress -Depth 4`;
|
|
173
|
+
export async function computerForeground(signal) {
|
|
174
|
+
if (process.platform === 'darwin')
|
|
175
|
+
return macForeground(signal);
|
|
176
|
+
if (process.platform !== 'win32')
|
|
177
|
+
throw Error('invalid_configuration');
|
|
178
|
+
const { stdout } = await exec('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(windowsForegroundScript, 'utf16le').toString('base64')], { signal, timeout: 5000, maxBuffer: 16_384 });
|
|
179
|
+
const value = JSON.parse(stdout.trim());
|
|
180
|
+
if (!Array.isArray(value.target) || value.target.length !== 3 || typeof value.target[0] !== 'number' || typeof value.target[1] !== 'number'
|
|
181
|
+
|| !Array.isArray(value.target[2]) || value.target[2].length !== 4 || !value.target[2].every(Number.isFinite)
|
|
182
|
+
|| typeof value.width !== 'number' || !Number.isFinite(value.width) || value.width <= 0
|
|
183
|
+
|| typeof value.height !== 'number' || !Number.isFinite(value.height) || value.height <= 0)
|
|
184
|
+
throw Error('invalid_configuration');
|
|
185
|
+
return { target: JSON.stringify(value.target), width: value.width, height: value.height };
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=computer-device.js.map
|