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,605 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The desktop wire format: audio frames, control messages, and the delivery report.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the codec half of `src/nova_personal_agent/realtime/desktop.py`. Everything here is
|
|
5
|
+
* byte-exact by requirement rather than by preference -- a renderer built against one runtime has to
|
|
6
|
+
* work against the other, and a header that differs by a separator or a field order is a renderer that
|
|
7
|
+
* silently drops audio.
|
|
8
|
+
*
|
|
9
|
+
* Two encodings, and the difference is deliberate. Audio headers and playback control use
|
|
10
|
+
* `ensure_ascii=True`, because they carry only identifiers and integers and an ASCII-only frame is one
|
|
11
|
+
* fewer thing to get wrong in a transport. Captions and the project view use `ensure_ascii=False`,
|
|
12
|
+
* because they carry text a person reads and escaping every CJK character would triple the frame for
|
|
13
|
+
* nothing.
|
|
14
|
+
*/
|
|
15
|
+
import { CODING_BACKEND_IDS } from '../config/coding-backends.js';
|
|
16
|
+
import { codePointLengthLikePython, stripLikePython } from '../text/python-text.js';
|
|
17
|
+
import { PROJECT_CONFIRMATION_TTL_SECONDS } from '../projects/project-confirmation.js';
|
|
18
|
+
import { APPROVAL_TTL_SECONDS, } from '../core/approval-port.js';
|
|
19
|
+
/** Text frames produced on the orb socket (bootstrap, controls and camera requests). */
|
|
20
|
+
export const WIRE_FRAME_TYPES = Object.freeze([
|
|
21
|
+
'playback.clear',
|
|
22
|
+
'playback.alert',
|
|
23
|
+
'playback.terminal',
|
|
24
|
+
'executor.state',
|
|
25
|
+
'project.state',
|
|
26
|
+
'executor.approval',
|
|
27
|
+
'caption',
|
|
28
|
+
'executor.progress',
|
|
29
|
+
'executor.results.reset',
|
|
30
|
+
'executor.result',
|
|
31
|
+
'desktop.activity',
|
|
32
|
+
'clock.ping',
|
|
33
|
+
'desktop.ready',
|
|
34
|
+
'camera.capture',
|
|
35
|
+
'camera.permission',
|
|
36
|
+
'executor.tasks',
|
|
37
|
+
'executor.task_action_result',
|
|
38
|
+
]);
|
|
39
|
+
export const [PLAYBACK_CLEAR, PLAYBACK_ALERT, PLAYBACK_TERMINAL, EXECUTOR_STATE, PROJECT_STATE, EXECUTOR_APPROVAL, CAPTION, EXECUTOR_PROGRESS, EXECUTOR_RESULTS_RESET, EXECUTOR_RESULT, DESKTOP_ACTIVITY, CLOCK_PING, DESKTOP_READY, CAMERA_CAPTURE, CAMERA_PERMISSION, EXECUTOR_TASKS, EXECUTOR_TASK_ACTION_RESULT] = WIRE_FRAME_TYPES;
|
|
40
|
+
export const MAX_DESKTOP_JSON_BYTES = 16 * 1_024;
|
|
41
|
+
export const MAX_DESKTOP_PCM_BYTES = 64 * 1_024;
|
|
42
|
+
/** Bounded so a malformed length prefix cannot make a reader allocate arbitrarily. */
|
|
43
|
+
export const MAX_AUDIO_HEADER_BYTES = 2_048;
|
|
44
|
+
/** `NOVA`, so a frame that is not one is rejected before its length is trusted. */
|
|
45
|
+
const AUDIO_MAGIC = new Uint8Array([0x4e, 0x4f, 0x56, 0x41]);
|
|
46
|
+
export class DesktopProtocolError extends Error {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = 'DesktopProtocolError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Frame one PCM chunk for the renderer.
|
|
54
|
+
*
|
|
55
|
+
* Magic, then a two-byte big-endian header length, then an ASCII JSON header, then the raw PCM. The
|
|
56
|
+
* length prefix is what lets a reader find the audio without scanning it -- and scanning would be
|
|
57
|
+
* wrong anyway, since PCM can contain any byte sequence including the magic.
|
|
58
|
+
*/
|
|
59
|
+
export function encodeAudioFrame(frame) {
|
|
60
|
+
validatePlaybackFrame(frame);
|
|
61
|
+
if (frame.pcm.length > MAX_DESKTOP_PCM_BYTES) {
|
|
62
|
+
throw new DesktopProtocolError('desktop PCM frame is too large');
|
|
63
|
+
}
|
|
64
|
+
const header = asciiJson({
|
|
65
|
+
utterance_id: frame.utterance_id,
|
|
66
|
+
generation_epoch: frame.generation_epoch,
|
|
67
|
+
sequence: frame.sequence,
|
|
68
|
+
});
|
|
69
|
+
const headerBytes = new TextEncoder().encode(header);
|
|
70
|
+
if (headerBytes.length > MAX_AUDIO_HEADER_BYTES) {
|
|
71
|
+
throw new DesktopProtocolError('desktop audio header is too large');
|
|
72
|
+
}
|
|
73
|
+
const out = new Uint8Array(AUDIO_MAGIC.length + 2 + headerBytes.length + frame.pcm.length);
|
|
74
|
+
out.set(AUDIO_MAGIC, 0);
|
|
75
|
+
out[AUDIO_MAGIC.length] = (headerBytes.length >> 8) & 0xff;
|
|
76
|
+
out[AUDIO_MAGIC.length + 1] = headerBytes.length & 0xff;
|
|
77
|
+
out.set(headerBytes, AUDIO_MAGIC.length + 2);
|
|
78
|
+
out.set(frame.pcm, AUDIO_MAGIC.length + 2 + headerBytes.length);
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Read one framed PCM chunk.
|
|
83
|
+
*
|
|
84
|
+
* Every bound is checked before the byte range it guards is used: the magic before the length, the
|
|
85
|
+
* length before the split, the split before the slice. A reader that trusted the prefix first would
|
|
86
|
+
* hand an attacker the shape of its own memory.
|
|
87
|
+
*/
|
|
88
|
+
export function decodeAudioFrame(raw) {
|
|
89
|
+
if (raw.length < AUDIO_MAGIC.length + 2) {
|
|
90
|
+
throw new DesktopProtocolError('desktop audio frame is invalid');
|
|
91
|
+
}
|
|
92
|
+
for (const [index, byte] of AUDIO_MAGIC.entries()) {
|
|
93
|
+
if (raw[index] !== byte)
|
|
94
|
+
throw new DesktopProtocolError('desktop audio frame has invalid magic');
|
|
95
|
+
}
|
|
96
|
+
const headerSize = ((raw[4] ?? 0) << 8) | (raw[5] ?? 0);
|
|
97
|
+
// At least two, because the smallest possible JSON object is `{}`.
|
|
98
|
+
if (headerSize < 2 || headerSize > MAX_AUDIO_HEADER_BYTES) {
|
|
99
|
+
throw new DesktopProtocolError('desktop audio header is invalid');
|
|
100
|
+
}
|
|
101
|
+
const split = 6 + headerSize;
|
|
102
|
+
if (split > raw.length)
|
|
103
|
+
throw new DesktopProtocolError('desktop audio frame is truncated');
|
|
104
|
+
let header;
|
|
105
|
+
let headerText;
|
|
106
|
+
try {
|
|
107
|
+
headerText = new TextDecoder('utf-8', { fatal: true }).decode(raw.subarray(6, split));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
throw new DesktopProtocolError('desktop audio header is invalid');
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
header = parseJsonWithIntegerFields(headerText, ['generation_epoch', 'sequence'], field => new DesktopProtocolError(`desktop ${field} is invalid`));
|
|
114
|
+
}
|
|
115
|
+
catch (cause) {
|
|
116
|
+
// A refusal from the integer check is specific and kept; a parse failure is not.
|
|
117
|
+
if (cause instanceof DesktopProtocolError)
|
|
118
|
+
throw cause;
|
|
119
|
+
throw new DesktopProtocolError('desktop audio header is invalid');
|
|
120
|
+
}
|
|
121
|
+
// Copied, not referenced: a subarray keeps the whole received buffer alive, and this frame outlives
|
|
122
|
+
// the read that produced it.
|
|
123
|
+
const pcm = new Uint8Array(raw.subarray(split));
|
|
124
|
+
const frame = {
|
|
125
|
+
utterance_id: readIdentifier(header, 'utterance_id'),
|
|
126
|
+
generation_epoch: readPositiveInteger(header, 'generation_epoch'),
|
|
127
|
+
sequence: readNonNegativeInteger(header, 'sequence'),
|
|
128
|
+
pcm,
|
|
129
|
+
};
|
|
130
|
+
validatePlaybackFrame(frame);
|
|
131
|
+
if (pcm.length > MAX_DESKTOP_PCM_BYTES) {
|
|
132
|
+
throw new DesktopProtocolError('desktop PCM frame is too large');
|
|
133
|
+
}
|
|
134
|
+
return frame;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Accept microphone PCM, or refuse it.
|
|
138
|
+
*
|
|
139
|
+
* Odd length means the renderer is not sending PCM16, and a half sample would shift every sample after
|
|
140
|
+
* it -- so this refuses rather than truncating, because truncating would produce audio that sounds
|
|
141
|
+
* plausible and is wrong.
|
|
142
|
+
*/
|
|
143
|
+
export function validateInputPcm(raw) {
|
|
144
|
+
if (raw.length === 0 || raw.length % 2 !== 0) {
|
|
145
|
+
throw new DesktopProtocolError('desktop input must be aligned PCM16 bytes');
|
|
146
|
+
}
|
|
147
|
+
if (raw.length > MAX_DESKTOP_PCM_BYTES) {
|
|
148
|
+
throw new DesktopProtocolError('desktop input PCM frame is too large');
|
|
149
|
+
}
|
|
150
|
+
return raw;
|
|
151
|
+
}
|
|
152
|
+
export function playbackClearMessage(utteranceId, generationEpoch) {
|
|
153
|
+
return asciiJson({
|
|
154
|
+
type: PLAYBACK_CLEAR,
|
|
155
|
+
utterance_id: plainIdentifier(utteranceId),
|
|
156
|
+
generation_epoch: plainPositiveInteger(generationEpoch),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Tell the renderer playback stalled.
|
|
161
|
+
*
|
|
162
|
+
* The identity is all-or-nothing: a half-identified alert names a generation without an utterance or
|
|
163
|
+
* the reverse, and the renderer cannot act on either. An alert with no identity at all is the
|
|
164
|
+
* legitimate "something is wrong and I cannot say which turn" case.
|
|
165
|
+
*/
|
|
166
|
+
export function playbackAlertMessage(utteranceId, generationEpoch) {
|
|
167
|
+
if ((utteranceId === null) !== (generationEpoch === null)) {
|
|
168
|
+
throw new DesktopProtocolError('desktop alert identity must be complete');
|
|
169
|
+
}
|
|
170
|
+
if (utteranceId === null || generationEpoch === null) {
|
|
171
|
+
return asciiJson({ type: PLAYBACK_ALERT });
|
|
172
|
+
}
|
|
173
|
+
return asciiJson({
|
|
174
|
+
type: PLAYBACK_ALERT,
|
|
175
|
+
utterance_id: plainIdentifier(utteranceId),
|
|
176
|
+
generation_epoch: plainPositiveInteger(generationEpoch),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
export function playbackTerminalMessage(utteranceId, generationEpoch) {
|
|
180
|
+
return asciiJson({
|
|
181
|
+
type: PLAYBACK_TERMINAL,
|
|
182
|
+
utterance_id: plainIdentifier(utteranceId),
|
|
183
|
+
generation_epoch: plainPositiveInteger(generationEpoch),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function executorIdentity(identity) {
|
|
187
|
+
const executor = plainIdentifier(identity.executor);
|
|
188
|
+
const displayName = identity.display_name;
|
|
189
|
+
if (typeof displayName !== 'string'
|
|
190
|
+
|| stripLikePython(displayName) === ''
|
|
191
|
+
|| codePointLengthLikePython(displayName) > 40)
|
|
192
|
+
throw new DesktopProtocolError('desktop executor identity is invalid');
|
|
193
|
+
return { executor, display_name: displayName };
|
|
194
|
+
}
|
|
195
|
+
export function executorStateMessage(state, identity) {
|
|
196
|
+
if (state !== 'idle' && state !== 'preparing' && state !== 'running') {
|
|
197
|
+
throw new DesktopProtocolError('desktop executor state is invalid');
|
|
198
|
+
}
|
|
199
|
+
return unicodeJson({ type: EXECUTOR_STATE, ...executorIdentity(identity), state });
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The project view the renderer displays.
|
|
203
|
+
*
|
|
204
|
+
* Non-ASCII is left literal here: these are names a person reads, and escaping every CJK character
|
|
205
|
+
* would triple the frame to no benefit.
|
|
206
|
+
*/
|
|
207
|
+
export function projectStateMessage(view) {
|
|
208
|
+
const pendingConfirmationId = view.pending_confirmation_id;
|
|
209
|
+
const pendingAction = view.pending_action ?? null;
|
|
210
|
+
const pendingWorkspace = view.pending_workspace_display_name ?? null;
|
|
211
|
+
const pendingSession = view.pending_session_title ?? null;
|
|
212
|
+
const pendingExpires = view.pending_expires_in_seconds ?? null;
|
|
213
|
+
for (const value of [
|
|
214
|
+
view.workspace_display_name,
|
|
215
|
+
view.session_title,
|
|
216
|
+
pendingWorkspace,
|
|
217
|
+
pendingSession,
|
|
218
|
+
]) {
|
|
219
|
+
if (value === null)
|
|
220
|
+
continue;
|
|
221
|
+
if (typeof value !== 'string' || value === '' || codePointLengthLikePython(value) > 120) {
|
|
222
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (typeof view.pending_confirmation !== 'boolean'
|
|
226
|
+
|| typeof view.pending_confirmation_busy !== 'boolean'
|
|
227
|
+
|| (!view.pending_confirmation && view.pending_confirmation_busy)) {
|
|
228
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
229
|
+
}
|
|
230
|
+
if (pendingConfirmationId !== undefined
|
|
231
|
+
&& (typeof pendingConfirmationId !== 'string'
|
|
232
|
+
|| pendingConfirmationId === ''
|
|
233
|
+
|| codePointLengthLikePython(pendingConfirmationId) > 128))
|
|
234
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
235
|
+
if (pendingAction !== null
|
|
236
|
+
&& !['create_workspace', 'reuse_workspace', 'select_workspace', 'resume_session'].includes(pendingAction)) {
|
|
237
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
238
|
+
}
|
|
239
|
+
const roster = view.roster ?? [];
|
|
240
|
+
const validName = (value) => typeof value === 'string' && value !== '' && codePointLengthLikePython(value) <= 120;
|
|
241
|
+
const validWork = (work) => typeof work.work_id === 'string' && work.work_id !== '' && validName(work.title)
|
|
242
|
+
&& (work.backend_id === undefined || CODING_BACKEND_IDS.includes(work.backend_id));
|
|
243
|
+
// `Array.isArray` alone would narrow the typed arrays to `any[]`; this guard keeps the element types.
|
|
244
|
+
const isList = (value) => Array.isArray(value);
|
|
245
|
+
if (!isList(roster) || roster.length > 10 || !roster.every(entry => validName(entry.name)
|
|
246
|
+
&& Number.isFinite(entry.last_used_at) && entry.last_used_at >= 0
|
|
247
|
+
&& isList(entry.running) && entry.running.every(validWork))) {
|
|
248
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
249
|
+
}
|
|
250
|
+
if (pendingExpires !== null
|
|
251
|
+
&& (typeof pendingExpires !== 'number'
|
|
252
|
+
|| !Number.isFinite(pendingExpires)
|
|
253
|
+
|| pendingExpires < 0
|
|
254
|
+
|| pendingExpires > PROJECT_CONFIRMATION_TTL_SECONDS)) {
|
|
255
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
256
|
+
}
|
|
257
|
+
const hasPendingMetadata = pendingAction !== null
|
|
258
|
+
|| pendingWorkspace !== null
|
|
259
|
+
|| pendingSession !== null
|
|
260
|
+
|| pendingExpires !== null;
|
|
261
|
+
if (!view.pending_confirmation && (hasPendingMetadata || pendingConfirmationId !== undefined)) {
|
|
262
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
263
|
+
}
|
|
264
|
+
if (view.pending_confirmation
|
|
265
|
+
&& hasPendingMetadata
|
|
266
|
+
&& (pendingWorkspace === null || pendingExpires === null)) {
|
|
267
|
+
throw new DesktopProtocolError('desktop project view is invalid');
|
|
268
|
+
}
|
|
269
|
+
return unicodeJson({
|
|
270
|
+
type: PROJECT_STATE,
|
|
271
|
+
workspace_display_name: view.workspace_display_name,
|
|
272
|
+
session_title: view.session_title,
|
|
273
|
+
roster: roster.map(entry => ({
|
|
274
|
+
name: entry.name,
|
|
275
|
+
last_used_at: entry.last_used_at,
|
|
276
|
+
running: entry.running.map(work => ({ work_id: work.work_id, title: work.title, ...(work.backend_id === undefined ? {} : { backend_id: work.backend_id }) })),
|
|
277
|
+
})),
|
|
278
|
+
pending_confirmation: view.pending_confirmation,
|
|
279
|
+
pending_confirmation_busy: view.pending_confirmation_busy,
|
|
280
|
+
...(pendingConfirmationId === undefined
|
|
281
|
+
? {}
|
|
282
|
+
: { pending_confirmation_id: pendingConfirmationId }),
|
|
283
|
+
pending_action: pendingAction,
|
|
284
|
+
pending_workspace_display_name: pendingWorkspace,
|
|
285
|
+
pending_session_title: pendingSession,
|
|
286
|
+
pending_expires_in_seconds: pendingExpires,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/** Independent foreground permission view; raw protocol request fields never enter this frame. */
|
|
290
|
+
export function executorApprovalMessage(view, now, identity) {
|
|
291
|
+
const executor = executorIdentity(identity);
|
|
292
|
+
if (!Number.isFinite(now))
|
|
293
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
294
|
+
if (typeof view.pending_approval !== 'boolean'
|
|
295
|
+
|| typeof view.pending_approval_busy !== 'boolean'
|
|
296
|
+
|| (!view.pending_approval && view.pending_approval_busy))
|
|
297
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
298
|
+
const approvalId = view.pending_approval_id;
|
|
299
|
+
if (!view.pending_approval) {
|
|
300
|
+
if (approvalId !== undefined
|
|
301
|
+
|| view.kind !== null
|
|
302
|
+
|| view.local_detail !== null
|
|
303
|
+
|| view.operation_summary !== null
|
|
304
|
+
|| view.expires_at !== null)
|
|
305
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
306
|
+
return unicodeJson({
|
|
307
|
+
type: EXECUTOR_APPROVAL,
|
|
308
|
+
...executor,
|
|
309
|
+
pending_approval: false,
|
|
310
|
+
pending_approval_busy: false,
|
|
311
|
+
kind: null,
|
|
312
|
+
local_detail: null,
|
|
313
|
+
operation_summary: null,
|
|
314
|
+
expires_in_seconds: null,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const detail = view.local_detail;
|
|
318
|
+
if (typeof approvalId !== 'string'
|
|
319
|
+
|| approvalId === ''
|
|
320
|
+
|| codePointLengthLikePython(approvalId) > 128
|
|
321
|
+
|| !['file_change', 'command_execution', 'network', 'permissions'].includes(view.kind ?? '')
|
|
322
|
+
|| detail?.kind !== view.kind
|
|
323
|
+
|| typeof view.operation_summary !== 'string'
|
|
324
|
+
|| stripLikePython(view.operation_summary) === ''
|
|
325
|
+
|| codePointLengthLikePython(view.operation_summary) > 256
|
|
326
|
+
|| typeof view.expires_at !== 'number'
|
|
327
|
+
|| !Number.isFinite(view.expires_at))
|
|
328
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
329
|
+
const localDetail = validateExecutorApprovalLocalDetail(detail);
|
|
330
|
+
const allowed = view.allowed_decisions;
|
|
331
|
+
if (allowed !== undefined && (!Array.isArray(allowed) || allowed.length === 0 || allowed.length > 3
|
|
332
|
+
|| allowed.some((value) => typeof value !== 'string' || !['accept', 'acceptForSession', 'decline'].includes(value))
|
|
333
|
+
|| !allowed.includes('decline')))
|
|
334
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
335
|
+
// A held head (parked behind a project confirmation) has no running countdown: the pill shows none
|
|
336
|
+
// rather than a number that never reaches zero.
|
|
337
|
+
const expiresInSeconds = view.held === true ? null : Math.min(APPROVAL_TTL_SECONDS, Math.max(0, view.expires_at - now));
|
|
338
|
+
// Spec 08: the pill names the asking work's project and session title, so two running works are told apart.
|
|
339
|
+
const work = view.work;
|
|
340
|
+
if (work !== null && (typeof work.work_id !== 'string' || work.work_id === '' || codePointLengthLikePython(work.work_id) > 128
|
|
341
|
+
|| typeof work.project !== 'string' || stripLikePython(work.project) === ''
|
|
342
|
+
|| typeof work.title !== 'string' || stripLikePython(work.title) === ''))
|
|
343
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
344
|
+
const clip = (value) => [...value].slice(0, 120).join('');
|
|
345
|
+
const message = unicodeJson({
|
|
346
|
+
type: EXECUTOR_APPROVAL,
|
|
347
|
+
...executor,
|
|
348
|
+
pending_approval: true,
|
|
349
|
+
pending_approval_busy: view.pending_approval_busy,
|
|
350
|
+
pending_approval_id: approvalId,
|
|
351
|
+
kind: view.kind,
|
|
352
|
+
local_detail: localDetail,
|
|
353
|
+
operation_summary: view.operation_summary,
|
|
354
|
+
expires_in_seconds: expiresInSeconds,
|
|
355
|
+
...(allowed === undefined ? {} : { allowed_decisions: allowed }),
|
|
356
|
+
...(work === null ? {} : { work: { work_id: work.work_id, project: clip(work.project), title: clip(work.title) } }),
|
|
357
|
+
});
|
|
358
|
+
if (new TextEncoder().encode(message).length > MAX_DESKTOP_JSON_BYTES) {
|
|
359
|
+
throw new DesktopProtocolError('desktop executor approval view is too large');
|
|
360
|
+
}
|
|
361
|
+
return message;
|
|
362
|
+
}
|
|
363
|
+
function validateExecutorApprovalLocalDetail(detail) {
|
|
364
|
+
if ('scope' in detail && (typeof detail.scope !== 'string' || stripLikePython(detail.scope) === '' || codePointLengthLikePython(detail.scope) > 1024)) {
|
|
365
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
366
|
+
}
|
|
367
|
+
if (detail.kind === 'permissions') {
|
|
368
|
+
if (Object.keys(detail).sort().join(',') !== 'kind,scope')
|
|
369
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
370
|
+
return detail;
|
|
371
|
+
}
|
|
372
|
+
if (detail.kind === 'command_execution' || detail.kind === 'network') {
|
|
373
|
+
if (Object.keys(detail).sort().join(',') !== (detail.scope === undefined ? 'command,cwd,kind' : 'command,cwd,kind,scope')
|
|
374
|
+
|| typeof detail.command !== 'string'
|
|
375
|
+
|| stripLikePython(detail.command) === ''
|
|
376
|
+
|| codePointLengthLikePython(detail.command) > 4096
|
|
377
|
+
|| typeof detail.cwd !== 'string'
|
|
378
|
+
|| stripLikePython(detail.cwd) === ''
|
|
379
|
+
|| codePointLengthLikePython(detail.cwd) > 4096)
|
|
380
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
381
|
+
return detail;
|
|
382
|
+
}
|
|
383
|
+
if (detail.kind !== 'file_change')
|
|
384
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
385
|
+
const rawChanges = detail.changes;
|
|
386
|
+
if (Object.keys(detail).sort().join(',') !== 'changes,kind'
|
|
387
|
+
|| !Array.isArray(rawChanges)
|
|
388
|
+
|| rawChanges.length === 0
|
|
389
|
+
|| rawChanges.length > 64)
|
|
390
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
391
|
+
for (const candidate of rawChanges) {
|
|
392
|
+
if (!isPlainObject(candidate)) {
|
|
393
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
394
|
+
}
|
|
395
|
+
const change = candidate;
|
|
396
|
+
if (Object.keys(change).sort().join(',') !== 'change,move_path,path'
|
|
397
|
+
|| change.change !== 'add' && change.change !== 'delete' && change.change !== 'update'
|
|
398
|
+
|| typeof change.path !== 'string'
|
|
399
|
+
|| stripLikePython(change.path) === ''
|
|
400
|
+
|| codePointLengthLikePython(change.path) > 4096
|
|
401
|
+
|| change.move_path !== null && (typeof change.move_path !== 'string'
|
|
402
|
+
|| stripLikePython(change.move_path) === ''
|
|
403
|
+
|| codePointLengthLikePython(change.move_path) > 4096))
|
|
404
|
+
throw new DesktopProtocolError('desktop executor approval view is invalid');
|
|
405
|
+
}
|
|
406
|
+
return detail;
|
|
407
|
+
}
|
|
408
|
+
/** Speculative or final transcript text. The sequence lets the renderer drop what arrives late. */
|
|
409
|
+
export function captionMessage(frame, sequence) {
|
|
410
|
+
return unicodeJson({
|
|
411
|
+
type: CAPTION,
|
|
412
|
+
...(frame.turn_id === undefined ? {} : { turn_id: frame.turn_id }),
|
|
413
|
+
...(frame.work_id === undefined ? {} : { work_id: frame.work_id }),
|
|
414
|
+
...(frame.executor === undefined ? {} : { executor: frame.executor }),
|
|
415
|
+
...(frame.project === undefined ? {} : { project: frame.project }),
|
|
416
|
+
...(frame.title === undefined ? {} : { title: frame.title }),
|
|
417
|
+
role: frame.role,
|
|
418
|
+
text: frame.text,
|
|
419
|
+
final: frame.final,
|
|
420
|
+
sequence,
|
|
421
|
+
...(frame.message_id === undefined ? {} : { message_id: frame.message_id }),
|
|
422
|
+
...(frame.full_text === undefined ? {} : { full_text: frame.full_text }),
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Map a delivery report to the Memory event; words nobody heard yield null.
|
|
427
|
+
*
|
|
428
|
+
* Suppressed means the audio never played, and empty text means there were no words -- either way
|
|
429
|
+
* recording it would put something in Memory the user did not hear, which later turns would then treat
|
|
430
|
+
* as shared context.
|
|
431
|
+
*/
|
|
432
|
+
export function deliveryToEvent(completion) {
|
|
433
|
+
if (completion.disposition === 'suppressed' || completion.text === '')
|
|
434
|
+
return null;
|
|
435
|
+
return {
|
|
436
|
+
text: completion.text,
|
|
437
|
+
utterance_id: completion.utterance_id,
|
|
438
|
+
delivery: completion.disposition,
|
|
439
|
+
played_ms: completion.played_ms,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Parse JSON, refusing any named field that is not written as an exactly-representable integer.
|
|
444
|
+
*
|
|
445
|
+
* Two problems the text cannot be trusted with, and one mechanism for both.
|
|
446
|
+
*
|
|
447
|
+
* **Spelling.** `json.loads` makes `1.0` a float and the oracle's `type(value) is not int` refuses it,
|
|
448
|
+
* while `JSON.parse` cannot tell `1.0` from `1`. The reviver's `context.source` carries the original
|
|
449
|
+
* literal, so the distinction survives the parse.
|
|
450
|
+
*
|
|
451
|
+
* **Range.** Python integers are unbounded; a JavaScript number is not. `9007199254740993` parses to
|
|
452
|
+
* `9007199254740992` here, and `Number.isInteger` is perfectly happy with the result -- so a renderer
|
|
453
|
+
* could have a generation fenced that is not the one it sent. Comparing the source against the parsed
|
|
454
|
+
* value catches exactly the cases where something was lost.
|
|
455
|
+
*
|
|
456
|
+
* This replaced a regex over the raw text, which was bypassable two ways: an escaped key spelling
|
|
457
|
+
* (`generation_\u0065poch`) decodes to the field name but does not match the pattern, and a duplicated
|
|
458
|
+
* key resolves to its *last* value in both parsers while a pattern finds the first. The reviver sees
|
|
459
|
+
* decoded keys and fires once per member with the surviving value, so neither applies.
|
|
460
|
+
*
|
|
461
|
+
* Refusing an out-of-range integer is a deliberate divergence: the oracle accepts it. Refusing is
|
|
462
|
+
* strictly safer than acting on a different number than the renderer sent.
|
|
463
|
+
*/
|
|
464
|
+
export function parseJsonWithIntegerFields(text, fields, onInvalid) {
|
|
465
|
+
const named = new Set(fields);
|
|
466
|
+
// Collected rather than judged in place: the reviver runs bottom-up, so the root object's identity is
|
|
467
|
+
// not known until the very end. A nested `{"meta":{"generation_epoch":1.5}}` is forward-compatible
|
|
468
|
+
// renderer metadata that the oracle parses and ignores -- it reads only `value.get(field)` on the
|
|
469
|
+
// root -- so rejecting it here would discard valid acknowledgements and strand playback state.
|
|
470
|
+
const candidates = [];
|
|
471
|
+
const parsed = JSON.parse(text, function reviver(key, value, context) {
|
|
472
|
+
if (named.has(key)
|
|
473
|
+
&& context?.source !== undefined
|
|
474
|
+
&& typeof this === 'object'
|
|
475
|
+
&& this !== null) {
|
|
476
|
+
candidates.push({ holder: this, field: key, source: context.source });
|
|
477
|
+
}
|
|
478
|
+
return value;
|
|
479
|
+
});
|
|
480
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
481
|
+
return parsed;
|
|
482
|
+
for (const candidate of candidates) {
|
|
483
|
+
// Only the root's own members. Identity works because this reviver returns every value unchanged,
|
|
484
|
+
// so the object the top-level members were revived into is the object that comes back.
|
|
485
|
+
if (candidate.holder !== parsed)
|
|
486
|
+
continue;
|
|
487
|
+
// `null` is a legal value wherever a field is optional; it is not a number at all.
|
|
488
|
+
if (candidate.source === 'null')
|
|
489
|
+
continue;
|
|
490
|
+
if (!/^-?\d+$/u.test(candidate.source) || String(parsed[candidate.field]) !== candidate.source) {
|
|
491
|
+
throw onInvalid(candidate.field);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return parsed;
|
|
495
|
+
}
|
|
496
|
+
function validatePlaybackFrame(frame) {
|
|
497
|
+
plainIdentifier(frame.utterance_id);
|
|
498
|
+
plainPositiveInteger(frame.generation_epoch);
|
|
499
|
+
if (!Number.isInteger(frame.sequence) || frame.sequence < 0) {
|
|
500
|
+
throw new DesktopProtocolError('desktop audio sequence is invalid');
|
|
501
|
+
}
|
|
502
|
+
if (frame.pcm.length === 0 || frame.pcm.length % 2 !== 0) {
|
|
503
|
+
throw new DesktopProtocolError('desktop audio must be aligned PCM16 bytes');
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function readIdentifier(payload, field) {
|
|
507
|
+
if (!isPlainObject(payload))
|
|
508
|
+
throw new DesktopProtocolError('desktop frame payload is invalid');
|
|
509
|
+
try {
|
|
510
|
+
return plainIdentifier(payload[field]);
|
|
511
|
+
}
|
|
512
|
+
catch {
|
|
513
|
+
throw new DesktopProtocolError(`desktop ${field} is invalid`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function readPositiveInteger(payload, field) {
|
|
517
|
+
if (!isPlainObject(payload))
|
|
518
|
+
throw new DesktopProtocolError('desktop frame payload is invalid');
|
|
519
|
+
try {
|
|
520
|
+
return plainPositiveInteger(payload[field]);
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
throw new DesktopProtocolError(`desktop ${field} is invalid`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function readNonNegativeInteger(payload, field) {
|
|
527
|
+
if (!isPlainObject(payload))
|
|
528
|
+
throw new DesktopProtocolError('desktop frame payload is invalid');
|
|
529
|
+
const candidate = payload[field];
|
|
530
|
+
if (typeof candidate !== 'number' || !Number.isInteger(candidate) || candidate < 0) {
|
|
531
|
+
throw new DesktopProtocolError(`desktop ${field} is invalid`);
|
|
532
|
+
}
|
|
533
|
+
return candidate;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* An identifier the renderer can use.
|
|
537
|
+
*
|
|
538
|
+
* Whitespace-only is refused but whitespace-containing is not, and the value is returned untrimmed:
|
|
539
|
+
* the oracle checks `value.strip()` and returns `value`, so trimming here would produce an identifier
|
|
540
|
+
* that no longer matches the one the session holds.
|
|
541
|
+
*/
|
|
542
|
+
function plainIdentifier(value) {
|
|
543
|
+
if (typeof value !== 'string'
|
|
544
|
+
|| stripLikePython(value) === ''
|
|
545
|
+
|| codePointLengthLikePython(value) > 256) {
|
|
546
|
+
throw new DesktopProtocolError('desktop identity is invalid');
|
|
547
|
+
}
|
|
548
|
+
return value;
|
|
549
|
+
}
|
|
550
|
+
function plainPositiveInteger(value) {
|
|
551
|
+
// Integer *and* at least one: a generation epoch counts from one, and a float here would render as
|
|
552
|
+
// `1.5` in a field the renderer reads as an epoch.
|
|
553
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
|
|
554
|
+
throw new DesktopProtocolError('desktop generation is invalid');
|
|
555
|
+
}
|
|
556
|
+
return value;
|
|
557
|
+
}
|
|
558
|
+
function isPlainObject(value) {
|
|
559
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Compact JSON with every non-ASCII character escaped, matching `ensure_ascii=True`.
|
|
563
|
+
*
|
|
564
|
+
* Field order is insertion order, as the oracle's dict is -- *not* sorted. These frames are compared
|
|
565
|
+
* byte for byte against the Python ones, so the order is part of the format.
|
|
566
|
+
*/
|
|
567
|
+
function asciiJson(value) {
|
|
568
|
+
return escapeNonAscii(compactJson(value));
|
|
569
|
+
}
|
|
570
|
+
/** Compact JSON leaving non-ASCII literal, matching `ensure_ascii=False`. */
|
|
571
|
+
function unicodeJson(value) {
|
|
572
|
+
return compactJson(value);
|
|
573
|
+
}
|
|
574
|
+
function compactJson(value) {
|
|
575
|
+
// `JSON.stringify` already emits `{"a":1,"b":2}` with no spaces, which is Python's
|
|
576
|
+
// `separators=(",", ":")`.
|
|
577
|
+
return JSON.stringify(value);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Escape every non-ASCII code point as `\uXXXX`, the way Python's `ensure_ascii=True` does.
|
|
581
|
+
*
|
|
582
|
+
* Astral characters become a surrogate pair of escapes, which is also what Python emits -- it escapes
|
|
583
|
+
* the UTF-16 encoding rather than the code point.
|
|
584
|
+
*/
|
|
585
|
+
function escapeNonAscii(text) {
|
|
586
|
+
let out = '';
|
|
587
|
+
for (const unit of text) {
|
|
588
|
+
const code = unit.codePointAt(0) ?? 0;
|
|
589
|
+
if (code < 0x80) {
|
|
590
|
+
out += unit;
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
if (code > 0xff_ff) {
|
|
594
|
+
// Re-derive the surrogate pair, because that is what Python escapes.
|
|
595
|
+
const offset = code - 0x1_00_00;
|
|
596
|
+
const high = 0xd8_00 + (offset >> 10);
|
|
597
|
+
const low = 0xdc_00 + (offset & 0x3ff);
|
|
598
|
+
out += `\\u${high.toString(16).padStart(4, '0')}\\u${low.toString(16).padStart(4, '0')}`;
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
out += `\\u${code.toString(16).padStart(4, '0')}`;
|
|
602
|
+
}
|
|
603
|
+
return out;
|
|
604
|
+
}
|
|
605
|
+
//# sourceMappingURL=desktop-wire.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Desktop-owned wrapper; the standalone server retains its headless lifecycle. */
|
|
2
|
+
import { runServerEntry } from '../server-entry.js';
|
|
3
|
+
import { installDesktopStopSources } from './desktop-session.js';
|
|
4
|
+
const parentPort = process.parentPort;
|
|
5
|
+
const stop = new AbortController();
|
|
6
|
+
const binding = installDesktopStopSources({ processEvents: process, stdin: process.stdin, stop,
|
|
7
|
+
...(parentPort === undefined ? {} : { parentPort }) });
|
|
8
|
+
const code = await runServerEntry({ stop, onDiagnostic: line => {
|
|
9
|
+
if (line.startsWith('[server-ready]'))
|
|
10
|
+
parentPort?.postMessage({ type: 'nova.phone.ready' });
|
|
11
|
+
else if (line.startsWith('[runtime-diagnostic]'))
|
|
12
|
+
process.stderr.write(`${line}\n`);
|
|
13
|
+
} });
|
|
14
|
+
binding.dispose();
|
|
15
|
+
await new Promise(resolve => process.stderr.write('', () => resolve()));
|
|
16
|
+
process.exit(code);
|
|
17
|
+
//# sourceMappingURL=phone-desktop-entry.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
const MAX_LENGTH = 296;
|
|
3
|
+
/** One terminal-safe line describing a startup exception, with the home directory and token-like strings removed. */
|
|
4
|
+
export function describeStartupError(error, home = homedir()) {
|
|
5
|
+
const code = error instanceof Error ? error.code : undefined;
|
|
6
|
+
const detail = error instanceof Error
|
|
7
|
+
? `${error.name}${typeof code === 'string' ? ` [${code}]` : ''}: ${error.message}`
|
|
8
|
+
: typeof error;
|
|
9
|
+
let line = detail.replace(/[\r\n]+/gu, ' ');
|
|
10
|
+
if (home.length > 1)
|
|
11
|
+
line = line.split(home).join('~');
|
|
12
|
+
line = line
|
|
13
|
+
.replace(/\b(Bearer|Basic)\s+\S+/giu, '$1 <redacted>')
|
|
14
|
+
.replace(/([?&](?:key|token|secret|password|api_key|access_token)=)[^\s&'"]+/giu, '$1<redacted>')
|
|
15
|
+
.replace(/[A-Za-z0-9_+=-]{32,}/gu, '<redacted>');
|
|
16
|
+
return line.slice(0, MAX_LENGTH);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=startup-error.js.map
|