@lostgradient/weft 0.3.0 → 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 +79 -24
- package/dist/cli/conformance.js +7 -1
- package/dist/cli/generated/operation-client.generated.d.ts +28 -13
- package/dist/cli/generated/operation-client.generated.js +1 -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 +79 -78
- package/dist/client/handle-delegation.d.ts +3 -2
- package/dist/client/handle-delegation.js +3 -1
- package/dist/client/http-client-requests.d.ts +2 -1
- package/dist/client/http-client-requests.js +7 -0
- package/dist/client/http-client.d.ts +9 -6
- package/dist/client/http-client.js +10 -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 +46 -5
- package/dist/client/local.d.ts +4 -1
- package/dist/client/local.js +12 -4
- package/dist/client/start-body.d.ts +4 -3
- 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 +100 -6
- 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 +9 -5
- package/dist/core/context/index.js +17 -12
- package/dist/core/context/internals.d.ts +20 -0
- package/dist/core/context/internals.js +3 -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 +6 -1
- package/dist/core/context/run-operation.js +41 -87
- 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 -0
- package/dist/core/engine/construction.js +21 -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 +13 -0
- package/dist/core/engine/engine-create-types.d.ts +14 -4
- package/dist/core/engine/engine-internal-types.d.ts +26 -3
- package/dist/core/engine/errors.d.ts +47 -0
- package/dist/core/engine/errors.js +20 -0
- 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/handles.d.ts +8 -0
- package/dist/core/engine/index.d.ts +34 -16
- package/dist/core/engine/index.js +133 -8
- package/dist/core/engine/inline-parking.js +3 -2
- package/dist/core/engine/internals.d.ts +107 -3
- 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/persist.js +10 -32
- 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 +16 -9
- 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 +9 -0
- package/dist/core/engine/lifecycle/start-commit.js +50 -8
- 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.d.ts +3 -2
- package/dist/core/engine/lifecycle/start-or-signal.js +11 -81
- 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 +4 -4
- package/dist/core/engine/lifecycle/start.js +17 -9
- package/dist/core/engine/lifecycle/transition.js +17 -5
- package/dist/core/engine/lifecycle.d.ts +1 -1
- package/dist/core/engine/list-candidate-resolution.js +2 -2
- package/dist/core/engine/listing.js +9 -5
- 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/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-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 +7 -4
- package/dist/core/engine/schedules.js +37 -16
- 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/signals.d.ts +18 -2
- package/dist/core/engine/signals.js +42 -21
- 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 +3 -1
- package/dist/core/engine/termination/cleanup.js +25 -1
- package/dist/core/engine/termination/complete.js +44 -6
- 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 +3 -1
- package/dist/core/engine/termination.d.ts +1 -0
- package/dist/core/engine/termination.js +4 -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 +32 -5
- 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 +4 -5
- 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 +18 -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 +88 -23
- package/dist/core/events/workflow-events.js +26 -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/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 +34 -0
- package/dist/core/start-workflow-validation.js +19 -0
- 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 +80 -61
- package/dist/core/types/bulk.d.ts +50 -9
- package/dist/core/types/checkpoint.d.ts +44 -8
- package/dist/core/types/list-options.d.ts +146 -0
- package/dist/core/types/list-options.js +0 -0
- package/dist/core/types/options.d.ts +121 -165
- package/dist/core/types/schedules.d.ts +39 -3
- package/dist/core/types/services-resolution.d.ts +2 -2
- 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 +42 -11
- 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 +84 -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.d.ts +4 -0
- package/dist/core/types.js +4 -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 +16 -0
- 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/format.js +1 -6
- package/dist/diagnostics/types.d.ts +4 -5
- package/dist/diagnostics/validate.d.ts +0 -1
- package/dist/diagnostics/version-check.d.ts +1 -1
- package/dist/diagnostics/version-check.js +4 -9
- package/dist/index.d.ts +12 -10
- package/dist/index.js +29 -3
- package/dist/json-schema.js +3 -3
- package/dist/mcp/cli.js +27 -27
- package/dist/mcp/dispatcher.js +1 -1
- package/dist/mcp/http.js +16 -6
- 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 +59 -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 +23 -23
- package/dist/server/index.d.ts +32 -2
- package/dist/server/index.js +26 -26
- 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/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 +6 -1
- package/dist/server/operations/start-or-signal-workflow.js +14 -24
- package/dist/server/operations/start-workflow-options.d.ts +6 -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 +8 -23
- 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/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 +3 -1
- package/dist/server/rest-bindings.js +12 -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-polling.js +61 -20
- 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 +38 -30
- package/dist/server/serve-internals.d.ts +3 -1
- package/dist/server/serve-internals.js +18 -2
- package/dist/server/task-state.d.ts +30 -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 +30 -30
- package/dist/storage/auto.js +1 -1
- package/dist/storage/bun-sql.js +24 -0
- 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 +76 -4
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/interface.d.ts +163 -0
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +10 -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 +30 -3
- package/dist/storage/neon-value-mapping.js +12 -0
- package/dist/storage/neon.d.ts +16 -0
- package/dist/storage/neon.js +9 -4
- package/dist/storage/node-sqlite.js +23 -0
- package/dist/storage/postgres-key-value-queries.d.ts +69 -44
- package/dist/storage/postgres-key-value-queries.js +62 -24
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/testing.d.ts +168 -0
- package/dist/storage/testing.js +2 -0
- 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 +28 -28
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/protocol.js +1 -1
- 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 +5 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ctx.log` structured-logging surface: the {@link WorkflowLogger} exposed on
|
|
3
|
+
* the workflow context, the {@link WorkflowLogRecord} envelope it emits, and the
|
|
4
|
+
* {@link WorkflowLogLevel} severity. Split out from `workflow-context.ts` so the
|
|
5
|
+
* context module stays under the line cap and the log types can be re-exported as
|
|
6
|
+
* a cohesive cluster.
|
|
7
|
+
*
|
|
8
|
+
* @module core/types/workflow-log
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Severity of a {@link WorkflowLogRecord}, ordered `debug < info < warn < error`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { WorkflowLogLevel } from '@lostgradient/weft';
|
|
16
|
+
* const isError = (level: WorkflowLogLevel) => level === 'error';
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type WorkflowLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
20
|
+
/**
|
|
21
|
+
* The structured record a {@link WorkflowLogger} emits for one log call. Envelope
|
|
22
|
+
* fields (`level`, `message`, `workflowId`, `workflowType`, `timestamp`) are
|
|
23
|
+
* engine-owned and always present; caller `attributes` nest under their own key so
|
|
24
|
+
* they can never shadow an envelope field. `timestamp` is wall-clock ms at emit —
|
|
25
|
+
* observability metadata, never checkpointed or replayed. Type a host sink
|
|
26
|
+
* installed via `EngineOptions.onLog` with this record.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { Engine, type WorkflowLogRecord } from '@lostgradient/weft';
|
|
31
|
+
* const engine = new Engine({ onLog: (r: WorkflowLogRecord) => console.log(r.level, r.message) });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface WorkflowLogRecord {
|
|
35
|
+
readonly level: WorkflowLogLevel;
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly workflowId: string;
|
|
38
|
+
readonly workflowType: string;
|
|
39
|
+
readonly timestamp: number;
|
|
40
|
+
readonly attributes?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The structured logger exposed as `WorkflowContext.log`. Each method emits
|
|
44
|
+
* a {@link WorkflowLogRecord} to the current process console (`console.debug` /
|
|
45
|
+
* `console.info` / `console.warn` / `console.error`) with `workflowId`,
|
|
46
|
+
* `workflowType`, `level`, and `timestamp` auto-attached. Caller-supplied
|
|
47
|
+
* `attributes` are nested under their own key and cannot overwrite the envelope.
|
|
48
|
+
*
|
|
49
|
+
* Replay behavior: a workflow body re-executes from the start on recovery to
|
|
50
|
+
* rebuild state. Log calls in the already-committed replay window are suppressed,
|
|
51
|
+
* so a recovered run does not re-emit logs it already emitted. Suppression is
|
|
52
|
+
* per-position: a log call sitting at a step the engine has already cached is
|
|
53
|
+
* silenced; a log call at the live frontier emits. This holds in both inline and
|
|
54
|
+
* worker execution modes.
|
|
55
|
+
*
|
|
56
|
+
* Two replay caveats. A log placed *after* the last committed step re-fires on
|
|
57
|
+
* recovery, because there is no cached step to suppress it (the same caveat
|
|
58
|
+
* Temporal's workflow logger carries); likewise a workflow with no committed
|
|
59
|
+
* durable step has no replay position to suppress against, so its logs may
|
|
60
|
+
* re-emit on recovery. Logs inside `ctx.all` / `ctx.runAll` branches follow that
|
|
61
|
+
* branch's re-execution semantics.
|
|
62
|
+
*
|
|
63
|
+
* A host sink installed via `EngineOptions.onLog` receives records from BOTH execution
|
|
64
|
+
* modes: inline records directly, and worker-mode records forwarded from the worker
|
|
65
|
+
* back to the host. When no sink is installed, worker-mode records go to the worker
|
|
66
|
+
* process console (and inline records to the engine-host console). Inline log
|
|
67
|
+
* timestamps come from the engine clock; worker-mode timestamps come from the worker
|
|
68
|
+
* process wall clock.
|
|
69
|
+
*
|
|
70
|
+
* Exported so a host can also type a logger it injects through `ctx.services`
|
|
71
|
+
* (the pre-`ctx.log` pattern).
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { workflow, type WorkflowContext, type WorkflowLogger } from '@lostgradient/weft';
|
|
76
|
+
*
|
|
77
|
+
* const myWorkflow = workflow({ name: 'my-workflow' }).execute(async function* (
|
|
78
|
+
* ctx: WorkflowContext,
|
|
79
|
+
* ) {
|
|
80
|
+
* ctx.log?.info('workflow started', { attempt: 1 });
|
|
81
|
+
* ctx.log?.warn('retrying activity', { reason: 'timeout' });
|
|
82
|
+
* // A host logger injected through `ctx.services` can reuse this type:
|
|
83
|
+
* const { log } = (ctx.services ?? {}) as { log?: WorkflowLogger };
|
|
84
|
+
* log?.error('activity failed', { error: 'ECONNREFUSED' });
|
|
85
|
+
* });
|
|
86
|
+
* void myWorkflow;
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export interface WorkflowLogger {
|
|
90
|
+
/** Emit a `debug` record. Auto-carries `workflowId`/`workflowType`; suppressed during replay. */
|
|
91
|
+
debug(message: string, attributes?: Record<string, unknown>): void;
|
|
92
|
+
/** Emit an `info` record. Auto-carries `workflowId`/`workflowType`; suppressed during replay. */
|
|
93
|
+
info(message: string, attributes?: Record<string, unknown>): void;
|
|
94
|
+
/** Emit a `warn` record. Auto-carries `workflowId`/`workflowType`; suppressed during replay. */
|
|
95
|
+
warn(message: string, attributes?: Record<string, unknown>): void;
|
|
96
|
+
/** Emit an `error` record. Auto-carries `workflowId`/`workflowType`; suppressed during replay. */
|
|
97
|
+
error(message: string, attributes?: Record<string, unknown>): void;
|
|
98
|
+
}
|
|
File without changes
|
|
@@ -32,6 +32,7 @@ export interface WorkflowRegistry {
|
|
|
32
32
|
export type WorkflowRegistryEntry = {
|
|
33
33
|
input: unknown;
|
|
34
34
|
output: unknown;
|
|
35
|
+
services?: unknown;
|
|
35
36
|
};
|
|
36
37
|
declare const defaultWorkflowRegistry: unique symbol;
|
|
37
38
|
declare const defaultActivityTypes: unique symbol;
|
|
@@ -73,7 +74,7 @@ export type IsDefaultWorkflowRegistry<TRegistry extends object> = TRegistry exte
|
|
|
73
74
|
*/
|
|
74
75
|
export type AnyWorkflowDefinition = {
|
|
75
76
|
readonly name: string;
|
|
76
|
-
readonly handler: WorkflowFunction<never> | StepWorkflowFunction<never>;
|
|
77
|
+
readonly handler: WorkflowFunction<never, unknown, never> | StepWorkflowFunction<never>;
|
|
77
78
|
};
|
|
78
79
|
/**
|
|
79
80
|
* Broad activity-definition constraint used by {@link Engine.create} and
|
|
@@ -100,6 +101,14 @@ export type WorkflowInput<TRegistry extends object, TName extends string> = TNam
|
|
|
100
101
|
export type WorkflowOutput<TRegistry extends object, TName extends string> = TName extends keyof TRegistry ? TRegistry[TName] extends {
|
|
101
102
|
output: infer TOutput;
|
|
102
103
|
} ? TOutput : unknown : unknown;
|
|
104
|
+
export type WorkflowServices<TRegistry extends object, TName extends string> = TName extends keyof TRegistry ? TRegistry[TName] extends {
|
|
105
|
+
services: infer TServices;
|
|
106
|
+
} ? TServices : unknown : unknown;
|
|
107
|
+
export type WorkflowServicesUnion<TRegistry extends object> = [keyof TRegistry & string] extends [
|
|
108
|
+
never
|
|
109
|
+
] ? unknown : {
|
|
110
|
+
[Name in keyof TRegistry & string]: WorkflowServices<TRegistry, Name>;
|
|
111
|
+
}[keyof TRegistry & string];
|
|
103
112
|
export type ActivityArguments<TActivities extends object, TName extends string> = TName extends keyof TActivities ? TActivities[TName] extends () => unknown ? [] : TActivities[TName] extends (input: infer TInput) => unknown ? [input: TInput] : [input: unknown] : [input?: unknown];
|
|
104
113
|
export type ActivityResult<TActivities extends object, TName extends string> = TName extends keyof TActivities ? TActivities[TName] extends (...arguments_: infer _TArguments) => infer TResult ? Awaited<TResult> : unknown : unknown;
|
|
105
114
|
export type RegisteredActivityFunction<TActivities extends object, TName extends string> = TName extends keyof TActivities ? TActivities[TName] extends () => infer TResult ? () => TResult : TActivities[TName] extends (input: infer TInput) => infer TResult ? (input: TInput) => TResult : never : never;
|
|
@@ -122,16 +131,18 @@ type MergeDefinitionEntries<TUnion> = [TUnion] extends [never] ? {} : UnionToInt
|
|
|
122
131
|
* void input;
|
|
123
132
|
* ```
|
|
124
133
|
*/
|
|
125
|
-
export type InferWorkflowEntry<TDefinition extends AnyWorkflowDefinition> = TDefinition extends WorkflowDefinition<infer TInput, infer TOutput, infer TName extends string> ? {
|
|
134
|
+
export type InferWorkflowEntry<TDefinition extends AnyWorkflowDefinition> = TDefinition extends WorkflowDefinition<infer TInput, infer TOutput, infer TName extends string, infer TServices> ? {
|
|
126
135
|
[Name in TName]: {
|
|
127
136
|
input: TInput;
|
|
128
137
|
output: TOutput;
|
|
138
|
+
services: TServices;
|
|
129
139
|
};
|
|
130
140
|
} : never;
|
|
131
|
-
type InferWorkflowEntryForKey<TName extends string, TDefinition extends AnyWorkflowDefinition> = TDefinition extends WorkflowDefinition<infer TInput, infer TOutput> ? {
|
|
141
|
+
type InferWorkflowEntryForKey<TName extends string, TDefinition extends AnyWorkflowDefinition> = TDefinition extends WorkflowDefinition<infer TInput, infer TOutput, string, infer TServices> ? {
|
|
132
142
|
[Name in TName]: {
|
|
133
143
|
input: TInput;
|
|
134
144
|
output: TOutput;
|
|
145
|
+
services: TServices;
|
|
135
146
|
};
|
|
136
147
|
} : never;
|
|
137
148
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DefinitionSchema } from './definition-schema.ts';
|
|
2
2
|
import type { SearchAttributeSchema } from './search-attributes.ts';
|
|
3
|
+
import type { WorkflowConcurrencyOptions } from './workflow-concurrency.ts';
|
|
3
4
|
/**
|
|
4
5
|
* Read-only metadata exposed by the engine for a registered workflow type.
|
|
5
6
|
*
|
|
@@ -28,4 +29,6 @@ export interface RegisteredWorkflowDefinition<TInput = unknown, TOutput = unknow
|
|
|
28
29
|
outputSchema?: DefinitionSchema<unknown, TOutput>;
|
|
29
30
|
/** Optional search attribute schema used for indexing and runtime validation. */
|
|
30
31
|
searchAttributes?: SearchAttributeSchema;
|
|
32
|
+
/** Optional start admission policy for this workflow type. */
|
|
33
|
+
concurrency?: WorkflowConcurrencyOptions<TInput>;
|
|
31
34
|
}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './types/activity-verification.ts';
|
|
1
2
|
export * from './types/activity.ts';
|
|
2
3
|
export * from './types/archive-adapter.ts';
|
|
3
4
|
export * from './types/bulk.ts';
|
|
@@ -8,6 +9,7 @@ export * from './types/definition-schema.ts';
|
|
|
8
9
|
export * from './types/history-policy.ts';
|
|
9
10
|
export * from './types/identity.ts';
|
|
10
11
|
export * from './types/launch-metadata.ts';
|
|
12
|
+
export * from './types/list-options.ts';
|
|
11
13
|
export * from './types/message-handles.ts';
|
|
12
14
|
export * from './types/options.ts';
|
|
13
15
|
export * from './types/payload-size-policy.ts';
|
|
@@ -22,8 +24,10 @@ export * from './types/state.ts';
|
|
|
22
24
|
export * from './types/workflow-builder-helpers.ts';
|
|
23
25
|
export * from './types/workflow-builder-runtime.ts';
|
|
24
26
|
export * from './types/workflow-builder.ts';
|
|
27
|
+
export * from './types/workflow-concurrency.ts';
|
|
25
28
|
export * from './types/workflow-context.ts';
|
|
26
29
|
export * from './types/workflow-function.ts';
|
|
30
|
+
export * from './types/workflow-log.ts';
|
|
27
31
|
export * from './types/workflow-registries.ts';
|
|
28
32
|
export * from './types/workflow-registry.ts';
|
|
29
33
|
export * from './types/workflow-snapshot.ts';
|
package/dist/core/types.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./types/activity-verification.js";
|
|
1
2
|
export * from "./types/activity.js";
|
|
2
3
|
export * from "./types/archive-adapter.js";
|
|
3
4
|
export * from "./types/bulk.js";
|
|
@@ -8,6 +9,7 @@ export * from "./types/definition-schema.js";
|
|
|
8
9
|
export * from "./types/history-policy.js";
|
|
9
10
|
export * from "./types/identity.js";
|
|
10
11
|
export * from "./types/launch-metadata.js";
|
|
12
|
+
export * from "./types/list-options.js";
|
|
11
13
|
export * from "./types/message-handles.js";
|
|
12
14
|
export * from "./types/options.js";
|
|
13
15
|
export * from "./types/payload-size-policy.js";
|
|
@@ -22,8 +24,10 @@ export * from "./types/state.js";
|
|
|
22
24
|
export * from "./types/workflow-builder-helpers.js";
|
|
23
25
|
export * from "./types/workflow-builder-runtime.js";
|
|
24
26
|
export * from "./types/workflow-builder.js";
|
|
27
|
+
export * from "./types/workflow-concurrency.js";
|
|
25
28
|
export * from "./types/workflow-context.js";
|
|
26
29
|
export * from "./types/workflow-function.js";
|
|
30
|
+
export * from "./types/workflow-log.js";
|
|
27
31
|
export * from "./types/workflow-registries.js";
|
|
28
32
|
export * from "./types/workflow-registry.js";
|
|
29
33
|
export * from "./types/workflow-snapshot.js";
|
|
@@ -1,62 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Workflow version comparison and checkpoint
|
|
2
|
+
* Workflow version comparison and checkpoint diagnostics.
|
|
3
3
|
*
|
|
4
4
|
* Provides utilities for detecting version mismatches between stored
|
|
5
|
-
* and registered workflow definitions
|
|
6
|
-
* and building atomic batch operations for version updates.
|
|
5
|
+
* and registered workflow definitions.
|
|
7
6
|
*
|
|
8
7
|
* @module versioning
|
|
9
8
|
*/
|
|
10
|
-
import type { BatchOperation } from '../storage/interface.ts';
|
|
11
9
|
import { WeftError } from './weft-error.ts';
|
|
12
10
|
import type { WorkflowVersionDiff } from './workflow-version-tuple.ts';
|
|
13
11
|
/** Default version string assigned when no version is specified. */
|
|
14
12
|
export declare const DEFAULT_WORKFLOW_VERSION = "0.0.0";
|
|
15
|
-
export type VersionCompatibility = 'compatible' | '
|
|
13
|
+
export type VersionCompatibility = 'compatible' | 'incompatible';
|
|
16
14
|
/**
|
|
17
15
|
* Compare a stored workflow version with the currently registered version.
|
|
18
16
|
*
|
|
19
17
|
* - `"compatible"` — versions match; no action needed.
|
|
20
|
-
* - `"
|
|
21
|
-
*
|
|
22
|
-
* will throw a {@link VersionMismatchError} instead of resuming silently.
|
|
18
|
+
* - `"incompatible"` — versions differ; the engine will throw a
|
|
19
|
+
* {@link VersionMismatchError} instead of resuming silently.
|
|
23
20
|
*
|
|
24
21
|
* @example
|
|
25
22
|
* ```ts
|
|
26
23
|
* import { checkVersionCompatibility } from '@lostgradient/weft';
|
|
27
24
|
*
|
|
28
|
-
* console.log(checkVersionCompatibility('1.0.0', '1.0.0'
|
|
29
|
-
* console.log(checkVersionCompatibility('1.0.0', '2.0.0'
|
|
30
|
-
* console.log(checkVersionCompatibility('1.0.0', '2.0.0', false)); // 'incompatible'
|
|
25
|
+
* console.log(checkVersionCompatibility('1.0.0', '1.0.0')); // 'compatible'
|
|
26
|
+
* console.log(checkVersionCompatibility('1.0.0', '2.0.0')); // 'incompatible'
|
|
31
27
|
* ```
|
|
32
28
|
*/
|
|
33
|
-
export declare function checkVersionCompatibility(storedVersion: string, registeredVersion: string
|
|
34
|
-
/**
|
|
35
|
-
* Run a migration function on checkpoint data, transforming it from one
|
|
36
|
-
* version to another.
|
|
37
|
-
*
|
|
38
|
-
* The caller is responsible for serializing the result back to bytes if needed.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* import { migrateCheckpoint } from '@lostgradient/weft';
|
|
43
|
-
*
|
|
44
|
-
* const oldData = { step: 0, locals: { counter: 1 }, version: '1.0.0' };
|
|
45
|
-
* const migrated = migrateCheckpoint(oldData, '1.0.0', '2.0.0', (data) => {
|
|
46
|
-
* const d = data as typeof oldData;
|
|
47
|
-
* return { ...d, locals: { ...d.locals, newField: 'default' } };
|
|
48
|
-
* });
|
|
49
|
-
* void migrated;
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export declare function migrateCheckpoint(checkpointData: unknown, fromVersion: string, _toVersion: string, migrate: (checkpoint: unknown, fromVersion: string) => unknown): unknown;
|
|
53
|
-
/**
|
|
54
|
-
* Build batch operations that atomically update the checkpoint and workflow
|
|
55
|
-
* state after a successful migration.
|
|
56
|
-
*
|
|
57
|
-
* The returned operations are suitable for passing to `Storage.batch()`.
|
|
58
|
-
*/
|
|
59
|
-
export declare function buildVersionUpdateOperations(workflowId: string, newCheckpointBytes: Uint8Array, _newVersion: string, workflowStateBytes: Uint8Array): BatchOperation[];
|
|
29
|
+
export declare function checkVersionCompatibility(storedVersion: string, registeredVersion: string): VersionCompatibility;
|
|
60
30
|
/** Description of a single field-level difference between checkpoint shapes. */
|
|
61
31
|
export type FieldDiff = {
|
|
62
32
|
field: string;
|
|
@@ -115,7 +85,7 @@ export type ShapeDiffOptions = {
|
|
|
115
85
|
};
|
|
116
86
|
/**
|
|
117
87
|
* Thrown when a workflow's stored version does not match its registered
|
|
118
|
-
* version
|
|
88
|
+
* version.
|
|
119
89
|
*
|
|
120
90
|
* When shape information is provided, the error message includes a
|
|
121
91
|
* field-level diff describing exactly which fields changed.
|
package/dist/core/versioning.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { KEYS } from "../storage/interface.js";
|
|
2
1
|
import { WeftError } from "./weft-error.js";
|
|
3
2
|
import { formatWorkflowVersionDiff } from "./workflow-version-tuple.js";
|
|
4
3
|
export const DEFAULT_WORKFLOW_VERSION = "0.0.0";
|
|
5
|
-
export function checkVersionCompatibility(storedVersion, registeredVersion
|
|
4
|
+
export function checkVersionCompatibility(storedVersion, registeredVersion) {
|
|
6
5
|
if (storedVersion === registeredVersion)
|
|
7
6
|
return "compatible";
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
export function migrateCheckpoint(checkpointData, fromVersion, _toVersion, migrate) {
|
|
11
|
-
return migrate(checkpointData, fromVersion);
|
|
12
|
-
}
|
|
13
|
-
export function buildVersionUpdateOperations(workflowId, newCheckpointBytes, _newVersion, workflowStateBytes) {
|
|
14
|
-
return [
|
|
15
|
-
{ type: "put", key: KEYS.checkpoint(workflowId), value: newCheckpointBytes },
|
|
16
|
-
{ type: "put", key: KEYS.workflow(workflowId), value: workflowStateBytes }
|
|
17
|
-
];
|
|
7
|
+
return "incompatible";
|
|
18
8
|
}
|
|
19
9
|
export function diffCheckpointShapes(oldShape, newShape) {
|
|
20
10
|
const diffs = [], allKeys = new Set([...Object.keys(oldShape), ...Object.keys(newShape)]);
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* when an error may have crossed a realm or duplicate-module boundary, where
|
|
10
10
|
* `instanceof` is unreliable.
|
|
11
11
|
*
|
|
12
|
+
* See `documentation/reference/api-errors.md` for the source-complete error
|
|
13
|
+
* code table and usage guidance for the exported guards.
|
|
14
|
+
*
|
|
12
15
|
* @example
|
|
13
16
|
* ```ts
|
|
14
17
|
* import { isWeftErrorLike, type WeftErrorCode } from '@lostgradient/weft';
|
|
@@ -22,7 +25,7 @@
|
|
|
22
25
|
* }
|
|
23
26
|
* ```
|
|
24
27
|
*/
|
|
25
|
-
export type WeftErrorCode = 'WorkflowAlreadyExistsError' | 'BulkDeleteRequiresTerminalWorkflowsError' | 'BulkOperationConfirmationError' | 'WorkflowTypeNotRegisteredForRecoveryError' | 'EngineCreateNameMismatchError' | 'EngineDisposedError' | 'WorkflowNotFoundError' | 'WorkflowNotRegisteredError' | 'ActivityResolutionError' | 'PersistedDataIncompatibleError' | 'WorkflowTimeoutError' | 'HttpClientError' | 'WorkerProtocolIncompatibleError' | 'UpdateTimeoutError' | 'UpdateValidationError' | 'WorkflowTerminalError' | 'WorkflowBuilderError' | 'VersionMismatchError' | 'EffectReplayConflictError' | 'ReviewTimeoutError' | 'AtomicStateConflictError' | 'StandardSchemaValidationError' | 'ActivityReconciliationCapabilityError' | 'ActivityReconciliationConflictError' | 'ActivityReconciliationIndeterminateError' | 'AsyncActivityTokenNotFoundError' | 'PayloadSizeExceededError' | 'StartOrSignalConflictError' | 'IdempotencyKeyPurgedError';
|
|
28
|
+
export type WeftErrorCode = 'WorkflowAlreadyExistsError' | 'BulkDeleteRequiresTerminalWorkflowsError' | 'BulkOperationConfirmationError' | 'WorkflowTypeNotRegisteredForRecoveryError' | 'EngineCreateNameMismatchError' | 'EngineDisposedError' | 'WorkflowNotFoundError' | 'WorkflowNotRegisteredError' | 'WorkflowConcurrencyLimitExceededError' | 'WorkflowSuspendNotSupportedError' | 'ActivityResolutionError' | 'BranchTopologyChangedError' | 'PersistedDataIncompatibleError' | 'WorkflowTimeoutError' | 'HttpClientError' | 'WorkerProtocolIncompatibleError' | 'UpdateTimeoutError' | 'UpdateValidationError' | 'WorkflowTerminalError' | 'WorkflowBuilderError' | 'VersionMismatchError' | 'EffectReplayConflictError' | 'ReviewTimeoutError' | 'AtomicStateConflictError' | 'StandardSchemaValidationError' | 'ActivityReconciliationCapabilityError' | 'ActivityReconciliationConflictError' | 'ActivityReconciliationIndeterminateError' | 'AsyncActivityTokenNotFoundError' | 'ActivityScheduleToCloseTimeoutError' | 'ActivityPerAttemptTimeoutError' | 'PayloadSizeExceededError' | 'StartOrSignalConflictError' | 'IdempotencyKeyPurgedError';
|
|
26
29
|
/**
|
|
27
30
|
* Generic abstract base for all Weft library errors. The `TCode` parameter
|
|
28
31
|
* makes each subclass's `code` its own literal type; the exported base surface
|
|
@@ -55,6 +58,9 @@ export declare abstract class WeftError<TCode extends string = string> extends E
|
|
|
55
58
|
* object structurally. {@link isWeftErrorCode} narrows a bare `code` *string*,
|
|
56
59
|
* not a caught `unknown`.
|
|
57
60
|
*
|
|
61
|
+
* See `documentation/reference/api-errors.md#error-helpers` for guard selection
|
|
62
|
+
* examples across same-realm and cross-boundary errors.
|
|
63
|
+
*
|
|
58
64
|
* @example
|
|
59
65
|
* ```ts
|
|
60
66
|
* import { isWeftError } from '@lostgradient/weft';
|
|
@@ -71,6 +77,9 @@ export declare function isWeftError(value: unknown): value is WeftError;
|
|
|
71
77
|
* a caught `unknown` (the common `catch` case), reach for {@link isWeftErrorLike},
|
|
72
78
|
* which checks the whole error object structurally.
|
|
73
79
|
*
|
|
80
|
+
* See `documentation/reference/api-errors.md#error-helpers` for guard selection
|
|
81
|
+
* examples across same-realm and cross-boundary errors.
|
|
82
|
+
*
|
|
74
83
|
* @example
|
|
75
84
|
* ```ts
|
|
76
85
|
* import { isWeftErrorCode } from '@lostgradient/weft';
|
|
@@ -96,6 +105,9 @@ export declare function isWeftErrorCode(value: unknown): value is WeftErrorCode;
|
|
|
96
105
|
* To match a *specific* code, narrow with this guard then compare `error.code`
|
|
97
106
|
* — TypeScript narrows it to the matched literal in the branch.
|
|
98
107
|
*
|
|
108
|
+
* See `documentation/reference/api-errors.md#error-helpers` for guard selection
|
|
109
|
+
* examples across same-realm and cross-boundary errors.
|
|
110
|
+
*
|
|
99
111
|
* @example
|
|
100
112
|
* ```ts
|
|
101
113
|
* import { isWeftErrorLike } from '@lostgradient/weft';
|
|
@@ -112,3 +124,34 @@ export declare function isWeftErrorLike(value: unknown): value is {
|
|
|
112
124
|
code: WeftErrorCode;
|
|
113
125
|
message: string;
|
|
114
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Transport-uniform error classification: `true` when `error` represents the
|
|
129
|
+
* given public {@link WeftErrorCode}, whether it was thrown in process or
|
|
130
|
+
* arrived over HTTP. This is the canonical way to branch on a specific Weft
|
|
131
|
+
* error without caring which transport produced it — the predicate the
|
|
132
|
+
* `WeftClient` "constructor change, not an API change" promise rests on.
|
|
133
|
+
*
|
|
134
|
+
* It matches two shapes with one rule:
|
|
135
|
+
* - An in-process typed error (or any {@link isWeftErrorLike} value) whose
|
|
136
|
+
* `code` equals `code` — what `LocalClient` throws.
|
|
137
|
+
* - An `HttpClientError` carrying `weftCode === code` — what `HttpClient`
|
|
138
|
+
* throws when the REST fault rehydrated the originating public code. The
|
|
139
|
+
* check is structural (`'weftCode' in error`) rather than `instanceof
|
|
140
|
+
* HttpClientError`, both to stay reliable across realm/duplicate-module
|
|
141
|
+
* boundaries and to keep this guard in the core layer without importing the
|
|
142
|
+
* client.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { isWeftFault } from '@lostgradient/weft';
|
|
147
|
+
*
|
|
148
|
+
* // The same branch holds over LocalClient and HttpClient: a missing workflow
|
|
149
|
+
* // is a no-op success ("nothing to tell"), not a failure to re-raise.
|
|
150
|
+
* function rethrowUnlessMissing(error: unknown): void {
|
|
151
|
+
* if (!isWeftFault(error, 'WorkflowNotFoundError')) {
|
|
152
|
+
* throw error;
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function isWeftFault(error: unknown, code: WeftErrorCode): boolean;
|
package/dist/core/weft-error.js
CHANGED
|
@@ -15,7 +15,10 @@ const publicWeftErrorCodeMap = {
|
|
|
15
15
|
EngineDisposedError: !0,
|
|
16
16
|
WorkflowNotFoundError: !0,
|
|
17
17
|
WorkflowNotRegisteredError: !0,
|
|
18
|
+
WorkflowConcurrencyLimitExceededError: !0,
|
|
19
|
+
WorkflowSuspendNotSupportedError: !0,
|
|
18
20
|
ActivityResolutionError: !0,
|
|
21
|
+
BranchTopologyChangedError: !0,
|
|
19
22
|
PersistedDataIncompatibleError: !0,
|
|
20
23
|
WorkflowTimeoutError: !0,
|
|
21
24
|
HttpClientError: !0,
|
|
@@ -33,6 +36,8 @@ const publicWeftErrorCodeMap = {
|
|
|
33
36
|
ActivityReconciliationConflictError: !0,
|
|
34
37
|
ActivityReconciliationIndeterminateError: !0,
|
|
35
38
|
AsyncActivityTokenNotFoundError: !0,
|
|
39
|
+
ActivityScheduleToCloseTimeoutError: !0,
|
|
40
|
+
ActivityPerAttemptTimeoutError: !0,
|
|
36
41
|
PayloadSizeExceededError: !0,
|
|
37
42
|
StartOrSignalConflictError: !0,
|
|
38
43
|
IdempotencyKeyPurgedError: !0
|
|
@@ -52,3 +57,14 @@ export function isWeftErrorLike(value) {
|
|
|
52
57
|
return !1;
|
|
53
58
|
}
|
|
54
59
|
}
|
|
60
|
+
export function isWeftFault(error, code) {
|
|
61
|
+
if (isWeftErrorLike(error) && error.code === code)
|
|
62
|
+
return !0;
|
|
63
|
+
if (typeof error !== "object" || error === null)
|
|
64
|
+
return !1;
|
|
65
|
+
try {
|
|
66
|
+
return "weftCode" in error && error.weftCode === code;
|
|
67
|
+
} catch {
|
|
68
|
+
return !1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
+
import type { WorkflowLogRecord } from './types/workflow-log.ts';
|
|
1
2
|
export interface WorkerExecutionStrategyOptions {
|
|
2
3
|
broadcastEvents?: boolean;
|
|
3
4
|
workflowTurnTimeoutMs?: number;
|
|
4
5
|
maxProtocolMessageBytes?: number;
|
|
5
6
|
requireProtocolVersion?: boolean;
|
|
6
7
|
discardOnCancel?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The engine host's `EngineOptions.onLog` sink (#529). When present, the strategy
|
|
10
|
+
* tells each worker (`hostHasLogSink: true` on `run`/`resume`) to forward `ctx.log`
|
|
11
|
+
* records back as `log` protocol messages, which are delivered here instead of the
|
|
12
|
+
* worker console. When absent, workers log to their own console (the default).
|
|
13
|
+
*/
|
|
14
|
+
onLog?: (record: WorkflowLogRecord) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Monotonic-enough wall clock (ms) for the forwarded-log abuse counter's flood
|
|
17
|
+
* window (#545). Injected so tests advance time deterministically; defaults to
|
|
18
|
+
* `Date.now` when omitted (the non-worker-construction path / direct tests).
|
|
19
|
+
*/
|
|
20
|
+
getNow?: () => number;
|
|
21
|
+
/**
|
|
22
|
+
* Internal test seams for the forwarded-log abuse counter (#545). Not a public
|
|
23
|
+
* engine option — the abuse thresholds are deliberately fixed and generous so honest
|
|
24
|
+
* high-log workflows are never discarded. These exist only so unit tests can inject
|
|
25
|
+
* small thresholds (and a controllable window) to exercise the discard paths without
|
|
26
|
+
* sending thousands of messages; each falls back to its worker-protocol default.
|
|
27
|
+
*/
|
|
28
|
+
forwardedLogFloodWindowMs?: number;
|
|
29
|
+
/** See {@link WorkerExecutionStrategyOptions.forwardedLogFloodWindowMs} — internal test seam (#545). */
|
|
30
|
+
forwardedLogFloodThreshold?: number;
|
|
31
|
+
/** See {@link WorkerExecutionStrategyOptions.forwardedLogFloodWindowMs} — internal test seam (#545). */
|
|
32
|
+
forwardedLogStrikeThreshold?: number;
|
|
7
33
|
}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { WorkerCheckpointResumeState } from "./worker-checkpoint-resume-state.js";
|
|
2
|
-
import {
|
|
3
|
-
WorkerExecutionDispatcher
|
|
4
|
-
} from "./worker-execution-dispatcher.js";
|
|
2
|
+
import { WorkerExecutionDispatcher } from "./worker-execution-dispatcher.js";
|
|
5
3
|
import { WorkerExecutionOwnership } from "./worker-execution-ownership.js";
|
|
4
|
+
import {
|
|
5
|
+
buildResumeMessage,
|
|
6
|
+
buildRunMessage
|
|
7
|
+
} from "./worker-inbound-message.js";
|
|
6
8
|
import { WorkerListenerRegistry } from "./worker-listener-registry.js";
|
|
9
|
+
import {
|
|
10
|
+
forwardedLogGateFromStrategyOptions
|
|
11
|
+
} from "./worker-log-abuse-counter.js";
|
|
7
12
|
import {
|
|
8
13
|
emitWorkerMessageToEngine,
|
|
9
14
|
isParkableWaitSignalCheckpoint
|
|
10
15
|
} from "./worker-message-helpers.js";
|
|
11
16
|
import { WorkerProtocolGuard } from "./worker-protocol-guard.js";
|
|
17
|
+
import { isWorkerLogMessage } from "./worker-protocol-log.js";
|
|
12
18
|
import { WORKER_PROTOCOL_VERSION } from "./worker-protocol.js";
|
|
13
19
|
import { WorkerTurnWatchdog } from "./worker-turn-watchdog.js";
|
|
14
20
|
|
|
@@ -23,6 +29,7 @@ export class WorkerExecutionStrategy {
|
|
|
23
29
|
#maxProtocolMessageBytes;
|
|
24
30
|
#requireProtocolVersion;
|
|
25
31
|
#discardOnCancel;
|
|
32
|
+
#forwardedLogGate;
|
|
26
33
|
#turnWatchdog;
|
|
27
34
|
#protocolGuard;
|
|
28
35
|
#dispatcher;
|
|
@@ -30,14 +37,22 @@ export class WorkerExecutionStrategy {
|
|
|
30
37
|
#disposed;
|
|
31
38
|
#nextTurnId;
|
|
32
39
|
constructor(pool, options) {
|
|
40
|
+
const {
|
|
41
|
+
workflowTurnTimeoutMs,
|
|
42
|
+
maxProtocolMessageBytes,
|
|
43
|
+
requireProtocolVersion = !1,
|
|
44
|
+
discardOnCancel = !1,
|
|
45
|
+
broadcastEvents = !1
|
|
46
|
+
} = options ?? {};
|
|
33
47
|
this.#pool = pool;
|
|
34
48
|
this.#ownership = new WorkerExecutionOwnership;
|
|
35
49
|
this.#workerListeners = new WorkerListenerRegistry;
|
|
36
50
|
this.#checkpointResumeState = new WorkerCheckpointResumeState;
|
|
37
|
-
this.#workflowTurnTimeoutMs =
|
|
38
|
-
this.#maxProtocolMessageBytes =
|
|
39
|
-
this.#requireProtocolVersion =
|
|
40
|
-
this.#discardOnCancel =
|
|
51
|
+
this.#workflowTurnTimeoutMs = workflowTurnTimeoutMs;
|
|
52
|
+
this.#maxProtocolMessageBytes = maxProtocolMessageBytes;
|
|
53
|
+
this.#requireProtocolVersion = requireProtocolVersion;
|
|
54
|
+
this.#discardOnCancel = discardOnCancel;
|
|
55
|
+
this.#forwardedLogGate = forwardedLogGateFromStrategyOptions(options, maxProtocolMessageBytes);
|
|
41
56
|
this.#turnWatchdog = new WorkerTurnWatchdog(this.#workflowTurnTimeoutMs, (turn) => {
|
|
42
57
|
this.#handleTurnTimeout(turn);
|
|
43
58
|
});
|
|
@@ -72,7 +87,7 @@ export class WorkerExecutionStrategy {
|
|
|
72
87
|
this.#broadcastListener = null;
|
|
73
88
|
this.#disposed = !1;
|
|
74
89
|
this.#nextTurnId = 1;
|
|
75
|
-
if (
|
|
90
|
+
if (broadcastEvents)
|
|
76
91
|
try {
|
|
77
92
|
this.#broadcastChannel = new BroadcastChannel("weft:events");
|
|
78
93
|
this.#broadcastListener = (event) => {
|
|
@@ -87,22 +102,7 @@ export class WorkerExecutionStrategy {
|
|
|
87
102
|
startWorkflow(parameters) {
|
|
88
103
|
this.#ownership.resetWorkflow(parameters.workflowId);
|
|
89
104
|
this.#checkpointResumeState.resetWorkflow(parameters.workflowId);
|
|
90
|
-
const message =
|
|
91
|
-
type: "run",
|
|
92
|
-
protocolVersion: WORKER_PROTOCOL_VERSION,
|
|
93
|
-
turnId: this.#nextTurnId++,
|
|
94
|
-
workflowId: parameters.workflowId,
|
|
95
|
-
workflowType: parameters.workflowType,
|
|
96
|
-
checkpoint: parameters.checkpoint,
|
|
97
|
-
input: parameters.input,
|
|
98
|
-
executionStateOwnerId: parameters.executionStateOwnerId ?? parameters.workflowId
|
|
99
|
-
};
|
|
100
|
-
if (this.#maxProtocolMessageBytes !== void 0)
|
|
101
|
-
message.maxProtocolMessageBytes = this.#maxProtocolMessageBytes;
|
|
102
|
-
if (parameters.deadline !== void 0)
|
|
103
|
-
message.deadline = parameters.deadline;
|
|
104
|
-
if (parameters.headers)
|
|
105
|
-
message.headers = parameters.headers;
|
|
105
|
+
const message = buildRunMessage(parameters, this.#inboundMessageContext());
|
|
106
106
|
if (!this.#assertHostToWorkerMessageWithinLimit(parameters.workflowId, message))
|
|
107
107
|
return;
|
|
108
108
|
this.#dispatcher.acquireAndSend(parameters.workflowId, message);
|
|
@@ -111,12 +111,14 @@ export class WorkerExecutionStrategy {
|
|
|
111
111
|
const worker = this.#ownership.getActiveWorker(parameters.workflowId);
|
|
112
112
|
if (worker) {
|
|
113
113
|
this.#checkpointResumeState.recordResume(parameters.workflowId);
|
|
114
|
-
|
|
114
|
+
const resumeMessage = buildResumeMessage(parameters, this.#inboundMessageContext());
|
|
115
|
+
this.#dispatcher.postResumeMessage(worker, parameters, resumeMessage);
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
118
|
const parkedWorker = this.#ownership.getParkedWorker(parameters.workflowId);
|
|
118
119
|
if (parkedWorker) {
|
|
119
|
-
|
|
120
|
+
const resumeMessage = buildResumeMessage(parameters, this.#inboundMessageContext());
|
|
121
|
+
this.#dispatcher.resumeParkedWorkflow(parameters, parkedWorker, resumeMessage);
|
|
120
122
|
return;
|
|
121
123
|
}
|
|
122
124
|
if (this.#ownership.consumeCancelled(parameters.workflowId))
|
|
@@ -128,18 +130,12 @@ export class WorkerExecutionStrategy {
|
|
|
128
130
|
error: `No worker assigned for workflow: ${parameters.workflowId}`
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
|
-
#
|
|
132
|
-
|
|
133
|
-
type: "resume",
|
|
134
|
-
protocolVersion: WORKER_PROTOCOL_VERSION,
|
|
133
|
+
#inboundMessageContext() {
|
|
134
|
+
return {
|
|
135
135
|
turnId: this.#nextTurnId++,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
operationResult: parameters.operationResult
|
|
136
|
+
maxProtocolMessageBytes: this.#maxProtocolMessageBytes,
|
|
137
|
+
hasLogSink: this.#forwardedLogGate.hasSink
|
|
139
138
|
};
|
|
140
|
-
if (this.#maxProtocolMessageBytes !== void 0)
|
|
141
|
-
message.maxProtocolMessageBytes = this.#maxProtocolMessageBytes;
|
|
142
|
-
return message;
|
|
143
139
|
}
|
|
144
140
|
cancelWorkflow(workflowId) {
|
|
145
141
|
const worker = this.#ownership.getActiveWorker(workflowId);
|
|
@@ -205,6 +201,12 @@ export class WorkerExecutionStrategy {
|
|
|
205
201
|
this.#messageHandler = null;
|
|
206
202
|
}
|
|
207
203
|
async#handleWorkerMessage(worker, message) {
|
|
204
|
+
if (isWorkerLogMessage(message)) {
|
|
205
|
+
const owns = (id) => this.#ownership.getTargetWorker(id) === worker, abuseDiscard = this.#forwardedLogGate.handle(worker, message, owns);
|
|
206
|
+
if (abuseDiscard)
|
|
207
|
+
this.#discardWorkerAndFailWorkflows(worker, abuseDiscard);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
208
210
|
if (!this.#acceptWorkerMessage(worker, message))
|
|
209
211
|
return;
|
|
210
212
|
this.#turnWatchdog.clear(worker);
|
|
@@ -322,6 +324,7 @@ export class WorkerExecutionStrategy {
|
|
|
322
324
|
const workflowIds = this.#ownership.workflowIdsForWorker(worker);
|
|
323
325
|
if (workflowIds.length === 0) {
|
|
324
326
|
this.#turnWatchdog.clear(worker);
|
|
327
|
+
this.#forwardedLogGate.forget(worker);
|
|
325
328
|
return;
|
|
326
329
|
}
|
|
327
330
|
for (const workflowId of workflowIds) {
|
|
@@ -338,6 +341,7 @@ export class WorkerExecutionStrategy {
|
|
|
338
341
|
});
|
|
339
342
|
}
|
|
340
343
|
this.#turnWatchdog.clear(worker);
|
|
344
|
+
this.#forwardedLogGate.forget(worker);
|
|
341
345
|
this.#workerListeners.detach(worker);
|
|
342
346
|
this.#pool.discard(worker);
|
|
343
347
|
}
|