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,373 @@
|
|
|
1
|
+
import { assessVision, VISION_ASSESS_SYSTEM, VisionMonitorMachine, } from './assess.js';
|
|
2
|
+
export const VISION_AGENT_DESCRIPTOR = Object.freeze({
|
|
3
|
+
name: 'vision',
|
|
4
|
+
summary: 'Monitors the camera for a bounded visual condition.',
|
|
5
|
+
ownedChannels: Object.freeze(['watch', 'guard']),
|
|
6
|
+
});
|
|
7
|
+
const EMPTY_DETAIL = Object.freeze({});
|
|
8
|
+
const VISION_STRING_LIMIT = 2_000;
|
|
9
|
+
const DEFAULT_ASSESSMENT_TIMEOUT_MS = 5_000;
|
|
10
|
+
const HOST_IDENTIFIER_LIMIT = 128;
|
|
11
|
+
function deepFreeze(value) {
|
|
12
|
+
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
13
|
+
Object.freeze(value);
|
|
14
|
+
for (const child of Object.values(value))
|
|
15
|
+
deepFreeze(child);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
/** JSON Schema sent to the assess model. Keep this in lockstep with visionAssessSchema. */
|
|
20
|
+
export const VISION_ASSESS_JSON_SCHEMA = deepFreeze({
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
request_id: { type: 'string', minLength: 1, maxLength: 128 },
|
|
24
|
+
revision: { type: 'integer', minimum: 0 },
|
|
25
|
+
kind: { type: 'string', enum: ['monitor', 'stop', 'unclear'] },
|
|
26
|
+
condition: { type: ['string', 'null'], maxLength: 300 },
|
|
27
|
+
urgency: { type: ['string', 'null'], enum: ['routine', 'urgent', null] },
|
|
28
|
+
urgency_evidence: { type: ['string', 'null'], maxLength: 300 },
|
|
29
|
+
interval_s: { type: ['number', 'null'] },
|
|
30
|
+
duration_s: { type: ['number', 'null'] },
|
|
31
|
+
question: { type: ['string', 'null'], maxLength: 300 },
|
|
32
|
+
},
|
|
33
|
+
required: [
|
|
34
|
+
'request_id', 'revision', 'kind', 'condition', 'urgency', 'urgency_evidence',
|
|
35
|
+
'interval_s', 'duration_s', 'question',
|
|
36
|
+
],
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
});
|
|
39
|
+
function emptyResult(code) {
|
|
40
|
+
return Object.freeze({ code, accepted: code === 'not_running' || code === 'busy' ? true : false, detail: EMPTY_DETAIL });
|
|
41
|
+
}
|
|
42
|
+
function unclearResult() {
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
code: 'unclear', accepted: true,
|
|
45
|
+
detail: Object.freeze({ reason: 'assessment_unclear' }),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function promptFor(identity, request) {
|
|
49
|
+
// JSON keeps the model-facing fields explicit while the per-field bounds prevent a user utterance
|
|
50
|
+
// from turning the assess slot into an unbounded context sink.
|
|
51
|
+
return JSON.stringify({
|
|
52
|
+
request_id: identity.request_id,
|
|
53
|
+
revision: identity.revision,
|
|
54
|
+
accepted_revision: identity.revision,
|
|
55
|
+
original_user_text: request.originalUserText.slice(0, VISION_STRING_LIMIT),
|
|
56
|
+
instruction: request.instruction.slice(0, VISION_STRING_LIMIT),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function sameIdentity(left, right) {
|
|
60
|
+
return left.request_id === right.request_id
|
|
61
|
+
&& left.revision === right.revision
|
|
62
|
+
&& left.session_epoch === right.session_epoch;
|
|
63
|
+
}
|
|
64
|
+
function safeWanted(fn) {
|
|
65
|
+
try {
|
|
66
|
+
return fn() === true;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Copy exactly the tiny runtime admission result; never retain a provider-owned object. */
|
|
73
|
+
function parseRuntimeAdmission(value) {
|
|
74
|
+
try {
|
|
75
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
76
|
+
return null;
|
|
77
|
+
const prototype = Object.getPrototypeOf(value);
|
|
78
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
79
|
+
return null;
|
|
80
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
81
|
+
const keys = Reflect.ownKeys(descriptors);
|
|
82
|
+
if (keys.length !== 2 || !keys.includes('accepted') || !keys.includes('delegate_id'))
|
|
83
|
+
return null;
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
if (typeof key !== 'string')
|
|
86
|
+
return null;
|
|
87
|
+
const descriptor = descriptors[key];
|
|
88
|
+
if (descriptor === undefined || !descriptor.enumerable
|
|
89
|
+
|| descriptor.get !== undefined || descriptor.set !== undefined
|
|
90
|
+
|| !Object.hasOwn(descriptor, 'value'))
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const accepted = descriptors.accepted?.value;
|
|
94
|
+
const delegateId = descriptors.delegate_id?.value;
|
|
95
|
+
if (typeof accepted !== 'boolean')
|
|
96
|
+
return null;
|
|
97
|
+
if (delegateId !== null && typeof delegateId !== 'string')
|
|
98
|
+
return null;
|
|
99
|
+
if (typeof delegateId === 'string' && delegateId.length > HOST_IDENTIFIER_LIMIT)
|
|
100
|
+
return null;
|
|
101
|
+
return { accepted, delegate_id: delegateId };
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Thin Vision controller core. It owns only assessment, the one-monitor reservation, and calls to
|
|
109
|
+
* the host runtime operation port. Public result wording and AgentController adaptation stay outside.
|
|
110
|
+
*/
|
|
111
|
+
export class VisionAgentControllerCore {
|
|
112
|
+
descriptor = VISION_AGENT_DESCRIPTOR;
|
|
113
|
+
#gateway;
|
|
114
|
+
#model;
|
|
115
|
+
#requestIdFactory;
|
|
116
|
+
#runtimePort;
|
|
117
|
+
#assessmentTimeoutMs;
|
|
118
|
+
#lifecycleSink;
|
|
119
|
+
#machine = new VisionMonitorMachine();
|
|
120
|
+
#active = null;
|
|
121
|
+
constructor(options) {
|
|
122
|
+
const model = options.watchModel ?? options.model;
|
|
123
|
+
const requestIdFactory = options.requestIdFactory ?? options.idFactory;
|
|
124
|
+
const runtimePort = options.runtimePort ?? options.runtime;
|
|
125
|
+
if (model === undefined || model.trim() === '')
|
|
126
|
+
throw new TypeError('vision watch model is required');
|
|
127
|
+
if (requestIdFactory === undefined)
|
|
128
|
+
throw new TypeError('vision request id factory is required');
|
|
129
|
+
if (runtimePort === undefined)
|
|
130
|
+
throw new TypeError('vision runtime port is required');
|
|
131
|
+
this.#gateway = options.gateway;
|
|
132
|
+
this.#model = model;
|
|
133
|
+
this.#requestIdFactory = requestIdFactory;
|
|
134
|
+
this.#runtimePort = runtimePort;
|
|
135
|
+
this.#assessmentTimeoutMs = options.assessmentTimeoutMs ?? DEFAULT_ASSESSMENT_TIMEOUT_MS;
|
|
136
|
+
this.#lifecycleSink = options.lifecycleSink;
|
|
137
|
+
}
|
|
138
|
+
get state() { return this.#machine.state; }
|
|
139
|
+
get identity() { return this.#machine.identity; }
|
|
140
|
+
async dispatch(request) {
|
|
141
|
+
if (this.#machine.state !== 'idle')
|
|
142
|
+
return emptyResult('busy');
|
|
143
|
+
if (!safeWanted(request.stillWanted))
|
|
144
|
+
return emptyResult('superseded');
|
|
145
|
+
let identity;
|
|
146
|
+
try {
|
|
147
|
+
identity = {
|
|
148
|
+
request_id: this.#requestIdFactory(),
|
|
149
|
+
revision: request.acceptedUserInputRevision,
|
|
150
|
+
session_epoch: request.sessionEpoch,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return emptyResult('assessment_unavailable');
|
|
155
|
+
}
|
|
156
|
+
const context = {
|
|
157
|
+
request_id: identity.request_id,
|
|
158
|
+
revision: identity.revision,
|
|
159
|
+
session_epoch: identity.session_epoch,
|
|
160
|
+
original_user_text: request.originalUserText,
|
|
161
|
+
stillWanted: request.stillWanted,
|
|
162
|
+
...(request.currentRequestId === undefined ? {} : { current_request_id: request.currentRequestId }),
|
|
163
|
+
...(request.currentRevision === undefined ? {} : { current_revision: request.currentRevision }),
|
|
164
|
+
...(request.currentSessionEpoch === undefined ? {} : { current_session_epoch: request.currentSessionEpoch }),
|
|
165
|
+
};
|
|
166
|
+
const assessed = await this.#assess(identity, request);
|
|
167
|
+
if (assessed === null)
|
|
168
|
+
return emptyResult('assessment_unavailable');
|
|
169
|
+
const decision = assessVision(assessed, context);
|
|
170
|
+
if (decision.code === 'no_action') {
|
|
171
|
+
return decision.reason === 'invalid_schema' ? emptyResult('assessment_unavailable') : unclearResult();
|
|
172
|
+
}
|
|
173
|
+
if (decision.code === 'superseded' || !decision.recheck())
|
|
174
|
+
return emptyResult('superseded');
|
|
175
|
+
if (decision.code === 'unclear')
|
|
176
|
+
return unclearResult();
|
|
177
|
+
if (decision.code === 'stop')
|
|
178
|
+
return Promise.resolve(this.#stop(request, 'requested_stop', decision.recheck));
|
|
179
|
+
// This is the last fence before reserving the global slot.
|
|
180
|
+
if (!decision.recheck())
|
|
181
|
+
return emptyResult('superseded');
|
|
182
|
+
const machineReservation = this.#machine.reserve(decision.identity);
|
|
183
|
+
if (machineReservation.code === 'busy')
|
|
184
|
+
return emptyResult('busy');
|
|
185
|
+
if (machineReservation.code === 'stale')
|
|
186
|
+
return emptyResult('superseded');
|
|
187
|
+
const channel = decision.assessment.urgency === 'urgent' ? 'guard' : 'watch';
|
|
188
|
+
// Publish the reservation before entering the port: permission callbacks can arrive reentrantly
|
|
189
|
+
// from the synchronous runtime adapter and must see the pending reservation.
|
|
190
|
+
const reservation = {
|
|
191
|
+
identity: { ...decision.identity }, channel, origin_ref: request.origin_ref,
|
|
192
|
+
stillWanted: request.stillWanted, fence: decision.recheck, delegate_id: '',
|
|
193
|
+
stopAccepted: false,
|
|
194
|
+
stopAdmission: null,
|
|
195
|
+
};
|
|
196
|
+
this.#active = reservation;
|
|
197
|
+
// The final pre-effect fence is intentionally after reservation: pending permission is already
|
|
198
|
+
// busy, but a stale request must not even enter the runtime operation port.
|
|
199
|
+
if (!decision.recheck()) {
|
|
200
|
+
this.#releaseRejected(decision.identity);
|
|
201
|
+
return emptyResult('superseded');
|
|
202
|
+
}
|
|
203
|
+
let admission;
|
|
204
|
+
try {
|
|
205
|
+
admission = parseRuntimeAdmission(await this.#runtimePort.dispatch({
|
|
206
|
+
channel,
|
|
207
|
+
op: 'start',
|
|
208
|
+
request: {
|
|
209
|
+
condition: decision.assessment.condition,
|
|
210
|
+
interval_s: decision.assessment.interval_s,
|
|
211
|
+
duration_s: decision.assessment.duration_s,
|
|
212
|
+
},
|
|
213
|
+
origin_ref: request.origin_ref,
|
|
214
|
+
stillWanted: () => safeWanted(request.stillWanted) && decision.recheck(),
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
admission = null;
|
|
219
|
+
}
|
|
220
|
+
if (admission === null || !admission.accepted || admission.delegate_id === null || admission.delegate_id === '') {
|
|
221
|
+
this.#releaseRejected(decision.identity);
|
|
222
|
+
return emptyResult('runtime_rejected');
|
|
223
|
+
}
|
|
224
|
+
// A reentrant terminal callback may have fenced and cleaned the reservation before dispatch
|
|
225
|
+
// returned. Its accepted result must not resurrect the monitor slot.
|
|
226
|
+
reservation.delegate_id = admission.delegate_id;
|
|
227
|
+
this.#lifecycleSink?.bind(admission.delegate_id, decision.identity);
|
|
228
|
+
const stateAfterAdmission = this.#machine.state;
|
|
229
|
+
const stillReserved = (stateAfterAdmission === 'permission-pending' || stateAfterAdmission === 'active')
|
|
230
|
+
&& this.#machine.identity !== null && sameIdentity(this.#machine.identity, decision.identity)
|
|
231
|
+
&& this.#active === reservation;
|
|
232
|
+
if (!stillReserved) {
|
|
233
|
+
this.#compensatingStop(reservation);
|
|
234
|
+
return emptyResult('superseded');
|
|
235
|
+
}
|
|
236
|
+
if (!decision.recheck()) {
|
|
237
|
+
this.#machine.cancel(decision.identity);
|
|
238
|
+
this.#compensatingStop(reservation);
|
|
239
|
+
return emptyResult('superseded');
|
|
240
|
+
}
|
|
241
|
+
return Object.freeze({
|
|
242
|
+
code: 'delegated',
|
|
243
|
+
accepted: true,
|
|
244
|
+
delegate_id: admission.delegate_id,
|
|
245
|
+
detail: Object.freeze({ channel, op: 'start' }),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
cancel(request) {
|
|
249
|
+
return Promise.resolve(this.#stop(request, 'cancelled'));
|
|
250
|
+
}
|
|
251
|
+
/** Host callback after camera permission admission. A stale identity is fenced, never granted. */
|
|
252
|
+
permissionGranted(identity) {
|
|
253
|
+
const active = this.#active;
|
|
254
|
+
if (active === null || !sameIdentity(active.identity, identity))
|
|
255
|
+
return false;
|
|
256
|
+
if (!safeWanted(active.stillWanted) || !safeWanted(active.fence)) {
|
|
257
|
+
if (this.#machine.state === 'permission-pending' || this.#machine.state === 'active') {
|
|
258
|
+
this.#machine.cancel(active.identity);
|
|
259
|
+
this.#compensatingStop(active);
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const granted = this.#machine.grant({ ...identity });
|
|
264
|
+
return granted.code === 'active' || granted.code === 'already_active';
|
|
265
|
+
}
|
|
266
|
+
/** Host callback for an executor terminal. Cleanup is exact-identity and idempotent. */
|
|
267
|
+
terminal(identity) { this.#cleanupTerminal({ ...identity }); }
|
|
268
|
+
/** Reports do not release the single active monitor reservation. */
|
|
269
|
+
hit(identity) { this.#machine.hit({ ...identity }); }
|
|
270
|
+
async #assess(identity, request) {
|
|
271
|
+
const controller = new AbortController();
|
|
272
|
+
let timer;
|
|
273
|
+
try {
|
|
274
|
+
const completion = this.#gateway.complete({
|
|
275
|
+
model: this.#model,
|
|
276
|
+
system: VISION_ASSESS_SYSTEM,
|
|
277
|
+
prompt: promptFor(identity, request),
|
|
278
|
+
jsonSchema: VISION_ASSESS_JSON_SCHEMA,
|
|
279
|
+
signal: controller.signal,
|
|
280
|
+
});
|
|
281
|
+
const response = Number.isFinite(this.#assessmentTimeoutMs) && this.#assessmentTimeoutMs > 0
|
|
282
|
+
? await Promise.race([
|
|
283
|
+
completion,
|
|
284
|
+
new Promise((_, reject) => {
|
|
285
|
+
timer = setTimeout(() => {
|
|
286
|
+
controller.abort();
|
|
287
|
+
reject(new Error('vision assessment timeout'));
|
|
288
|
+
}, this.#assessmentTimeoutMs);
|
|
289
|
+
}),
|
|
290
|
+
])
|
|
291
|
+
: await completion;
|
|
292
|
+
if (typeof response.text !== 'string')
|
|
293
|
+
return null;
|
|
294
|
+
return JSON.parse(response.text);
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
if (timer !== undefined)
|
|
301
|
+
clearTimeout(timer);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async #stop(request, successCode, wanted = request.stillWanted) {
|
|
305
|
+
const active = this.#active;
|
|
306
|
+
if (this.#machine.state === 'idle' || active === null)
|
|
307
|
+
return emptyResult('not_running');
|
|
308
|
+
if (!safeWanted(request.stillWanted) || !safeWanted(wanted))
|
|
309
|
+
return emptyResult('superseded');
|
|
310
|
+
const cancellation = this.#machine.cancel(active.identity);
|
|
311
|
+
if (cancellation.code === 'already_cancelled') {
|
|
312
|
+
if (!await this.#dispatchStop(active, request.origin_ref))
|
|
313
|
+
return emptyResult('runtime_rejected');
|
|
314
|
+
return Object.freeze({
|
|
315
|
+
code: 'requested_stop', accepted: true,
|
|
316
|
+
detail: Object.freeze({ channel: active.channel, op: 'stop' }),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (cancellation.code !== 'cancelled')
|
|
320
|
+
return emptyResult('not_running');
|
|
321
|
+
const accepted = await this.#dispatchStop(active, request.origin_ref);
|
|
322
|
+
if (!accepted) {
|
|
323
|
+
// Keep the fenced terminal reservation: the runtime may have started work even when its stop
|
|
324
|
+
// admission was rejected. Only an exact terminal callback can prove it is safe to reopen.
|
|
325
|
+
return emptyResult('runtime_rejected');
|
|
326
|
+
}
|
|
327
|
+
return Object.freeze({
|
|
328
|
+
code: successCode,
|
|
329
|
+
accepted: true,
|
|
330
|
+
detail: Object.freeze({ channel: active.channel, op: 'stop' }),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
#releaseRejected(identity) {
|
|
334
|
+
this.#machine.cancel({ ...identity });
|
|
335
|
+
this.#machine.cleanup({ ...identity });
|
|
336
|
+
if (this.#active !== null && sameIdentity(this.#active.identity, identity))
|
|
337
|
+
this.#active = null;
|
|
338
|
+
}
|
|
339
|
+
#compensatingStop(active) {
|
|
340
|
+
// This is cleanup for an already-admitted exact identity, so it must not depend on the stale
|
|
341
|
+
// user fence that caused the compensation. The machine is fenced before this effect.
|
|
342
|
+
void this.#dispatchStop(active);
|
|
343
|
+
}
|
|
344
|
+
/** Concurrent cancellation and compensation share the exact same pending stop admission. */
|
|
345
|
+
#dispatchStop(active, originRef = active.origin_ref) {
|
|
346
|
+
if (active.stopAccepted)
|
|
347
|
+
return Promise.resolve(true);
|
|
348
|
+
active.stopAdmission ??= (async () => {
|
|
349
|
+
try {
|
|
350
|
+
const result = parseRuntimeAdmission(await this.#runtimePort.dispatch({
|
|
351
|
+
channel: active.channel, op: 'stop', request: {}, origin_ref: originRef,
|
|
352
|
+
stillWanted: () => true,
|
|
353
|
+
}));
|
|
354
|
+
active.stopAccepted = result?.accepted === true;
|
|
355
|
+
return active.stopAccepted;
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
})().finally(() => { active.stopAdmission = null; });
|
|
361
|
+
return active.stopAdmission;
|
|
362
|
+
}
|
|
363
|
+
#cleanupTerminal(identity) {
|
|
364
|
+
const canceled = this.#machine.state === 'active' || this.#machine.state === 'permission-pending';
|
|
365
|
+
if (canceled)
|
|
366
|
+
this.#machine.cancel({ ...identity });
|
|
367
|
+
const cleaned = this.#machine.cleanup({ ...identity });
|
|
368
|
+
if ((cleaned.code === 'cleaned' || cleaned.code === 'already_idle')
|
|
369
|
+
&& this.#active !== null && sameIdentity(this.#active.identity, identity))
|
|
370
|
+
this.#active = null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
//# sourceMappingURL=controller-core.js.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { parseAgentActionResult, } from '../agent-controller.js';
|
|
2
|
+
import { types as nodeTypes } from 'node:util';
|
|
3
|
+
import { VISION_AGENT_DESCRIPTOR, } from './controller-core.js';
|
|
4
|
+
/**
|
|
5
|
+
* Public host-controller facade for the Vision core.
|
|
6
|
+
*
|
|
7
|
+
* The core owns assessment and runtime admission. This adapter owns the public, closed result
|
|
8
|
+
* vocabulary; it reconstructs every detail object so a future core/provider cannot put prose or an
|
|
9
|
+
* unbounded field on the realtime-facing result.
|
|
10
|
+
*/
|
|
11
|
+
export class VisionAgentController {
|
|
12
|
+
descriptor = VISION_AGENT_DESCRIPTOR;
|
|
13
|
+
#core;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.#core = options.core;
|
|
16
|
+
}
|
|
17
|
+
async dispatch(request) {
|
|
18
|
+
try {
|
|
19
|
+
return this.#normalize(await this.#core.dispatch(request));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return unavailable();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async cancel(request) {
|
|
26
|
+
try {
|
|
27
|
+
return this.#normalize(await this.#core.cancel(request));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return unavailable();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
#normalize(value) {
|
|
34
|
+
const record = readPlainRecord(value);
|
|
35
|
+
if (record === null || typeof record.values.code !== 'string')
|
|
36
|
+
return unavailable();
|
|
37
|
+
const code = record.values.code;
|
|
38
|
+
let candidate;
|
|
39
|
+
switch (code) {
|
|
40
|
+
case 'delegated': {
|
|
41
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'delegate_id', 'detail'])
|
|
42
|
+
|| record.values.accepted !== true || !isBoundedIdentifier(record.values.delegate_id))
|
|
43
|
+
return unavailable();
|
|
44
|
+
const detail = readPlainRecord(record.values.detail);
|
|
45
|
+
if (detail === null || !hasExactKeys(detail, ['channel', 'op'])
|
|
46
|
+
|| !isVisionChannel(detail.values.channel) || detail.values.op !== 'start')
|
|
47
|
+
return unavailable();
|
|
48
|
+
candidate = {
|
|
49
|
+
code: 'delegated', accepted: true, delegate_id: record.values.delegate_id,
|
|
50
|
+
detail: { channel: detail.values.channel, op: 'start' },
|
|
51
|
+
};
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'cancelled':
|
|
55
|
+
case 'requested_stop': {
|
|
56
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== true)
|
|
57
|
+
return unavailable();
|
|
58
|
+
const detail = readPlainRecord(record.values.detail);
|
|
59
|
+
if (detail === null || !hasExactKeys(detail, ['channel', 'op'])
|
|
60
|
+
|| !isVisionChannel(detail.values.channel) || detail.values.op !== 'stop')
|
|
61
|
+
return unavailable();
|
|
62
|
+
candidate = {
|
|
63
|
+
code: 'monitor_stop_requested', accepted: true,
|
|
64
|
+
detail: { channel: detail.values.channel, op: 'stop' },
|
|
65
|
+
};
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'unclear':
|
|
69
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== true
|
|
70
|
+
|| !hasExactDetail(record.values.detail, { reason: 'assessment_unclear' }))
|
|
71
|
+
return unavailable();
|
|
72
|
+
candidate = { code: 'clarification_required', accepted: true, detail: {} };
|
|
73
|
+
break;
|
|
74
|
+
case 'busy':
|
|
75
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== true
|
|
76
|
+
|| !isEmptyDetail(record.values.detail))
|
|
77
|
+
return unavailable();
|
|
78
|
+
candidate = { code: 'busy', accepted: true, detail: {} };
|
|
79
|
+
break;
|
|
80
|
+
case 'assessment_unavailable':
|
|
81
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== false
|
|
82
|
+
|| !isEmptyDetail(record.values.detail))
|
|
83
|
+
return unavailable();
|
|
84
|
+
candidate = { code: 'assessment_unavailable', accepted: false, detail: {} };
|
|
85
|
+
break;
|
|
86
|
+
case 'not_running':
|
|
87
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== true
|
|
88
|
+
|| !isEmptyDetail(record.values.detail))
|
|
89
|
+
return unavailable();
|
|
90
|
+
candidate = { code: 'not_running', accepted: true, detail: {} };
|
|
91
|
+
break;
|
|
92
|
+
case 'superseded':
|
|
93
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== false
|
|
94
|
+
|| !isEmptyDetail(record.values.detail))
|
|
95
|
+
return unavailable();
|
|
96
|
+
candidate = { code: 'superseded', accepted: false, detail: {} };
|
|
97
|
+
break;
|
|
98
|
+
case 'runtime_rejected':
|
|
99
|
+
if (!hasExactKeys(record, ['accepted', 'code', 'detail']) || record.values.accepted !== false
|
|
100
|
+
|| !isEmptyDetail(record.values.detail))
|
|
101
|
+
return unavailable();
|
|
102
|
+
candidate = { code: 'runtime_rejected', accepted: false, detail: {} };
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
return unavailable();
|
|
106
|
+
}
|
|
107
|
+
return parseAgentActionResult(candidate) ?? unavailable();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function readPlainRecord(value) {
|
|
111
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
112
|
+
return null;
|
|
113
|
+
try {
|
|
114
|
+
if (nodeTypes.isProxy(value) || Object.getPrototypeOf(value) !== Object.prototype)
|
|
115
|
+
return null;
|
|
116
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
117
|
+
const keys = Reflect.ownKeys(descriptors);
|
|
118
|
+
const stringKeys = [];
|
|
119
|
+
const values = Object.create(null);
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
if (typeof key !== 'string')
|
|
122
|
+
return null;
|
|
123
|
+
stringKeys.push(key);
|
|
124
|
+
const descriptor = descriptors[key];
|
|
125
|
+
if (descriptor === undefined || !descriptor.enumerable || descriptor.get !== undefined
|
|
126
|
+
|| descriptor.set !== undefined || !Object.hasOwn(descriptor, 'value'))
|
|
127
|
+
return null;
|
|
128
|
+
Object.defineProperty(values, key, { value: descriptor.value, enumerable: true, writable: false, configurable: false });
|
|
129
|
+
}
|
|
130
|
+
return Object.freeze({ values: Object.freeze(values), keys: Object.freeze(stringKeys) });
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function hasExactKeys(record, expected) {
|
|
137
|
+
if (record.keys.length !== expected.length)
|
|
138
|
+
return false;
|
|
139
|
+
return expected.every(key => record.keys.includes(key));
|
|
140
|
+
}
|
|
141
|
+
function isEmptyDetail(value) {
|
|
142
|
+
const detail = readPlainRecord(value);
|
|
143
|
+
return detail !== null && detail.keys.length === 0;
|
|
144
|
+
}
|
|
145
|
+
function hasExactDetail(value, expected) {
|
|
146
|
+
const detail = readPlainRecord(value);
|
|
147
|
+
if (detail === null || !hasExactKeys(detail, Object.keys(expected)))
|
|
148
|
+
return false;
|
|
149
|
+
return Object.entries(expected).every(([key, item]) => detail.values[key] === item);
|
|
150
|
+
}
|
|
151
|
+
function isBoundedIdentifier(value) {
|
|
152
|
+
return typeof value === 'string' && value.length >= 1 && value.length <= 128;
|
|
153
|
+
}
|
|
154
|
+
function isVisionChannel(value) {
|
|
155
|
+
return value === 'watch' || value === 'guard';
|
|
156
|
+
}
|
|
157
|
+
function unavailable() {
|
|
158
|
+
const result = { code: 'assessment_unavailable', accepted: false, detail: {} };
|
|
159
|
+
const parsed = parseAgentActionResult(result);
|
|
160
|
+
if (parsed === null)
|
|
161
|
+
throw new Error('invalid built-in assessment_unavailable result');
|
|
162
|
+
return parsed;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
/** Host-private delegate correlation; stale callbacks can only touch their own identity. */
|
|
3
|
+
export class VisionLifecycleBridge {
|
|
4
|
+
static MAX_PENDING = 64;
|
|
5
|
+
#identities = new Map();
|
|
6
|
+
#pending = new Map();
|
|
7
|
+
#target = null;
|
|
8
|
+
attach(target) { this.#target = target; }
|
|
9
|
+
bind(delegateId, identity) {
|
|
10
|
+
this.#identities.set(delegateId, { ...identity });
|
|
11
|
+
const pending = this.#pending.get(delegateId);
|
|
12
|
+
this.#pending.delete(delegateId);
|
|
13
|
+
// A callback which arrived before its delegate was bound must fail closed. Its Watch has already
|
|
14
|
+
// stopped, so a following terminal wins over any queued grant and must not briefly activate this
|
|
15
|
+
// controller slot while binding catches up.
|
|
16
|
+
if (pending?.has('terminal')) {
|
|
17
|
+
this.#terminal(delegateId, identity);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (pending?.has('granted'))
|
|
21
|
+
this.#target?.permissionGranted(identity);
|
|
22
|
+
if (pending?.has('hit'))
|
|
23
|
+
this.#target?.hit(identity);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Permission is the synchronous no-return boundary: a queued runtime stop cannot prevent a Watch
|
|
27
|
+
* from arming in the current stack, so it must receive an immediate proceed/deny decision here.
|
|
28
|
+
*/
|
|
29
|
+
admission(delegateId, status) {
|
|
30
|
+
if (status !== 'granted')
|
|
31
|
+
return true;
|
|
32
|
+
const identity = this.#identities.get(delegateId);
|
|
33
|
+
if (identity === undefined) {
|
|
34
|
+
this.#queue(delegateId, 'granted');
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
return this.#target?.permissionGranted(identity) === true;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** A hit is a report; only stop/timeout/failure releases the task. */
|
|
45
|
+
hit(delegateId) { this.#deliver(delegateId, 'hit'); return false; }
|
|
46
|
+
terminal(delegateId) { this.#deliver(delegateId, 'terminal'); }
|
|
47
|
+
#deliver(delegateId, kind) {
|
|
48
|
+
const identity = this.#identities.get(delegateId);
|
|
49
|
+
if (identity === undefined) {
|
|
50
|
+
this.#queue(delegateId, kind);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (kind === 'hit')
|
|
54
|
+
this.#target?.hit(identity);
|
|
55
|
+
else
|
|
56
|
+
this.#terminal(delegateId, identity);
|
|
57
|
+
}
|
|
58
|
+
#queue(delegateId, kind) {
|
|
59
|
+
if (this.#pending.size >= _a.MAX_PENDING && !this.#pending.has(delegateId))
|
|
60
|
+
return;
|
|
61
|
+
this.#pending.set(delegateId, new Set([...(this.#pending.get(delegateId) ?? []), kind]));
|
|
62
|
+
}
|
|
63
|
+
#terminal(delegateId, identity) {
|
|
64
|
+
this.#target?.terminal(identity);
|
|
65
|
+
this.#identities.delete(delegateId);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_a = VisionLifecycleBridge;
|
|
69
|
+
//# sourceMappingURL=lifecycle.js.map
|