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,139 @@
|
|
|
1
|
+
export class VirtualClock {
|
|
2
|
+
#waiters = [];
|
|
3
|
+
#current;
|
|
4
|
+
#sequence = 0;
|
|
5
|
+
constructor(start = 0) {
|
|
6
|
+
requireNotNaN(start, 'virtual clock start');
|
|
7
|
+
this.#current = start;
|
|
8
|
+
}
|
|
9
|
+
now() {
|
|
10
|
+
return this.#current;
|
|
11
|
+
}
|
|
12
|
+
sleep(duration, signal) {
|
|
13
|
+
requireNotNaN(duration, 'sleep duration');
|
|
14
|
+
if (duration < 0)
|
|
15
|
+
throw new RangeError(`sleep duration cannot be negative: ${duration}`);
|
|
16
|
+
if (signal?.aborted === true)
|
|
17
|
+
return Promise.reject(abortError());
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
this.#sequence += 1;
|
|
20
|
+
const waiter = {
|
|
21
|
+
due: this.#current + duration,
|
|
22
|
+
sequence: this.#sequence,
|
|
23
|
+
resolve,
|
|
24
|
+
reject,
|
|
25
|
+
signal,
|
|
26
|
+
onAbort: undefined,
|
|
27
|
+
settled: false,
|
|
28
|
+
};
|
|
29
|
+
waiter.onAbort = () => {
|
|
30
|
+
if (waiter.settled)
|
|
31
|
+
return;
|
|
32
|
+
waiter.settled = true;
|
|
33
|
+
waiter.reject(abortError());
|
|
34
|
+
this.#discardSettled();
|
|
35
|
+
};
|
|
36
|
+
signal?.addEventListener('abort', waiter.onAbort, { once: true });
|
|
37
|
+
this.#waiters.push(waiter);
|
|
38
|
+
this.#waiters.sort(compareWaiters);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
waiterCount() {
|
|
42
|
+
return this.#waiters.reduce((count, waiter) => count + Number(!waiter.settled), 0);
|
|
43
|
+
}
|
|
44
|
+
nextTimerTimestamp() {
|
|
45
|
+
const waiter = this.#waiters.find(candidate => !candidate.settled);
|
|
46
|
+
return waiter === undefined || !Number.isFinite(waiter.due) ? undefined : waiter.due;
|
|
47
|
+
}
|
|
48
|
+
advanceTo(timestamp) {
|
|
49
|
+
requireNotNaN(timestamp, 'virtual clock timestamp');
|
|
50
|
+
if (timestamp < this.#current) {
|
|
51
|
+
throw new RangeError(`virtual clock cannot move backwards: ${this.#current} -> ${timestamp}`);
|
|
52
|
+
}
|
|
53
|
+
this.#current = timestamp;
|
|
54
|
+
for (const waiter of this.#waiters) {
|
|
55
|
+
if (waiter.settled || waiter.due > timestamp)
|
|
56
|
+
continue;
|
|
57
|
+
waiter.settled = true;
|
|
58
|
+
if (waiter.onAbort !== undefined) {
|
|
59
|
+
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
60
|
+
}
|
|
61
|
+
waiter.resolve();
|
|
62
|
+
}
|
|
63
|
+
this.#discardSettled();
|
|
64
|
+
}
|
|
65
|
+
#discardSettled() {
|
|
66
|
+
for (let index = this.#waiters.length - 1; index >= 0; index -= 1) {
|
|
67
|
+
if (this.#waiters[index]?.settled === true)
|
|
68
|
+
this.#waiters.splice(index, 1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class RealClock {
|
|
73
|
+
now() {
|
|
74
|
+
return performance.now() / 1000;
|
|
75
|
+
}
|
|
76
|
+
async sleep(duration, signal) {
|
|
77
|
+
if (!Number.isFinite(duration) || duration < 0) {
|
|
78
|
+
throw new RangeError(`sleep duration must be a non-negative finite number: ${duration}`);
|
|
79
|
+
}
|
|
80
|
+
if (signal?.aborted === true)
|
|
81
|
+
throw abortError();
|
|
82
|
+
await new Promise((resolve, reject) => {
|
|
83
|
+
const onAbort = () => {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
signal?.removeEventListener('abort', onAbort);
|
|
86
|
+
reject(abortError());
|
|
87
|
+
};
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
signal?.removeEventListener('abort', onAbort);
|
|
90
|
+
resolve();
|
|
91
|
+
}, duration * 1000);
|
|
92
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function compareWaiters(left, right) {
|
|
97
|
+
return left.due - right.due || left.sequence - right.sequence;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reject NaN and non-numbers, but deliberately allow the infinities.
|
|
101
|
+
*
|
|
102
|
+
* `sleep(Infinity)` is the "park until the clock is advanced past everything"
|
|
103
|
+
* primitive the runtime uses for an unbounded wait, and `nextTimerTimestamp`
|
|
104
|
+
* filters those waiters out rather than reporting a non-finite deadline. NaN has
|
|
105
|
+
* no such use and would silently corrupt every ordering comparison.
|
|
106
|
+
*/
|
|
107
|
+
function requireNotNaN(value, field) {
|
|
108
|
+
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
109
|
+
throw new TypeError(`${field} must be a number and cannot be NaN`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function abortError() {
|
|
113
|
+
const error = new Error('sleep aborted');
|
|
114
|
+
error.name = 'AbortError';
|
|
115
|
+
return error;
|
|
116
|
+
}
|
|
117
|
+
/** Passive race; the caller retains operation cancellation and late-result ownership. */
|
|
118
|
+
export async function raceDeadline(work, clock, remaining, signal, timeoutError, abortFailure = timeoutError) {
|
|
119
|
+
const timer = new AbortController();
|
|
120
|
+
const candidates = [work];
|
|
121
|
+
if (remaining !== null)
|
|
122
|
+
candidates.push(clock.sleep(remaining, timer.signal).then(() => { throw timeoutError(); }));
|
|
123
|
+
let onAbort;
|
|
124
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
125
|
+
onAbort = () => reject(abortFailure());
|
|
126
|
+
if (signal?.aborted === true)
|
|
127
|
+
onAbort();
|
|
128
|
+
else
|
|
129
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
130
|
+
});
|
|
131
|
+
try {
|
|
132
|
+
return await Promise.race([...candidates, aborted]);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
timer.abort();
|
|
136
|
+
signal?.removeEventListener('abort', onAbort);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { canonicalJson } from '../text/canonical-json.js';
|
|
2
|
+
import { CONVERSATION_CHANNEL, } from './memory.js';
|
|
3
|
+
import { isSuggestionAvailable } from './suggestions.js';
|
|
4
|
+
export const RECENT_LIMIT = 5;
|
|
5
|
+
export const UNCOMPRESSED_LIMIT = 40;
|
|
6
|
+
export const PENDING_CHARACTER_LIMIT = 16000;
|
|
7
|
+
export const FRESH_WINDOW = 30;
|
|
8
|
+
export function compileContextView(memory, floor, now, options = {}) {
|
|
9
|
+
const channels = [...memory.channels.values()].map(channel => {
|
|
10
|
+
// Keep new evidence visible while compression is running or cooling down.
|
|
11
|
+
// ponytail: cap pending rows at 40; explicit overflow avoids an unbounded prompt.
|
|
12
|
+
const limit = Math.max(RECENT_LIMIT, Math.min(channel.uncompressed, UNCOMPRESSED_LIMIT));
|
|
13
|
+
let start = Math.max(0, channel.items.length - RECENT_LIMIT);
|
|
14
|
+
let extraCharacters = 0;
|
|
15
|
+
const earliest = Math.max(0, channel.items.length - limit);
|
|
16
|
+
while (start > earliest) {
|
|
17
|
+
const size = canonicalJson(channel.items[start - 1]).length;
|
|
18
|
+
if (extraCharacters + size > PENDING_CHARACTER_LIMIT)
|
|
19
|
+
break;
|
|
20
|
+
extraCharacters += size;
|
|
21
|
+
start--;
|
|
22
|
+
}
|
|
23
|
+
const recent = channel.items.slice(start);
|
|
24
|
+
const uncompressedOmitted = channel.items.filter(item => item.seq > channel.summaryThroughSequence
|
|
25
|
+
&& item.seq < (recent[0]?.seq ?? Infinity)).length;
|
|
26
|
+
return {
|
|
27
|
+
name: channel.name,
|
|
28
|
+
summary: channel.summary,
|
|
29
|
+
recent,
|
|
30
|
+
omitted: Math.max(channel.items.length - recent.length, 0),
|
|
31
|
+
...(channel.summary === null ? {} : { summary_through_seq: channel.summaryThroughSequence }),
|
|
32
|
+
...(uncompressedOmitted === 0 ? {} : { uncompressed_omitted: uncompressedOmitted }),
|
|
33
|
+
...(channel.restoredThroughSequence === 0 ? {} : { historical_through_seq: channel.restoredThroughSequence }),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
const inFlight = [...(options.inFlight ?? [])]
|
|
37
|
+
.sort(compareDelegates)
|
|
38
|
+
.map(delegate => compileInFlight(delegate, memory));
|
|
39
|
+
const affordances = [
|
|
40
|
+
...compileProbes(channels, options.manifests ?? []),
|
|
41
|
+
...compileSuggestions(options.suggestions ?? [], now, options.selectedSuggestion ?? null),
|
|
42
|
+
...compileUpdates(channels, now, options.freshWindow ?? FRESH_WINDOW),
|
|
43
|
+
];
|
|
44
|
+
return {
|
|
45
|
+
channels: structuredClone(channels),
|
|
46
|
+
in_flight: structuredClone(inFlight),
|
|
47
|
+
affordances: structuredClone(affordances),
|
|
48
|
+
floor,
|
|
49
|
+
now,
|
|
50
|
+
trigger_kind: options.triggerKind ?? null,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function compileProbes(channels, manifests) {
|
|
54
|
+
const manifestsByName = new Map(manifests.map(manifest => [manifest.name, manifest]));
|
|
55
|
+
const output = [];
|
|
56
|
+
for (const channel of channels) {
|
|
57
|
+
const manifest = manifestsByName.get(channel.name);
|
|
58
|
+
if (manifest === undefined || manifest.probe_policy === 'none')
|
|
59
|
+
continue;
|
|
60
|
+
for (const item of channel.recent.slice(-RECENT_LIMIT)) {
|
|
61
|
+
if (item.seq <= (channel.historical_through_seq ?? 0))
|
|
62
|
+
continue;
|
|
63
|
+
if (item.outcome !== 'unknown')
|
|
64
|
+
continue;
|
|
65
|
+
for (const operation of manifest.ops) {
|
|
66
|
+
if (!operation.readonly)
|
|
67
|
+
continue;
|
|
68
|
+
output.push({
|
|
69
|
+
source: 'probe',
|
|
70
|
+
ref: makeItemReference(item),
|
|
71
|
+
content: {
|
|
72
|
+
executor: manifest.name,
|
|
73
|
+
op: operation.name,
|
|
74
|
+
unknown: structuredClone(item.content),
|
|
75
|
+
},
|
|
76
|
+
conclusive: operation.verifies.includes(typeof item.content.op === 'string' ? item.content.op : ''),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return output;
|
|
82
|
+
}
|
|
83
|
+
function compileSuggestions(suggestions, now, selected) {
|
|
84
|
+
return suggestions.flatMap(suggestion => {
|
|
85
|
+
if (!isSuggestionAvailable(suggestion, now))
|
|
86
|
+
return [];
|
|
87
|
+
if (selected !== null && suggestion.id !== selected)
|
|
88
|
+
return [];
|
|
89
|
+
const content = {
|
|
90
|
+
kind: suggestion.kind,
|
|
91
|
+
salience: suggestion.salience,
|
|
92
|
+
evidence_refs: [...suggestion.evidence_refs],
|
|
93
|
+
suggestion: structuredClone(suggestion.content),
|
|
94
|
+
};
|
|
95
|
+
if (suggestion.id === selected)
|
|
96
|
+
content.selected = true;
|
|
97
|
+
return [{
|
|
98
|
+
source: 'suggestion',
|
|
99
|
+
ref: suggestion.id,
|
|
100
|
+
content,
|
|
101
|
+
conclusive: null,
|
|
102
|
+
}];
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function compileUpdates(channels, now, freshWindow) {
|
|
106
|
+
const output = [];
|
|
107
|
+
for (const channel of channels) {
|
|
108
|
+
if (channel.name === CONVERSATION_CHANNEL || channel.recent.length === 0)
|
|
109
|
+
continue;
|
|
110
|
+
const item = channel.recent.at(-1);
|
|
111
|
+
if (item.seq <= (channel.historical_through_seq ?? 0))
|
|
112
|
+
continue;
|
|
113
|
+
if (now - item.ts > freshWindow)
|
|
114
|
+
continue;
|
|
115
|
+
output.push({
|
|
116
|
+
source: 'channel_update',
|
|
117
|
+
ref: makeItemReference(item),
|
|
118
|
+
content: {
|
|
119
|
+
channel: channel.name,
|
|
120
|
+
ts: item.ts,
|
|
121
|
+
outcome: item.outcome,
|
|
122
|
+
observation: structuredClone(item.content),
|
|
123
|
+
},
|
|
124
|
+
conclusive: null,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return output;
|
|
128
|
+
}
|
|
129
|
+
function compileInFlight(delegate, memory) {
|
|
130
|
+
const policy = memory.policies.get(delegate.executor);
|
|
131
|
+
if (policy === undefined)
|
|
132
|
+
throw new Error(`missing policy for delegate executor: ${delegate.executor}`);
|
|
133
|
+
return {
|
|
134
|
+
delegate_id: delegate.delegate_id,
|
|
135
|
+
what: describeDelegate(delegate),
|
|
136
|
+
origin_ref: delegate.origin_ref,
|
|
137
|
+
dispatched_at: delegate.dispatched_at,
|
|
138
|
+
eta: delegate.dispatched_at + policy.typical_latency,
|
|
139
|
+
deadline: delegate.deadline,
|
|
140
|
+
routing_class: delegate.routing_class,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function describeDelegate(delegate) {
|
|
144
|
+
return `${delegate.executor}.${delegate.op}(${canonicalJson(delegate.request)})`;
|
|
145
|
+
}
|
|
146
|
+
function makeItemReference(item) {
|
|
147
|
+
return `${item.channel}:${item.seq}`;
|
|
148
|
+
}
|
|
149
|
+
function compareDelegates(left, right) {
|
|
150
|
+
return left.dispatched_at - right.dispatched_at
|
|
151
|
+
|| compareStrings(left.delegate_id, right.delegate_id);
|
|
152
|
+
}
|
|
153
|
+
function compareStrings(left, right) {
|
|
154
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=context-view.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observable effects the runtime emits, as runtime-owned contracts.
|
|
3
|
+
*
|
|
4
|
+
* These used to live in `fixtures.ts`, which made the production reducer's own
|
|
5
|
+
* types derive from the test-oracle schema: `runtime.ts` read them back out as
|
|
6
|
+
* `z.infer<typeof fixtureExpectedSchema>['executor_effects'][number]`. That is the
|
|
7
|
+
* dependency backwards. The runtime defines what it emits; the fixture contract
|
|
8
|
+
* composes those definitions to describe a recorded scenario.
|
|
9
|
+
*
|
|
10
|
+
* Keeping them here also keeps the fixture harness, the virtual clock, and the
|
|
11
|
+
* scripted id factory out of the module graph a packaged desktop runtime loads.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { jsonValueSchema } from './events.js';
|
|
15
|
+
import { delegateSchema } from './ports.js';
|
|
16
|
+
export const floorDecisionRecordSchema = z.object({
|
|
17
|
+
event_seq: z.number().int().nonnegative(),
|
|
18
|
+
priority: z.number().int(),
|
|
19
|
+
decision: z.enum(['allow', 'preempt', 'defer']),
|
|
20
|
+
}).strict();
|
|
21
|
+
export const desktopEffectSchema = z.object({
|
|
22
|
+
kind: z.string().min(1),
|
|
23
|
+
data: z.record(z.string(), jsonValueSchema),
|
|
24
|
+
}).strict();
|
|
25
|
+
export const executorEffectSchema = z.discriminatedUnion('kind', [
|
|
26
|
+
z.object({ kind: z.literal('dispatch'), delegate: delegateSchema }).strict(),
|
|
27
|
+
z.object({ kind: z.literal('cancel'), delegate_id: z.string().min(1) }).strict(),
|
|
28
|
+
]);
|
|
29
|
+
export const diagnosticSchema = z.object({
|
|
30
|
+
code: z.string().min(1),
|
|
31
|
+
message: z.string().optional(),
|
|
32
|
+
details: z.record(z.string(), jsonValueSchema).optional(),
|
|
33
|
+
}).strict();
|
|
34
|
+
export const playbackGenerationSchema = z.object({
|
|
35
|
+
session_epoch: z.number().int().positive(),
|
|
36
|
+
generation_epoch: z.number().int().positive(),
|
|
37
|
+
generation_id: z.string().min(1),
|
|
38
|
+
utterance_id: z.string().min(1),
|
|
39
|
+
response_id: z.string().min(1),
|
|
40
|
+
}).strict();
|
|
41
|
+
export const playbackCompletionSchema = z.object({
|
|
42
|
+
session_epoch: z.number().int().positive(),
|
|
43
|
+
response_id: z.string().min(1),
|
|
44
|
+
utterance_id: z.string().min(1),
|
|
45
|
+
generation_epoch: z.number().int().positive(),
|
|
46
|
+
text: z.string(),
|
|
47
|
+
disposition: z.enum(['spoken', 'interrupted', 'suppressed']),
|
|
48
|
+
started: z.boolean(),
|
|
49
|
+
played_ms: z.number().int().nonnegative().nullable(),
|
|
50
|
+
}).strict();
|
|
51
|
+
export const playbackEffectSchema = z.discriminatedUnion('kind', [
|
|
52
|
+
z.object({ kind: z.literal('open'), generation: playbackGenerationSchema }).strict(),
|
|
53
|
+
z.object({
|
|
54
|
+
kind: z.literal('ack'),
|
|
55
|
+
ack: z.enum(['started', 'cleared', 'done']),
|
|
56
|
+
utterance_id: z.string().min(1),
|
|
57
|
+
generation_epoch: z.number().int().positive(),
|
|
58
|
+
accepted: z.boolean(),
|
|
59
|
+
completion: playbackCompletionSchema.nullable(),
|
|
60
|
+
}).strict(),
|
|
61
|
+
]);
|
|
62
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { hasOtherCategory } from '../text/unicode-tables.js';
|
|
3
|
+
export const EVENT_KINDS = [
|
|
4
|
+
'user_input',
|
|
5
|
+
'handoff',
|
|
6
|
+
'progress',
|
|
7
|
+
'observation',
|
|
8
|
+
'deadline',
|
|
9
|
+
'compress',
|
|
10
|
+
'model_done',
|
|
11
|
+
'compress_done',
|
|
12
|
+
'speak_start',
|
|
13
|
+
'speak_end',
|
|
14
|
+
'assistant_spoken',
|
|
15
|
+
'discovery_tick',
|
|
16
|
+
];
|
|
17
|
+
export const trustSchema = z.enum([
|
|
18
|
+
'trusted_user',
|
|
19
|
+
'trusted_system',
|
|
20
|
+
'untrusted_external',
|
|
21
|
+
]);
|
|
22
|
+
export const outcomeSchema = z.enum(['ok', 'refused', 'unknown', 'failed', 'cancelled']);
|
|
23
|
+
export const jsonValueSchema = z.lazy(() => z.union([
|
|
24
|
+
z.null(),
|
|
25
|
+
z.boolean(),
|
|
26
|
+
z.number().finite(),
|
|
27
|
+
z.string(),
|
|
28
|
+
z.array(jsonValueSchema),
|
|
29
|
+
z.record(z.string(), jsonValueSchema),
|
|
30
|
+
]));
|
|
31
|
+
const jsonObjectSchema = z.record(z.string(), jsonValueSchema);
|
|
32
|
+
const timestampSchema = z.number().finite();
|
|
33
|
+
const sequenceSchema = z.number().int().nonnegative();
|
|
34
|
+
export const PROGRESS_SUMMARY_LIMIT = 400;
|
|
35
|
+
export function validProgressSummary(summary, phase) {
|
|
36
|
+
if (summary === null)
|
|
37
|
+
return true;
|
|
38
|
+
if (typeof summary !== 'string' || phase !== 'working')
|
|
39
|
+
return false;
|
|
40
|
+
const characters = [...summary];
|
|
41
|
+
return characters.length >= 1
|
|
42
|
+
&& characters.length <= PROGRESS_SUMMARY_LIMIT
|
|
43
|
+
// Pinned Unicode 15.0.0 rather than /\p{C}/u, which resolves against the
|
|
44
|
+
// host ICU's newer Unicode version and would classify recently assigned code
|
|
45
|
+
// points differently from the Python oracle that exported every fixture.
|
|
46
|
+
&& !hasOtherCategory(summary);
|
|
47
|
+
}
|
|
48
|
+
const eventRecord = (kind, payload) => z.object({
|
|
49
|
+
seq: sequenceSchema,
|
|
50
|
+
ts: timestampSchema,
|
|
51
|
+
kind,
|
|
52
|
+
payload,
|
|
53
|
+
}).strict();
|
|
54
|
+
const eventInput = (kind, payload) => z.object({ kind, payload }).strict();
|
|
55
|
+
const userInputPayloadSchema = z.object({
|
|
56
|
+
text: z.string(),
|
|
57
|
+
media_refs: z.array(z.string()).optional(),
|
|
58
|
+
}).strict().overwrite(payload => (payload.media_refs?.length === 0 ? { text: payload.text } : payload));
|
|
59
|
+
const handoffPayloadSchema = z.object({
|
|
60
|
+
channel: z.string(),
|
|
61
|
+
delegate_id: z.string(),
|
|
62
|
+
origin_ref: z.string(),
|
|
63
|
+
outcome: outcomeSchema,
|
|
64
|
+
trust: trustSchema,
|
|
65
|
+
content: jsonObjectSchema,
|
|
66
|
+
refs: z.array(z.string()).default([]),
|
|
67
|
+
}).strict();
|
|
68
|
+
const observationPayloadSchema = z.object({
|
|
69
|
+
channel: z.string(),
|
|
70
|
+
delegate_id: z.string(),
|
|
71
|
+
op: z.string(),
|
|
72
|
+
origin_ref: z.string(),
|
|
73
|
+
trust: trustSchema,
|
|
74
|
+
content: jsonObjectSchema,
|
|
75
|
+
refs: z.array(z.string()).default([]),
|
|
76
|
+
}).strict();
|
|
77
|
+
const payloadSchemas = {
|
|
78
|
+
user_input: userInputPayloadSchema,
|
|
79
|
+
handoff: handoffPayloadSchema,
|
|
80
|
+
progress: z.object({
|
|
81
|
+
channel: z.string(),
|
|
82
|
+
delegate_id: z.string(),
|
|
83
|
+
op: z.string(),
|
|
84
|
+
phase: z.enum(['started', 'working']),
|
|
85
|
+
internal_activity: z.number().int().nonnegative(),
|
|
86
|
+
elapsed: z.number().finite().nonnegative(),
|
|
87
|
+
summary: z.string().nullable(),
|
|
88
|
+
}).strict(),
|
|
89
|
+
observation: observationPayloadSchema,
|
|
90
|
+
deadline: z.object({ delegate_id: z.string() }).strict(),
|
|
91
|
+
compress: z.object({ channel: z.string() }).strict(),
|
|
92
|
+
model_done: z.object({ slot: z.string(), job_id: z.string() }).strict(),
|
|
93
|
+
compress_done: z.object({ channel: z.string(), job_id: z.string() }).strict(),
|
|
94
|
+
speak_start: z.object({
|
|
95
|
+
utterance_id: z.string(),
|
|
96
|
+
priority: z.number().int(),
|
|
97
|
+
}).strict(),
|
|
98
|
+
speak_end: z.object({ utterance_id: z.string() }).strict(),
|
|
99
|
+
discovery_tick: z.object({ local_date: z.string(), weekday: z.string(), timezone: z.string() }).strict(),
|
|
100
|
+
assistant_spoken: z.object({
|
|
101
|
+
text: z.string(),
|
|
102
|
+
utterance_id: z.string(),
|
|
103
|
+
delivery: z.enum(['spoken', 'interrupted']),
|
|
104
|
+
played_ms: z.number().int().nonnegative().nullable(),
|
|
105
|
+
}).strict(),
|
|
106
|
+
};
|
|
107
|
+
export const eventRecordSchema = z.discriminatedUnion('kind', [
|
|
108
|
+
eventRecord(z.literal('user_input'), payloadSchemas.user_input),
|
|
109
|
+
eventRecord(z.literal('handoff'), payloadSchemas.handoff),
|
|
110
|
+
eventRecord(z.literal('progress'), payloadSchemas.progress),
|
|
111
|
+
eventRecord(z.literal('observation'), payloadSchemas.observation),
|
|
112
|
+
eventRecord(z.literal('deadline'), payloadSchemas.deadline),
|
|
113
|
+
eventRecord(z.literal('compress'), payloadSchemas.compress),
|
|
114
|
+
eventRecord(z.literal('model_done'), payloadSchemas.model_done),
|
|
115
|
+
eventRecord(z.literal('compress_done'), payloadSchemas.compress_done),
|
|
116
|
+
eventRecord(z.literal('speak_start'), payloadSchemas.speak_start),
|
|
117
|
+
eventRecord(z.literal('speak_end'), payloadSchemas.speak_end),
|
|
118
|
+
eventRecord(z.literal('assistant_spoken'), payloadSchemas.assistant_spoken),
|
|
119
|
+
eventRecord(z.literal('discovery_tick'), payloadSchemas.discovery_tick),
|
|
120
|
+
]);
|
|
121
|
+
export const eventInputSchema = z.discriminatedUnion('kind', [
|
|
122
|
+
eventInput(z.literal('user_input'), payloadSchemas.user_input),
|
|
123
|
+
eventInput(z.literal('handoff'), payloadSchemas.handoff),
|
|
124
|
+
eventInput(z.literal('progress'), payloadSchemas.progress),
|
|
125
|
+
eventInput(z.literal('observation'), payloadSchemas.observation),
|
|
126
|
+
eventInput(z.literal('deadline'), payloadSchemas.deadline),
|
|
127
|
+
eventInput(z.literal('compress'), payloadSchemas.compress),
|
|
128
|
+
eventInput(z.literal('model_done'), payloadSchemas.model_done),
|
|
129
|
+
eventInput(z.literal('compress_done'), payloadSchemas.compress_done),
|
|
130
|
+
eventInput(z.literal('speak_start'), payloadSchemas.speak_start),
|
|
131
|
+
eventInput(z.literal('speak_end'), payloadSchemas.speak_end),
|
|
132
|
+
eventInput(z.literal('assistant_spoken'), payloadSchemas.assistant_spoken),
|
|
133
|
+
eventInput(z.literal('discovery_tick'), payloadSchemas.discovery_tick),
|
|
134
|
+
]);
|
|
135
|
+
export class EventQueue {
|
|
136
|
+
#heap = [];
|
|
137
|
+
#sequence = 0;
|
|
138
|
+
push(input, at) {
|
|
139
|
+
if (!Number.isFinite(at))
|
|
140
|
+
throw new TypeError('event timestamp must be finite');
|
|
141
|
+
this.#sequence += 1;
|
|
142
|
+
const event = eventRecordSchema.parse({
|
|
143
|
+
...input,
|
|
144
|
+
seq: this.#sequence,
|
|
145
|
+
ts: at,
|
|
146
|
+
});
|
|
147
|
+
this.#heap.push({ event, rank: event.kind === 'deadline' ? 1 : 0 });
|
|
148
|
+
this.#siftUp(this.#heap.length - 1);
|
|
149
|
+
return event;
|
|
150
|
+
}
|
|
151
|
+
popReady(now) {
|
|
152
|
+
const first = this.#heap[0];
|
|
153
|
+
if (first === undefined || first.event.ts > now)
|
|
154
|
+
return undefined;
|
|
155
|
+
const last = this.#heap.pop();
|
|
156
|
+
if (this.#heap.length > 0 && last !== undefined) {
|
|
157
|
+
this.#heap[0] = last;
|
|
158
|
+
this.#siftDown(0);
|
|
159
|
+
}
|
|
160
|
+
return first.event;
|
|
161
|
+
}
|
|
162
|
+
nextTimestamp() {
|
|
163
|
+
return this.#heap[0]?.event.ts;
|
|
164
|
+
}
|
|
165
|
+
get size() {
|
|
166
|
+
return this.#heap.length;
|
|
167
|
+
}
|
|
168
|
+
/** Remove obsolete queued work while retaining the queue's monotonic event sequence. */
|
|
169
|
+
removeWhere(remove) {
|
|
170
|
+
const retained = this.#heap.filter(entry => !remove(entry.event));
|
|
171
|
+
if (retained.length === this.#heap.length)
|
|
172
|
+
return;
|
|
173
|
+
this.#heap.length = 0;
|
|
174
|
+
for (const entry of retained)
|
|
175
|
+
this.#heap.push(entry);
|
|
176
|
+
for (let index = Math.floor(this.#heap.length / 2) - 1; index >= 0; index -= 1) {
|
|
177
|
+
this.#siftDown(index);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
#siftUp(index) {
|
|
181
|
+
let child = index;
|
|
182
|
+
while (child > 0) {
|
|
183
|
+
const parent = Math.floor((child - 1) / 2);
|
|
184
|
+
if (compareEntries(this.#heap[parent], this.#heap[child]) <= 0)
|
|
185
|
+
return;
|
|
186
|
+
[this.#heap[parent], this.#heap[child]] = [this.#heap[child], this.#heap[parent]];
|
|
187
|
+
child = parent;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
#siftDown(index) {
|
|
191
|
+
let parent = index;
|
|
192
|
+
while (true) {
|
|
193
|
+
const left = parent * 2 + 1;
|
|
194
|
+
const right = left + 1;
|
|
195
|
+
let smallest = parent;
|
|
196
|
+
if (left < this.#heap.length
|
|
197
|
+
&& compareEntries(this.#heap[left], this.#heap[smallest]) < 0)
|
|
198
|
+
smallest = left;
|
|
199
|
+
if (right < this.#heap.length
|
|
200
|
+
&& compareEntries(this.#heap[right], this.#heap[smallest]) < 0)
|
|
201
|
+
smallest = right;
|
|
202
|
+
if (smallest === parent)
|
|
203
|
+
return;
|
|
204
|
+
[this.#heap[parent], this.#heap[smallest]] = [
|
|
205
|
+
this.#heap[smallest],
|
|
206
|
+
this.#heap[parent],
|
|
207
|
+
];
|
|
208
|
+
parent = smallest;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function compareEntries(left, right) {
|
|
213
|
+
return left.event.ts - right.event.ts
|
|
214
|
+
|| left.rank - right.rank
|
|
215
|
+
|| left.event.seq - right.event.seq;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Untrusted server evidence for local task details, never an execution instruction. */
|
|
3
|
+
export const executorDiagnosticSchema = z.object({
|
|
4
|
+
method: z.string().min(1).max(128),
|
|
5
|
+
server_code: z.number().int().nullable(),
|
|
6
|
+
elapsed_ms: z.number().nonnegative().optional(),
|
|
7
|
+
message: z.string().max(4000),
|
|
8
|
+
}).strict();
|
|
9
|
+
//# sourceMappingURL=executor-diagnostic.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class MonotonicIdFactory {
|
|
2
|
+
#sequences = new Map();
|
|
3
|
+
next(namespace) {
|
|
4
|
+
const sequence = (this.#sequences.get(namespace) ?? 0) + 1;
|
|
5
|
+
this.#sequences.set(namespace, sequence);
|
|
6
|
+
return `${namespace}-${sequence}`;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class ScriptedIdFactory {
|
|
10
|
+
#values;
|
|
11
|
+
#offsets = new Map();
|
|
12
|
+
constructor(values) {
|
|
13
|
+
this.#values = structuredClone(values);
|
|
14
|
+
}
|
|
15
|
+
next(namespace) {
|
|
16
|
+
const offset = this.#offsets.get(namespace) ?? 0;
|
|
17
|
+
const value = this.#values[namespace]?.[offset];
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
throw new Error(`scripted id sequence exhausted: ${namespace}`);
|
|
20
|
+
this.#offsets.set(namespace, offset + 1);
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
assertExhausted() {
|
|
24
|
+
const unused = Object.entries(this.#values).flatMap(([namespace, values]) => {
|
|
25
|
+
const remaining = values.length - (this.#offsets.get(namespace) ?? 0);
|
|
26
|
+
return remaining === 0 ? [] : [`${namespace}:${remaining}`];
|
|
27
|
+
});
|
|
28
|
+
if (unused.length > 0)
|
|
29
|
+
throw new Error(`unused scripted ids: ${unused.join(', ')}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ids.js.map
|