awaitly 1.34.0 → 2.0.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 (241) hide show
  1. package/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
  2. package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
  3. package/dist/errors-DtXvrCiO.d.cts +708 -0
  4. package/dist/errors-DtXvrCiO.d.ts +708 -0
  5. package/dist/index.cjs +4594 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +1970 -141
  8. package/dist/index.d.ts +1970 -141
  9. package/dist/index.js +4398 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/result.cjs +641 -1
  12. package/dist/result.cjs.map +1 -1
  13. package/dist/result.d.cts +35 -5
  14. package/dist/result.d.ts +35 -5
  15. package/dist/result.js +561 -1
  16. package/dist/result.js.map +1 -1
  17. package/dist/testing.cjs +4202 -8
  18. package/dist/testing.cjs.map +1 -1
  19. package/dist/testing.d.cts +2 -6
  20. package/dist/testing.d.ts +2 -6
  21. package/dist/testing.js +4154 -8
  22. package/dist/testing.js.map +1 -1
  23. package/dist/{run-entry-D2MmJFj9.d.cts → types-B8NfNRGX.d.ts} +1152 -1499
  24. package/dist/{run-entry-Dduz-is2.d.ts → types-BZ2f4MRR.d.cts} +1152 -1499
  25. package/dist/workflow.cjs +7096 -6
  26. package/dist/workflow.cjs.map +1 -1
  27. package/dist/workflow.d.cts +3346 -22
  28. package/dist/workflow.d.ts +3346 -22
  29. package/dist/workflow.js +6929 -6
  30. package/dist/workflow.js.map +1 -1
  31. package/package.json +13 -178
  32. package/dist/adapters.cjs +0 -7
  33. package/dist/adapters.cjs.map +0 -1
  34. package/dist/adapters.d.cts +0 -179
  35. package/dist/adapters.d.ts +0 -179
  36. package/dist/adapters.js +0 -7
  37. package/dist/adapters.js.map +0 -1
  38. package/dist/batch.cjs +0 -7
  39. package/dist/batch.cjs.map +0 -1
  40. package/dist/batch.d.cts +0 -200
  41. package/dist/batch.d.ts +0 -200
  42. package/dist/batch.js +0 -7
  43. package/dist/batch.js.map +0 -1
  44. package/dist/bind-deps.cjs +0 -2
  45. package/dist/bind-deps.cjs.map +0 -1
  46. package/dist/bind-deps.d.cts +0 -28
  47. package/dist/bind-deps.d.ts +0 -28
  48. package/dist/bind-deps.js +0 -2
  49. package/dist/bind-deps.js.map +0 -1
  50. package/dist/cache.cjs +0 -2
  51. package/dist/cache.cjs.map +0 -1
  52. package/dist/cache.d.cts +0 -269
  53. package/dist/cache.d.ts +0 -269
  54. package/dist/cache.js +0 -2
  55. package/dist/cache.js.map +0 -1
  56. package/dist/circuit-breaker.cjs +0 -7
  57. package/dist/circuit-breaker.cjs.map +0 -1
  58. package/dist/circuit-breaker.d.cts +0 -211
  59. package/dist/circuit-breaker.d.ts +0 -211
  60. package/dist/circuit-breaker.js +0 -7
  61. package/dist/circuit-breaker.js.map +0 -1
  62. package/dist/conditional.cjs +0 -2
  63. package/dist/conditional.cjs.map +0 -1
  64. package/dist/conditional.d.cts +0 -252
  65. package/dist/conditional.d.ts +0 -252
  66. package/dist/conditional.js +0 -2
  67. package/dist/conditional.js.map +0 -1
  68. package/dist/core.cjs +0 -7
  69. package/dist/core.cjs.map +0 -1
  70. package/dist/core.d.cts +0 -5
  71. package/dist/core.d.ts +0 -5
  72. package/dist/core.js +0 -7
  73. package/dist/core.js.map +0 -1
  74. package/dist/di-COl5oFnR.d.cts +0 -15
  75. package/dist/di-CyDj_JyZ.d.ts +0 -15
  76. package/dist/diagnostics.cjs +0 -8
  77. package/dist/diagnostics.cjs.map +0 -1
  78. package/dist/diagnostics.d.cts +0 -68
  79. package/dist/diagnostics.d.ts +0 -68
  80. package/dist/diagnostics.js +0 -8
  81. package/dist/diagnostics.js.map +0 -1
  82. package/dist/durable.cjs +0 -11
  83. package/dist/durable.cjs.map +0 -1
  84. package/dist/durable.d.cts +0 -9
  85. package/dist/durable.d.ts +0 -9
  86. package/dist/durable.js +0 -11
  87. package/dist/durable.js.map +0 -1
  88. package/dist/duration.cjs +0 -2
  89. package/dist/duration.cjs.map +0 -1
  90. package/dist/duration.js +0 -2
  91. package/dist/duration.js.map +0 -1
  92. package/dist/engine.cjs +0 -11
  93. package/dist/engine.cjs.map +0 -1
  94. package/dist/engine.d.cts +0 -115
  95. package/dist/engine.d.ts +0 -115
  96. package/dist/engine.js +0 -11
  97. package/dist/engine.js.map +0 -1
  98. package/dist/errors.cjs +0 -2
  99. package/dist/errors.cjs.map +0 -1
  100. package/dist/errors.d.cts +0 -361
  101. package/dist/errors.d.ts +0 -361
  102. package/dist/errors.js +0 -2
  103. package/dist/errors.js.map +0 -1
  104. package/dist/fetch.cjs +0 -7
  105. package/dist/fetch.cjs.map +0 -1
  106. package/dist/fetch.d.cts +0 -86
  107. package/dist/fetch.d.ts +0 -86
  108. package/dist/fetch.js +0 -7
  109. package/dist/fetch.js.map +0 -1
  110. package/dist/flow.cjs +0 -7
  111. package/dist/flow.cjs.map +0 -1
  112. package/dist/flow.d.cts +0 -163
  113. package/dist/flow.d.ts +0 -163
  114. package/dist/flow.js +0 -7
  115. package/dist/flow.js.map +0 -1
  116. package/dist/functional.cjs +0 -2
  117. package/dist/functional.cjs.map +0 -1
  118. package/dist/functional.d.cts +0 -444
  119. package/dist/functional.d.ts +0 -444
  120. package/dist/functional.js +0 -2
  121. package/dist/functional.js.map +0 -1
  122. package/dist/guards-BodHXLzX.d.cts +0 -72
  123. package/dist/guards-CeWoQ8fn.d.ts +0 -72
  124. package/dist/hitl-BPE_1UiM.d.cts +0 -468
  125. package/dist/hitl-byp570uC.d.ts +0 -468
  126. package/dist/hitl.cjs +0 -7
  127. package/dist/hitl.cjs.map +0 -1
  128. package/dist/hitl.d.cts +0 -442
  129. package/dist/hitl.d.ts +0 -442
  130. package/dist/hitl.js +0 -7
  131. package/dist/hitl.js.map +0 -1
  132. package/dist/index-BYT3amEz.d.ts +0 -417
  133. package/dist/index-C_ak66jy.d.cts +0 -417
  134. package/dist/match-entry-DjI2bLpD.d.cts +0 -209
  135. package/dist/match-entry-DjI2bLpD.d.ts +0 -209
  136. package/dist/match.cjs +0 -2
  137. package/dist/match.cjs.map +0 -1
  138. package/dist/match.d.cts +0 -1
  139. package/dist/match.d.ts +0 -1
  140. package/dist/match.js +0 -2
  141. package/dist/match.js.map +0 -1
  142. package/dist/otel.cjs +0 -2
  143. package/dist/otel.cjs.map +0 -1
  144. package/dist/otel.d.cts +0 -188
  145. package/dist/otel.d.ts +0 -188
  146. package/dist/otel.js +0 -2
  147. package/dist/otel.js.map +0 -1
  148. package/dist/persistence-entry-DOMx3woy.d.ts +0 -822
  149. package/dist/persistence-entry-ymCA4iDu.d.cts +0 -822
  150. package/dist/persistence.cjs +0 -2
  151. package/dist/persistence.cjs.map +0 -1
  152. package/dist/persistence.d.cts +0 -7
  153. package/dist/persistence.d.ts +0 -7
  154. package/dist/persistence.js +0 -2
  155. package/dist/persistence.js.map +0 -1
  156. package/dist/policies.cjs +0 -2
  157. package/dist/policies.cjs.map +0 -1
  158. package/dist/policies.d.cts +0 -379
  159. package/dist/policies.d.ts +0 -379
  160. package/dist/policies.js +0 -2
  161. package/dist/policies.js.map +0 -1
  162. package/dist/ratelimit.cjs +0 -7
  163. package/dist/ratelimit.cjs.map +0 -1
  164. package/dist/ratelimit.d.cts +0 -458
  165. package/dist/ratelimit.d.ts +0 -458
  166. package/dist/ratelimit.js +0 -7
  167. package/dist/ratelimit.js.map +0 -1
  168. package/dist/reliability.cjs +0 -11
  169. package/dist/reliability.cjs.map +0 -1
  170. package/dist/reliability.d.cts +0 -11
  171. package/dist/reliability.d.ts +0 -11
  172. package/dist/reliability.js +0 -11
  173. package/dist/reliability.js.map +0 -1
  174. package/dist/resolver.cjs +0 -7
  175. package/dist/resolver.cjs.map +0 -1
  176. package/dist/resolver.d.cts +0 -68
  177. package/dist/resolver.d.ts +0 -68
  178. package/dist/resolver.js +0 -7
  179. package/dist/resolver.js.map +0 -1
  180. package/dist/resource.cjs +0 -7
  181. package/dist/resource.cjs.map +0 -1
  182. package/dist/resource.d.cts +0 -174
  183. package/dist/resource.d.ts +0 -174
  184. package/dist/resource.js +0 -7
  185. package/dist/resource.js.map +0 -1
  186. package/dist/result/retry.cjs +0 -2
  187. package/dist/result/retry.cjs.map +0 -1
  188. package/dist/result/retry.d.cts +0 -70
  189. package/dist/result/retry.d.ts +0 -70
  190. package/dist/result/retry.js +0 -2
  191. package/dist/result/retry.js.map +0 -1
  192. package/dist/retry.cjs +0 -2
  193. package/dist/retry.cjs.map +0 -1
  194. package/dist/retry.d.cts +0 -388
  195. package/dist/retry.d.ts +0 -388
  196. package/dist/retry.js +0 -2
  197. package/dist/retry.js.map +0 -1
  198. package/dist/run.cjs +0 -7
  199. package/dist/run.cjs.map +0 -1
  200. package/dist/run.d.cts +0 -4
  201. package/dist/run.d.ts +0 -4
  202. package/dist/run.js +0 -7
  203. package/dist/run.js.map +0 -1
  204. package/dist/saga.cjs +0 -11
  205. package/dist/saga.cjs.map +0 -1
  206. package/dist/saga.d.cts +0 -164
  207. package/dist/saga.d.ts +0 -164
  208. package/dist/saga.js +0 -11
  209. package/dist/saga.js.map +0 -1
  210. package/dist/singleflight.cjs +0 -2
  211. package/dist/singleflight.cjs.map +0 -1
  212. package/dist/singleflight.d.cts +0 -145
  213. package/dist/singleflight.d.ts +0 -145
  214. package/dist/singleflight.js +0 -2
  215. package/dist/singleflight.js.map +0 -1
  216. package/dist/slugs.cjs +0 -2
  217. package/dist/slugs.cjs.map +0 -1
  218. package/dist/slugs.d.cts +0 -67
  219. package/dist/slugs.d.ts +0 -67
  220. package/dist/slugs.js +0 -2
  221. package/dist/slugs.js.map +0 -1
  222. package/dist/streaming.cjs +0 -9
  223. package/dist/streaming.cjs.map +0 -1
  224. package/dist/streaming.d.cts +0 -596
  225. package/dist/streaming.d.ts +0 -596
  226. package/dist/streaming.js +0 -9
  227. package/dist/streaming.js.map +0 -1
  228. package/dist/tagged-error.cjs +0 -2
  229. package/dist/tagged-error.cjs.map +0 -1
  230. package/dist/tagged-error.d.cts +0 -275
  231. package/dist/tagged-error.d.ts +0 -275
  232. package/dist/tagged-error.js +0 -2
  233. package/dist/tagged-error.js.map +0 -1
  234. package/dist/types-DQmzO9f4.d.ts +0 -323
  235. package/dist/types-qBUOYi-4.d.cts +0 -323
  236. package/dist/webhook.cjs +0 -7
  237. package/dist/webhook.cjs.map +0 -1
  238. package/dist/webhook.d.cts +0 -499
  239. package/dist/webhook.d.ts +0 -499
  240. package/dist/webhook.js +0 -7
  241. package/dist/webhook.js.map +0 -1
package/dist/hitl.d.cts DELETED
@@ -1,442 +0,0 @@
1
- import { R as ResumeState, a as Workflow } from './persistence-entry-ymCA4iDu.cjs';
2
- export { A as ApprovalRejected, b as ApprovalStepOptions, G as GatedStepOptions, P as PendingApproval } from './persistence-entry-ymCA4iDu.cjs';
3
- export { a as isApprovalRejected, b as isPendingApproval } from './guards-BodHXLzX.cjs';
4
- export { c as clearStep, a as createApprovalStateCollector, b as createApprovalStep, g as gatedStep, d as getPendingApprovals, h as hasPendingApproval, i as injectApproval, p as pendingApproval } from './hitl-BPE_1UiM.cjs';
5
- import { R as Result, ag as WorkflowEvent } from './run-entry-D2MmJFj9.cjs';
6
- import './types-qBUOYi-4.cjs';
7
- import '@standard-schema/spec';
8
- import './errors.cjs';
9
- import './tagged-error.cjs';
10
- import './slugs.cjs';
11
-
12
- /**
13
- * awaitly/hitl
14
- *
15
- * Human-in-the-Loop Orchestration Helpers.
16
- * Provides pollers, webhook handlers, and resume injectors
17
- * for production-ready approval workflows.
18
- */
19
-
20
- /**
21
- * Options passed to the workflow factory by the HITL orchestrator.
22
- */
23
- interface HITLWorkflowFactoryOptions {
24
- /** Resume state for replaying completed steps */
25
- resumeState?: ResumeState;
26
- /** Event handler for tracking workflow events (required for HITL) */
27
- onEvent: (event: WorkflowEvent<unknown>) => void;
28
- }
29
- /**
30
- * Approval status returned from the approval store.
31
- */
32
- type ApprovalStatus<T = unknown> = {
33
- status: "pending";
34
- } | {
35
- status: "approved";
36
- value: T;
37
- approvedBy?: string;
38
- approvedAt?: number;
39
- } | {
40
- status: "rejected";
41
- reason: string;
42
- rejectedBy?: string;
43
- rejectedAt?: number;
44
- } | {
45
- status: "expired";
46
- expiredAt: number;
47
- } | {
48
- status: "edited";
49
- originalValue: T;
50
- editedValue: T;
51
- editedBy?: string;
52
- editedAt?: number;
53
- };
54
- /**
55
- * Context passed to notification channel when an approval is needed.
56
- */
57
- interface ApprovalNeededContext {
58
- /** Unique approval key for correlation */
59
- approvalKey: string;
60
- /** Workflow run ID */
61
- runId: string;
62
- /** Workflow name/type */
63
- workflowName: string;
64
- /** Human-readable reason for the approval */
65
- reason?: string;
66
- /** Custom metadata attached to the approval */
67
- metadata?: Record<string, unknown>;
68
- /** When the approval expires (timestamp) */
69
- expiresAt?: number;
70
- /** Human-readable summary for notifications */
71
- summary?: string;
72
- /** For gated steps: the operation args that need approval */
73
- pendingArgs?: Record<string, unknown>;
74
- }
75
- /**
76
- * Context passed to notification channel when an approval is resolved.
77
- */
78
- interface ApprovalResolvedContext {
79
- /** Unique approval key */
80
- approvalKey: string;
81
- /** Resolution action */
82
- action: "approved" | "rejected" | "edited" | "expired" | "cancelled";
83
- /** Who performed the action (if available) */
84
- actorId?: string;
85
- /** Timestamp of resolution */
86
- resolvedAt: number;
87
- /** Reason (for rejections) */
88
- reason?: string;
89
- /** Value (for approvals/edits) */
90
- value?: unknown;
91
- /** Original value (for edits) */
92
- originalValue?: unknown;
93
- }
94
- /**
95
- * Notification channel for external integrations (Slack, email, etc).
96
- * Implement this interface to receive push notifications when approvals
97
- * are created or resolved.
98
- */
99
- interface NotificationChannel {
100
- /**
101
- * Called when a new approval request is created.
102
- * Use this to send Slack messages, emails, or push to a UI.
103
- */
104
- onApprovalNeeded(context: ApprovalNeededContext): Promise<void>;
105
- /**
106
- * Called when an approval is granted, rejected, edited, or expires.
107
- * Use this to update Slack messages, send confirmation emails, etc.
108
- */
109
- onApprovalResolved?(context: ApprovalResolvedContext): Promise<void>;
110
- }
111
- /**
112
- * Interface for approval storage backends.
113
- */
114
- interface ApprovalStore {
115
- /**
116
- * Get the status of an approval.
117
- */
118
- getApproval(key: string): Promise<ApprovalStatus>;
119
- /**
120
- * Create or update a pending approval request.
121
- */
122
- createApproval(key: string, options?: {
123
- metadata?: Record<string, unknown>;
124
- expiresAt?: number;
125
- requestedBy?: string;
126
- }): Promise<void>;
127
- /**
128
- * Grant an approval.
129
- */
130
- grantApproval<T>(key: string, value: T, options?: {
131
- approvedBy?: string;
132
- }): Promise<void>;
133
- /**
134
- * Reject an approval.
135
- */
136
- rejectApproval(key: string, reason: string, options?: {
137
- rejectedBy?: string;
138
- }): Promise<void>;
139
- /**
140
- * Edit an approval (approve with modifications).
141
- * Records both the original proposed value and the edited value.
142
- */
143
- editApproval<T>(key: string, originalValue: T, editedValue: T, options?: {
144
- editedBy?: string;
145
- }): Promise<void>;
146
- /**
147
- * Cancel a pending approval.
148
- */
149
- cancelApproval(key: string): Promise<void>;
150
- /**
151
- * List all pending approvals.
152
- */
153
- listPending(options?: {
154
- prefix?: string;
155
- }): Promise<string[]>;
156
- }
157
- /**
158
- * Saved workflow state for resumption.
159
- */
160
- interface SavedWorkflowState {
161
- /** Unique identifier for this workflow run */
162
- runId: string;
163
- /** Workflow name/type */
164
- workflowName: string;
165
- /** Resume state with step results */
166
- resumeState: ResumeState;
167
- /** Pending approval keys */
168
- pendingApprovals: string[];
169
- /** Input that was passed to the workflow */
170
- input?: unknown;
171
- /** Custom metadata */
172
- metadata?: Record<string, unknown>;
173
- /** When the workflow was started */
174
- startedAt: number;
175
- /** When the state was last updated */
176
- updatedAt: number;
177
- }
178
- /**
179
- * Interface for workflow state storage.
180
- */
181
- interface WorkflowStateStore {
182
- /**
183
- * Save workflow state.
184
- */
185
- save(state: SavedWorkflowState): Promise<void>;
186
- /**
187
- * Load workflow state by run ID.
188
- */
189
- load(runId: string): Promise<SavedWorkflowState | undefined>;
190
- /**
191
- * Delete workflow state.
192
- */
193
- delete(runId: string): Promise<void>;
194
- /**
195
- * List all saved workflow states.
196
- */
197
- list(options?: {
198
- workflowName?: string;
199
- hasPendingApprovals?: boolean;
200
- }): Promise<string[]>;
201
- /**
202
- * Find workflows waiting for a specific approval.
203
- */
204
- findByPendingApproval(approvalKey: string): Promise<string[]>;
205
- }
206
- /**
207
- * Options for the HITL orchestrator.
208
- */
209
- interface HITLOrchestratorOptions {
210
- /** Approval store for managing approval states */
211
- approvalStore: ApprovalStore;
212
- /** Workflow state store for persisting workflow state */
213
- workflowStateStore: WorkflowStateStore;
214
- /** Default expiration time for approvals (in milliseconds) */
215
- defaultExpirationMs?: number;
216
- /** Logger function */
217
- logger?: (message: string) => void;
218
- /**
219
- * Notification channel for external integrations.
220
- * When provided, the orchestrator will call onApprovalNeeded when
221
- * an approval is created, and onApprovalResolved when resolved.
222
- */
223
- notificationChannel?: NotificationChannel;
224
- }
225
- /**
226
- * Result of executing a workflow that may pause for approval.
227
- * Uses unknown for error type since workflows add UnexpectedError to the union.
228
- */
229
- type HITLExecutionResult<T, E> = {
230
- status: "completed";
231
- result: Result<T, E | unknown>;
232
- } | {
233
- status: "paused";
234
- runId: string;
235
- pendingApprovals: string[];
236
- reason?: string;
237
- } | {
238
- status: "resumed";
239
- runId: string;
240
- result: Result<T, E | unknown>;
241
- };
242
- /**
243
- * Poller configuration.
244
- */
245
- interface PollerOptions {
246
- /** Polling interval in milliseconds */
247
- intervalMs: number;
248
- /** Maximum number of polls (undefined = unlimited) */
249
- maxPolls?: number;
250
- /** Timeout for the entire polling operation */
251
- timeoutMs?: number;
252
- /** Callback when polling starts */
253
- onPollStart?: () => void;
254
- /** Callback when a poll completes */
255
- onPollComplete?: (result: ApprovalStatus) => void;
256
- }
257
- /**
258
- * Create an in-memory approval store for development/testing.
259
- */
260
- declare function createMemoryApprovalStore(): ApprovalStore;
261
- /**
262
- * Create an in-memory workflow state store for development/testing.
263
- */
264
- declare function createMemoryWorkflowStateStore(): WorkflowStateStore;
265
- /**
266
- * HITL orchestrator interface.
267
- */
268
- interface HITLOrchestrator {
269
- /**
270
- * Execute a workflow that may pause for approvals.
271
- * If the workflow pauses, state is automatically saved.
272
- *
273
- * The workflowFactory receives options including onEvent handler which MUST be
274
- * passed to createWorkflow for HITL tracking to work.
275
- */
276
- execute<T, E, TInput>(workflowName: string, workflowFactory: (options: HITLWorkflowFactoryOptions) => Workflow<E, unknown>, workflowFn: (context: {
277
- step: unknown;
278
- deps: unknown;
279
- args: TInput;
280
- }) => Promise<T>, input: TInput, options?: {
281
- runId?: string;
282
- metadata?: Record<string, unknown>;
283
- }): Promise<HITLExecutionResult<T, E>>;
284
- /**
285
- * Resume a paused workflow after approvals have been granted.
286
- */
287
- resume<T, E, TInput>(runId: string, workflowFactory: (options: HITLWorkflowFactoryOptions) => Workflow<E, unknown>, workflowFn: (context: {
288
- step: unknown;
289
- deps: unknown;
290
- args: TInput;
291
- }) => Promise<T>): Promise<HITLExecutionResult<T, E>>;
292
- /**
293
- * Grant an approval and automatically resume any waiting workflows.
294
- */
295
- grantApproval<T>(approvalKey: string, value: T, options?: {
296
- approvedBy?: string;
297
- autoResume?: boolean;
298
- }): Promise<{
299
- grantedAt: number;
300
- resumedWorkflows: string[];
301
- }>;
302
- /**
303
- * Reject an approval.
304
- */
305
- rejectApproval(approvalKey: string, reason: string, options?: {
306
- rejectedBy?: string;
307
- }): Promise<void>;
308
- /**
309
- * Edit an approval (approve with modifications).
310
- * Use this when a human wants to approve but with changes to the proposed value.
311
- * Records both the original and edited values for audit trail.
312
- */
313
- editApproval<T>(approvalKey: string, originalValue: T, editedValue: T, options?: {
314
- editedBy?: string;
315
- }): Promise<{
316
- editedAt: number;
317
- }>;
318
- /**
319
- * Poll for an approval to be granted.
320
- */
321
- pollApproval<T>(approvalKey: string, options?: PollerOptions): Promise<ApprovalStatus<T>>;
322
- /**
323
- * Get the status of a workflow run.
324
- */
325
- getWorkflowStatus(runId: string): Promise<SavedWorkflowState | undefined>;
326
- /**
327
- * List all pending workflows.
328
- */
329
- listPendingWorkflows(workflowName?: string): Promise<string[]>;
330
- /**
331
- * Clean up completed workflows older than the specified age.
332
- */
333
- cleanup(maxAgeMs: number): Promise<number>;
334
- }
335
- /**
336
- * Create a HITL orchestrator for managing approval workflows.
337
- *
338
- * @example
339
- * ```typescript
340
- * const orchestrator = createHITLOrchestrator({
341
- * approvalStore: createMemoryApprovalStore(),
342
- * workflowStateStore: createMemoryWorkflowStateStore(),
343
- * });
344
- *
345
- * // Execute workflow - IMPORTANT: pass onEvent to createWorkflow!
346
- * const result = await orchestrator.execute(
347
- * 'order-approval',
348
- * ({ resumeState, onEvent }) => createWorkflow('order-approval', deps, { resumeState, onEvent }),
349
- * async ({ step, deps, args: input }) => {
350
- * const order = await step(() => deps.createOrder(input));
351
- * const approval = await step(() => deps.requireApproval(order.id), { key: `approval:${order.id}` });
352
- * await step(() => deps.processOrder(order.id));
353
- * return { orderId: order.id, approvedBy: approval.approvedBy };
354
- * },
355
- * { items: [...], total: 100 }
356
- * );
357
- *
358
- * if (result.status === 'paused') {
359
- * console.log(`Workflow paused, waiting for: ${result.pendingApprovals}`);
360
- * }
361
- *
362
- * // Later, grant approval
363
- * await orchestrator.grantApproval(
364
- * `approval:${orderId}`,
365
- * { approvedBy: 'manager@example.com' },
366
- * { autoResume: true }
367
- * );
368
- * ```
369
- */
370
- declare function createHITLOrchestrator(options: HITLOrchestratorOptions): HITLOrchestrator;
371
- /**
372
- * Approval webhook request body.
373
- */
374
- interface ApprovalWebhookRequest {
375
- /** Approval key */
376
- key: string;
377
- /** Action: approve, reject, edit, or cancel */
378
- action: "approve" | "reject" | "edit" | "cancel";
379
- /** Value to inject (for approve) */
380
- value?: unknown;
381
- /** Original value (for edit - what was proposed) */
382
- originalValue?: unknown;
383
- /** Edited value (for edit - what human changed it to) */
384
- editedValue?: unknown;
385
- /** Reason (for reject) */
386
- reason?: string;
387
- /** Who performed this action */
388
- actorId?: string;
389
- }
390
- /**
391
- * Approval webhook response.
392
- */
393
- interface ApprovalWebhookResponse {
394
- success: boolean;
395
- message: string;
396
- data?: {
397
- key: string;
398
- action: string;
399
- timestamp: number;
400
- };
401
- }
402
- /**
403
- * Create a webhook handler for approval actions.
404
- *
405
- * @example
406
- * ```typescript
407
- * const handleApproval = createApprovalWebhookHandler(approvalStore);
408
- *
409
- * // Express
410
- * app.post('/api/approvals', async (req, res) => {
411
- * const result = await handleApproval(req.body);
412
- * res.json(result);
413
- * });
414
- * ```
415
- */
416
- declare function createApprovalWebhookHandler(store: ApprovalStore): (request: ApprovalWebhookRequest) => Promise<ApprovalWebhookResponse>;
417
- /**
418
- * Create an approval checker function for use in approval steps.
419
- * This wraps the approval store with the standard checkApproval interface.
420
- *
421
- * @example
422
- * ```typescript
423
- * const checkApproval = createApprovalChecker(approvalStore);
424
- *
425
- * const requireManagerApproval = createApprovalStep<{ approvedBy: string }>({
426
- * key: 'manager-approval',
427
- * checkApproval: checkApproval('manager-approval'),
428
- * pendingReason: 'Waiting for manager approval',
429
- * });
430
- * ```
431
- */
432
- declare function createApprovalChecker<T>(store: ApprovalStore): (key: string) => () => Promise<{
433
- status: "pending";
434
- } | {
435
- status: "approved";
436
- value: T;
437
- } | {
438
- status: "rejected";
439
- reason: string;
440
- }>;
441
-
442
- export { type ApprovalNeededContext, type ApprovalResolvedContext, type ApprovalStatus, type ApprovalStore, type ApprovalWebhookRequest, type ApprovalWebhookResponse, type HITLExecutionResult, type HITLOrchestrator, type HITLOrchestratorOptions, type HITLWorkflowFactoryOptions, type NotificationChannel, type PollerOptions, type SavedWorkflowState, type WorkflowStateStore, createApprovalChecker, createApprovalWebhookHandler, createHITLOrchestrator, createMemoryApprovalStore, createMemoryWorkflowStateStore };