@zhin.js/agent 1.1.13 → 1.1.14
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/README.md +40 -20
- package/lib/ai-event-bus.d.ts +1 -1
- package/lib/ai-hook-handlers.d.ts +1 -1
- package/lib/assistant/config.d.ts +3 -17
- package/lib/assistant/config.d.ts.map +1 -1
- package/lib/assistant/config.js +1 -8
- package/lib/assistant/config.js.map +1 -1
- package/lib/assistant/index.d.ts +6 -9
- package/lib/assistant/index.d.ts.map +1 -1
- package/lib/assistant/index.js +4 -6
- package/lib/assistant/index.js.map +1 -1
- package/lib/assistant/job-engine.d.ts +0 -4
- package/lib/assistant/job-engine.d.ts.map +1 -1
- package/lib/assistant/job-engine.js +0 -2
- package/lib/assistant/job-engine.js.map +1 -1
- package/lib/assistant/job-store.d.ts +1 -8
- package/lib/assistant/job-store.d.ts.map +1 -1
- package/lib/assistant/job-store.js +3 -9
- package/lib/assistant/job-store.js.map +1 -1
- package/lib/assistant/job-worker.d.ts +2 -3
- package/lib/assistant/job-worker.d.ts.map +1 -1
- package/lib/assistant/job-worker.js +15 -25
- package/lib/assistant/job-worker.js.map +1 -1
- package/lib/assistant/runtime-contract.d.ts +22 -0
- package/lib/assistant/runtime-contract.d.ts.map +1 -0
- package/lib/assistant/runtime-contract.js +2 -0
- package/lib/assistant/runtime-contract.js.map +1 -0
- package/lib/assistant/types.d.ts +0 -10
- package/lib/assistant/types.d.ts.map +1 -1
- package/lib/assistant/types.js +0 -4
- package/lib/assistant/types.js.map +1 -1
- package/lib/authoring/bridge.d.ts +1 -1
- package/lib/authoring/index.d.ts +0 -4
- package/lib/authoring/index.d.ts.map +1 -1
- package/lib/authoring/index.js +0 -2
- package/lib/authoring/index.js.map +1 -1
- package/lib/authoring/types.d.ts +3 -39
- package/lib/authoring/types.d.ts.map +1 -1
- package/lib/authoring/types.js.map +1 -1
- package/lib/builtin/bash-tool.d.ts.map +1 -1
- package/lib/builtin/bash-tool.js +15 -2
- package/lib/builtin/bash-tool.js.map +1 -1
- package/lib/builtin/five-agent/index.d.ts +0 -1
- package/lib/builtin/five-agent/index.d.ts.map +1 -1
- package/lib/builtin/five-agent/index.js +0 -1
- package/lib/builtin/five-agent/index.js.map +1 -1
- package/lib/builtin/five-agent/role-capability-policy.d.ts +1 -1
- package/lib/builtin/five-agent/role-capability-policy.d.ts.map +1 -1
- package/lib/builtin/five-agent/role-capability-policy.js +1 -1
- package/lib/builtin/five-agent/role-capability-policy.js.map +1 -1
- package/lib/builtin/spawn-task-tool.d.ts +1 -1
- package/lib/builtin/spawn-task-tool.d.ts.map +1 -1
- package/lib/builtin/spawn-task-tool.js +4 -100
- package/lib/builtin/spawn-task-tool.js.map +1 -1
- package/lib/builtin-tools.d.ts +0 -2
- package/lib/builtin-tools.d.ts.map +1 -1
- package/lib/builtin-tools.js +0 -6
- package/lib/builtin-tools.js.map +1 -1
- package/lib/common-adapter-tools.d.ts +1 -1
- package/lib/config/agent-interfaces.d.ts +2 -1
- package/lib/config/agent-interfaces.d.ts.map +1 -1
- package/lib/config/index.d.ts +3 -3
- package/lib/config/index.d.ts.map +1 -1
- package/lib/config/index.js +2 -2
- package/lib/config/index.js.map +1 -1
- package/lib/config/keyword-triggers.d.ts +0 -1
- package/lib/config/keyword-triggers.d.ts.map +1 -1
- package/lib/config/keyword-triggers.js +0 -1
- package/lib/config/keyword-triggers.js.map +1 -1
- package/lib/config/normalize-ai-config.d.ts.map +1 -1
- package/lib/config/normalize-ai-config.js +9 -0
- package/lib/config/normalize-ai-config.js.map +1 -1
- package/lib/config/validate-ai-config.d.ts +1 -0
- package/lib/config/validate-ai-config.d.ts.map +1 -1
- package/lib/config/validate-ai-config.js +179 -0
- package/lib/config/validate-ai-config.js.map +1 -1
- package/lib/config/zhin-agent-config.d.ts +0 -3
- package/lib/config/zhin-agent-config.d.ts.map +1 -1
- package/lib/config/zhin-agent-constants.d.ts +0 -3
- package/lib/config/zhin-agent-constants.d.ts.map +1 -1
- package/lib/config/zhin-agent-constants.js +0 -14
- package/lib/config/zhin-agent-constants.js.map +1 -1
- package/lib/config/zhin-agent-defaults.d.ts.map +1 -1
- package/lib/config/zhin-agent-defaults.js +0 -3
- package/lib/config/zhin-agent-defaults.js.map +1 -1
- package/lib/config/zhin-agent-dependencies.d.ts +4 -5
- package/lib/config/zhin-agent-dependencies.d.ts.map +1 -1
- package/lib/context/context-system.d.ts +2 -1
- package/lib/context/context-system.d.ts.map +1 -1
- package/lib/context/context-system.js +1 -0
- package/lib/context/context-system.js.map +1 -1
- package/lib/context/context-tail-limit.d.ts +2 -2
- package/lib/context/context-tail-limit.d.ts.map +1 -1
- package/lib/context/context-tail-limit.js +2 -3
- package/lib/context/context-tail-limit.js.map +1 -1
- package/lib/context/im-turn-context-adapter.d.ts +1 -2
- package/lib/context/im-turn-context-adapter.d.ts.map +1 -1
- package/lib/context/im-turn-context-adapter.js +1 -5
- package/lib/context/im-turn-context-adapter.js.map +1 -1
- package/lib/context/turn-envelope.d.ts +1 -1
- package/lib/context/turn-envelope.d.ts.map +1 -1
- package/lib/context/turn-envelope.js +4 -0
- package/lib/context/turn-envelope.js.map +1 -1
- package/lib/context/turn-user-message.d.ts +1 -1
- package/lib/context/turn-user-message.d.ts.map +1 -1
- package/lib/context/turn-user-message.js +3 -3
- package/lib/context/turn-user-message.js.map +1 -1
- package/lib/core/agent-core-run.d.ts.map +1 -1
- package/lib/core/agent-core-run.js +36 -12
- package/lib/core/agent-core-run.js.map +1 -1
- package/lib/core/agent-loop-standalone.d.ts +1 -1
- package/lib/core/agent-loop-standalone.js +13 -6
- package/lib/core/agent-loop-standalone.js.map +1 -1
- package/lib/core/tool-execution-authority.d.ts +2 -2
- package/lib/core/tool-execution-authority.d.ts.map +1 -1
- package/lib/data-governance/data-governance.d.ts +198 -0
- package/lib/data-governance/data-governance.d.ts.map +1 -0
- package/lib/data-governance/data-governance.js +660 -0
- package/lib/data-governance/data-governance.js.map +1 -0
- package/lib/data-governance/database-payload-lifecycle-repository.d.ts +68 -0
- package/lib/data-governance/database-payload-lifecycle-repository.d.ts.map +1 -0
- package/lib/data-governance/database-payload-lifecycle-repository.js +226 -0
- package/lib/data-governance/database-payload-lifecycle-repository.js.map +1 -0
- package/lib/data-governance/disclosure-manifest.d.ts +110 -0
- package/lib/data-governance/disclosure-manifest.d.ts.map +1 -0
- package/lib/data-governance/disclosure-manifest.js +264 -0
- package/lib/data-governance/disclosure-manifest.js.map +1 -0
- package/lib/data-governance/encrypted-database-payload-vault.d.ts +107 -0
- package/lib/data-governance/encrypted-database-payload-vault.d.ts.map +1 -0
- package/lib/data-governance/encrypted-database-payload-vault.js +236 -0
- package/lib/data-governance/encrypted-database-payload-vault.js.map +1 -0
- package/lib/data-governance/encrypted-file-payload-vault.d.ts +117 -0
- package/lib/data-governance/encrypted-file-payload-vault.d.ts.map +1 -0
- package/lib/data-governance/encrypted-file-payload-vault.js +507 -0
- package/lib/data-governance/encrypted-file-payload-vault.js.map +1 -0
- package/lib/data-governance/file-payload-lifecycle-repository.d.ts +19 -0
- package/lib/data-governance/file-payload-lifecycle-repository.d.ts.map +1 -0
- package/lib/data-governance/file-payload-lifecycle-repository.js +194 -0
- package/lib/data-governance/file-payload-lifecycle-repository.js.map +1 -0
- package/lib/data-governance/governance-authority-repository.d.ts +148 -0
- package/lib/data-governance/governance-authority-repository.d.ts.map +1 -0
- package/lib/data-governance/governance-authority-repository.js +439 -0
- package/lib/data-governance/governance-authority-repository.js.map +1 -0
- package/lib/data-governance/governed-payload-write-saga.d.ts +126 -0
- package/lib/data-governance/governed-payload-write-saga.d.ts.map +1 -0
- package/lib/data-governance/governed-payload-write-saga.js +471 -0
- package/lib/data-governance/governed-payload-write-saga.js.map +1 -0
- package/lib/data-governance/payload-hold-overdue-projection.d.ts +57 -0
- package/lib/data-governance/payload-hold-overdue-projection.d.ts.map +1 -0
- package/lib/data-governance/payload-hold-overdue-projection.js +80 -0
- package/lib/data-governance/payload-hold-overdue-projection.js.map +1 -0
- package/lib/data-governance/payload-lifecycle.d.ts +359 -0
- package/lib/data-governance/payload-lifecycle.d.ts.map +1 -0
- package/lib/data-governance/payload-lifecycle.js +930 -0
- package/lib/data-governance/payload-lifecycle.js.map +1 -0
- package/lib/data-governance/payload-vault-storage-handoff.d.ts +255 -0
- package/lib/data-governance/payload-vault-storage-handoff.d.ts.map +1 -0
- package/lib/data-governance/payload-vault-storage-handoff.js +471 -0
- package/lib/data-governance/payload-vault-storage-handoff.js.map +1 -0
- package/lib/defaults/hooks.d.ts +2 -2
- package/lib/defaults/hooks.d.ts.map +1 -1
- package/lib/defaults/hooks.js +2 -2
- package/lib/defaults/hooks.js.map +1 -1
- package/lib/defaults/subagents.d.ts +2 -2
- package/lib/defaults/subagents.d.ts.map +1 -1
- package/lib/defaults/subagents.js +2 -2
- package/lib/defaults/subagents.js.map +1 -1
- package/lib/defaults/tools.d.ts +1 -2
- package/lib/defaults/tools.js +2 -2
- package/lib/defaults/tools.js.map +1 -1
- package/lib/discovery/agent-surface-info.d.ts +0 -2
- package/lib/discovery/agent-surface-info.d.ts.map +1 -1
- package/lib/discovery/agent-surface-info.js +0 -5
- package/lib/discovery/agent-surface-info.js.map +1 -1
- package/lib/discovery/agent-surface.d.ts.map +1 -1
- package/lib/discovery/agent-surface.js +0 -39
- package/lib/discovery/agent-surface.js.map +1 -1
- package/lib/event/agent-stream-hooks.d.ts +1 -1
- package/lib/event/hook-stream-sink.d.ts +1 -1
- package/lib/event/publish-agent-stream.d.ts +3 -3
- package/lib/event/publish-agent-stream.d.ts.map +1 -1
- package/lib/event/publish-agent-stream.js +1 -1
- package/lib/event/publish-agent-stream.js.map +1 -1
- package/lib/event/session-events.d.ts +1 -1
- package/lib/event/turn-event.d.ts +22 -2
- package/lib/event/turn-event.d.ts.map +1 -1
- package/lib/event/turn-event.js.map +1 -1
- package/lib/event/turn-to-agent-stream.js +6 -0
- package/lib/event/turn-to-agent-stream.js.map +1 -1
- package/lib/features/agent-feature.d.ts +1 -1
- package/lib/features/mcp-feature.d.ts +1 -1
- package/lib/index.d.ts +99 -33
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +94 -21
- package/lib/index.js.map +1 -1
- package/lib/ingress/capability-ingress.d.ts +5 -5
- package/lib/ingress/capability-ingress.d.ts.map +1 -1
- package/lib/ingress/capability-ingress.js +26 -26
- package/lib/ingress/capability-ingress.js.map +1 -1
- package/lib/init/activate-ai-database-storage.d.ts +5 -3
- package/lib/init/activate-ai-database-storage.d.ts.map +1 -1
- package/lib/init/activate-ai-database-storage.js +23 -32
- package/lib/init/activate-ai-database-storage.js.map +1 -1
- package/lib/init/configure-zhin-agent.d.ts +1 -1
- package/lib/init/configure-zhin-agent.d.ts.map +1 -1
- package/lib/init/configure-zhin-agent.js +3 -5
- package/lib/init/configure-zhin-agent.js.map +1 -1
- package/lib/init/define-ai-database-models.d.ts.map +1 -1
- package/lib/init/define-ai-database-models.js +21 -5
- package/lib/init/define-ai-database-models.js.map +1 -1
- package/lib/init/dispose-zhin-agent.d.ts +1 -3
- package/lib/init/dispose-zhin-agent.d.ts.map +1 -1
- package/lib/init/dispose-zhin-agent.js +0 -2
- package/lib/init/dispose-zhin-agent.js.map +1 -1
- package/lib/init/introspection-collectors.d.ts +1 -1
- package/lib/init/introspection-collectors.d.ts.map +1 -1
- package/lib/init/introspection-collectors.js +13 -14
- package/lib/init/introspection-collectors.js.map +1 -1
- package/lib/internal/agent-host.d.ts +5 -8
- package/lib/internal/agent-host.d.ts.map +1 -1
- package/lib/internal/host-types.d.ts +4 -0
- package/lib/internal/host-types.d.ts.map +1 -1
- package/lib/journal/persistent-turn-journal.d.ts +5 -1
- package/lib/journal/persistent-turn-journal.d.ts.map +1 -1
- package/lib/journal/persistent-turn-journal.js +11 -1
- package/lib/journal/persistent-turn-journal.js.map +1 -1
- package/lib/mcp-client/bridge.d.ts +1 -1
- package/lib/mcp-client/connection.d.ts +1 -1
- package/lib/mcp-client/index.d.ts +1 -1
- package/lib/media/media-normalize.d.ts +9 -5
- package/lib/media/media-normalize.d.ts.map +1 -1
- package/lib/media/media-normalize.js +125 -69
- package/lib/media/media-normalize.js.map +1 -1
- package/lib/media/media-publisher.d.ts.map +1 -1
- package/lib/media/media-publisher.js +48 -3
- package/lib/media/media-publisher.js.map +1 -1
- package/lib/media/vision-capability.js +1 -1
- package/lib/media/vision-capability.js.map +1 -1
- package/lib/memory/index.d.ts +1 -1
- package/lib/memory/index.d.ts.map +1 -1
- package/lib/plugin-ai-hook-bus.d.ts +1 -1
- package/lib/plugin-runtime/agent-host-port.d.ts +66 -4
- package/lib/plugin-runtime/agent-host-port.d.ts.map +1 -1
- package/lib/plugin-runtime/agent-host-port.js.map +1 -1
- package/lib/plugin-runtime/agent-runtime.d.ts +3 -0
- package/lib/plugin-runtime/agent-runtime.d.ts.map +1 -1
- package/lib/plugin-runtime/agent-runtime.js +73 -3
- package/lib/plugin-runtime/agent-runtime.js.map +1 -1
- package/lib/plugin-runtime/agent-trace-runtime.d.ts +37 -0
- package/lib/plugin-runtime/agent-trace-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/agent-trace-runtime.js +150 -0
- package/lib/plugin-runtime/agent-trace-runtime.js.map +1 -0
- package/lib/plugin-runtime/capability-tools.js +2 -2
- package/lib/plugin-runtime/capability-tools.js.map +1 -1
- package/lib/plugin-runtime/database-overlay-pack-promotion-repository.d.ts +70 -0
- package/lib/plugin-runtime/database-overlay-pack-promotion-repository.d.ts.map +1 -0
- package/lib/plugin-runtime/database-overlay-pack-promotion-repository.js +203 -0
- package/lib/plugin-runtime/database-overlay-pack-promotion-repository.js.map +1 -0
- package/lib/plugin-runtime/deferred-capability-plan.d.ts +26 -0
- package/lib/plugin-runtime/deferred-capability-plan.d.ts.map +1 -1
- package/lib/plugin-runtime/deferred-capability-plan.js +98 -4
- package/lib/plugin-runtime/deferred-capability-plan.js.map +1 -1
- package/lib/plugin-runtime/full-agent-turn-engine.js +48 -5
- package/lib/plugin-runtime/full-agent-turn-engine.js.map +1 -1
- package/lib/plugin-runtime/host-mcp-projection.d.ts +1 -1
- package/lib/plugin-runtime/index.d.ts +66 -0
- package/lib/plugin-runtime/index.d.ts.map +1 -1
- package/lib/plugin-runtime/index.js +65 -0
- package/lib/plugin-runtime/index.js.map +1 -1
- package/lib/plugin-runtime/native-interaction-tools.js +1 -1
- package/lib/plugin-runtime/native-interaction-tools.js.map +1 -1
- package/lib/plugin-runtime/native-semantic-memory-tools.d.ts +17 -0
- package/lib/plugin-runtime/native-semantic-memory-tools.d.ts.map +1 -0
- package/lib/plugin-runtime/native-semantic-memory-tools.js +169 -0
- package/lib/plugin-runtime/native-semantic-memory-tools.js.map +1 -0
- package/lib/plugin-runtime/turn-intent-resolver.d.ts +20 -0
- package/lib/plugin-runtime/turn-intent-resolver.d.ts.map +1 -0
- package/lib/plugin-runtime/turn-intent-resolver.js +8 -0
- package/lib/plugin-runtime/turn-intent-resolver.js.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-authority.d.ts +5 -0
- package/lib/plugin-runtime/workroom-acceptance-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-authority.js +14 -0
- package/lib/plugin-runtime/workroom-acceptance-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-fact-providers.d.ts +233 -0
- package/lib/plugin-runtime/workroom-acceptance-fact-providers.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-fact-providers.js +517 -0
- package/lib/plugin-runtime/workroom-acceptance-fact-providers.js.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-internal-providers.d.ts +139 -0
- package/lib/plugin-runtime/workroom-acceptance-internal-providers.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-internal-providers.js +430 -0
- package/lib/plugin-runtime/workroom-acceptance-internal-providers.js.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-policy.d.ts +4 -0
- package/lib/plugin-runtime/workroom-acceptance-policy.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-policy.js +20 -0
- package/lib/plugin-runtime/workroom-acceptance-policy.js.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-production-composition.d.ts +175 -0
- package/lib/plugin-runtime/workroom-acceptance-production-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-production-composition.js +793 -0
- package/lib/plugin-runtime/workroom-acceptance-production-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-provider-composition.d.ts +186 -0
- package/lib/plugin-runtime/workroom-acceptance-provider-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-acceptance-provider-composition.js +553 -0
- package/lib/plugin-runtime/workroom-acceptance-provider-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-accepted-source-runtime.d.ts +75 -0
- package/lib/plugin-runtime/workroom-accepted-source-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-accepted-source-runtime.js +267 -0
- package/lib/plugin-runtime/workroom-accepted-source-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-assignment-authority-grant-runtime.d.ts +42 -0
- package/lib/plugin-runtime/workroom-assignment-authority-grant-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-assignment-authority-grant-runtime.js +90 -0
- package/lib/plugin-runtime/workroom-assignment-authority-grant-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-assignment-authority-provider.d.ts +159 -0
- package/lib/plugin-runtime/workroom-assignment-authority-provider.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-assignment-authority-provider.js +595 -0
- package/lib/plugin-runtime/workroom-assignment-authority-provider.js.map +1 -0
- package/lib/plugin-runtime/workroom-assignment-knowledge-composition.d.ts +58 -0
- package/lib/plugin-runtime/workroom-assignment-knowledge-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-assignment-knowledge-composition.js +218 -0
- package/lib/plugin-runtime/workroom-assignment-knowledge-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-authority-writer.d.ts +47 -0
- package/lib/plugin-runtime/workroom-data-governance-authority-writer.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-authority-writer.js +115 -0
- package/lib/plugin-runtime/workroom-data-governance-authority-writer.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-composition.d.ts +28 -0
- package/lib/plugin-runtime/workroom-data-governance-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-composition.js +41 -0
- package/lib/plugin-runtime/workroom-data-governance-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-root-provider.d.ts +51 -0
- package/lib/plugin-runtime/workroom-data-governance-root-provider.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-root-provider.js +66 -0
- package/lib/plugin-runtime/workroom-data-governance-root-provider.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-runtime.d.ts +134 -0
- package/lib/plugin-runtime/workroom-data-governance-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-runtime.js +1253 -0
- package/lib/plugin-runtime/workroom-data-governance-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-storage.d.ts +66 -0
- package/lib/plugin-runtime/workroom-data-governance-storage.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-governance-storage.js +160 -0
- package/lib/plugin-runtime/workroom-data-governance-storage.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-composition.d.ts +37 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-composition.js +131 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-console.d.ts +238 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-console.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-console.js +495 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-console.js.map +1 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-human-ingress.d.ts +15 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-human-ingress.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-human-ingress.js +119 -0
- package/lib/plugin-runtime/workroom-data-lifecycle-human-ingress.js.map +1 -0
- package/lib/plugin-runtime/workroom-dynamic-planning-provider.d.ts +142 -0
- package/lib/plugin-runtime/workroom-dynamic-planning-provider.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-dynamic-planning-provider.js +301 -0
- package/lib/plugin-runtime/workroom-dynamic-planning-provider.js.map +1 -0
- package/lib/plugin-runtime/workroom-dynamic-planning.d.ts +4 -0
- package/lib/plugin-runtime/workroom-dynamic-planning.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-dynamic-planning.js +13 -0
- package/lib/plugin-runtime/workroom-dynamic-planning.js.map +1 -0
- package/lib/plugin-runtime/workroom-effect-composition.d.ts +37 -0
- package/lib/plugin-runtime/workroom-effect-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-effect-composition.js +69 -0
- package/lib/plugin-runtime/workroom-effect-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-effect-production.d.ts +133 -0
- package/lib/plugin-runtime/workroom-effect-production.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-effect-production.js +272 -0
- package/lib/plugin-runtime/workroom-effect-production.js.map +1 -0
- package/lib/plugin-runtime/workroom-effect-runtime.d.ts +72 -0
- package/lib/plugin-runtime/workroom-effect-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-effect-runtime.js +179 -0
- package/lib/plugin-runtime/workroom-effect-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-composition.d.ts +27 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-composition.js +40 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-reasons.d.ts +10 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-reasons.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-reasons.js +20 -0
- package/lib/plugin-runtime/workroom-governed-dispatch-reasons.js.map +1 -0
- package/lib/plugin-runtime/workroom-journal-payload-composition.d.ts +16 -0
- package/lib/plugin-runtime/workroom-journal-payload-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-journal-payload-composition.js +69 -0
- package/lib/plugin-runtime/workroom-journal-payload-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-local-agent-core-adapter.d.ts +17 -0
- package/lib/plugin-runtime/workroom-local-agent-core-adapter.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-local-agent-core-adapter.js +101 -0
- package/lib/plugin-runtime/workroom-local-agent-core-adapter.js.map +1 -0
- package/lib/plugin-runtime/workroom-local-agent-loop.d.ts +90 -0
- package/lib/plugin-runtime/workroom-local-agent-loop.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-local-agent-loop.js +303 -0
- package/lib/plugin-runtime/workroom-local-agent-loop.js.map +1 -0
- package/lib/plugin-runtime/workroom-local-assignment-authority.d.ts +5 -0
- package/lib/plugin-runtime/workroom-local-assignment-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-local-assignment-authority.js +16 -0
- package/lib/plugin-runtime/workroom-local-assignment-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-local-assignment-runtime.d.ts +33 -0
- package/lib/plugin-runtime/workroom-local-assignment-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-local-assignment-runtime.js +189 -0
- package/lib/plugin-runtime/workroom-local-assignment-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-local-assignment-supply.d.ts +39 -0
- package/lib/plugin-runtime/workroom-local-assignment-supply.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-local-assignment-supply.js +107 -0
- package/lib/plugin-runtime/workroom-local-assignment-supply.js.map +1 -0
- package/lib/plugin-runtime/workroom-overlay-pack-promotion.d.ts +145 -0
- package/lib/plugin-runtime/workroom-overlay-pack-promotion.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-overlay-pack-promotion.js +516 -0
- package/lib/plugin-runtime/workroom-overlay-pack-promotion.js.map +1 -0
- package/lib/plugin-runtime/workroom-payload-processor-recall.d.ts +91 -0
- package/lib/plugin-runtime/workroom-payload-processor-recall.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-payload-processor-recall.js +189 -0
- package/lib/plugin-runtime/workroom-payload-processor-recall.js.map +1 -0
- package/lib/plugin-runtime/workroom-plan-gate-authority.d.ts +7 -0
- package/lib/plugin-runtime/workroom-plan-gate-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-plan-gate-authority.js +40 -0
- package/lib/plugin-runtime/workroom-plan-gate-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-capacity.d.ts +132 -0
- package/lib/plugin-runtime/workroom-portfolio-capacity.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-capacity.js +189 -0
- package/lib/plugin-runtime/workroom-portfolio-capacity.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-checkpoint-ack.d.ts +38 -0
- package/lib/plugin-runtime/workroom-portfolio-checkpoint-ack.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-checkpoint-ack.js +103 -0
- package/lib/plugin-runtime/workroom-portfolio-checkpoint-ack.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-control-composition.d.ts +30 -0
- package/lib/plugin-runtime/workroom-portfolio-control-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-control-composition.js +102 -0
- package/lib/plugin-runtime/workroom-portfolio-control-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-control-runtime.d.ts +41 -0
- package/lib/plugin-runtime/workroom-portfolio-control-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-control-runtime.js +208 -0
- package/lib/plugin-runtime/workroom-portfolio-control-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-grant-assignment.d.ts +141 -0
- package/lib/plugin-runtime/workroom-portfolio-grant-assignment.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-grant-assignment.js +331 -0
- package/lib/plugin-runtime/workroom-portfolio-grant-assignment.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-kernel-authority.d.ts +23 -0
- package/lib/plugin-runtime/workroom-portfolio-kernel-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-kernel-authority.js +82 -0
- package/lib/plugin-runtime/workroom-portfolio-kernel-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-sponsor.d.ts +96 -0
- package/lib/plugin-runtime/workroom-portfolio-sponsor.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-portfolio-sponsor.js +313 -0
- package/lib/plugin-runtime/workroom-portfolio-sponsor.js.map +1 -0
- package/lib/plugin-runtime/workroom-preemption-runtime.d.ts +57 -0
- package/lib/plugin-runtime/workroom-preemption-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-preemption-runtime.js +163 -0
- package/lib/plugin-runtime/workroom-preemption-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-priority-authority.d.ts +11 -0
- package/lib/plugin-runtime/workroom-priority-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-priority-authority.js +72 -0
- package/lib/plugin-runtime/workroom-priority-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-profile-authority-composition.d.ts +61 -0
- package/lib/plugin-runtime/workroom-profile-authority-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-profile-authority-composition.js +231 -0
- package/lib/plugin-runtime/workroom-profile-authority-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-profile-authority-runtime.d.ts +228 -0
- package/lib/plugin-runtime/workroom-profile-authority-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-profile-authority-runtime.js +1132 -0
- package/lib/plugin-runtime/workroom-profile-authority-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-projection-outbound.d.ts +10 -0
- package/lib/plugin-runtime/workroom-projection-outbound.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-projection-outbound.js +35 -0
- package/lib/plugin-runtime/workroom-projection-outbound.js.map +1 -0
- package/lib/plugin-runtime/workroom-projection-runtime.d.ts +87 -0
- package/lib/plugin-runtime/workroom-projection-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-projection-runtime.js +421 -0
- package/lib/plugin-runtime/workroom-projection-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-remote-assignment-authority.d.ts +9 -0
- package/lib/plugin-runtime/workroom-remote-assignment-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-remote-assignment-authority.js +20 -0
- package/lib/plugin-runtime/workroom-remote-assignment-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-remote-callback-runtime.d.ts +38 -0
- package/lib/plugin-runtime/workroom-remote-callback-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-remote-callback-runtime.js +80 -0
- package/lib/plugin-runtime/workroom-remote-callback-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-remote-executor.d.ts +20 -0
- package/lib/plugin-runtime/workroom-remote-executor.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-remote-executor.js +42 -0
- package/lib/plugin-runtime/workroom-remote-executor.js.map +1 -0
- package/lib/plugin-runtime/workroom-reviewer-authority-runtime.d.ts +72 -0
- package/lib/plugin-runtime/workroom-reviewer-authority-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-reviewer-authority-runtime.js +142 -0
- package/lib/plugin-runtime/workroom-reviewer-authority-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-risk-acceptance-runtime.d.ts +112 -0
- package/lib/plugin-runtime/workroom-risk-acceptance-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-risk-acceptance-runtime.js +376 -0
- package/lib/plugin-runtime/workroom-risk-acceptance-runtime.js.map +1 -0
- package/lib/plugin-runtime/workroom-run-profile-pin-authority.d.ts +42 -0
- package/lib/plugin-runtime/workroom-run-profile-pin-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-run-profile-pin-authority.js +125 -0
- package/lib/plugin-runtime/workroom-run-profile-pin-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-composition.d.ts +25 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-composition.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-composition.js +79 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-composition.js.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-contract.d.ts +16 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-contract.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-contract.js +49 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-contract.js.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-request-authority.d.ts +63 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-request-authority.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-request-authority.js +233 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-request-authority.js.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-supply.d.ts +37 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-supply.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-supply.js +122 -0
- package/lib/plugin-runtime/workroom-scheduler-portfolio-supply.js.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-route-registry.d.ts +27 -0
- package/lib/plugin-runtime/workroom-scheduler-route-registry.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-route-registry.js +136 -0
- package/lib/plugin-runtime/workroom-scheduler-route-registry.js.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-runtime.d.ts +84 -0
- package/lib/plugin-runtime/workroom-scheduler-runtime.d.ts.map +1 -0
- package/lib/plugin-runtime/workroom-scheduler-runtime.js +231 -0
- package/lib/plugin-runtime/workroom-scheduler-runtime.js.map +1 -0
- package/lib/portfolio/capacity-control-outbox.d.ts +174 -0
- package/lib/portfolio/capacity-control-outbox.d.ts.map +1 -0
- package/lib/portfolio/capacity-control-outbox.js +338 -0
- package/lib/portfolio/capacity-control-outbox.js.map +1 -0
- package/lib/portfolio/database-capacity-control-outbox.d.ts +62 -0
- package/lib/portfolio/database-capacity-control-outbox.d.ts.map +1 -0
- package/lib/portfolio/database-capacity-control-outbox.js +166 -0
- package/lib/portfolio/database-capacity-control-outbox.js.map +1 -0
- package/lib/portfolio/file-capacity-control-outbox.d.ts +10 -0
- package/lib/portfolio/file-capacity-control-outbox.d.ts.map +1 -0
- package/lib/portfolio/file-capacity-control-outbox.js +113 -0
- package/lib/portfolio/file-capacity-control-outbox.js.map +1 -0
- package/lib/portfolio/file-portfolio-journal.d.ts +11 -0
- package/lib/portfolio/file-portfolio-journal.d.ts.map +1 -0
- package/lib/portfolio/file-portfolio-journal.js +196 -0
- package/lib/portfolio/file-portfolio-journal.js.map +1 -0
- package/lib/portfolio/portfolio-admission.d.ts +95 -0
- package/lib/portfolio/portfolio-admission.d.ts.map +1 -0
- package/lib/portfolio/portfolio-admission.js +1080 -0
- package/lib/portfolio/portfolio-admission.js.map +1 -0
- package/lib/portfolio/portfolio-journal.d.ts +359 -0
- package/lib/portfolio/portfolio-journal.d.ts.map +1 -0
- package/lib/portfolio/portfolio-journal.js +844 -0
- package/lib/portfolio/portfolio-journal.js.map +1 -0
- package/lib/portfolio/resource-bundle.d.ts +136 -0
- package/lib/portfolio/resource-bundle.d.ts.map +1 -0
- package/lib/portfolio/resource-bundle.js +387 -0
- package/lib/portfolio/resource-bundle.js.map +1 -0
- package/lib/portfolio/sponsor-projection.d.ts +78 -0
- package/lib/portfolio/sponsor-projection.d.ts.map +1 -0
- package/lib/portfolio/sponsor-projection.js +135 -0
- package/lib/portfolio/sponsor-projection.js.map +1 -0
- package/lib/prompt/assembly.d.ts.map +1 -1
- package/lib/prompt/assembly.js +1 -3
- package/lib/prompt/assembly.js.map +1 -1
- package/lib/prompt/prompt-builder.d.ts +1 -1
- package/lib/prompt/prompt-builder.d.ts.map +1 -1
- package/lib/prompt/system-prompt.d.ts +1 -1
- package/lib/prompt/system-prompt.js +2 -2
- package/lib/prompt/system-prompt.js.map +1 -1
- package/lib/reserved-tools.d.ts.map +1 -1
- package/lib/reserved-tools.js +0 -1
- package/lib/reserved-tools.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/hook-registry.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/hook-registry.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/index.d.ts +4 -11
- package/lib/{orchestrator → resource-hub}/index.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/index.js +4 -8
- package/lib/{orchestrator → resource-hub}/index.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/mcp-lifecycle.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/mcp-lifecycle.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/mcp-registry.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/mcp-registry.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/resolve-subagent-tools.d.ts +3 -3
- package/lib/resource-hub/resolve-subagent-tools.d.ts.map +1 -0
- package/lib/{orchestrator → resource-hub}/resolve-subagent-tools.js +18 -13
- package/lib/resource-hub/resolve-subagent-tools.js.map +1 -0
- package/lib/{orchestrator → resource-hub}/resource-registry.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/resource-registry.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/role-configs.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/role-configs.js +0 -2
- package/lib/{orchestrator → resource-hub}/role-configs.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/skill-registry.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/skill-registry.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/subagent-registry.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/subagent-registry.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/tool-registry.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/tool-registry.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/tool-selection.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/tool-selection.js.map +1 -1
- package/lib/{orchestrator → resource-hub}/types.d.ts +1 -1
- package/lib/{orchestrator → resource-hub}/types.d.ts.map +1 -1
- package/lib/{orchestrator → resource-hub}/types.js.map +1 -1
- package/lib/routing/workroom-bot-identity.d.ts +22 -0
- package/lib/routing/workroom-bot-identity.d.ts.map +1 -0
- package/lib/routing/workroom-bot-identity.js +46 -0
- package/lib/routing/workroom-bot-identity.js.map +1 -0
- package/lib/schedule-domain/budget-guard.d.ts +1 -1
- package/lib/schedule-domain/budget-guard.d.ts.map +1 -1
- package/lib/schedule-domain/budget-guard.js +9 -1
- package/lib/schedule-domain/budget-guard.js.map +1 -1
- package/lib/schedule-domain/execution-domain.d.ts +1 -0
- package/lib/schedule-domain/execution-domain.d.ts.map +1 -1
- package/lib/schedule-domain/execution-domain.js +3 -1
- package/lib/schedule-domain/execution-domain.js.map +1 -1
- package/lib/schedule-domain/schedule-execution-queue.d.ts +24 -0
- package/lib/schedule-domain/schedule-execution-queue.d.ts.map +1 -0
- package/lib/schedule-domain/schedule-execution-queue.js +123 -0
- package/lib/schedule-domain/schedule-execution-queue.js.map +1 -0
- package/lib/seam/seam-integration.d.ts +1 -1
- package/lib/seam/seam-integration.js +1 -1
- package/lib/seam/skill-service.d.ts +1 -1
- package/lib/security/exec-policy.d.ts +11 -1
- package/lib/security/exec-policy.d.ts.map +1 -1
- package/lib/security/exec-policy.js +16 -4
- package/lib/security/exec-policy.js.map +1 -1
- package/lib/security/policy-facade.d.ts.map +1 -1
- package/lib/security/policy-facade.js +60 -5
- package/lib/security/policy-facade.js.map +1 -1
- package/lib/security/sandbox-docker.js +1 -1
- package/lib/security/sandbox-docker.js.map +1 -1
- package/lib/security/sandbox.d.ts +2 -0
- package/lib/security/sandbox.d.ts.map +1 -1
- package/lib/security/sandbox.js +16 -4
- package/lib/security/sandbox.js.map +1 -1
- package/lib/security/turn-file-authority.d.ts +1 -1
- package/lib/security/turn-file-authority.d.ts.map +1 -1
- package/lib/security/turn-file-authority.js +10 -3
- package/lib/security/turn-file-authority.js.map +1 -1
- package/lib/security/turn-sandbox-authority.d.ts +13 -0
- package/lib/security/turn-sandbox-authority.d.ts.map +1 -0
- package/lib/security/turn-sandbox-authority.js +42 -0
- package/lib/security/turn-sandbox-authority.js.map +1 -0
- package/lib/service.d.ts +2 -0
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +2 -1
- package/lib/service.js.map +1 -1
- package/lib/session/approval-port.d.ts +2 -0
- package/lib/session/approval-port.d.ts.map +1 -1
- package/lib/session/approval-port.js.map +1 -1
- package/lib/session/index.d.ts +2 -6
- package/lib/session/index.d.ts.map +1 -1
- package/lib/session/index.js +2 -4
- package/lib/session/index.js.map +1 -1
- package/lib/session/session-io.d.ts +2 -6
- package/lib/session/session-io.d.ts.map +1 -1
- package/lib/session/session-io.js +4 -20
- package/lib/session/session-io.js.map +1 -1
- package/lib/session/session-system.d.ts +0 -2
- package/lib/session/session-system.d.ts.map +1 -1
- package/lib/session/session-system.js +2 -13
- package/lib/session/session-system.js.map +1 -1
- package/lib/session/turn-ingress-session.d.ts +1 -5
- package/lib/session/turn-ingress-session.d.ts.map +1 -1
- package/lib/session/turn-ingress-session.js +27 -29
- package/lib/session/turn-ingress-session.js.map +1 -1
- package/lib/session-tree-runtime.d.ts +15 -0
- package/lib/session-tree-runtime.d.ts.map +1 -0
- package/lib/{session-tree-runtime-registry.js → session-tree-runtime.js} +5 -15
- package/lib/session-tree-runtime.js.map +1 -0
- package/lib/skill/index.d.ts +2 -2
- package/lib/skill/index.d.ts.map +1 -1
- package/lib/skill/index.js +1 -1
- package/lib/skill/skill-registry-as-service.d.ts +1 -1
- package/lib/skill/skill-system.d.ts +4 -4
- package/lib/skill/skill-system.d.ts.map +1 -1
- package/lib/skill/skill-system.js +2 -2
- package/lib/skill/skill-system.js.map +1 -1
- package/lib/subagent/subagent-runtime.d.ts +2 -7
- package/lib/subagent/subagent-runtime.d.ts.map +1 -1
- package/lib/subagent/subagent-runtime.js +4 -43
- package/lib/subagent/subagent-runtime.js.map +1 -1
- package/lib/subagent/subagent-system-init.d.ts.map +1 -1
- package/lib/subagent/subagent-system-init.js +0 -2
- package/lib/subagent/subagent-system-init.js.map +1 -1
- package/lib/subagent-ai-events.d.ts +1 -1
- package/lib/subagent-ai-events.js +1 -1
- package/lib/subagent-preset.d.ts +1 -1
- package/lib/subagent-preset.d.ts.map +1 -1
- package/lib/subagent-prompt.d.ts +0 -2
- package/lib/subagent-prompt.d.ts.map +1 -1
- package/lib/subagent-prompt.js +3 -3
- package/lib/subagent-prompt.js.map +1 -1
- package/lib/task-executor.d.ts +1 -0
- package/lib/task-executor.d.ts.map +1 -1
- package/lib/task-executor.js +4 -1
- package/lib/task-executor.js.map +1 -1
- package/lib/tool/classic-tool-execution-authority.js +2 -2
- package/lib/tool/classic-tool-execution-authority.js.map +1 -1
- package/lib/tool/context-tools.d.ts +1 -4
- package/lib/tool/context-tools.d.ts.map +1 -1
- package/lib/tool/context-tools.js +0 -50
- package/lib/tool/context-tools.js.map +1 -1
- package/lib/tool/contracts.d.ts +1 -1
- package/lib/tool/conversation-reference-tool.d.ts +5 -0
- package/lib/tool/conversation-reference-tool.d.ts.map +1 -0
- package/lib/tool/conversation-reference-tool.js +40 -0
- package/lib/tool/conversation-reference-tool.js.map +1 -0
- package/lib/tool/index.d.ts +1 -0
- package/lib/tool/index.d.ts.map +1 -1
- package/lib/tool/index.js +1 -0
- package/lib/tool/index.js.map +1 -1
- package/lib/tool/prepare-turn-tools.d.ts.map +1 -1
- package/lib/tool/prepare-turn-tools.js +7 -22
- package/lib/tool/prepare-turn-tools.js.map +1 -1
- package/lib/tool/runtime.d.ts +3 -4
- package/lib/tool/runtime.d.ts.map +1 -1
- package/lib/tool/runtime.js +0 -1
- package/lib/tool/runtime.js.map +1 -1
- package/lib/tool/sources.d.ts +3 -4
- package/lib/tool/sources.d.ts.map +1 -1
- package/lib/tool/sources.js +2 -6
- package/lib/tool/sources.js.map +1 -1
- package/lib/tool/tool-approval-once-store.d.ts +1 -1
- package/lib/tool/tool-approval-once-store.js +1 -1
- package/lib/tool/tool-system.d.ts.map +1 -1
- package/lib/tool/tool-system.js.map +1 -1
- package/lib/tool/turn-tool-runtime.d.ts +2 -1
- package/lib/tool/turn-tool-runtime.d.ts.map +1 -1
- package/lib/tool/turn-tool-runtime.js +76 -21
- package/lib/tool/turn-tool-runtime.js.map +1 -1
- package/lib/tool-bridge.d.ts +2 -2
- package/lib/tool-bridge.js +1 -1
- package/lib/tool-catalog/deferred-turn-controller.d.ts +1 -1
- package/lib/tool-catalog/tool-catalog.d.ts +1 -1
- package/lib/turn/auto-continue.d.ts +1 -1
- package/lib/turn/deferred-delivery.d.ts +1 -1
- package/lib/turn/inbound-media.d.ts +12 -8
- package/lib/turn/inbound-media.d.ts.map +1 -1
- package/lib/turn/inbound-media.js +61 -42
- package/lib/turn/inbound-media.js.map +1 -1
- package/lib/turn/inbound-queue-config.d.ts +1 -1
- package/lib/turn/inbound-queue-runtime.d.ts +1 -1
- package/lib/turn/inbound-turn-queue.d.ts +1 -1
- package/lib/turn/index.d.ts +1 -1
- package/lib/turn/index.d.ts.map +1 -1
- package/lib/turn/index.js.map +1 -1
- package/lib/turn/persist-deferred-context.d.ts +1 -1
- package/lib/turn/persist-subagent-context.d.ts +1 -1
- package/lib/turn/process-stream.d.ts +1 -1
- package/lib/turn/prompt-api.d.ts +1 -1
- package/lib/turn/prompt-controller.d.ts +6 -0
- package/lib/turn/prompt-controller.d.ts.map +1 -1
- package/lib/turn/prompt-controller.js +58 -5
- package/lib/turn/prompt-controller.js.map +1 -1
- package/lib/turn/turn-ingress.d.ts +55 -5
- package/lib/turn/turn-ingress.d.ts.map +1 -1
- package/lib/turn/turn-ingress.js +18 -0
- package/lib/turn/turn-ingress.js.map +1 -1
- package/lib/turn/turn-pipeline.d.ts.map +1 -1
- package/lib/turn/turn-pipeline.js +5 -4
- package/lib/turn/turn-pipeline.js.map +1 -1
- package/lib/utils/keyed-mutex.d.ts +1 -1
- package/lib/utils/keyed-mutex.d.ts.map +1 -1
- package/lib/utils/keyed-mutex.js +32 -5
- package/lib/utils/keyed-mutex.js.map +1 -1
- package/lib/workroom/acceptance-control.d.ts +76 -0
- package/lib/workroom/acceptance-control.d.ts.map +1 -0
- package/lib/workroom/acceptance-control.js +335 -0
- package/lib/workroom/acceptance-control.js.map +1 -0
- package/lib/workroom/acceptance-policy.d.ts +152 -0
- package/lib/workroom/acceptance-policy.d.ts.map +1 -0
- package/lib/workroom/acceptance-policy.js +610 -0
- package/lib/workroom/acceptance-policy.js.map +1 -0
- package/lib/workroom/accepted-source-memory-application.d.ts +113 -0
- package/lib/workroom/accepted-source-memory-application.d.ts.map +1 -0
- package/lib/workroom/accepted-source-memory-application.js +327 -0
- package/lib/workroom/accepted-source-memory-application.js.map +1 -0
- package/lib/workroom/accepted-source-projector.d.ts +89 -0
- package/lib/workroom/accepted-source-projector.d.ts.map +1 -0
- package/lib/workroom/accepted-source-projector.js +281 -0
- package/lib/workroom/accepted-source-projector.js.map +1 -0
- package/lib/workroom/assignment-authority-grant-application.d.ts +125 -0
- package/lib/workroom/assignment-authority-grant-application.d.ts.map +1 -0
- package/lib/workroom/assignment-authority-grant-application.js +317 -0
- package/lib/workroom/assignment-authority-grant-application.js.map +1 -0
- package/lib/workroom/assignment-authority-grant-repository.d.ts +151 -0
- package/lib/workroom/assignment-authority-grant-repository.d.ts.map +1 -0
- package/lib/workroom/assignment-authority-grant-repository.js +387 -0
- package/lib/workroom/assignment-authority-grant-repository.js.map +1 -0
- package/lib/workroom/assignment-executor.d.ts +110 -0
- package/lib/workroom/assignment-executor.d.ts.map +1 -0
- package/lib/workroom/assignment-executor.js +371 -0
- package/lib/workroom/assignment-executor.js.map +1 -0
- package/lib/workroom/assignment-observation-ingress.d.ts +21 -0
- package/lib/workroom/assignment-observation-ingress.d.ts.map +1 -0
- package/lib/workroom/assignment-observation-ingress.js +24 -0
- package/lib/workroom/assignment-observation-ingress.js.map +1 -0
- package/lib/workroom/canonical-value.d.ts +7 -0
- package/lib/workroom/canonical-value.d.ts.map +1 -0
- package/lib/workroom/canonical-value.js +32 -0
- package/lib/workroom/canonical-value.js.map +1 -0
- package/lib/workroom/catalog-definition.d.ts +49 -0
- package/lib/workroom/catalog-definition.d.ts.map +1 -0
- package/lib/workroom/catalog-definition.js +2 -0
- package/lib/workroom/catalog-definition.js.map +1 -0
- package/lib/workroom/catalog.d.ts +80 -0
- package/lib/workroom/catalog.d.ts.map +1 -0
- package/lib/workroom/catalog.js +372 -0
- package/lib/workroom/catalog.js.map +1 -0
- package/lib/workroom/database-project-knowledge-journal.d.ts +62 -0
- package/lib/workroom/database-project-knowledge-journal.d.ts.map +1 -0
- package/lib/workroom/database-project-knowledge-journal.js +161 -0
- package/lib/workroom/database-project-knowledge-journal.js.map +1 -0
- package/lib/workroom/durable-file-store.d.ts +52 -0
- package/lib/workroom/durable-file-store.d.ts.map +1 -0
- package/lib/workroom/durable-file-store.js +117 -0
- package/lib/workroom/durable-file-store.js.map +1 -0
- package/lib/workroom/dynamic-workflow-planner.d.ts +86 -0
- package/lib/workroom/dynamic-workflow-planner.d.ts.map +1 -0
- package/lib/workroom/dynamic-workflow-planner.js +260 -0
- package/lib/workroom/dynamic-workflow-planner.js.map +1 -0
- package/lib/workroom/effect-blocker-repository.d.ts +35 -0
- package/lib/workroom/effect-blocker-repository.d.ts.map +1 -0
- package/lib/workroom/effect-blocker-repository.js +174 -0
- package/lib/workroom/effect-blocker-repository.js.map +1 -0
- package/lib/workroom/effect-ledger.d.ts +191 -0
- package/lib/workroom/effect-ledger.d.ts.map +1 -0
- package/lib/workroom/effect-ledger.js +443 -0
- package/lib/workroom/effect-ledger.js.map +1 -0
- package/lib/workroom/file-accepted-source-memory-repository.d.ts +15 -0
- package/lib/workroom/file-accepted-source-memory-repository.d.ts.map +1 -0
- package/lib/workroom/file-accepted-source-memory-repository.js +133 -0
- package/lib/workroom/file-accepted-source-memory-repository.js.map +1 -0
- package/lib/workroom/file-effect-ledger.d.ts +10 -0
- package/lib/workroom/file-effect-ledger.d.ts.map +1 -0
- package/lib/workroom/file-effect-ledger.js +118 -0
- package/lib/workroom/file-effect-ledger.js.map +1 -0
- package/lib/workroom/file-human-ingress-application.d.ts +10 -0
- package/lib/workroom/file-human-ingress-application.d.ts.map +1 -0
- package/lib/workroom/file-human-ingress-application.js +177 -0
- package/lib/workroom/file-human-ingress-application.js.map +1 -0
- package/lib/workroom/file-human-ingress.d.ts +24 -0
- package/lib/workroom/file-human-ingress.d.ts.map +1 -0
- package/lib/workroom/file-human-ingress.js +234 -0
- package/lib/workroom/file-human-ingress.js.map +1 -0
- package/lib/workroom/file-interaction-space-binding-repository.d.ts +24 -0
- package/lib/workroom/file-interaction-space-binding-repository.d.ts.map +1 -0
- package/lib/workroom/file-interaction-space-binding-repository.js +293 -0
- package/lib/workroom/file-interaction-space-binding-repository.js.map +1 -0
- package/lib/workroom/file-profile-journal.d.ts +32 -0
- package/lib/workroom/file-profile-journal.d.ts.map +1 -0
- package/lib/workroom/file-profile-journal.js +308 -0
- package/lib/workroom/file-profile-journal.js.map +1 -0
- package/lib/workroom/git-workspace-gateway.d.ts +149 -0
- package/lib/workroom/git-workspace-gateway.d.ts.map +1 -0
- package/lib/workroom/git-workspace-gateway.js +248 -0
- package/lib/workroom/git-workspace-gateway.js.map +1 -0
- package/lib/workroom/human-ingress-application.d.ts +126 -0
- package/lib/workroom/human-ingress-application.d.ts.map +1 -0
- package/lib/workroom/human-ingress-application.js +414 -0
- package/lib/workroom/human-ingress-application.js.map +1 -0
- package/lib/workroom/human-ingress-orchestrator.d.ts +99 -0
- package/lib/workroom/human-ingress-orchestrator.d.ts.map +1 -0
- package/lib/workroom/human-ingress-orchestrator.js +234 -0
- package/lib/workroom/human-ingress-orchestrator.js.map +1 -0
- package/lib/workroom/human-ingress-source-reader.d.ts +29 -0
- package/lib/workroom/human-ingress-source-reader.d.ts.map +1 -0
- package/lib/workroom/human-ingress-source-reader.js +119 -0
- package/lib/workroom/human-ingress-source-reader.js.map +1 -0
- package/lib/workroom/human-ingress.d.ts +182 -0
- package/lib/workroom/human-ingress.d.ts.map +1 -0
- package/lib/workroom/human-ingress.js +526 -0
- package/lib/workroom/human-ingress.js.map +1 -0
- package/lib/workroom/interaction-space-binding-service.d.ts +57 -0
- package/lib/workroom/interaction-space-binding-service.d.ts.map +1 -0
- package/lib/workroom/interaction-space-binding-service.js +197 -0
- package/lib/workroom/interaction-space-binding-service.js.map +1 -0
- package/lib/workroom/interaction-space-router.d.ts +75 -0
- package/lib/workroom/interaction-space-router.d.ts.map +1 -0
- package/lib/workroom/interaction-space-router.js +243 -0
- package/lib/workroom/interaction-space-router.js.map +1 -0
- package/lib/workroom/journal-model.d.ts +40 -0
- package/lib/workroom/journal-model.d.ts.map +1 -0
- package/lib/workroom/journal-model.js +12 -0
- package/lib/workroom/journal-model.js.map +1 -0
- package/lib/workroom/journal.d.ts +214 -0
- package/lib/workroom/journal.d.ts.map +1 -0
- package/lib/workroom/journal.js +1935 -0
- package/lib/workroom/journal.js.map +1 -0
- package/lib/workroom/kernel-contracts.d.ts +167 -0
- package/lib/workroom/kernel-contracts.d.ts.map +1 -0
- package/lib/workroom/kernel-contracts.js +2 -0
- package/lib/workroom/kernel-contracts.js.map +1 -0
- package/lib/workroom/kernel-state.d.ts +5 -0
- package/lib/workroom/kernel-state.d.ts.map +1 -0
- package/lib/workroom/kernel-state.js +819 -0
- package/lib/workroom/kernel-state.js.map +1 -0
- package/lib/workroom/legacy-embedded-payload-migration.d.ts +89 -0
- package/lib/workroom/legacy-embedded-payload-migration.d.ts.map +1 -0
- package/lib/workroom/legacy-embedded-payload-migration.js +312 -0
- package/lib/workroom/legacy-embedded-payload-migration.js.map +1 -0
- package/lib/workroom/legacy-run-offline-migration.d.ts +84 -0
- package/lib/workroom/legacy-run-offline-migration.d.ts.map +1 -0
- package/lib/workroom/legacy-run-offline-migration.js +470 -0
- package/lib/workroom/legacy-run-offline-migration.js.map +1 -0
- package/lib/workroom/local-assignment-executor.d.ts +59 -0
- package/lib/workroom/local-assignment-executor.d.ts.map +1 -0
- package/lib/workroom/local-assignment-executor.js +197 -0
- package/lib/workroom/local-assignment-executor.js.map +1 -0
- package/lib/workroom/local-assignment-issuance.d.ts +68 -0
- package/lib/workroom/local-assignment-issuance.d.ts.map +1 -0
- package/lib/workroom/local-assignment-issuance.js +128 -0
- package/lib/workroom/local-assignment-issuance.js.map +1 -0
- package/lib/workroom/plan-approval-control.d.ts +52 -0
- package/lib/workroom/plan-approval-control.d.ts.map +1 -0
- package/lib/workroom/plan-approval-control.js +9 -0
- package/lib/workroom/plan-approval-control.js.map +1 -0
- package/lib/workroom/plan-revision.d.ts +44 -0
- package/lib/workroom/plan-revision.d.ts.map +1 -0
- package/lib/workroom/plan-revision.js +133 -0
- package/lib/workroom/plan-revision.js.map +1 -0
- package/lib/workroom/profile-compiler.d.ts +130 -0
- package/lib/workroom/profile-compiler.d.ts.map +1 -0
- package/lib/workroom/profile-compiler.js +357 -0
- package/lib/workroom/profile-compiler.js.map +1 -0
- package/lib/workroom/profile-registry.d.ts +191 -0
- package/lib/workroom/profile-registry.d.ts.map +1 -0
- package/lib/workroom/profile-registry.js +698 -0
- package/lib/workroom/profile-registry.js.map +1 -0
- package/lib/workroom/project-knowledge-registry.d.ts +136 -0
- package/lib/workroom/project-knowledge-registry.d.ts.map +1 -0
- package/lib/workroom/project-knowledge-registry.js +429 -0
- package/lib/workroom/project-knowledge-registry.js.map +1 -0
- package/lib/workroom/projection-outbox.d.ts +254 -0
- package/lib/workroom/projection-outbox.d.ts.map +1 -0
- package/lib/workroom/projection-outbox.js +1312 -0
- package/lib/workroom/projection-outbox.js.map +1 -0
- package/lib/workroom/remote-assignment-dispatch-command.d.ts +31 -0
- package/lib/workroom/remote-assignment-dispatch-command.d.ts.map +1 -0
- package/lib/workroom/remote-assignment-dispatch-command.js +56 -0
- package/lib/workroom/remote-assignment-dispatch-command.js.map +1 -0
- package/lib/workroom/remote-assignment-issuance.d.ts +88 -0
- package/lib/workroom/remote-assignment-issuance.d.ts.map +1 -0
- package/lib/workroom/remote-assignment-issuance.js +201 -0
- package/lib/workroom/remote-assignment-issuance.js.map +1 -0
- package/lib/workroom/remote-callback-application.d.ts +115 -0
- package/lib/workroom/remote-callback-application.d.ts.map +1 -0
- package/lib/workroom/remote-callback-application.js +570 -0
- package/lib/workroom/remote-callback-application.js.map +1 -0
- package/lib/workroom/remote-callback-gateway.d.ts +60 -0
- package/lib/workroom/remote-callback-gateway.d.ts.map +1 -0
- package/lib/workroom/remote-callback-gateway.js +173 -0
- package/lib/workroom/remote-callback-gateway.js.map +1 -0
- package/lib/workroom/remote-callback-inbox.d.ts +278 -0
- package/lib/workroom/remote-callback-inbox.d.ts.map +1 -0
- package/lib/workroom/remote-callback-inbox.js +1088 -0
- package/lib/workroom/remote-callback-inbox.js.map +1 -0
- package/lib/workroom/remote-callback-reconciliation-worker.d.ts +60 -0
- package/lib/workroom/remote-callback-reconciliation-worker.d.ts.map +1 -0
- package/lib/workroom/remote-callback-reconciliation-worker.js +197 -0
- package/lib/workroom/remote-callback-reconciliation-worker.js.map +1 -0
- package/lib/workroom/remote-dispatch-admission.d.ts +45 -0
- package/lib/workroom/remote-dispatch-admission.d.ts.map +1 -0
- package/lib/workroom/remote-dispatch-admission.js +187 -0
- package/lib/workroom/remote-dispatch-admission.js.map +1 -0
- package/lib/workroom/remote-dispatch-outbox.d.ts +203 -0
- package/lib/workroom/remote-dispatch-outbox.d.ts.map +1 -0
- package/lib/workroom/remote-dispatch-outbox.js +765 -0
- package/lib/workroom/remote-dispatch-outbox.js.map +1 -0
- package/lib/workroom/remote-dispatch-scheduler.d.ts +36 -0
- package/lib/workroom/remote-dispatch-scheduler.d.ts.map +1 -0
- package/lib/workroom/remote-dispatch-scheduler.js +133 -0
- package/lib/workroom/remote-dispatch-scheduler.js.map +1 -0
- package/lib/workroom/remote-dispatch-worker.d.ts +22 -0
- package/lib/workroom/remote-dispatch-worker.d.ts.map +1 -0
- package/lib/workroom/remote-dispatch-worker.js +124 -0
- package/lib/workroom/remote-dispatch-worker.js.map +1 -0
- package/lib/workroom/remote-dispatch.d.ts +79 -0
- package/lib/workroom/remote-dispatch.d.ts.map +1 -0
- package/lib/workroom/remote-dispatch.js +220 -0
- package/lib/workroom/remote-dispatch.js.map +1 -0
- package/lib/workroom/role-capability-snapshot.d.ts +88 -0
- package/lib/workroom/role-capability-snapshot.d.ts.map +1 -0
- package/lib/workroom/role-capability-snapshot.js +456 -0
- package/lib/workroom/role-capability-snapshot.js.map +1 -0
- package/lib/workroom/runtime.d.ts +109 -0
- package/lib/workroom/runtime.d.ts.map +1 -0
- package/lib/workroom/runtime.js +450 -0
- package/lib/workroom/runtime.js.map +1 -0
- package/lib/workroom/scheduler-priority-control.d.ts +35 -0
- package/lib/workroom/scheduler-priority-control.d.ts.map +1 -0
- package/lib/workroom/scheduler-priority-control.js +9 -0
- package/lib/workroom/scheduler-priority-control.js.map +1 -0
- package/lib/workroom/workflow-plan-builder.d.ts +88 -0
- package/lib/workroom/workflow-plan-builder.d.ts.map +1 -0
- package/lib/workroom/workflow-plan-builder.js +232 -0
- package/lib/workroom/workflow-plan-builder.js.map +1 -0
- package/lib/workroom/workroom-assignment-knowledge-context.d.ts +102 -0
- package/lib/workroom/workroom-assignment-knowledge-context.d.ts.map +1 -0
- package/lib/workroom/workroom-assignment-knowledge-context.js +127 -0
- package/lib/workroom/workroom-assignment-knowledge-context.js.map +1 -0
- package/lib/workroom/workroom-kernel.d.ts +141 -0
- package/lib/workroom/workroom-kernel.d.ts.map +1 -0
- package/lib/workroom/workroom-kernel.js +1325 -0
- package/lib/workroom/workroom-kernel.js.map +1 -0
- package/lib/workroom/workroom-preemption.d.ts +65 -0
- package/lib/workroom/workroom-preemption.d.ts.map +1 -0
- package/lib/workroom/workroom-preemption.js +213 -0
- package/lib/workroom/workroom-preemption.js.map +1 -0
- package/lib/workroom/workroom-scheduler-application.d.ts +43 -0
- package/lib/workroom/workroom-scheduler-application.d.ts.map +1 -0
- package/lib/workroom/workroom-scheduler-application.js +71 -0
- package/lib/workroom/workroom-scheduler-application.js.map +1 -0
- package/lib/workroom/workroom-scheduler.d.ts +135 -0
- package/lib/workroom/workroom-scheduler.d.ts.map +1 -0
- package/lib/workroom/workroom-scheduler.js +649 -0
- package/lib/workroom/workroom-scheduler.js.map +1 -0
- package/lib/workroom/workroom-task-report-store.d.ts +131 -0
- package/lib/workroom/workroom-task-report-store.d.ts.map +1 -0
- package/lib/workroom/workroom-task-report-store.js +528 -0
- package/lib/workroom/workroom-task-report-store.js.map +1 -0
- package/lib/zhin-agent/index.d.ts +7 -22
- package/lib/zhin-agent/index.d.ts.map +1 -1
- package/lib/zhin-agent/index.js +5 -33
- package/lib/zhin-agent/index.js.map +1 -1
- package/lib/zhin-agent/runtime-modules.d.ts +3 -3
- package/lib/zhin-agent/runtime-modules.d.ts.map +1 -1
- package/lib/zhin-agent/runtime-modules.js +3 -3
- package/lib/zhin-agent/runtime-modules.js.map +1 -1
- package/package.json +10 -16
- package/lib/a2a/delegation-message.d.ts +0 -14
- package/lib/a2a/delegation-message.d.ts.map +0 -1
- package/lib/a2a/delegation-message.js +0 -53
- package/lib/a2a/delegation-message.js.map +0 -1
- package/lib/a2a/task-state.d.ts +0 -9
- package/lib/a2a/task-state.d.ts.map +0 -1
- package/lib/a2a/task-state.js +0 -53
- package/lib/a2a/task-state.js.map +0 -1
- package/lib/assistant/runtime-registry.d.ts +0 -23
- package/lib/assistant/runtime-registry.d.ts.map +0 -1
- package/lib/assistant/runtime-registry.js +0 -27
- package/lib/assistant/runtime-registry.js.map +0 -1
- package/lib/authoring/define-dynamic.d.ts +0 -4
- package/lib/authoring/define-dynamic.d.ts.map +0 -1
- package/lib/authoring/define-dynamic.js +0 -8
- package/lib/authoring/define-dynamic.js.map +0 -1
- package/lib/authoring/define-state.d.ts +0 -4
- package/lib/authoring/define-state.d.ts.map +0 -1
- package/lib/authoring/define-state.js +0 -8
- package/lib/authoring/define-state.js.map +0 -1
- package/lib/builtin/five-agent/strategy.d.ts +0 -4
- package/lib/builtin/five-agent/strategy.d.ts.map +0 -1
- package/lib/builtin/five-agent/strategy.js +0 -42
- package/lib/builtin/five-agent/strategy.js.map +0 -1
- package/lib/builtin/memory-search-tool.d.ts +0 -2
- package/lib/builtin/memory-search-tool.d.ts.map +0 -1
- package/lib/builtin/memory-search-tool.js +0 -58
- package/lib/builtin/memory-search-tool.js.map +0 -1
- package/lib/builtin/memory-upsert-tool.d.ts +0 -2
- package/lib/builtin/memory-upsert-tool.d.ts.map +0 -1
- package/lib/builtin/memory-upsert-tool.js +0 -72
- package/lib/builtin/memory-upsert-tool.js.map +0 -1
- package/lib/builtin/orchestration-tools.d.ts +0 -7
- package/lib/builtin/orchestration-tools.d.ts.map +0 -1
- package/lib/builtin/orchestration-tools.js +0 -259
- package/lib/builtin/orchestration-tools.js.map +0 -1
- package/lib/connection/authorization-flow.d.ts +0 -26
- package/lib/connection/authorization-flow.d.ts.map +0 -1
- package/lib/connection/authorization-flow.js +0 -76
- package/lib/connection/authorization-flow.js.map +0 -1
- package/lib/connection/index.d.ts +0 -3
- package/lib/connection/index.d.ts.map +0 -1
- package/lib/connection/index.js +0 -2
- package/lib/connection/index.js.map +0 -1
- package/lib/dynamic/dynamic-registry.d.ts +0 -34
- package/lib/dynamic/dynamic-registry.d.ts.map +0 -1
- package/lib/dynamic/dynamic-registry.js +0 -52
- package/lib/dynamic/dynamic-registry.js.map +0 -1
- package/lib/init/bootstrap-gate.d.ts +0 -6
- package/lib/init/bootstrap-gate.d.ts.map +0 -1
- package/lib/init/bootstrap-gate.js +0 -28
- package/lib/init/bootstrap-gate.js.map +0 -1
- package/lib/memory-entry-registry.d.ts +0 -13
- package/lib/memory-entry-registry.d.ts.map +0 -1
- package/lib/memory-entry-registry.js +0 -24
- package/lib/memory-entry-registry.js.map +0 -1
- package/lib/orchestration-memory-hook.d.ts +0 -3
- package/lib/orchestration-memory-hook.d.ts.map +0 -1
- package/lib/orchestration-memory-hook.js +0 -22
- package/lib/orchestration-memory-hook.js.map +0 -1
- package/lib/orchestration-runtime-registry.d.ts +0 -16
- package/lib/orchestration-runtime-registry.d.ts.map +0 -1
- package/lib/orchestration-runtime-registry.js +0 -20
- package/lib/orchestration-runtime-registry.js.map +0 -1
- package/lib/orchestrator/agent-dispatcher.d.ts +0 -171
- package/lib/orchestrator/agent-dispatcher.d.ts.map +0 -1
- package/lib/orchestrator/agent-dispatcher.js +0 -415
- package/lib/orchestrator/agent-dispatcher.js.map +0 -1
- package/lib/orchestrator/bootstrap-executors.d.ts +0 -7
- package/lib/orchestrator/bootstrap-executors.d.ts.map +0 -1
- package/lib/orchestrator/bootstrap-executors.js +0 -73
- package/lib/orchestrator/bootstrap-executors.js.map +0 -1
- package/lib/orchestrator/orchestration-mappers.d.ts +0 -9
- package/lib/orchestrator/orchestration-mappers.d.ts.map +0 -1
- package/lib/orchestrator/orchestration-mappers.js +0 -117
- package/lib/orchestrator/orchestration-mappers.js.map +0 -1
- package/lib/orchestrator/orchestration-repository.d.ts +0 -91
- package/lib/orchestrator/orchestration-repository.d.ts.map +0 -1
- package/lib/orchestrator/orchestration-repository.js +0 -389
- package/lib/orchestrator/orchestration-repository.js.map +0 -1
- package/lib/orchestrator/orchestration-service.d.ts +0 -133
- package/lib/orchestrator/orchestration-service.d.ts.map +0 -1
- package/lib/orchestrator/orchestration-service.js +0 -582
- package/lib/orchestrator/orchestration-service.js.map +0 -1
- package/lib/orchestrator/orchestration-source.d.ts +0 -5
- package/lib/orchestrator/orchestration-source.d.ts.map +0 -1
- package/lib/orchestrator/orchestration-source.js +0 -22
- package/lib/orchestrator/orchestration-source.js.map +0 -1
- package/lib/orchestrator/orchestration-types.d.ts +0 -88
- package/lib/orchestrator/orchestration-types.d.ts.map +0 -1
- package/lib/orchestrator/orchestration-types.js +0 -2
- package/lib/orchestrator/orchestration-types.js.map +0 -1
- package/lib/orchestrator/remote-agent-registry.d.ts +0 -37
- package/lib/orchestrator/remote-agent-registry.d.ts.map +0 -1
- package/lib/orchestrator/remote-agent-registry.js +0 -178
- package/lib/orchestrator/remote-agent-registry.js.map +0 -1
- package/lib/orchestrator/remote-task-executor.d.ts +0 -10
- package/lib/orchestrator/remote-task-executor.d.ts.map +0 -1
- package/lib/orchestrator/remote-task-executor.js +0 -231
- package/lib/orchestrator/remote-task-executor.js.map +0 -1
- package/lib/orchestrator/remote-task-poller.d.ts +0 -18
- package/lib/orchestrator/remote-task-poller.d.ts.map +0 -1
- package/lib/orchestrator/remote-task-poller.js +0 -84
- package/lib/orchestrator/remote-task-poller.js.map +0 -1
- package/lib/orchestrator/resolve-subagent-tools.d.ts.map +0 -1
- package/lib/orchestrator/resolve-subagent-tools.js.map +0 -1
- package/lib/orchestrator/task-queue.d.ts +0 -167
- package/lib/orchestrator/task-queue.d.ts.map +0 -1
- package/lib/orchestrator/task-queue.js +0 -416
- package/lib/orchestrator/task-queue.js.map +0 -1
- package/lib/session/passive-group-buffer.d.ts +0 -15
- package/lib/session/passive-group-buffer.d.ts.map +0 -1
- package/lib/session/passive-group-buffer.js +0 -50
- package/lib/session/passive-group-buffer.js.map +0 -1
- package/lib/session/passive-group-session.d.ts +0 -10
- package/lib/session/passive-group-session.d.ts.map +0 -1
- package/lib/session/passive-group-session.js +0 -32
- package/lib/session/passive-group-session.js.map +0 -1
- package/lib/session-tree-runtime-registry.d.ts +0 -22
- package/lib/session-tree-runtime-registry.d.ts.map +0 -1
- package/lib/session-tree-runtime-registry.js.map +0 -1
- package/lib/state/agent-state-store.d.ts +0 -18
- package/lib/state/agent-state-store.d.ts.map +0 -1
- package/lib/state/agent-state-store.js +0 -50
- package/lib/state/agent-state-store.js.map +0 -1
- /package/lib/{orchestrator → resource-hub}/hook-registry.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/hook-registry.js +0 -0
- /package/lib/{orchestrator → resource-hub}/mcp-lifecycle.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/mcp-lifecycle.js +0 -0
- /package/lib/{orchestrator → resource-hub}/mcp-registry.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/mcp-registry.js +0 -0
- /package/lib/{orchestrator → resource-hub}/resource-registry.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/resource-registry.js +0 -0
- /package/lib/{orchestrator → resource-hub}/role-configs.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/skill-registry.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/skill-registry.js +0 -0
- /package/lib/{orchestrator → resource-hub}/subagent-registry.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/subagent-registry.js +0 -0
- /package/lib/{orchestrator → resource-hub}/tool-registry.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/tool-registry.js +0 -0
- /package/lib/{orchestrator → resource-hub}/tool-selection.d.ts +0 -0
- /package/lib/{orchestrator → resource-hub}/tool-selection.js +0 -0
- /package/lib/{orchestrator → resource-hub}/types.js +0 -0
|
@@ -0,0 +1,1935 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
import { assertAcceptanceContract, assertPersistedAcceptanceRecord } from './acceptance-policy.js';
|
|
5
|
+
import { canonicalWorkroomJson, compareCanonicalWorkroomText, deepFreezeWorkroomValue as deepFreeze, digestCanonicalWorkroomValue, } from './canonical-value.js';
|
|
6
|
+
import { assertWorkflowPlanProposal } from './workflow-plan-builder.js';
|
|
7
|
+
import { assertWorkflowPlanRevisionCandidate } from './plan-revision.js';
|
|
8
|
+
import { parseWorkroomRemoteAssignmentIssuance } from './remote-assignment-issuance.js';
|
|
9
|
+
import { parseWorkroomLocalAssignmentIssuance } from './local-assignment-issuance.js';
|
|
10
|
+
import { assertWorkroomSchedulerPolicySnapshot, parseWorkroomDispatchTaskDecision, parseWorkroomPreemptionPrepareDecision, parseWorkroomPriorityChangeProposal, } from './workroom-scheduler.js';
|
|
11
|
+
import { DurableFileStore } from './durable-file-store.js';
|
|
12
|
+
import { FileLegacyEmbeddedPayloadReadAdapter, LegacyEmbeddedPayloadDetectedError, assertActiveStoreHasNoLegacyEmbeddedPayload, } from './legacy-embedded-payload-migration.js';
|
|
13
|
+
export class WorkroomJournalPayloadAuthorityUnavailableError extends Error {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('Governed Workroom Journal payload authority is unavailable');
|
|
16
|
+
this.name = 'WorkroomJournalPayloadAuthorityUnavailableError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class WorkroomSequenceConflictError extends Error {
|
|
20
|
+
runId;
|
|
21
|
+
expectedSequence;
|
|
22
|
+
actualSequence;
|
|
23
|
+
constructor(runId, expectedSequence, actualSequence) {
|
|
24
|
+
super(`Workroom ${runId} sequence conflict: expected ${expectedSequence}, actual ${actualSequence}`);
|
|
25
|
+
this.runId = runId;
|
|
26
|
+
this.expectedSequence = expectedSequence;
|
|
27
|
+
this.actualSequence = actualSequence;
|
|
28
|
+
this.name = 'WorkroomSequenceConflictError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class MemoryWorkroomJournal {
|
|
32
|
+
#runs = new Map();
|
|
33
|
+
#payloads;
|
|
34
|
+
constructor(payloads = new MemoryWorkroomJournalPayloadPort()) {
|
|
35
|
+
this.#payloads = payloads;
|
|
36
|
+
}
|
|
37
|
+
async listRunIds() {
|
|
38
|
+
return Object.freeze([...this.#runs.keys()].sort());
|
|
39
|
+
}
|
|
40
|
+
async scanStoredHeaders() {
|
|
41
|
+
return Object.freeze([...this.#runs.entries()]
|
|
42
|
+
.sort(([left], [right]) => compareCanonicalWorkroomText(left, right))
|
|
43
|
+
.map(([runId, events]) => storedRunHeaders(runId, events)));
|
|
44
|
+
}
|
|
45
|
+
async readStoredHeaders(runId) {
|
|
46
|
+
const events = this.#runs.get(runId) ?? [];
|
|
47
|
+
return events.length === 0 ? null : storedRunHeaders(runId, events);
|
|
48
|
+
}
|
|
49
|
+
async verifyGovernedPayloadPublication(intent) {
|
|
50
|
+
const events = this.#runs.get(intent.publicationScope ?? '') ?? [];
|
|
51
|
+
return verifyJournalPayloadPublication(intent, events);
|
|
52
|
+
}
|
|
53
|
+
async read(runId) {
|
|
54
|
+
const events = this.#runs.get(runId) ?? [];
|
|
55
|
+
return events.length === 0
|
|
56
|
+
? Object.freeze([])
|
|
57
|
+
: await materializeStoredEvents(events, this.#payloads);
|
|
58
|
+
}
|
|
59
|
+
async append(runId, expectedSequence, drafts) {
|
|
60
|
+
const current = this.#runs.get(runId) ?? [];
|
|
61
|
+
const actualSequence = current.at(-1)?.sequence ?? -1;
|
|
62
|
+
if (actualSequence !== expectedSequence) {
|
|
63
|
+
throw new WorkroomSequenceConflictError(runId, expectedSequence, actualSequence);
|
|
64
|
+
}
|
|
65
|
+
if (drafts.length === 0)
|
|
66
|
+
return [];
|
|
67
|
+
const appended = materializeEvents(runId, expectedSequence, drafts);
|
|
68
|
+
const projectId = projectIdForAppend(current, appended);
|
|
69
|
+
const protectedEvents = await protectEvents(appended, projectId, this.#payloads);
|
|
70
|
+
const winner = this.#runs.get(runId) ?? [];
|
|
71
|
+
const winnerSequence = winner.at(-1)?.sequence ?? -1;
|
|
72
|
+
if (winnerSequence !== expectedSequence) {
|
|
73
|
+
throw new WorkroomSequenceConflictError(runId, expectedSequence, winnerSequence);
|
|
74
|
+
}
|
|
75
|
+
this.#runs.set(runId, Object.freeze([...current, ...protectedEvents]));
|
|
76
|
+
return appended;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** In-memory authority used by the non-production Memory journal. */
|
|
80
|
+
export class MemoryWorkroomJournalPayloadPort {
|
|
81
|
+
#values = new Map();
|
|
82
|
+
async write(input) {
|
|
83
|
+
if (digestCanonicalWorkroomValue(input.value) !== input.contentHash) {
|
|
84
|
+
throw new Error('Memory Workroom Journal payload content hash drift');
|
|
85
|
+
}
|
|
86
|
+
const objectId = createWorkroomJournalPayloadObjectId(input);
|
|
87
|
+
const vaultObjectId = `memory:${digestCanonicalWorkroomValue({ objectId, contentHash: input.contentHash })}`;
|
|
88
|
+
const existing = this.#values.get(vaultObjectId);
|
|
89
|
+
if (existing !== undefined
|
|
90
|
+
&& digestCanonicalWorkroomValue(existing) !== input.contentHash) {
|
|
91
|
+
throw new Error('Memory Workroom Journal payload identity conflict');
|
|
92
|
+
}
|
|
93
|
+
this.#values.set(vaultObjectId, structuredClone(input.value));
|
|
94
|
+
return Object.freeze({
|
|
95
|
+
descriptor: Object.freeze({
|
|
96
|
+
vaultObjectId,
|
|
97
|
+
objectId,
|
|
98
|
+
payloadHash: input.contentHash,
|
|
99
|
+
descriptorDigest: digestCanonicalWorkroomValue({
|
|
100
|
+
objectId,
|
|
101
|
+
payloadHash: input.contentHash,
|
|
102
|
+
projectId: input.projectId,
|
|
103
|
+
}),
|
|
104
|
+
locationManifestDigest: digestCanonicalWorkroomValue({ location: vaultObjectId }),
|
|
105
|
+
bytes: Buffer.byteLength(canonicalWorkroomJson(input.value)),
|
|
106
|
+
}),
|
|
107
|
+
source: Object.freeze({
|
|
108
|
+
kind: 'command',
|
|
109
|
+
ref: input.source.ref,
|
|
110
|
+
digest: input.source.digest,
|
|
111
|
+
bindingDigest: input.source.bindingDigest,
|
|
112
|
+
verification: 'verified',
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async read(input) {
|
|
117
|
+
const value = this.#values.get(input.receipt.descriptor.vaultObjectId);
|
|
118
|
+
if (value === undefined)
|
|
119
|
+
throw new Error('Memory Workroom Journal payload is unavailable');
|
|
120
|
+
return structuredClone(value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Durable append-only journal. Every committed batch is an immutable segment;
|
|
125
|
+
* publishing its first sequence with an exclusive hard-link is the filesystem
|
|
126
|
+
* CAS. Separate generation instances and separate processes therefore cannot
|
|
127
|
+
* overwrite one another after reading the same expectedSequence.
|
|
128
|
+
*/
|
|
129
|
+
export class FileWorkroomJournal {
|
|
130
|
+
#directory;
|
|
131
|
+
#store;
|
|
132
|
+
#payloads;
|
|
133
|
+
constructor(directory, payloads) {
|
|
134
|
+
this.#directory = directory;
|
|
135
|
+
this.#store = new DurableFileStore(directory);
|
|
136
|
+
this.#payloads = payloads;
|
|
137
|
+
}
|
|
138
|
+
async listRunIds() {
|
|
139
|
+
let names;
|
|
140
|
+
try {
|
|
141
|
+
names = await readdir(this.#directory);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (isMissingFile(error))
|
|
145
|
+
return Object.freeze([]);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
if (names.some(name => name.endsWith('.json') && !isSegmentName(name))) {
|
|
149
|
+
throw new Error('Invalid Workroom journal segment name');
|
|
150
|
+
}
|
|
151
|
+
const ids = new Set();
|
|
152
|
+
for (const name of names) {
|
|
153
|
+
if (!isSegmentName(name))
|
|
154
|
+
continue;
|
|
155
|
+
const events = await this.#readStoredFile(join(this.#directory, name), segmentFirstSequence(name));
|
|
156
|
+
const runId = events[0]?.runId;
|
|
157
|
+
if (runId)
|
|
158
|
+
ids.add(runId);
|
|
159
|
+
}
|
|
160
|
+
if (ids.size > 0)
|
|
161
|
+
await this.#store.syncLeaf();
|
|
162
|
+
return Object.freeze([...ids].sort());
|
|
163
|
+
}
|
|
164
|
+
async scanStoredHeaders() {
|
|
165
|
+
const groups = new Map();
|
|
166
|
+
let names;
|
|
167
|
+
try {
|
|
168
|
+
names = (await readdir(this.#directory)).filter(name => name.endsWith('.json')).sort();
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (isMissingFile(error))
|
|
172
|
+
return Object.freeze([]);
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
if (names.some(name => !isSegmentName(name))) {
|
|
176
|
+
throw new Error('Invalid Workroom journal segment name');
|
|
177
|
+
}
|
|
178
|
+
for (const name of names) {
|
|
179
|
+
const events = await this.#readStoredFile(join(this.#directory, name), segmentFirstSequence(name));
|
|
180
|
+
const runId = events[0]?.runId;
|
|
181
|
+
if (!runId)
|
|
182
|
+
throw new Error('Workroom journal segment has no Run header');
|
|
183
|
+
groups.set(runId, [...(groups.get(runId) ?? []), ...events]);
|
|
184
|
+
}
|
|
185
|
+
if (groups.size > 0)
|
|
186
|
+
await this.#store.syncLeaf();
|
|
187
|
+
return Object.freeze([...groups.entries()]
|
|
188
|
+
.sort(([left], [right]) => compareCanonicalWorkroomText(left, right))
|
|
189
|
+
.map(([runId, events]) => storedRunHeaders(runId, events)));
|
|
190
|
+
}
|
|
191
|
+
async readStoredHeaders(runId) {
|
|
192
|
+
const events = await this.#readStoredWithoutPayloads(runId);
|
|
193
|
+
return events.length === 0 ? null : storedRunHeaders(runId, events);
|
|
194
|
+
}
|
|
195
|
+
async verifyGovernedPayloadPublication(intent) {
|
|
196
|
+
if (!intent.publicationScope)
|
|
197
|
+
return deepFreeze({ status: 'missing' });
|
|
198
|
+
return verifyJournalPayloadPublication(intent, await this.#readStoredWithoutPayloads(intent.publicationScope));
|
|
199
|
+
}
|
|
200
|
+
async read(runId) {
|
|
201
|
+
const digest = this.#digest(runId);
|
|
202
|
+
let names;
|
|
203
|
+
try {
|
|
204
|
+
const entries = await readdir(this.#directory);
|
|
205
|
+
names = entries
|
|
206
|
+
.filter(name => name.startsWith(`${digest}.`) && name.endsWith('.json'));
|
|
207
|
+
if (names.some(name => !isSegmentName(name))) {
|
|
208
|
+
throw new Error('Invalid Workroom journal segment name');
|
|
209
|
+
}
|
|
210
|
+
names.sort();
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (isMissingFile(error))
|
|
214
|
+
return [];
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
const segments = await Promise.all(names.map(name => this.#readStoredFile(join(this.#directory, name), segmentFirstSequence(name))));
|
|
218
|
+
const events = segments.flat();
|
|
219
|
+
if (events.some(event => event.runId !== runId)) {
|
|
220
|
+
throw new Error('Workroom journal digest collision');
|
|
221
|
+
}
|
|
222
|
+
const ordered = events.sort((left, right) => left.sequence - right.sequence);
|
|
223
|
+
if (ordered.some((event, index) => event.sequence !== index)) {
|
|
224
|
+
throw new Error('Workroom journal sequence is not contiguous');
|
|
225
|
+
}
|
|
226
|
+
if (ordered.length > 0) {
|
|
227
|
+
await this.#store.syncLeaf();
|
|
228
|
+
await reconcileJournalPayloads(runId, ordered, this.#requirePayloads());
|
|
229
|
+
}
|
|
230
|
+
if (ordered.length === 0)
|
|
231
|
+
return Object.freeze([]);
|
|
232
|
+
return await materializeStoredEvents(Object.freeze(ordered), this.#requirePayloads());
|
|
233
|
+
}
|
|
234
|
+
async append(runId, expectedSequence, drafts) {
|
|
235
|
+
const current = await this.#readStored(runId);
|
|
236
|
+
const actualSequence = current.at(-1)?.sequence ?? -1;
|
|
237
|
+
if (actualSequence !== expectedSequence) {
|
|
238
|
+
throw new WorkroomSequenceConflictError(runId, expectedSequence, actualSequence);
|
|
239
|
+
}
|
|
240
|
+
if (drafts.length === 0)
|
|
241
|
+
return [];
|
|
242
|
+
const result = materializeEvents(runId, expectedSequence, drafts);
|
|
243
|
+
const projectId = projectIdForAppend(current, result);
|
|
244
|
+
await this.#store.ensureDurableLeaf('Workroom Journal');
|
|
245
|
+
await this.#assertNoLegacyEmbeddedPayload();
|
|
246
|
+
const protectedEvents = await protectEvents(result, projectId, this.#requirePayloads());
|
|
247
|
+
const segment = this.#segmentPath(runId, expectedSequence + 1);
|
|
248
|
+
const payload = Object.freeze({
|
|
249
|
+
version: 3,
|
|
250
|
+
runId,
|
|
251
|
+
expectedSequence,
|
|
252
|
+
events: protectedEvents,
|
|
253
|
+
});
|
|
254
|
+
const stored = Object.freeze({
|
|
255
|
+
...payload,
|
|
256
|
+
payloadDigest: digestCanonicalWorkroomValue(payload),
|
|
257
|
+
});
|
|
258
|
+
const receipts = collectGovernedPayloadReceipts(protectedEvents);
|
|
259
|
+
await this.#requirePayloads().prepare?.({ projectId, runId, receipts });
|
|
260
|
+
let headerPublished = false;
|
|
261
|
+
try {
|
|
262
|
+
const published = await this.#store.publishCreateOnly({
|
|
263
|
+
target: segment,
|
|
264
|
+
content: canonicalWorkroomJson(stored),
|
|
265
|
+
createdValue: result,
|
|
266
|
+
onConflict: async () => {
|
|
267
|
+
const winner = await this.#readStored(runId);
|
|
268
|
+
throw new WorkroomSequenceConflictError(runId, expectedSequence, winner.at(-1)?.sequence ?? -1);
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
headerPublished = true;
|
|
272
|
+
await this.#requirePayloads().publish?.({
|
|
273
|
+
projectId,
|
|
274
|
+
runId,
|
|
275
|
+
receipts,
|
|
276
|
+
publicationDigest: journalPublicationDigest(runId, [...current, ...protectedEvents]),
|
|
277
|
+
});
|
|
278
|
+
return published.value;
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
if (!headerPublished) {
|
|
282
|
+
await this.#requirePayloads().abandon?.({ projectId, runId, receipts, reason: 'cas_lost' });
|
|
283
|
+
}
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
async #readStored(runId) {
|
|
288
|
+
const events = await this.#readStoredWithoutPayloads(runId);
|
|
289
|
+
if (events.length > 0)
|
|
290
|
+
await reconcileJournalPayloads(runId, events, this.#requirePayloads());
|
|
291
|
+
return events;
|
|
292
|
+
}
|
|
293
|
+
async #assertNoLegacyEmbeddedPayload() {
|
|
294
|
+
const names = await readdir(this.#directory);
|
|
295
|
+
const unexpected = names.find(name => !isSegmentName(name) && !isSegmentTemporaryName(name));
|
|
296
|
+
if (unexpected)
|
|
297
|
+
throw new Error('Invalid Workroom journal segment name');
|
|
298
|
+
const segments = names.filter(isSegmentName).sort();
|
|
299
|
+
if (segments.length === 0)
|
|
300
|
+
return;
|
|
301
|
+
await assertActiveStoreHasNoLegacyEmbeddedPayload(new FileLegacyEmbeddedPayloadReadAdapter(segments.map(name => ({ sourceKind: 'journal', path: join(this.#directory, name) }))));
|
|
302
|
+
}
|
|
303
|
+
async #readStoredWithoutPayloads(runId) {
|
|
304
|
+
const digest = this.#digest(runId);
|
|
305
|
+
let names;
|
|
306
|
+
try {
|
|
307
|
+
names = (await readdir(this.#directory))
|
|
308
|
+
.filter(name => name.startsWith(`${digest}.`) && name.endsWith('.json'))
|
|
309
|
+
.sort();
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
if (isMissingFile(error))
|
|
313
|
+
return [];
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
const events = (await Promise.all(names.map(name => this.#readStoredFile(join(this.#directory, name), segmentFirstSequence(name))))).flat().sort((left, right) => left.sequence - right.sequence);
|
|
317
|
+
if (events.some((event, index) => event.runId !== runId || event.sequence !== index)) {
|
|
318
|
+
throw new Error('Workroom journal sequence or Run binding is invalid');
|
|
319
|
+
}
|
|
320
|
+
if (events.length > 0)
|
|
321
|
+
await this.#store.syncLeaf();
|
|
322
|
+
return Object.freeze(events);
|
|
323
|
+
}
|
|
324
|
+
async #readStoredFile(path, expectedFirstSequence) {
|
|
325
|
+
try {
|
|
326
|
+
const parsed = JSON.parse(await readFile(path, 'utf8'));
|
|
327
|
+
if (Array.isArray(parsed)) {
|
|
328
|
+
throw legacyJournalPayloadError();
|
|
329
|
+
}
|
|
330
|
+
if (isRecord(parsed) && (parsed.version === 1 || parsed.version === 2)) {
|
|
331
|
+
throw legacyJournalPayloadError();
|
|
332
|
+
}
|
|
333
|
+
if (!isRecord(parsed) || parsed.version !== 3 || !isNonEmptyString(parsed.runId)
|
|
334
|
+
|| !Number.isSafeInteger(parsed.expectedSequence)
|
|
335
|
+
|| !Array.isArray(parsed.events) || typeof parsed.payloadDigest !== 'string') {
|
|
336
|
+
throw new Error('Invalid Workroom journal segment envelope');
|
|
337
|
+
}
|
|
338
|
+
if (parsed.expectedSequence !== expectedFirstSequence - 1) {
|
|
339
|
+
throw new Error('Workroom journal segment first sequence does not match its filename');
|
|
340
|
+
}
|
|
341
|
+
const events = parseStoredEvents(parsed.events);
|
|
342
|
+
const payload = Object.freeze({
|
|
343
|
+
version: 3,
|
|
344
|
+
runId: parsed.runId,
|
|
345
|
+
expectedSequence: parsed.expectedSequence,
|
|
346
|
+
events,
|
|
347
|
+
});
|
|
348
|
+
const stored = Object.freeze({
|
|
349
|
+
...payload,
|
|
350
|
+
payloadDigest: parsed.payloadDigest,
|
|
351
|
+
});
|
|
352
|
+
if (parsed.payloadDigest !== digestCanonicalWorkroomValue(payload)
|
|
353
|
+
|| canonicalWorkroomJson(parsed) !== canonicalWorkroomJson(stored)) {
|
|
354
|
+
throw new Error('Workroom journal segment payload digest mismatch');
|
|
355
|
+
}
|
|
356
|
+
if (events.some(event => event.runId !== parsed.runId)) {
|
|
357
|
+
throw new Error('Workroom journal segment Run binding drift');
|
|
358
|
+
}
|
|
359
|
+
if (basename(path) !== `${this.#digest(parsed.runId)}.${String(expectedFirstSequence).padStart(16, '0')}.json`) {
|
|
360
|
+
throw new Error('Workroom journal segment Run digest does not match its filename');
|
|
361
|
+
}
|
|
362
|
+
if (events.length === 0 || events[0].sequence !== expectedFirstSequence) {
|
|
363
|
+
throw new Error('Workroom journal segment first sequence does not match its filename');
|
|
364
|
+
}
|
|
365
|
+
if (events.some((event, index) => event.sequence !== expectedFirstSequence + index)) {
|
|
366
|
+
throw new Error('Workroom journal segment sequence is not contiguous');
|
|
367
|
+
}
|
|
368
|
+
return events;
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
if (isMissingFile(error))
|
|
372
|
+
return [];
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
#digest(runId) {
|
|
377
|
+
return createHash('sha256').update(runId).digest('hex');
|
|
378
|
+
}
|
|
379
|
+
#segmentPath(runId, firstSequence) {
|
|
380
|
+
return join(this.#directory, `${this.#digest(runId)}.${String(firstSequence).padStart(16, '0')}.json`);
|
|
381
|
+
}
|
|
382
|
+
#requirePayloads() {
|
|
383
|
+
if (!this.#payloads)
|
|
384
|
+
throw new WorkroomJournalPayloadAuthorityUnavailableError();
|
|
385
|
+
return this.#payloads;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/** Candidate-owned latch: no caller can observe a placeholder journal. */
|
|
389
|
+
export class ActivatableWorkroomJournal {
|
|
390
|
+
#delegate = null;
|
|
391
|
+
get active() {
|
|
392
|
+
return this.#delegate !== null;
|
|
393
|
+
}
|
|
394
|
+
activate(delegate) {
|
|
395
|
+
if (this.#delegate)
|
|
396
|
+
throw new Error('Workroom journal is already active');
|
|
397
|
+
this.#delegate = delegate;
|
|
398
|
+
}
|
|
399
|
+
listRunIds() {
|
|
400
|
+
return this.#require().listRunIds();
|
|
401
|
+
}
|
|
402
|
+
scanStoredHeaders() {
|
|
403
|
+
return this.#require().scanStoredHeaders();
|
|
404
|
+
}
|
|
405
|
+
readStoredHeaders(runId) {
|
|
406
|
+
return this.#require().readStoredHeaders(runId);
|
|
407
|
+
}
|
|
408
|
+
verifyGovernedPayloadPublication(intent) {
|
|
409
|
+
const delegate = this.#require();
|
|
410
|
+
return delegate.verifyGovernedPayloadPublication
|
|
411
|
+
? delegate.verifyGovernedPayloadPublication(intent)
|
|
412
|
+
: Promise.resolve(deepFreeze({ status: 'unknown' }));
|
|
413
|
+
}
|
|
414
|
+
read(runId) {
|
|
415
|
+
return this.#require().read(runId);
|
|
416
|
+
}
|
|
417
|
+
append(runId, expectedSequence, events) {
|
|
418
|
+
return this.#require().append(runId, expectedSequence, events);
|
|
419
|
+
}
|
|
420
|
+
#require() {
|
|
421
|
+
if (!this.#delegate)
|
|
422
|
+
throw new Error('Workroom journal is not active');
|
|
423
|
+
return this.#delegate;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
export class DatabaseWorkroomJournal {
|
|
427
|
+
#database;
|
|
428
|
+
#eventModel;
|
|
429
|
+
#payloads;
|
|
430
|
+
constructor(database, eventModel, payloads) {
|
|
431
|
+
this.#database = database;
|
|
432
|
+
this.#eventModel = eventModel;
|
|
433
|
+
this.#payloads = payloads;
|
|
434
|
+
}
|
|
435
|
+
async listRunIds() {
|
|
436
|
+
return Object.freeze((await this.scanStoredHeaders()).map(run => run.runId));
|
|
437
|
+
}
|
|
438
|
+
async scanStoredHeaders() {
|
|
439
|
+
const rows = await this.#eventModel.select().where({});
|
|
440
|
+
return Object.freeze([...parseStoredRowGroups(rows).entries()]
|
|
441
|
+
.map(([runId, events]) => storedRunHeaders(runId, events)));
|
|
442
|
+
}
|
|
443
|
+
async readStoredHeaders(runId) {
|
|
444
|
+
const rows = await this.#eventModel.select().where({ run_id: runId });
|
|
445
|
+
const events = parseStoredRows(runId, rows);
|
|
446
|
+
return events.length === 0 ? null : storedRunHeaders(runId, events);
|
|
447
|
+
}
|
|
448
|
+
async verifyGovernedPayloadPublication(intent) {
|
|
449
|
+
if (!intent.publicationScope)
|
|
450
|
+
return deepFreeze({ status: 'missing' });
|
|
451
|
+
const rows = await this.#eventModel.select().where({ run_id: intent.publicationScope });
|
|
452
|
+
return verifyJournalPayloadPublication(intent, parseStoredRows(intent.publicationScope, rows));
|
|
453
|
+
}
|
|
454
|
+
async read(runId) {
|
|
455
|
+
const rows = await this.#eventModel.select().where({ run_id: runId });
|
|
456
|
+
const events = parseStoredRows(runId, rows);
|
|
457
|
+
if (events.length === 0)
|
|
458
|
+
return Object.freeze([]);
|
|
459
|
+
await reconcileJournalPayloads(runId, events, this.#requirePayloads());
|
|
460
|
+
return await materializeStoredEvents(events, this.#requirePayloads());
|
|
461
|
+
}
|
|
462
|
+
async append(runId, expectedSequence, drafts) {
|
|
463
|
+
let publication;
|
|
464
|
+
try {
|
|
465
|
+
const appended = await this.#database.transaction(async (transaction) => {
|
|
466
|
+
const allRows = await transaction.select('workroom_events').where({});
|
|
467
|
+
await assertActiveStoreHasNoLegacyEmbeddedPayload({
|
|
468
|
+
read: async () => legacyDatabaseJournalRecords(allRows),
|
|
469
|
+
});
|
|
470
|
+
const current = parseStoredRowGroups(allRows).get(runId) ?? Object.freeze([]);
|
|
471
|
+
if (current.length > 0)
|
|
472
|
+
await reconcileJournalPayloads(runId, current, this.#requirePayloads());
|
|
473
|
+
const actualSequence = current.at(-1)?.sequence ?? -1;
|
|
474
|
+
if (actualSequence !== expectedSequence) {
|
|
475
|
+
throw new WorkroomSequenceConflictError(runId, expectedSequence, actualSequence);
|
|
476
|
+
}
|
|
477
|
+
if (drafts.length === 0)
|
|
478
|
+
return [];
|
|
479
|
+
const appended = materializeEvents(runId, expectedSequence, drafts);
|
|
480
|
+
const projectId = projectIdForAppend(current, appended);
|
|
481
|
+
const protectedEvents = await protectEvents(appended, projectId, this.#requirePayloads());
|
|
482
|
+
await this.#requirePayloads().prepare?.({
|
|
483
|
+
projectId,
|
|
484
|
+
runId,
|
|
485
|
+
receipts: collectGovernedPayloadReceipts(protectedEvents),
|
|
486
|
+
});
|
|
487
|
+
await transaction.insertMany('workroom_events', protectedEvents.map(toRow));
|
|
488
|
+
publication = { projectId, protectedEvents, current };
|
|
489
|
+
return appended;
|
|
490
|
+
}, { isolationLevel: 'SERIALIZABLE' });
|
|
491
|
+
if (publication) {
|
|
492
|
+
await this.#requirePayloads().publish?.({
|
|
493
|
+
projectId: publication.projectId,
|
|
494
|
+
runId,
|
|
495
|
+
receipts: collectGovernedPayloadReceipts(publication.protectedEvents),
|
|
496
|
+
publicationDigest: journalPublicationDigest(runId, [...publication.current, ...publication.protectedEvents]),
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
return appended;
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
if (error instanceof WorkroomSequenceConflictError)
|
|
503
|
+
throw error;
|
|
504
|
+
// A serializable/unique-key loser is dialect-specific. Re-read the
|
|
505
|
+
// authoritative sequence and normalize only a proven concurrent winner;
|
|
506
|
+
// unrelated database failures retain their original error.
|
|
507
|
+
const actualSequence = (await this.read(runId)).at(-1)?.sequence ?? -1;
|
|
508
|
+
if (actualSequence !== expectedSequence) {
|
|
509
|
+
throw new WorkroomSequenceConflictError(runId, expectedSequence, actualSequence);
|
|
510
|
+
}
|
|
511
|
+
if (publication) {
|
|
512
|
+
await this.#requirePayloads().abandon?.({
|
|
513
|
+
projectId: publication.projectId,
|
|
514
|
+
runId,
|
|
515
|
+
receipts: collectGovernedPayloadReceipts(publication.protectedEvents),
|
|
516
|
+
reason: 'write_failed',
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
throw error;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
#requirePayloads() {
|
|
523
|
+
if (!this.#payloads)
|
|
524
|
+
throw new WorkroomJournalPayloadAuthorityUnavailableError();
|
|
525
|
+
return this.#payloads;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function legacyDatabaseJournalRecords(rows) {
|
|
529
|
+
return Object.freeze(rows.map(row => {
|
|
530
|
+
let envelope;
|
|
531
|
+
try {
|
|
532
|
+
envelope = JSON.parse(String(row.payload_json));
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
throw new Error('Legacy Workroom Journal database payload is corrupt or unknown');
|
|
536
|
+
}
|
|
537
|
+
return Object.freeze({
|
|
538
|
+
storage: 'database',
|
|
539
|
+
sourceKind: 'journal',
|
|
540
|
+
recordRef: `workroom-events:${digestCanonicalWorkroomValue({
|
|
541
|
+
runId: String(row.run_id),
|
|
542
|
+
sequence: row.sequence,
|
|
543
|
+
})}`,
|
|
544
|
+
value: Object.freeze({ version: row.version, envelope }),
|
|
545
|
+
});
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
function materializeEvents(runId, expectedSequence, drafts) {
|
|
549
|
+
if (!isNonEmptyString(runId) || !Number.isSafeInteger(expectedSequence) || expectedSequence < -1) {
|
|
550
|
+
throw new Error('Invalid Workroom append position');
|
|
551
|
+
}
|
|
552
|
+
return Object.freeze(drafts.map((draft, index) => {
|
|
553
|
+
if (!isNonEmptyString(draft.eventId) || !isFiniteNumber(draft.occurredAt)
|
|
554
|
+
|| !isWorkroomEventType(draft.type) || !isRecord(draft.payload)) {
|
|
555
|
+
throw new Error('Invalid Workroom event draft');
|
|
556
|
+
}
|
|
557
|
+
validatePayload(draft.type, draft.payload, expectedSequence + index + 1);
|
|
558
|
+
return Object.freeze({
|
|
559
|
+
...draft,
|
|
560
|
+
version: 1,
|
|
561
|
+
runId,
|
|
562
|
+
sequence: expectedSequence + index + 1,
|
|
563
|
+
payload: Object.freeze({ ...draft.payload }),
|
|
564
|
+
});
|
|
565
|
+
}));
|
|
566
|
+
}
|
|
567
|
+
function parseStoredEvents(values) {
|
|
568
|
+
const events = values.map((value) => {
|
|
569
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
570
|
+
throw new Error('Invalid Workroom journal event');
|
|
571
|
+
}
|
|
572
|
+
const raw = value;
|
|
573
|
+
if (raw.version === 1 || raw.version === 2)
|
|
574
|
+
throw legacyJournalPayloadError();
|
|
575
|
+
assertExactRecordKeys(raw, [
|
|
576
|
+
'version', 'eventId', 'runId', 'sequence', 'occurredAt', 'type', 'control', 'payload',
|
|
577
|
+
], 'Stored Workroom event');
|
|
578
|
+
const event = value;
|
|
579
|
+
if (event.version !== 3 || !isNonEmptyString(event.eventId) || !isNonEmptyString(event.runId)
|
|
580
|
+
|| !isSequence(event.sequence) || !isFiniteNumber(event.occurredAt)
|
|
581
|
+
|| !isWorkroomEventType(event.type) || !isRecord(event.control) || !isRecord(event.payload)) {
|
|
582
|
+
throw new Error('Invalid Workroom journal event');
|
|
583
|
+
}
|
|
584
|
+
validateStoredEventControl(event.type, event.control);
|
|
585
|
+
validateProtectedPayload(event.type, event.payload);
|
|
586
|
+
const sequence = Number(event.sequence);
|
|
587
|
+
return Object.freeze({
|
|
588
|
+
...event,
|
|
589
|
+
version: 3,
|
|
590
|
+
eventId: event.eventId,
|
|
591
|
+
runId: event.runId,
|
|
592
|
+
sequence,
|
|
593
|
+
occurredAt: event.occurredAt,
|
|
594
|
+
type: event.type,
|
|
595
|
+
control: deepFreeze({ ...event.control }),
|
|
596
|
+
payload: Object.freeze({ ...event.payload }),
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
return Object.freeze(events.sort((left, right) => left.sequence - right.sequence));
|
|
600
|
+
}
|
|
601
|
+
function isMissingFile(error) {
|
|
602
|
+
return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';
|
|
603
|
+
}
|
|
604
|
+
function isSegmentName(name) {
|
|
605
|
+
return /^[a-f0-9]{64}\.[0-9]{16}\.json$/u.test(name);
|
|
606
|
+
}
|
|
607
|
+
function isSegmentTemporaryName(name) {
|
|
608
|
+
return /^[a-f0-9]{64}\.[0-9]{16}\.json\.[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\.tmp$/u
|
|
609
|
+
.test(name);
|
|
610
|
+
}
|
|
611
|
+
function segmentFirstSequence(name) {
|
|
612
|
+
if (!isSegmentName(name))
|
|
613
|
+
throw new Error('Invalid Workroom journal segment name');
|
|
614
|
+
const value = Number(name.slice(65, 81));
|
|
615
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
616
|
+
throw new Error('Invalid Workroom journal segment first sequence');
|
|
617
|
+
}
|
|
618
|
+
return value;
|
|
619
|
+
}
|
|
620
|
+
function toRow(event) {
|
|
621
|
+
const storedEventDigest = digestStoredWorkroomEvent(event);
|
|
622
|
+
const row = {
|
|
623
|
+
id: `${event.runId}:${event.sequence}`,
|
|
624
|
+
run_id: event.runId,
|
|
625
|
+
sequence: event.sequence,
|
|
626
|
+
version: event.version,
|
|
627
|
+
type: event.type,
|
|
628
|
+
payload_json: canonicalWorkroomJson({
|
|
629
|
+
eventId: event.eventId,
|
|
630
|
+
control: event.control,
|
|
631
|
+
payload: event.payload,
|
|
632
|
+
}),
|
|
633
|
+
occurred_at: event.occurredAt,
|
|
634
|
+
stored_event_digest: storedEventDigest,
|
|
635
|
+
};
|
|
636
|
+
return { ...row, row_binding_digest: digestWorkroomEventRowBinding(row) };
|
|
637
|
+
}
|
|
638
|
+
function parseStoredRows(runId, rows) {
|
|
639
|
+
const events = rows.map(row => {
|
|
640
|
+
if (row.version === 1 || row.version === 2)
|
|
641
|
+
throw legacyJournalPayloadError();
|
|
642
|
+
if (!isDigest(row.stored_event_digest) || !isDigest(row.row_binding_digest)) {
|
|
643
|
+
throw legacyJournalPayloadError();
|
|
644
|
+
}
|
|
645
|
+
if (row.version !== 3)
|
|
646
|
+
throw new Error(`Unsupported Workroom event version: ${String(row.version)}`);
|
|
647
|
+
let envelope;
|
|
648
|
+
try {
|
|
649
|
+
envelope = JSON.parse(String(row.payload_json));
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
throw new Error('Invalid Workroom event payload JSON');
|
|
653
|
+
}
|
|
654
|
+
if (!envelope || !isNonEmptyString(envelope.eventId) || !isRecord(envelope.control)
|
|
655
|
+
|| !isRecord(envelope.payload)
|
|
656
|
+
|| !isSequence(row.sequence) || !isFiniteNumber(row.occurred_at)
|
|
657
|
+
|| !isWorkroomEventType(row.type)) {
|
|
658
|
+
throw new Error('Invalid Workroom event payload envelope');
|
|
659
|
+
}
|
|
660
|
+
assertExactRecordKeys(envelope, ['eventId', 'control', 'payload'], 'Workroom event payload envelope');
|
|
661
|
+
const expectedId = `${runId}:${Number(row.sequence)}`;
|
|
662
|
+
if (row.id !== expectedId)
|
|
663
|
+
throw new Error('Workroom event row id binding is invalid');
|
|
664
|
+
if (String(row.payload_json) !== canonicalWorkroomJson(envelope)) {
|
|
665
|
+
throw new Error('Workroom event payload JSON is not canonical');
|
|
666
|
+
}
|
|
667
|
+
validateStoredEventControl(row.type, envelope.control);
|
|
668
|
+
validateProtectedPayload(row.type, envelope.payload);
|
|
669
|
+
const event = Object.freeze({
|
|
670
|
+
version: 3,
|
|
671
|
+
eventId: envelope.eventId,
|
|
672
|
+
runId,
|
|
673
|
+
sequence: row.sequence,
|
|
674
|
+
occurredAt: row.occurred_at,
|
|
675
|
+
type: row.type,
|
|
676
|
+
control: deepFreeze({ ...envelope.control }),
|
|
677
|
+
payload: Object.freeze({ ...envelope.payload }),
|
|
678
|
+
});
|
|
679
|
+
if (row.stored_event_digest !== digestStoredWorkroomEvent(event)) {
|
|
680
|
+
throw new Error('Workroom stored event digest mismatch');
|
|
681
|
+
}
|
|
682
|
+
if (row.row_binding_digest !== digestWorkroomEventRowBinding(row)) {
|
|
683
|
+
throw new Error('Workroom event row binding digest mismatch');
|
|
684
|
+
}
|
|
685
|
+
return event;
|
|
686
|
+
}).sort((left, right) => left.sequence - right.sequence);
|
|
687
|
+
const stored = Object.freeze(events);
|
|
688
|
+
if (stored.length > 0)
|
|
689
|
+
assertStoredEventReceiptBindings(stored);
|
|
690
|
+
return stored;
|
|
691
|
+
}
|
|
692
|
+
function parseStoredRowGroups(rows) {
|
|
693
|
+
const rowGroups = new Map();
|
|
694
|
+
for (const row of rows) {
|
|
695
|
+
const runId = String(row.run_id ?? '');
|
|
696
|
+
if (!isNonEmptyString(runId))
|
|
697
|
+
throw new Error('Invalid Workroom event Run id');
|
|
698
|
+
rowGroups.set(runId, [...(rowGroups.get(runId) ?? []), row]);
|
|
699
|
+
}
|
|
700
|
+
return new Map([...rowGroups.entries()]
|
|
701
|
+
.sort(([left], [right]) => compareCanonicalWorkroomText(left, right))
|
|
702
|
+
.map(([runId, runRows]) => [runId, parseStoredRows(runId, runRows)]));
|
|
703
|
+
}
|
|
704
|
+
export function digestStoredWorkroomEvent(event) {
|
|
705
|
+
return digestCanonicalWorkroomValue({
|
|
706
|
+
version: event.version,
|
|
707
|
+
eventId: event.eventId,
|
|
708
|
+
runId: event.runId,
|
|
709
|
+
sequence: event.sequence,
|
|
710
|
+
occurredAt: event.occurredAt,
|
|
711
|
+
type: event.type,
|
|
712
|
+
control: event.control,
|
|
713
|
+
payload: event.payload,
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
export function digestWorkroomEventRowBinding(row) {
|
|
717
|
+
return digestCanonicalWorkroomValue({
|
|
718
|
+
version: 1,
|
|
719
|
+
id: row.id,
|
|
720
|
+
runId: row.run_id,
|
|
721
|
+
sequence: row.sequence,
|
|
722
|
+
storedVersion: row.version,
|
|
723
|
+
type: row.type,
|
|
724
|
+
payloadJson: row.payload_json,
|
|
725
|
+
occurredAt: row.occurred_at,
|
|
726
|
+
storedEventDigest: row.stored_event_digest,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
function storedRunHeaders(runId, values) {
|
|
730
|
+
if (!isNonEmptyString(runId) || values.length === 0
|
|
731
|
+
|| values.some((event, index) => event.runId !== runId || event.sequence !== index)) {
|
|
732
|
+
throw new Error('Stored Workroom Journal header sequence or Run binding is invalid');
|
|
733
|
+
}
|
|
734
|
+
assertStoredEventReceiptBindings(values);
|
|
735
|
+
const events = values.map((event) => {
|
|
736
|
+
const protectedPayloadDigest = digestCanonicalWorkroomValue(event.payload);
|
|
737
|
+
const body = deepFreeze({
|
|
738
|
+
version: 1,
|
|
739
|
+
eventRef: `workroom-event:${digestCanonicalWorkroomValue({
|
|
740
|
+
runId, eventId: event.eventId, sequence: event.sequence,
|
|
741
|
+
})}`,
|
|
742
|
+
runId,
|
|
743
|
+
sequence: event.sequence,
|
|
744
|
+
occurredAt: event.occurredAt,
|
|
745
|
+
type: event.type,
|
|
746
|
+
control: event.control,
|
|
747
|
+
protectedPayloadDigest,
|
|
748
|
+
protectedReceipts: storedProtectedReceiptHeaders(event.payload),
|
|
749
|
+
});
|
|
750
|
+
return deepFreeze({ ...body, digest: digestCanonicalWorkroomValue(body) });
|
|
751
|
+
});
|
|
752
|
+
const body = deepFreeze({ version: 1, runId, events });
|
|
753
|
+
return deepFreeze({ ...body, digest: digestCanonicalWorkroomValue(body) });
|
|
754
|
+
}
|
|
755
|
+
function deriveStoredEventControl(event) {
|
|
756
|
+
const payload = event.payload;
|
|
757
|
+
const taskKey = () => opaqueStoredRef('task', event.runId, storedHeaderText(payload, 'taskKey'));
|
|
758
|
+
const assignmentId = () => opaqueStoredRef('assignment', event.runId, storedHeaderText(payload, 'assignmentId'));
|
|
759
|
+
switch (event.type) {
|
|
760
|
+
case 'run.created': return deepFreeze({ projectId: storedHeaderText(payload, 'projectId') });
|
|
761
|
+
case 'task.planned': return deepFreeze({
|
|
762
|
+
taskKey: taskKey(),
|
|
763
|
+
required: payload.required === true,
|
|
764
|
+
maxAttempts: storedHeaderPositiveInteger(payload, 'maxAttempts'),
|
|
765
|
+
});
|
|
766
|
+
case 'task.blocked':
|
|
767
|
+
case 'task.blocker_resolved': return deepFreeze({
|
|
768
|
+
taskKey: taskKey(),
|
|
769
|
+
blockerId: opaqueStoredRef('blocker', event.runId, storedHeaderText(payload, 'blockerId')),
|
|
770
|
+
});
|
|
771
|
+
case 'assignment.claimed': return deepFreeze({
|
|
772
|
+
taskKey: taskKey(),
|
|
773
|
+
assignmentId: assignmentId(),
|
|
774
|
+
role: storedHeaderRole(payload.role),
|
|
775
|
+
attempt: storedHeaderPositiveInteger(payload, 'attempt'),
|
|
776
|
+
assignmentRevision: storedHeaderPositiveInteger(payload, 'assignmentRevision'),
|
|
777
|
+
fence: storedHeaderPositiveInteger(payload, 'fence'),
|
|
778
|
+
});
|
|
779
|
+
case 'assignment.started':
|
|
780
|
+
case 'assignment.progress':
|
|
781
|
+
case 'assignment.heartbeat':
|
|
782
|
+
case 'assignment.checkpointed':
|
|
783
|
+
case 'assignment.checkpoint_requested':
|
|
784
|
+
case 'assignment.preempted':
|
|
785
|
+
case 'assignment.execution_completed':
|
|
786
|
+
case 'assignment.cancel_requested':
|
|
787
|
+
case 'assignment.lease_expired': return deepFreeze({ assignmentId: assignmentId() });
|
|
788
|
+
case 'assignment.cancelled': return deepFreeze({
|
|
789
|
+
assignmentId: assignmentId(), outcome: storedHeaderOutcome(payload.outcome),
|
|
790
|
+
});
|
|
791
|
+
case 'task.accepted':
|
|
792
|
+
case 'task.acceptance_pinned':
|
|
793
|
+
case 'task.acceptance_blocked':
|
|
794
|
+
case 'task.cancel_requested':
|
|
795
|
+
case 'task.cancelled':
|
|
796
|
+
case 'task.failed':
|
|
797
|
+
case 'task.rework_requested': return deepFreeze({ taskKey: taskKey() });
|
|
798
|
+
case 'task.revised': return deepFreeze({
|
|
799
|
+
taskKey: taskKey(), maxAttempts: storedHeaderPositiveInteger(payload, 'maxAttempts'),
|
|
800
|
+
});
|
|
801
|
+
case 'task.plan_revised': return deepFreeze({
|
|
802
|
+
taskKey: taskKey(), required: payload.required === true,
|
|
803
|
+
maxAttempts: storedHeaderPositiveInteger(payload, 'maxAttempts'),
|
|
804
|
+
newTaskRevision: storedHeaderPositiveInteger(payload, 'newTaskRevision'),
|
|
805
|
+
});
|
|
806
|
+
case 'reviewer.assigned': {
|
|
807
|
+
const assignment = storedHeaderRecord(payload, 'assignment');
|
|
808
|
+
return deepFreeze({
|
|
809
|
+
taskKey: taskKey(),
|
|
810
|
+
waitId: opaqueStoredRef('reviewer', event.runId, storedHeaderText(assignment, 'id')),
|
|
811
|
+
waitStatus: storedHeaderText(assignment, 'status'),
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
case 'reviewer.claimed':
|
|
815
|
+
case 'reviewer.verdict_recorded':
|
|
816
|
+
case 'reviewer.expired': return deepFreeze({
|
|
817
|
+
taskKey: taskKey(),
|
|
818
|
+
waitId: opaqueStoredRef('reviewer', event.runId, storedHeaderText(payload, 'assignmentId')),
|
|
819
|
+
...(event.type === 'reviewer.verdict_recorded'
|
|
820
|
+
? { verdictOutcome: payload.outcome === 'passed' ? 'passed' : 'rework' }
|
|
821
|
+
: {}),
|
|
822
|
+
});
|
|
823
|
+
case 'sponsor_gate.opened': {
|
|
824
|
+
const gate = storedHeaderRecord(payload, 'gate');
|
|
825
|
+
return deepFreeze({
|
|
826
|
+
taskKey: taskKey(),
|
|
827
|
+
waitId: opaqueStoredRef('sponsor-gate', event.runId, storedHeaderText(gate, 'id')),
|
|
828
|
+
waitStatus: storedHeaderText(gate, 'status'),
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
case 'sponsor_gate.decided': return deepFreeze({
|
|
832
|
+
taskKey: taskKey(),
|
|
833
|
+
waitId: opaqueStoredRef('sponsor-gate', event.runId, storedHeaderText(payload, 'gateId')),
|
|
834
|
+
decision: storedHeaderDecision(payload.decision),
|
|
835
|
+
});
|
|
836
|
+
case 'sponsor_gate.expired': return deepFreeze({
|
|
837
|
+
taskKey: taskKey(),
|
|
838
|
+
waitId: opaqueStoredRef('sponsor-gate', event.runId, storedHeaderText(payload, 'gateId')),
|
|
839
|
+
});
|
|
840
|
+
default: return Object.freeze({});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
const WORKROOM_EVENT_CONTROL_KEYS = Object.freeze({
|
|
844
|
+
'run.created': ['projectId'],
|
|
845
|
+
'task.planned': ['taskKey', 'required', 'maxAttempts'],
|
|
846
|
+
'task.blocked': ['taskKey', 'blockerId'],
|
|
847
|
+
'task.blocker_resolved': ['taskKey', 'blockerId'],
|
|
848
|
+
'assignment.claimed': [
|
|
849
|
+
'taskKey', 'assignmentId', 'role', 'attempt', 'assignmentRevision', 'fence',
|
|
850
|
+
],
|
|
851
|
+
'assignment.started': ['assignmentId'],
|
|
852
|
+
'assignment.progress': ['assignmentId'],
|
|
853
|
+
'assignment.heartbeat': ['assignmentId'],
|
|
854
|
+
'assignment.checkpointed': ['assignmentId'],
|
|
855
|
+
'assignment.checkpoint_requested': ['assignmentId'],
|
|
856
|
+
'assignment.preempted': ['assignmentId'],
|
|
857
|
+
'assignment.execution_completed': ['assignmentId'],
|
|
858
|
+
'assignment.cancel_requested': ['assignmentId'],
|
|
859
|
+
'assignment.cancelled': ['assignmentId', 'outcome'],
|
|
860
|
+
'assignment.lease_expired': ['assignmentId'],
|
|
861
|
+
'task.accepted': ['taskKey'],
|
|
862
|
+
'task.acceptance_pinned': ['taskKey'],
|
|
863
|
+
'task.acceptance_blocked': ['taskKey'],
|
|
864
|
+
'task.cancel_requested': ['taskKey'],
|
|
865
|
+
'task.cancelled': ['taskKey'],
|
|
866
|
+
'task.failed': ['taskKey'],
|
|
867
|
+
'task.rework_requested': ['taskKey'],
|
|
868
|
+
'task.revised': ['taskKey', 'maxAttempts'],
|
|
869
|
+
'task.plan_revised': ['taskKey', 'required', 'maxAttempts', 'newTaskRevision'],
|
|
870
|
+
'reviewer.assigned': ['taskKey', 'waitId', 'waitStatus'],
|
|
871
|
+
'reviewer.claimed': ['taskKey', 'waitId'],
|
|
872
|
+
'reviewer.verdict_recorded': ['taskKey', 'waitId', 'verdictOutcome'],
|
|
873
|
+
'reviewer.expired': ['taskKey', 'waitId'],
|
|
874
|
+
'sponsor_gate.opened': ['taskKey', 'waitId', 'waitStatus'],
|
|
875
|
+
'sponsor_gate.decided': ['taskKey', 'waitId', 'decision'],
|
|
876
|
+
'sponsor_gate.expired': ['taskKey', 'waitId'],
|
|
877
|
+
'plan.admitted': [],
|
|
878
|
+
'plan.revision_applied': [],
|
|
879
|
+
'plan_gate.decided': [],
|
|
880
|
+
'run.cancel_requested': [],
|
|
881
|
+
'run.cancelled': [],
|
|
882
|
+
'scheduler.dispatch_requested': [],
|
|
883
|
+
'scheduler.priority_changed': [],
|
|
884
|
+
'scheduler.preemption_requested': [],
|
|
885
|
+
'scheduler.preemption_checkpoint_acknowledged': [],
|
|
886
|
+
'scheduler.preemption_timed_out': [],
|
|
887
|
+
'local_execution.requested': [],
|
|
888
|
+
'remote_dispatch.requested': [],
|
|
889
|
+
'clock.advanced': [],
|
|
890
|
+
});
|
|
891
|
+
function validateStoredEventControl(type, control) {
|
|
892
|
+
assertExactRecordKeys(control, WORKROOM_EVENT_CONTROL_KEYS[type], 'Stored Workroom control');
|
|
893
|
+
if (control.projectId !== undefined)
|
|
894
|
+
storedHeaderText(control, 'projectId');
|
|
895
|
+
for (const key of ['taskKey', 'assignmentId', 'blockerId', 'waitId']) {
|
|
896
|
+
if (control[key] !== undefined && (typeof control[key] !== 'string'
|
|
897
|
+
|| !/^workroom-[a-z-]+:[a-f0-9]{64}$/u.test(control[key]))) {
|
|
898
|
+
throw new Error(`Stored Workroom control ${key} is invalid`);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
for (const key of ['maxAttempts', 'attempt', 'assignmentRevision', 'fence', 'newTaskRevision']) {
|
|
902
|
+
if (control[key] !== undefined)
|
|
903
|
+
storedHeaderPositiveInteger(control, key);
|
|
904
|
+
}
|
|
905
|
+
if (control.required !== undefined && typeof control.required !== 'boolean') {
|
|
906
|
+
throw new Error('Stored Workroom control required is invalid');
|
|
907
|
+
}
|
|
908
|
+
if (control.role !== undefined)
|
|
909
|
+
storedHeaderRole(control.role);
|
|
910
|
+
if (control.outcome !== undefined)
|
|
911
|
+
storedHeaderOutcome(control.outcome);
|
|
912
|
+
if (control.decision !== undefined)
|
|
913
|
+
storedHeaderDecision(control.decision);
|
|
914
|
+
if (control.verdictOutcome !== undefined
|
|
915
|
+
&& control.verdictOutcome !== 'passed' && control.verdictOutcome !== 'rework') {
|
|
916
|
+
throw new Error('Stored Workroom control verdict outcome is invalid');
|
|
917
|
+
}
|
|
918
|
+
if (control.waitStatus !== undefined && ![
|
|
919
|
+
'open', 'claimed', 'passed', 'rework', 'expired', 'cancelled', 'satisfied', 'stale',
|
|
920
|
+
].includes(String(control.waitStatus))) {
|
|
921
|
+
throw new Error('Stored Workroom control wait status is invalid');
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
function storedProtectedReceiptHeaders(value) {
|
|
925
|
+
const headers = [];
|
|
926
|
+
const visit = (candidate) => {
|
|
927
|
+
if (isGovernedJournalPayloadReference(candidate)) {
|
|
928
|
+
headers.push(deepFreeze({
|
|
929
|
+
fieldPath: candidate.fieldPath,
|
|
930
|
+
contentHash: candidate.contentHash,
|
|
931
|
+
descriptorDigest: candidate.receipt.descriptor.descriptorDigest,
|
|
932
|
+
sourceDigest: candidate.receipt.source.digest,
|
|
933
|
+
sourceBindingDigest: candidate.receipt.source.bindingDigest,
|
|
934
|
+
}));
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
if (Array.isArray(candidate)) {
|
|
938
|
+
for (const item of candidate)
|
|
939
|
+
visit(item);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (isRecord(candidate))
|
|
943
|
+
for (const item of Object.values(candidate))
|
|
944
|
+
visit(item);
|
|
945
|
+
};
|
|
946
|
+
visit(value);
|
|
947
|
+
return deepFreeze(headers.sort((left, right) => compareCanonicalWorkroomText(left.fieldPath, right.fieldPath)));
|
|
948
|
+
}
|
|
949
|
+
function opaqueStoredRef(kind, runId, rawId) {
|
|
950
|
+
return `workroom-${kind}:${digestCanonicalWorkroomValue({ kind, runId, rawId }).slice('sha256:'.length)}`;
|
|
951
|
+
}
|
|
952
|
+
function storedHeaderText(payload, key) {
|
|
953
|
+
const value = payload[key];
|
|
954
|
+
if (!isNonEmptyString(value))
|
|
955
|
+
throw new Error(`Stored Workroom header ${key} is invalid`);
|
|
956
|
+
return value;
|
|
957
|
+
}
|
|
958
|
+
function storedHeaderPositiveInteger(payload, key) {
|
|
959
|
+
const value = payload[key];
|
|
960
|
+
if (!Number.isSafeInteger(value) || Number(value) < 1) {
|
|
961
|
+
throw new Error(`Stored Workroom header ${key} is invalid`);
|
|
962
|
+
}
|
|
963
|
+
return Number(value);
|
|
964
|
+
}
|
|
965
|
+
function storedHeaderRecord(payload, key) {
|
|
966
|
+
const value = payload[key];
|
|
967
|
+
if (!isRecord(value))
|
|
968
|
+
throw new Error(`Stored Workroom header ${key} is invalid`);
|
|
969
|
+
return value;
|
|
970
|
+
}
|
|
971
|
+
function storedHeaderRole(value) {
|
|
972
|
+
if (value !== 'executor' && value !== 'reviewer' && value !== 'integration') {
|
|
973
|
+
throw new Error('Stored Workroom header Assignment role is invalid');
|
|
974
|
+
}
|
|
975
|
+
return value;
|
|
976
|
+
}
|
|
977
|
+
function storedHeaderOutcome(value) {
|
|
978
|
+
if (value !== 'interrupted' && value !== 'committed' && value !== 'outcome_unknown') {
|
|
979
|
+
throw new Error('Stored Workroom header Assignment outcome is invalid');
|
|
980
|
+
}
|
|
981
|
+
return value;
|
|
982
|
+
}
|
|
983
|
+
function storedHeaderDecision(value) {
|
|
984
|
+
if (value !== 'approve' && value !== 'reject' && value !== 'request_changes' && value !== 'cancel') {
|
|
985
|
+
throw new Error('Stored Workroom header Sponsor decision is invalid');
|
|
986
|
+
}
|
|
987
|
+
return value;
|
|
988
|
+
}
|
|
989
|
+
async function protectEvents(events, projectId, payloads) {
|
|
990
|
+
return Object.freeze(await Promise.all(events.map(async (event) => Object.freeze({
|
|
991
|
+
...event,
|
|
992
|
+
version: 3,
|
|
993
|
+
control: deriveStoredEventControl(event),
|
|
994
|
+
payload: await protectValue(event.payload, '$.payload', event, projectId, payloads),
|
|
995
|
+
}))));
|
|
996
|
+
}
|
|
997
|
+
async function protectValue(value, fieldPath, event, projectId, payloads) {
|
|
998
|
+
if (Array.isArray(value)) {
|
|
999
|
+
return Object.freeze(await Promise.all(value.map((item, index) => protectValue(item, `${fieldPath}[${index}]`, event, projectId, payloads))));
|
|
1000
|
+
}
|
|
1001
|
+
if (!isRecord(value))
|
|
1002
|
+
return value;
|
|
1003
|
+
const entries = [];
|
|
1004
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1005
|
+
const path = `${fieldPath}.${key}`;
|
|
1006
|
+
if (!isContentFreeJournalValue(event.type, path, child) && containsGovernedValue(child)) {
|
|
1007
|
+
const contentHash = digestCanonicalWorkroomValue(child);
|
|
1008
|
+
const source = journalPayloadSource(event, path, contentHash);
|
|
1009
|
+
const receipt = await payloads.write({
|
|
1010
|
+
projectId,
|
|
1011
|
+
runId: event.runId,
|
|
1012
|
+
eventId: event.eventId,
|
|
1013
|
+
eventType: event.type,
|
|
1014
|
+
fieldPath: path,
|
|
1015
|
+
value: structuredClone(child),
|
|
1016
|
+
contentHash,
|
|
1017
|
+
source,
|
|
1018
|
+
});
|
|
1019
|
+
assertJournalPayloadReceipt(receipt, createWorkroomJournalPayloadObjectId({
|
|
1020
|
+
projectId,
|
|
1021
|
+
runId: event.runId,
|
|
1022
|
+
eventId: event.eventId,
|
|
1023
|
+
eventType: event.type,
|
|
1024
|
+
fieldPath: path,
|
|
1025
|
+
contentHash,
|
|
1026
|
+
}), contentHash, source);
|
|
1027
|
+
entries.push([key, Object.freeze({
|
|
1028
|
+
version: 1,
|
|
1029
|
+
kind: 'governed_workroom_journal_payload',
|
|
1030
|
+
fieldPath: path,
|
|
1031
|
+
contentHash,
|
|
1032
|
+
receipt,
|
|
1033
|
+
})]);
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
entries.push([key, await protectValue(child, path, event, projectId, payloads)]);
|
|
1037
|
+
}
|
|
1038
|
+
return Object.freeze(Object.fromEntries(entries));
|
|
1039
|
+
}
|
|
1040
|
+
async function materializeStoredEvents(events, payloads) {
|
|
1041
|
+
assertStoredEventReceiptBindings(events);
|
|
1042
|
+
const projectId = storedProjectId(events);
|
|
1043
|
+
const materialized = await Promise.all(events.map(async (event) => {
|
|
1044
|
+
const payload = await materializeValue(event.payload, '$.payload', event, projectId, payloads);
|
|
1045
|
+
if (!isRecord(payload))
|
|
1046
|
+
throw new Error('Materialized Workroom Journal payload is invalid');
|
|
1047
|
+
validatePayload(event.type, payload, event.sequence);
|
|
1048
|
+
if (canonicalWorkroomJson(event.control)
|
|
1049
|
+
!== canonicalWorkroomJson(deriveStoredEventControl({ ...event, version: 1, payload }))) {
|
|
1050
|
+
throw new Error('Stored Workroom control projection does not match the governed payload');
|
|
1051
|
+
}
|
|
1052
|
+
const { control: _control, ...eventHeader } = event;
|
|
1053
|
+
return Object.freeze({
|
|
1054
|
+
...eventHeader,
|
|
1055
|
+
version: 1,
|
|
1056
|
+
payload: Object.freeze({ ...payload }),
|
|
1057
|
+
});
|
|
1058
|
+
}));
|
|
1059
|
+
return Object.freeze(materialized);
|
|
1060
|
+
}
|
|
1061
|
+
async function reconcileJournalPayloads(runId, events, payloads) {
|
|
1062
|
+
if (!payloads.reconcile || events.length === 0)
|
|
1063
|
+
return;
|
|
1064
|
+
await payloads.reconcile({
|
|
1065
|
+
projectId: storedProjectId(events),
|
|
1066
|
+
runId,
|
|
1067
|
+
receipts: collectGovernedPayloadReceipts(events),
|
|
1068
|
+
publicationDigest: journalPublicationDigest(runId, events),
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
function journalPublicationDigest(runId, events) {
|
|
1072
|
+
return digestCanonicalWorkroomValue({
|
|
1073
|
+
version: 1,
|
|
1074
|
+
runId,
|
|
1075
|
+
eventHeaders: events.map(event => ({
|
|
1076
|
+
eventId: event.eventId,
|
|
1077
|
+
sequence: event.sequence,
|
|
1078
|
+
type: event.type,
|
|
1079
|
+
control: event.control,
|
|
1080
|
+
payload: event.payload,
|
|
1081
|
+
})),
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function verifyJournalPayloadPublication(intent, events) {
|
|
1085
|
+
if (intent.consumer !== 'journal_header')
|
|
1086
|
+
return deepFreeze({ status: 'unknown' });
|
|
1087
|
+
const runId = intent.publicationScope;
|
|
1088
|
+
if (!runId || events.length === 0 || events.some(event => event.runId !== runId)) {
|
|
1089
|
+
return deepFreeze({ status: 'missing' });
|
|
1090
|
+
}
|
|
1091
|
+
const exact = collectGovernedPayloadReceipts(events).some(receipt => receipt.descriptor.objectId === intent.objectId
|
|
1092
|
+
&& receipt.descriptor.payloadHash === intent.payloadHash
|
|
1093
|
+
&& receipt.descriptor.descriptorDigest === intent.descriptorDigest
|
|
1094
|
+
&& receipt.source.bindingDigest === intent.sourceBindingDigest);
|
|
1095
|
+
return exact
|
|
1096
|
+
? deepFreeze({
|
|
1097
|
+
status: 'exact',
|
|
1098
|
+
publicationDigest: journalPublicationDigest(runId, events),
|
|
1099
|
+
})
|
|
1100
|
+
: deepFreeze({ status: 'missing' });
|
|
1101
|
+
}
|
|
1102
|
+
function collectGovernedPayloadReceipts(events) {
|
|
1103
|
+
const receipts = [];
|
|
1104
|
+
const visit = (value) => {
|
|
1105
|
+
if (isGovernedJournalPayloadReference(value)) {
|
|
1106
|
+
receipts.push(value.receipt);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
if (Array.isArray(value)) {
|
|
1110
|
+
for (const item of value)
|
|
1111
|
+
visit(item);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
if (isRecord(value)) {
|
|
1115
|
+
for (const item of Object.values(value))
|
|
1116
|
+
visit(item);
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
for (const event of events)
|
|
1120
|
+
visit(event.payload);
|
|
1121
|
+
return Object.freeze(receipts);
|
|
1122
|
+
}
|
|
1123
|
+
async function materializeValue(value, fieldPath, event, projectId, payloads) {
|
|
1124
|
+
if (isGovernedJournalPayloadReference(value)) {
|
|
1125
|
+
if (value.fieldPath !== fieldPath)
|
|
1126
|
+
throw new Error('Governed Workroom Journal payload field binding drift');
|
|
1127
|
+
const source = journalPayloadSource(event, fieldPath, value.contentHash);
|
|
1128
|
+
assertJournalPayloadReceipt(value.receipt, createWorkroomJournalPayloadObjectId({
|
|
1129
|
+
projectId,
|
|
1130
|
+
runId: event.runId,
|
|
1131
|
+
eventId: event.eventId,
|
|
1132
|
+
eventType: event.type,
|
|
1133
|
+
fieldPath,
|
|
1134
|
+
contentHash: value.contentHash,
|
|
1135
|
+
}), value.contentHash, source);
|
|
1136
|
+
const materialized = await payloads.read({
|
|
1137
|
+
projectId,
|
|
1138
|
+
runId: event.runId,
|
|
1139
|
+
eventId: event.eventId,
|
|
1140
|
+
eventType: event.type,
|
|
1141
|
+
fieldPath,
|
|
1142
|
+
contentHash: value.contentHash,
|
|
1143
|
+
receipt: value.receipt,
|
|
1144
|
+
purpose: 'kernel-replay',
|
|
1145
|
+
});
|
|
1146
|
+
if (digestCanonicalWorkroomValue(materialized) !== value.contentHash) {
|
|
1147
|
+
throw new Error('Governed Workroom Journal payload content hash mismatch');
|
|
1148
|
+
}
|
|
1149
|
+
if (Buffer.byteLength(canonicalWorkroomJson(materialized)) !== value.receipt.descriptor.bytes) {
|
|
1150
|
+
throw new Error('Governed Workroom Journal payload byte length mismatch');
|
|
1151
|
+
}
|
|
1152
|
+
return materialized;
|
|
1153
|
+
}
|
|
1154
|
+
if (Array.isArray(value)) {
|
|
1155
|
+
return Object.freeze(await Promise.all(value.map((item, index) => materializeValue(item, `${fieldPath}[${index}]`, event, projectId, payloads))));
|
|
1156
|
+
}
|
|
1157
|
+
if (!isRecord(value))
|
|
1158
|
+
return value;
|
|
1159
|
+
return Object.freeze(Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, child]) => [
|
|
1160
|
+
key,
|
|
1161
|
+
await materializeValue(child, `${fieldPath}.${key}`, event, projectId, payloads),
|
|
1162
|
+
]))));
|
|
1163
|
+
}
|
|
1164
|
+
function projectIdForAppend(current, appended) {
|
|
1165
|
+
if (current.length > 0)
|
|
1166
|
+
return storedProjectId(current);
|
|
1167
|
+
const created = appended[0];
|
|
1168
|
+
if (!created || created.type !== 'run.created' || !isNonEmptyString(created.payload.projectId)) {
|
|
1169
|
+
throw new Error('Workroom Journal first append must begin with a Project-bound run.created event');
|
|
1170
|
+
}
|
|
1171
|
+
return created.payload.projectId;
|
|
1172
|
+
}
|
|
1173
|
+
function storedProjectId(events) {
|
|
1174
|
+
const created = events[0];
|
|
1175
|
+
if (!created || created.type !== 'run.created' || !isNonEmptyString(created.payload.projectId)) {
|
|
1176
|
+
throw new Error('Stored Workroom Journal has no Project-bound run.created header');
|
|
1177
|
+
}
|
|
1178
|
+
return created.payload.projectId;
|
|
1179
|
+
}
|
|
1180
|
+
function journalPayloadSource(event, fieldPath, contentHash) {
|
|
1181
|
+
const ref = `workroom-journal-event:${event.runId}:${event.eventId}:${fieldPath}`;
|
|
1182
|
+
const sourceBody = Object.freeze({
|
|
1183
|
+
version: 1,
|
|
1184
|
+
runId: event.runId,
|
|
1185
|
+
eventId: event.eventId,
|
|
1186
|
+
eventType: event.type,
|
|
1187
|
+
fieldPath,
|
|
1188
|
+
contentHash,
|
|
1189
|
+
});
|
|
1190
|
+
const sourceDigest = digestCanonicalWorkroomValue(sourceBody);
|
|
1191
|
+
return Object.freeze({
|
|
1192
|
+
ref,
|
|
1193
|
+
digest: sourceDigest,
|
|
1194
|
+
bindingDigest: digestCanonicalWorkroomValue({ ref, sourceDigest, ...sourceBody }),
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
function assertJournalPayloadReceipt(receipt, objectId, contentHash, source) {
|
|
1198
|
+
if (!receipt || !isRecord(receipt.descriptor) || !isRecord(receipt.source)
|
|
1199
|
+
|| !isNonEmptyString(receipt.descriptor.vaultObjectId)
|
|
1200
|
+
|| receipt.descriptor.objectId !== objectId
|
|
1201
|
+
|| receipt.descriptor.payloadHash !== contentHash
|
|
1202
|
+
|| !isDigest(receipt.descriptor.descriptorDigest)
|
|
1203
|
+
|| !isDigest(receipt.descriptor.locationManifestDigest)
|
|
1204
|
+
|| !Number.isSafeInteger(receipt.descriptor.bytes) || Number(receipt.descriptor.bytes) < 0
|
|
1205
|
+
|| receipt.source.kind !== 'command'
|
|
1206
|
+
|| receipt.source.ref !== source.ref
|
|
1207
|
+
|| receipt.source.digest !== source.digest
|
|
1208
|
+
|| receipt.source.bindingDigest !== source.bindingDigest
|
|
1209
|
+
|| receipt.source.verification !== 'verified') {
|
|
1210
|
+
throw new Error('Governed Workroom Journal payload receipt is forged or incomplete');
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
function assertStoredEventReceiptBindings(events) {
|
|
1214
|
+
if (events.length === 0)
|
|
1215
|
+
return;
|
|
1216
|
+
const projectId = storedProjectId(events);
|
|
1217
|
+
const visit = (value, fieldPath, event) => {
|
|
1218
|
+
if (isGovernedJournalPayloadReference(value)) {
|
|
1219
|
+
if (value.fieldPath !== fieldPath) {
|
|
1220
|
+
throw new Error('Governed Workroom Journal payload field binding drift');
|
|
1221
|
+
}
|
|
1222
|
+
const source = journalPayloadSource(event, fieldPath, value.contentHash);
|
|
1223
|
+
assertJournalPayloadReceipt(value.receipt, createWorkroomJournalPayloadObjectId({
|
|
1224
|
+
projectId,
|
|
1225
|
+
runId: event.runId,
|
|
1226
|
+
eventId: event.eventId,
|
|
1227
|
+
eventType: event.type,
|
|
1228
|
+
fieldPath,
|
|
1229
|
+
contentHash: value.contentHash,
|
|
1230
|
+
}), value.contentHash, source);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
if (Array.isArray(value)) {
|
|
1234
|
+
value.forEach((item, index) => visit(item, `${fieldPath}[${index}]`, event));
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
if (isRecord(value)) {
|
|
1238
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1239
|
+
visit(child, `${fieldPath}.${key}`, event);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
for (const event of events)
|
|
1244
|
+
visit(event.payload, '$.payload', event);
|
|
1245
|
+
}
|
|
1246
|
+
export function createWorkroomJournalPayloadObjectId(input) {
|
|
1247
|
+
return `workroom-journal-payload:${digestCanonicalWorkroomValue({
|
|
1248
|
+
projectId: input.projectId,
|
|
1249
|
+
runId: input.runId,
|
|
1250
|
+
eventId: input.eventId,
|
|
1251
|
+
eventType: input.eventType,
|
|
1252
|
+
fieldPath: input.fieldPath,
|
|
1253
|
+
contentHash: input.contentHash,
|
|
1254
|
+
})}`;
|
|
1255
|
+
}
|
|
1256
|
+
function isGovernedJournalPayloadReference(value) {
|
|
1257
|
+
if (!isRecord(value) || value.version !== 1 || value.kind !== 'governed_workroom_journal_payload'
|
|
1258
|
+
|| !isNonEmptyString(value.fieldPath) || !isDigest(value.contentHash)
|
|
1259
|
+
|| !isRecord(value.receipt))
|
|
1260
|
+
return false;
|
|
1261
|
+
const keys = Object.keys(value).sort();
|
|
1262
|
+
return keys.length === 5
|
|
1263
|
+
&& ['contentHash', 'fieldPath', 'kind', 'receipt', 'version'].every((key, index) => keys[index] === key);
|
|
1264
|
+
}
|
|
1265
|
+
function validateProtectedPayload(type, payload) {
|
|
1266
|
+
assertAllowedPayloadKeys(type, payload);
|
|
1267
|
+
const visit = (value, fieldPath) => {
|
|
1268
|
+
if (isGovernedJournalPayloadReference(value)) {
|
|
1269
|
+
if (value.fieldPath !== fieldPath)
|
|
1270
|
+
throw new Error('Governed Workroom Journal payload path is invalid');
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
if (Array.isArray(value)) {
|
|
1274
|
+
value.forEach((item, index) => visit(item, `${fieldPath}[${index}]`));
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
if (!isRecord(value))
|
|
1278
|
+
return;
|
|
1279
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1280
|
+
if (!isContentFreeJournalValue(type, `${fieldPath}.${key}`, child) && containsGovernedValue(child)
|
|
1281
|
+
&& !isGovernedJournalPayloadReference(child)) {
|
|
1282
|
+
throw legacyJournalPayloadError();
|
|
1283
|
+
}
|
|
1284
|
+
visit(child, `${fieldPath}.${key}`);
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
visit(payload, '$.payload');
|
|
1288
|
+
}
|
|
1289
|
+
function isContentFreeJournalValue(type, fieldPath, value) {
|
|
1290
|
+
if (value === undefined || value === null || value === '')
|
|
1291
|
+
return true;
|
|
1292
|
+
if (typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value)))
|
|
1293
|
+
return true;
|
|
1294
|
+
if (typeof value !== 'string')
|
|
1295
|
+
return false;
|
|
1296
|
+
if (type === 'run.created' && fieldPath === '$.payload.projectId')
|
|
1297
|
+
return true;
|
|
1298
|
+
return isDigest(value);
|
|
1299
|
+
}
|
|
1300
|
+
function containsGovernedValue(value) {
|
|
1301
|
+
if (value === undefined || value === null || value === '')
|
|
1302
|
+
return false;
|
|
1303
|
+
if (Array.isArray(value))
|
|
1304
|
+
return value.length > 0;
|
|
1305
|
+
return typeof value !== 'object' || Object.keys(value).length > 0;
|
|
1306
|
+
}
|
|
1307
|
+
function legacyJournalPayloadError() {
|
|
1308
|
+
return new LegacyEmbeddedPayloadDetectedError('Legacy embedded Workroom Journal payload is quarantined; use offline export/purge verification before activation');
|
|
1309
|
+
}
|
|
1310
|
+
function isDigest(value) {
|
|
1311
|
+
return typeof value === 'string' && /^sha256:[a-f0-9]{64}$/u.test(value);
|
|
1312
|
+
}
|
|
1313
|
+
const WORKROOM_EVENT_TYPES = new Set([
|
|
1314
|
+
'run.created', 'run.cancel_requested', 'run.cancelled', 'plan.admitted', 'plan_gate.decided',
|
|
1315
|
+
'plan.revision_applied',
|
|
1316
|
+
'task.planned', 'task.blocked', 'task.blocker_resolved',
|
|
1317
|
+
'task.cancel_requested', 'task.cancelled', 'task.failed',
|
|
1318
|
+
'task.accepted', 'task.acceptance_pinned', 'task.acceptance_blocked', 'task.rework_requested', 'task.revised',
|
|
1319
|
+
'task.plan_revised',
|
|
1320
|
+
'reviewer.assigned', 'reviewer.claimed', 'reviewer.verdict_recorded', 'reviewer.expired',
|
|
1321
|
+
'sponsor_gate.opened', 'sponsor_gate.decided', 'sponsor_gate.expired',
|
|
1322
|
+
'assignment.claimed', 'assignment.started', 'assignment.heartbeat',
|
|
1323
|
+
'assignment.progress', 'assignment.checkpointed',
|
|
1324
|
+
'assignment.checkpoint_requested', 'assignment.preempted',
|
|
1325
|
+
'assignment.execution_completed', 'assignment.cancel_requested',
|
|
1326
|
+
'assignment.cancelled', 'assignment.lease_expired',
|
|
1327
|
+
'scheduler.dispatch_requested', 'scheduler.priority_changed', 'scheduler.preemption_requested',
|
|
1328
|
+
'scheduler.preemption_checkpoint_acknowledged', 'scheduler.preemption_timed_out',
|
|
1329
|
+
'local_execution.requested',
|
|
1330
|
+
'remote_dispatch.requested', 'clock.advanced',
|
|
1331
|
+
]);
|
|
1332
|
+
function isWorkroomEventType(value) {
|
|
1333
|
+
return typeof value === 'string' && WORKROOM_EVENT_TYPES.has(value);
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Closed top-level schema for every persisted Kernel fact. Values not listed
|
|
1337
|
+
* here are rejected before either the Journal header or Payload Vault is
|
|
1338
|
+
* written, so adding a future field requires an explicit governance choice.
|
|
1339
|
+
*/
|
|
1340
|
+
const WORKROOM_EVENT_PAYLOAD_KEYS = Object.freeze({
|
|
1341
|
+
'run.created': ['projectId', 'title'],
|
|
1342
|
+
'run.cancel_requested': ['reason'],
|
|
1343
|
+
'run.cancelled': ['reason'],
|
|
1344
|
+
'plan.admitted': [
|
|
1345
|
+
'operationId', 'sourceEventRef', 'sourceEventDigest', 'orchestratorAgentDefinitionId',
|
|
1346
|
+
'plan', 'schedulerPolicy',
|
|
1347
|
+
],
|
|
1348
|
+
'plan.revision_applied': ['candidate', 'planRevision', 'recomputedDiffDigest'],
|
|
1349
|
+
'plan_gate.decided': [
|
|
1350
|
+
'operationId', 'requestDigest', 'taskKey', 'taskRevision', 'gateId', 'planDigest',
|
|
1351
|
+
'policyRevisionId', 'policyDigest', 'decision', 'sponsorPrincipalId', 'authorizedBy',
|
|
1352
|
+
'reasonDigest',
|
|
1353
|
+
],
|
|
1354
|
+
'task.planned': [
|
|
1355
|
+
'type', 'taskKey', 'title', 'required', 'maxAttempts', 'role', 'dependsOn', 'requires',
|
|
1356
|
+
'sponsorLane', 'localRank', 'deadline', 'enqueuedAt', 'preemptibility', 'approvalGate',
|
|
1357
|
+
],
|
|
1358
|
+
'task.blocked': [
|
|
1359
|
+
'type', 'taskKey', 'blockerId', 'kind', 'owner', 'reason', 'deadline', 'allowedActions',
|
|
1360
|
+
],
|
|
1361
|
+
'task.blocker_resolved': ['type', 'taskKey', 'blockerId'],
|
|
1362
|
+
'task.cancel_requested': ['taskKey', 'reason'],
|
|
1363
|
+
'task.cancelled': ['taskKey', 'reason'],
|
|
1364
|
+
'task.failed': ['taskKey', 'reason'],
|
|
1365
|
+
'task.accepted': ['taskKey', 'reportRef', 'record'],
|
|
1366
|
+
'task.acceptance_pinned': ['taskKey', 'contract'],
|
|
1367
|
+
'task.acceptance_blocked': ['taskKey', 'reportRef', 'reason', 'evaluation'],
|
|
1368
|
+
'task.rework_requested': ['type', 'taskKey', 'reason', 'evaluation'],
|
|
1369
|
+
'task.revised': ['type', 'taskKey', 'title', 'reason', 'maxAttempts'],
|
|
1370
|
+
'task.plan_revised': [
|
|
1371
|
+
'taskKey', 'title', 'required', 'maxAttempts', 'role', 'dependsOn', 'requires',
|
|
1372
|
+
'sponsorLane', 'localRank', 'deadline', 'enqueuedAt', 'preemptibility', 'approvalGate',
|
|
1373
|
+
'expectedTaskRevision', 'newTaskRevision', 'reason',
|
|
1374
|
+
],
|
|
1375
|
+
'reviewer.assigned': ['taskKey', 'reason', 'assignment'],
|
|
1376
|
+
'reviewer.claimed': [
|
|
1377
|
+
'taskKey', 'assignmentId', 'reviewerPrincipalId', 'authorizedBy', 'authorization',
|
|
1378
|
+
],
|
|
1379
|
+
'reviewer.verdict_recorded': [
|
|
1380
|
+
'taskKey', 'assignmentId', 'reviewerPrincipalId', 'authorizedBy', 'outcome',
|
|
1381
|
+
'verdict', 'authorization',
|
|
1382
|
+
],
|
|
1383
|
+
'reviewer.expired': ['taskKey', 'assignmentId'],
|
|
1384
|
+
'sponsor_gate.opened': ['taskKey', 'reason', 'gate'],
|
|
1385
|
+
'sponsor_gate.decided': [
|
|
1386
|
+
'taskKey', 'gateId', 'sponsorPrincipalId', 'authorizedBy', 'reason', 'candidateHash',
|
|
1387
|
+
'decision', 'authorization',
|
|
1388
|
+
],
|
|
1389
|
+
'sponsor_gate.expired': ['taskKey', 'gateId'],
|
|
1390
|
+
'assignment.claimed': [
|
|
1391
|
+
'type', 'taskKey', 'assignmentId', 'owner', 'role', 'taskRevision', 'attempt',
|
|
1392
|
+
'assignmentRevision', 'fence', 'envelopeDigest', 'leaseExpiresAt',
|
|
1393
|
+
],
|
|
1394
|
+
'assignment.started': ['assignmentId'],
|
|
1395
|
+
'assignment.progress': [
|
|
1396
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest', 'progress',
|
|
1397
|
+
],
|
|
1398
|
+
'assignment.heartbeat': [
|
|
1399
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest', 'leaseExpiresAt',
|
|
1400
|
+
],
|
|
1401
|
+
'assignment.checkpointed': [
|
|
1402
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest',
|
|
1403
|
+
'checkpointRef', 'checkpointDigest',
|
|
1404
|
+
],
|
|
1405
|
+
'assignment.checkpoint_requested': [
|
|
1406
|
+
'decisionId', 'assignmentId', 'envelopeDigest', 'reservedTaskKey', 'requestedAt',
|
|
1407
|
+
'deadline', 'takeoverFence', 'owner', 'allowedSuccessors',
|
|
1408
|
+
],
|
|
1409
|
+
'assignment.preempted': [
|
|
1410
|
+
'decisionId', 'assignmentId', 'checkpointRef', 'checkpointDigest', 'outcome',
|
|
1411
|
+
],
|
|
1412
|
+
'assignment.execution_completed': [
|
|
1413
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest', 'reportRef',
|
|
1414
|
+
'reportDigest', 'candidateRef', 'candidateHash', 'completionReceiptDigest',
|
|
1415
|
+
],
|
|
1416
|
+
'assignment.cancel_requested': ['assignmentId', 'controlDeadline'],
|
|
1417
|
+
'assignment.cancelled': ['assignmentId', 'outcome'],
|
|
1418
|
+
'assignment.lease_expired': ['assignmentId'],
|
|
1419
|
+
'scheduler.dispatch_requested': [
|
|
1420
|
+
'version', 'type', 'decisionId', 'digest', 'projectId', 'runId', 'expectedSequence',
|
|
1421
|
+
'taskKey', 'taskRevision', 'role', 'sponsorLane', 'reason', 'policy',
|
|
1422
|
+
],
|
|
1423
|
+
'scheduler.priority_changed': [
|
|
1424
|
+
'version', 'type', 'proposalId', 'digest', 'projectId', 'runId', 'taskKey',
|
|
1425
|
+
'taskRevision', 'expectedSequence', 'currentLane', 'requestedLane', 'localRank',
|
|
1426
|
+
'principalId', 'authority', 'authorityRef', 'deadline', 'owner', 'allowedSuccessors',
|
|
1427
|
+
'authorizedBy',
|
|
1428
|
+
],
|
|
1429
|
+
'scheduler.preemption_requested': [
|
|
1430
|
+
'version', 'type', 'decisionId', 'digest', 'projectId', 'runId', 'expectedSequence',
|
|
1431
|
+
'victimTaskKey', 'victimTaskRevision', 'reservedTaskKey', 'reservedTaskRevision',
|
|
1432
|
+
'assignmentId', 'assignmentAttempt', 'assignmentFence', 'assignmentEnvelopeDigest',
|
|
1433
|
+
'owner', 'requestedAt', 'deadline', 'takeoverFence', 'reason', 'allowedSuccessors', 'policy',
|
|
1434
|
+
],
|
|
1435
|
+
'scheduler.preemption_checkpoint_acknowledged': [
|
|
1436
|
+
'decisionId', 'assignmentId', 'envelopeDigest', 'observationId', 'observationDigest',
|
|
1437
|
+
'checkpointRef', 'checkpointDigest', 'assignmentAttempt', 'assignmentFence', 'takeoverFence',
|
|
1438
|
+
],
|
|
1439
|
+
'scheduler.preemption_timed_out': [
|
|
1440
|
+
'decisionId', 'assignmentId', 'reservedTaskKey', 'blockerId', 'owner', 'deadline',
|
|
1441
|
+
'allowedSuccessors', 'reason',
|
|
1442
|
+
],
|
|
1443
|
+
'local_execution.requested': [
|
|
1444
|
+
'operationId', 'requestDigest', 'agentDefinitionId', 'issuedAt', 'envelope',
|
|
1445
|
+
],
|
|
1446
|
+
'remote_dispatch.requested': [
|
|
1447
|
+
'operationId', 'requestDigest', 'issuedAt', 'reconcileDeadline', 'envelope', 'dispatchItem',
|
|
1448
|
+
],
|
|
1449
|
+
'clock.advanced': ['now'],
|
|
1450
|
+
});
|
|
1451
|
+
function assertAllowedPayloadKeys(type, payload) {
|
|
1452
|
+
const allowed = WORKROOM_EVENT_PAYLOAD_KEYS[type];
|
|
1453
|
+
if (Object.keys(payload).some(key => !allowed.includes(key))) {
|
|
1454
|
+
throw new Error(`Invalid Workroom event payload keys: ${type}`);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
function validatePayload(type, payload, sequence) {
|
|
1458
|
+
assertAllowedPayloadKeys(type, payload);
|
|
1459
|
+
switch (type) {
|
|
1460
|
+
case 'run.created':
|
|
1461
|
+
requirePayloadString(payload, 'projectId');
|
|
1462
|
+
requirePayloadString(payload, 'title');
|
|
1463
|
+
return;
|
|
1464
|
+
case 'plan.admitted':
|
|
1465
|
+
requirePayloadString(payload, 'operationId');
|
|
1466
|
+
requirePayloadString(payload, 'sourceEventRef');
|
|
1467
|
+
requirePayloadDigest(payload, 'sourceEventDigest');
|
|
1468
|
+
requirePayloadString(payload, 'orchestratorAgentDefinitionId');
|
|
1469
|
+
assertWorkflowPlanProposal(requirePayloadRecord(payload, 'plan'));
|
|
1470
|
+
if (payload.schedulerPolicy !== undefined) {
|
|
1471
|
+
assertWorkroomSchedulerPolicySnapshot(payload.schedulerPolicy, sequence);
|
|
1472
|
+
}
|
|
1473
|
+
return;
|
|
1474
|
+
case 'plan.revision_applied': {
|
|
1475
|
+
const candidate = requirePayloadRecord(payload, 'candidate');
|
|
1476
|
+
assertWorkflowPlanRevisionCandidate(candidate);
|
|
1477
|
+
requirePayloadPositiveInteger(payload, 'planRevision');
|
|
1478
|
+
requirePayloadDigest(payload, 'recomputedDiffDigest');
|
|
1479
|
+
if (payload.recomputedDiffDigest !== digestCanonicalWorkroomValue(candidate.diff)) {
|
|
1480
|
+
throw new Error('Persisted Plan Revision recomputed diff digest is invalid');
|
|
1481
|
+
}
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
case 'plan_gate.decided':
|
|
1485
|
+
requirePayloadString(payload, 'operationId');
|
|
1486
|
+
requirePayloadDigest(payload, 'requestDigest');
|
|
1487
|
+
requirePayloadString(payload, 'taskKey');
|
|
1488
|
+
requirePayloadPositiveInteger(payload, 'taskRevision');
|
|
1489
|
+
requirePayloadString(payload, 'gateId');
|
|
1490
|
+
requirePayloadDigest(payload, 'planDigest');
|
|
1491
|
+
requirePayloadString(payload, 'policyRevisionId');
|
|
1492
|
+
requirePayloadDigest(payload, 'policyDigest');
|
|
1493
|
+
requirePayloadEnum(payload, 'decision', ['approve', 'reject', 'request_changes', 'cancel']);
|
|
1494
|
+
requirePayloadString(payload, 'sponsorPrincipalId');
|
|
1495
|
+
requirePayloadString(payload, 'authorizedBy');
|
|
1496
|
+
requirePayloadDigest(payload, 'reasonDigest');
|
|
1497
|
+
return;
|
|
1498
|
+
case 'local_execution.requested':
|
|
1499
|
+
parseWorkroomLocalAssignmentIssuance(payload);
|
|
1500
|
+
return;
|
|
1501
|
+
case 'remote_dispatch.requested':
|
|
1502
|
+
parseWorkroomRemoteAssignmentIssuance(payload);
|
|
1503
|
+
return;
|
|
1504
|
+
case 'scheduler.dispatch_requested':
|
|
1505
|
+
parseWorkroomDispatchTaskDecision(payload);
|
|
1506
|
+
return;
|
|
1507
|
+
case 'scheduler.priority_changed':
|
|
1508
|
+
requirePayloadString(payload, 'proposalId');
|
|
1509
|
+
requirePayloadDigest(payload, 'digest');
|
|
1510
|
+
requirePayloadString(payload, 'projectId');
|
|
1511
|
+
requirePayloadString(payload, 'runId');
|
|
1512
|
+
requirePayloadString(payload, 'taskKey');
|
|
1513
|
+
requirePayloadPositiveInteger(payload, 'taskRevision');
|
|
1514
|
+
requirePayloadEnum(payload, 'currentLane', ['urgent', 'high', 'normal', 'low']);
|
|
1515
|
+
requirePayloadEnum(payload, 'requestedLane', ['urgent', 'high', 'normal', 'low']);
|
|
1516
|
+
requirePayloadEnum(payload, 'authority', ['sponsor', 'orchestrator']);
|
|
1517
|
+
requirePayloadString(payload, 'principalId');
|
|
1518
|
+
requirePayloadString(payload, 'authorityRef');
|
|
1519
|
+
requirePayloadString(payload, 'owner');
|
|
1520
|
+
requirePayloadNumber(payload, 'deadline');
|
|
1521
|
+
requirePayloadString(payload, 'authorizedBy');
|
|
1522
|
+
parseWorkroomPriorityChangeProposal({
|
|
1523
|
+
version: payload.version,
|
|
1524
|
+
type: payload.type,
|
|
1525
|
+
proposalId: payload.proposalId,
|
|
1526
|
+
digest: payload.digest,
|
|
1527
|
+
projectId: payload.projectId,
|
|
1528
|
+
runId: payload.runId,
|
|
1529
|
+
taskKey: payload.taskKey,
|
|
1530
|
+
taskRevision: payload.taskRevision,
|
|
1531
|
+
expectedSequence: payload.expectedSequence,
|
|
1532
|
+
currentLane: payload.currentLane,
|
|
1533
|
+
requestedLane: payload.requestedLane,
|
|
1534
|
+
localRank: payload.localRank,
|
|
1535
|
+
principalId: payload.principalId,
|
|
1536
|
+
authority: payload.authority,
|
|
1537
|
+
authorityRef: payload.authorityRef,
|
|
1538
|
+
deadline: payload.deadline,
|
|
1539
|
+
owner: payload.owner,
|
|
1540
|
+
allowedSuccessors: payload.allowedSuccessors,
|
|
1541
|
+
});
|
|
1542
|
+
if (payload.authorizedBy !== payload.authorityRef) {
|
|
1543
|
+
throw new Error('Persisted Workroom priority authority proof is not exact');
|
|
1544
|
+
}
|
|
1545
|
+
return;
|
|
1546
|
+
case 'scheduler.preemption_requested':
|
|
1547
|
+
parseWorkroomPreemptionPrepareDecision(payload);
|
|
1548
|
+
return;
|
|
1549
|
+
case 'scheduler.preemption_checkpoint_acknowledged':
|
|
1550
|
+
requirePayloadString(payload, 'decisionId');
|
|
1551
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1552
|
+
requirePayloadDigest(payload, 'envelopeDigest');
|
|
1553
|
+
requirePayloadString(payload, 'observationId');
|
|
1554
|
+
requirePayloadDigest(payload, 'observationDigest');
|
|
1555
|
+
requirePayloadString(payload, 'checkpointRef');
|
|
1556
|
+
requirePayloadDigest(payload, 'checkpointDigest');
|
|
1557
|
+
requirePayloadPositiveInteger(payload, 'assignmentAttempt');
|
|
1558
|
+
requirePayloadPositiveInteger(payload, 'assignmentFence');
|
|
1559
|
+
requirePayloadPositiveInteger(payload, 'takeoverFence');
|
|
1560
|
+
if (payload.takeoverFence !== Number(payload.assignmentFence) + 1) {
|
|
1561
|
+
throw new Error('Invalid Workroom event payload: preemption takeover fence');
|
|
1562
|
+
}
|
|
1563
|
+
return;
|
|
1564
|
+
case 'scheduler.preemption_timed_out':
|
|
1565
|
+
requirePayloadString(payload, 'decisionId');
|
|
1566
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1567
|
+
requirePayloadString(payload, 'reservedTaskKey');
|
|
1568
|
+
requirePayloadString(payload, 'blockerId');
|
|
1569
|
+
requirePayloadString(payload, 'owner');
|
|
1570
|
+
requirePayloadNumber(payload, 'deadline');
|
|
1571
|
+
requirePayloadString(payload, 'reason');
|
|
1572
|
+
if (canonicalWorkroomJson(payload.allowedSuccessors) !== canonicalWorkroomJson(['replan', 'cancel_run'])) {
|
|
1573
|
+
throw new Error('Invalid Workroom event payload: preemption timeout successors');
|
|
1574
|
+
}
|
|
1575
|
+
return;
|
|
1576
|
+
case 'run.cancel_requested':
|
|
1577
|
+
case 'run.cancelled':
|
|
1578
|
+
requirePayloadString(payload, 'reason');
|
|
1579
|
+
return;
|
|
1580
|
+
case 'task.planned':
|
|
1581
|
+
requirePayloadString(payload, 'taskKey');
|
|
1582
|
+
requirePayloadString(payload, 'title');
|
|
1583
|
+
requirePayloadBoolean(payload, 'required');
|
|
1584
|
+
requirePayloadPositiveInteger(payload, 'maxAttempts');
|
|
1585
|
+
if (payload.approvalGate !== undefined) {
|
|
1586
|
+
const gate = requirePayloadRecord(payload, 'approvalGate');
|
|
1587
|
+
requirePayloadString(gate, 'id');
|
|
1588
|
+
requirePayloadEnum(gate, 'kind', ['sponsor']);
|
|
1589
|
+
requirePayloadString(gate, 'owner');
|
|
1590
|
+
requirePayloadPositiveInteger(gate, 'decisionTimeoutMs');
|
|
1591
|
+
requirePayloadString(gate, 'policyRevisionId');
|
|
1592
|
+
requirePayloadDigest(gate, 'policyDigest');
|
|
1593
|
+
if (!Array.isArray(gate.allowedActions)
|
|
1594
|
+
|| canonicalWorkroomJson(gate.allowedActions) !== canonicalWorkroomJson(['approve', 'reject', 'replan', 'cancel'])) {
|
|
1595
|
+
throw new Error('Invalid Workroom event payload: approvalGate allowedActions');
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return;
|
|
1599
|
+
case 'task.blocked':
|
|
1600
|
+
requirePayloadString(payload, 'taskKey');
|
|
1601
|
+
requirePayloadString(payload, 'blockerId');
|
|
1602
|
+
requirePayloadEnum(payload, 'kind', ['dependency', 'approval', 'capability', 'external', 'human_input']);
|
|
1603
|
+
requirePayloadString(payload, 'owner');
|
|
1604
|
+
requirePayloadString(payload, 'reason');
|
|
1605
|
+
requirePayloadNumber(payload, 'deadline');
|
|
1606
|
+
return;
|
|
1607
|
+
case 'task.blocker_resolved':
|
|
1608
|
+
requirePayloadString(payload, 'taskKey');
|
|
1609
|
+
requirePayloadString(payload, 'blockerId');
|
|
1610
|
+
return;
|
|
1611
|
+
case 'task.cancel_requested':
|
|
1612
|
+
case 'task.cancelled':
|
|
1613
|
+
case 'task.failed':
|
|
1614
|
+
requirePayloadString(payload, 'taskKey');
|
|
1615
|
+
requirePayloadString(payload, 'reason');
|
|
1616
|
+
return;
|
|
1617
|
+
case 'task.accepted':
|
|
1618
|
+
requirePayloadString(payload, 'taskKey');
|
|
1619
|
+
requirePayloadString(payload, 'reportRef');
|
|
1620
|
+
assertPersistedAcceptanceRecord(payload.record, String(payload.taskKey), String(payload.reportRef), sequence);
|
|
1621
|
+
return;
|
|
1622
|
+
case 'task.acceptance_pinned': {
|
|
1623
|
+
requirePayloadString(payload, 'taskKey');
|
|
1624
|
+
const contract = requirePayloadRecord(payload, 'contract');
|
|
1625
|
+
assertAcceptanceContract(contract, String(payload.taskKey), Number(contract.taskRevision));
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
1628
|
+
case 'task.acceptance_blocked':
|
|
1629
|
+
requirePayloadString(payload, 'taskKey');
|
|
1630
|
+
requirePayloadString(payload, 'reportRef');
|
|
1631
|
+
requirePayloadString(payload, 'reason');
|
|
1632
|
+
requirePayloadRecord(payload, 'evaluation');
|
|
1633
|
+
return;
|
|
1634
|
+
case 'reviewer.assigned':
|
|
1635
|
+
requirePayloadString(payload, 'taskKey');
|
|
1636
|
+
requirePayloadString(payload, 'reason');
|
|
1637
|
+
validateAcceptanceWait(requirePayloadRecord(payload, 'assignment'), String(payload.taskKey), true);
|
|
1638
|
+
return;
|
|
1639
|
+
case 'reviewer.expired':
|
|
1640
|
+
requirePayloadString(payload, 'taskKey');
|
|
1641
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1642
|
+
return;
|
|
1643
|
+
case 'reviewer.claimed':
|
|
1644
|
+
requirePayloadString(payload, 'taskKey');
|
|
1645
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1646
|
+
requirePayloadString(payload, 'reviewerPrincipalId');
|
|
1647
|
+
requirePayloadString(payload, 'authorizedBy');
|
|
1648
|
+
requirePayloadRecord(payload, 'authorization');
|
|
1649
|
+
return;
|
|
1650
|
+
case 'reviewer.verdict_recorded':
|
|
1651
|
+
requirePayloadString(payload, 'taskKey');
|
|
1652
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1653
|
+
requirePayloadEnum(payload, 'outcome', ['passed', 'rework']);
|
|
1654
|
+
requirePayloadRecord(payload, 'verdict');
|
|
1655
|
+
requirePayloadRecord(payload, 'authorization');
|
|
1656
|
+
return;
|
|
1657
|
+
case 'sponsor_gate.opened':
|
|
1658
|
+
requirePayloadString(payload, 'taskKey');
|
|
1659
|
+
requirePayloadString(payload, 'reason');
|
|
1660
|
+
validateAcceptanceWait(requirePayloadRecord(payload, 'gate'), String(payload.taskKey), false);
|
|
1661
|
+
return;
|
|
1662
|
+
case 'sponsor_gate.expired':
|
|
1663
|
+
requirePayloadString(payload, 'taskKey');
|
|
1664
|
+
requirePayloadString(payload, 'gateId');
|
|
1665
|
+
return;
|
|
1666
|
+
case 'sponsor_gate.decided':
|
|
1667
|
+
requirePayloadString(payload, 'taskKey');
|
|
1668
|
+
requirePayloadString(payload, 'gateId');
|
|
1669
|
+
requirePayloadString(payload, 'sponsorPrincipalId');
|
|
1670
|
+
requirePayloadString(payload, 'authorizedBy');
|
|
1671
|
+
requirePayloadString(payload, 'reason');
|
|
1672
|
+
requirePayloadString(payload, 'candidateHash');
|
|
1673
|
+
requirePayloadEnum(payload, 'decision', ['approve', 'reject', 'request_changes', 'cancel']);
|
|
1674
|
+
requirePayloadRecord(payload, 'authorization');
|
|
1675
|
+
return;
|
|
1676
|
+
case 'task.rework_requested':
|
|
1677
|
+
requirePayloadString(payload, 'taskKey');
|
|
1678
|
+
requirePayloadString(payload, 'reason');
|
|
1679
|
+
return;
|
|
1680
|
+
case 'task.revised':
|
|
1681
|
+
requirePayloadString(payload, 'taskKey');
|
|
1682
|
+
requirePayloadString(payload, 'title');
|
|
1683
|
+
requirePayloadString(payload, 'reason');
|
|
1684
|
+
requirePayloadPositiveInteger(payload, 'maxAttempts');
|
|
1685
|
+
return;
|
|
1686
|
+
case 'task.plan_revised':
|
|
1687
|
+
requirePayloadString(payload, 'taskKey');
|
|
1688
|
+
requirePayloadPositiveInteger(payload, 'expectedTaskRevision');
|
|
1689
|
+
requirePayloadPositiveInteger(payload, 'newTaskRevision');
|
|
1690
|
+
requirePayloadString(payload, 'title');
|
|
1691
|
+
requirePayloadBoolean(payload, 'required');
|
|
1692
|
+
requirePayloadPositiveInteger(payload, 'maxAttempts');
|
|
1693
|
+
requirePayloadString(payload, 'role');
|
|
1694
|
+
requirePayloadString(payload, 'reason');
|
|
1695
|
+
return;
|
|
1696
|
+
case 'assignment.claimed':
|
|
1697
|
+
requirePayloadString(payload, 'taskKey');
|
|
1698
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1699
|
+
requirePayloadString(payload, 'owner');
|
|
1700
|
+
requirePayloadEnum(payload, 'role', ['executor', 'reviewer', 'integration']);
|
|
1701
|
+
requirePayloadPositiveInteger(payload, 'taskRevision');
|
|
1702
|
+
requirePayloadPositiveInteger(payload, 'attempt');
|
|
1703
|
+
requirePayloadPositiveInteger(payload, 'assignmentRevision');
|
|
1704
|
+
requirePayloadPositiveInteger(payload, 'fence');
|
|
1705
|
+
requirePayloadDigest(payload, 'envelopeDigest');
|
|
1706
|
+
requirePayloadNumber(payload, 'leaseExpiresAt');
|
|
1707
|
+
return;
|
|
1708
|
+
case 'assignment.started':
|
|
1709
|
+
case 'assignment.lease_expired':
|
|
1710
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1711
|
+
return;
|
|
1712
|
+
case 'assignment.progress':
|
|
1713
|
+
validateAssignmentObservationHeader(payload);
|
|
1714
|
+
assertExactPayloadKeys(payload, [
|
|
1715
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest', 'progress',
|
|
1716
|
+
], type);
|
|
1717
|
+
validateProgress(requirePayloadRecord(payload, 'progress'));
|
|
1718
|
+
assertPersistedAssignmentObservationDigest(payload, {
|
|
1719
|
+
version: 1,
|
|
1720
|
+
type: 'progress',
|
|
1721
|
+
observationId: payload.observationId,
|
|
1722
|
+
envelopeDigest: payload.envelopeDigest,
|
|
1723
|
+
progress: payload.progress,
|
|
1724
|
+
});
|
|
1725
|
+
return;
|
|
1726
|
+
case 'assignment.heartbeat':
|
|
1727
|
+
validateAssignmentObservationHeader(payload);
|
|
1728
|
+
assertExactPayloadKeys(payload, [
|
|
1729
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest', 'leaseExpiresAt',
|
|
1730
|
+
], type);
|
|
1731
|
+
requirePayloadNumber(payload, 'leaseExpiresAt');
|
|
1732
|
+
assertPersistedAssignmentObservationDigest(payload, {
|
|
1733
|
+
version: 1,
|
|
1734
|
+
type: 'heartbeat',
|
|
1735
|
+
observationId: payload.observationId,
|
|
1736
|
+
envelopeDigest: payload.envelopeDigest,
|
|
1737
|
+
});
|
|
1738
|
+
return;
|
|
1739
|
+
case 'assignment.checkpointed':
|
|
1740
|
+
validateAssignmentObservationHeader(payload);
|
|
1741
|
+
assertExactPayloadKeys(payload, [
|
|
1742
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest',
|
|
1743
|
+
'checkpointRef', 'checkpointDigest',
|
|
1744
|
+
], type);
|
|
1745
|
+
requirePayloadString(payload, 'checkpointRef');
|
|
1746
|
+
requirePayloadDigest(payload, 'checkpointDigest');
|
|
1747
|
+
assertPersistedAssignmentObservationDigest(payload, {
|
|
1748
|
+
version: 1,
|
|
1749
|
+
type: 'checkpoint',
|
|
1750
|
+
observationId: payload.observationId,
|
|
1751
|
+
envelopeDigest: payload.envelopeDigest,
|
|
1752
|
+
checkpoint: { ref: payload.checkpointRef, digest: payload.checkpointDigest },
|
|
1753
|
+
});
|
|
1754
|
+
return;
|
|
1755
|
+
case 'assignment.checkpoint_requested':
|
|
1756
|
+
requirePayloadString(payload, 'decisionId');
|
|
1757
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1758
|
+
requirePayloadDigest(payload, 'envelopeDigest');
|
|
1759
|
+
requirePayloadString(payload, 'reservedTaskKey');
|
|
1760
|
+
requirePayloadNumber(payload, 'requestedAt');
|
|
1761
|
+
requirePayloadNumber(payload, 'deadline');
|
|
1762
|
+
requirePayloadPositiveInteger(payload, 'takeoverFence');
|
|
1763
|
+
requirePayloadString(payload, 'owner');
|
|
1764
|
+
if (Number(payload.deadline) <= Number(payload.requestedAt)
|
|
1765
|
+
|| canonicalWorkroomJson(payload.allowedSuccessors) !== canonicalWorkroomJson(['replan', 'cancel_run'])) {
|
|
1766
|
+
throw new Error('Invalid Workroom event payload: checkpoint request recovery metadata');
|
|
1767
|
+
}
|
|
1768
|
+
return;
|
|
1769
|
+
case 'assignment.preempted':
|
|
1770
|
+
requirePayloadString(payload, 'decisionId');
|
|
1771
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1772
|
+
requirePayloadString(payload, 'checkpointRef');
|
|
1773
|
+
requirePayloadDigest(payload, 'checkpointDigest');
|
|
1774
|
+
requirePayloadEnum(payload, 'outcome', ['interrupted']);
|
|
1775
|
+
return;
|
|
1776
|
+
case 'assignment.execution_completed':
|
|
1777
|
+
validateAssignmentObservationHeader(payload);
|
|
1778
|
+
assertExactPayloadKeys(payload, [
|
|
1779
|
+
'assignmentId', 'observationId', 'observationDigest', 'envelopeDigest',
|
|
1780
|
+
'reportRef', 'reportDigest', 'candidateRef', 'candidateHash',
|
|
1781
|
+
...(payload.completionReceiptDigest === undefined
|
|
1782
|
+
? []
|
|
1783
|
+
: ['completionReceiptDigest']),
|
|
1784
|
+
], type);
|
|
1785
|
+
requirePayloadString(payload, 'reportRef');
|
|
1786
|
+
requirePayloadDigest(payload, 'reportDigest');
|
|
1787
|
+
requirePayloadString(payload, 'candidateRef');
|
|
1788
|
+
requirePayloadDigest(payload, 'candidateHash');
|
|
1789
|
+
if (payload.completionReceiptDigest !== undefined) {
|
|
1790
|
+
requirePayloadDigest(payload, 'completionReceiptDigest');
|
|
1791
|
+
}
|
|
1792
|
+
assertPersistedAssignmentObservationDigest(payload, {
|
|
1793
|
+
version: 1,
|
|
1794
|
+
type: 'execution_completed',
|
|
1795
|
+
observationId: payload.observationId,
|
|
1796
|
+
envelopeDigest: payload.envelopeDigest,
|
|
1797
|
+
completion: {
|
|
1798
|
+
report: { ref: payload.reportRef, digest: payload.reportDigest },
|
|
1799
|
+
candidate: { ref: payload.candidateRef, hash: payload.candidateHash },
|
|
1800
|
+
...(payload.completionReceiptDigest === undefined
|
|
1801
|
+
? {}
|
|
1802
|
+
: { completionReceiptDigest: payload.completionReceiptDigest }),
|
|
1803
|
+
},
|
|
1804
|
+
});
|
|
1805
|
+
return;
|
|
1806
|
+
case 'assignment.cancel_requested':
|
|
1807
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1808
|
+
requirePayloadNumber(payload, 'controlDeadline');
|
|
1809
|
+
return;
|
|
1810
|
+
case 'assignment.cancelled':
|
|
1811
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1812
|
+
requirePayloadEnum(payload, 'outcome', ['interrupted', 'committed', 'outcome_unknown']);
|
|
1813
|
+
return;
|
|
1814
|
+
case 'clock.advanced':
|
|
1815
|
+
requirePayloadNumber(payload, 'now');
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
function validateAssignmentObservationHeader(payload) {
|
|
1820
|
+
requirePayloadString(payload, 'assignmentId');
|
|
1821
|
+
requirePayloadString(payload, 'observationId');
|
|
1822
|
+
requirePayloadDigest(payload, 'observationDigest');
|
|
1823
|
+
requirePayloadDigest(payload, 'envelopeDigest');
|
|
1824
|
+
}
|
|
1825
|
+
function assertPersistedAssignmentObservationDigest(payload, observation) {
|
|
1826
|
+
if (digestCanonicalWorkroomValue(observation) !== payload.observationDigest) {
|
|
1827
|
+
throw new Error('Invalid Workroom event payload: observationDigest does not match body');
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
function validateProgress(progress) {
|
|
1831
|
+
const keys = Object.keys(progress);
|
|
1832
|
+
if (keys.some(key => !['summary', 'completedUnits', 'totalUnits'].includes(key))) {
|
|
1833
|
+
throw new Error('Invalid Workroom event payload: progress keys');
|
|
1834
|
+
}
|
|
1835
|
+
requirePayloadString(progress, 'summary');
|
|
1836
|
+
const completed = progress.completedUnits;
|
|
1837
|
+
const total = progress.totalUnits;
|
|
1838
|
+
if (completed !== undefined && (!Number.isSafeInteger(completed) || completed < 0)) {
|
|
1839
|
+
throw new Error('Invalid Workroom event payload: completedUnits');
|
|
1840
|
+
}
|
|
1841
|
+
if (total !== undefined && (!Number.isSafeInteger(total) || total < 1)) {
|
|
1842
|
+
throw new Error('Invalid Workroom event payload: totalUnits');
|
|
1843
|
+
}
|
|
1844
|
+
if (typeof completed === 'number' && typeof total === 'number' && completed > total) {
|
|
1845
|
+
throw new Error('Invalid Workroom event payload: completedUnits exceeds totalUnits');
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
function assertExactPayloadKeys(payload, expected, type) {
|
|
1849
|
+
const actual = Object.keys(payload).sort();
|
|
1850
|
+
const canonical = [...expected].sort();
|
|
1851
|
+
if (actual.length !== canonical.length || actual.some((key, index) => key !== canonical[index])) {
|
|
1852
|
+
throw new Error(`Invalid Workroom event payload keys: ${type}`);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
function assertExactRecordKeys(value, expected, label) {
|
|
1856
|
+
const actual = Object.keys(value).sort();
|
|
1857
|
+
const canonical = [...expected].sort();
|
|
1858
|
+
if (actual.length !== canonical.length || actual.some((key, index) => key !== canonical[index])) {
|
|
1859
|
+
throw new Error(`${label} keys are invalid`);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
function validateAcceptanceWait(value, taskKey, reviewer) {
|
|
1863
|
+
for (const key of ['id', 'taskKey', 'candidateHash', 'contractId', 'owner']) {
|
|
1864
|
+
requirePayloadString(value, key);
|
|
1865
|
+
}
|
|
1866
|
+
requirePayloadPositiveInteger(value, 'taskRevision');
|
|
1867
|
+
requirePayloadEnum(value, 'riskTier', ['low', 'medium', 'high', 'critical']);
|
|
1868
|
+
requirePayloadEnum(value, 'route', ['reviewer_required', 'sponsor_required', 'reviewer_then_sponsor']);
|
|
1869
|
+
if (value.taskKey !== taskKey)
|
|
1870
|
+
throw new Error('Invalid Workroom event payload: wait taskKey');
|
|
1871
|
+
requirePayloadNumber(value, 'deadline');
|
|
1872
|
+
requirePayloadEnum(value, 'status', ['open']);
|
|
1873
|
+
requirePayloadRecord(value, 'evaluation');
|
|
1874
|
+
const policy = requirePayloadRecord(value, 'policy');
|
|
1875
|
+
requirePayloadString(policy, 'id');
|
|
1876
|
+
requirePayloadString(policy, 'digest');
|
|
1877
|
+
requirePayloadPositiveInteger(policy, 'revision');
|
|
1878
|
+
if (reviewer)
|
|
1879
|
+
requirePayloadString(value, 'producerPrincipalId');
|
|
1880
|
+
if (!Array.isArray(value.allowedActions) || value.allowedActions.length === 0
|
|
1881
|
+
|| value.allowedActions.some(action => !isNonEmptyString(action)
|
|
1882
|
+
|| !ACCEPTANCE_WAIT_ACTIONS.has(action))) {
|
|
1883
|
+
throw new Error('Invalid Workroom event payload: allowedActions');
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
const ACCEPTANCE_WAIT_ACTIONS = new Set([
|
|
1887
|
+
'claim', 'submit_verdict', 'approve', 'reject', 'request_changes',
|
|
1888
|
+
'reassign', 'reopen', 'rebase', 'replan', 'cancel',
|
|
1889
|
+
]);
|
|
1890
|
+
function isRecord(value) {
|
|
1891
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
1892
|
+
}
|
|
1893
|
+
function isNonEmptyString(value) {
|
|
1894
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
1895
|
+
}
|
|
1896
|
+
function isFiniteNumber(value) {
|
|
1897
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
1898
|
+
}
|
|
1899
|
+
function isSequence(value) {
|
|
1900
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
1901
|
+
}
|
|
1902
|
+
function requirePayloadString(payload, key) {
|
|
1903
|
+
if (!isNonEmptyString(payload[key]))
|
|
1904
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1905
|
+
}
|
|
1906
|
+
function requirePayloadNumber(payload, key) {
|
|
1907
|
+
if (!isFiniteNumber(payload[key]))
|
|
1908
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1909
|
+
}
|
|
1910
|
+
function requirePayloadDigest(payload, key) {
|
|
1911
|
+
if (typeof payload[key] !== 'string' || !/^sha256:[a-f0-9]{64}$/u.test(payload[key])) {
|
|
1912
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
function requirePayloadRecord(payload, key) {
|
|
1916
|
+
if (!isRecord(payload[key]))
|
|
1917
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1918
|
+
return payload[key];
|
|
1919
|
+
}
|
|
1920
|
+
function requirePayloadPositiveInteger(payload, key) {
|
|
1921
|
+
const value = payload[key];
|
|
1922
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
1923
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
function requirePayloadBoolean(payload, key) {
|
|
1927
|
+
if (typeof payload[key] !== 'boolean')
|
|
1928
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1929
|
+
}
|
|
1930
|
+
function requirePayloadEnum(payload, key, values) {
|
|
1931
|
+
if (typeof payload[key] !== 'string' || !values.includes(payload[key])) {
|
|
1932
|
+
throw new Error(`Invalid Workroom event payload: ${key}`);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
//# sourceMappingURL=journal.js.map
|