@abot-ai/runtime 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/src/bridge/request-steering.d.ts +2 -1
- package/dist/src/bridge/request-steering.js +4 -2
- package/dist/src/bridge/runtime-replay.js +2 -19
- package/dist/src/bridge/start-agent-bridge.js +1 -1
- package/dist/src/capabilities/normal-invocation/validator.js +1 -1
- package/dist/src/capabilities/tool-definition-validator/event-presentation.js +3 -0
- package/dist/src/capabilities/tool-definition-validator/event-result-metadata.d.ts +2 -0
- package/dist/src/capabilities/tool-definition-validator/event-result-metadata.js +74 -0
- package/dist/src/capabilities/tool-event-metadata.js +3 -0
- package/dist/src/capabilities/tool-result-event-projection.d.ts +3 -0
- package/dist/src/capabilities/tool-result-event-projection.js +82 -0
- package/dist/src/capabilities/tool-types.d.ts +5 -0
- package/dist/src/cli/abot.js +2 -11
- package/dist/src/runtime/adapters/in-memory-session-store.js +1 -0
- package/dist/src/runtime/adapters/long-term-memory/file-lock/acquisition.js +11 -2
- package/dist/src/runtime/adapters/long-term-memory/file-lock/contracts.d.ts +2 -0
- package/dist/src/runtime/adapters/long-term-memory/file-lock/synchronous-release.d.ts +2 -0
- package/dist/src/runtime/adapters/long-term-memory/file-lock/synchronous-release.js +40 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/approval.d.ts +3 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/approval.js +9 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/rejection-event.d.ts +13 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/rejection-event.js +25 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/run.js +18 -2
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/executor.js +8 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/payload/lifecycle.js +7 -3
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/contracts.d.ts +17 -2
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/event-metadata.d.ts +9 -0
- package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/event-metadata.js +8 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.js +16 -1
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-observability.js +2 -2
- package/dist/src/runtime/adapters/scheduled-request-outcome.d.ts +11 -0
- package/dist/src/runtime/adapters/scheduled-request-outcome.js +41 -0
- package/dist/src/runtime/adapters/scheduler-runtime.d.ts +19 -0
- package/dist/src/runtime/adapters/scheduler-runtime.js +138 -0
- package/dist/src/runtime/capabilities/scheduling/create-operations.d.ts +55 -0
- package/dist/src/runtime/capabilities/scheduling/create-operations.js +30 -0
- package/dist/src/runtime/capabilities/scheduling/create-time-zone.d.ts +1 -0
- package/dist/src/runtime/capabilities/scheduling/create-time-zone.js +11 -0
- package/dist/src/runtime/capabilities/scheduling/job-list-page.d.ts +25 -0
- package/dist/src/runtime/capabilities/scheduling/job-list-page.js +40 -0
- package/dist/src/runtime/capabilities/scheduling/model-validation.d.ts +2 -0
- package/dist/src/runtime/capabilities/scheduling/model-validation.js +15 -0
- package/dist/src/runtime/capabilities/scheduling/tool-contract.d.ts +2 -0
- package/dist/src/runtime/capabilities/scheduling/tool-contract.js +35 -0
- package/dist/src/runtime/capabilities/scheduling/tool-input-properties.d.ts +43 -0
- package/dist/src/runtime/capabilities/scheduling/tool-input-properties.js +27 -0
- package/dist/src/runtime/capabilities/scheduling/tool-module.d.ts +4 -0
- package/dist/src/runtime/capabilities/scheduling/tool-module.js +158 -0
- package/dist/src/runtime/capabilities/scheduling/update-operations.d.ts +2 -0
- package/dist/src/runtime/capabilities/scheduling/update-operations.js +49 -0
- package/dist/src/runtime/composition.d.ts +23 -3
- package/dist/src/runtime/composition.js +12 -17
- package/dist/src/runtime/config/environment-paths.d.ts +10 -0
- package/dist/src/runtime/config/environment-paths.js +31 -0
- package/dist/src/runtime/config/environment-storage.d.ts +9 -0
- package/dist/src/runtime/config/environment-storage.js +65 -0
- package/dist/src/runtime/config/fields.js +7 -0
- package/dist/src/runtime/config/long-term-memory.js +15 -0
- package/dist/src/runtime/config/schema.js +8 -0
- package/dist/src/runtime/config.js +9 -5
- package/dist/src/runtime/context/scheduled-execution-context.d.ts +10 -0
- package/dist/src/runtime/context/scheduled-execution-context.js +52 -0
- package/dist/src/runtime/default-adapters.d.ts +3 -32
- package/dist/src/runtime/default-adapters.js +3 -270
- package/dist/src/runtime/default-environment-adapters.d.ts +19 -0
- package/dist/src/runtime/default-environment-adapters.js +144 -0
- package/dist/src/runtime/index.d.ts +5 -0
- package/dist/src/runtime/index.js +4 -0
- package/dist/src/runtime/local-application.d.ts +22 -0
- package/dist/src/runtime/local-application.js +81 -0
- package/dist/src/runtime/local-host/app-memory-dispatch.d.ts +11 -0
- package/dist/src/runtime/local-host/app-memory-dispatch.js +103 -0
- package/dist/src/runtime/local-host/app-owner.d.ts +4 -0
- package/dist/src/runtime/local-host/app-owner.js +119 -0
- package/dist/src/runtime/local-host/app-request-control.d.ts +24 -0
- package/dist/src/runtime/local-host/app-request-control.js +135 -0
- package/dist/src/runtime/local-host/app-service-dispatch.d.ts +5 -0
- package/dist/src/runtime/local-host/app-service-dispatch.js +64 -0
- package/dist/src/runtime/local-host/client-identity.d.ts +3 -0
- package/dist/src/runtime/local-host/client-identity.js +17 -0
- package/dist/src/runtime/local-host/client-memory.d.ts +7 -0
- package/dist/src/runtime/local-host/client-memory.js +54 -0
- package/dist/src/runtime/local-host/client-requests.d.ts +19 -0
- package/dist/src/runtime/local-host/client-requests.js +145 -0
- package/dist/src/runtime/local-host/client-services.d.ts +10 -0
- package/dist/src/runtime/local-host/client-services.js +14 -0
- package/dist/src/runtime/local-host/contracts.d.ts +36 -0
- package/dist/src/runtime/local-host/contracts.js +1 -0
- package/dist/src/runtime/local-host/endpoint.d.ts +7 -0
- package/dist/src/runtime/local-host/endpoint.js +79 -0
- package/dist/src/runtime/local-host/owner-activity.d.ts +10 -0
- package/dist/src/runtime/local-host/owner-activity.js +30 -0
- package/dist/src/runtime/local-host/owner-retirement.d.ts +3 -0
- package/dist/src/runtime/local-host/owner-retirement.js +15 -0
- package/dist/src/runtime/local-host/owner-server.d.ts +6 -0
- package/dist/src/runtime/local-host/owner-server.js +88 -0
- package/dist/src/runtime/local-host/private-access.d.ts +2 -0
- package/dist/src/runtime/local-host/private-access.js +16 -0
- package/dist/src/runtime/local-host/private-directory.d.ts +1 -0
- package/dist/src/runtime/local-host/private-directory.js +57 -0
- package/dist/src/runtime/local-host/rpc-peer.d.ts +22 -0
- package/dist/src/runtime/local-host/rpc-peer.js +168 -0
- package/dist/src/runtime/local-host/rpc-protocol.d.ts +21 -0
- package/dist/src/runtime/local-host/rpc-protocol.js +46 -0
- package/dist/src/runtime/local-host/startup-connection.d.ts +5 -0
- package/dist/src/runtime/local-host/startup-connection.js +72 -0
- package/dist/src/runtime/local-host/transport.d.ts +3 -0
- package/dist/src/runtime/local-host/transport.js +88 -0
- package/dist/src/runtime/local-host/windows-private-access.d.ts +1 -0
- package/dist/src/runtime/local-host/windows-private-access.js +51 -0
- package/dist/src/runtime/long-term-memory/onboarding/configuration.js +6 -0
- package/dist/src/runtime/long-term-memory/recall-binding.d.ts +3 -0
- package/dist/src/runtime/long-term-memory/recall-binding.js +27 -0
- package/dist/src/runtime/long-term-memory/recall-context.d.ts +20 -0
- package/dist/src/runtime/long-term-memory/recall-context.js +101 -0
- package/dist/src/runtime/long-term-memory/recall-continuation.d.ts +8 -0
- package/dist/src/runtime/long-term-memory/recall-continuation.js +36 -0
- package/dist/src/runtime/long-term-memory/recall-policy.d.ts +7 -0
- package/dist/src/runtime/long-term-memory/recall-policy.js +14 -0
- package/dist/src/runtime/long-term-memory/recall-result.d.ts +5 -0
- package/dist/src/runtime/long-term-memory/recall-result.js +54 -0
- package/dist/src/runtime/long-term-memory/repository-state.d.ts +2 -1
- package/dist/src/runtime/long-term-memory/repository-state.js +2 -2
- package/dist/src/runtime/model/invoke-raw-step.d.ts +1 -0
- package/dist/src/runtime/model/invoke-raw-step.js +1 -0
- package/dist/src/runtime/model/invoke-step.js +6 -0
- package/dist/src/runtime/model/invoke-structured-step.d.ts +1 -0
- package/dist/src/runtime/model/invoke-structured-step.js +1 -0
- package/dist/src/runtime/model/model-step-port.d.ts +2 -0
- package/dist/src/runtime/model/model-step-steering.d.ts +8 -0
- package/dist/src/runtime/model/model-step-steering.js +19 -0
- package/dist/src/runtime/orchestration/final-response/authoring-contract.js +1 -1
- package/dist/src/runtime/orchestration/final-response/invoke.d.ts +1 -0
- package/dist/src/runtime/orchestration/final-response/invoke.js +1 -0
- package/dist/src/runtime/orchestration/role-calls/activation-budget.js +1 -0
- package/dist/src/runtime/orchestration/role-calls/candidate-validation.js +9 -49
- package/dist/src/runtime/orchestration/role-calls/capability-selection-reconsideration.d.ts +9 -0
- package/dist/src/runtime/orchestration/role-calls/capability-selection-reconsideration.js +17 -8
- package/dist/src/runtime/orchestration/role-calls/capability-selection-supervision-validation.d.ts +2 -0
- package/dist/src/runtime/orchestration/role-calls/capability-selection-supervision-validation.js +62 -0
- package/dist/src/runtime/orchestration/role-calls/command-decoder.js +4 -0
- package/dist/src/runtime/orchestration/role-calls/command-dispatch/memory-recall-transitions.d.ts +4 -0
- package/dist/src/runtime/orchestration/role-calls/command-dispatch/memory-recall-transitions.js +89 -0
- package/dist/src/runtime/orchestration/role-calls/command-dispatch.js +5 -0
- package/dist/src/runtime/orchestration/role-calls/contracts.d.ts +9 -7
- package/dist/src/runtime/orchestration/role-calls/contracts.js +2 -2
- package/dist/src/runtime/orchestration/role-calls/diagnostics.js +3 -0
- package/dist/src/runtime/orchestration/role-calls/index.d.ts +1 -0
- package/dist/src/runtime/orchestration/role-calls/index.js +1 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-contract.d.ts +51 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-contract.js +4 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-decoder.d.ts +6 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-decoder.js +147 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-diagnostics.d.ts +5 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-diagnostics.js +27 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-state-validation.d.ts +3 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-state-validation.js +121 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-transactions.d.ts +3 -0
- package/dist/src/runtime/orchestration/role-calls/memory-recall-transactions.js +44 -0
- package/dist/src/runtime/orchestration/role-calls/reducer.js +1 -0
- package/dist/src/runtime/orchestration/role-calls/transaction-effect.d.ts +5 -0
- package/dist/src/runtime/orchestration/role-calls/transaction-effect.js +14 -0
- package/dist/src/runtime/orchestration/role-calls/transactions.js +3 -24
- package/dist/src/runtime/plugins/manifest-validator.js +4 -1
- package/dist/src/runtime/ports.d.ts +4 -0
- package/dist/src/runtime/request/bound-runtime-handler.d.ts +2 -0
- package/dist/src/runtime/request/bound-runtime-handler.js +25 -0
- package/dist/src/runtime/request/contracts.d.ts +6 -0
- package/dist/src/runtime/request/execution-agent-root-execution.js +12 -0
- package/dist/src/runtime/request/execution-facets.js +6 -0
- package/dist/src/runtime/request/execution-scope-surfaces.js +10 -0
- package/dist/src/runtime/request/execution-scope.d.ts +1 -1
- package/dist/src/runtime/request/handler.js +6 -0
- package/dist/src/runtime/request/root-contract.d.ts +7 -1
- package/dist/src/runtime/request/root-execution-kernel.js +33 -37
- package/dist/src/runtime/request/root-memory-recall.d.ts +11 -0
- package/dist/src/runtime/request/root-memory-recall.js +71 -0
- package/dist/src/runtime/request/root-observation-handoff.d.ts +17 -0
- package/dist/src/runtime/request/root-observation-handoff.js +44 -0
- package/dist/src/runtime/request/scheduled-execution.d.ts +9 -0
- package/dist/src/runtime/request/scheduled-execution.js +32 -0
- package/dist/src/runtime/request/session-admission.d.ts +17 -0
- package/dist/src/runtime/request/session-admission.js +88 -0
- package/dist/src/runtime/request/supervisor-root-execution-diagnostics.d.ts +1 -1
- package/dist/src/runtime/request/supervisor-root-execution.js +8 -0
- package/dist/src/runtime/runtime-environment.d.ts +31 -0
- package/dist/src/runtime/runtime-environment.js +102 -0
- package/dist/src/runtime/runtime-host-environment.d.ts +8 -0
- package/dist/src/runtime/runtime-host-environment.js +57 -0
- package/dist/src/runtime/runtime-host-lifecycle.d.ts +4 -0
- package/dist/src/runtime/runtime-host-lifecycle.js +64 -0
- package/dist/src/runtime/runtime-host-scheduler-ownership.d.ts +5 -0
- package/dist/src/runtime/runtime-host-scheduler-ownership.js +67 -0
- package/dist/src/runtime/runtime-host.d.ts +19 -0
- package/dist/src/runtime/runtime-host.js +63 -0
- package/dist/src/runtime/scheduler/calendar-time.d.ts +10 -0
- package/dist/src/runtime/scheduler/calendar-time.js +58 -0
- package/dist/src/runtime/scheduler/contracts.d.ts +143 -0
- package/dist/src/runtime/scheduler/contracts.js +1 -0
- package/dist/src/runtime/scheduler/file-store.d.ts +2 -0
- package/dist/src/runtime/scheduler/file-store.js +76 -0
- package/dist/src/runtime/scheduler/instant-validation.d.ts +4 -0
- package/dist/src/runtime/scheduler/instant-validation.js +69 -0
- package/dist/src/runtime/scheduler/interval-range.d.ts +8 -0
- package/dist/src/runtime/scheduler/interval-range.js +24 -0
- package/dist/src/runtime/scheduler/job-management.d.ts +8 -0
- package/dist/src/runtime/scheduler/job-management.js +212 -0
- package/dist/src/runtime/scheduler/journal-checkpoint.d.ts +9 -0
- package/dist/src/runtime/scheduler/journal-checkpoint.js +45 -0
- package/dist/src/runtime/scheduler/journal-durability.d.ts +8 -0
- package/dist/src/runtime/scheduler/journal-durability.js +59 -0
- package/dist/src/runtime/scheduler/journal-files.d.ts +14 -0
- package/dist/src/runtime/scheduler/journal-files.js +59 -0
- package/dist/src/runtime/scheduler/journal-head.d.ts +21 -0
- package/dist/src/runtime/scheduler/journal-head.js +81 -0
- package/dist/src/runtime/scheduler/journal-index-state.d.ts +31 -0
- package/dist/src/runtime/scheduler/journal-index-state.js +137 -0
- package/dist/src/runtime/scheduler/journal-index.d.ts +22 -0
- package/dist/src/runtime/scheduler/journal-index.js +195 -0
- package/dist/src/runtime/scheduler/journal-store.d.ts +21 -0
- package/dist/src/runtime/scheduler/journal-store.js +184 -0
- package/dist/src/runtime/scheduler/journal-transaction.d.ts +14 -0
- package/dist/src/runtime/scheduler/journal-transaction.js +104 -0
- package/dist/src/runtime/scheduler/next-occurrence.d.ts +3 -0
- package/dist/src/runtime/scheduler/next-occurrence.js +39 -0
- package/dist/src/runtime/scheduler/run-completion.d.ts +12 -0
- package/dist/src/runtime/scheduler/run-completion.js +77 -0
- package/dist/src/runtime/scheduler/run-list-query.d.ts +5 -0
- package/dist/src/runtime/scheduler/run-list-query.js +38 -0
- package/dist/src/runtime/scheduler/run-records.d.ts +6 -0
- package/dist/src/runtime/scheduler/run-records.js +41 -0
- package/dist/src/runtime/scheduler/schedule-update.d.ts +3 -0
- package/dist/src/runtime/scheduler/schedule-update.js +22 -0
- package/dist/src/runtime/scheduler/schedule-validation.d.ts +10 -0
- package/dist/src/runtime/scheduler/schedule-validation.js +132 -0
- package/dist/src/runtime/scheduler/scheduler-engine.d.ts +2 -0
- package/dist/src/runtime/scheduler/scheduler-engine.js +174 -0
- package/dist/src/runtime/scheduler/scheduler-service.d.ts +10 -0
- package/dist/src/runtime/scheduler/scheduler-service.js +115 -0
- package/dist/src/runtime/scheduler/service-context.d.ts +21 -0
- package/dist/src/runtime/scheduler/service-context.js +26 -0
- package/dist/src/runtime/scheduler/session-deletion-state.d.ts +9 -0
- package/dist/src/runtime/scheduler/session-deletion-state.js +30 -0
- package/dist/src/runtime/scheduler/snapshot-validation.d.ts +4 -0
- package/dist/src/runtime/scheduler/snapshot-validation.js +112 -0
- package/dist/src/runtime/scheduler/startup-recovery.d.ts +2 -0
- package/dist/src/runtime/scheduler/startup-recovery.js +38 -0
- package/dist/src/runtime/scheduler/validation-error.d.ts +4 -0
- package/dist/src/runtime/scheduler/validation-error.js +8 -0
- package/dist/src/runtime/scheduler/working-store.d.ts +3 -0
- package/dist/src/runtime/scheduler/working-store.js +8 -0
- package/dist/src/runtime/session/request-session.d.ts +1 -0
- package/dist/src/runtime/session/request-session.js +14 -1
- package/dist/src/runtime/session/session-attachment-deletion.d.ts +8 -0
- package/dist/src/runtime/session/session-attachment-deletion.js +87 -0
- package/dist/src/runtime/session/session-deletion-boundary.d.ts +10 -0
- package/dist/src/runtime/session/session-deletion-boundary.js +39 -0
- package/dist/src/runtime/session/session-deletion-cleanup.d.ts +7 -0
- package/dist/src/runtime/session/session-deletion-cleanup.js +62 -0
- package/dist/src/runtime/session/session-deletion-finalization.d.ts +7 -0
- package/dist/src/runtime/session/session-deletion-finalization.js +34 -0
- package/dist/src/runtime/session/session-deletion-receipts.d.ts +7 -0
- package/dist/src/runtime/session/session-deletion-receipts.js +18 -0
- package/dist/src/runtime/session/session-lifecycle-store.d.ts +21 -0
- package/dist/src/runtime/session/session-lifecycle-store.js +72 -0
- package/dist/src/runtime/session/session-mutation-queue.d.ts +3 -0
- package/dist/src/runtime/session/session-mutation-queue.js +15 -0
- package/dist/src/runtime/steps/execution-agent/capability-decision-parsing.d.ts +16 -0
- package/dist/src/runtime/steps/execution-agent/capability-decision-parsing.js +165 -0
- package/dist/src/runtime/steps/execution-agent/contracts.d.ts +3 -1
- package/dist/src/runtime/steps/execution-agent/decision-parsing.d.ts +2 -0
- package/dist/src/runtime/steps/execution-agent/decision-parsing.js +195 -0
- package/dist/src/runtime/steps/execution-agent/decision-validation.d.ts +30 -0
- package/dist/src/runtime/steps/execution-agent/decision-validation.js +127 -0
- package/dist/src/runtime/steps/execution-agent/format.d.ts +1 -0
- package/dist/src/runtime/steps/execution-agent/format.js +12 -0
- package/dist/src/runtime/steps/execution-agent/input.d.ts +2 -1
- package/dist/src/runtime/steps/execution-agent/input.js +17 -2
- package/dist/src/runtime/steps/execution-agent/parser.d.ts +1 -2
- package/dist/src/runtime/steps/execution-agent/parser.js +1 -472
- package/dist/src/runtime/steps/execution-agent/prompt.d.ts +2 -0
- package/dist/src/runtime/steps/execution-agent/prompt.js +2 -0
- package/dist/src/runtime/steps/execution-agent/reconsideration-context.js +4 -3
- package/dist/src/runtime/steps/execution-agent/response-input.js +5 -4
- package/dist/src/runtime/steps/execution-agent/response-run.d.ts +3 -0
- package/dist/src/runtime/steps/execution-agent/response-run.js +7 -3
- package/dist/src/runtime/steps/execution-agent/run.d.ts +2 -0
- package/dist/src/runtime/steps/execution-agent/run.js +2 -0
- package/dist/src/runtime/steps/execution-agent/state-context.d.ts +2 -1
- package/dist/src/runtime/steps/execution-agent/state-context.js +13 -5
- package/dist/src/runtime/steps/memory-recall-decision.d.ts +30 -0
- package/dist/src/runtime/steps/memory-recall-decision.js +101 -0
- package/dist/src/runtime/steps/memory-recall-prompt.d.ts +1 -0
- package/dist/src/runtime/steps/memory-recall-prompt.js +15 -0
- package/dist/src/runtime/steps/supervisor-decision/contracts.d.ts +4 -2
- package/dist/src/runtime/steps/supervisor-decision/diagnostics.d.ts +2 -0
- package/dist/src/runtime/steps/supervisor-decision/diagnostics.js +13 -6
- package/dist/src/runtime/steps/supervisor-decision/format.d.ts +2 -0
- package/dist/src/runtime/steps/supervisor-decision/format.js +41 -2
- package/dist/src/runtime/steps/supervisor-decision/input.d.ts +5 -1
- package/dist/src/runtime/steps/supervisor-decision/input.js +25 -5
- package/dist/src/runtime/steps/supervisor-decision/memory-recall-continuation.d.ts +10 -0
- package/dist/src/runtime/steps/supervisor-decision/memory-recall-continuation.js +32 -0
- package/dist/src/runtime/steps/supervisor-decision/parser.d.ts +2 -0
- package/dist/src/runtime/steps/supervisor-decision/parser.js +36 -1
- package/dist/src/runtime/steps/supervisor-decision/prompt.d.ts +3 -0
- package/dist/src/runtime/steps/supervisor-decision/prompt.js +16 -8
- package/dist/src/runtime/steps/supervisor-decision/response-recommendation.d.ts +13 -0
- package/dist/src/runtime/steps/supervisor-decision/response-recommendation.js +32 -0
- package/dist/src/runtime/steps/supervisor-decision/resume.d.ts +2 -0
- package/dist/src/runtime/steps/supervisor-decision/resume.js +13 -0
- package/dist/src/runtime/steps/supervisor-decision/run.d.ts +3 -0
- package/dist/src/runtime/steps/supervisor-decision/run.js +19 -0
- package/dist/src/runtime/steps/supervisor-decision/working-directory.js +7 -1
- package/dist/src/runtime/steps/supervisor-response/diagnostics.d.ts +1 -0
- package/dist/src/runtime/steps/supervisor-response/diagnostics.js +1 -0
- package/dist/src/runtime/steps/supervisor-response/input.d.ts +2 -1
- package/dist/src/runtime/steps/supervisor-response/input.js +17 -4
- package/dist/src/runtime/steps/supervisor-response/memory-authoring.d.ts +1 -0
- package/dist/src/runtime/steps/supervisor-response/memory-authoring.js +4 -0
- package/dist/src/runtime/steps/supervisor-response/prompt.d.ts +1 -0
- package/dist/src/runtime/steps/supervisor-response/prompt.js +8 -2
- package/dist/src/runtime/steps/supervisor-response/response-recommendation.d.ts +10 -0
- package/dist/src/runtime/steps/supervisor-response/response-recommendation.js +25 -0
- package/dist/src/runtime/steps/supervisor-response/run.d.ts +6 -1
- package/dist/src/runtime/steps/supervisor-response/run.js +26 -7
- package/dist/src/sessions/record/projection.js +1 -0
- package/dist/src/sessions/schedule-metadata.d.ts +8 -0
- package/dist/src/sessions/schedule-metadata.js +1 -0
- package/dist/src/sessions/session-service.d.ts +1 -0
- package/dist/src/sessions/session-service.js +1 -0
- package/dist/src/sessions/types.d.ts +2 -0
- package/dist/src/shared/http-server-shutdown.d.ts +4 -0
- package/dist/src/shared/http-server-shutdown.js +17 -0
- package/dist/src/shared/public-http/aggregate-gate.d.ts +3 -0
- package/dist/src/shared/public-http/aggregate-gate.js +87 -0
- package/dist/src/shared/public-http/deadline.d.ts +2 -0
- package/dist/src/shared/public-http/deadline.js +29 -0
- package/dist/src/shared/public-http/errors.d.ts +6 -0
- package/dist/src/shared/public-http/errors.js +11 -0
- package/dist/src/shared/public-http/limits.d.ts +8 -0
- package/dist/src/shared/public-http/limits.js +8 -0
- package/dist/src/shared/public-http/network-policy.d.ts +11 -0
- package/dist/src/shared/public-http/network-policy.js +178 -0
- package/dist/src/shared/public-http/public-http.d.ts +24 -0
- package/dist/src/shared/public-http/public-http.js +85 -0
- package/dist/src/shared/public-http/request-hop.d.ts +18 -0
- package/dist/src/shared/public-http/request-hop.js +140 -0
- package/dist/src/web-ui/app/ARCHITECTURE.md +66 -4
- package/dist/src/web-ui/app/app-bootstrap.js +53 -0
- package/dist/src/web-ui/app/app-dom.js +80 -0
- package/dist/src/web-ui/app/app.js +195 -212
- package/dist/src/web-ui/app/components/conversation-activity.d.ts +2 -0
- package/dist/src/web-ui/app/components/conversation-activity.js +34 -7
- package/dist/src/web-ui/app/components/conversation-role-cards.d.ts +1 -0
- package/dist/src/web-ui/app/components/conversation-role-cards.js +61 -5
- package/dist/src/web-ui/app/components/conversation-schedule.js +71 -0
- package/dist/src/web-ui/app/components/conversation-status.js +65 -0
- package/dist/src/web-ui/app/components/conversation-tools.d.ts +13 -0
- package/dist/src/web-ui/app/components/conversation-tools.js +284 -0
- package/dist/src/web-ui/app/components/conversation-view.js +39 -11
- package/dist/src/web-ui/app/components/dashboard/activity.js +61 -0
- package/dist/src/web-ui/app/components/dashboard/icons.js +23 -0
- package/dist/src/web-ui/app/components/dashboard/recent-conversations.js +64 -0
- package/dist/src/web-ui/app/components/dashboard/workspace.js +107 -0
- package/dist/src/web-ui/app/components/message-link-previews.d.ts +16 -0
- package/dist/src/web-ui/app/components/message-link-previews.js +179 -0
- package/dist/src/web-ui/app/components/schedules/details.js +101 -0
- package/dist/src/web-ui/app/components/schedules/form.d.ts +13 -0
- package/dist/src/web-ui/app/components/schedules/form.js +246 -0
- package/dist/src/web-ui/app/components/schedules/workspace-state.js +59 -0
- package/dist/src/web-ui/app/components/schedules/workspace.js +165 -0
- package/dist/src/web-ui/app/components/workspace-shell.js +48 -2
- package/dist/src/web-ui/app/configuration-feature.js +72 -0
- package/dist/src/web-ui/app/controllers/composer-attachments-controller.d.ts +1 -0
- package/dist/src/web-ui/app/controllers/composer-attachments-controller.js +17 -6
- package/dist/src/web-ui/app/controllers/composer-submit-controller.d.ts +2 -0
- package/dist/src/web-ui/app/controllers/composer-submit-controller.js +15 -1
- package/dist/src/web-ui/app/controllers/composer-surface-controller.js +58 -0
- package/dist/src/web-ui/app/controllers/composer-workspace-controller.d.ts +53 -0
- package/dist/src/web-ui/app/controllers/composer-workspace-controller.js +180 -0
- package/dist/src/web-ui/app/controllers/conversation-read-state-controller.d.ts +23 -0
- package/dist/src/web-ui/app/controllers/conversation-read-state-controller.js +82 -0
- package/dist/src/web-ui/app/controllers/conversation-session-controller.d.ts +8 -0
- package/dist/src/web-ui/app/controllers/conversation-session-controller.js +28 -39
- package/dist/src/web-ui/app/controllers/dashboard-controller.js +127 -0
- package/dist/src/web-ui/app/controllers/home-composer-feature.d.ts +40 -0
- package/dist/src/web-ui/app/controllers/home-composer-feature.js +119 -0
- package/dist/src/web-ui/app/controllers/home-conversation-activation.js +37 -0
- package/dist/src/web-ui/app/controllers/realtime-event-controller.d.ts +1 -0
- package/dist/src/web-ui/app/controllers/realtime-event-controller.js +74 -3
- package/dist/src/web-ui/app/controllers/runtime-selection-controller.d.ts +2 -1
- package/dist/src/web-ui/app/controllers/runtime-selection-controller.js +15 -14
- package/dist/src/web-ui/app/controllers/schedule-realtime.js +118 -0
- package/dist/src/web-ui/app/controllers/schedules-controller.js +421 -0
- package/dist/src/web-ui/app/controllers/session-controller.js +30 -3
- package/dist/src/web-ui/app/dashboard-feature.js +44 -0
- package/dist/src/web-ui/app/index.html +53 -1
- package/dist/src/web-ui/app/lib/composer-submission-scope.d.ts +21 -0
- package/dist/src/web-ui/app/lib/composer-submission-scope.js +13 -0
- package/dist/src/web-ui/app/lib/context-window-snapshot-order.d.ts +15 -0
- package/dist/src/web-ui/app/lib/context-window-snapshot-order.js +31 -0
- package/dist/src/web-ui/app/lib/conversation-role-model.d.ts +10 -1
- package/dist/src/web-ui/app/lib/conversation-role-model.js +97 -15
- package/dist/src/web-ui/app/lib/conversation-status-model.d.ts +12 -0
- package/dist/src/web-ui/app/lib/conversation-status-model.js +116 -0
- package/dist/src/web-ui/app/lib/dashboard-job-templates.js +41 -0
- package/dist/src/web-ui/app/lib/dashboard-presentation.js +126 -0
- package/dist/src/web-ui/app/lib/message-markdown.d.ts +5 -0
- package/dist/src/web-ui/app/lib/message-markdown.js +99 -0
- package/dist/src/web-ui/app/lib/message-url-policy.d.ts +1 -0
- package/dist/src/web-ui/app/lib/message-url-policy.js +13 -0
- package/dist/src/web-ui/app/lib/schedule-errors.js +29 -0
- package/dist/src/web-ui/app/lib/schedule-message.js +30 -0
- package/dist/src/web-ui/app/lib/schedule-presentation.js +81 -0
- package/dist/src/web-ui/app/lib/session-read-state.d.ts +22 -0
- package/dist/src/web-ui/app/lib/session-read-state.js +63 -0
- package/dist/src/web-ui/app/lib/text-format.js +2 -143
- package/dist/src/web-ui/app/lib/tool-activity-event.d.ts +26 -0
- package/dist/src/web-ui/app/lib/tool-activity-event.js +228 -0
- package/dist/src/web-ui/app/lib/tool-activity-model.d.ts +41 -0
- package/dist/src/web-ui/app/lib/tool-activity-model.js +255 -0
- package/dist/src/web-ui/app/lib/tool-timeline.d.ts +3 -0
- package/dist/src/web-ui/app/lib/tool-timeline.js +18 -0
- package/dist/src/web-ui/app/schedules-feature.js +87 -0
- package/dist/src/web-ui/app/services/message-link-preview-client.d.ts +14 -0
- package/dist/src/web-ui/app/services/message-link-preview-client.js +96 -0
- package/dist/src/web-ui/app/services/runtime-web-client/schedules.js +51 -0
- package/dist/src/web-ui/app/services/runtime-web-client.d.ts +37 -0
- package/dist/src/web-ui/app/services/runtime-web-client.js +13 -8
- package/dist/src/web-ui/app/styles/00-tokens-base.css +11 -11
- package/dist/src/web-ui/app/styles/18-dashboard.css +384 -0
- package/dist/src/web-ui/app/styles/20-chat-composer.css +1 -130
- package/dist/src/web-ui/app/styles/26-message-content.css +295 -0
- package/dist/src/web-ui/app/styles/27-conversation-tools.css +266 -0
- package/dist/src/web-ui/app/styles/28-conversation-status.css +52 -0
- package/dist/src/web-ui/app/styles/38-schedule-workspace.css +263 -0
- package/dist/src/web-ui/app/styles/38-schedules.css +352 -0
- package/dist/src/web-ui/app/styles/90-responsive.css +14 -0
- package/dist/src/web-ui/app/styles/91-schedules-responsive.css +72 -0
- package/dist/src/web-ui/app/styles/92-dashboard-responsive.css +88 -0
- package/dist/src/web-ui/app/styles.css +8 -0
- package/dist/src/web-ui/app/ui-behavior.d.ts +1 -1
- package/dist/src/web-ui/app/ui-behavior.js +3 -1
- package/dist/src/web-ui/app/vendor/README.md +15 -0
- package/dist/src/web-ui/app/vendor/markdown-it.LICENSE +22 -0
- package/dist/src/web-ui/app/vendor/markdown-it.js +3003 -0
- package/dist/src/web-ui/link-preview/metadata.d.ts +9 -0
- package/dist/src/web-ui/link-preview/metadata.js +97 -0
- package/dist/src/web-ui/link-preview/preview-cache.d.ts +4 -0
- package/dist/src/web-ui/link-preview/preview-cache.js +23 -0
- package/dist/src/web-ui/link-preview/raster-response.d.ts +9 -0
- package/dist/src/web-ui/link-preview/raster-response.js +49 -0
- package/dist/src/web-ui/link-preview/routes.d.ts +3 -0
- package/dist/src/web-ui/link-preview/routes.js +97 -0
- package/dist/src/web-ui/link-preview/service.d.ts +11 -0
- package/dist/src/web-ui/link-preview/service.js +117 -0
- package/dist/src/web-ui/local-runtime/api-router.d.ts +4 -1
- package/dist/src/web-ui/local-runtime/api-router.js +42 -73
- package/dist/src/web-ui/local-runtime/contracts.d.ts +2 -2
- package/dist/src/web-ui/local-runtime/environment-registry.d.ts +12 -1
- package/dist/src/web-ui/local-runtime/environment-registry.js +38 -3
- package/dist/src/web-ui/local-runtime/realtime-controller.js +3 -1
- package/dist/src/web-ui/local-runtime/request-execution.d.ts +5 -1
- package/dist/src/web-ui/local-runtime/request-execution.js +38 -2
- package/dist/src/web-ui/local-runtime/schedule-job-creation.d.ts +7 -0
- package/dist/src/web-ui/local-runtime/schedule-job-creation.js +62 -0
- package/dist/src/web-ui/local-runtime/schedule-management-routes.d.ts +30 -0
- package/dist/src/web-ui/local-runtime/schedule-management-routes.js +134 -0
- package/dist/src/web-ui/local-runtime/schedule-run-page.d.ts +5 -0
- package/dist/src/web-ui/local-runtime/schedule-run-page.js +23 -0
- package/dist/src/web-ui/local-runtime/session-routes.d.ts +17 -0
- package/dist/src/web-ui/local-runtime/session-routes.js +74 -0
- package/dist/src/web-ui/local-runtime-backend.d.ts +2 -0
- package/dist/src/web-ui/local-runtime-backend.js +11 -1
- package/dist/src/web-ui/schedule-creation-contract.d.ts +7 -0
- package/dist/src/web-ui/schedule-creation-contract.js +1 -0
- package/dist/src/web-ui/server-shutdown.d.ts +4 -0
- package/dist/src/web-ui/server-shutdown.js +32 -0
- package/dist/src/web-ui/server.js +13 -10
- package/dist/src/web-ui/session-read-state/availability.d.ts +16 -0
- package/dist/src/web-ui/session-read-state/availability.js +20 -0
- package/dist/src/web-ui/session-read-state/projection.d.ts +17 -0
- package/dist/src/web-ui/session-read-state/projection.js +71 -0
- package/dist/src/web-ui/session-read-state/service.d.ts +86 -0
- package/dist/src/web-ui/session-read-state/service.js +89 -0
- package/dist/src/web-ui/session-read-state/store.d.ts +22 -0
- package/dist/src/web-ui/session-read-state/store.js +110 -0
- package/docs/configuration.md +41 -1
- package/docs/long-term-memory.md +46 -5
- package/docs/runtime-invariant-coverage.md +1 -1
- package/docs/runtime-library.md +23 -0
- package/docs/runtime-public-contracts.md +32 -1
- package/package.json +3 -1
- package/plugins/code-outline/plugin.json +15 -0
- package/plugins/document-reader/plugin.json +17 -0
- package/plugins/filesystem/plugin.json +17 -2
- package/plugins/json-inspector/plugin.json +12 -0
- package/plugins/local-search/plugin.json +12 -0
- package/plugins/memory/plugin.json +26 -1
- package/plugins/memory/source/index.ts +10 -6
- package/plugins/memory/src/index.cjs +11 -7
- package/plugins/project-orientation/plugin.json +14 -0
- package/plugins/web/source/aggregate-gate.ts +8 -130
- package/plugins/web/source/deadline.ts +14 -50
- package/plugins/web/source/errors.ts +17 -11
- package/plugins/web/source/limits.ts +3 -6
- package/plugins/web/source/network-policy.ts +28 -226
- package/plugins/web/source/public-http.ts +17 -142
- package/plugins/web/source/request-hop.ts +11 -191
- package/plugins/web/src/index.cjs +119 -59
- package/runtime.config.schema.json +7 -0
- package/src/runtime/README.md +105 -1
- package/src/runtime/local-host/README.md +86 -0
- package/src/runtime/scheduler/README.md +166 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { SchedulerValidationError } from "./validation-error.js";
|
|
2
|
+
import { parseSchedulerInstant, schedulerInstantFromMilliseconds, } from "./instant-validation.js";
|
|
3
|
+
export { SchedulerValidationError } from "./validation-error.js";
|
|
4
|
+
export { parseSchedulerInstant } from "./instant-validation.js";
|
|
5
|
+
export function requireSchedulerText(value, field) {
|
|
6
|
+
if (typeof value !== "string") {
|
|
7
|
+
throw new SchedulerValidationError("scheduler_invalid_job", `${field} must be text`);
|
|
8
|
+
}
|
|
9
|
+
const text = value.trim();
|
|
10
|
+
if (!text)
|
|
11
|
+
throw new SchedulerValidationError("scheduler_invalid_job", `${field} is required`);
|
|
12
|
+
return text;
|
|
13
|
+
}
|
|
14
|
+
export function validateSchedulerJobInput(input) {
|
|
15
|
+
if (!input || typeof input !== "object") {
|
|
16
|
+
throw new SchedulerValidationError("scheduler_invalid_job", "job input is required");
|
|
17
|
+
}
|
|
18
|
+
for (const field of [
|
|
19
|
+
"sessionId",
|
|
20
|
+
"title",
|
|
21
|
+
"prompt",
|
|
22
|
+
"modelProfileId",
|
|
23
|
+
]) {
|
|
24
|
+
requireSchedulerText(input[field], field);
|
|
25
|
+
}
|
|
26
|
+
const allowedModes = ["fast", "reasoning", "deep"];
|
|
27
|
+
if (!allowedModes.includes(input.agentMode)) {
|
|
28
|
+
throw new SchedulerValidationError("scheduler_invalid_job", "agentMode is invalid");
|
|
29
|
+
}
|
|
30
|
+
validateTimeZone(input.timeZone);
|
|
31
|
+
}
|
|
32
|
+
export function validateTimeZone(timeZone) {
|
|
33
|
+
try {
|
|
34
|
+
requireSchedulerText(timeZone, "timeZone");
|
|
35
|
+
new Intl.DateTimeFormat("en", { timeZone }).format();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new SchedulerValidationError("scheduler_invalid_timezone", "An IANA timeZone is required");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function requirePositiveDuration(value) {
|
|
42
|
+
if (!Number.isSafeInteger(value)) {
|
|
43
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "duration must be integer milliseconds");
|
|
44
|
+
}
|
|
45
|
+
if (value < 1_000) {
|
|
46
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "duration must be at least one second");
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
export function requireCalendarHour(value) {
|
|
51
|
+
if (typeof value !== "string") {
|
|
52
|
+
throw new SchedulerValidationError("scheduler_exact_time_required", "Supply an exact HH:mm time");
|
|
53
|
+
}
|
|
54
|
+
if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(value)) {
|
|
55
|
+
throw new SchedulerValidationError("scheduler_exact_time_required", "Supply an exact HH:mm time");
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
export function normalizeSchedulerSchedule(input, now) {
|
|
60
|
+
if (!input || typeof input !== "object") {
|
|
61
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "schedule is required");
|
|
62
|
+
}
|
|
63
|
+
switch (input.kind) {
|
|
64
|
+
case "timer": {
|
|
65
|
+
const delayMs = requirePositiveDuration(input.delayMs);
|
|
66
|
+
const at = schedulerInstantFromMilliseconds(now + delayMs);
|
|
67
|
+
return { kind: "timer", delayMs, at };
|
|
68
|
+
}
|
|
69
|
+
case "once":
|
|
70
|
+
return { kind: "once", at: parseSchedulerInstant(input.at, "at") };
|
|
71
|
+
case "interval": {
|
|
72
|
+
const everyMs = requirePositiveDuration(input.everyMs);
|
|
73
|
+
const anchorAt = input.anchorAt === undefined
|
|
74
|
+
? schedulerInstantFromMilliseconds(now + everyMs)
|
|
75
|
+
: parseSchedulerInstant(input.anchorAt, "anchorAt");
|
|
76
|
+
return { kind: "interval", everyMs, anchorAt };
|
|
77
|
+
}
|
|
78
|
+
case "daily":
|
|
79
|
+
return { kind: "daily", at: requireCalendarHour(input.at) };
|
|
80
|
+
case "weekly": {
|
|
81
|
+
const weekdays = normalizeWeekdays(input.weekdays);
|
|
82
|
+
return { kind: "weekly", at: requireCalendarHour(input.at), weekdays };
|
|
83
|
+
}
|
|
84
|
+
case "monthly":
|
|
85
|
+
if (!isSupportedMonthDay(input.dayOfMonth)) {
|
|
86
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "dayOfMonth must be 1–31");
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
kind: "monthly",
|
|
90
|
+
at: requireCalendarHour(input.at),
|
|
91
|
+
dayOfMonth: input.dayOfMonth,
|
|
92
|
+
};
|
|
93
|
+
default:
|
|
94
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "Unknown schedule kind");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Stored timer deadlines are canonical state, not new relative timer input. */
|
|
98
|
+
export function normalizeStoredSchedulerSchedule(schedule) {
|
|
99
|
+
if (schedule?.kind !== "timer")
|
|
100
|
+
return normalizeSchedulerSchedule(schedule, 0);
|
|
101
|
+
return {
|
|
102
|
+
kind: "timer",
|
|
103
|
+
delayMs: requirePositiveDuration(schedule.delayMs),
|
|
104
|
+
at: parseSchedulerInstant(schedule.at, "at"),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function normalizeWeekdays(value) {
|
|
108
|
+
if (!Array.isArray(value)) {
|
|
109
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "weekdays must contain Sunday=0 through Saturday=6");
|
|
110
|
+
}
|
|
111
|
+
if (value.length === 0) {
|
|
112
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "Choose at least one weekday");
|
|
113
|
+
}
|
|
114
|
+
if (!value.every(isSupportedWeekday)) {
|
|
115
|
+
throw new SchedulerValidationError("scheduler_invalid_schedule", "weekdays must contain integers 0–6");
|
|
116
|
+
}
|
|
117
|
+
return [...new Set(value)].sort((a, b) => a - b);
|
|
118
|
+
}
|
|
119
|
+
function isSupportedWeekday(value) {
|
|
120
|
+
if (!Number.isInteger(value))
|
|
121
|
+
return false;
|
|
122
|
+
if (Number(value) < 0)
|
|
123
|
+
return false;
|
|
124
|
+
return Number(value) <= 6;
|
|
125
|
+
}
|
|
126
|
+
function isSupportedMonthDay(value) {
|
|
127
|
+
if (!Number.isInteger(value))
|
|
128
|
+
return false;
|
|
129
|
+
if (value < 1)
|
|
130
|
+
return false;
|
|
131
|
+
return value <= 31;
|
|
132
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { nextSchedulerOccurrence } from "./next-occurrence.js";
|
|
2
|
+
import { reconcileSchedulerCompletions, settleSchedulerRun, } from "./run-completion.js";
|
|
3
|
+
import { findPendingRun, hasRunningSession, makeSchedulerRun, } from "./run-records.js";
|
|
4
|
+
import { canBeginSchedulerRun, jobEpoch, } from "./service-context.js";
|
|
5
|
+
export async function tickScheduler(context) {
|
|
6
|
+
if (!context.running)
|
|
7
|
+
return;
|
|
8
|
+
await reconcileSchedulerCompletions(context);
|
|
9
|
+
if (!context.running)
|
|
10
|
+
return;
|
|
11
|
+
const now = context.now();
|
|
12
|
+
const snapshot = await context.store.read();
|
|
13
|
+
const hasDue = snapshot.jobs.some((job) => isDueJob(job, now));
|
|
14
|
+
if (hasDue)
|
|
15
|
+
await enqueueDueOccurrences(context, now);
|
|
16
|
+
const pending = (await context.store.read()).runs.filter((run) => run.status === "pending");
|
|
17
|
+
for (const run of pending) {
|
|
18
|
+
if (!context.running)
|
|
19
|
+
return;
|
|
20
|
+
await dispatchPendingRun(context, run);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function isDueJob(job, now) {
|
|
24
|
+
if (job.state !== "active")
|
|
25
|
+
return false;
|
|
26
|
+
if (!job.nextRunAt)
|
|
27
|
+
return false;
|
|
28
|
+
return Date.parse(job.nextRunAt) <= now;
|
|
29
|
+
}
|
|
30
|
+
async function enqueueDueOccurrences(context, now) {
|
|
31
|
+
await context.store.update((state) => {
|
|
32
|
+
for (const job of state.jobs) {
|
|
33
|
+
if (!isDueJob(job, now))
|
|
34
|
+
continue;
|
|
35
|
+
const pending = findPendingRun(state, job.id);
|
|
36
|
+
if (!canRecordScheduledOccurrence(pending))
|
|
37
|
+
continue;
|
|
38
|
+
if (!pending) {
|
|
39
|
+
state.runs.push(makeSchedulerRun(job, job.nextRunAt, "schedule"));
|
|
40
|
+
}
|
|
41
|
+
job.nextRunAt = nextSchedulerOccurrence(job.schedule, job.timeZone, now);
|
|
42
|
+
if (!job.nextRunAt)
|
|
43
|
+
job.state = "completed";
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function canRecordScheduledOccurrence(pending) {
|
|
48
|
+
if (!pending)
|
|
49
|
+
return true;
|
|
50
|
+
// A manual run cannot consume a recurrence. Keep its due time until the
|
|
51
|
+
// single pending slot can represent scheduled work instead.
|
|
52
|
+
return pending.trigger === "schedule";
|
|
53
|
+
}
|
|
54
|
+
async function dispatchPendingRun(context, pending) {
|
|
55
|
+
const epoch = jobEpoch(context, pending.jobId);
|
|
56
|
+
const exists = await lookupPendingRunSession(context, pending);
|
|
57
|
+
if (exists === undefined)
|
|
58
|
+
return;
|
|
59
|
+
if (!exists) {
|
|
60
|
+
context.deletedSessions.add(pending.sessionId);
|
|
61
|
+
await removeDeletedSession(context, pending.sessionId);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!canBeginSchedulerRun(context, pending.jobId, pending.sessionId, epoch))
|
|
65
|
+
return;
|
|
66
|
+
const release = context.executor.tryReserve(pending.sessionId);
|
|
67
|
+
if (!release)
|
|
68
|
+
return;
|
|
69
|
+
let delegated = false;
|
|
70
|
+
try {
|
|
71
|
+
const claimed = await claimPendingRun(context, pending, epoch);
|
|
72
|
+
if (!claimed)
|
|
73
|
+
return;
|
|
74
|
+
// Last validity guard and start invocation are in the same synchronous turn.
|
|
75
|
+
if (!canBeginSchedulerRun(context, pending.jobId, pending.sessionId, epoch)) {
|
|
76
|
+
await cancelClaimedRun(context, pending.id);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const execution = startCapturedRun(context, claimed.job, claimed.run);
|
|
80
|
+
delegated = true;
|
|
81
|
+
void settleSchedulerRun(context, claimed.run, context.generation, execution, release);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
if (!delegated)
|
|
85
|
+
release();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function lookupPendingRunSession(context, pending) {
|
|
89
|
+
const generation = context.generation;
|
|
90
|
+
try {
|
|
91
|
+
return await context.executor.sessionExists(pending.sessionId);
|
|
92
|
+
}
|
|
93
|
+
catch (cause) {
|
|
94
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
95
|
+
const error = new Error(`scheduler_session_lookup_failed: ${detail}`, {
|
|
96
|
+
cause,
|
|
97
|
+
});
|
|
98
|
+
// Settle after mutations already queued during lookup. A no-op edit changes
|
|
99
|
+
// the preparation epoch but must not cause this same failed run to retry.
|
|
100
|
+
// Cancellation or a replacement snapshot still wins by exact run identity.
|
|
101
|
+
void context
|
|
102
|
+
.enqueue(async () => {
|
|
103
|
+
if (!context.running)
|
|
104
|
+
return;
|
|
105
|
+
if (context.generation !== generation)
|
|
106
|
+
return;
|
|
107
|
+
await context.store.update((state) => {
|
|
108
|
+
const run = state.runs.find((candidate) => candidate.id === pending.id);
|
|
109
|
+
if (!run || run.status !== "pending")
|
|
110
|
+
return;
|
|
111
|
+
run.status = "failed";
|
|
112
|
+
run.finishedAt = new Date(context.now()).toISOString();
|
|
113
|
+
run.error = error.message;
|
|
114
|
+
});
|
|
115
|
+
})
|
|
116
|
+
.catch(context.onError);
|
|
117
|
+
context.onError(error);
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function claimPendingRun(context, pending, epoch) {
|
|
122
|
+
return context.store.update((state) => {
|
|
123
|
+
if (!canBeginSchedulerRun(context, pending.jobId, pending.sessionId, epoch))
|
|
124
|
+
return null;
|
|
125
|
+
const job = state.jobs.find((item) => item.id === pending.jobId);
|
|
126
|
+
if (!job)
|
|
127
|
+
return null;
|
|
128
|
+
if (job.state === "cancelled")
|
|
129
|
+
return null;
|
|
130
|
+
const run = state.runs.find((item) => item.id === pending.id);
|
|
131
|
+
if (!run || run.status !== "pending")
|
|
132
|
+
return null;
|
|
133
|
+
if (job.state === "paused" && run.trigger !== "manual")
|
|
134
|
+
return null;
|
|
135
|
+
if (hasRunningSession(state, run.sessionId))
|
|
136
|
+
return null;
|
|
137
|
+
run.status = "running";
|
|
138
|
+
run.startedAt = new Date(context.now()).toISOString();
|
|
139
|
+
return { job, run };
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function startCapturedRun(context, job, run) {
|
|
143
|
+
try {
|
|
144
|
+
// The immutable run text owns this invocation even after a later Job edit.
|
|
145
|
+
return context.executor.start({
|
|
146
|
+
...job,
|
|
147
|
+
prompt: run.prompt,
|
|
148
|
+
title: run.title,
|
|
149
|
+
modelProfileId: run.modelProfileId,
|
|
150
|
+
agentMode: run.agentMode,
|
|
151
|
+
timeZone: run.timeZone,
|
|
152
|
+
revision: run.jobRevision,
|
|
153
|
+
}, run);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
return Promise.reject(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function cancelClaimedRun(context, runId) {
|
|
160
|
+
await context.store.update((state) => {
|
|
161
|
+
const run = state.runs.find((candidate) => candidate.id === runId);
|
|
162
|
+
if (!run)
|
|
163
|
+
return;
|
|
164
|
+
run.status = "cancelled";
|
|
165
|
+
run.finishedAt = new Date(context.now()).toISOString();
|
|
166
|
+
delete run.startedAt;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async function removeDeletedSession(context, sessionId) {
|
|
170
|
+
await context.store.update((state) => {
|
|
171
|
+
state.jobs = state.jobs.filter((job) => job.sessionId !== sessionId);
|
|
172
|
+
state.runs = state.runs.filter((run) => run.sessionId !== sessionId);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SchedulerExecutor, SchedulerService, SchedulerStore } from "./contracts.js";
|
|
2
|
+
export interface SchedulerServiceOptions {
|
|
3
|
+
environmentId: string;
|
|
4
|
+
store: SchedulerStore;
|
|
5
|
+
executor: SchedulerExecutor;
|
|
6
|
+
now?: () => number;
|
|
7
|
+
tickIntervalMs?: number;
|
|
8
|
+
onError?: (error: unknown) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function createSchedulerService(options: SchedulerServiceOptions): SchedulerService;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { changeSchedulerJobState, createSchedulerJob, deleteSchedulerSession, matchesSchedulerFilter, requestSchedulerRunNow, updateSchedulerJob, } from "./job-management.js";
|
|
2
|
+
import { tickScheduler } from "./scheduler-engine.js";
|
|
3
|
+
import { requireRunningScheduler, } from "./service-context.js";
|
|
4
|
+
import { recoverSchedulerSnapshot } from "./startup-recovery.js";
|
|
5
|
+
import { querySchedulerRuns } from "./run-list-query.js";
|
|
6
|
+
import { createSchedulerWorkingStore } from "./working-store.js";
|
|
7
|
+
import { SchedulerSessionDeletionState } from "./session-deletion-state.js";
|
|
8
|
+
export function createSchedulerService(options) {
|
|
9
|
+
let tail = Promise.resolve();
|
|
10
|
+
let releaseOwner;
|
|
11
|
+
let timer;
|
|
12
|
+
let ticking;
|
|
13
|
+
const context = {
|
|
14
|
+
environmentId: options.environmentId,
|
|
15
|
+
store: createSchedulerWorkingStore(options.store),
|
|
16
|
+
executor: options.executor,
|
|
17
|
+
now: options.now ?? Date.now,
|
|
18
|
+
running: false,
|
|
19
|
+
generation: 0,
|
|
20
|
+
jobEpochs: new Map(),
|
|
21
|
+
pendingJobMutations: new Set(),
|
|
22
|
+
deletedSessions: new SchedulerSessionDeletionState(),
|
|
23
|
+
pendingCompletions: new Map(),
|
|
24
|
+
enqueue: (operation) => {
|
|
25
|
+
const result = tail.then(operation);
|
|
26
|
+
tail = result.catch(() => undefined);
|
|
27
|
+
return result;
|
|
28
|
+
},
|
|
29
|
+
onError: options.onError ?? ((error) => console.error("Scheduler failed:", error)),
|
|
30
|
+
};
|
|
31
|
+
const service = {
|
|
32
|
+
start: () => {
|
|
33
|
+
const requestedGeneration = context.generation;
|
|
34
|
+
return context.enqueue(async () => {
|
|
35
|
+
if (requestedGeneration !== context.generation)
|
|
36
|
+
return;
|
|
37
|
+
if (context.running)
|
|
38
|
+
return;
|
|
39
|
+
const release = await options.store.acquire();
|
|
40
|
+
releaseOwner = release;
|
|
41
|
+
try {
|
|
42
|
+
await context.store.update((state) => {
|
|
43
|
+
recoverSchedulerSnapshot(state, options.environmentId, context.now());
|
|
44
|
+
});
|
|
45
|
+
if (requestedGeneration !== context.generation) {
|
|
46
|
+
await release();
|
|
47
|
+
releaseOwner = undefined;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
context.running = true;
|
|
51
|
+
timer = setInterval(() => {
|
|
52
|
+
void service.tick().catch(context.onError);
|
|
53
|
+
}, options.tickIntervalMs ?? 1_000);
|
|
54
|
+
timer.unref();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
await release();
|
|
58
|
+
releaseOwner = undefined;
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
stop: () => {
|
|
64
|
+
// Stop invalidates every in-flight preparation before waiting for disk writes.
|
|
65
|
+
context.generation += 1;
|
|
66
|
+
context.running = false;
|
|
67
|
+
context.pendingCompletions.clear();
|
|
68
|
+
if (timer)
|
|
69
|
+
clearInterval(timer);
|
|
70
|
+
timer = undefined;
|
|
71
|
+
return context.enqueue(async () => {
|
|
72
|
+
const release = releaseOwner;
|
|
73
|
+
releaseOwner = undefined;
|
|
74
|
+
await release?.();
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
tick: () => {
|
|
78
|
+
if (ticking)
|
|
79
|
+
return ticking;
|
|
80
|
+
const pending = context.enqueue(() => tickScheduler(context));
|
|
81
|
+
ticking = pending;
|
|
82
|
+
void pending
|
|
83
|
+
.finally(() => {
|
|
84
|
+
if (ticking === pending)
|
|
85
|
+
ticking = undefined;
|
|
86
|
+
})
|
|
87
|
+
.catch(() => undefined);
|
|
88
|
+
return pending;
|
|
89
|
+
},
|
|
90
|
+
create: (input) => createSchedulerJob(context, input),
|
|
91
|
+
list: (filter = {}) => context.enqueue(async () => {
|
|
92
|
+
requireRunningScheduler(context);
|
|
93
|
+
return (await context.store.read()).jobs.filter((job) => matchesSchedulerFilter(job, filter));
|
|
94
|
+
}),
|
|
95
|
+
get: (jobId) => context.enqueue(async () => {
|
|
96
|
+
requireRunningScheduler(context);
|
|
97
|
+
return ((await context.store.read()).jobs.find((job) => job.id === jobId) ??
|
|
98
|
+
null);
|
|
99
|
+
}),
|
|
100
|
+
update: (jobId, patch) => updateSchedulerJob(context, jobId, patch),
|
|
101
|
+
pause: (jobId) => changeSchedulerJobState(context, jobId, "paused"),
|
|
102
|
+
resume: (jobId) => changeSchedulerJobState(context, jobId, "active"),
|
|
103
|
+
cancel: (jobId) => changeSchedulerJobState(context, jobId, "cancelled"),
|
|
104
|
+
runNow: (jobId) => requestSchedulerRunNow(context, jobId),
|
|
105
|
+
deleteSession: (sessionId) => deleteSchedulerSession(context, sessionId),
|
|
106
|
+
listRuns: (jobId, query) => context.enqueue(async () => {
|
|
107
|
+
requireRunningScheduler(context);
|
|
108
|
+
if (options.store.readRuns)
|
|
109
|
+
return options.store.readRuns(jobId, query);
|
|
110
|
+
const runs = (await options.store.read()).runs;
|
|
111
|
+
return querySchedulerRuns(runs, jobId, query);
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
return service;
|
|
115
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SchedulerExecutor, SchedulerStore } from "./contracts.js";
|
|
2
|
+
import type { SchedulerRunCompletion } from "./run-completion.js";
|
|
3
|
+
import type { SchedulerSessionDeletionState } from "./session-deletion-state.js";
|
|
4
|
+
export interface SchedulerContext {
|
|
5
|
+
environmentId: string;
|
|
6
|
+
store: SchedulerStore;
|
|
7
|
+
executor: SchedulerExecutor;
|
|
8
|
+
now(): number;
|
|
9
|
+
running: boolean;
|
|
10
|
+
generation: number;
|
|
11
|
+
jobEpochs: Map<string, number>;
|
|
12
|
+
pendingJobMutations: Set<string>;
|
|
13
|
+
deletedSessions: SchedulerSessionDeletionState;
|
|
14
|
+
pendingCompletions: Map<string, SchedulerRunCompletion>;
|
|
15
|
+
enqueue<T>(operation: () => Promise<T>): Promise<T>;
|
|
16
|
+
onError(error: unknown): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function requireRunningScheduler(context: SchedulerContext): void;
|
|
19
|
+
export declare function jobEpoch(context: SchedulerContext, jobId: string): number;
|
|
20
|
+
export declare function invalidateJob(context: SchedulerContext, jobId: string): () => void;
|
|
21
|
+
export declare function canBeginSchedulerRun(context: SchedulerContext, jobId: string, sessionId: string, epoch: number): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function requireRunningScheduler(context) {
|
|
2
|
+
if (!context.running)
|
|
3
|
+
throw new Error("scheduler_not_started");
|
|
4
|
+
}
|
|
5
|
+
export function jobEpoch(context, jobId) {
|
|
6
|
+
return context.jobEpochs.get(jobId) ?? 0;
|
|
7
|
+
}
|
|
8
|
+
export function invalidateJob(context, jobId) {
|
|
9
|
+
const epoch = jobEpoch(context, jobId) + 1;
|
|
10
|
+
context.jobEpochs.set(jobId, epoch);
|
|
11
|
+
context.pendingJobMutations.add(jobId);
|
|
12
|
+
return () => {
|
|
13
|
+
if (jobEpoch(context, jobId) !== epoch)
|
|
14
|
+
return;
|
|
15
|
+
context.pendingJobMutations.delete(jobId);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function canBeginSchedulerRun(context, jobId, sessionId, epoch) {
|
|
19
|
+
if (!context.running)
|
|
20
|
+
return false;
|
|
21
|
+
if (context.deletedSessions.has(sessionId))
|
|
22
|
+
return false;
|
|
23
|
+
if (context.pendingJobMutations.has(jobId))
|
|
24
|
+
return false;
|
|
25
|
+
return jobEpoch(context, jobId) === epoch;
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Accepted deletion survives storage failure; rejected lifecycle calls release intent. */
|
|
2
|
+
export declare class SchedulerSessionDeletionState {
|
|
3
|
+
private readonly confirmed;
|
|
4
|
+
private readonly pending;
|
|
5
|
+
has(sessionId: string): boolean;
|
|
6
|
+
add(sessionId: string): void;
|
|
7
|
+
reserveIntent(sessionId: string): () => void;
|
|
8
|
+
private canReleaseSessionIntents;
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Accepted deletion survives storage failure; rejected lifecycle calls release intent. */
|
|
2
|
+
export class SchedulerSessionDeletionState {
|
|
3
|
+
confirmed = new Set();
|
|
4
|
+
pending = new Map();
|
|
5
|
+
has(sessionId) {
|
|
6
|
+
if (this.confirmed.has(sessionId))
|
|
7
|
+
return true;
|
|
8
|
+
return this.pending.has(sessionId);
|
|
9
|
+
}
|
|
10
|
+
add(sessionId) {
|
|
11
|
+
this.confirmed.add(sessionId);
|
|
12
|
+
}
|
|
13
|
+
reserveIntent(sessionId) {
|
|
14
|
+
const reservations = this.pending.get(sessionId) ?? new Set();
|
|
15
|
+
const intent = Symbol();
|
|
16
|
+
reservations.add(intent);
|
|
17
|
+
this.pending.set(sessionId, reservations);
|
|
18
|
+
return () => {
|
|
19
|
+
reservations.delete(intent);
|
|
20
|
+
if (!this.canReleaseSessionIntents(sessionId, reservations))
|
|
21
|
+
return;
|
|
22
|
+
this.pending.delete(sessionId);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
canReleaseSessionIntents(sessionId, reservations) {
|
|
26
|
+
if (reservations.size > 0)
|
|
27
|
+
return false;
|
|
28
|
+
return this.pending.get(sessionId) === reservations;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SchedulerJob, SchedulerRun, SchedulerSnapshot } from "./contracts.js";
|
|
2
|
+
export declare function parseStoredJob(value: unknown): SchedulerJob;
|
|
3
|
+
export declare function parseStoredRun(value: unknown): SchedulerRun;
|
|
4
|
+
export declare function parseSchedulerSnapshot(value: unknown): SchedulerSnapshot;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { normalizeStoredSchedulerSchedule, validateSchedulerJobInput, validateTimeZone, } from "./schedule-validation.js";
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
if (!value || typeof value !== "object")
|
|
4
|
+
return false;
|
|
5
|
+
return !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function failSnapshot() {
|
|
8
|
+
throw new Error("scheduler_store_corrupt");
|
|
9
|
+
}
|
|
10
|
+
function requireSnapshotInstant(value) {
|
|
11
|
+
if (typeof value !== "string")
|
|
12
|
+
failSnapshot();
|
|
13
|
+
if (!Number.isFinite(Date.parse(value)))
|
|
14
|
+
failSnapshot();
|
|
15
|
+
}
|
|
16
|
+
export function parseStoredJob(value) {
|
|
17
|
+
if (!isRecord(value))
|
|
18
|
+
failSnapshot();
|
|
19
|
+
const job = value;
|
|
20
|
+
validateSchedulerJobInput(job);
|
|
21
|
+
if (!job.id || !job.environmentId)
|
|
22
|
+
failSnapshot();
|
|
23
|
+
if (job.toolPermissionMode !== "full_access")
|
|
24
|
+
failSnapshot();
|
|
25
|
+
if (!["active", "paused", "cancelled", "completed"].includes(job.state))
|
|
26
|
+
failSnapshot();
|
|
27
|
+
if (!Number.isSafeInteger(job.revision))
|
|
28
|
+
failSnapshot();
|
|
29
|
+
requireSnapshotInstant(job.createdAt);
|
|
30
|
+
requireSnapshotInstant(job.updatedAt);
|
|
31
|
+
if (job.nextRunAt !== null)
|
|
32
|
+
requireSnapshotInstant(job.nextRunAt);
|
|
33
|
+
// Canonical storage must not silently synthesize a missing timer/interval anchor.
|
|
34
|
+
if (job.schedule?.kind === "timer" && !job.schedule.at)
|
|
35
|
+
failSnapshot();
|
|
36
|
+
if (job.schedule?.kind === "interval" && !job.schedule.anchorAt)
|
|
37
|
+
failSnapshot();
|
|
38
|
+
const normalized = normalizeStoredSchedulerSchedule(job.schedule);
|
|
39
|
+
return { ...job, schedule: normalized };
|
|
40
|
+
}
|
|
41
|
+
export function parseStoredRun(value) {
|
|
42
|
+
if (!isRecord(value))
|
|
43
|
+
failSnapshot();
|
|
44
|
+
for (const field of [
|
|
45
|
+
"id",
|
|
46
|
+
"jobId",
|
|
47
|
+
"environmentId",
|
|
48
|
+
"sessionId",
|
|
49
|
+
"requestId",
|
|
50
|
+
"title",
|
|
51
|
+
"prompt",
|
|
52
|
+
"modelProfileId",
|
|
53
|
+
"timeZone",
|
|
54
|
+
]) {
|
|
55
|
+
if (typeof value[field] !== "string")
|
|
56
|
+
failSnapshot();
|
|
57
|
+
}
|
|
58
|
+
if (!["fast", "reasoning", "deep"].includes(String(value.agentMode)))
|
|
59
|
+
failSnapshot();
|
|
60
|
+
if (!Number.isSafeInteger(value.jobRevision))
|
|
61
|
+
failSnapshot();
|
|
62
|
+
if (Number(value.jobRevision) < 1)
|
|
63
|
+
failSnapshot();
|
|
64
|
+
validateTimeZone(String(value.timeZone));
|
|
65
|
+
const states = [
|
|
66
|
+
"pending",
|
|
67
|
+
"running",
|
|
68
|
+
"succeeded",
|
|
69
|
+
"failed",
|
|
70
|
+
"cancelled",
|
|
71
|
+
"interrupted",
|
|
72
|
+
"missed",
|
|
73
|
+
];
|
|
74
|
+
if (!states.includes(String(value.status)))
|
|
75
|
+
failSnapshot();
|
|
76
|
+
if (!["schedule", "manual"].includes(String(value.trigger)))
|
|
77
|
+
failSnapshot();
|
|
78
|
+
requireSnapshotInstant(value.scheduledAt);
|
|
79
|
+
if (value.startedAt !== undefined)
|
|
80
|
+
requireSnapshotInstant(value.startedAt);
|
|
81
|
+
if (value.finishedAt !== undefined)
|
|
82
|
+
requireSnapshotInstant(value.finishedAt);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
export function parseSchedulerSnapshot(value) {
|
|
86
|
+
if (!isRecord(value))
|
|
87
|
+
failSnapshot();
|
|
88
|
+
if (value.schemaVersion !== 1)
|
|
89
|
+
failSnapshot();
|
|
90
|
+
if (!Array.isArray(value.jobs))
|
|
91
|
+
failSnapshot();
|
|
92
|
+
if (!Array.isArray(value.runs))
|
|
93
|
+
failSnapshot();
|
|
94
|
+
const jobs = value.jobs.map(parseStoredJob);
|
|
95
|
+
const runs = value.runs.map(parseStoredRun);
|
|
96
|
+
if (new Set(jobs.map((job) => job.id)).size !== jobs.length)
|
|
97
|
+
failSnapshot();
|
|
98
|
+
if (new Set(runs.map((run) => run.id)).size !== runs.length)
|
|
99
|
+
failSnapshot();
|
|
100
|
+
for (const run of runs) {
|
|
101
|
+
const owner = jobs.find((job) => job.id === run.jobId);
|
|
102
|
+
if (!owner)
|
|
103
|
+
failSnapshot();
|
|
104
|
+
if (owner.sessionId !== run.sessionId)
|
|
105
|
+
failSnapshot();
|
|
106
|
+
if (owner.environmentId !== run.environmentId)
|
|
107
|
+
failSnapshot();
|
|
108
|
+
if (run.jobRevision > owner.revision)
|
|
109
|
+
failSnapshot();
|
|
110
|
+
}
|
|
111
|
+
return { schemaVersion: 1, jobs, runs };
|
|
112
|
+
}
|