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,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded recall over the conversation Memory: which past items a model gets to see.
|
|
3
|
+
*
|
|
4
|
+
* Ported from `src/nova_personal_agent/realtime/recall.py`. Pure -- it reads Memory and mutates
|
|
5
|
+
* nothing -- and every bound is part of the contract rather than a safety net, because the output is
|
|
6
|
+
* what the model is shown. Two items scoring equally have to break the tie the same way on both
|
|
7
|
+
* legs, or the two runtimes answer the same question differently.
|
|
8
|
+
*
|
|
9
|
+
* The scoring is lexical and deliberately crude: tokens shared between the query and an item's
|
|
10
|
+
* evidence. What makes it delicate is Unicode. Tokenization runs over `NFKC` then lowercase, and
|
|
11
|
+
* both stages diverge between CPython's Unicode database and the host ICU, so this module uses the
|
|
12
|
+
* pinned pipeline from `unicode-normalize.ts` rather than the host's. A code point assigned after
|
|
13
|
+
* the pin would otherwise tokenize differently here than in the oracle, and change which memories
|
|
14
|
+
* come back.
|
|
15
|
+
*/
|
|
16
|
+
import { compareCodePoints } from '../text/canonical-json.js';
|
|
17
|
+
import { stripLikePython } from '../text/python-text.js';
|
|
18
|
+
import { CONVERSATION_CHANNEL, makeMemoryRef, parseMemoryRef, } from '../core/memory.js';
|
|
19
|
+
import { normalizeAndLowerPinned } from '../text/unicode-normalize.js';
|
|
20
|
+
import { safeMemoryEvidence } from './evidence.js';
|
|
21
|
+
/** Per channel, in `recent` scope. Small because recency is the point of that scope. */
|
|
22
|
+
const RECENT_PER_CHANNEL = 5;
|
|
23
|
+
/** The `any` scope reads the whole of Memory, so it needs a hard ceiling. */
|
|
24
|
+
const ANY_SCAN_LIMIT = 500;
|
|
25
|
+
const HIT_LIMIT = 5;
|
|
26
|
+
const MAX_QUERY_CHARS = 512;
|
|
27
|
+
/** ASCII runs of two or more, which is what a Latin query matches on. */
|
|
28
|
+
const ASCII_TOKEN = /[a-z0-9]+/gu;
|
|
29
|
+
/**
|
|
30
|
+
* CJK runs, tokenized into overlapping bigrams rather than words.
|
|
31
|
+
*
|
|
32
|
+
* Chinese has no spaces, so a single character is too common to discriminate and a whole run is too
|
|
33
|
+
* specific to match anything. Bigrams are the compromise the oracle chose.
|
|
34
|
+
*/
|
|
35
|
+
const CJK_RUN = /[㐀-䶿一-鿿豈-]+/gu;
|
|
36
|
+
/** The recall cutoff is not an accepted trusted-user conversation item. */
|
|
37
|
+
export class RecallOriginError extends Error {
|
|
38
|
+
}
|
|
39
|
+
/** Compile a deterministic recall view without mutating Memory. */
|
|
40
|
+
export function compileMemoryRecall(memory, options) {
|
|
41
|
+
const query = stripLikePython(options.query);
|
|
42
|
+
// Code points, as Python's `len` counts: 512 astral characters are 1024 UTF-16 units, and
|
|
43
|
+
// measuring those would reject a query the oracle accepts.
|
|
44
|
+
const queryLength = [...query].length;
|
|
45
|
+
if (queryLength === 0 || queryLength > MAX_QUERY_CHARS) {
|
|
46
|
+
throw new RangeError(`query must contain 1 to ${MAX_QUERY_CHARS} characters`);
|
|
47
|
+
}
|
|
48
|
+
if (options.scope !== 'recent' && options.scope !== 'any') {
|
|
49
|
+
throw new TypeError("scope must be 'recent' or 'any'");
|
|
50
|
+
}
|
|
51
|
+
const cutoffSeq = conversationCutoff(memory, options.beforeRef);
|
|
52
|
+
const { items: rawItems, truncated } = rawCandidates(memory, options.scope, cutoffSeq);
|
|
53
|
+
const queryTokens = lexicalTokens(query);
|
|
54
|
+
const candidates = [];
|
|
55
|
+
for (const item of rawItems) {
|
|
56
|
+
// An item with no safe evidence is not a candidate at all: recall may only surface what the
|
|
57
|
+
// evidence layer has already judged safe to show. That layer returns null rather than an empty
|
|
58
|
+
// string for everything it rejects, so null is the whole condition -- the oracle's
|
|
59
|
+
// `if not evidence` reads as a falsy check but can only ever see None here.
|
|
60
|
+
const evidence = safeMemoryEvidence(item, options.coding ?? null);
|
|
61
|
+
if (evidence === null)
|
|
62
|
+
continue;
|
|
63
|
+
const itemTokens = lexicalTokens(evidence);
|
|
64
|
+
let score = 0;
|
|
65
|
+
for (const token of queryTokens) {
|
|
66
|
+
if (itemTokens.has(token))
|
|
67
|
+
score += 1;
|
|
68
|
+
}
|
|
69
|
+
candidates.push({ item, evidence, score });
|
|
70
|
+
}
|
|
71
|
+
if (candidates.length === 0) {
|
|
72
|
+
return {
|
|
73
|
+
state: 'empty',
|
|
74
|
+
scope: options.scope,
|
|
75
|
+
raw_scanned: rawItems.length,
|
|
76
|
+
searched_count: 0,
|
|
77
|
+
scan_truncated: truncated,
|
|
78
|
+
hits: [],
|
|
79
|
+
omitted: 0,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const lexical = candidates.filter(candidate => candidate.score > 0);
|
|
83
|
+
let ranked;
|
|
84
|
+
let match;
|
|
85
|
+
if (lexical.length > 0) {
|
|
86
|
+
ranked = [...lexical].sort((left, right) => right.score - left.score || byRecencyRank(memory, left, right));
|
|
87
|
+
match = 'lexical';
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// Nothing matched, so the newest items are a better answer than none: the model asked about
|
|
91
|
+
// something, and recent context is more likely relevant than silence.
|
|
92
|
+
ranked = [...candidates].sort((left, right) => byRecencyRank(memory, left, right));
|
|
93
|
+
match = 'recency_fallback';
|
|
94
|
+
}
|
|
95
|
+
const selected = ranked.slice(0, HIT_LIMIT);
|
|
96
|
+
return {
|
|
97
|
+
state: 'ok',
|
|
98
|
+
scope: options.scope,
|
|
99
|
+
raw_scanned: rawItems.length,
|
|
100
|
+
searched_count: candidates.length,
|
|
101
|
+
scan_truncated: truncated,
|
|
102
|
+
hits: selected.map(candidate => ({
|
|
103
|
+
// `ref` is derived from channel and sequence, as it is in the oracle, rather than stored.
|
|
104
|
+
ref: makeMemoryRef(candidate.item.channel, candidate.item.seq),
|
|
105
|
+
channel: candidate.item.channel,
|
|
106
|
+
ts: candidate.item.ts,
|
|
107
|
+
trust: candidate.item.trust,
|
|
108
|
+
outcome: candidate.item.outcome ?? null,
|
|
109
|
+
match,
|
|
110
|
+
evidence: candidate.evidence,
|
|
111
|
+
...(memory.isHistorical(candidate.item) ? {
|
|
112
|
+
historical: true,
|
|
113
|
+
recorded_at_ms: memory.channels.get(candidate.item.channel).restoredRecord(candidate.item.seq).recordedAtMs,
|
|
114
|
+
} : {}),
|
|
115
|
+
})),
|
|
116
|
+
omitted: ranked.length - selected.length,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Encode a recall view, dropping only whole trailing hits to fit the budget.
|
|
121
|
+
*
|
|
122
|
+
* Whole hits, never truncated text: half an item's evidence is worse than none, because the model
|
|
123
|
+
* cannot tell it was cut. The dropped ones are counted into `omitted` so the view stays honest
|
|
124
|
+
* about what it is not showing.
|
|
125
|
+
*/
|
|
126
|
+
export function encodeMemoryRecall(view, options = {}) {
|
|
127
|
+
const maxChars = options.maxChars ?? 3000;
|
|
128
|
+
// The messages here are spelled as the oracle spells them, snake_case parameter name included:
|
|
129
|
+
// the golden records them, so they are part of the cross-language contract rather than wording.
|
|
130
|
+
if (maxChars <= 0)
|
|
131
|
+
throw new RangeError('max_chars must be positive');
|
|
132
|
+
const hits = [...view.hits];
|
|
133
|
+
let removed = 0;
|
|
134
|
+
for (;;) {
|
|
135
|
+
const encoded = encodeRecallPayload(view, hits, removed);
|
|
136
|
+
// Measured in code points, as Python's `len` is, not UTF-16 units.
|
|
137
|
+
if ([...encoded].length <= maxChars)
|
|
138
|
+
return encoded;
|
|
139
|
+
if (hits.length === 0) {
|
|
140
|
+
throw new RangeError('max_chars is too small for the recall envelope');
|
|
141
|
+
}
|
|
142
|
+
hits.pop();
|
|
143
|
+
removed += 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The recall envelope, with keys in code-point order and no separator whitespace.
|
|
148
|
+
*
|
|
149
|
+
* Built by hand rather than via `canonicalJson` because the oracle uses `json.dumps` with
|
|
150
|
+
* `sort_keys=True`, and this text is what a model reads: it has to be byte-identical, including the
|
|
151
|
+
* key order and the absence of spaces. Verified against Python across control characters, U+007F,
|
|
152
|
+
* U+00A0, U+2028, NUL, quotes, backslashes, CJK and astral characters -- identical on all of them.
|
|
153
|
+
*
|
|
154
|
+
* Lone surrogates are the one case where matching the oracle would be wrong. `json.dumps` with
|
|
155
|
+
* `ensure_ascii=False` embeds a lone surrogate raw, producing a string that cannot be encoded as
|
|
156
|
+
* UTF-8 at all, so those bytes could never reach a provider. This encoder refuses them instead.
|
|
157
|
+
*/
|
|
158
|
+
function encodeRecallPayload(view, hits, removed) {
|
|
159
|
+
const encodedHits = hits.map(hit => {
|
|
160
|
+
if ((hit.historical === true) !== (hit.recorded_at_ms !== undefined)
|
|
161
|
+
|| (hit.recorded_at_ms !== undefined && (!Number.isSafeInteger(hit.recorded_at_ms) || hit.recorded_at_ms < 0))) {
|
|
162
|
+
throw new RangeError('historical recall requires a valid recorded_at_ms');
|
|
163
|
+
}
|
|
164
|
+
requireWellFormed(hit.evidence, 'evidence');
|
|
165
|
+
requireWellFormed(hit.channel, 'channel');
|
|
166
|
+
requireWellFormed(hit.ref, 'ref');
|
|
167
|
+
const fields = [
|
|
168
|
+
['channel', JSON.stringify(hit.channel)],
|
|
169
|
+
['evidence', JSON.stringify(hit.evidence)],
|
|
170
|
+
...(hit.historical === true ? [['historical', 'true']] : []),
|
|
171
|
+
['match', JSON.stringify(hit.match)],
|
|
172
|
+
['outcome', hit.outcome === null ? 'null' : JSON.stringify(hit.outcome)],
|
|
173
|
+
...(hit.recorded_at_ms === undefined ? [] : [['recorded_at_ms', encodeCount(hit.recorded_at_ms)]]),
|
|
174
|
+
['ref', JSON.stringify(hit.ref)],
|
|
175
|
+
['trust', JSON.stringify(hit.trust)],
|
|
176
|
+
['ts', encodeTimestamp(hit.ts)],
|
|
177
|
+
];
|
|
178
|
+
return `{${fields.map(([key, value]) => `${JSON.stringify(key)}:${value}`).join(',')}}`;
|
|
179
|
+
});
|
|
180
|
+
const fields = [
|
|
181
|
+
['hits', `[${encodedHits.join(',')}]`],
|
|
182
|
+
['omitted', encodeCount(view.omitted + removed)],
|
|
183
|
+
['raw_scanned', encodeCount(view.raw_scanned)],
|
|
184
|
+
['scan_truncated', view.scan_truncated ? 'true' : 'false'],
|
|
185
|
+
['scope', JSON.stringify(view.scope)],
|
|
186
|
+
['searched_count', encodeCount(view.searched_count)],
|
|
187
|
+
['state', JSON.stringify(view.state)],
|
|
188
|
+
];
|
|
189
|
+
return `{${fields.map(([key, value]) => `${JSON.stringify(key)}:${value}`).join(',')}}`;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Refuse text that cannot survive being encoded.
|
|
193
|
+
*
|
|
194
|
+
* A lone surrogate is not a valid scalar value, so an envelope containing one cannot be sent as
|
|
195
|
+
* UTF-8. The oracle would embed it raw and fail at the transport instead; failing here names the
|
|
196
|
+
* field, which is more use to a caller.
|
|
197
|
+
*/
|
|
198
|
+
function requireWellFormed(value, field) {
|
|
199
|
+
// `String.prototype.isWellFormed` is ES2024 and this project targets earlier; the regex says the
|
|
200
|
+
// same thing -- a high surrogate not followed by a low one, or a low one not preceded by a high.
|
|
201
|
+
if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(value)) {
|
|
202
|
+
throw new RangeError(`recall ${field} contains a lone surrogate and cannot be encoded`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The range where a float's `json.dumps` spelling is reproducible in JavaScript.
|
|
207
|
+
*
|
|
208
|
+
* Below 1e16 Python writes positional notation and JavaScript agrees digit for digit. At and above
|
|
209
|
+
* it Python switches to `1e+16` while JavaScript stays positional until 1e21, and their exponent
|
|
210
|
+
* spellings differ anyway (`1e-07` versus `1e-7`). Rather than reimplement `repr`, this module
|
|
211
|
+
* refuses that range: a timestamp there is a bug in the caller, not a formatting question.
|
|
212
|
+
*/
|
|
213
|
+
const MAX_REPRODUCIBLE_MAGNITUDE = 1e16;
|
|
214
|
+
/**
|
|
215
|
+
* A timestamp as `json.dumps` writes a Python float.
|
|
216
|
+
*
|
|
217
|
+
* `ts` is typed `float` in the oracle, so an integral value spells `1.0` there where JavaScript
|
|
218
|
+
* would write `1`. The counts beside it are `int` and spell the same in both, which is why they use
|
|
219
|
+
* `encodeCount` instead -- getting this backwards made every envelope differ.
|
|
220
|
+
*
|
|
221
|
+
* Negative zero is refused rather than encoded: Python writes `-0.0` where JavaScript writes `0`,
|
|
222
|
+
* and a negative-zero timestamp has no meaning to preserve.
|
|
223
|
+
*/
|
|
224
|
+
function encodeTimestamp(value) {
|
|
225
|
+
if (!Number.isFinite(value) || Math.abs(value) >= MAX_REPRODUCIBLE_MAGNITUDE) {
|
|
226
|
+
throw new RangeError(`recall cannot reproduce this timestamp's Python spelling: ${value}`);
|
|
227
|
+
}
|
|
228
|
+
if (Object.is(value, -0))
|
|
229
|
+
throw new RangeError('recall cannot encode a negative-zero timestamp');
|
|
230
|
+
// A small magnitude can still render exponentially in JavaScript, where Python pads the exponent.
|
|
231
|
+
if (String(value).includes('e')) {
|
|
232
|
+
throw new RangeError(`recall cannot reproduce this timestamp's Python spelling: ${value}`);
|
|
233
|
+
}
|
|
234
|
+
return Number.isInteger(value) ? `${value}.0` : `${value}`;
|
|
235
|
+
}
|
|
236
|
+
/** An integer count, spelled as both runtimes spell one. */
|
|
237
|
+
function encodeCount(value) {
|
|
238
|
+
if (!Number.isInteger(value))
|
|
239
|
+
throw new RangeError(`recall count must be an integer: ${value}`);
|
|
240
|
+
return `${value}`;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Resolve the recall cutoff, which must be an accepted trusted-user conversation item.
|
|
244
|
+
*
|
|
245
|
+
* Recall answers "what happened before this turn of mine", so the cutoff has to be a real user turn
|
|
246
|
+
* and not, say, an assistant message or an untrusted item -- otherwise a model could aim the cutoff
|
|
247
|
+
* at content it chose and read past a boundary it does not own.
|
|
248
|
+
*/
|
|
249
|
+
export function conversationCutoff(memory, beforeRef) {
|
|
250
|
+
const message = 'before_ref must name an existing trusted user conversation item';
|
|
251
|
+
let channel;
|
|
252
|
+
let seq;
|
|
253
|
+
try {
|
|
254
|
+
;
|
|
255
|
+
[channel, seq] = parseMemoryRef(beforeRef);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
throw new RecallOriginError(message);
|
|
259
|
+
}
|
|
260
|
+
const conversation = memory.channels.get(CONVERSATION_CHANNEL);
|
|
261
|
+
if (conversation === undefined)
|
|
262
|
+
throw new RecallOriginError(message);
|
|
263
|
+
if (channel !== CONVERSATION_CHANNEL || seq < 1) {
|
|
264
|
+
throw new RecallOriginError(message);
|
|
265
|
+
}
|
|
266
|
+
const origin = conversation.getBySeq(seq);
|
|
267
|
+
if (origin === undefined
|
|
268
|
+
|| memory.isHistorical(origin)
|
|
269
|
+
|| makeMemoryRef(origin.channel, origin.seq) !== beforeRef
|
|
270
|
+
|| origin.trust !== 'trusted_user') {
|
|
271
|
+
throw new RecallOriginError(message);
|
|
272
|
+
}
|
|
273
|
+
return seq;
|
|
274
|
+
}
|
|
275
|
+
function rawCandidates(memory, scope, cutoffSeq) {
|
|
276
|
+
if (scope === 'recent') {
|
|
277
|
+
const items = [];
|
|
278
|
+
for (const channel of memory.channels.values()) {
|
|
279
|
+
// The cutoff item itself and everything after it are excluded: recall looks strictly before
|
|
280
|
+
// the turn that asked.
|
|
281
|
+
const eligible = channel.name === CONVERSATION_CHANNEL
|
|
282
|
+
? channel.items.filter(item => item.seq < cutoffSeq)
|
|
283
|
+
: channel.items;
|
|
284
|
+
items.push(...eligible.slice(-RECENT_PER_CHANNEL));
|
|
285
|
+
}
|
|
286
|
+
return { items, truncated: false };
|
|
287
|
+
}
|
|
288
|
+
const items = [];
|
|
289
|
+
for (const channel of memory.channels.values()) {
|
|
290
|
+
for (const item of channel.items) {
|
|
291
|
+
if (item.channel !== CONVERSATION_CHANNEL || item.seq < cutoffSeq)
|
|
292
|
+
items.push(item);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
items.sort((left, right) => byNewestRaw(memory, left, right));
|
|
296
|
+
return { items: items.slice(0, ANY_SCAN_LIMIT), truncated: items.length > ANY_SCAN_LIMIT };
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The tokens a piece of text matches on.
|
|
300
|
+
*
|
|
301
|
+
* Normalization runs through the pinned pipeline, not the host's: a code point assigned after the
|
|
302
|
+
* pin would otherwise decompose or lowercase here and not in the oracle, and a query would match
|
|
303
|
+
* memories the oracle would not return.
|
|
304
|
+
*/
|
|
305
|
+
function lexicalTokens(text) {
|
|
306
|
+
const normalized = normalizeAndLowerPinned(text);
|
|
307
|
+
const tokens = new Set();
|
|
308
|
+
for (const match of normalized.matchAll(ASCII_TOKEN)) {
|
|
309
|
+
// Single characters are too common to discriminate.
|
|
310
|
+
if (match[0].length >= 2)
|
|
311
|
+
tokens.add(match[0]);
|
|
312
|
+
}
|
|
313
|
+
for (const match of normalized.matchAll(CJK_RUN)) {
|
|
314
|
+
const run = [...match[0]];
|
|
315
|
+
// Overlapping bigrams. A one-character run contributes nothing, which is deliberate.
|
|
316
|
+
for (let index = 0; index < run.length - 1; index += 1) {
|
|
317
|
+
tokens.add(run.slice(index, index + 2).join(''));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return tokens;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Newest first, then most important, then channel name, then newest sequence.
|
|
324
|
+
*
|
|
325
|
+
* Every tie-break has to match the oracle's tuple ordering exactly, including comparing channel
|
|
326
|
+
* names by code point rather than by locale, because the selected set is what a model sees.
|
|
327
|
+
*/
|
|
328
|
+
function byNewestRaw(memory, left, right) {
|
|
329
|
+
return (memory.compareRecency(left, right)
|
|
330
|
+
|| right.priority - left.priority
|
|
331
|
+
|| compareCodePoints(left.channel, right.channel)
|
|
332
|
+
|| right.seq - left.seq);
|
|
333
|
+
}
|
|
334
|
+
/** Note `seq` ascends here, unlike the raw scan. */
|
|
335
|
+
function byRecencyRank(memory, left, right) {
|
|
336
|
+
return (memory.compareRecency(left.item, right.item)
|
|
337
|
+
|| right.item.priority - left.item.priority
|
|
338
|
+
|| compareCodePoints(left.item.channel, right.item.channel)
|
|
339
|
+
|| left.item.seq - right.item.seq);
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=recall.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import {} from '../executors/agent-controller.js';
|
|
2
|
+
import {} from '../core/events.js';
|
|
3
|
+
import {} from '../executors/coding/intake.js';
|
|
4
|
+
import {} from '../core/memory.js';
|
|
5
|
+
import {} from './service-state.js';
|
|
6
|
+
import {} from './session-state.js';
|
|
7
|
+
import {} from './session.js';
|
|
8
|
+
//# sourceMappingURL=service-ports.js.map
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state model behind `RealtimeService`.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the constants and private dataclasses at the head of
|
|
5
|
+
* `src/nova_personal_agent/realtime/service.py`. These live apart from the orchestration for the same
|
|
6
|
+
* reason `session-state.ts` does: the service is a single coupled state machine with around seventy
|
|
7
|
+
* mutable fields, and the only way to read it is to be able to see what each field *is* before
|
|
8
|
+
* following what changes it.
|
|
9
|
+
*
|
|
10
|
+
* Every bound here is behavior, not tuning. A ledger that grows without one is a leak in a process
|
|
11
|
+
* meant to run for hours, and a ledger that evicts in the wrong order forgets the wrong thing --
|
|
12
|
+
* which is why each is spelled out with what it protects rather than left to a comment saying "cap".
|
|
13
|
+
*/
|
|
14
|
+
/** Longest host fact the provider will be given. Beyond this the model stops attending to it. */
|
|
15
|
+
export const MAX_HOST_FACT_CHARS = 3_000;
|
|
16
|
+
export const MAX_TRACKED_TOOL_CALLS = 500;
|
|
17
|
+
export const MAX_PENDING_TOOL_REFUSALS = 32;
|
|
18
|
+
export const PROJECT_EXPIRY_STEP_TIMEOUT_S = 5;
|
|
19
|
+
export const MAX_TRACKED_SEMANTIC_ACKNOWLEDGEMENTS = 500;
|
|
20
|
+
export const MAX_TRACKED_ORIGIN_DELIVERY_PROOFS = MAX_TRACKED_SEMANTIC_ACKNOWLEDGEMENTS;
|
|
21
|
+
export const MAX_UNCERTAIN_DELIVERY_RETRIES = 256;
|
|
22
|
+
/**
|
|
23
|
+
* R105: delegates whose sync wait was resolved by a Deadline.
|
|
24
|
+
*
|
|
25
|
+
* A later handoff still downgrades to one host fact, so the record has to outlive the wait -- but not
|
|
26
|
+
* forever. Bounded, oldest dropped.
|
|
27
|
+
*/
|
|
28
|
+
export const MAX_LATE_SYNC_RESULTS = 64;
|
|
29
|
+
export const SYNC_RESULT_TITLE_CHARS = 120;
|
|
30
|
+
export const SYNC_RESULT_SNIPPET_CHARS = 400;
|
|
31
|
+
/** Longest a user may hold the floor before the hold is treated as stale and released. */
|
|
32
|
+
export const USER_HOLD_MAX_S = 30;
|
|
33
|
+
export const STALE_DELIVERY_RETRY_S = 1;
|
|
34
|
+
/** Below this priority a host item waits its turn; at or above it may interrupt the agent. */
|
|
35
|
+
export const PREEMPT_MIN_PRIORITY = 80;
|
|
36
|
+
/** Ordinary progress older than this is stale operational narration, not a current user fact. */
|
|
37
|
+
export const PROGRESS_HOST_ITEM_TTL_S = 45;
|
|
38
|
+
/** The bounded interruption deadline for an alert whose policy permits preemption. */
|
|
39
|
+
export const PREEMPTIVE_ALERT_DEADLINE_S = 0.35;
|
|
40
|
+
/** The bounded renderer-clear acknowledgement wait for a preemptive alert. */
|
|
41
|
+
export const PREEMPTIVE_ALERT_CLEAR_ACK_DEADLINE_S = 0.5;
|
|
42
|
+
/**
|
|
43
|
+
* A monitoring hit outranks routine executor announcements (codex=50) without reaching the
|
|
44
|
+
* preemption band; heartbeats and misses keep the manifest priority.
|
|
45
|
+
*/
|
|
46
|
+
export const HIT_ALERT_MIN_PRIORITY = 55;
|
|
47
|
+
/** What the service will say when a confirmed project operation could not be carried out. */
|
|
48
|
+
const PROJECT_COMMIT_FAILURE_TEXT = new Map([
|
|
49
|
+
['workspace_name_conflict', '工作区名称已存在,本次操作未执行。'],
|
|
50
|
+
['workspace_limit', '工作区数量已达上限,本次操作未执行。'],
|
|
51
|
+
['session_limit', 'Session 数量已达上限,本次操作未执行。'],
|
|
52
|
+
['state_busy', '工作区状态正忙,请稍后再试。'],
|
|
53
|
+
['confirmation_invalid', '确认状态已失效,本次操作未执行。'],
|
|
54
|
+
['workspace_not_found', '没有找到指定工作区,本次操作未执行。'],
|
|
55
|
+
['session_not_found', '没有找到指定 Session,本次操作未执行。'],
|
|
56
|
+
['session_unavailable', '指定 Session 当前不可继续,本次操作未执行。'],
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* Explain a failed commit in words a user hears.
|
|
60
|
+
*
|
|
61
|
+
* The fallback is deliberately vague about *why*: an unrecognised code means the failure came from
|
|
62
|
+
* somewhere this layer does not model, and inventing a specific reason for it would be worse than
|
|
63
|
+
* admitting the operation did not happen.
|
|
64
|
+
*/
|
|
65
|
+
export function projectCommitFailureText(code, displayName = '执行器') {
|
|
66
|
+
if (code === 'busy' || code === 'runtime_rejected')
|
|
67
|
+
return `${displayName} 当前正忙,本次操作未执行。`;
|
|
68
|
+
if (typeof code !== 'string')
|
|
69
|
+
return '已确认,但操作未执行。';
|
|
70
|
+
return PROJECT_COMMIT_FAILURE_TEXT.get(code) ?? '已确认,但操作未执行。';
|
|
71
|
+
}
|
|
72
|
+
export function toolCallState(input) {
|
|
73
|
+
return {
|
|
74
|
+
acceptance: input.acceptance,
|
|
75
|
+
provider_response_id: input.provider_response_id,
|
|
76
|
+
provider_session_epoch: input.provider_session_epoch,
|
|
77
|
+
origin_user_input_revision: input.origin_user_input_revision,
|
|
78
|
+
observation: input.observation,
|
|
79
|
+
dispatch: input.dispatch,
|
|
80
|
+
logical_name: input.logical_name ?? null,
|
|
81
|
+
output: 'pending',
|
|
82
|
+
continuation: 'queued',
|
|
83
|
+
continuation_response_id: null,
|
|
84
|
+
final_disposition: null,
|
|
85
|
+
sync: input.sync ?? 'none',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function continuationBatch(providerResponseId) {
|
|
89
|
+
return {
|
|
90
|
+
provider_response_id: providerResponseId,
|
|
91
|
+
call_keys: [],
|
|
92
|
+
origin_status: 'active',
|
|
93
|
+
phase: 'collecting',
|
|
94
|
+
continuation_response_id: null,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function semanticAcknowledgement(input) {
|
|
98
|
+
return {
|
|
99
|
+
event_id: input.event_id,
|
|
100
|
+
delegate_id: input.delegate_id,
|
|
101
|
+
summary: input.summary,
|
|
102
|
+
channel: input.channel,
|
|
103
|
+
origin_session_epoch: null,
|
|
104
|
+
origin_response_id: null,
|
|
105
|
+
origin_user_input_revision: null,
|
|
106
|
+
origin_delivered: false,
|
|
107
|
+
heard: false,
|
|
108
|
+
phase: 'pending',
|
|
109
|
+
response_id: null,
|
|
110
|
+
response_session_epoch: null,
|
|
111
|
+
provider_event_id: null,
|
|
112
|
+
binding: null,
|
|
113
|
+
failed_retry_consumed: false,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Order two queued items the way the oracle's tuple comparison does. */
|
|
117
|
+
export function compareQueuedHostResponses(left, right) {
|
|
118
|
+
return left.sortKey[0] - right.sortKey[0]
|
|
119
|
+
|| left.sortKey[1] - right.sortKey[1]
|
|
120
|
+
|| left.sortKey[2] - right.sortKey[2];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A key for the `(session_epoch, id)` ledgers.
|
|
124
|
+
*
|
|
125
|
+
* The epoch is in nearly every key in this layer, and that is the reconnect contract rather than
|
|
126
|
+
* defensive prefixing: after a reconnect the provider may reuse an id, and a ledger keyed on the id
|
|
127
|
+
* alone would let the new session's item answer the old session's question.
|
|
128
|
+
*/
|
|
129
|
+
export function callKey(sessionEpoch, id) {
|
|
130
|
+
return `${sessionEpoch}:${id}`;
|
|
131
|
+
}
|
|
132
|
+
/** Recover the two halves of a call key. Refuses a key that was not built by `callKey`. */
|
|
133
|
+
export function parseCallKey(key) {
|
|
134
|
+
const separator = key.indexOf(':');
|
|
135
|
+
if (separator <= 0)
|
|
136
|
+
throw new TypeError(`malformed call key: ${key}`);
|
|
137
|
+
const sessionEpoch = Number(key.slice(0, separator));
|
|
138
|
+
if (!Number.isInteger(sessionEpoch))
|
|
139
|
+
throw new TypeError(`malformed call key: ${key}`);
|
|
140
|
+
return { sessionEpoch, id: key.slice(separator + 1) };
|
|
141
|
+
}
|
|
142
|
+
/** A host fact carrying one context item. */
|
|
143
|
+
export function hostFactIntent(item) {
|
|
144
|
+
// `call_id` belongs to tool output alone, and a host fact is never that.
|
|
145
|
+
return {
|
|
146
|
+
kind: 'host_fact',
|
|
147
|
+
item: { ...item, call_id: null },
|
|
148
|
+
task_summary: null,
|
|
149
|
+
origin_spoken: false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A mutual exclusion lock with FIFO ordering.
|
|
154
|
+
*
|
|
155
|
+
* FIFO rather than whoever-wins, because the delivery lock decides the order host facts reach the
|
|
156
|
+
* provider: a waiter that jumped the queue would reorder what the user hears.
|
|
157
|
+
*/
|
|
158
|
+
export class Mutex {
|
|
159
|
+
#locked = false;
|
|
160
|
+
#waiting = [];
|
|
161
|
+
async run(body) {
|
|
162
|
+
await this.#acquire();
|
|
163
|
+
try {
|
|
164
|
+
return await body();
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
this.#release();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
get locked() {
|
|
171
|
+
return this.#locked;
|
|
172
|
+
}
|
|
173
|
+
async #acquire() {
|
|
174
|
+
if (!this.#locked) {
|
|
175
|
+
this.#locked = true;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
await new Promise(resolve => {
|
|
179
|
+
this.#waiting.push(resolve);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
#release() {
|
|
183
|
+
const next = this.#waiting.shift();
|
|
184
|
+
if (next === undefined) {
|
|
185
|
+
this.#locked = false;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// Handed straight to the next waiter rather than unlocked and re-acquired, so nothing that
|
|
189
|
+
// arrives in between can take the lock ahead of someone already waiting.
|
|
190
|
+
next();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** A latch that stays set until cleared, matching `asyncio.Event`. */
|
|
194
|
+
export class Signal {
|
|
195
|
+
#set = false;
|
|
196
|
+
#waiting = [];
|
|
197
|
+
set() {
|
|
198
|
+
this.#set = true;
|
|
199
|
+
const waiting = this.#waiting.splice(0, this.#waiting.length);
|
|
200
|
+
for (const resolve of waiting)
|
|
201
|
+
resolve();
|
|
202
|
+
}
|
|
203
|
+
clear() {
|
|
204
|
+
this.#set = false;
|
|
205
|
+
}
|
|
206
|
+
async wait(signal) {
|
|
207
|
+
if (this.#set)
|
|
208
|
+
return;
|
|
209
|
+
if (signal?.aborted === true)
|
|
210
|
+
return;
|
|
211
|
+
await new Promise(resolve => {
|
|
212
|
+
let settled = false;
|
|
213
|
+
const finish = () => {
|
|
214
|
+
if (settled)
|
|
215
|
+
return;
|
|
216
|
+
settled = true;
|
|
217
|
+
signal?.removeEventListener('abort', onAbort);
|
|
218
|
+
resolve();
|
|
219
|
+
};
|
|
220
|
+
const onAbort = () => {
|
|
221
|
+
const index = this.#waiting.indexOf(finish);
|
|
222
|
+
if (index >= 0)
|
|
223
|
+
this.#waiting.splice(index, 1);
|
|
224
|
+
finish();
|
|
225
|
+
};
|
|
226
|
+
this.#waiting.push(finish);
|
|
227
|
+
// Resolves rather than rejects: an interrupted wait is a normal shutdown, and the caller
|
|
228
|
+
// re-reads the signal immediately afterwards.
|
|
229
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
230
|
+
// Abort may win between the early check and listener registration. EventTarget does not replay
|
|
231
|
+
// an already-fired abort event, so close that race explicitly.
|
|
232
|
+
if (signal?.aborted === true)
|
|
233
|
+
onAbort();
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Whether this rejection is an abort, which is an ordinary cancellation rather than a failure. */
|
|
238
|
+
export function isAbort(cause) {
|
|
239
|
+
return cause instanceof Error && (cause.name === 'AbortError' || cause.name === 'TimeoutError');
|
|
240
|
+
}
|
|
241
|
+
export function diagnosticName(cause) {
|
|
242
|
+
return cause instanceof Error ? cause.constructor.name : typeof cause;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Seconds as the oracle's `f"{value:.0f}"` renders them.
|
|
246
|
+
*
|
|
247
|
+
* Python rounds half to even and JavaScript's `toFixed` rounds half away from zero, so 0.5 renders as
|
|
248
|
+
* "0" there and "1" here. Reproduced explicitly because this string is spoken to the user.
|
|
249
|
+
*/
|
|
250
|
+
export function formatSeconds(value) {
|
|
251
|
+
const floor = Math.floor(value);
|
|
252
|
+
const remainder = value - floor;
|
|
253
|
+
if (remainder > 0.5)
|
|
254
|
+
return `${floor + 1}`;
|
|
255
|
+
if (remainder < 0.5)
|
|
256
|
+
return `${floor}`;
|
|
257
|
+
return `${floor % 2 === 0 ? floor : floor + 1}`;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=service-state.js.map
|