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,586 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Correlates the unordered events belonging to one confirmation turn.
|
|
3
|
+
*
|
|
4
|
+
* This class deliberately makes no confirmation decision. Callers provide authority and choose
|
|
5
|
+
* their own policy; the isolation state only prevents an event from one epoch or user revision
|
|
6
|
+
* being associated with another.
|
|
7
|
+
*/
|
|
8
|
+
/** Owns bounded, instance-local correlation state for one potential confirmation turn. */
|
|
9
|
+
export class ConfirmationTurnIsolation {
|
|
10
|
+
#limit;
|
|
11
|
+
#authority = null;
|
|
12
|
+
#reservation = null;
|
|
13
|
+
#responses = new Map();
|
|
14
|
+
#initialResponseId = null;
|
|
15
|
+
#retryResponseId = null;
|
|
16
|
+
#pendingTranscript = null;
|
|
17
|
+
#deferredCalls = new Map();
|
|
18
|
+
#deferredCount = 0;
|
|
19
|
+
#responseFencePending = false;
|
|
20
|
+
constructor(limit) {
|
|
21
|
+
if (!isPositiveInteger(limit))
|
|
22
|
+
throw new TypeError('deferred call limit must be a positive integer');
|
|
23
|
+
this.#limit = limit;
|
|
24
|
+
}
|
|
25
|
+
get authority() {
|
|
26
|
+
return this.#authority;
|
|
27
|
+
}
|
|
28
|
+
get reservation() {
|
|
29
|
+
return this.#reservation;
|
|
30
|
+
}
|
|
31
|
+
get blocking() {
|
|
32
|
+
const response = this.#primaryResponse();
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
responseId: response?.responseId ?? null,
|
|
35
|
+
closing: response?.closing ?? false,
|
|
36
|
+
quarantined: response?.quarantined ?? false,
|
|
37
|
+
transcript: response?.transcript ?? null,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
get blockedResponses() {
|
|
41
|
+
return [...this.#responses.values()]
|
|
42
|
+
.filter(response => response.blocked)
|
|
43
|
+
.map(responseView);
|
|
44
|
+
}
|
|
45
|
+
get responseFencePending() {
|
|
46
|
+
return this.#responseFencePending;
|
|
47
|
+
}
|
|
48
|
+
/** The bounded number of opaque calls that are still awaiting an exact response binding. */
|
|
49
|
+
get deferredCallCount() {
|
|
50
|
+
return this.#deferredCount;
|
|
51
|
+
}
|
|
52
|
+
/** Replace all local state with immutable authority for a new turn. */
|
|
53
|
+
beginAuthority(input) {
|
|
54
|
+
validateAuthority(input);
|
|
55
|
+
const authority = Object.freeze({
|
|
56
|
+
authorityId: input.authorityId,
|
|
57
|
+
sessionEpoch: input.sessionEpoch,
|
|
58
|
+
createdUserRevision: input.createdUserRevision,
|
|
59
|
+
expiresAt: input.expiresAt,
|
|
60
|
+
});
|
|
61
|
+
this.#clear();
|
|
62
|
+
this.#authority = authority;
|
|
63
|
+
return authority;
|
|
64
|
+
}
|
|
65
|
+
/** Reserve exactly one later user item; a newer rival revision stales the old reservation. */
|
|
66
|
+
reserveUserItem(input) {
|
|
67
|
+
if (!isItemIdentity(input) || !this.#isPostAuthority(input.sessionEpoch, input.userRevision)) {
|
|
68
|
+
return 'refused';
|
|
69
|
+
}
|
|
70
|
+
const reserved = this.#reservation;
|
|
71
|
+
if (reserved === null) {
|
|
72
|
+
this.#reservation = freezeReservation(input);
|
|
73
|
+
return 'reserved';
|
|
74
|
+
}
|
|
75
|
+
if (reserved.sessionEpoch === input.sessionEpoch
|
|
76
|
+
&& reserved.itemId === input.itemId
|
|
77
|
+
&& reserved.userRevision === input.userRevision)
|
|
78
|
+
return 'idempotent';
|
|
79
|
+
if (input.userRevision <= reserved.userRevision)
|
|
80
|
+
return 'refused';
|
|
81
|
+
this.#clearReservation();
|
|
82
|
+
return 'stale';
|
|
83
|
+
}
|
|
84
|
+
/** Bind an exact response to the reserved user item. The first binding is immutable. */
|
|
85
|
+
bindResponse(input) {
|
|
86
|
+
if (!isResponseBindingIdentity(input) || !this.#matchesReservation(input))
|
|
87
|
+
return 'stale';
|
|
88
|
+
const reservation = this.#reservation;
|
|
89
|
+
if (reservation === null)
|
|
90
|
+
return 'stale';
|
|
91
|
+
if (this.#initialResponseId !== null) {
|
|
92
|
+
return this.#initialResponseId === input.responseId ? 'idempotent' : 'stale';
|
|
93
|
+
}
|
|
94
|
+
if (!this.#ensureResponseCapacity(input.sessionEpoch, input.responseId))
|
|
95
|
+
return 'stale';
|
|
96
|
+
const key = deferredKey(input.sessionEpoch, input.userRevision, input.responseId);
|
|
97
|
+
const calls = this.#deferredCalls.get(key);
|
|
98
|
+
this.#deferredCalls.clear();
|
|
99
|
+
this.#deferredCount = 0;
|
|
100
|
+
if (calls !== undefined) {
|
|
101
|
+
this.#deferredCalls.set(key, calls);
|
|
102
|
+
this.#deferredCount = calls.length;
|
|
103
|
+
}
|
|
104
|
+
const pendingTranscript = this.#pendingTranscript;
|
|
105
|
+
this.#pendingTranscript = null;
|
|
106
|
+
const existing = this.#responses.get(responseKey(input.sessionEpoch, input.responseId));
|
|
107
|
+
this.#responses.set(responseKey(input.sessionEpoch, input.responseId), {
|
|
108
|
+
sessionEpoch: input.sessionEpoch,
|
|
109
|
+
itemId: input.itemId,
|
|
110
|
+
userRevision: input.userRevision,
|
|
111
|
+
responseId: input.responseId,
|
|
112
|
+
authorizationCarrier: true,
|
|
113
|
+
provisional: false,
|
|
114
|
+
terminal: existing?.terminal ?? false,
|
|
115
|
+
blocked: existing?.blocked ?? false,
|
|
116
|
+
closing: existing?.closing ?? false,
|
|
117
|
+
quarantined: existing?.quarantined ?? false,
|
|
118
|
+
transcript: pendingTranscript !== null && matchesPendingTranscript(pendingTranscript, input)
|
|
119
|
+
? pendingTranscript.transcript
|
|
120
|
+
: 'pending',
|
|
121
|
+
});
|
|
122
|
+
this.#initialResponseId = input.responseId;
|
|
123
|
+
this.#reservation = Object.freeze({
|
|
124
|
+
sessionEpoch: reservation.sessionEpoch,
|
|
125
|
+
itemId: reservation.itemId,
|
|
126
|
+
userRevision: reservation.userRevision,
|
|
127
|
+
responseId: input.responseId,
|
|
128
|
+
});
|
|
129
|
+
return 'bound';
|
|
130
|
+
}
|
|
131
|
+
/** Bind another exact response to the same reservation; the caller owns retry policy. */
|
|
132
|
+
bindRetryResponse(input) {
|
|
133
|
+
if (!isResponseBindingIdentity(input) || !this.#matchesReservation(input))
|
|
134
|
+
return 'stale';
|
|
135
|
+
if (this.#initialResponseId === null || input.responseId === this.#initialResponseId)
|
|
136
|
+
return 'stale';
|
|
137
|
+
if (this.#retryResponseId !== null) {
|
|
138
|
+
return this.#retryResponseId === input.responseId ? 'idempotent' : 'stale';
|
|
139
|
+
}
|
|
140
|
+
if (!this.#ensureResponseCapacity(input.sessionEpoch, input.responseId))
|
|
141
|
+
return 'stale';
|
|
142
|
+
const key = responseKey(input.sessionEpoch, input.responseId);
|
|
143
|
+
const existing = this.#responses.get(key);
|
|
144
|
+
this.#responses.set(key, {
|
|
145
|
+
sessionEpoch: input.sessionEpoch,
|
|
146
|
+
itemId: input.itemId,
|
|
147
|
+
userRevision: input.userRevision,
|
|
148
|
+
responseId: input.responseId,
|
|
149
|
+
authorizationCarrier: true,
|
|
150
|
+
provisional: false,
|
|
151
|
+
terminal: existing?.terminal ?? false,
|
|
152
|
+
blocked: existing?.blocked ?? false,
|
|
153
|
+
closing: existing?.closing ?? false,
|
|
154
|
+
quarantined: existing?.quarantined ?? false,
|
|
155
|
+
transcript: 'pending',
|
|
156
|
+
});
|
|
157
|
+
this.#retryResponseId = input.responseId;
|
|
158
|
+
return 'bound';
|
|
159
|
+
}
|
|
160
|
+
/** Taint one exact response for service-level blocking without granting it authority. */
|
|
161
|
+
markBlockedResponse(input) {
|
|
162
|
+
if (!isResponseIdentity(input) || this.#authority?.sessionEpoch !== input.sessionEpoch) {
|
|
163
|
+
return 'stale';
|
|
164
|
+
}
|
|
165
|
+
const key = responseKey(input.sessionEpoch, input.responseId);
|
|
166
|
+
const existing = this.#responses.get(key);
|
|
167
|
+
if (existing !== undefined) {
|
|
168
|
+
if (existing.blocked)
|
|
169
|
+
return 'idempotent';
|
|
170
|
+
existing.blocked = true;
|
|
171
|
+
return 'tracked';
|
|
172
|
+
}
|
|
173
|
+
if (this.#responses.size >= this.#limit)
|
|
174
|
+
return 'overflow';
|
|
175
|
+
this.#responses.set(key, {
|
|
176
|
+
sessionEpoch: input.sessionEpoch,
|
|
177
|
+
responseId: input.responseId,
|
|
178
|
+
itemId: null,
|
|
179
|
+
userRevision: null,
|
|
180
|
+
authorizationCarrier: false,
|
|
181
|
+
provisional: false,
|
|
182
|
+
terminal: false,
|
|
183
|
+
blocked: true,
|
|
184
|
+
closing: false,
|
|
185
|
+
quarantined: false,
|
|
186
|
+
transcript: null,
|
|
187
|
+
});
|
|
188
|
+
return 'tracked';
|
|
189
|
+
}
|
|
190
|
+
isBlockedResponse(input) {
|
|
191
|
+
return isResponseIdentity(input)
|
|
192
|
+
&& this.#responses.get(responseKey(input.sessionEpoch, input.responseId))?.blocked === true;
|
|
193
|
+
}
|
|
194
|
+
/** Track one silent response that may belong to the next final-only user item. */
|
|
195
|
+
trackProvisionalResponse(input) {
|
|
196
|
+
if (!isDeferredCallIdentity(input)
|
|
197
|
+
|| this.#reservation !== null
|
|
198
|
+
|| !this.#isPostAuthority(input.sessionEpoch, input.userRevision))
|
|
199
|
+
return 'stale';
|
|
200
|
+
const key = responseKey(input.sessionEpoch, input.responseId);
|
|
201
|
+
const existing = this.#responses.get(key);
|
|
202
|
+
if (existing !== undefined) {
|
|
203
|
+
return existing.provisional && existing.userRevision === input.userRevision
|
|
204
|
+
? 'idempotent'
|
|
205
|
+
: 'stale';
|
|
206
|
+
}
|
|
207
|
+
if (this.#responses.size >= this.#limit)
|
|
208
|
+
return 'overflow';
|
|
209
|
+
this.#responses.set(key, {
|
|
210
|
+
sessionEpoch: input.sessionEpoch,
|
|
211
|
+
responseId: input.responseId,
|
|
212
|
+
itemId: null,
|
|
213
|
+
userRevision: input.userRevision,
|
|
214
|
+
authorizationCarrier: false,
|
|
215
|
+
provisional: true,
|
|
216
|
+
terminal: false,
|
|
217
|
+
blocked: true,
|
|
218
|
+
closing: false,
|
|
219
|
+
quarantined: false,
|
|
220
|
+
transcript: null,
|
|
221
|
+
});
|
|
222
|
+
return 'tracked';
|
|
223
|
+
}
|
|
224
|
+
/** Hold a structured call only for an already tracked final-only response. */
|
|
225
|
+
deferProvisionalCall(input) {
|
|
226
|
+
if (!isResponseIdentity(input))
|
|
227
|
+
return 'stale';
|
|
228
|
+
const response = this.#responses.get(responseKey(input.sessionEpoch, input.responseId));
|
|
229
|
+
if (!response?.provisional || response.userRevision === null)
|
|
230
|
+
return 'stale';
|
|
231
|
+
return this.deferCall({
|
|
232
|
+
sessionEpoch: input.sessionEpoch,
|
|
233
|
+
userRevision: response.userRevision,
|
|
234
|
+
responseId: input.responseId,
|
|
235
|
+
call: input.call,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/** Retain a terminal provisional response until its unordered user item arrives. */
|
|
239
|
+
markProvisionalTerminal(input) {
|
|
240
|
+
if (!isResponseIdentity(input))
|
|
241
|
+
return false;
|
|
242
|
+
const response = this.#responses.get(responseKey(input.sessionEpoch, input.responseId));
|
|
243
|
+
if (response?.provisional !== true)
|
|
244
|
+
return false;
|
|
245
|
+
response.terminal = true;
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
/** Bind the only exact provisional response to the now-revealed reserved item. */
|
|
249
|
+
bindProvisionalResponse() {
|
|
250
|
+
const reservation = this.#reservation;
|
|
251
|
+
if (reservation === null || this.#initialResponseId !== null)
|
|
252
|
+
return { kind: 'none' };
|
|
253
|
+
const candidates = [...this.#responses.values()].filter(response => (response.provisional
|
|
254
|
+
&& response.sessionEpoch === reservation.sessionEpoch
|
|
255
|
+
&& response.userRevision === reservation.userRevision));
|
|
256
|
+
const withCalls = candidates.filter(response => this.#deferredCalls.has(deferredKey(response.sessionEpoch, reservation.userRevision, response.responseId)));
|
|
257
|
+
const eligible = withCalls.length > 0 ? withCalls : candidates;
|
|
258
|
+
if (eligible.length === 0)
|
|
259
|
+
return { kind: 'none' };
|
|
260
|
+
if (eligible.length !== 1)
|
|
261
|
+
return { kind: 'ambiguous' };
|
|
262
|
+
const response = eligible[0];
|
|
263
|
+
const result = this.bindResponse({
|
|
264
|
+
sessionEpoch: reservation.sessionEpoch,
|
|
265
|
+
itemId: reservation.itemId,
|
|
266
|
+
userRevision: reservation.userRevision,
|
|
267
|
+
responseId: response.responseId,
|
|
268
|
+
});
|
|
269
|
+
return result === 'bound' || result === 'idempotent'
|
|
270
|
+
? { kind: 'bound', responseId: response.responseId, terminal: response.terminal }
|
|
271
|
+
: { kind: 'none' };
|
|
272
|
+
}
|
|
273
|
+
hasBlockedResponseInEpoch(sessionEpoch) {
|
|
274
|
+
if (!isEpoch(sessionEpoch))
|
|
275
|
+
return false;
|
|
276
|
+
return [...this.#responses.values()]
|
|
277
|
+
.some(response => response.sessionEpoch === sessionEpoch && response.blocked);
|
|
278
|
+
}
|
|
279
|
+
isAuthorizationCarrier(input) {
|
|
280
|
+
if (!isDeferredCallIdentity(input))
|
|
281
|
+
return false;
|
|
282
|
+
const reservation = this.#reservation;
|
|
283
|
+
return reservation !== null
|
|
284
|
+
&& reservation.sessionEpoch === input.sessionEpoch
|
|
285
|
+
&& reservation.userRevision === input.userRevision
|
|
286
|
+
&& (input.responseId === this.#initialResponseId || input.responseId === this.#retryResponseId);
|
|
287
|
+
}
|
|
288
|
+
responseState(input) {
|
|
289
|
+
if (!isResponseIdentity(input))
|
|
290
|
+
return null;
|
|
291
|
+
const response = this.#responses.get(responseKey(input.sessionEpoch, input.responseId));
|
|
292
|
+
return response === undefined ? null : responseView(response);
|
|
293
|
+
}
|
|
294
|
+
/** Track whether an exact not-yet-started response is still fenced. */
|
|
295
|
+
setResponseFencePending(pending) {
|
|
296
|
+
if (typeof pending !== 'boolean' || (pending && this.#authority === null))
|
|
297
|
+
return false;
|
|
298
|
+
this.#responseFencePending = pending;
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
/** Hold an opaque structured call until its current response is bound, subject to one fixed bound. */
|
|
302
|
+
deferCall(input) {
|
|
303
|
+
if (!isDeferredCallIdentity(input) || !this.#matchesDeferredTurn(input))
|
|
304
|
+
return 'stale';
|
|
305
|
+
if (this.#deferredCount >= this.#limit)
|
|
306
|
+
return 'overflow';
|
|
307
|
+
const key = deferredKey(input.sessionEpoch, input.userRevision, input.responseId);
|
|
308
|
+
const calls = this.#deferredCalls.get(key);
|
|
309
|
+
if (calls === undefined)
|
|
310
|
+
this.#deferredCalls.set(key, [input.call]);
|
|
311
|
+
else
|
|
312
|
+
calls.push(input.call);
|
|
313
|
+
this.#deferredCount += 1;
|
|
314
|
+
return 'deferred';
|
|
315
|
+
}
|
|
316
|
+
/** Release the calls for one already-bound response exactly once. */
|
|
317
|
+
releaseCallsForResponse(input) {
|
|
318
|
+
if (!isDeferredCallIdentity(input) || !this.#matchesResponse(input))
|
|
319
|
+
return [];
|
|
320
|
+
const key = deferredKey(input.sessionEpoch, input.userRevision, input.responseId);
|
|
321
|
+
const calls = this.#deferredCalls.get(key);
|
|
322
|
+
if (calls === undefined)
|
|
323
|
+
return [];
|
|
324
|
+
this.#deferredCalls.delete(key);
|
|
325
|
+
this.#deferredCount -= calls.length;
|
|
326
|
+
return [...calls];
|
|
327
|
+
}
|
|
328
|
+
/** Atomically abandon deferred calls outside an optional exact turn or response identity. */
|
|
329
|
+
takeAbandonedCalls(keep) {
|
|
330
|
+
if (keep !== undefined
|
|
331
|
+
&& (!isEpoch(keep.sessionEpoch)
|
|
332
|
+
|| !isRevision(keep.userRevision)
|
|
333
|
+
|| (keep.responseId !== undefined && !isNonemptyString(keep.responseId))))
|
|
334
|
+
return [];
|
|
335
|
+
const retainedPrefix = keep === undefined
|
|
336
|
+
? null
|
|
337
|
+
: `${keep.sessionEpoch}:${keep.userRevision}:`;
|
|
338
|
+
const retainedKey = keep?.responseId === undefined
|
|
339
|
+
? null
|
|
340
|
+
: deferredKey(keep.sessionEpoch, keep.userRevision, keep.responseId);
|
|
341
|
+
const abandoned = [];
|
|
342
|
+
for (const [key, calls] of this.#deferredCalls) {
|
|
343
|
+
const retained = retainedKey === null
|
|
344
|
+
? retainedPrefix !== null && key.startsWith(retainedPrefix)
|
|
345
|
+
: key === retainedKey;
|
|
346
|
+
if (retained)
|
|
347
|
+
continue;
|
|
348
|
+
abandoned.push(...calls);
|
|
349
|
+
this.#deferredCalls.delete(key);
|
|
350
|
+
this.#deferredCount -= calls.length;
|
|
351
|
+
}
|
|
352
|
+
return abandoned;
|
|
353
|
+
}
|
|
354
|
+
/** Record text-free transcript correlation metadata for the exact current response. */
|
|
355
|
+
markResponse(input) {
|
|
356
|
+
if (!isDeferredCallIdentity(input) || !isTranscript(input.transcript))
|
|
357
|
+
return false;
|
|
358
|
+
const response = this.#responseForCarrier(input);
|
|
359
|
+
if (response !== null) {
|
|
360
|
+
response.transcript = input.transcript;
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
if (!this.#matchesDeferredTurn(input))
|
|
364
|
+
return false;
|
|
365
|
+
const pending = this.#pendingTranscript;
|
|
366
|
+
if (pending !== null && !matchesPendingTranscript(pending, input))
|
|
367
|
+
return false;
|
|
368
|
+
this.#pendingTranscript = Object.freeze({
|
|
369
|
+
sessionEpoch: input.sessionEpoch,
|
|
370
|
+
userRevision: input.userRevision,
|
|
371
|
+
responseId: input.responseId,
|
|
372
|
+
transcript: input.transcript,
|
|
373
|
+
});
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
/** Mark service-level closing state for the exact current response. */
|
|
377
|
+
beginClosing(input) {
|
|
378
|
+
const response = this.#responseForIdentity(input);
|
|
379
|
+
if (response === null)
|
|
380
|
+
return false;
|
|
381
|
+
response.closing = true;
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
/** Clear service-level closing state for the exact current response. */
|
|
385
|
+
endClosing(input) {
|
|
386
|
+
const response = this.#responseForIdentity(input);
|
|
387
|
+
if (response?.closing !== true)
|
|
388
|
+
return false;
|
|
389
|
+
response.closing = false;
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
/** Mark an exact current response as quarantined without invoking provider policy. */
|
|
393
|
+
markQuarantined(input) {
|
|
394
|
+
const response = this.#responseForIdentity(input);
|
|
395
|
+
if (response === null)
|
|
396
|
+
return false;
|
|
397
|
+
response.quarantined = true;
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
clearQuarantined(input) {
|
|
401
|
+
const response = this.#responseForIdentity(input);
|
|
402
|
+
if (response?.quarantined !== true)
|
|
403
|
+
return false;
|
|
404
|
+
response.quarantined = false;
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
/** Release only item authority while retaining response cleanup records until terminal. */
|
|
408
|
+
releaseReservation(input) {
|
|
409
|
+
if (!isItemIdentity(input) || !this.#matchesReservation(input))
|
|
410
|
+
return false;
|
|
411
|
+
this.#reservation = null;
|
|
412
|
+
this.#initialResponseId = null;
|
|
413
|
+
this.#retryResponseId = null;
|
|
414
|
+
this.#pendingTranscript = null;
|
|
415
|
+
this.#deferredCalls.clear();
|
|
416
|
+
this.#deferredCount = 0;
|
|
417
|
+
this.#responseFencePending = false;
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
/** Clear one terminal response without releasing the authority or reserved item. */
|
|
421
|
+
clearResponse(input) {
|
|
422
|
+
if (!isResponseIdentity(input))
|
|
423
|
+
return false;
|
|
424
|
+
const key = responseKey(input.sessionEpoch, input.responseId);
|
|
425
|
+
const changed = this.#responses.delete(key);
|
|
426
|
+
const pending = this.#pendingTranscript;
|
|
427
|
+
if (pending?.sessionEpoch === input.sessionEpoch && pending.responseId === input.responseId) {
|
|
428
|
+
this.#pendingTranscript = null;
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
return changed;
|
|
432
|
+
}
|
|
433
|
+
/** Invalidate all correlations when the containing session is replaced. */
|
|
434
|
+
invalidate() {
|
|
435
|
+
const changed = this.#authority !== null || this.#reservation !== null || this.#responses.size !== 0
|
|
436
|
+
|| this.#deferredCount !== 0 || this.#responseFencePending;
|
|
437
|
+
this.#clear();
|
|
438
|
+
return changed;
|
|
439
|
+
}
|
|
440
|
+
#isPostAuthority(sessionEpoch, userRevision) {
|
|
441
|
+
const authority = this.#authority;
|
|
442
|
+
return authority !== null
|
|
443
|
+
&& authority.sessionEpoch === sessionEpoch
|
|
444
|
+
&& userRevision > authority.createdUserRevision;
|
|
445
|
+
}
|
|
446
|
+
#matchesReservation(input) {
|
|
447
|
+
const reservation = this.#reservation;
|
|
448
|
+
return reservation !== null
|
|
449
|
+
&& reservation.sessionEpoch === input.sessionEpoch
|
|
450
|
+
&& reservation.itemId === input.itemId
|
|
451
|
+
&& reservation.userRevision === input.userRevision;
|
|
452
|
+
}
|
|
453
|
+
#matchesDeferredTurn(input) {
|
|
454
|
+
const reservation = this.#reservation;
|
|
455
|
+
if (reservation === null)
|
|
456
|
+
return this.#isPostAuthority(input.sessionEpoch, input.userRevision);
|
|
457
|
+
return reservation.responseId === null
|
|
458
|
+
&& reservation.sessionEpoch === input.sessionEpoch
|
|
459
|
+
&& reservation.userRevision === input.userRevision;
|
|
460
|
+
}
|
|
461
|
+
#matchesResponse(input) {
|
|
462
|
+
const response = this.#responseForCarrier(input);
|
|
463
|
+
return response !== null
|
|
464
|
+
&& response.sessionEpoch === input.sessionEpoch
|
|
465
|
+
&& response.userRevision === input.userRevision
|
|
466
|
+
&& response.responseId === input.responseId
|
|
467
|
+
&& (input.itemId === undefined || response.itemId === input.itemId);
|
|
468
|
+
}
|
|
469
|
+
#clearReservation() {
|
|
470
|
+
this.#reservation = null;
|
|
471
|
+
this.#responses.clear();
|
|
472
|
+
this.#initialResponseId = null;
|
|
473
|
+
this.#retryResponseId = null;
|
|
474
|
+
this.#pendingTranscript = null;
|
|
475
|
+
this.#deferredCalls.clear();
|
|
476
|
+
this.#deferredCount = 0;
|
|
477
|
+
this.#responseFencePending = false;
|
|
478
|
+
}
|
|
479
|
+
#clear() {
|
|
480
|
+
this.#authority = null;
|
|
481
|
+
this.#clearReservation();
|
|
482
|
+
}
|
|
483
|
+
#primaryResponse() {
|
|
484
|
+
const epoch = this.#reservation?.sessionEpoch;
|
|
485
|
+
if (epoch === undefined)
|
|
486
|
+
return null;
|
|
487
|
+
if (this.#initialResponseId !== null) {
|
|
488
|
+
const initial = this.#responses.get(responseKey(epoch, this.#initialResponseId));
|
|
489
|
+
if (initial !== undefined)
|
|
490
|
+
return initial;
|
|
491
|
+
}
|
|
492
|
+
if (this.#retryResponseId !== null) {
|
|
493
|
+
return this.#responses.get(responseKey(epoch, this.#retryResponseId)) ?? null;
|
|
494
|
+
}
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
#responseForCarrier(input) {
|
|
498
|
+
if (!isDeferredCallIdentity(input))
|
|
499
|
+
return null;
|
|
500
|
+
const response = this.#responses.get(responseKey(input.sessionEpoch, input.responseId));
|
|
501
|
+
return response?.authorizationCarrier === true && response.userRevision === input.userRevision
|
|
502
|
+
? response
|
|
503
|
+
: null;
|
|
504
|
+
}
|
|
505
|
+
#responseForIdentity(input) {
|
|
506
|
+
if (!isResponseIdentity(input))
|
|
507
|
+
return null;
|
|
508
|
+
const response = this.#responses.get(responseKey(input.sessionEpoch, input.responseId));
|
|
509
|
+
if (response === undefined)
|
|
510
|
+
return null;
|
|
511
|
+
return input.userRevision === undefined || response.userRevision === input.userRevision
|
|
512
|
+
? response
|
|
513
|
+
: null;
|
|
514
|
+
}
|
|
515
|
+
#ensureResponseCapacity(sessionEpoch, responseId) {
|
|
516
|
+
return this.#responses.has(responseKey(sessionEpoch, responseId)) || this.#responses.size < this.#limit;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function freezeReservation(input) {
|
|
520
|
+
return Object.freeze({
|
|
521
|
+
sessionEpoch: input.sessionEpoch,
|
|
522
|
+
itemId: input.itemId,
|
|
523
|
+
userRevision: input.userRevision,
|
|
524
|
+
responseId: null,
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
function deferredKey(sessionEpoch, userRevision, responseId) {
|
|
528
|
+
return `${sessionEpoch}:${userRevision}:${responseId}`;
|
|
529
|
+
}
|
|
530
|
+
function responseKey(sessionEpoch, responseId) {
|
|
531
|
+
return `${sessionEpoch}:${responseId}`;
|
|
532
|
+
}
|
|
533
|
+
function responseView(response) {
|
|
534
|
+
return Object.freeze({
|
|
535
|
+
sessionEpoch: response.sessionEpoch,
|
|
536
|
+
responseId: response.responseId,
|
|
537
|
+
userRevision: response.userRevision,
|
|
538
|
+
authorizationCarrier: response.authorizationCarrier,
|
|
539
|
+
blocked: response.blocked,
|
|
540
|
+
closing: response.closing,
|
|
541
|
+
quarantined: response.quarantined,
|
|
542
|
+
transcript: response.transcript,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
function matchesPendingTranscript(pending, input) {
|
|
546
|
+
return pending.sessionEpoch === input.sessionEpoch
|
|
547
|
+
&& pending.userRevision === input.userRevision
|
|
548
|
+
&& pending.responseId === input.responseId;
|
|
549
|
+
}
|
|
550
|
+
function validateAuthority(input) {
|
|
551
|
+
if (input === null
|
|
552
|
+
|| typeof input !== 'object'
|
|
553
|
+
|| !isNonemptyString(input.authorityId)
|
|
554
|
+
|| !isEpoch(input.sessionEpoch)
|
|
555
|
+
|| !isRevision(input.createdUserRevision)
|
|
556
|
+
|| !Number.isFinite(input.expiresAt))
|
|
557
|
+
throw new TypeError('invalid confirmation authority');
|
|
558
|
+
}
|
|
559
|
+
function isItemIdentity(input) {
|
|
560
|
+
return isEpoch(input.sessionEpoch) && isNonemptyString(input.itemId) && isRevision(input.userRevision);
|
|
561
|
+
}
|
|
562
|
+
function isResponseBindingIdentity(input) {
|
|
563
|
+
return isItemIdentity(input) && isNonemptyString(input.responseId);
|
|
564
|
+
}
|
|
565
|
+
function isDeferredCallIdentity(input) {
|
|
566
|
+
return isEpoch(input.sessionEpoch) && isRevision(input.userRevision) && isNonemptyString(input.responseId);
|
|
567
|
+
}
|
|
568
|
+
function isResponseIdentity(input) {
|
|
569
|
+
return isEpoch(input.sessionEpoch) && isNonemptyString(input.responseId);
|
|
570
|
+
}
|
|
571
|
+
function isPositiveInteger(value) {
|
|
572
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
573
|
+
}
|
|
574
|
+
function isEpoch(value) {
|
|
575
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
576
|
+
}
|
|
577
|
+
function isRevision(value) {
|
|
578
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
579
|
+
}
|
|
580
|
+
function isNonemptyString(value) {
|
|
581
|
+
return typeof value === 'string' && value !== '';
|
|
582
|
+
}
|
|
583
|
+
function isTranscript(value) {
|
|
584
|
+
return value === 'completed' || value === 'failed';
|
|
585
|
+
}
|
|
586
|
+
//# sourceMappingURL=confirmation-turn-isolation.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class DictationError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = 'DictationError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Below this peak (of 32768) a recording is digital silence: the microphone delivered nothing. */
|
|
10
|
+
export const DICTATION_SILENCE_PEAK = 64;
|
|
11
|
+
/** 0.2 s of PCM16 mono at 16 kHz; shorter presses cannot contain a word. */
|
|
12
|
+
export const DICTATION_MIN_BYTES = 6400;
|
|
13
|
+
export function pcmLevel(pcm) {
|
|
14
|
+
const samples = pcm.length >> 1;
|
|
15
|
+
if (samples === 0)
|
|
16
|
+
return { peak: 0, rms: 0 };
|
|
17
|
+
const view = new DataView(pcm.buffer, pcm.byteOffset, samples * 2);
|
|
18
|
+
let peak = 0, sum = 0;
|
|
19
|
+
for (let index = 0; index < samples; index++) {
|
|
20
|
+
const value = view.getInt16(index * 2, true);
|
|
21
|
+
const magnitude = Math.abs(value);
|
|
22
|
+
if (magnitude > peak)
|
|
23
|
+
peak = magnitude;
|
|
24
|
+
sum += value * value;
|
|
25
|
+
}
|
|
26
|
+
return { peak, rms: Math.round(Math.sqrt(sum / samples)) };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=dictation.js.map
|