@lostgradient/weft 0.12.0 → 0.13.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 +1 -1
- package/dist/cli/api.d.ts +2 -0
- package/dist/cli/api.js +3 -4
- package/dist/cli/generated/operation-catalog.snapshot.json +508 -12
- package/dist/cli/generated/operation-client.generated.d.ts +118 -10
- package/dist/cli/generated/operation-client.generated.js +74 -1
- package/dist/cli/operation-catalog-snapshot.d.ts +11 -2
- package/dist/cli/operation-catalog-snapshot.js +14 -5
- package/dist/cli/operation-client-runtime.d.ts +29 -0
- package/dist/client/client-storage.d.ts +24 -0
- package/dist/client/client-storage.js +14 -0
- package/dist/client/handle-delegation.d.ts +3 -3
- package/dist/client/handle-delegation.js +2 -2
- package/dist/client/http-client-requests.d.ts +5 -3
- package/dist/client/http-client-requests.js +20 -2
- package/dist/client/http-client-storage.d.ts +3 -0
- package/dist/client/http-client-storage.js +110 -0
- package/dist/client/http-client.d.ts +9 -6
- package/dist/client/http-client.js +13 -18
- package/dist/client/http-operations.d.ts +3 -1
- package/dist/client/http-operations.js +77 -1
- package/dist/client/http-request.d.ts +15 -8
- package/dist/client/http-request.js +19 -7
- package/dist/client/in-process-operations.d.ts +2 -2
- package/dist/client/in-process-operations.js +2 -2
- package/dist/client/index.d.ts +5 -1
- package/dist/client/index.js +13 -2
- package/dist/client/interface.d.ts +26 -26
- package/dist/client/local.d.ts +9 -6
- package/dist/client/local.js +9 -4
- package/dist/client/search-params.js +10 -6
- package/dist/client/start-body.d.ts +3 -1
- package/dist/client/start-body.js +9 -0
- package/dist/core/bulk-workflow-filter.d.ts +2 -1
- package/dist/core/bulk-workflow-filter.js +5 -1
- package/dist/core/engine/async-activity-records.d.ts +12 -1
- package/dist/core/engine/async-activity-records.js +81 -2
- package/dist/core/engine/bulk-operations-purge.js +16 -1
- package/dist/core/engine/bulk-operations-shared.js +2 -0
- package/dist/core/engine/callback-creators-schedule.d.ts +2 -1
- package/dist/core/engine/callback-creators-schedule.js +3 -3
- package/dist/core/engine/checkpoint-reads.js +11 -1
- package/dist/core/engine/child-workflow.js +15 -6
- package/dist/core/engine/construction.js +3 -0
- package/dist/core/engine/disposal.js +2 -0
- package/dist/core/engine/engine-internal-types.d.ts +4 -1
- package/dist/core/engine/fenced-write.d.ts +5 -3
- package/dist/core/engine/finalizer-status.d.ts +10 -0
- package/dist/core/engine/finalizer-status.js +82 -0
- package/dist/core/engine/index.d.ts +26 -2
- package/dist/core/engine/index.js +71 -8
- package/dist/core/engine/internals.d.ts +3 -0
- package/dist/core/engine/lease-health.d.ts +64 -0
- package/dist/core/engine/lease-health.js +0 -0
- package/dist/core/engine/lease-manager.d.ts +4 -2
- package/dist/core/engine/lease-manager.js +32 -4
- package/dist/core/engine/lifecycle/recovered-services.js +0 -2
- package/dist/core/engine/lifecycle/shared.d.ts +11 -8
- package/dist/core/engine/lifecycle/start-batch.js +12 -0
- package/dist/core/engine/lifecycle/start.d.ts +1 -1
- package/dist/core/engine/lifecycle/start.js +34 -5
- package/dist/core/engine/operations-coordination.d.ts +1 -12
- package/dist/core/engine/operations-coordination.js +57 -10
- package/dist/core/engine/operations-speculate.d.ts +1 -1
- package/dist/core/engine/operations-speculate.js +19 -5
- package/dist/core/engine/registration.js +14 -0
- package/dist/core/engine/schedule-handle.d.ts +4 -4
- package/dist/core/engine/schedule-handle.js +2 -2
- package/dist/core/engine/schedule-overlap.d.ts +11 -0
- package/dist/core/engine/schedule-overlap.js +50 -0
- package/dist/core/engine/schedule-run.d.ts +11 -3
- package/dist/core/engine/schedule-run.js +27 -4
- package/dist/core/engine/schedule-timer.js +10 -1
- package/dist/core/engine/schedules.d.ts +5 -4
- package/dist/core/engine/schedules.js +62 -56
- package/dist/core/engine/state-utilities.js +1 -1
- package/dist/core/engine/storage-io.d.ts +12 -0
- package/dist/core/engine/storage-io.js +49 -10
- package/dist/core/engine/termination/finalizer-claim.d.ts +8 -6
- package/dist/core/engine/termination/finalizer-claim.js +2 -1
- package/dist/core/engine/termination/finalizer.js +10 -14
- package/dist/core/engine/timeline-coordinator-constants.d.ts +3 -0
- package/dist/core/engine/timeline-coordinator-constants.js +1 -0
- package/dist/core/engine/timeline-coordinator-detail.d.ts +13 -0
- package/dist/core/engine/timeline-coordinator-detail.js +76 -0
- package/dist/core/engine/validation/schedule-options.d.ts +8 -1
- package/dist/core/engine/validation/schedule-options.js +18 -0
- package/dist/core/engine/validation/schedule.d.ts +1 -1
- package/dist/core/engine/validation/schedule.js +27 -3
- package/dist/core/engine/validation.js +66 -2
- package/dist/core/engine/workflow-state-stream.d.ts +5 -1
- package/dist/core/engine/workflow-state-stream.js +37 -14
- package/dist/core/events/schedule-events.d.ts +3 -4
- package/dist/core/events/workflow-events.d.ts +2 -1
- package/dist/core/list-filter-validation.d.ts +3 -0
- package/dist/core/list-filter-validation.js +11 -0
- package/dist/core/registry-snapshot.d.ts +32 -0
- package/dist/core/registry-snapshot.js +28 -0
- package/dist/core/review/index.d.ts +4 -4
- package/dist/core/types/activity.d.ts +52 -5
- package/dist/core/types/bulk.d.ts +1 -0
- package/dist/core/types/list-options.d.ts +6 -0
- package/dist/core/types/options.d.ts +6 -5
- package/dist/core/types/reviews.d.ts +2 -2
- package/dist/core/types/schedules.d.ts +45 -2
- package/dist/core/types/services-resolution.d.ts +5 -5
- package/dist/core/types/state.d.ts +64 -0
- package/dist/core/types/workflow-log.d.ts +3 -2
- package/dist/core/types/workflow-observability.d.ts +50 -0
- package/dist/core/types/workflow-observability.js +0 -0
- package/dist/core/types/workflow-registry.d.ts +7 -0
- package/dist/core/types.d.ts +1 -0
- package/dist/core/types.js +1 -0
- package/dist/http.js +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/indexeddb.js +1 -1
- package/dist/server/access-policy-metadata.d.ts +92 -0
- package/dist/server/access-policy-metadata.js +78 -0
- package/dist/server/fault-to-http.d.ts +3 -7
- package/dist/server/fault-to-http.js +2 -34
- package/dist/server/handler/index.js +1 -1
- package/dist/server/handler/route-dispatch.d.ts +10 -3
- package/dist/server/handler/route-dispatch.js +19 -4
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server/interactive-operations.js +2 -0
- package/dist/server/openapi-error-responses.js +55 -4
- package/dist/server/openapi.d.ts +3 -1
- package/dist/server/openapi.js +4 -0
- package/dist/server/openrpc-document-schema.d.ts +64 -0
- package/dist/server/openrpc-document-schema.js +6 -26
- package/dist/server/openrpc.d.ts +4 -0
- package/dist/server/openrpc.js +9 -33
- package/dist/server/operation-fault.d.ts +24 -7
- package/dist/server/operation-fault.js +65 -13
- package/dist/server/operations/aggregate-workflows.d.ts +6 -0
- package/dist/server/operations/aggregate-workflows.js +3 -2
- package/dist/server/operations/async-activity.d.ts +14 -0
- package/dist/server/operations/async-activity.js +88 -4
- package/dist/server/operations/bulk-filter-helpers.d.ts +3 -0
- package/dist/server/operations/bulk-filter-helpers.js +27 -3
- package/dist/server/operations/bulk-mutate-workflow-tags.d.ts +6 -0
- package/dist/server/operations/bulk-signal-workflows.d.ts +6 -0
- package/dist/server/operations/get-stream-chunks.js +2 -7
- package/dist/server/operations/get-system-lease.d.ts +19 -0
- package/dist/server/operations/get-system-lease.js +48 -0
- package/dist/server/operations/get-workflow-observability.d.ts +24 -0
- package/dist/server/operations/get-workflow-observability.js +80 -0
- package/dist/server/operations/get-workflow-result.js +2 -2
- package/dist/server/operations/get-workflow.d.ts +2 -2
- package/dist/server/operations/list-filter-query-extractor.js +15 -0
- package/dist/server/operations/list-workflows.d.ts +6 -0
- package/dist/server/operations/list-workflows.js +12 -3
- package/dist/server/operations/operation-helpers.d.ts +9 -18
- package/dist/server/operations/operation-helpers.js +5 -23
- package/dist/server/operations/purge-workflows.d.ts +3 -0
- package/dist/server/operations/recover-all.js +2 -1
- package/dist/server/operations/single-workflow-tag-mutation.js +2 -2
- package/dist/server/operations/sse-stream.js +2 -7
- package/dist/server/operations/storage-capabilities.d.ts +34 -0
- package/dist/server/operations/storage-capabilities.js +38 -0
- package/dist/server/operations/storage.js +8 -17
- package/dist/server/operations/stream-workflow-sse.js +3 -9
- package/dist/server/operations/update-schedule.d.ts +8 -0
- package/dist/server/operations/update-schedule.js +70 -7
- package/dist/server/operations/workflow-events-sse.js +2 -2
- package/dist/server/rest-binding.d.ts +7 -6
- package/dist/server/rest-bindings.d.ts +2 -13
- package/dist/server/rest-bindings.js +19 -10
- package/dist/server/task-queue.d.ts +7 -5
- package/dist/storage/capabilities.d.ts +1 -1
- package/dist/storage/cloudflare-value-codec.d.ts +5 -3
- package/dist/storage/cloudflare-value-codec.js +1 -1
- package/dist/storage/compressed-storage.js +1 -1
- package/dist/storage/index.d.ts +7 -1
- package/dist/storage/interface.d.ts +16 -4
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +4 -0
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon.js +4 -4
- package/dist/storage/postgres.js +4 -4
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/testing.js +1 -1
- package/dist/storage/turso.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/web-extension.js +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,10 @@ import { normalizeFailureCategory } from "../failure-categories.js";
|
|
|
4
4
|
import { coerceStartWorkflowId, parseStartWorkflowDuration } from "../start-workflow-validation.js";
|
|
5
5
|
import { DEFAULT_WORKFLOW_VERSION } from "../versioning.js";
|
|
6
6
|
import { isWorkflowTagArray } from "../workflow-tags.js";
|
|
7
|
+
import {
|
|
8
|
+
MAX_TIMELINE_COORDINATOR_DETAILS,
|
|
9
|
+
MAX_TIMELINE_DETAIL_STRING_LENGTH
|
|
10
|
+
} from "./timeline-coordinator-constants.js";
|
|
7
11
|
const WORKFLOW_TIMELINE_STATUSES = new Set([
|
|
8
12
|
"running",
|
|
9
13
|
"completed",
|
|
@@ -28,12 +32,15 @@ const WORKFLOW_STATE_FIELD_NAMES = new Set(defineCompleteWorkflowStateFieldNames
|
|
|
28
32
|
"versionTuple",
|
|
29
33
|
"workflowExecutionToken",
|
|
30
34
|
"executionStateOwnerId",
|
|
35
|
+
"parentWorkflowId",
|
|
36
|
+
"parentWorkflowExecutionToken",
|
|
31
37
|
"createdAt",
|
|
32
38
|
"startedAt",
|
|
33
39
|
"updatedAt",
|
|
34
40
|
"terminalCleanupToken",
|
|
35
41
|
"executionDeadline",
|
|
36
|
-
"forkedFrom"
|
|
42
|
+
"forkedFrom",
|
|
43
|
+
"restartedFrom"
|
|
37
44
|
]));
|
|
38
45
|
export function isSanitizedSearchAttributeValue(value) {
|
|
39
46
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
@@ -53,6 +60,30 @@ export function isFiniteNumber(value) {
|
|
|
53
60
|
export function isTimelineStep(value) {
|
|
54
61
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
55
62
|
}
|
|
63
|
+
const WORKFLOW_TIMELINE_DETAIL_OUTCOMES = new Set(["fulfilled", "rejected", "won", "lost"]);
|
|
64
|
+
function isBoundedTimelineDetailString(value) {
|
|
65
|
+
return typeof value === "string" && value.length <= MAX_TIMELINE_DETAIL_STRING_LENGTH;
|
|
66
|
+
}
|
|
67
|
+
const TIMELINE_DETAIL_FIELD_CHECKS = [
|
|
68
|
+
(detail) => typeof detail.index === "number" && Number.isSafeInteger(detail.index) && detail.index >= 0,
|
|
69
|
+
(detail) => detail.key === void 0 || isBoundedTimelineDetailString(detail.key),
|
|
70
|
+
(detail) => isBoundedTimelineDetailString(detail.operationId),
|
|
71
|
+
(detail) => isBoundedTimelineDetailString(detail.operationType),
|
|
72
|
+
(detail) => isBoundedTimelineDetailString(detail.operationLabel),
|
|
73
|
+
(detail) => WORKFLOW_TIMELINE_DETAIL_OUTCOMES.has(detail.outcome),
|
|
74
|
+
(detail) => detail.errorSummary === void 0 || isBoundedTimelineDetailString(detail.errorSummary)
|
|
75
|
+
];
|
|
76
|
+
function isWorkflowTimelineOperationDetail(value) {
|
|
77
|
+
if (!isRecord(value))
|
|
78
|
+
return !1;
|
|
79
|
+
return TIMELINE_DETAIL_FIELD_CHECKS.every((check) => check(value));
|
|
80
|
+
}
|
|
81
|
+
function isWorkflowTimelineOperationDetails(value) {
|
|
82
|
+
return value === void 0 || Array.isArray(value) && value.length <= MAX_TIMELINE_COORDINATOR_DETAILS && value.every(isWorkflowTimelineOperationDetail);
|
|
83
|
+
}
|
|
84
|
+
function isOmittedTimelineDetailCount(value) {
|
|
85
|
+
return value === void 0 || typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
86
|
+
}
|
|
56
87
|
const TIMELINE_ENTRY_FIELD_CHECKS = [
|
|
57
88
|
(entry) => isTimelineStep(entry.step),
|
|
58
89
|
(entry) => typeof entry.operationType === "string",
|
|
@@ -62,7 +93,12 @@ const TIMELINE_ENTRY_FIELD_CHECKS = [
|
|
|
62
93
|
(entry) => WORKFLOW_TIMELINE_STATUSES.has(entry.status),
|
|
63
94
|
(entry) => entry.outputSummary === void 0 || typeof entry.outputSummary === "string",
|
|
64
95
|
(entry) => entry.duration === void 0 || isFiniteNumber(entry.duration),
|
|
65
|
-
(entry) => entry.versionTuple === void 0 || isWorkflowVersionTuple(entry.versionTuple)
|
|
96
|
+
(entry) => entry.versionTuple === void 0 || isWorkflowVersionTuple(entry.versionTuple),
|
|
97
|
+
(entry) => isWorkflowTimelineOperationDetails(entry.branches),
|
|
98
|
+
(entry) => isOmittedTimelineDetailCount(entry.branchesOmitted),
|
|
99
|
+
(entry) => isWorkflowTimelineOperationDetails(entry.children),
|
|
100
|
+
(entry) => isOmittedTimelineDetailCount(entry.childrenOmitted),
|
|
101
|
+
(entry) => entry.speculationOutcome === void 0 || entry.speculationOutcome === "committed" || entry.speculationOutcome === "rolled-back"
|
|
66
102
|
];
|
|
67
103
|
export function isWorkflowTimelineEntry(value) {
|
|
68
104
|
if (!isRecord(value))
|
|
@@ -102,8 +138,36 @@ export function decodeWorkflowState(bytes) {
|
|
|
102
138
|
console.warn(`[weft] Decoded workflow state for "${String(state.id)}" has an invalid executionStateOwnerId field; falling back to the workflow id as the execution owner. This usually indicates corruption or tampering of the storage record.`);
|
|
103
139
|
delete state.executionStateOwnerId;
|
|
104
140
|
}
|
|
141
|
+
sanitizeDecodedParentLineage(state);
|
|
142
|
+
sanitizeDecodedRestartLineage(state);
|
|
105
143
|
return decodedRecord === void 0 ? state : stripUnknownWorkflowStateFields(state, decodedRecord);
|
|
106
144
|
}
|
|
145
|
+
function sanitizeDecodedParentLineage(state) {
|
|
146
|
+
if (state.parentWorkflowId !== void 0)
|
|
147
|
+
try {
|
|
148
|
+
coerceStartWorkflowId(state.parentWorkflowId, "parentWorkflowId");
|
|
149
|
+
} catch {
|
|
150
|
+
delete state.parentWorkflowId;
|
|
151
|
+
}
|
|
152
|
+
if (typeof state.parentWorkflowExecutionToken !== "string" || state.parentWorkflowExecutionToken.length === 0 || state.parentWorkflowId === void 0)
|
|
153
|
+
delete state.parentWorkflowExecutionToken;
|
|
154
|
+
}
|
|
155
|
+
function sanitizeDecodedRestartLineage(state) {
|
|
156
|
+
const restartedFrom = state.restartedFrom;
|
|
157
|
+
if (!isRecord(restartedFrom)) {
|
|
158
|
+
delete state.restartedFrom;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
coerceStartWorkflowId(restartedFrom.workflowId, "restartedFrom.workflowId");
|
|
163
|
+
} catch {
|
|
164
|
+
delete state.restartedFrom;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const { workflowExecutionToken, replacedAt } = restartedFrom;
|
|
168
|
+
if (workflowExecutionToken !== void 0 && (typeof workflowExecutionToken !== "string" || workflowExecutionToken.length === 0) || typeof replacedAt !== "number" || !Number.isSafeInteger(replacedAt) || replacedAt < 0)
|
|
169
|
+
delete state.restartedFrom;
|
|
170
|
+
}
|
|
107
171
|
function stripUnknownWorkflowStateFields(state, stateFields) {
|
|
108
172
|
for (const fieldName of Object.keys(stateFields))
|
|
109
173
|
if (!WORKFLOW_STATE_FIELD_NAMES.has(fieldName))
|
|
@@ -2,8 +2,12 @@ import type { AttributeFilter, ListFilter, WorkflowState } from '../types.ts';
|
|
|
2
2
|
import type { EngineInternals } from './internals.ts';
|
|
3
3
|
/** Stream decoded workflow states that match a list filter. */
|
|
4
4
|
export declare function streamMatchingWorkflowStates(internals: EngineInternals, filter?: ListFilter): AsyncGenerator<WorkflowState>;
|
|
5
|
-
/** Resolve
|
|
5
|
+
/** Resolve indexed workflow IDs implied by lineage, schedule, tag, and search-attribute filters. */
|
|
6
6
|
export declare function resolveConstrainedIds(internals: EngineInternals, filter: ListFilter | undefined, normalizedTagFilters: readonly string[] | undefined): Promise<Set<string> | null>;
|
|
7
7
|
/** Query a single search-attribute index filter and return matching workflow IDs. */
|
|
8
8
|
export declare function queryAttributeIndex(internals: EngineInternals, filter: AttributeFilter): Promise<Set<string>>;
|
|
9
|
+
/** Resolve the durable reverse index from one concrete parent run to its direct children. */
|
|
10
|
+
export declare function queryChildWorkflowIndex(internals: EngineInternals, parentWorkflowId: string, parentWorkflowExecutionToken: string | undefined): Promise<Set<string>>;
|
|
11
|
+
/** Resolve the durable reverse index from a schedule id to launched workflow ids. */
|
|
12
|
+
export declare function queryScheduleRunIndex(internals: EngineInternals, scheduleId: string): Promise<Set<string>>;
|
|
9
13
|
export declare function isTopLevelWorkflowStateKey(key: string): boolean;
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
matchesListFilter
|
|
16
16
|
} from "./state-utilities.js";
|
|
17
17
|
import { decodeWorkflowState } from "./validation.js";
|
|
18
|
+
import { MAX_LIST_SCAN_ROWS, WorkflowListScanCapExceededError } from "./workflow-indexes.js";
|
|
18
19
|
const ATTRIBUTE_SCAN_CONCURRENCY = 8;
|
|
19
20
|
export async function* streamMatchingWorkflowStates(internals, filter) {
|
|
20
21
|
const normalizedTagFilters = normalizeWorkflowTags(filter?.tags), constrainedIds = await resolveConstrainedIds(internals, filter, normalizedTagFilters);
|
|
@@ -54,10 +55,9 @@ async function readSearchAttributesForFilter(internals, workflowId, filter) {
|
|
|
54
55
|
return decodeSearchAttributeRecord(await internals.storage.get(KEYS.attribute(workflowId)));
|
|
55
56
|
}
|
|
56
57
|
export async function resolveConstrainedIds(internals, filter, normalizedTagFilters) {
|
|
57
|
-
const attributeFilters = filter?.attributes,
|
|
58
|
-
if (
|
|
58
|
+
const attributeFilters = filter?.attributes, queries = buildConstrainedIdQueries(internals, normalizedTagFilters, attributeFilters, filter?.scheduleId, filter?.parentWorkflowId, filter?.parentWorkflowExecutionToken);
|
|
59
|
+
if (queries.length === 0)
|
|
59
60
|
return null;
|
|
60
|
-
const queries = buildConstrainedIdQueries(internals, normalizedTagFilters, attributeFilters);
|
|
61
61
|
return intersectIdentifierSets(await runConstrainedIdQueries(queries));
|
|
62
62
|
}
|
|
63
63
|
export async function queryAttributeIndex(internals, filter) {
|
|
@@ -68,29 +68,52 @@ export async function queryAttributeIndex(internals, filter) {
|
|
|
68
68
|
await collectRangeAttributeMatches(internals, filter, prefix, ids);
|
|
69
69
|
return ids;
|
|
70
70
|
}
|
|
71
|
-
function buildConstrainedIdQueries(internals, normalizedTagFilters, attributeFilters) {
|
|
71
|
+
function buildConstrainedIdQueries(internals, normalizedTagFilters, attributeFilters, scheduleId, parentWorkflowId, parentWorkflowExecutionToken) {
|
|
72
72
|
return [
|
|
73
|
+
...scheduleId === void 0 ? [] : [() => queryScheduleRunIndex(internals, scheduleId)],
|
|
74
|
+
...parentWorkflowId === void 0 ? [] : [() => queryChildWorkflowIndex(internals, parentWorkflowId, parentWorkflowExecutionToken)],
|
|
73
75
|
...normalizedTagFilters?.map((tag) => () => queryTagIndex(internals, tag)) ?? [],
|
|
74
76
|
...attributeFilters?.map((attributeFilter) => () => queryAttributeIndex(internals, attributeFilter)) ?? []
|
|
75
77
|
];
|
|
76
78
|
}
|
|
79
|
+
export async function queryChildWorkflowIndex(internals, parentWorkflowId, parentWorkflowExecutionToken) {
|
|
80
|
+
const workflowIds = new Set, prefix = KEYS.childWorkflowByParentPrefix(parentWorkflowId, parentWorkflowExecutionToken);
|
|
81
|
+
for await (const [key] of internals.storage.scan(prefix)) {
|
|
82
|
+
if (workflowIds.size >= MAX_LIST_SCAN_ROWS)
|
|
83
|
+
throw new WorkflowListScanCapExceededError(MAX_LIST_SCAN_ROWS);
|
|
84
|
+
const encodedWorkflowId = key.slice(prefix.length).split(":").at(-1);
|
|
85
|
+
if (encodedWorkflowId === void 0)
|
|
86
|
+
continue;
|
|
87
|
+
const workflowId = tryDecodeStorageKeyComponent(encodedWorkflowId);
|
|
88
|
+
if (workflowId !== null)
|
|
89
|
+
workflowIds.add(workflowId);
|
|
90
|
+
}
|
|
91
|
+
return workflowIds;
|
|
92
|
+
}
|
|
93
|
+
export async function queryScheduleRunIndex(internals, scheduleId) {
|
|
94
|
+
const workflowIds = new Set, prefix = KEYS.scheduleRunBySchedulePrefix(scheduleId);
|
|
95
|
+
for await (const [key] of internals.storage.scan(prefix)) {
|
|
96
|
+
if (workflowIds.size >= MAX_LIST_SCAN_ROWS)
|
|
97
|
+
throw new WorkflowListScanCapExceededError(MAX_LIST_SCAN_ROWS);
|
|
98
|
+
const encodedWorkflowId = key.slice(prefix.length), workflowId = tryDecodeStorageKeyComponent(encodedWorkflowId);
|
|
99
|
+
if (workflowId !== null)
|
|
100
|
+
workflowIds.add(workflowId);
|
|
101
|
+
}
|
|
102
|
+
return workflowIds;
|
|
103
|
+
}
|
|
77
104
|
async function runConstrainedIdQueries(queries) {
|
|
78
|
-
const idSets = Array.from({ length: queries.length });
|
|
79
105
|
let nextIndex = 0;
|
|
80
106
|
const runWorker = async () => {
|
|
107
|
+
const workerResults = [];
|
|
81
108
|
while (nextIndex < queries.length) {
|
|
82
109
|
const currentIndex = nextIndex;
|
|
83
110
|
nextIndex += 1;
|
|
84
|
-
|
|
111
|
+
workerResults.push([currentIndex, await queries[currentIndex]()]);
|
|
85
112
|
}
|
|
86
|
-
|
|
87
|
-
await Promise.all(Array.from({ length: workerLimit }, () => runWorker()));
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function requireConstrainedIdSet(idSet) {
|
|
91
|
-
if (idSet === void 0)
|
|
92
|
-
throw Error("Attribute index query did not produce a workflow ID set.");
|
|
93
|
-
return idSet;
|
|
113
|
+
return workerResults;
|
|
114
|
+
}, workerLimit = Math.max(1, Math.min(ATTRIBUTE_SCAN_CONCURRENCY, queries.length)), completedResults = (await Promise.all(Array.from({ length: workerLimit }, () => runWorker()))).flat();
|
|
115
|
+
completedResults.sort(([leftIndex], [rightIndex]) => leftIndex - rightIndex);
|
|
116
|
+
return completedResults.map(([, idSet]) => idSet);
|
|
94
117
|
}
|
|
95
118
|
async function collectExactAttributeMatches(internals, filter, attributeName, ids) {
|
|
96
119
|
const exactValues = attributeFilterExactValues(filter);
|
|
@@ -38,10 +38,9 @@ export declare class ScheduleFiredEvent extends Event {
|
|
|
38
38
|
/** Wall-clock time the run was launched, from the engine's injected clock. */
|
|
39
39
|
readonly firedAt: number;
|
|
40
40
|
/**
|
|
41
|
-
* The scheduled grid timestamp the occurrence was due.
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* and cannot be reported when the run finally launches.
|
|
41
|
+
* The scheduled grid timestamp the occurrence was due. Queue overlap retains
|
|
42
|
+
* this timestamp on the durable queue entry and reports it when the run drains.
|
|
43
|
+
* It is undefined only when an internal caller did not supply an occurrence.
|
|
45
44
|
*/
|
|
46
45
|
readonly occurrence: number | undefined;
|
|
47
46
|
constructor(scheduleId: string, workflowId: string, firedAt: number, occurrence?: number);
|
|
@@ -241,7 +241,8 @@ export declare class WorkflowRecoverySkippedEvent extends Event {
|
|
|
241
241
|
* dead-letter horizon is reached. Per-attempt observability — fires on every retry.
|
|
242
242
|
* - `'dead-lettered'`: the retry horizon was reached without success; the external
|
|
243
243
|
* resource may be leaked. The durable record is `KEYS.teardownDeadLetter`, which
|
|
244
|
-
* survives purge so
|
|
244
|
+
* survives purge so `getFinalizerStatus()` remains auditable after the workflow
|
|
245
|
+
* record is gone.
|
|
245
246
|
*
|
|
246
247
|
* @example
|
|
247
248
|
* ```ts
|
|
@@ -20,6 +20,9 @@ import { WeftError } from './weft-error.ts';
|
|
|
20
20
|
export declare const listFilterObjectSchema: z.ZodObject<{
|
|
21
21
|
status: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<WorkflowStatus, unknown, z.core.$ZodTypeInternals<WorkflowStatus, unknown>>, z.ZodArray<z.ZodType<WorkflowStatus, unknown, z.core.$ZodTypeInternals<WorkflowStatus, unknown>>>]>>;
|
|
22
22
|
type: z.ZodOptional<z.ZodString>;
|
|
23
|
+
scheduleId: z.ZodOptional<z.ZodString>;
|
|
24
|
+
parentWorkflowId: z.ZodOptional<z.ZodString>;
|
|
25
|
+
parentWorkflowExecutionToken: z.ZodOptional<z.ZodString>;
|
|
23
26
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
27
|
attributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
25
28
|
key: z.ZodUnion<readonly [z.ZodString, z.ZodAny]>;
|
|
@@ -35,6 +35,9 @@ const WORKFLOW_STATUSES = [
|
|
|
35
35
|
export const listFilterObjectSchema = z.object({
|
|
36
36
|
status: z.union([workflowStatusSchema, z.array(workflowStatusSchema)]).optional(),
|
|
37
37
|
type: z.string().min(1).optional(),
|
|
38
|
+
scheduleId: z.string().min(1).optional(),
|
|
39
|
+
parentWorkflowId: z.string().min(1).optional(),
|
|
40
|
+
parentWorkflowExecutionToken: z.string().min(1).optional(),
|
|
38
41
|
tags: z.array(z.string()).optional(),
|
|
39
42
|
attributes: z.array(attributeFilterSchema).optional(),
|
|
40
43
|
limit: z.number().int().min(1).max(1000).optional(),
|
|
@@ -70,6 +73,14 @@ export function normalizeListFilter(input) {
|
|
|
70
73
|
const result = listFilterObjectSchema.safeParse(input ?? {});
|
|
71
74
|
if (!result.success)
|
|
72
75
|
throw new ListFilterValidationError(result.error.issues.map(flattenIssue));
|
|
76
|
+
if (result.data.parentWorkflowExecutionToken !== void 0 && result.data.parentWorkflowId === void 0)
|
|
77
|
+
throw new ListFilterValidationError([
|
|
78
|
+
{
|
|
79
|
+
path: ["parentWorkflowExecutionToken"],
|
|
80
|
+
message: "parentWorkflowExecutionToken requires parentWorkflowId",
|
|
81
|
+
code: "custom"
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
73
84
|
return result.data;
|
|
74
85
|
}
|
|
75
86
|
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure builder that captures a snapshot of the engine's locally-registered
|
|
3
|
+
* workflows and activities, with their JSON Schemas. This is the data source
|
|
4
|
+
* behind the `GET /v1/registry` REST endpoint and (later) the MCP server.
|
|
5
|
+
*
|
|
6
|
+
* The output is a plain object designed to be safe for JSON serialization.
|
|
7
|
+
* Absent metadata fields are omitted (never `null`, never `{}`); converter
|
|
8
|
+
* exceptions surface as a typed {@link RegistrySchemaConversionError} (see
|
|
9
|
+
* its JSDoc for what reaches the wire vs server logs).
|
|
10
|
+
*
|
|
11
|
+
* **Ordering guarantee.** Builder code inserts workflow, activity, signal,
|
|
12
|
+
* update, and query keys in alphabetical (codepoint) order. Workflow and
|
|
13
|
+
* activity names cannot be integer-like (the name grammar requires a leading
|
|
14
|
+
* letter or underscore), but signal/update/query names accept any string, so
|
|
15
|
+
* integer-like message names could theoretically be reordered by JS engines
|
|
16
|
+
* despite the explicit sort. Clients that want to protect themselves from
|
|
17
|
+
* future registry sources should still sort `Object.keys(...)` before
|
|
18
|
+
* presenting or diffing snapshot entries.
|
|
19
|
+
*
|
|
20
|
+
* @module core/registry-snapshot
|
|
21
|
+
*/
|
|
22
|
+
import type { ActivityMetadata } from './activity-registry.ts';
|
|
1
23
|
import type { Engine } from './engine.ts';
|
|
2
24
|
import { WeftError } from './weft-error.ts';
|
|
3
25
|
/**
|
|
@@ -6,12 +28,20 @@ import { WeftError } from './weft-error.ts';
|
|
|
6
28
|
* versions with a clear upgrade message.
|
|
7
29
|
*/
|
|
8
30
|
export declare const REGISTRY_VERSION = 1;
|
|
31
|
+
/** Schema metadata reported for a statically registered workflow message. */
|
|
32
|
+
export type RegistryMessageEntry = {
|
|
33
|
+
inputSchema?: Record<string, unknown>;
|
|
34
|
+
outputSchema?: Record<string, unknown>;
|
|
35
|
+
};
|
|
9
36
|
/** Metadata reported per workflow in a registry snapshot. */
|
|
10
37
|
export type RegistryWorkflowEntry = {
|
|
11
38
|
inputSchema?: Record<string, unknown>;
|
|
12
39
|
outputSchema?: Record<string, unknown>;
|
|
13
40
|
description?: string;
|
|
14
41
|
tags?: ReadonlyArray<string>;
|
|
42
|
+
signals?: Record<string, RegistryMessageEntry>;
|
|
43
|
+
updates?: Record<string, RegistryMessageEntry>;
|
|
44
|
+
queries?: Record<string, RegistryMessageEntry>;
|
|
15
45
|
};
|
|
16
46
|
/**
|
|
17
47
|
* Metadata reported per activity in a registry snapshot.
|
|
@@ -31,6 +61,8 @@ export type RegistryActivityEntry = {
|
|
|
31
61
|
/** Engine assigns a default queue when none is specified, so this is always populated. */
|
|
32
62
|
queue: string;
|
|
33
63
|
description?: string;
|
|
64
|
+
retry?: ActivityMetadata['retry'];
|
|
65
|
+
timeout?: ActivityMetadata['timeout'];
|
|
34
66
|
};
|
|
35
67
|
/**
|
|
36
68
|
* Snapshot of every locally-registered workflow and activity, suitable for
|
|
@@ -49,8 +49,32 @@ function buildWorkflowEntry(definition) {
|
|
|
49
49
|
entry.description = definition.description;
|
|
50
50
|
if (definition.tags.length > 0)
|
|
51
51
|
entry.tags = [...definition.tags];
|
|
52
|
+
addWorkflowMessageEntries(entry, definition);
|
|
52
53
|
return entry;
|
|
53
54
|
}
|
|
55
|
+
function addWorkflowMessageEntries(entry, definition) {
|
|
56
|
+
if (definition.signals !== void 0 && Object.keys(definition.signals).length > 0)
|
|
57
|
+
entry.signals = buildMessageEntries(definition.type, "signal", definition.signals);
|
|
58
|
+
if (definition.updates !== void 0 && Object.keys(definition.updates).length > 0)
|
|
59
|
+
entry.updates = buildMessageEntries(definition.type, "update", definition.updates);
|
|
60
|
+
if (definition.queries !== void 0 && Object.keys(definition.queries).length > 0)
|
|
61
|
+
entry.queries = buildMessageEntries(definition.type, "query", definition.queries);
|
|
62
|
+
}
|
|
63
|
+
function buildMessageEntries(workflowType, messageKind, definitions) {
|
|
64
|
+
const entries = Object.create(null);
|
|
65
|
+
for (const name of Object.keys(definitions).toSorted()) {
|
|
66
|
+
const definition = definitions[name];
|
|
67
|
+
if (definition === void 0)
|
|
68
|
+
continue;
|
|
69
|
+
const entry = {}, entityName = `${workflowType}.${messageKind}.${name}`;
|
|
70
|
+
if (definition.inputSchema !== void 0)
|
|
71
|
+
entry.inputSchema = convertSchema("workflow", entityName, "inputSchema", definition.inputSchema);
|
|
72
|
+
if (definition.outputSchema !== void 0)
|
|
73
|
+
entry.outputSchema = convertSchema("workflow", entityName, "outputSchema", definition.outputSchema);
|
|
74
|
+
entries[name] = entry;
|
|
75
|
+
}
|
|
76
|
+
return entries;
|
|
77
|
+
}
|
|
54
78
|
function buildActivityEntry(metadata) {
|
|
55
79
|
const entry = { queue: metadata.queue };
|
|
56
80
|
if (metadata.inputSchema !== void 0)
|
|
@@ -59,6 +83,10 @@ function buildActivityEntry(metadata) {
|
|
|
59
83
|
entry.outputSchema = convertSchema("activity", metadata.name, "outputSchema", metadata.outputSchema);
|
|
60
84
|
if (metadata.description !== void 0)
|
|
61
85
|
entry.description = metadata.description;
|
|
86
|
+
if (metadata.retry !== void 0)
|
|
87
|
+
entry.retry = metadata.retry;
|
|
88
|
+
if (metadata.timeout !== void 0)
|
|
89
|
+
entry.timeout = metadata.timeout;
|
|
62
90
|
return entry;
|
|
63
91
|
}
|
|
64
92
|
function convertSchema(entityKind, entityName, field, schema) {
|
|
@@ -43,7 +43,7 @@ export interface ReviewRequest {
|
|
|
43
43
|
* The `decision` field is the binary outcome; `sectionDecisions` carries
|
|
44
44
|
* per-section verdicts when `allowPartial` is enabled on the request.
|
|
45
45
|
*/
|
|
46
|
-
export interface
|
|
46
|
+
export interface ReviewDecisionRecord {
|
|
47
47
|
reviewId: string;
|
|
48
48
|
decision: 'approved' | 'rejected' | 'needs-changes';
|
|
49
49
|
reviewer: string;
|
|
@@ -119,7 +119,7 @@ export interface HumanReviewOptions extends ReviewOptions {
|
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* The decision payload returned to the workflow from `ctx.review()`.
|
|
122
|
-
* Alias for {@link
|
|
122
|
+
* Alias for {@link ReviewDecisionRecord}.
|
|
123
123
|
*
|
|
124
124
|
* @example
|
|
125
125
|
* ```ts
|
|
@@ -134,7 +134,7 @@ export interface HumanReviewOptions extends ReviewOptions {
|
|
|
134
134
|
* void result;
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
export type HumanReviewResult =
|
|
137
|
+
export type HumanReviewResult = ReviewDecisionRecord;
|
|
138
138
|
/**
|
|
139
139
|
* The action returned by {@link ReviewCoordinator.checkEscalations} when an
|
|
140
140
|
* escalation step has fired. Either reassigns the review to a new owner or
|
|
@@ -253,7 +253,7 @@ export declare class ReviewCoordinator {
|
|
|
253
253
|
/** Create a review request and persist it. */
|
|
254
254
|
createReview(workflowId: string, options: ReviewOptions): Promise<ReviewRequest>;
|
|
255
255
|
/** Submit a review decision. */
|
|
256
|
-
submitDecision(reviewId: string, decision: Omit<
|
|
256
|
+
submitDecision(reviewId: string, decision: Omit<ReviewDecisionRecord, 'reviewId' | 'timestamp'>): Promise<ReviewDecisionRecord>;
|
|
257
257
|
/** Get a pending review. */
|
|
258
258
|
getReview(workflowId: string, reviewId: string): Promise<ReviewRequest | null>;
|
|
259
259
|
/** List pending reviews. */
|
|
@@ -116,16 +116,18 @@ export interface ActivityContext {
|
|
|
116
116
|
* `client.activity.*` methods).
|
|
117
117
|
*
|
|
118
118
|
* The durable task token is announced on the engine as an
|
|
119
|
-
* `activity:async-pending` event
|
|
120
|
-
*
|
|
121
|
-
*
|
|
119
|
+
* `activity:async-pending` event and remains discoverable through
|
|
120
|
+
* `engine.listPendingAsyncActivities(workflowId)` or
|
|
121
|
+
* `client.activity.listPending(workflowId)`. The token is deterministic and
|
|
122
|
+
* survives engine restart: it is re-minted identically on recovery.
|
|
122
123
|
*
|
|
123
124
|
* Security: the token is a deterministic identifier, NOT a secret. When the
|
|
124
125
|
* completion endpoint is reachable by untrusted callers, anyone who can infer
|
|
125
126
|
* a workflow id can forge this activity's result or error. Treat the completed
|
|
126
127
|
* value as hostile external input (validate it as you would a signal payload),
|
|
127
|
-
*
|
|
128
|
-
*
|
|
128
|
+
* The transport query requires `workflows:read`; completion and failure require
|
|
129
|
+
* `workflows:write`. Configure `serve({ auth })` with those scopes before
|
|
130
|
+
* exposing the routes.
|
|
129
131
|
*
|
|
130
132
|
* `completeAsync()` never returns normally — it throws an internal sentinel
|
|
131
133
|
* that the engine recognizes to park the activity. Call it as the last
|
|
@@ -148,6 +150,51 @@ export interface ActivityContext {
|
|
|
148
150
|
*/
|
|
149
151
|
completeAsync(): never;
|
|
150
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Durable metadata for one activity awaiting out-of-band completion.
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* import type { PendingAsyncActivityInfo } from '@lostgradient/weft';
|
|
158
|
+
* declare const pending: PendingAsyncActivityInfo; console.log(pending.token, pending.activityName);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export interface PendingAsyncActivityInfo {
|
|
162
|
+
readonly token: string;
|
|
163
|
+
readonly operationId: string;
|
|
164
|
+
readonly activityName: string;
|
|
165
|
+
readonly step: number;
|
|
166
|
+
readonly attempt: number;
|
|
167
|
+
readonly createdAt: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Bounded cursor options for listing a workflow's pending async activities.
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import type { PendingAsyncActivityListOptions } from '@lostgradient/weft';
|
|
174
|
+
* const options: PendingAsyncActivityListOptions = { limit: 25 };
|
|
175
|
+
* void options;
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export interface PendingAsyncActivityListOptions {
|
|
179
|
+
/** Maximum records to inspect for this page. Defaults to 50 and cannot exceed 200. */
|
|
180
|
+
readonly limit?: number;
|
|
181
|
+
/** Opaque continuation cursor returned by the previous page. */
|
|
182
|
+
readonly cursor?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* One deterministic page of pending async activities.
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* import type { PendingAsyncActivityPage } from '@lostgradient/weft';
|
|
189
|
+
* const page: PendingAsyncActivityPage = { items: [] };
|
|
190
|
+
* void page;
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export interface PendingAsyncActivityPage {
|
|
194
|
+
readonly items: PendingAsyncActivityInfo[];
|
|
195
|
+
/** Present when another page of durable records may remain. */
|
|
196
|
+
readonly nextCursor?: string;
|
|
197
|
+
}
|
|
151
198
|
/**
|
|
152
199
|
* Per-invocation overrides when calling an activity from a workflow via
|
|
153
200
|
* `ctx.run(activity, input, options)`. Any field overrides the
|
|
@@ -43,6 +43,12 @@ export interface ListFilter {
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
type?: string;
|
|
46
|
+
/** Match workflow runs launched by this recurring schedule. */
|
|
47
|
+
scheduleId?: string;
|
|
48
|
+
/** Match direct child workflows launched by this parent workflow id. */
|
|
49
|
+
parentWorkflowId?: string;
|
|
50
|
+
/** Narrow `parentWorkflowId` to one concrete parent run generation. */
|
|
51
|
+
parentWorkflowExecutionToken?: string;
|
|
46
52
|
/** Match workflows that carry every listed tag. */
|
|
47
53
|
tags?: string[];
|
|
48
54
|
/** Filter on indexed search attributes (equality, string any-of, or range). */
|
|
@@ -446,14 +446,15 @@ export interface EngineOptions<TServices = unknown> {
|
|
|
446
446
|
resolveWorkflowServices?: (info: WorkflowServicesResolverInfo) => WorkflowServicesResolution<TServices> | Promise<WorkflowServicesResolution<TServices>>;
|
|
447
447
|
/**
|
|
448
448
|
* Optional host sink for `ctx.log` records. When provided, every non-replayed
|
|
449
|
-
* record from inline workflow execution is routed here (into your
|
|
450
|
-
* / OpenTelemetry stack, etc.) **instead of** the console; when
|
|
451
|
-
* fall back to the matching
|
|
449
|
+
* record from inline and worker workflow execution is routed here (into your
|
|
450
|
+
* pino / winston / OpenTelemetry stack, etc.) **instead of** the console; when
|
|
451
|
+
* omitted, records fall back to the matching process console.
|
|
452
452
|
*
|
|
453
453
|
* Engine-scoped infrastructure: set once at construction, never per run. The sink
|
|
454
454
|
* is not invoked for records suppressed during replay, so a recovered run does
|
|
455
|
-
* not re-emit its replayed prefix.
|
|
456
|
-
*
|
|
455
|
+
* not re-emit its replayed prefix. Weft does not persist these records or expose
|
|
456
|
+
* a log-history API; the sink is the integration point for retention and remote
|
|
457
|
+
* log queries.
|
|
457
458
|
*/
|
|
458
459
|
onLog?: (record: WorkflowLogRecord) => void;
|
|
459
460
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReviewDecisionRecord, ReviewRequest } from '../review/index.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Outcome of a human review step initiated by `ctx.waitForReview`. Pass as
|
|
4
4
|
* the `decision` field in {@link SubmitReviewOptions} when calling
|
|
@@ -125,7 +125,7 @@ export interface PendingReviewEntry extends ReviewRequest {
|
|
|
125
125
|
* void entry;
|
|
126
126
|
* ```
|
|
127
127
|
*/
|
|
128
|
-
export interface CompletedReviewEntry extends
|
|
128
|
+
export interface CompletedReviewEntry extends ReviewDecisionRecord {
|
|
129
129
|
status: 'completed';
|
|
130
130
|
workflowId: string;
|
|
131
131
|
artifact: unknown;
|
|
@@ -23,6 +23,29 @@ export type ScheduleStatus = 'active' | 'paused' | 'cancelled';
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
export type ScheduleOverlapPolicy = 'skip' | 'queue' | 'cancel-running' | 'allow';
|
|
26
|
+
/**
|
|
27
|
+
* One occurrence waiting behind the active run of a `queue` overlap schedule.
|
|
28
|
+
* `workflowId` is reserved when the occurrence enters the durable queue and is
|
|
29
|
+
* used when it eventually starts. No workflow record exists for that id until
|
|
30
|
+
* the queue drains, so `engine.get(workflowId)` returns `null` while it waits.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import type { ScheduleQueuedRun } from '@lostgradient/weft';
|
|
35
|
+
*
|
|
36
|
+
* const queuedRun: ScheduleQueuedRun = {
|
|
37
|
+
* workflowId: 'daily-report-queued-1',
|
|
38
|
+
* queuedAt: Date.now(),
|
|
39
|
+
* };
|
|
40
|
+
* void queuedRun;
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export interface ScheduleQueuedRun {
|
|
44
|
+
workflowId: string;
|
|
45
|
+
queuedAt: number;
|
|
46
|
+
/** Nominal cadence timestamp retained from the occurrence that was queued. */
|
|
47
|
+
occurrence?: number;
|
|
48
|
+
}
|
|
26
49
|
/**
|
|
27
50
|
* Recurrence specification for a schedule. A schedule fires either on a cron
|
|
28
51
|
* cadence (`{ cron: '0 9 * * *' }`) or at a fixed interval
|
|
@@ -95,6 +118,24 @@ export interface ScheduleOptions {
|
|
|
95
118
|
*/
|
|
96
119
|
jitter?: Duration;
|
|
97
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Mutable options accepted when updating an existing schedule. Omitted fields
|
|
123
|
+
* retain their persisted values. Schedule identity, workflow type, and input
|
|
124
|
+
* are intentionally excluded.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { Engine, workflow, type ScheduleUpdateOptions } from '@lostgradient/weft';
|
|
129
|
+
*
|
|
130
|
+
* const engine = new Engine();
|
|
131
|
+
* engine.register(workflow({ name: 'report' }).execute(async function* () { return 'done'; }));
|
|
132
|
+
* await engine.schedule('report', null, '0 9 * * *', { id: 'daily-report' });
|
|
133
|
+
* const options: ScheduleUpdateOptions = { overlap: 'queue', jitter: '30s' };
|
|
134
|
+
* await engine.updateSchedule('daily-report', '30 9 * * *', options);
|
|
135
|
+
* engine[Symbol.dispose]();
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export type ScheduleUpdateOptions = Pick<ScheduleOptions, 'description' | 'overlap' | 'backfill' | 'jitter'>;
|
|
98
139
|
/**
|
|
99
140
|
* Declarative recurring schedule definition returned by {@link schedule}. Supply
|
|
100
141
|
* exactly one of `cron` (cron cadence) or `every` (fixed interval).
|
|
@@ -176,7 +217,8 @@ export interface ScheduleState {
|
|
|
176
217
|
missedFireCount: number;
|
|
177
218
|
nextFireAt: number | null;
|
|
178
219
|
currentWorkflowId?: string;
|
|
179
|
-
|
|
220
|
+
/** Ordered durable occurrences waiting behind `currentWorkflowId`. */
|
|
221
|
+
queuedRuns: ScheduleQueuedRun[];
|
|
180
222
|
}
|
|
181
223
|
/**
|
|
182
224
|
* Lightweight summary of a recurring schedule returned by list operations.
|
|
@@ -208,7 +250,8 @@ export interface ScheduleSummary {
|
|
|
208
250
|
missedFireCount: number;
|
|
209
251
|
nextFireAt: number | null;
|
|
210
252
|
currentWorkflowId?: string;
|
|
211
|
-
|
|
253
|
+
/** Ordered durable occurrences waiting behind `currentWorkflowId`. */
|
|
254
|
+
queuedRuns: ScheduleQueuedRun[];
|
|
212
255
|
}
|
|
213
256
|
/**
|
|
214
257
|
* Filter criteria for `engine.listSchedules`. All fields are optional.
|
|
@@ -50,11 +50,11 @@ export interface WorkflowServicesResolverLaunchOptions {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Schedule context passed to {@link EngineOptions.resolveWorkflowServices} for
|
|
53
|
-
* scheduled occurrences.
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
53
|
+
* scheduled occurrences. Scheduled runs persist this context with the workflow
|
|
54
|
+
* record, so a fresh-process recovery receives the same schedule id and known
|
|
55
|
+
* occurrence timestamp as the live launch path. Queue entries retain the
|
|
56
|
+
* occurrence timestamp through drain; runs from older stores that predate this
|
|
57
|
+
* metadata may omit the context or occurrence.
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* ```ts
|