@lostgradient/weft 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -43
- package/dist/cli/conformance.js +7 -1
- package/dist/cli/generated/operation-client.generated.d.ts +55 -13
- package/dist/cli/generated/operation-client.generated.js +3 -0
- package/dist/cli/help-text.d.ts +1 -1
- package/dist/cli/help-text.js +1 -0
- package/dist/cli/operation-catalog-snapshot.d.ts +8 -0
- package/dist/cli/operation-catalog-snapshot.js +11 -0
- package/dist/cli/parse-schedule-arguments.js +3 -1
- package/dist/cli/schedule.js +2 -1
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli-main.js +80 -79
- package/dist/client/handle-delegation.d.ts +7 -2
- package/dist/client/handle-delegation.js +9 -1
- package/dist/client/http-client-requests.d.ts +4 -1
- package/dist/client/http-client-requests.js +10 -0
- package/dist/client/http-client.d.ts +10 -4
- package/dist/client/http-client.js +18 -1
- package/dist/client/http-request.d.ts +11 -1
- package/dist/client/http-request.js +17 -7
- package/dist/client/index.d.ts +1 -1
- package/dist/client/interface.d.ts +100 -4
- package/dist/client/local.d.ts +7 -1
- package/dist/client/local.js +17 -2
- package/dist/client/start-body.d.ts +9 -2
- package/dist/client/start-body.js +13 -4
- package/dist/core/byte-arrays.d.ts +5 -0
- package/dist/core/byte-arrays.js +5 -0
- package/dist/core/checkpoint/lifecycle.d.ts +3 -0
- package/dist/core/checkpoint/lifecycle.js +9 -4
- package/dist/core/checkpoint/serialization.js +12 -5
- package/dist/core/codec/extension-codec.d.ts +16 -0
- package/dist/core/codec/extension-codec.js +104 -8
- package/dist/core/codec/index.d.ts +1 -0
- package/dist/core/codec/index.js +1 -0
- package/dist/core/codec/serializer-registry.d.ts +122 -0
- package/dist/core/codec/serializer-registry.js +51 -0
- package/dist/core/context/activity-retry-state.d.ts +38 -0
- package/dist/core/context/activity-retry-state.js +89 -0
- package/dist/core/context/activity-schedule-to-close.d.ts +159 -0
- package/dist/core/context/activity-schedule-to-close.js +69 -0
- package/dist/core/context/child-workflow-pipe.d.ts +5 -5
- package/dist/core/context/child-workflow-pipe.js +15 -2
- package/dist/core/context/context-presence.d.ts +19 -0
- package/dist/core/context/context-presence.js +13 -0
- package/dist/core/context/durable-operations.d.ts +25 -0
- package/dist/core/context/durable-operations.js +64 -0
- package/dist/core/context/index.d.ts +18 -5
- package/dist/core/context/index.js +17 -12
- package/dist/core/context/internals.d.ts +29 -0
- package/dist/core/context/internals.js +6 -1
- package/dist/core/context/operation-request.d.ts +35 -0
- package/dist/core/context/parallel-cache-entry.d.ts +14 -5
- package/dist/core/context/run-operation.d.ts +21 -3
- package/dist/core/context/run-operation.js +56 -93
- package/dist/core/context/session-state.js +7 -8
- package/dist/core/context/speculative-child.js +2 -0
- package/dist/core/context/types.d.ts +15 -0
- package/dist/core/context/version-patching.d.ts +8 -0
- package/dist/core/context/version-patching.js +40 -0
- package/dist/core/context/workflow-logger.d.ts +98 -0
- package/dist/core/context/workflow-logger.js +68 -0
- package/dist/core/engine/activity-heartbeat-tracking.d.ts +64 -0
- package/dist/core/engine/activity-heartbeat-tracking.js +42 -0
- package/dist/core/engine/activity-per-attempt-timeout.d.ts +41 -0
- package/dist/core/engine/activity-per-attempt-timeout.js +36 -0
- package/dist/core/engine/activity-reconciliation.d.ts +1 -0
- package/dist/core/engine/activity-reconciliation.js +12 -1
- package/dist/core/engine/activity-resolution.d.ts +23 -0
- package/dist/core/engine/activity-resolution.js +37 -0
- package/dist/core/engine/aggregate.js +66 -30
- package/dist/core/engine/async-activity-completion.d.ts +23 -6
- package/dist/core/engine/async-activity-completion.js +53 -12
- package/dist/core/engine/attributes-tags.js +9 -4
- package/dist/core/engine/bulk-operations-purge.d.ts +26 -0
- package/dist/core/engine/bulk-operations-purge.js +38 -3
- package/dist/core/engine/bulk-operations-shared.d.ts +2 -0
- package/dist/core/engine/bulk-operations-shared.js +8 -2
- package/dist/core/engine/bulk-operations.d.ts +4 -1
- package/dist/core/engine/bulk-operations.js +235 -24
- package/dist/core/engine/callback-creators-bundles.d.ts +9 -0
- package/dist/core/engine/callback-creators-bundles.js +30 -2
- package/dist/core/engine/callback-creators-core.js +6 -4
- package/dist/core/engine/callback-creators-router.js +10 -0
- package/dist/core/engine/callback-creators-schedule.d.ts +2 -2
- package/dist/core/engine/callback-creators-schedule.js +12 -8
- package/dist/core/engine/candidate-read-batching.d.ts +6 -0
- package/dist/core/engine/candidate-read-batching.js +1 -0
- package/dist/core/engine/checkpoint-io.js +61 -25
- package/dist/core/engine/checkpoint-reads.js +3 -2
- package/dist/core/engine/checkpoint-replay.d.ts +20 -0
- package/dist/core/engine/checkpoint-replay.js +242 -0
- package/dist/core/engine/checkpoint-side-effects.d.ts +23 -0
- package/dist/core/engine/checkpoint-side-effects.js +35 -0
- package/dist/core/engine/child-workflow-cancellation.d.ts +10 -0
- package/dist/core/engine/child-workflow-cancellation.js +40 -0
- package/dist/core/engine/child-workflow.js +27 -4
- package/dist/core/engine/condition-waiters.d.ts +14 -0
- package/dist/core/engine/condition-waiters.js +5 -0
- package/dist/core/engine/construction.d.ts +3 -1
- package/dist/core/engine/construction.js +30 -8
- package/dist/core/engine/coordination-branch-executors.d.ts +70 -0
- package/dist/core/engine/coordination-branch-executors.js +107 -0
- package/dist/core/engine/deferred-consume-envelope.d.ts +59 -0
- package/dist/core/engine/deferred-consume-envelope.js +14 -0
- package/dist/core/engine/disposal.js +25 -0
- package/dist/core/engine/engine-create-types.d.ts +14 -18
- package/dist/core/engine/engine-internal-types.d.ts +38 -3
- package/dist/core/engine/engine-leak-warnings.d.ts +6 -0
- package/dist/core/engine/engine-leak-warnings.js +4 -0
- package/dist/core/engine/engine-runtime-helpers.d.ts +17 -0
- package/dist/core/engine/engine-runtime-helpers.js +26 -5
- package/dist/core/engine/errors.d.ts +121 -0
- package/dist/core/engine/errors.js +45 -1
- package/dist/core/engine/event-log-compaction.d.ts +8 -0
- package/dist/core/engine/event-log-compaction.js +20 -2
- package/dist/core/engine/fenced-write.d.ts +65 -0
- package/dist/core/engine/fenced-write.js +71 -0
- package/dist/core/engine/finalizer-state.d.ts +28 -0
- package/dist/core/engine/finalizer-state.js +16 -0
- package/dist/core/engine/handle-result.js +1 -1
- package/dist/core/engine/handles.d.ts +97 -40
- package/dist/core/engine/handles.js +25 -27
- package/dist/core/engine/index.d.ts +125 -15
- package/dist/core/engine/index.js +207 -11
- package/dist/core/engine/inline-launch-queue.d.ts +14 -0
- package/dist/core/engine/inline-launch-queue.js +32 -7
- package/dist/core/engine/inline-parking.js +3 -2
- package/dist/core/engine/internals.d.ts +125 -13
- package/dist/core/engine/lease-codec.d.ts +35 -0
- package/dist/core/engine/lease-codec.js +32 -0
- package/dist/core/engine/lease-deposition.d.ts +66 -0
- package/dist/core/engine/lease-deposition.js +10 -0
- package/dist/core/engine/lease-errors.d.ts +99 -0
- package/dist/core/engine/lease-errors.js +30 -0
- package/dist/core/engine/lease-manager.d.ts +114 -0
- package/dist/core/engine/lease-manager.js +135 -0
- package/dist/core/engine/lifecycle/fork-helpers.js +1 -7
- package/dist/core/engine/lifecycle/persist.js +15 -52
- package/dist/core/engine/lifecycle/recovered-services.d.ts +8 -6
- package/dist/core/engine/lifecycle/recovered-services.js +18 -3
- package/dist/core/engine/lifecycle/resume.js +39 -11
- package/dist/core/engine/lifecycle/shared.d.ts +8 -1
- package/dist/core/engine/lifecycle/start-batch.d.ts +1 -1
- package/dist/core/engine/lifecycle/start-batch.js +2 -1
- package/dist/core/engine/lifecycle/start-commit.d.ts +56 -0
- package/dist/core/engine/lifecycle/start-commit.js +69 -0
- package/dist/core/engine/lifecycle/start-exec.d.ts +30 -2
- package/dist/core/engine/lifecycle/start-exec.js +38 -0
- package/dist/core/engine/lifecycle/start-or-signal-create.d.ts +58 -0
- package/dist/core/engine/lifecycle/start-or-signal-create.js +95 -0
- package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +79 -0
- package/dist/core/engine/lifecycle/start-or-signal-resolution.js +60 -0
- package/dist/core/engine/lifecycle/start-or-signal.d.ts +46 -0
- package/dist/core/engine/lifecycle/start-or-signal.js +71 -0
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +39 -0
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +28 -0
- package/dist/core/engine/lifecycle/start.d.ts +6 -6
- package/dist/core/engine/lifecycle/start.js +47 -45
- package/dist/core/engine/lifecycle/transition.js +17 -5
- package/dist/core/engine/lifecycle.d.ts +3 -2
- package/dist/core/engine/lifecycle.js +9 -2
- package/dist/core/engine/list-candidate-resolution.js +2 -2
- package/dist/core/engine/listing.js +10 -6
- package/dist/core/engine/operations-activity.d.ts +4 -11
- package/dist/core/engine/operations-activity.js +22 -49
- package/dist/core/engine/operations-coordination.d.ts +10 -0
- package/dist/core/engine/operations-coordination.js +43 -8
- package/dist/core/engine/operations-router.d.ts +6 -0
- package/dist/core/engine/operations-router.js +2 -0
- package/dist/core/engine/operations-speculate.js +6 -2
- package/dist/core/engine/operations-stream.js +12 -2
- package/dist/core/engine/operations-time.d.ts +4 -2
- package/dist/core/engine/operations-time.js +14 -2
- package/dist/core/engine/operations-wait-condition.d.ts +23 -0
- package/dist/core/engine/operations-wait-condition.js +62 -0
- package/dist/core/engine/ownership-options.d.ts +23 -0
- package/dist/core/engine/ownership-options.js +26 -0
- package/dist/core/engine/payload-size-policy.d.ts +3 -0
- package/dist/core/engine/payload-size-policy.js +4 -0
- package/dist/core/engine/pending-updates.d.ts +17 -0
- package/dist/core/engine/pending-updates.js +33 -11
- package/dist/core/engine/persisted-data-version.d.ts +5 -9
- package/dist/core/engine/persisted-data-version.js +4 -5
- package/dist/core/engine/queries.js +1 -1
- package/dist/core/engine/registration.d.ts +1 -0
- package/dist/core/engine/registration.js +18 -3
- package/dist/core/engine/schedule-handle.d.ts +45 -0
- package/dist/core/engine/schedule-handle.js +26 -0
- package/dist/core/engine/schedule-jitter.d.ts +5 -0
- package/dist/core/engine/schedule-jitter.js +10 -0
- package/dist/core/engine/schedule-run.d.ts +17 -0
- package/dist/core/engine/schedule-run.js +38 -0
- package/dist/core/engine/schedule-timer.js +81 -17
- package/dist/core/engine/schedules.d.ts +8 -5
- package/dist/core/engine/schedules.js +44 -19
- package/dist/core/engine/search-attribute-records.d.ts +4 -0
- package/dist/core/engine/search-attribute-records.js +17 -0
- package/dist/core/engine/second-instance-detector.d.ts +96 -0
- package/dist/core/engine/second-instance-detector.js +108 -0
- package/dist/core/engine/signals.d.ts +38 -0
- package/dist/core/engine/signals.js +55 -19
- package/dist/core/engine/state-utilities.d.ts +49 -2
- package/dist/core/engine/state-utilities.js +114 -3
- package/dist/core/engine/storage-io.d.ts +16 -2
- package/dist/core/engine/storage-io.js +26 -5
- package/dist/core/engine/stream-chunk-loading.d.ts +2 -0
- package/dist/core/engine/stream-chunk-loading.js +24 -1
- package/dist/core/engine/sub-operation.js +22 -3
- package/dist/core/engine/termination/cleanup.d.ts +28 -1
- package/dist/core/engine/termination/cleanup.js +44 -2
- package/dist/core/engine/termination/complete.js +48 -9
- package/dist/core/engine/termination/finalizer-activity.d.ts +53 -0
- package/dist/core/engine/termination/finalizer-activity.js +30 -0
- package/dist/core/engine/termination/finalizer-claim.d.ts +110 -0
- package/dist/core/engine/termination/finalizer-claim.js +80 -0
- package/dist/core/engine/termination/finalizer.d.ts +48 -0
- package/dist/core/engine/termination/finalizer.js +159 -0
- package/dist/core/engine/termination/suspend.d.ts +70 -0
- package/dist/core/engine/termination/suspend.js +41 -0
- package/dist/core/engine/termination.d.ts +5 -2
- package/dist/core/engine/termination.js +6 -0
- package/dist/core/engine/updates.js +5 -25
- package/dist/core/engine/validation/schedule.d.ts +2 -1
- package/dist/core/engine/validation/schedule.js +51 -2
- package/dist/core/engine/validation.js +54 -3
- package/dist/core/engine/waiting-update-response.d.ts +8 -0
- package/dist/core/engine/waiting-update-response.js +22 -0
- package/dist/core/engine/workflow-concurrency.d.ts +10 -0
- package/dist/core/engine/workflow-concurrency.js +136 -0
- package/dist/core/engine/workflow-feed.d.ts +9 -8
- package/dist/core/engine/workflow-feed.js +4 -1
- package/dist/core/engine/workflow-indexes.d.ts +9 -0
- package/dist/core/engine/workflow-indexes.js +10 -0
- package/dist/core/engine/workflow-state-stream.js +33 -13
- package/dist/core/engine/workflow-visibility-queries.d.ts +2 -2
- package/dist/core/engine-helpers.js +1 -0
- package/dist/core/events/activity-events.d.ts +43 -12
- package/dist/core/events/activity-events.js +28 -0
- package/dist/core/events/attribute-events.d.ts +2 -3
- package/dist/core/events/event-map.d.ts +19 -12
- package/dist/core/events/index.d.ts +1 -0
- package/dist/core/events/index.js +1 -0
- package/dist/core/events/schedule-events.d.ts +71 -0
- package/dist/core/events/schedule-events.js +29 -0
- package/dist/core/events/signal-events.d.ts +4 -6
- package/dist/core/events/system-events.d.ts +29 -19
- package/dist/core/events/system-events.js +26 -0
- package/dist/core/events/update-events.d.ts +6 -8
- package/dist/core/events/workflow-events.d.ts +108 -20
- package/dist/core/events/workflow-events.js +35 -0
- package/dist/core/failure-categories.js +5 -17
- package/dist/core/fault-code.d.ts +9 -3
- package/dist/core/fault-code.js +1 -0
- package/dist/core/inline-execution-strategy.context-options.d.ts +69 -0
- package/dist/core/inline-execution-strategy.context-options.js +56 -0
- package/dist/core/inline-execution-strategy.d.ts +31 -36
- package/dist/core/inline-execution-strategy.js +16 -27
- package/dist/core/list-filter-validation.d.ts +1 -1
- package/dist/core/list-filter-validation.js +2 -1
- package/dist/core/payload-size.d.ts +1 -1
- package/dist/core/persisted-data-incompatible-error.d.ts +9 -7
- package/dist/core/review/events.d.ts +6 -8
- package/dist/core/scheduler/scheduler-class.d.ts +10 -1
- package/dist/core/scheduler/scheduler-class.js +38 -11
- package/dist/core/scheduler/timer-batch.js +9 -1
- package/dist/core/scheduler/timer-sources.d.ts +1 -0
- package/dist/core/scheduler/timer-sources.js +11 -5
- package/dist/core/session-state.d.ts +0 -1
- package/dist/core/session-state.js +2 -2
- package/dist/core/start-workflow-validation.d.ts +56 -0
- package/dist/core/start-workflow-validation.js +30 -1
- package/dist/core/step-context.d.ts +10 -6
- package/dist/core/step-context.js +7 -15
- package/dist/core/types/activity-verification.d.ts +67 -0
- package/dist/core/types/activity-verification.js +0 -0
- package/dist/core/types/activity.d.ts +86 -64
- package/dist/core/types/bulk.d.ts +50 -9
- package/dist/core/types/checkpoint.d.ts +44 -8
- package/dist/core/types/identity.d.ts +8 -1
- package/dist/core/types/launch-metadata.d.ts +33 -0
- package/dist/core/types/launch-metadata.js +0 -0
- package/dist/core/types/list-options.d.ts +146 -0
- package/dist/core/types/list-options.js +0 -0
- package/dist/core/types/message-handles.d.ts +25 -0
- package/dist/core/types/options.d.ts +165 -215
- package/dist/core/types/reviews.d.ts +2 -1
- package/dist/core/types/schedules.d.ts +39 -3
- package/dist/core/types/services-resolution.d.ts +47 -0
- package/dist/core/types/services-resolution.js +0 -0
- package/dist/core/types/state.d.ts +11 -11
- package/dist/core/types/workflow-builder-runtime.d.ts +12 -3
- package/dist/core/types/workflow-builder-runtime.js +11 -2
- package/dist/core/types/workflow-builder.d.ts +47 -15
- package/dist/core/types/workflow-concurrency.d.ts +39 -0
- package/dist/core/types/workflow-concurrency.js +0 -0
- package/dist/core/types/workflow-context.d.ts +157 -14
- package/dist/core/types/workflow-definition.d.ts +53 -10
- package/dist/core/types/workflow-function.d.ts +101 -9
- package/dist/core/types/workflow-log.d.ts +98 -0
- package/dist/core/types/workflow-log.js +0 -0
- package/dist/core/types/workflow-registries.d.ts +14 -3
- package/dist/core/types/workflow-registry.d.ts +3 -0
- package/dist/core/types/workflow-snapshot.d.ts +29 -0
- package/dist/core/types/workflow-snapshot.js +0 -0
- package/dist/core/types.d.ts +7 -0
- package/dist/core/types.js +7 -0
- package/dist/core/versioning.d.ts +9 -39
- package/dist/core/versioning.js +2 -12
- package/dist/core/weft-error.d.ts +44 -1
- package/dist/core/weft-error.js +19 -1
- package/dist/core/worker-execution-strategy-options.d.ts +26 -0
- package/dist/core/worker-execution-strategy.js +40 -36
- package/dist/core/worker-inbound-message.d.ts +38 -0
- package/dist/core/worker-inbound-message.js +37 -0
- package/dist/core/worker-log-abuse-counter.d.ts +175 -0
- package/dist/core/worker-log-abuse-counter.js +107 -0
- package/dist/core/worker-message-helpers.d.ts +47 -0
- package/dist/core/worker-message-helpers.js +26 -0
- package/dist/core/worker-protocol-guard.js +1 -1
- package/dist/core/worker-protocol-log.d.ts +56 -0
- package/dist/core/worker-protocol-log.js +18 -0
- package/dist/core/worker-protocol.d.ts +23 -0
- package/dist/core/worker-protocol.js +12 -2
- package/dist/core/workflow-version-tuple.d.ts +3 -9
- package/dist/core/workflow-version-tuple.js +2 -3
- package/dist/diagnostics/doctor.js +6 -3
- package/dist/diagnostics/format.js +3 -8
- package/dist/diagnostics/types.d.ts +5 -5
- package/dist/diagnostics/validate.d.ts +0 -1
- package/dist/diagnostics/version-check.d.ts +1 -1
- package/dist/diagnostics/version-check.js +10 -13
- package/dist/index.d.ts +13 -11
- package/dist/index.js +39 -4
- package/dist/json-schema.js +3 -3
- package/dist/mcp/cli.js +35 -35
- package/dist/mcp/dispatcher.js +1 -1
- package/dist/mcp/http.js +16 -6
- package/dist/mcp/list-filter.js +2 -1
- package/dist/mcp/protocol.d.ts +2 -0
- package/dist/mcp/protocol.js +1 -1
- package/dist/mcp/session.d.ts +16 -0
- package/dist/mcp/session.js +60 -6
- package/dist/mcp/tools.js +73 -6
- package/dist/observability/index.js +2 -2
- package/dist/server/asyncapi-channels.js +5 -2
- package/dist/server/attribute-filters.d.ts +8 -3
- package/dist/server/attribute-filters.js +6 -1
- package/dist/server/authentication/api-key.d.ts +2 -1
- package/dist/server/authentication/api-key.js +5 -2
- package/dist/server/authentication/constant-time-api-key.d.ts +15 -0
- package/dist/server/authentication/constant-time-api-key.js +24 -0
- package/dist/server/authentication/index.d.ts +1 -1
- package/dist/server/authentication/index.js +7 -4
- package/dist/server/authentication/rotating-api-key-store.d.ts +5 -3
- package/dist/server/authentication/rotating-api-key-store.js +19 -11
- package/dist/server/engine-event-feed-backend.d.ts +4 -5
- package/dist/server/fault-to-http.js +8 -1
- package/dist/server/fault-to-json-rpc.js +1 -0
- package/dist/server/fleet-event-feed.d.ts +31 -0
- package/dist/server/fleet-event-feed.js +157 -0
- package/dist/server/handler/index.js +1 -1
- package/dist/server/handler/response-helpers.js +2 -1
- package/dist/server/handler/route-dispatch.d.ts +6 -3
- package/dist/server/handler/route-dispatch.js +2 -2
- package/dist/server/handler.js +31 -31
- package/dist/server/index.d.ts +32 -2
- package/dist/server/index.js +35 -35
- package/dist/server/interactive-operations.js +1 -0
- package/dist/server/json-rpc-transport-helpers.d.ts +1 -0
- package/dist/server/json-rpc-transport-helpers.js +2 -1
- package/dist/server/json-rpc-websocket-runtime.d.ts +11 -2
- package/dist/server/json-rpc-websocket-runtime.js +1 -0
- package/dist/server/json-rpc-websocket-subscriptions.d.ts +10 -0
- package/dist/server/json-rpc-websocket-subscriptions.js +29 -0
- package/dist/server/json-rpc-websocket-types.d.ts +22 -0
- package/dist/server/json-rpc-websocket-types.js +0 -0
- package/dist/server/json-rpc-websocket-validation.js +20 -4
- package/dist/server/json-rpc-websocket.d.ts +2 -43
- package/dist/server/json-rpc-websocket.js +57 -74
- package/dist/server/openapi.d.ts +2 -1
- package/dist/server/openapi.js +1 -3
- package/dist/server/openrpc-document-schema.d.ts +78 -0
- package/dist/server/openrpc-document-schema.js +27 -1
- package/dist/server/openrpc-errors.d.ts +3 -0
- package/dist/server/openrpc-errors.js +2 -1
- package/dist/server/openrpc.js +32 -0
- package/dist/server/operation-catalog/index.d.ts +1 -1
- package/dist/server/operation-catalog/pipeline-helpers.js +1 -0
- package/dist/server/operation-catalog/pipeline-stages.js +26 -12
- package/dist/server/operation-catalog/pipeline.js +8 -1
- package/dist/server/operation-catalog/registry.js +13 -0
- package/dist/server/operation-catalog/types.d.ts +20 -9
- package/dist/server/operation-fault.d.ts +10 -0
- package/dist/server/operation-fault.js +2 -0
- package/dist/server/operation-registry.d.ts +12 -11
- package/dist/server/operation-registry.js +12 -3
- package/dist/server/operations/aggregate-workflows.d.ts +15 -15
- package/dist/server/operations/async-activity.d.ts +2 -2
- package/dist/server/operations/async-activity.js +12 -7
- package/dist/server/operations/bulk-cancel-workflows.d.ts +1 -1
- package/dist/server/operations/bulk-cancel-workflows.js +2 -2
- package/dist/server/operations/bulk-delete-workflows.d.ts +1 -1
- package/dist/server/operations/bulk-delete-workflows.js +2 -2
- package/dist/server/operations/bulk-filter-helpers.d.ts +8 -6
- package/dist/server/operations/bulk-filter-helpers.js +54 -24
- package/dist/server/operations/bulk-mutate-workflow-tags.d.ts +11 -9
- package/dist/server/operations/bulk-mutate-workflow-tags.js +2 -2
- package/dist/server/operations/bulk-operation-helpers.d.ts +2 -2
- package/dist/server/operations/bulk-retry-failed-workflows.d.ts +7 -0
- package/dist/server/operations/bulk-retry-failed-workflows.js +64 -0
- package/dist/server/operations/bulk-signal-workflows.d.ts +11 -9
- package/dist/server/operations/bulk-signal-workflows.js +2 -2
- package/dist/server/operations/cancel-schedule.d.ts +1 -1
- package/dist/server/operations/create-schedule.d.ts +3 -1
- package/dist/server/operations/create-schedule.js +29 -11
- package/dist/server/operations/fleet-events-subscription.d.ts +54 -0
- package/dist/server/operations/fleet-events-subscription.js +99 -0
- package/dist/server/operations/fork-workflow.d.ts +1 -1
- package/dist/server/operations/fork-workflow.js +3 -2
- package/dist/server/operations/get-checkpoint-at.d.ts +1 -1
- package/dist/server/operations/get-registry.d.ts +1 -1
- package/dist/server/operations/get-retention-overview.d.ts +1 -1
- package/dist/server/operations/get-review.d.ts +1 -1
- package/dist/server/operations/get-schedule.d.ts +1 -1
- package/dist/server/operations/get-stream-chunks.d.ts +1 -1
- package/dist/server/operations/get-system-metrics.d.ts +2 -2
- package/dist/server/operations/get-task-diagnostics.d.ts +45 -6
- package/dist/server/operations/get-task-diagnostics.js +101 -7
- package/dist/server/operations/get-update-result.d.ts +1 -1
- package/dist/server/operations/get-workflow-attributes.d.ts +1 -1
- package/dist/server/operations/get-workflow-events.d.ts +1 -1
- package/dist/server/operations/get-workflow-result.d.ts +1 -1
- package/dist/server/operations/get-workflow-timeline.d.ts +1 -1
- package/dist/server/operations/get-workflow.d.ts +1 -1
- package/dist/server/operations/list-checkpoints.d.ts +1 -1
- package/dist/server/operations/list-reviews.d.ts +1 -1
- package/dist/server/operations/list-schedules.d.ts +1 -1
- package/dist/server/operations/list-task-queues.d.ts +2 -2
- package/dist/server/operations/list-workers.d.ts +2 -2
- package/dist/server/operations/list-workflows.d.ts +1 -1
- package/dist/server/operations/operation-helpers.d.ts +16 -1
- package/dist/server/operations/operation-helpers.js +15 -3
- package/dist/server/operations/pause-schedule.d.ts +1 -1
- package/dist/server/operations/purge-workflows.d.ts +5 -5
- package/dist/server/operations/purge-workflows.js +2 -2
- package/dist/server/operations/query-workflow.d.ts +1 -1
- package/dist/server/operations/query-workflow.js +3 -2
- package/dist/server/operations/recover-all.d.ts +1 -1
- package/dist/server/operations/replay-workflow.d.ts +1 -1
- package/dist/server/operations/resume-schedule.d.ts +1 -1
- package/dist/server/operations/resume-workflow.js +2 -2
- package/dist/server/operations/set-workflow-attributes.d.ts +1 -1
- package/dist/server/operations/set-workflow-attributes.js +6 -3
- package/dist/server/operations/signal-workflow.js +8 -3
- package/dist/server/operations/single-workflow-tag-mutation.js +13 -3
- package/dist/server/operations/start-or-signal-workflow.d.ts +44 -0
- package/dist/server/operations/start-or-signal-workflow.js +130 -0
- package/dist/server/operations/start-workflow-options.d.ts +38 -0
- package/dist/server/operations/start-workflow-options.js +63 -0
- package/dist/server/operations/start-workflow-rest-input.d.ts +14 -0
- package/dist/server/operations/start-workflow-rest-input.js +31 -0
- package/dist/server/operations/start-workflow.d.ts +1 -1
- package/dist/server/operations/start-workflow.js +15 -92
- package/dist/server/operations/storage.d.ts +6 -6
- package/dist/server/operations/storage.js +24 -14
- package/dist/server/operations/stream-workflow-sse.d.ts +1 -1
- package/dist/server/operations/submit-review-decision.d.ts +1 -1
- package/dist/server/operations/submit-review-decision.js +6 -3
- package/dist/server/operations/suspend-workflow.d.ts +13 -0
- package/dist/server/operations/suspend-workflow.js +36 -0
- package/dist/server/operations/update-schedule.d.ts +1 -1
- package/dist/server/operations/update-schedule.js +7 -4
- package/dist/server/operations/update-workflow.d.ts +1 -1
- package/dist/server/operations/update-workflow.js +7 -3
- package/dist/server/operations/worker-drain.d.ts +8 -8
- package/dist/server/operations/worker-drain.js +11 -8
- package/dist/server/operations/workflow-events-subscription.d.ts +7 -8
- package/dist/server/operations/workflow-events-subscription.js +43 -8
- package/dist/server/rest-binding.d.ts +21 -8
- package/dist/server/rest-bindings.js +24 -0
- package/dist/server/rest-body.d.ts +10 -0
- package/dist/server/rest-body.js +80 -0
- package/dist/server/runtime/authentication-bridge.d.ts +1 -0
- package/dist/server/runtime/authentication-bridge.js +33 -6
- package/dist/server/runtime/client-visible-events.d.ts +3 -0
- package/dist/server/runtime/client-visible-events.js +65 -0
- package/dist/server/runtime/context.d.ts +7 -0
- package/dist/server/runtime/event-broadcasting.d.ts +6 -0
- package/dist/server/runtime/event-broadcasting.js +72 -38
- package/dist/server/runtime/retry.d.ts +1 -0
- package/dist/server/runtime/retry.js +14 -0
- package/dist/server/runtime/shutdown.d.ts +7 -6
- package/dist/server/runtime/shutdown.js +6 -1
- package/dist/server/runtime/task-dispatch.js +5 -3
- package/dist/server/runtime/task-polling.d.ts +16 -2
- package/dist/server/runtime/task-polling.js +80 -24
- package/dist/server/runtime/task-reconciliation.js +9 -1
- package/dist/server/runtime/task-result-resolution.d.ts +15 -0
- package/dist/server/runtime/task-result-resolution.js +81 -0
- package/dist/server/runtime/websocket-stream.d.ts +20 -1
- package/dist/server/runtime/websocket-stream.js +173 -7
- package/dist/server/runtime/websocket-upgrade.js +22 -3
- package/dist/server/runtime/websocket-worker.d.ts +1 -1
- package/dist/server/runtime/websocket-worker.js +46 -30
- package/dist/server/serve-internals.d.ts +11 -1
- package/dist/server/serve-internals.js +20 -2
- package/dist/server/task-state.d.ts +38 -0
- package/dist/server/task-state.js +28 -0
- package/dist/server/workflow-event-feed.d.ts +36 -115
- package/dist/server/workflow-event-feed.js +92 -27
- package/dist/service-worker/index.js +31 -31
- package/dist/storage/auto.js +1 -1
- package/dist/storage/bun-sql.js +24 -0
- package/dist/storage/capabilities.d.ts +10 -2
- package/dist/storage/capabilities.js +2 -2
- package/dist/storage/compressed-storage.js +1 -1
- package/dist/storage/default-scope.d.ts +7 -4
- package/dist/storage/http.js +2 -2
- package/dist/storage/index.d.ts +81 -4
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/interface.d.ts +189 -0
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +12 -0
- package/dist/storage/lmdb.d.ts +4 -3
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon-batch.d.ts +30 -0
- package/dist/storage/neon-batch.js +30 -0
- package/dist/storage/neon-value-mapping.d.ts +74 -0
- package/dist/storage/neon-value-mapping.js +23 -0
- package/dist/storage/neon.d.ts +124 -0
- package/dist/storage/neon.js +15 -0
- package/dist/storage/node-sqlite-loader.d.ts +71 -0
- package/dist/storage/node-sqlite-loader.js +41 -0
- package/dist/storage/node-sqlite.d.ts +1 -19
- package/dist/storage/node-sqlite.js +61 -32
- package/dist/storage/postgres-key-value-queries.d.ts +104 -0
- package/dist/storage/postgres-key-value-queries.js +101 -0
- package/dist/storage/resolve.d.ts +2 -165
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/storage-configuration.d.ts +209 -0
- package/dist/storage/storage-configuration.js +0 -0
- package/dist/storage/testing.d.ts +168 -0
- package/dist/storage/testing.js +2 -0
- package/dist/storage/text-value-store.d.ts +9 -9
- package/dist/storage/turso.d.ts +8 -0
- package/dist/storage/turso.js +2 -2
- package/dist/storage/typed-storage.js +1 -1
- package/dist/storage/web-extension.js +1 -1
- package/dist/testing/index.js +35 -35
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/index.js +9 -5
- package/dist/worker/long-poll.js +4 -0
- package/dist/worker/protocol-messages.d.ts +20 -0
- package/dist/worker/protocol-schemas.d.ts +32 -0
- package/dist/worker/protocol-schemas.js +8 -4
- package/dist/worker/protocol-task-result.d.ts +28 -0
- package/dist/worker/protocol-task-result.js +76 -0
- package/dist/worker/protocol.d.ts +4 -15
- package/dist/worker/protocol.js +1 -1
- package/dist/worker/registry/fair-share.d.ts +29 -0
- package/dist/worker/registry/fair-share.js +30 -0
- package/dist/worker/registry/routing.d.ts +18 -0
- package/dist/worker/registry/routing.js +14 -0
- package/dist/worker/registry/types.d.ts +7 -0
- package/dist/worker/registry.d.ts +16 -1
- package/dist/worker/registry.js +24 -36
- package/dist/workers/worker-replay-state.d.ts +32 -0
- package/dist/workers/worker-replay-state.js +35 -0
- package/dist/workers/worker-state-namespace.d.ts +21 -0
- package/dist/workers/worker-state-namespace.js +13 -0
- package/dist/workers/workflow-runner.d.ts +19 -15
- package/dist/workers/workflow-runner.js +72 -60
- package/dist/workers/workflow-worker-entry.js +5 -2
- package/package.json +21 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { KEYS, storageConditionalBatch } from "../../storage/interface.js";
|
|
2
|
+
import { decodeEpoch } from "./lease-codec.js";
|
|
3
|
+
import { handleDeposition } from "./lease-deposition.js";
|
|
4
|
+
import { EngineDeposedError, EngineLeaseNotHeldError } from "./lease-errors.js";
|
|
5
|
+
export function assertLeaseHeldForEngineWork(internals) {
|
|
6
|
+
if (internals.options.ownershipMode !== "lease")
|
|
7
|
+
return;
|
|
8
|
+
if (!(!internals.deposed && internals.leaseManager !== null && internals.leaseManager.currentEpochBytes() !== null))
|
|
9
|
+
throw new EngineLeaseNotHeldError;
|
|
10
|
+
}
|
|
11
|
+
async function fencedCommit(internals, operations, baseConditions) {
|
|
12
|
+
const epochBytes = resolveFenceEpochOrHalt(internals);
|
|
13
|
+
if (epochBytes === null) {
|
|
14
|
+
if (baseConditions.length === 0) {
|
|
15
|
+
await internals.storage.batch(operations);
|
|
16
|
+
return "committed";
|
|
17
|
+
}
|
|
18
|
+
return await storageConditionalBatch(internals.storage, baseConditions, operations) ? "committed" : "lost-race";
|
|
19
|
+
}
|
|
20
|
+
const conditions = [
|
|
21
|
+
...baseConditions,
|
|
22
|
+
{ key: KEYS.leaseEpoch(), expectedValue: epochBytes }
|
|
23
|
+
];
|
|
24
|
+
if (await storageConditionalBatch(internals.storage, conditions, operations))
|
|
25
|
+
return "committed";
|
|
26
|
+
if (await isDeposed(internals, epochBytes)) {
|
|
27
|
+
handleDeposition(internals);
|
|
28
|
+
throw new EngineDeposedError;
|
|
29
|
+
}
|
|
30
|
+
return "lost-race";
|
|
31
|
+
}
|
|
32
|
+
function resolveFenceEpochOrHalt(internals) {
|
|
33
|
+
if (internals.deposed)
|
|
34
|
+
throw new EngineDeposedError;
|
|
35
|
+
if (internals.options.ownershipMode !== "lease")
|
|
36
|
+
return null;
|
|
37
|
+
const epochBytes = internals.leaseManager?.currentEpochBytes() ?? null;
|
|
38
|
+
if (epochBytes === null) {
|
|
39
|
+
handleDeposition(internals);
|
|
40
|
+
throw new EngineDeposedError;
|
|
41
|
+
}
|
|
42
|
+
return epochBytes;
|
|
43
|
+
}
|
|
44
|
+
export async function commitFencedEngineWrite(internals, operations, baseConditions, onLostRace) {
|
|
45
|
+
if (await fencedCommit(internals, operations, baseConditions) === "lost-race")
|
|
46
|
+
throw onLostRace();
|
|
47
|
+
}
|
|
48
|
+
export async function commitFencedEngineWriteAllowingPreconditionFailure(internals, operations, baseConditions) {
|
|
49
|
+
return await fencedCommit(internals, operations, baseConditions) === "committed";
|
|
50
|
+
}
|
|
51
|
+
function epochBytesEqual(a, b) {
|
|
52
|
+
if (b === null || a.byteLength !== b.byteLength)
|
|
53
|
+
return !1;
|
|
54
|
+
for (let index = 0;index < a.byteLength; index += 1)
|
|
55
|
+
if (a[index] !== b[index])
|
|
56
|
+
return !1;
|
|
57
|
+
return !0;
|
|
58
|
+
}
|
|
59
|
+
async function isDeposed(internals, heldEpochBytes) {
|
|
60
|
+
let currentEpochRaw;
|
|
61
|
+
try {
|
|
62
|
+
currentEpochRaw = await internals.storage.get(KEYS.leaseEpoch());
|
|
63
|
+
} catch {
|
|
64
|
+
return !0;
|
|
65
|
+
}
|
|
66
|
+
if (currentEpochRaw === null)
|
|
67
|
+
return !0;
|
|
68
|
+
if (decodeEpoch(currentEpochRaw) === null)
|
|
69
|
+
return !0;
|
|
70
|
+
return !epochBytesEqual(heldEpochBytes, currentEpochRaw);
|
|
71
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EngineInternals } from './internals.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Engine-side handler for `ctx.setFinalizerState(value)` (issue #446). Durably
|
|
4
|
+
* records the payload associated with the workflow's definition-level
|
|
5
|
+
* `finalizer` activity.
|
|
6
|
+
*
|
|
7
|
+
* This handler only records the value; the engine passes the decoded payload as
|
|
8
|
+
* the finalizer's input when it drives cancel/timeout teardown (#446 Phase 2).
|
|
9
|
+
*
|
|
10
|
+
* The value is staged as a pending atomic side-effect — a `put` of
|
|
11
|
+
* {@link KEYS.finalizerState} — that commits with whichever durable write lands
|
|
12
|
+
* first: the next checkpoint/suspend commit, or, if no checkpoint runs before the
|
|
13
|
+
* workflow terminates, the terminal `updateWorkflowState` batch
|
|
14
|
+
* (`includePendingAtomicSideEffects` is set for terminal transitions). Either way
|
|
15
|
+
* the resource id is durable before teardown is driven: a cancel arriving before
|
|
16
|
+
* the next checkpoint still flushes the staged op in the terminal batch, so the
|
|
17
|
+
* finalizer always sees the resource id. The staged op inherits the lease-epoch
|
|
18
|
+
* fence (#470) for free, since checkpoint and terminal commits route through
|
|
19
|
+
* `commitFencedWorkflowStateOperations`.
|
|
20
|
+
*
|
|
21
|
+
* Oversized payloads are rejected before staging (the same hostile-input guard
|
|
22
|
+
* activity results use). A call made once the workflow is already terminalizing
|
|
23
|
+
* — e.g. from an `onCancel` handler, which runs after the terminal batch has
|
|
24
|
+
* already taken the pending side-effects — is a no-op: the staged op has no
|
|
25
|
+
* future commit to ride and is cleared on terminal cleanup. A development
|
|
26
|
+
* warning is emitted so the footgun is visible, but no error is thrown.
|
|
27
|
+
*/
|
|
28
|
+
export declare function recordFinalizerState(internals: EngineInternals, workflowId: string, value: unknown): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { KEYS } from "../../storage/interface.js";
|
|
2
|
+
import { encode } from "../codec.js";
|
|
3
|
+
import { assertPayloadWithinLimit } from "../payload-size.js";
|
|
4
|
+
import { stageAtomicWorkflowCommitSideEffects } from "./checkpoint-side-effects.js";
|
|
5
|
+
export function recordFinalizerState(internals, workflowId, value) {
|
|
6
|
+
if (internals.terminalizingWorkflows.has(workflowId)) {
|
|
7
|
+
if (internals.options.development)
|
|
8
|
+
console.warn(`[weft] ctx.setFinalizerState() called for workflow "${workflowId}" after it began terminalizing; the value is ignored. Record finalizer state while the workflow is still running.`);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
assertPayloadWithinLimit(value, internals.options.payloadSizePolicy.maxBytes, "finalizer state");
|
|
12
|
+
stageAtomicWorkflowCommitSideEffects(internals, workflowId, {
|
|
13
|
+
conditions: [],
|
|
14
|
+
operations: [{ type: "put", key: KEYS.finalizerState(workflowId), value: encode(value) }]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -35,7 +35,7 @@ export async function bootstrapWorkflowResultResolver(internals, workflowId, wai
|
|
|
35
35
|
waiter.reject(Error(`Workflow "${workflowId}" not found in storage`));
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
if (state.status === "running" || state.status === "pending")
|
|
38
|
+
if (state.status === "running" || state.status === "pending" || state.status === "suspended")
|
|
39
39
|
return;
|
|
40
40
|
try {
|
|
41
41
|
const result = await loadWorkflowResult(internals, workflowId);
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LaunchMetadata, QueryDefinition, SearchAttributeValue, SignalDefinition, SignalDeliveryOptions, UpdateDefinition, WorkflowState } from '../types.ts';
|
|
2
|
+
import type { WorkflowSnapshot } from '../types/workflow-snapshot.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Which atomic path a `startOrSignal` call took, returned alongside the
|
|
5
|
+
* {@link WorkflowHandle} in `StartOrSignalResult` (not a field on the handle —
|
|
6
|
+
* converged concurrent callers share one cached engine handle, so the outcome
|
|
7
|
+
* rides the per-call result instead). `'started'` when the call created the
|
|
8
|
+
* run, `'signalled'` when it delivered a signal to a run that already existed.
|
|
9
|
+
*/
|
|
10
|
+
export type StartOrSignalOutcome = 'started' | 'signalled';
|
|
2
11
|
export declare function getWorkflowExecutionStartedAt(state: Pick<WorkflowState, 'createdAt' | 'startedAt'>): number;
|
|
3
12
|
export declare const HANDLE_RESULT_PROMISE: unique symbol;
|
|
4
13
|
export interface WorkflowHandleEngine extends EventTarget {
|
|
5
14
|
[HANDLE_RESULT_PROMISE](workflowId: string): Promise<unknown>;
|
|
6
15
|
cancel(workflowId: string): Promise<void>;
|
|
16
|
+
suspend(workflowId: string): Promise<void>;
|
|
17
|
+
resume(workflowId: string): Promise<WorkflowHandle>;
|
|
7
18
|
signal(workflowId: string, name: string, payload?: unknown, options?: SignalDeliveryOptions): Promise<void>;
|
|
8
19
|
update(workflowId: string, name: string, payload?: unknown, options?: {
|
|
9
20
|
timeout?: number;
|
|
@@ -14,13 +25,13 @@ export interface WorkflowHandleEngine extends EventTarget {
|
|
|
14
25
|
addTags(workflowId: string, ...tags: string[]): Promise<void>;
|
|
15
26
|
removeTags(workflowId: string, ...tags: string[]): Promise<void>;
|
|
16
27
|
get(workflowId: string): Promise<WorkflowState | null>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Current checkpoint step (the run's cursor) for a workflow, or `null` when no
|
|
30
|
+
* checkpoint exists. Reads the in-memory checkpoint when the run is live in
|
|
31
|
+
* this engine, otherwise the durably persisted checkpoint — so it is correct
|
|
32
|
+
* for both an in-flight run and one recovered or inspected in a fresh process.
|
|
33
|
+
*/
|
|
34
|
+
getCurrentCheckpointStep(workflowId: string): Promise<number | null>;
|
|
24
35
|
}
|
|
25
36
|
/**
|
|
26
37
|
* Handle to a running or completed workflow. Returned by {@link Engine.start}
|
|
@@ -72,6 +83,84 @@ export declare class WorkflowHandle<TResult = unknown> extends EventTarget imple
|
|
|
72
83
|
constructor(id: string, engine: WorkflowHandleEngine);
|
|
73
84
|
result(): Promise<TResult>;
|
|
74
85
|
cancel(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Suspend this workflow without terminating it: it transitions to the
|
|
88
|
+
* non-terminal `'suspended'` status, keeps its durable checkpoint, and is
|
|
89
|
+
* later resumable via {@link WorkflowHandle.resume}. Unlike `cancel()`, this
|
|
90
|
+
* does not run cancel handlers and does not settle `result()` — the result
|
|
91
|
+
* promise stays pending until a later `resume()` completes the run. A
|
|
92
|
+
* suspended workflow is NOT auto-recovered by `engine.recoverAll()`; resume it
|
|
93
|
+
* explicitly. Suspending a workflow that is not running is a no-op.
|
|
94
|
+
*/
|
|
95
|
+
suspend(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Resume this workflow from its persisted checkpoint after it was suspended
|
|
98
|
+
* (or left `'running'` by a prior process). The run is re-driven on this
|
|
99
|
+
* engine; `result()` on this handle resolves when the resumed run completes.
|
|
100
|
+
* Throws if the workflow is in a status that cannot be resumed (terminal,
|
|
101
|
+
* pending, or not found).
|
|
102
|
+
*/
|
|
103
|
+
resume(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Reconstruct this workflow's launch context — its original `input` and the
|
|
106
|
+
* launch options recoverable from durable state — from the persisted
|
|
107
|
+
* {@link WorkflowState}. Resolves `null` if the workflow no longer exists
|
|
108
|
+
* (never started, or purged).
|
|
109
|
+
*
|
|
110
|
+
* Designed for the post-`recoverAll()` case: a recovered handle can recover
|
|
111
|
+
* the input a run was started with (and its `id`/`tags`) without the caller
|
|
112
|
+
* keeping a side table correlating recovered workflows back to their launch
|
|
113
|
+
* context. This is an async read (it loads state) so it behaves identically
|
|
114
|
+
* on handles from `start()`, `recoverAll()`, and `getHandle()` — none of which
|
|
115
|
+
* is special-cased — rather than a sync property that would be `undefined` on
|
|
116
|
+
* a handle created without a state load.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { Engine } from '@lostgradient/weft';
|
|
121
|
+
*
|
|
122
|
+
* const engine = new Engine();
|
|
123
|
+
* const handles = await engine.recoverAll();
|
|
124
|
+
* for (const handle of handles) {
|
|
125
|
+
* const metadata = await handle.getLaunchMetadata();
|
|
126
|
+
* if (metadata) {
|
|
127
|
+
* // rebuild this run's dependencies from metadata.input
|
|
128
|
+
* void metadata.input;
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
getLaunchMetadata(): Promise<LaunchMetadata | null>;
|
|
134
|
+
/**
|
|
135
|
+
* A point-in-time view of this workflow's progress: its status and current
|
|
136
|
+
* checkpoint step (cursor). Resolves `null` if the workflow no longer exists.
|
|
137
|
+
* The `status` matches `engine.get(id)` — notably it reports `'pending'` for a
|
|
138
|
+
* run whose inline start is still queued, even though its persisted status is
|
|
139
|
+
* `'running'`.
|
|
140
|
+
*
|
|
141
|
+
* Designed for observing a recovered run: after `engine.recoverAll()`, a
|
|
142
|
+
* caller can read where a resumed run currently is — and rebuild its own
|
|
143
|
+
* progress adapter to re-register the run on a live surface — without waiting
|
|
144
|
+
* for the run's final `result()`. It is an async read (loads state +
|
|
145
|
+
* checkpoint), so it behaves identically on handles from `start()`,
|
|
146
|
+
* `recoverAll()`, and `getHandle()`.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { Engine } from '@lostgradient/weft';
|
|
151
|
+
*
|
|
152
|
+
* const engine = new Engine();
|
|
153
|
+
* const handles = await engine.recoverAll();
|
|
154
|
+
* for (const handle of handles) {
|
|
155
|
+
* const snapshot = await handle.snapshot();
|
|
156
|
+
* if (snapshot) {
|
|
157
|
+
* // re-register a progress adapter at snapshot.step
|
|
158
|
+
* void snapshot.step;
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
snapshot(): Promise<WorkflowSnapshot | null>;
|
|
75
164
|
signal(name: SignalDefinition): Promise<void>;
|
|
76
165
|
signal<TInput>(name: SignalDefinition<TInput>, payload: TInput, options?: SignalDeliveryOptions): Promise<void>;
|
|
77
166
|
signal(name: string, payload?: unknown, options?: SignalDeliveryOptions): Promise<void>;
|
|
@@ -103,35 +192,3 @@ export declare class WorkflowHandle<TResult = unknown> extends EventTarget imple
|
|
|
103
192
|
};
|
|
104
193
|
[Symbol.asyncDispose](): Promise<void>;
|
|
105
194
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Handle to a recurring schedule created by {@link Engine.schedule}. Use
|
|
108
|
-
* `handle.pause()`, `handle.resume()`, `handle.cancel()`, or
|
|
109
|
-
* `handle.update(cronExpression)` to manage the schedule lifecycle.
|
|
110
|
-
* `handle.describe()` returns the current {@link ScheduleSummary}.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```ts
|
|
114
|
-
* import { workflow, Engine, ScheduleHandle } from '@lostgradient/weft';
|
|
115
|
-
*
|
|
116
|
-
* const engine = new Engine();
|
|
117
|
-
* engine.register(workflow({ name: 'daily-report' }).execute(async function* () { return 'ok'; }));
|
|
118
|
-
*
|
|
119
|
-
* const handle = await engine.schedule('daily-report', null, '0 9 * * *');
|
|
120
|
-
* const typedHandle: ScheduleHandle = handle;
|
|
121
|
-
* await handle.pause();
|
|
122
|
-
* const summary = await handle.describe();
|
|
123
|
-
* void typedHandle;
|
|
124
|
-
* console.log(summary.status); // 'paused'
|
|
125
|
-
* await handle.cancel();
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
export declare class ScheduleHandle {
|
|
129
|
-
#private;
|
|
130
|
-
readonly id: string;
|
|
131
|
-
constructor(id: string, engine: ScheduleHandleEngine);
|
|
132
|
-
pause(): Promise<void>;
|
|
133
|
-
resume(): Promise<void>;
|
|
134
|
-
cancel(): Promise<void>;
|
|
135
|
-
update(newSpec: string | ScheduleSpec): Promise<void>;
|
|
136
|
-
describe(): Promise<ScheduleSummary>;
|
|
137
|
-
}
|
|
@@ -51,6 +51,31 @@ export class WorkflowHandle extends EventTarget {
|
|
|
51
51
|
async cancel() {
|
|
52
52
|
return this.#engine.cancel(this.id);
|
|
53
53
|
}
|
|
54
|
+
async suspend() {
|
|
55
|
+
return this.#engine.suspend(this.id);
|
|
56
|
+
}
|
|
57
|
+
async resume() {
|
|
58
|
+
await this.#engine.resume(this.id);
|
|
59
|
+
}
|
|
60
|
+
async getLaunchMetadata() {
|
|
61
|
+
const state = await this.#engine.get(this.id);
|
|
62
|
+
if (state === null)
|
|
63
|
+
return null;
|
|
64
|
+
return {
|
|
65
|
+
input: state.input,
|
|
66
|
+
launchOptions: {
|
|
67
|
+
id: state.id,
|
|
68
|
+
...state.tags !== void 0 && state.tags.length > 0 && { tags: state.tags }
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async snapshot() {
|
|
73
|
+
const state = await this.#engine.get(this.id);
|
|
74
|
+
if (state === null)
|
|
75
|
+
return null;
|
|
76
|
+
const step = await this.#engine.getCurrentCheckpointStep(this.id);
|
|
77
|
+
return { status: state.status, step: step ?? 0 };
|
|
78
|
+
}
|
|
54
79
|
async signal(nameOrDefinition, payload, options) {
|
|
55
80
|
return this.#engine.signal(this.id, messageName(nameOrDefinition), payload, options);
|
|
56
81
|
}
|
|
@@ -144,30 +169,3 @@ export class WorkflowHandle extends EventTarget {
|
|
|
144
169
|
}
|
|
145
170
|
async[Symbol.asyncDispose]() {}
|
|
146
171
|
}
|
|
147
|
-
|
|
148
|
-
export class ScheduleHandle {
|
|
149
|
-
id;
|
|
150
|
-
#engine;
|
|
151
|
-
constructor(id, engine) {
|
|
152
|
-
this.id = id;
|
|
153
|
-
this.#engine = engine;
|
|
154
|
-
}
|
|
155
|
-
async pause() {
|
|
156
|
-
await this.#engine.pauseSchedule(this.id);
|
|
157
|
-
}
|
|
158
|
-
async resume() {
|
|
159
|
-
await this.#engine.resumeSchedule(this.id);
|
|
160
|
-
}
|
|
161
|
-
async cancel() {
|
|
162
|
-
await this.#engine.cancelSchedule(this.id);
|
|
163
|
-
}
|
|
164
|
-
async update(newSpec) {
|
|
165
|
-
await this.#engine.updateSchedule(this.id, newSpec);
|
|
166
|
-
}
|
|
167
|
-
async describe() {
|
|
168
|
-
const schedule = await this.#engine.getSchedule(this.id);
|
|
169
|
-
if (!schedule)
|
|
170
|
-
throw Error(`Schedule "${this.id}" not found`);
|
|
171
|
-
return schedule;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
import { type Storage as WeftStorage } from '../../storage/interface.ts';
|
|
2
2
|
import { type ActivityMetadata, type ActivityRegistrationOptions, type RegisteredActivityFunction } from '../activity-registry.ts';
|
|
3
3
|
import type { StoredStreamChunk } from '../context.ts';
|
|
4
|
+
import type { TypedEventTarget, WeftEventMap } from '../events.ts';
|
|
4
5
|
import type { Interceptor } from '../interceptor.ts';
|
|
5
6
|
import { type ReviewRequest } from '../review/index.ts';
|
|
6
7
|
import { Scheduler } from '../scheduler.ts';
|
|
7
|
-
import { type AnyActivityDefinition, type AnyWorkflowDefinition, type AttributeFilterKey, type BulkCancelResult, type BulkDeleteResult, type BulkOperationCommitOptions, type BulkOperationDryRunOptions, type BulkOperationDryRunResult, type BulkSignalAllCommitOptions, type BulkSignalAllDryRunOptions, type BulkSignalResult, type BulkTagResult, type CheckpointState, type CheckpointSummary, type CoordinatedUpdateResult, type DefaultActivityTypes, type DefaultWorkflowRegistry, type ForkOptions, type InferActivityEntries, type InferActivityEntry, type InferWorkflowEntries, type InferWorkflowEntry, type ListFilter, type ListOptions, type PaginatedResult, type PurgeResult, type QueryDefinition, type RegisteredWorkflowDefinition, type RetentionOverview, type ReviewListEntry, type ReviewListFilter, type ScheduleDefinition, type ScheduleFilter, type ScheduleOptions, type ScheduleSpec, type ScheduleSummary, type SearchAttributeValue, type SignalDefinition, type SignalDeliveryOptions, type StartOptions, type SubmitReviewOptions, type TypedListFilter, type UpdateDefinition, type WorkflowEvent, type WorkflowInput, type WorkflowOutput, type WorkflowReplay, type WorkflowState, type WorkflowSummary, type WorkflowTimelineEntry } from '../types.ts';
|
|
8
|
+
import { type AnyActivityDefinition, type AnyWorkflowDefinition, type AttributeFilterKey, type BulkCancelResult, type BulkDeleteResult, type BulkOperationCommitOptions, type BulkOperationDryRunOptions, type BulkOperationDryRunResult, type BulkRetryFailedResult, type BulkSignalAllCommitOptions, type BulkSignalAllDryRunOptions, type BulkSignalResult, type BulkTagResult, type CheckpointState, type CheckpointSummary, type CoordinatedUpdateResult, type DefaultActivityTypes, type DefaultWorkflowRegistry, type ForkOptions, type InferActivityEntries, type InferActivityEntry, type InferWorkflowEntries, type InferWorkflowEntry, type ListFilter, type ListOptions, type PaginatedResult, type PurgeResult, type QueryDefinition, type RegisteredWorkflowDefinition, type RetentionOverview, type ReviewListEntry, type ReviewListFilter, type ScheduleDefinition, type ScheduleFilter, type ScheduleOptions, type ScheduleSpec, type ScheduleSummary, type SearchAttributeValue, type SignalDefinition, type SignalDeliveryOptions, type StartOptions, type StartOrSignalSignal, type StartWorkflowOptions, type SubmitReviewOptions, type TypedListFilter, type UpdateDefinition, type WorkflowEvent, type WorkflowInput, type WorkflowOutput, type WorkflowReplay, type WorkflowServices, type WorkflowServicesUnion, type WorkflowState, type WorkflowSummary, type WorkflowTimelineEntry } from '../types.ts';
|
|
8
9
|
import type { TimerEntry } from '../types/checkpoint.ts';
|
|
9
10
|
import type { WorkflowAlreadyRegistered } from '../types/workflow-builder.ts';
|
|
10
11
|
import { type AggregateOptions, type AggregateResult } from './aggregate.ts';
|
|
11
12
|
import { type EmptyActivityDefinitions, type EmptyWorkflowDefinitions, type KnownWorkflowNames } from './construction.ts';
|
|
12
|
-
import { type ActivityDefinitionName, type EngineCreateOptions, type RegisteredActivityDefinitionExecute, type UnknownWorkflowNameWhenDefaultRegistryIsEmpty } from './engine-create-types.ts';
|
|
13
|
+
import { type ActivityDefinitionName, type EngineCreateOptions, type EngineCreateWorkflowRegistry, type RegisteredActivityDefinitionExecute, type UnknownWorkflowNameWhenDefaultRegistryIsEmpty } from './engine-create-types.ts';
|
|
13
14
|
import type { EngineConstructorOptions } from './engine-internal-types.ts';
|
|
14
15
|
import type { EngineStateNamespace } from './engine-state-namespace.ts';
|
|
15
|
-
import { HANDLE_RESULT_PROMISE,
|
|
16
|
-
import {
|
|
16
|
+
import { HANDLE_RESULT_PROMISE, WorkflowHandle } from './handles.ts';
|
|
17
|
+
import { ENGINE_LEASE_LOST_WARNING_NAME } from './lease-deposition.ts';
|
|
18
|
+
import { type RecoverAllOptions, type StartOrSignalResult } from './lifecycle.ts';
|
|
17
19
|
import { assertCompatiblePersistedDataVersion } from './persisted-data-version.ts';
|
|
20
|
+
import { ScheduleHandle } from './schedule-handle.ts';
|
|
18
21
|
import { type WorkflowFeedListener, type WorkflowFeedRecord, type WorkflowFeedSelector } from './workflow-feed.ts';
|
|
19
22
|
export { ActivityReconciliationCapabilityError, ActivityReconciliationConflictError, ActivityReconciliationIndeterminateError, } from './activity-reconciliation.ts';
|
|
20
23
|
export { AsyncActivityTokenNotFoundError } from './async-activity-completion.ts';
|
|
21
24
|
export type { PendingAsyncActivity } from './async-activity-completion.ts';
|
|
22
25
|
export type { PendingTimelineEntry, RegistrationEntry, ResolvedOptions, TrackedWaiterKeys, WorkflowResultWaiter, } from './engine-internal-types.ts';
|
|
23
|
-
export { ActivityResolutionError, BulkDeleteRequiresTerminalWorkflowsError, BulkOperationConfirmationError, EngineCreateNameMismatchError, EngineDisposedError, PersistedDataIncompatibleError, WorkflowAlreadyExistsError, WorkflowNotFoundError, WorkflowNotRegisteredError, WorkflowTypeNotRegisteredForRecoveryError, } from './errors.ts';
|
|
24
|
-
export { HANDLE_RESULT_PROMISE,
|
|
26
|
+
export { ActivityResolutionError, BulkDeleteRequiresTerminalWorkflowsError, BulkOperationConfirmationError, EngineCreateNameMismatchError, EngineDisposedError, IdempotencyKeyPurgedError, PersistedDataIncompatibleError, StartOrSignalConflictError, WorkflowAlreadyExistsError, WorkflowConcurrencyLimitExceededError, WorkflowNotFoundError, WorkflowNotRegisteredError, WorkflowSuspendNotSupportedError, WorkflowTeardownPendingError, WorkflowTypeNotRegisteredForRecoveryError, } from './errors.ts';
|
|
27
|
+
export { HANDLE_RESULT_PROMISE, WorkflowHandle } from './handles.ts';
|
|
28
|
+
export { EngineLeaseAcquisitionTimeoutError, EngineLeaseCorruptedError, EngineLeaseNotHeldError, } from './lease-errors.ts';
|
|
25
29
|
export type { RecoverAllOptions } from './lifecycle.ts';
|
|
30
|
+
export { ScheduleHandle } from './schedule-handle.ts';
|
|
26
31
|
export type { WorkflowFeedListener, WorkflowFeedRecord, WorkflowFeedSelector, } from './workflow-feed.ts';
|
|
27
32
|
export type { EngineCreateOptions } from './engine-create-types.ts';
|
|
28
33
|
export { clearEngineLeakWarningTokenForTesting, getEngineLeakCollectionCountForTesting, hasEngineLeakWarningTokenForTesting, setEngineLeakWarningOverrideForTesting, setNextEngineLeakWarningTokenForTesting, shouldEmitEngineLeakWarningForTesting, } from './engine-leak-warnings.ts';
|
|
@@ -30,6 +35,8 @@ export type { EngineStateNamespace } from './engine-state-namespace.ts';
|
|
|
30
35
|
export { assertCompatiblePersistedDataVersion };
|
|
31
36
|
export declare const ENGINE_PARKED_WORKFLOW_COUNT_FOR_TESTING: unique symbol;
|
|
32
37
|
export declare const ENGINE_SIGNAL_WAITER_COUNT_FOR_TESTING: unique symbol;
|
|
38
|
+
export declare const ENGINE_SLEEP_RESOLVER_COUNT_FOR_TESTING: unique symbol;
|
|
39
|
+
export { ENGINE_LEASE_LOST_WARNING_NAME };
|
|
33
40
|
/**
|
|
34
41
|
* Durable execution engine.
|
|
35
42
|
*
|
|
@@ -72,7 +79,7 @@ export declare const ENGINE_SIGNAL_WAITER_COUNT_FOR_TESTING: unique symbol;
|
|
|
72
79
|
* void engine;
|
|
73
80
|
* ```
|
|
74
81
|
*/
|
|
75
|
-
export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry, TActivities extends object = DefaultActivityTypes> extends EventTarget implements Disposable, AsyncDisposable {
|
|
82
|
+
export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry, TActivities extends object = DefaultActivityTypes> extends EventTarget implements Disposable, AsyncDisposable, TypedEventTarget<WeftEventMap> {
|
|
76
83
|
#private;
|
|
77
84
|
/**
|
|
78
85
|
* Construct and register an engine in one step. Activities are registered
|
|
@@ -102,7 +109,7 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
102
109
|
static create<TWorkflowDefinitions extends Record<string, AnyWorkflowDefinition>>(options: EngineCreateOptions<TWorkflowDefinitions, EmptyActivityDefinitions> & {
|
|
103
110
|
activities?: undefined;
|
|
104
111
|
workflows: TWorkflowDefinitions;
|
|
105
|
-
}): Promise<Engine<
|
|
112
|
+
}): Promise<Engine<EngineCreateWorkflowRegistry<TWorkflowDefinitions>>>;
|
|
106
113
|
static create<TActivityDefinitions extends Record<string, AnyActivityDefinition>>(options: EngineCreateOptions<EmptyWorkflowDefinitions, TActivityDefinitions> & {
|
|
107
114
|
activities: TActivityDefinitions;
|
|
108
115
|
workflows?: undefined;
|
|
@@ -110,8 +117,12 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
110
117
|
static create<TWorkflowDefinitions extends Record<string, AnyWorkflowDefinition>, TActivityDefinitions extends Record<string, AnyActivityDefinition>>(options: EngineCreateOptions<TWorkflowDefinitions, TActivityDefinitions> & {
|
|
111
118
|
activities: TActivityDefinitions;
|
|
112
119
|
workflows: TWorkflowDefinitions;
|
|
113
|
-
}): Promise<Engine<
|
|
114
|
-
constructor(options?: EngineConstructorOptions);
|
|
120
|
+
}): Promise<Engine<EngineCreateWorkflowRegistry<TWorkflowDefinitions>, InferActivityEntries<TActivityDefinitions>>>;
|
|
121
|
+
constructor(options?: EngineConstructorOptions<WorkflowServicesUnion<TWorkflows>>);
|
|
122
|
+
addEventListener<K extends Extract<keyof WeftEventMap, string>>(type: K, listener: (event: WeftEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
123
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
|
|
124
|
+
removeEventListener<K extends Extract<keyof WeftEventMap, string>>(type: K, listener: (event: WeftEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
|
|
125
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
|
|
115
126
|
get state(): EngineStateNamespace;
|
|
116
127
|
/**
|
|
117
128
|
* Register a workflow by name or definition, or register an activity
|
|
@@ -183,8 +194,27 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
183
194
|
listWorkflowDefinitions(): RegisteredWorkflowDefinition[];
|
|
184
195
|
getActivityDefinition(name: string): ActivityMetadata | undefined;
|
|
185
196
|
listActivityDefinitions(): ActivityMetadata[];
|
|
186
|
-
start<TName extends KnownWorkflowNames<TWorkflows>>(type: TName, input: WorkflowInput<TWorkflows, TName>, options?:
|
|
187
|
-
start<TName extends string>(type: UnknownWorkflowNameWhenDefaultRegistryIsEmpty<TWorkflows, TName>, input: unknown, options?:
|
|
197
|
+
start<TName extends KnownWorkflowNames<TWorkflows>>(type: TName, input: WorkflowInput<TWorkflows, TName>, options?: StartWorkflowOptions<WorkflowServices<TWorkflows, TName>>): Promise<WorkflowHandle<WorkflowOutput<TWorkflows, TName>>>;
|
|
198
|
+
start<TName extends string>(type: UnknownWorkflowNameWhenDefaultRegistryIsEmpty<TWorkflows, TName>, input: unknown, options?: StartWorkflowOptions): Promise<WorkflowHandle>;
|
|
199
|
+
/**
|
|
200
|
+
* Atomically start a workflow or signal it if it already exists
|
|
201
|
+
* (signal-with-start). With an absent target, the workflow record and the
|
|
202
|
+
* first signal commit in one batch and the freshly-launched run consumes the
|
|
203
|
+
* signal on its first drive. A non-terminal target (running, pending, or
|
|
204
|
+
* suspended) is signalled through the normal signal path; a terminal target
|
|
205
|
+
* throws {@link StartOrSignalConflictError} rather than starting a new run or
|
|
206
|
+
* dropping the signal.
|
|
207
|
+
*
|
|
208
|
+
* Concurrent callers converge on one workflow and one delivered signal. Pass
|
|
209
|
+
* `options.idempotencyKey` to dedup independent callers (e.g. retried
|
|
210
|
+
* webhooks); the signal id derives from the key when `signal.signalId` is
|
|
211
|
+
* omitted, so callers that share only the key still converge. `signal.signalId`
|
|
212
|
+
* and `options.idempotencyKey` are mutually exclusive (provide exactly one), as
|
|
213
|
+
* are `options.id` and `options.idempotencyKey`. Requires a storage backend
|
|
214
|
+
* with `conditionalBatch`.
|
|
215
|
+
*/
|
|
216
|
+
startOrSignal<TName extends KnownWorkflowNames<TWorkflows>>(type: TName, input: WorkflowInput<TWorkflows, TName>, signal: StartOrSignalSignal, options?: StartOptions<WorkflowServices<TWorkflows, TName>>): Promise<StartOrSignalResult<WorkflowOutput<TWorkflows, TName>>>;
|
|
217
|
+
startOrSignal<TName extends string>(type: UnknownWorkflowNameWhenDefaultRegistryIsEmpty<TWorkflows, TName>, input: unknown, signal: StartOrSignalSignal, options?: StartOptions): Promise<StartOrSignalResult>;
|
|
188
218
|
getHandle(workflowId: string): WorkflowHandle;
|
|
189
219
|
list<const TAttributeKeys extends readonly AttributeFilterKey[] = readonly AttributeFilterKey[]>(filter?: TypedListFilter<TAttributeKeys>, options?: ListOptions): Promise<PaginatedResult<WorkflowSummary>>;
|
|
190
220
|
aggregate(filter: ListFilter | undefined, options: AggregateOptions): Promise<AggregateResult>;
|
|
@@ -192,6 +222,8 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
192
222
|
purge(filter?: ListFilter): Promise<PurgeResult>;
|
|
193
223
|
cancelAll(filter: ListFilter, options: BulkOperationDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
194
224
|
cancelAll(filter: ListFilter, options?: BulkOperationCommitOptions): Promise<BulkCancelResult>;
|
|
225
|
+
retryFailedAll(filter: ListFilter, options: BulkOperationDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
226
|
+
retryFailedAll(filter: ListFilter, options?: BulkOperationCommitOptions): Promise<BulkRetryFailedResult>;
|
|
195
227
|
signalAll(filter: ListFilter, name: string, payload: unknown, options: BulkSignalAllDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
196
228
|
signalAll(filter: ListFilter, name: string, payload: unknown, options: BulkSignalAllCommitOptions): Promise<BulkSignalResult>;
|
|
197
229
|
signalAll(filter: ListFilter, name: string, payload?: unknown, options?: BulkOperationCommitOptions): Promise<BulkSignalResult>;
|
|
@@ -201,6 +233,37 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
201
233
|
tagAll(filter: ListFilter, tags: string[], options?: BulkOperationCommitOptions): Promise<BulkTagResult>;
|
|
202
234
|
untagAll(filter: ListFilter, tags: string[], options: BulkOperationDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
203
235
|
untagAll(filter: ListFilter, tags: string[], options?: BulkOperationCommitOptions): Promise<BulkTagResult>;
|
|
236
|
+
/**
|
|
237
|
+
* Register a recurring schedule that starts a workflow on a cron expression or
|
|
238
|
+
* fixed interval. Returns a {@link ScheduleHandle} for pausing, resuming,
|
|
239
|
+
* updating, or cancelling the schedule.
|
|
240
|
+
*
|
|
241
|
+
* Two call forms:
|
|
242
|
+
* - A {@link ScheduleDefinition} object: `engine.schedule({ workflow, cron, input })`.
|
|
243
|
+
* Carries the workflow (definition or type name), the `cron`/`every` spec,
|
|
244
|
+
* optional `input`, `id`, `overlapPolicy`, `backfill`, and `jitter`.
|
|
245
|
+
* - Positional: `engine.schedule(type, input, spec, options?)` where `spec` is
|
|
246
|
+
* a cron string or a {@link ScheduleSpec} (`{ cron }` or `{ every }`).
|
|
247
|
+
*
|
|
248
|
+
* The {@link ScheduleOptions.overlap} policy governs what happens when a tick
|
|
249
|
+
* fires while the previous run is still in flight.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* import { workflow, Engine } from '@lostgradient/weft';
|
|
254
|
+
*
|
|
255
|
+
* const engine = new Engine();
|
|
256
|
+
* engine.register(workflow({ name: 'sweep' }).execute(async function* () { return 'ok'; }));
|
|
257
|
+
*
|
|
258
|
+
* // Definition form: every day at 09:00, skip a tick if the prior run is still running.
|
|
259
|
+
* const handle = await engine.schedule({
|
|
260
|
+
* workflow: 'sweep',
|
|
261
|
+
* cron: '0 9 * * *',
|
|
262
|
+
* overlapPolicy: 'skip',
|
|
263
|
+
* });
|
|
264
|
+
* await handle.pause();
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
204
267
|
schedule<TInput>(definition: ScheduleDefinition<TInput>): Promise<ScheduleHandle>;
|
|
205
268
|
schedule(type: string, input: unknown, spec: string | ScheduleSpec, options?: ScheduleOptions): Promise<ScheduleHandle>;
|
|
206
269
|
getSchedule(scheduleId: string): Promise<ScheduleSummary | null>;
|
|
@@ -212,6 +275,7 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
212
275
|
[HANDLE_RESULT_PROMISE](workflowId: string): Promise<unknown>;
|
|
213
276
|
[ENGINE_PARKED_WORKFLOW_COUNT_FOR_TESTING](): number;
|
|
214
277
|
[ENGINE_SIGNAL_WAITER_COUNT_FOR_TESTING](): number;
|
|
278
|
+
[ENGINE_SLEEP_RESOLVER_COUNT_FOR_TESTING](): number;
|
|
215
279
|
signal(workflowId: string, name: SignalDefinition): Promise<void>;
|
|
216
280
|
signal<TInput>(workflowId: string, name: SignalDefinition<TInput>, payload: TInput, options?: SignalDeliveryOptions): Promise<void>;
|
|
217
281
|
signal(workflowId: string, name: string, payload?: unknown, options?: SignalDeliveryOptions): Promise<void>;
|
|
@@ -257,6 +321,13 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
257
321
|
*/
|
|
258
322
|
getOffload(workflowId: string, key: string): Promise<unknown>;
|
|
259
323
|
fork(sourceWorkflowId: string, options?: ForkOptions): Promise<WorkflowHandle>;
|
|
324
|
+
/**
|
|
325
|
+
* Re-drive a workflow from its persisted checkpoint and return a live handle.
|
|
326
|
+
* Accepts a workflow left `'running'` (e.g. recovered after a process restart)
|
|
327
|
+
* or one explicitly `'suspended'` via {@link Engine.suspend} — a suspended
|
|
328
|
+
* workflow is durably flipped back to `'running'` as part of resuming. Throws
|
|
329
|
+
* if the workflow is in any other status (terminal, pending) or not found.
|
|
330
|
+
*/
|
|
260
331
|
resume(workflowId: string): Promise<WorkflowHandle>;
|
|
261
332
|
/**
|
|
262
333
|
* Recover every running workflow found in storage. By default, recovery
|
|
@@ -264,7 +335,7 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
264
335
|
* registered workflow type on this engine.
|
|
265
336
|
*
|
|
266
337
|
* `acknowledgeUnknownWorkflowTypes` is a dangerous escape hatch for rolling
|
|
267
|
-
* deploys or explicit storage
|
|
338
|
+
* deploys or explicit operator storage repair.
|
|
268
339
|
* When set, unknown workflow types are skipped and reported through
|
|
269
340
|
* {@link WorkflowRecoverySkippedEvent}.
|
|
270
341
|
*/
|
|
@@ -274,7 +345,11 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
274
345
|
* have parked itself via `ActivityContext.completeAsync()`; pass the durable
|
|
275
346
|
* task token announced through the `activity:async-pending` event (or
|
|
276
347
|
* persisted by your callback dispatcher). The parked workflow resumes as
|
|
277
|
-
* though the activity had returned `result` inline.
|
|
348
|
+
* though the activity had returned `result` inline. During recovery, a
|
|
349
|
+
* completion that arrives after token recovery but before replay adopts the
|
|
350
|
+
* workflow generator is buffered and delivered when replay reaches the same
|
|
351
|
+
* async-activity token. Await `recoverAll()` before accepting callback traffic
|
|
352
|
+
* when your application needs startup ordering to be fully deterministic.
|
|
278
353
|
*
|
|
279
354
|
* @throws {AsyncActivityTokenNotFoundError} when no pending activity matches
|
|
280
355
|
* the token (unknown, or already completed/failed — tokens are single-use).
|
|
@@ -284,15 +359,34 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
284
359
|
* Fail a deferred activity out-of-band with `error`. The error is thrown into
|
|
285
360
|
* the workflow generator at the parked step — identical to an inline activity
|
|
286
361
|
* that threw — so the workflow's own try/catch and any configured retry
|
|
287
|
-
* policy apply unchanged.
|
|
362
|
+
* policy apply unchanged. During recovery, a failure that arrives after token
|
|
363
|
+
* recovery but before replay adopts the workflow generator is buffered and
|
|
364
|
+
* delivered when replay reaches the same async-activity token. Await
|
|
365
|
+
* `recoverAll()` before accepting callback traffic when your application needs
|
|
366
|
+
* startup ordering to be fully deterministic.
|
|
288
367
|
*
|
|
289
368
|
* @throws {AsyncActivityTokenNotFoundError} when no pending activity matches
|
|
290
369
|
* the token (unknown, or already completed/failed — tokens are single-use).
|
|
291
370
|
*/
|
|
292
371
|
failAsyncActivity(token: string, error: unknown): Promise<void>;
|
|
293
372
|
cancel(workflowId: string): Promise<void>;
|
|
373
|
+
/**
|
|
374
|
+
* Suspend a running workflow without terminating it. The workflow transitions
|
|
375
|
+
* to the non-terminal `'suspended'` status, keeps its durable checkpoint, and
|
|
376
|
+
* is later resumable via {@link Engine.resume} (or `handle.resume()`). Unlike
|
|
377
|
+
* {@link Engine.cancel}, this does not run cancel handlers and does not settle
|
|
378
|
+
* the result promise — `handle.result()` stays pending until a later `resume()`
|
|
379
|
+
* drives the run to completion.
|
|
380
|
+
*
|
|
381
|
+
* Suspension is client-driven preemption, so a suspended workflow is NOT
|
|
382
|
+
* auto-recovered by {@link Engine.recoverAll}; resume it explicitly. Calling
|
|
383
|
+
* `suspend` on a workflow that is not running (already terminal, or never
|
|
384
|
+
* started) is a no-op.
|
|
385
|
+
*/
|
|
386
|
+
suspend(workflowId: string): Promise<void>;
|
|
294
387
|
timeout(workflowId: string): Promise<void>;
|
|
295
388
|
get(workflowId: string): Promise<WorkflowState | null>;
|
|
389
|
+
getCurrentCheckpointStep(workflowId: string): Promise<number | null>;
|
|
296
390
|
getAttributes(workflowId: string): Promise<Record<string, SearchAttributeValue> | null>;
|
|
297
391
|
setAttributes(workflowId: string, attributes: Record<string, SearchAttributeValue>): Promise<void>;
|
|
298
392
|
addTags(workflowId: string, ...tags: string[]): Promise<void>;
|
|
@@ -313,7 +407,23 @@ export declare class Engine<TWorkflows extends object = DefaultWorkflowRegistry,
|
|
|
313
407
|
timeout?: number;
|
|
314
408
|
idempotencyKey?: string;
|
|
315
409
|
}): Promise<CoordinatedUpdateResult>;
|
|
410
|
+
/**
|
|
411
|
+
* Synchronous teardown (`using engine = ...`). Pending inline launches that
|
|
412
|
+
* have not yet run are **discarded**, not executed. When you need queued
|
|
413
|
+
* starts to complete before teardown — or want a clean event loop with no
|
|
414
|
+
* dangling deferred-launch macrotask — prefer {@link Engine[Symbol.asyncDispose]}
|
|
415
|
+
* via `await using`.
|
|
416
|
+
*/
|
|
316
417
|
[Symbol.dispose](): void;
|
|
418
|
+
/**
|
|
419
|
+
* Async teardown (`await using engine = ...`). Drains pending inline launches
|
|
420
|
+
* so each queued workflow completes its first turn before disposal, leaving no
|
|
421
|
+
* deferred-launch macrotask to fire against torn-down state. The drain is
|
|
422
|
+
* bounded (a pass cap and the abort signal); in the pathological case where it
|
|
423
|
+
* cannot converge, anything still queued is discarded by the synchronous
|
|
424
|
+
* teardown that always follows. Prefer this over the synchronous
|
|
425
|
+
* {@link Engine[Symbol.dispose]} in async contexts and tests.
|
|
426
|
+
*/
|
|
317
427
|
[Symbol.asyncDispose](): Promise<void>;
|
|
318
428
|
get storage(): WeftStorage;
|
|
319
429
|
get scheduler(): Scheduler;
|