@lostgradient/weft 0.12.0 → 0.14.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.
Files changed (226) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/api.d.ts +2 -0
  3. package/dist/cli/api.js +3 -4
  4. package/dist/cli/generated/operation-catalog.snapshot.json +508 -12
  5. package/dist/cli/generated/operation-client.generated.d.ts +118 -10
  6. package/dist/cli/generated/operation-client.generated.js +74 -1
  7. package/dist/cli/help-text.d.ts +3 -3
  8. package/dist/cli/help-text.js +4 -4
  9. package/dist/cli/operation-catalog-snapshot.d.ts +12 -3
  10. package/dist/cli/operation-catalog-snapshot.js +14 -5
  11. package/dist/cli/operation-client-runtime.d.ts +29 -0
  12. package/dist/cli/schedule.js +1 -3
  13. package/dist/cli/serve-registrations.d.ts +3 -3
  14. package/dist/cli/serve-registrations.js +2 -2
  15. package/dist/cli/shutdown.d.ts +11 -0
  16. package/dist/cli/shutdown.js +25 -0
  17. package/dist/cli/validate.d.ts +1 -1
  18. package/dist/cli/version-check.d.ts +1 -1
  19. package/dist/cli/version-check.js +1 -1
  20. package/dist/cli-main.js +10 -29
  21. package/dist/client/client-storage.d.ts +24 -0
  22. package/dist/client/client-storage.js +14 -0
  23. package/dist/client/handle-delegation.d.ts +3 -3
  24. package/dist/client/handle-delegation.js +2 -2
  25. package/dist/client/http-client-requests.d.ts +5 -3
  26. package/dist/client/http-client-requests.js +20 -2
  27. package/dist/client/http-client-storage.d.ts +3 -0
  28. package/dist/client/http-client-storage.js +82 -0
  29. package/dist/client/http-client.d.ts +9 -6
  30. package/dist/client/http-client.js +13 -18
  31. package/dist/client/http-operations.d.ts +3 -1
  32. package/dist/client/http-operations.js +77 -1
  33. package/dist/client/http-request.d.ts +20 -14
  34. package/dist/client/http-request.js +21 -31
  35. package/dist/client/in-process-operations.d.ts +2 -2
  36. package/dist/client/in-process-operations.js +2 -2
  37. package/dist/client/index.d.ts +5 -1
  38. package/dist/client/index.js +13 -2
  39. package/dist/client/interface.d.ts +26 -26
  40. package/dist/client/local.d.ts +9 -6
  41. package/dist/client/local.js +9 -4
  42. package/dist/client/search-params.js +10 -6
  43. package/dist/client/start-body.d.ts +3 -1
  44. package/dist/client/start-body.js +9 -0
  45. package/dist/core/bulk-workflow-filter.d.ts +2 -1
  46. package/dist/core/bulk-workflow-filter.js +5 -1
  47. package/dist/core/context/parallel-operations.d.ts +0 -2
  48. package/dist/core/context/parallel-operations.js +0 -7
  49. package/dist/core/engine/async-activity-records.d.ts +12 -1
  50. package/dist/core/engine/async-activity-records.js +81 -2
  51. package/dist/core/engine/bulk-operations-purge.js +16 -1
  52. package/dist/core/engine/bulk-operations-shared.js +2 -0
  53. package/dist/core/engine/callback-checkpoint-persistence.d.ts +2 -0
  54. package/dist/core/engine/callback-checkpoint-persistence.js +6 -3
  55. package/dist/core/engine/callback-creators-schedule.d.ts +2 -1
  56. package/dist/core/engine/callback-creators-schedule.js +3 -3
  57. package/dist/core/engine/callback-creators.js +4 -22
  58. package/dist/core/engine/checkpoint-io.d.ts +1 -1
  59. package/dist/core/engine/checkpoint-reads.js +11 -1
  60. package/dist/core/engine/child-workflow.js +15 -6
  61. package/dist/core/engine/construction.js +3 -0
  62. package/dist/core/engine/disposal.js +2 -0
  63. package/dist/core/engine/engine-internal-types.d.ts +4 -1
  64. package/dist/core/engine/fenced-write.d.ts +5 -3
  65. package/dist/core/engine/finalizer-status.d.ts +10 -0
  66. package/dist/core/engine/finalizer-status.js +82 -0
  67. package/dist/core/engine/index.d.ts +26 -2
  68. package/dist/core/engine/index.js +71 -8
  69. package/dist/core/engine/internals.d.ts +3 -0
  70. package/dist/core/engine/lease-health.d.ts +64 -0
  71. package/dist/core/engine/lease-health.js +0 -0
  72. package/dist/core/engine/lease-manager.d.ts +4 -2
  73. package/dist/core/engine/lease-manager.js +32 -4
  74. package/dist/core/engine/lifecycle/recovered-services.js +0 -2
  75. package/dist/core/engine/lifecycle/shared.d.ts +11 -8
  76. package/dist/core/engine/lifecycle/start-batch.js +12 -0
  77. package/dist/core/engine/lifecycle/start.d.ts +1 -1
  78. package/dist/core/engine/lifecycle/start.js +34 -5
  79. package/dist/core/engine/operations-coordination.d.ts +1 -12
  80. package/dist/core/engine/operations-coordination.js +58 -11
  81. package/dist/core/engine/operations-speculate.d.ts +1 -1
  82. package/dist/core/engine/operations-speculate.js +19 -5
  83. package/dist/core/engine/parallel-dispatch.d.ts +1 -1
  84. package/dist/core/engine/parallel-dispatch.js +1 -1
  85. package/dist/core/engine/registration.js +14 -0
  86. package/dist/core/engine/review-list-entries.d.ts +1 -1
  87. package/dist/core/engine/review-list-entries.js +6 -30
  88. package/dist/core/engine/schedule-handle.d.ts +4 -4
  89. package/dist/core/engine/schedule-handle.js +2 -2
  90. package/dist/core/engine/schedule-overlap.d.ts +11 -0
  91. package/dist/core/engine/schedule-overlap.js +50 -0
  92. package/dist/core/engine/schedule-run.d.ts +11 -3
  93. package/dist/core/engine/schedule-run.js +27 -4
  94. package/dist/core/engine/schedule-timer.js +10 -1
  95. package/dist/core/engine/schedules.d.ts +5 -4
  96. package/dist/core/engine/schedules.js +62 -56
  97. package/dist/core/engine/state-utilities.js +1 -1
  98. package/dist/core/engine/storage-io.d.ts +12 -0
  99. package/dist/core/engine/storage-io.js +49 -10
  100. package/dist/core/engine/termination/finalizer-claim.d.ts +8 -6
  101. package/dist/core/engine/termination/finalizer-claim.js +2 -1
  102. package/dist/core/engine/termination/finalizer.js +10 -14
  103. package/dist/core/engine/timeline-coordinator-constants.d.ts +3 -0
  104. package/dist/core/engine/timeline-coordinator-constants.js +1 -0
  105. package/dist/core/engine/timeline-coordinator-detail.d.ts +13 -0
  106. package/dist/core/engine/timeline-coordinator-detail.js +76 -0
  107. package/dist/core/engine/validation/schedule-options.d.ts +8 -1
  108. package/dist/core/engine/validation/schedule-options.js +18 -0
  109. package/dist/core/engine/validation/schedule.d.ts +1 -1
  110. package/dist/core/engine/validation/schedule.js +27 -3
  111. package/dist/core/engine/validation.js +66 -2
  112. package/dist/core/engine/workflow-state-stream.d.ts +5 -1
  113. package/dist/core/engine/workflow-state-stream.js +37 -14
  114. package/dist/core/events/schedule-events.d.ts +3 -4
  115. package/dist/core/events/workflow-events.d.ts +2 -1
  116. package/dist/core/list-filter-validation.d.ts +3 -0
  117. package/dist/core/list-filter-validation.js +11 -0
  118. package/dist/core/registry-snapshot.d.ts +32 -0
  119. package/dist/core/registry-snapshot.js +28 -0
  120. package/dist/core/review/index.d.ts +91 -4
  121. package/dist/core/review/index.js +29 -0
  122. package/dist/core/types/activity.d.ts +52 -5
  123. package/dist/core/types/bulk.d.ts +1 -0
  124. package/dist/core/types/list-options.d.ts +6 -0
  125. package/dist/core/types/options.d.ts +6 -5
  126. package/dist/core/types/reviews.d.ts +2 -2
  127. package/dist/core/types/schedules.d.ts +45 -2
  128. package/dist/core/types/services-resolution.d.ts +5 -5
  129. package/dist/core/types/state.d.ts +64 -0
  130. package/dist/core/types/workflow-log.d.ts +3 -2
  131. package/dist/core/types/workflow-observability.d.ts +50 -0
  132. package/dist/core/types/workflow-observability.js +0 -0
  133. package/dist/core/types/workflow-registry.d.ts +7 -0
  134. package/dist/core/types.d.ts +1 -0
  135. package/dist/core/types.js +1 -0
  136. package/dist/diagnostics/validate.d.ts +9 -30
  137. package/dist/diagnostics/validate.js +83 -21
  138. package/dist/diagnostics/version-check.d.ts +2 -2
  139. package/dist/http.js +2 -2
  140. package/dist/index.d.ts +4 -3
  141. package/dist/indexeddb.js +1 -1
  142. package/dist/server/access-policy-metadata.d.ts +92 -0
  143. package/dist/server/access-policy-metadata.js +78 -0
  144. package/dist/server/fault-to-http.d.ts +3 -7
  145. package/dist/server/fault-to-http.js +2 -34
  146. package/dist/server/handler/index.js +1 -1
  147. package/dist/server/handler/route-dispatch.d.ts +10 -3
  148. package/dist/server/handler/route-dispatch.js +19 -4
  149. package/dist/server/index.d.ts +1 -1
  150. package/dist/server/index.js +1 -0
  151. package/dist/server/interactive-operations.js +2 -0
  152. package/dist/server/openapi-error-responses.js +41 -4
  153. package/dist/server/openapi.d.ts +3 -1
  154. package/dist/server/openapi.js +4 -0
  155. package/dist/server/openrpc-document-schema.d.ts +64 -0
  156. package/dist/server/openrpc-document-schema.js +6 -26
  157. package/dist/server/openrpc.d.ts +4 -0
  158. package/dist/server/openrpc.js +9 -33
  159. package/dist/server/operation-catalog/index.d.ts +1 -1
  160. package/dist/server/operation-catalog/raise-fault.d.ts +2 -1
  161. package/dist/server/operation-catalog/types.d.ts +2 -1
  162. package/dist/server/operation-fault.d.ts +22 -8
  163. package/dist/server/operation-fault.js +65 -13
  164. package/dist/server/operation-registry.d.ts +1 -1
  165. package/dist/server/operations/aggregate-workflows.d.ts +6 -0
  166. package/dist/server/operations/aggregate-workflows.js +3 -2
  167. package/dist/server/operations/async-activity.d.ts +14 -0
  168. package/dist/server/operations/async-activity.js +88 -4
  169. package/dist/server/operations/bulk-filter-helpers.d.ts +3 -0
  170. package/dist/server/operations/bulk-filter-helpers.js +27 -3
  171. package/dist/server/operations/bulk-mutate-workflow-tags.d.ts +6 -0
  172. package/dist/server/operations/bulk-signal-workflows.d.ts +6 -0
  173. package/dist/server/operations/get-stream-chunks.js +2 -7
  174. package/dist/server/operations/get-system-lease.d.ts +19 -0
  175. package/dist/server/operations/get-system-lease.js +48 -0
  176. package/dist/server/operations/get-workflow-observability.d.ts +24 -0
  177. package/dist/server/operations/get-workflow-observability.js +80 -0
  178. package/dist/server/operations/get-workflow-result.js +2 -2
  179. package/dist/server/operations/get-workflow.d.ts +2 -2
  180. package/dist/server/operations/list-filter-query-extractor.js +15 -0
  181. package/dist/server/operations/list-reviews.js +2 -19
  182. package/dist/server/operations/list-workflows.d.ts +6 -0
  183. package/dist/server/operations/list-workflows.js +12 -3
  184. package/dist/server/operations/operation-helpers.d.ts +9 -18
  185. package/dist/server/operations/operation-helpers.js +5 -23
  186. package/dist/server/operations/purge-workflows.d.ts +3 -0
  187. package/dist/server/operations/recover-all.js +1 -9
  188. package/dist/server/operations/single-workflow-control-operation.d.ts +2 -1
  189. package/dist/server/operations/single-workflow-tag-mutation.js +2 -2
  190. package/dist/server/operations/sse-stream.js +2 -7
  191. package/dist/server/operations/storage-capabilities.d.ts +34 -0
  192. package/dist/server/operations/storage-capabilities.js +38 -0
  193. package/dist/server/operations/storage.js +8 -17
  194. package/dist/server/operations/stream-workflow-sse.js +3 -9
  195. package/dist/server/operations/update-schedule.d.ts +8 -0
  196. package/dist/server/operations/update-schedule.js +70 -7
  197. package/dist/server/operations/workflow-events-sse.js +2 -2
  198. package/dist/server/rest-binding.d.ts +7 -6
  199. package/dist/server/rest-bindings.d.ts +2 -13
  200. package/dist/server/rest-bindings.js +19 -10
  201. package/dist/server/task-queue.d.ts +7 -5
  202. package/dist/storage/bounded-ndjson-response.d.ts +5 -0
  203. package/dist/storage/bounded-ndjson-response.js +33 -0
  204. package/dist/storage/capabilities.d.ts +1 -1
  205. package/dist/storage/cloudflare-value-codec.d.ts +5 -3
  206. package/dist/storage/cloudflare-value-codec.js +1 -1
  207. package/dist/storage/compressed-storage.js +1 -1
  208. package/dist/storage/http.js +5 -37
  209. package/dist/storage/index.d.ts +7 -1
  210. package/dist/storage/interface.d.ts +16 -4
  211. package/dist/storage/interface.js +1 -1
  212. package/dist/storage/key-prefixes.d.ts +1 -1
  213. package/dist/storage/key-prefixes.js +4 -0
  214. package/dist/storage/lmdb.js +1 -1
  215. package/dist/storage/memory.js +1 -1
  216. package/dist/storage/neon.d.ts +3 -16
  217. package/dist/storage/neon.js +4 -4
  218. package/dist/storage/postgres.js +4 -4
  219. package/dist/storage/resolve.js +1 -1
  220. package/dist/storage/scoped-storage.js +1 -1
  221. package/dist/storage/testing.js +1 -1
  222. package/dist/storage/turso.js +2 -2
  223. package/dist/version.d.ts +1 -1
  224. package/dist/version.js +1 -1
  225. package/dist/web-extension.js +1 -1
  226. package/package.json +1 -1
@@ -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) {
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module human-review
8
8
  */
9
+ import { z } from 'zod';
9
10
  import type { BatchOperation, Storage } from '../../storage/interface.ts';
10
11
  import { WeftError } from '../weft-error.ts';
11
12
  /**
@@ -43,7 +44,7 @@ export interface ReviewRequest {
43
44
  * The `decision` field is the binary outcome; `sectionDecisions` carries
44
45
  * per-section verdicts when `allowPartial` is enabled on the request.
45
46
  */
46
- export interface ReviewDecision {
47
+ export interface ReviewDecisionRecord {
47
48
  reviewId: string;
48
49
  decision: 'approved' | 'rejected' | 'needs-changes';
49
50
  reviewer: string;
@@ -51,6 +52,92 @@ export interface ReviewDecision {
51
52
  sectionDecisions?: Record<string, 'approved' | 'rejected'>;
52
53
  timestamp: number;
53
54
  }
55
+ /** Canonical schema for a persisted review request without its storage envelope. */
56
+ export declare const reviewRequestSchema: z.ZodObject<{
57
+ reviewId: z.ZodString;
58
+ workflowId: z.ZodString;
59
+ artifact: z.ZodNonOptional<z.ZodUnknown>;
60
+ reviewType: z.ZodString;
61
+ reviewers: z.ZodArray<z.ZodString>;
62
+ allowPartial: z.ZodBoolean;
63
+ timeout: z.ZodOptional<z.ZodNumber>;
64
+ webhookUrl: z.ZodOptional<z.ZodString>;
65
+ createdAt: z.ZodNumber;
66
+ }, z.core.$strip>;
67
+ /** Canonical schema for a pending review entry returned by review list surfaces. */
68
+ export declare const pendingReviewEntrySchema: z.ZodObject<{
69
+ reviewId: z.ZodString;
70
+ workflowId: z.ZodString;
71
+ artifact: z.ZodNonOptional<z.ZodUnknown>;
72
+ reviewType: z.ZodString;
73
+ reviewers: z.ZodArray<z.ZodString>;
74
+ allowPartial: z.ZodBoolean;
75
+ timeout: z.ZodOptional<z.ZodNumber>;
76
+ webhookUrl: z.ZodOptional<z.ZodString>;
77
+ createdAt: z.ZodNumber;
78
+ status: z.ZodLiteral<"pending">;
79
+ }, z.core.$strip>;
80
+ /** Canonical schema for a completed review entry returned by review list surfaces. */
81
+ export declare const completedReviewEntrySchema: z.ZodObject<{
82
+ decision: z.ZodEnum<{
83
+ approved: "approved";
84
+ rejected: "rejected";
85
+ "needs-changes": "needs-changes";
86
+ }>;
87
+ reviewer: z.ZodString;
88
+ feedback: z.ZodOptional<z.ZodString>;
89
+ sectionDecisions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
90
+ approved: "approved";
91
+ rejected: "rejected";
92
+ }>>>;
93
+ timestamp: z.ZodNumber;
94
+ reviewId: z.ZodString;
95
+ workflowId: z.ZodString;
96
+ artifact: z.ZodNonOptional<z.ZodUnknown>;
97
+ reviewType: z.ZodString;
98
+ reviewers: z.ZodArray<z.ZodString>;
99
+ allowPartial: z.ZodBoolean;
100
+ timeout: z.ZodOptional<z.ZodNumber>;
101
+ webhookUrl: z.ZodOptional<z.ZodString>;
102
+ createdAt: z.ZodNumber;
103
+ status: z.ZodLiteral<"completed">;
104
+ }, z.core.$strip>;
105
+ /** Canonical schema for the discriminated review list-entry union. */
106
+ export declare const reviewListEntrySchema: z.ZodUnion<readonly [z.ZodObject<{
107
+ reviewId: z.ZodString;
108
+ workflowId: z.ZodString;
109
+ artifact: z.ZodNonOptional<z.ZodUnknown>;
110
+ reviewType: z.ZodString;
111
+ reviewers: z.ZodArray<z.ZodString>;
112
+ allowPartial: z.ZodBoolean;
113
+ timeout: z.ZodOptional<z.ZodNumber>;
114
+ webhookUrl: z.ZodOptional<z.ZodString>;
115
+ createdAt: z.ZodNumber;
116
+ status: z.ZodLiteral<"pending">;
117
+ }, z.core.$strip>, z.ZodObject<{
118
+ decision: z.ZodEnum<{
119
+ approved: "approved";
120
+ rejected: "rejected";
121
+ "needs-changes": "needs-changes";
122
+ }>;
123
+ reviewer: z.ZodString;
124
+ feedback: z.ZodOptional<z.ZodString>;
125
+ sectionDecisions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
126
+ approved: "approved";
127
+ rejected: "rejected";
128
+ }>>>;
129
+ timestamp: z.ZodNumber;
130
+ reviewId: z.ZodString;
131
+ workflowId: z.ZodString;
132
+ artifact: z.ZodNonOptional<z.ZodUnknown>;
133
+ reviewType: z.ZodString;
134
+ reviewers: z.ZodArray<z.ZodString>;
135
+ allowPartial: z.ZodBoolean;
136
+ timeout: z.ZodOptional<z.ZodNumber>;
137
+ webhookUrl: z.ZodOptional<z.ZodString>;
138
+ createdAt: z.ZodNumber;
139
+ status: z.ZodLiteral<"completed">;
140
+ }, z.core.$strip>]>;
54
141
  /**
55
142
  * One step in a {@link ReviewOptions.escalation} chain. Either reassigns the
56
143
  * pending review to a new owner (`to`) or auto-decides it (`action`) after
@@ -119,7 +206,7 @@ export interface HumanReviewOptions extends ReviewOptions {
119
206
  }
120
207
  /**
121
208
  * The decision payload returned to the workflow from `ctx.review()`.
122
- * Alias for {@link ReviewDecision}.
209
+ * Alias for {@link ReviewDecisionRecord}.
123
210
  *
124
211
  * @example
125
212
  * ```ts
@@ -134,7 +221,7 @@ export interface HumanReviewOptions extends ReviewOptions {
134
221
  * void result;
135
222
  * ```
136
223
  */
137
- export type HumanReviewResult = ReviewDecision;
224
+ export type HumanReviewResult = ReviewDecisionRecord;
138
225
  /**
139
226
  * The action returned by {@link ReviewCoordinator.checkEscalations} when an
140
227
  * escalation step has fired. Either reassigns the review to a new owner or
@@ -253,7 +340,7 @@ export declare class ReviewCoordinator {
253
340
  /** Create a review request and persist it. */
254
341
  createReview(workflowId: string, options: ReviewOptions): Promise<ReviewRequest>;
255
342
  /** Submit a review decision. */
256
- submitDecision(reviewId: string, decision: Omit<ReviewDecision, 'reviewId' | 'timestamp'>): Promise<ReviewDecision>;
343
+ submitDecision(reviewId: string, decision: Omit<ReviewDecisionRecord, 'reviewId' | 'timestamp'>): Promise<ReviewDecisionRecord>;
257
344
  /** Get a pending review. */
258
345
  getReview(workflowId: string, reviewId: string): Promise<ReviewRequest | null>;
259
346
  /** List pending reviews. */
@@ -1,7 +1,36 @@
1
+ import { z } from "zod";
1
2
  import { KEYS } from "../../storage/interface.js";
2
3
  import { decode, encode } from "../codec.js";
3
4
  import { WeftError } from "../weft-error.js";
4
5
  import { ReviewRequestedEvent } from "./events.js";
6
+ const reviewRequestFields = {
7
+ reviewId: z.string(),
8
+ workflowId: z.string(),
9
+ artifact: z.unknown().nonoptional(),
10
+ reviewType: z.string(),
11
+ reviewers: z.array(z.string()),
12
+ allowPartial: z.boolean(),
13
+ timeout: z.number().optional(),
14
+ webhookUrl: z.string().optional(),
15
+ createdAt: z.number()
16
+ }, reviewDecisionFields = {
17
+ decision: z.enum(["approved", "rejected", "needs-changes"]),
18
+ reviewer: z.string(),
19
+ feedback: z.string().optional(),
20
+ sectionDecisions: z.record(z.string(), z.enum(["approved", "rejected"])).optional(),
21
+ timestamp: z.number()
22
+ };
23
+ export const reviewRequestSchema = z.object(reviewRequestFields), pendingReviewEntrySchema = z.object({
24
+ status: z.literal("pending"),
25
+ ...reviewRequestFields
26
+ }), completedReviewEntrySchema = z.object({
27
+ status: z.literal("completed"),
28
+ ...reviewRequestFields,
29
+ ...reviewDecisionFields
30
+ }), reviewListEntrySchema = z.union([
31
+ pendingReviewEntrySchema,
32
+ completedReviewEntrySchema
33
+ ]);
5
34
 
6
35
  export class ReviewTimeoutError extends WeftError {
7
36
  reviewId;
@@ -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 (listen for it to receive the token).
120
- * The token is deterministic and survives engine restart: it is re-minted
121
- * identically when the activity replays after recovery.
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
- * and gate the mutating surface with `serve({ auth })` if completions must not
128
- * be anonymous.
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
@@ -52,6 +52,7 @@ export type BulkOperationPrincipal = {
52
52
  export type BulkOperationFilterSummary = {
53
53
  status?: WorkflowStatus | WorkflowStatus[];
54
54
  type?: string;
55
+ scheduleId?: string;
55
56
  tags?: string[];
56
57
  attributes?: Array<{
57
58
  key: string;
@@ -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 pino / winston
450
- * / OpenTelemetry stack, etc.) **instead of** the console; when omitted, records
451
- * fall back to the matching `console` method, preserving the default behavior.
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. Worker-mode records still log to the worker
456
- * process's console routing them back to the host is tracked separately.
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 { ReviewDecision as CompletedReviewDecision, ReviewRequest } from '../review/index.ts';
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 CompletedReviewDecision {
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
- queuedRuns: number;
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
- queuedRuns: number;
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. New scheduled runs persist this context with the
54
- * workflow record, so a fresh-process recovery receives the same schedule id and
55
- * known occurrence timestamp as the live launch path. Runs from older stores
56
- * that predate the metadata may omit it, and queue-drained runs may omit
57
- * `occurrence` because their original grid timestamp was not retained.
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
@@ -66,6 +66,10 @@ export interface WorkflowState {
66
66
  * tree.
67
67
  */
68
68
  executionStateOwnerId?: string;
69
+ /** Immediate parent workflow id for runs launched through `ctx.startChild()`. */
70
+ parentWorkflowId?: WorkflowId;
71
+ /** Concrete parent run token, used to distinguish stable-id reuse generations. */
72
+ parentWorkflowExecutionToken?: string;
69
73
  createdAt: number;
70
74
  startedAt?: number;
71
75
  updatedAt: number;
@@ -76,6 +80,30 @@ export interface WorkflowState {
76
80
  * another workflow checkpoint. Absent for workflows started normally.
77
81
  */
78
82
  forkedFrom?: ForkLineage;
83
+ /** Immediate terminal run displaced when this run was created with `start-new`. */
84
+ restartedFrom?: RestartLineage;
85
+ }
86
+ /**
87
+ * Immediate predecessor recorded when `onTerminalConflict: 'start-new'` reuses
88
+ * a stable workflow id. The execution token identifies the concrete displaced
89
+ * run because both runs share the same workflow id.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import type { RestartLineage } from '@lostgradient/weft';
94
+ *
95
+ * const lineage: RestartLineage = {
96
+ * workflowId: 'nightly-reconciliation',
97
+ * workflowExecutionToken: 'prior-run-token',
98
+ * replacedAt: Date.now(),
99
+ * };
100
+ * void lineage;
101
+ * ```
102
+ */
103
+ export interface RestartLineage {
104
+ workflowId: WorkflowId;
105
+ workflowExecutionToken?: string;
106
+ replacedAt: number;
79
107
  }
80
108
  /**
81
109
  * Lineage metadata recorded when a workflow was created by forking another
@@ -92,6 +120,32 @@ export interface ForkLineage {
92
120
  * whole workflow. Used in {@link WorkflowTimelineEntry}.
93
121
  */
94
122
  export type WorkflowTimelineStatus = 'running' | 'completed' | 'failed' | 'cancelled' | 'timed-out';
123
+ /**
124
+ * Bounded metadata describing one direct operation inside a timeline coordinator.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import type { WorkflowTimelineOperationDetail } from '@lostgradient/weft';
129
+ *
130
+ * const winner: WorkflowTimelineOperationDetail = {
131
+ * index: 0,
132
+ * operationId: 'race:0:0',
133
+ * operationType: 'activity',
134
+ * operationLabel: 'fetchPrimary',
135
+ * outcome: 'won',
136
+ * };
137
+ * void winner;
138
+ * ```
139
+ */
140
+ export type WorkflowTimelineOperationDetail = {
141
+ index: number;
142
+ key?: string;
143
+ operationId: string;
144
+ operationType: string;
145
+ operationLabel: string;
146
+ outcome: 'fulfilled' | 'rejected' | 'won' | 'lost';
147
+ errorSummary?: string;
148
+ };
95
149
  /**
96
150
  * A single chronological entry in a workflow's execution timeline, summarising
97
151
  * one operation (activity call, sleep, signal wait, etc.). Returned by
@@ -110,6 +164,16 @@ export type WorkflowTimelineEntry = {
110
164
  timestamp: number;
111
165
  status: WorkflowTimelineStatus;
112
166
  versionTuple?: WorkflowVersionTuple;
167
+ /** Direct branch metadata for `ctx.all`, `ctx.runAll`, and `ctx.race`. */
168
+ branches?: WorkflowTimelineOperationDetail[];
169
+ /** Number of direct branches omitted from `branches` by the durable size bound. */
170
+ branchesOmitted?: number;
171
+ /** Ordered direct operations yielded by `ctx.speculate`. */
172
+ children?: WorkflowTimelineOperationDetail[];
173
+ /** Number of direct speculative children omitted from `children` by the durable size bound. */
174
+ childrenOmitted?: number;
175
+ /** Whether the speculative child context committed or rolled back. */
176
+ speculationOutcome?: 'committed' | 'rolled-back';
113
177
  };
114
178
  /**
115
179
  * Options accepted by `ctx.state.session(key, options)`.
@@ -22,8 +22,9 @@ export type WorkflowLogLevel = 'debug' | 'info' | 'warn' | 'error';
22
22
  * fields (`level`, `message`, `workflowId`, `workflowType`, `timestamp`) are
23
23
  * engine-owned and always present; caller `attributes` nest under their own key so
24
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.
25
+ * observability metadata, never checkpointed or replayed. Weft does not retain
26
+ * records for later engine/client/transport queries; a host that needs history
27
+ * persists records received through `EngineOptions.onLog` in its logging system.
27
28
  *
28
29
  * @example
29
30
  * ```ts
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The recurring schedule occurrence that launched a workflow run.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { type WorkflowScheduleProvenance } from '@lostgradient/weft';
7
+ *
8
+ * const provenance: WorkflowScheduleProvenance = {
9
+ * scheduleId: 'nightly-cleanup',
10
+ * occurrence: Date.UTC(2026, 0, 1),
11
+ * };
12
+ * void provenance;
13
+ * ```
14
+ */
15
+ export interface WorkflowScheduleProvenance {
16
+ scheduleId: string;
17
+ occurrence?: number;
18
+ }
19
+ /**
20
+ * Durable progress and outcome of a workflow's post-terminal finalizer.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { type WorkflowFinalizerStatus } from '@lostgradient/weft';
25
+ *
26
+ * const finalizer: WorkflowFinalizerStatus = {
27
+ * status: 'succeeded',
28
+ * attempts: 1,
29
+ * completedAt: Date.now(),
30
+ * };
31
+ * void finalizer;
32
+ * ```
33
+ */
34
+ export type WorkflowFinalizerStatus = {
35
+ status: 'pending';
36
+ attempts: number;
37
+ } | {
38
+ status: 'running';
39
+ attempts: number;
40
+ startedAt: number;
41
+ } | {
42
+ status: 'succeeded';
43
+ attempts: number;
44
+ completedAt: number;
45
+ } | {
46
+ status: 'failed';
47
+ attempts: number;
48
+ failedAt: number;
49
+ error: string;
50
+ };
File without changes
@@ -1,4 +1,5 @@
1
1
  import type { DefinitionSchema } from './definition-schema.ts';
2
+ import type { QueryDefinition, SignalDefinition, UpdateDefinition } from './message-handles.ts';
2
3
  import type { SearchAttributeSchema } from './search-attributes.ts';
3
4
  import type { WorkflowConcurrencyOptions } from './workflow-concurrency.ts';
4
5
  /**
@@ -27,6 +28,12 @@ export interface RegisteredWorkflowDefinition<TInput = unknown, TOutput = unknow
27
28
  inputSchema?: DefinitionSchema<unknown, TInput>;
28
29
  /** Optional output schema metadata for introspection; core execution does not validate output against it. */
29
30
  outputSchema?: DefinitionSchema<unknown, TOutput>;
31
+ /** Statically registered signal definitions keyed by their public names. */
32
+ signals?: Readonly<Record<string, Readonly<SignalDefinition<unknown>>>>;
33
+ /** Statically registered update definitions keyed by their public names. */
34
+ updates?: Readonly<Record<string, Readonly<UpdateDefinition<unknown>>>>;
35
+ /** Statically registered query definitions keyed by their public names. */
36
+ queries?: Readonly<Record<string, Readonly<QueryDefinition<unknown>>>>;
30
37
  /** Optional search attribute schema used for indexing and runtime validation. */
31
38
  searchAttributes?: SearchAttributeSchema;
32
39
  /** Optional start admission policy for this workflow type. */
@@ -28,6 +28,7 @@ export * from './types/workflow-concurrency.ts';
28
28
  export * from './types/workflow-context.ts';
29
29
  export * from './types/workflow-function.ts';
30
30
  export * from './types/workflow-log.ts';
31
+ export * from './types/workflow-observability.ts';
31
32
  export * from './types/workflow-registries.ts';
32
33
  export * from './types/workflow-registry.ts';
33
34
  export * from './types/workflow-snapshot.ts';
@@ -28,6 +28,7 @@ export * from "./types/workflow-concurrency.js";
28
28
  export * from "./types/workflow-context.js";
29
29
  export * from "./types/workflow-function.js";
30
30
  export * from "./types/workflow-log.js";
31
+ export * from "./types/workflow-observability.js";
31
32
  export * from "./types/workflow-registries.js";
32
33
  export * from "./types/workflow-registry.js";
33
34
  export * from "./types/workflow-snapshot.js";