@upstash/workflow 0.2.7 → 0.2.8

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/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Cuqlx2Cr.mjs';
2
- export { A as AsyncStepFunction, C as CallResponse, q as CallSettings, D as Duration, k as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, o as NotifyStepResponse, P as ParallelCallState, j as PublicServeOptions, g as RawStep, l as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, T as Telemetry, p as WaitEventOptions, m as WaitRequest, n as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, s as WorkflowLogger, r as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Cuqlx2Cr.mjs';
3
- import { Client as Client$1, QstashError } from '@upstash/qstash';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter, c as Step } from './types-B62AnIU3.mjs';
2
+ export { A as AsyncStepFunction, C as CallResponse, r as CallSettings, D as Duration, l as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, p as NotifyStepResponse, P as ParallelCallState, k as PublicServeOptions, m as RequiredExceptFields, j as StepFunction, h as StepTypes, i as SyncStepFunction, T as Telemetry, q as WaitEventOptions, n as WaitRequest, o as WaitStepResponse, f as WorkflowClient, e as WorkflowContext, t as WorkflowLogger, s as WorkflowLoggerOptions, g as WorkflowReceiver, d as WorkflowTool } from './types-B62AnIU3.mjs';
3
+ import { HTTPMethods, State, Client as Client$1, QstashError } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -17,6 +17,233 @@ declare const serve: <TInitialPayload = unknown, TRequest extends Request = Requ
17
17
  handler: (request: TRequest) => Promise<TResponse>;
18
18
  };
19
19
 
20
+ type BaseStepLog = {
21
+ /**
22
+ * id of the step
23
+ */
24
+ stepId?: number;
25
+ /**
26
+ * name of the step
27
+ */
28
+ stepName: string;
29
+ /**
30
+ * type of the step (example: "call", "wait", "invoke")
31
+ */
32
+ stepType: StepType;
33
+ /**
34
+ * call type of the step.
35
+ *
36
+ * in most cases it's `step`. For context.call, it will become `toCallback` and `fromCallback`
37
+ * as the step executes.
38
+ */
39
+ callType: RawStep["callType"];
40
+ /**
41
+ * message id of the step
42
+ */
43
+ messageId: string;
44
+ /**
45
+ * result of the step
46
+ *
47
+ * will be undefined for an unfinished parallel step.
48
+ */
49
+ out: unknown;
50
+ /**
51
+ * number of parallel steps
52
+ *
53
+ * if the step is sequential (non-parallel), will be 1.
54
+ */
55
+ concurrent: number;
56
+ /**
57
+ * state of the step
58
+ */
59
+ state: "STEP_PROGRESS" | "STEP_SUCCESS" | "STEP_RETRY" | "STEP_FAILED";
60
+ /**
61
+ * time when the step was created
62
+ */
63
+ createdAt: number;
64
+ /**
65
+ * headers
66
+ */
67
+ headers: Record<string, string[]>;
68
+ };
69
+ type CallUrlGroup = {
70
+ /**
71
+ * URL called in context.call
72
+ */
73
+ callUrl: string;
74
+ /**
75
+ * Method used in context.call
76
+ */
77
+ callMethod: HTTPMethods;
78
+ /**
79
+ * headers sent in context.call
80
+ */
81
+ callHeaders: Record<string, string[]>;
82
+ /**
83
+ * Body sent in context.call
84
+ */
85
+ callBody: unknown;
86
+ };
87
+ type CallResponseStatusGroup = {
88
+ /**
89
+ * Status code of the context.call response
90
+ */
91
+ callResponseStatus: number;
92
+ /**
93
+ * Response body of the context.call response
94
+ */
95
+ callResponseBody: unknown;
96
+ /**
97
+ * Headers received from the context.call response
98
+ */
99
+ callResponseHeaders: Record<string, string[]>;
100
+ } & CallUrlGroup;
101
+ type InvokedWorkflowGroup = {
102
+ /**
103
+ * id of the workflow run invoked in context.invoke
104
+ */
105
+ invokedWorkflowRunId: string;
106
+ /**
107
+ * URL of the workflow invoked in context.invoke
108
+ */
109
+ invokedWorkflowUrl: string;
110
+ /**
111
+ * Time when the workflow was invoked
112
+ */
113
+ invokedWorkflowCreatedAt: number;
114
+ /**
115
+ * Body sent in context.invoke
116
+ */
117
+ invokedWorkflowRunBody: unknown;
118
+ /**
119
+ * Headers sent in context.invoke
120
+ */
121
+ invokedWorkflowRunHeaders: Record<string, string[]>;
122
+ };
123
+ type WaitEventGroup = {
124
+ /**
125
+ * id of the event waited in context.waitForEvent
126
+ */
127
+ waitEventId: string;
128
+ /**
129
+ * Duration until the time when the event will be triggered due to timeout
130
+ */
131
+ waitTimeoutDuration: string;
132
+ /**
133
+ * Time when the event will be triggered due to timeout
134
+ */
135
+ waitTimeoutDeadline: number;
136
+ /**
137
+ * Whether the event was triggered due to timeout
138
+ */
139
+ waitTimeout: boolean;
140
+ };
141
+ type AsOptional<TType> = TType | {
142
+ [P in keyof TType]?: never;
143
+ };
144
+ type StepLog = BaseStepLog & AsOptional<CallUrlGroup> & AsOptional<CallResponseStatusGroup> & AsOptional<InvokedWorkflowGroup> & AsOptional<WaitEventGroup>;
145
+ type StepLogGroup = {
146
+ /**
147
+ * Log which belongs to a single step
148
+ */
149
+ steps: [StepLog];
150
+ /**
151
+ * Log which belongs to a single step
152
+ */
153
+ type: "sequential";
154
+ } | {
155
+ /**
156
+ * Log which belongs to parallel steps
157
+ */
158
+ steps: StepLog[];
159
+ /**
160
+ * Log which belongs to parallel steps
161
+ */
162
+ type: "parallel";
163
+ } | {
164
+ /**
165
+ * Log which belongs to the next step
166
+ */
167
+ steps: {
168
+ messageId: string;
169
+ state: "STEP_PROGRESS" | "STEP_RETRY" | "STEP_FAILED";
170
+ }[];
171
+ /**
172
+ * Log which belongs to the next step
173
+ */
174
+ type: "next";
175
+ };
176
+ type FailureFunctionLog = {
177
+ /**
178
+ * messageId of the message published for handling the failure
179
+ */
180
+ messageId: string;
181
+ /**
182
+ * URL of the function that handles the failure
183
+ */
184
+ url: string;
185
+ /**
186
+ * State of the message published for failure
187
+ */
188
+ state: State;
189
+ /**
190
+ * Headers received from the step which caused the workflow to fail
191
+ */
192
+ failHeaders: Record<string, string[]>;
193
+ /**
194
+ * Status code of the step which caused the workflow to fail
195
+ */
196
+ failStatus: number;
197
+ /**
198
+ * Response body of the step which caused the workflow to fail
199
+ */
200
+ failResponse: string;
201
+ dlqId: string;
202
+ };
203
+ type WorkflowRunLog = {
204
+ /**
205
+ * Unique identifier for the workflow run
206
+ */
207
+ workflowRunId: string;
208
+ /**
209
+ * URL of the workflow that was run
210
+ */
211
+ workflowUrl: string;
212
+ /**
213
+ * State of the workflow run
214
+ *
215
+ * - RUN_STARTED: Workflow run has started and is in progress
216
+ * - RUN_SUCCESS: Workflow run has completed successfully
217
+ * - RUN_FAILED: Workflow run has failed
218
+ */
219
+ workflowState: "RUN_STARTED" | "RUN_SUCCESS" | "RUN_FAILED" | "RUN_CANCELED";
220
+ /**
221
+ * Time when the workflow run was created
222
+ *
223
+ * in unix milliseconds format
224
+ */
225
+ workflowRunCreatedAt: number;
226
+ /**
227
+ * Time when the workflow run was completed
228
+ *
229
+ * in unix milliseconds format
230
+ */
231
+ workflowRunCompletedAt?: number;
232
+ /**
233
+ * Message published when the workflow fails if failureUrl or failureFunction
234
+ * are set.
235
+ */
236
+ failureFunction?: FailureFunctionLog;
237
+ /**
238
+ *
239
+ */
240
+ steps: StepLogGroup[];
241
+ };
242
+ type WorkflowRunLogs = {
243
+ cursor: string;
244
+ runs: WorkflowRunLog[];
245
+ };
246
+
20
247
  type ClientConfig = ConstructorParameters<typeof Client$1>[0];
21
248
  /**
22
249
  * Workflow client for canceling & notifying workflows and getting waiters of an
@@ -164,6 +391,41 @@ declare class Client {
164
391
  }): Promise<{
165
392
  workflowRunId: string;
166
393
  }>;
394
+ /**
395
+ * Fetches logs for workflow runs.
396
+ *
397
+ * @param workflowRunId - The ID of the workflow run to fetch logs for.
398
+ * @param cursor - The cursor for pagination.
399
+ * @param count - Number of runs to fetch. Default value is 10.
400
+ * @param state - The state of the workflow run.
401
+ * @param workflowUrl - The URL of the workflow. Should be an exact match.
402
+ * @param workflowCreatedAt - The creation time of the workflow. If you have two workflow runs with the same URL, you can use this to filter them.
403
+ * @returns A promise that resolves to either a `WorkflowRunLog` or a `WorkflowRunResponse`.
404
+ *
405
+ * @example
406
+ * Fetch logs for a specific workflow run:
407
+ * ```typescript
408
+ * const { runs } = await client.logs({ workflowRunId: '12345' });
409
+ * const steps = runs[0].steps; // access steps
410
+ * ```
411
+ *
412
+ * @example
413
+ * Fetch logs with pagination:
414
+ * ```typescript
415
+ * const { runs, cursor } = await client.logs();
416
+ * const steps = runs[0].steps // access steps
417
+ *
418
+ * const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
419
+ * ```
420
+ */
421
+ logs(params?: {
422
+ workflowRunId?: WorkflowRunLog["workflowRunId"];
423
+ cursor?: string;
424
+ count?: number;
425
+ state?: WorkflowRunLog["workflowState"];
426
+ workflowUrl?: WorkflowRunLog["workflowUrl"];
427
+ workflowCreatedAt?: WorkflowRunLog["workflowRunCreatedAt"];
428
+ }): Promise<WorkflowRunLogs>;
167
429
  }
168
430
 
169
431
  /**
@@ -192,4 +454,4 @@ declare class WorkflowAbort extends Error {
192
454
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
193
455
  }
194
456
 
195
- export { Client, ExclusiveValidationOptions, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
457
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Cuqlx2Cr.js';
2
- export { A as AsyncStepFunction, C as CallResponse, q as CallSettings, D as Duration, k as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, o as NotifyStepResponse, P as ParallelCallState, j as PublicServeOptions, g as RawStep, l as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, T as Telemetry, p as WaitEventOptions, m as WaitRequest, n as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, s as WorkflowLogger, r as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Cuqlx2Cr.js';
3
- import { Client as Client$1, QstashError } from '@upstash/qstash';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter, c as Step } from './types-B62AnIU3.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, r as CallSettings, D as Duration, l as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, p as NotifyStepResponse, P as ParallelCallState, k as PublicServeOptions, m as RequiredExceptFields, j as StepFunction, h as StepTypes, i as SyncStepFunction, T as Telemetry, q as WaitEventOptions, n as WaitRequest, o as WaitStepResponse, f as WorkflowClient, e as WorkflowContext, t as WorkflowLogger, s as WorkflowLoggerOptions, g as WorkflowReceiver, d as WorkflowTool } from './types-B62AnIU3.js';
3
+ import { HTTPMethods, State, Client as Client$1, QstashError } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -17,6 +17,233 @@ declare const serve: <TInitialPayload = unknown, TRequest extends Request = Requ
17
17
  handler: (request: TRequest) => Promise<TResponse>;
18
18
  };
19
19
 
20
+ type BaseStepLog = {
21
+ /**
22
+ * id of the step
23
+ */
24
+ stepId?: number;
25
+ /**
26
+ * name of the step
27
+ */
28
+ stepName: string;
29
+ /**
30
+ * type of the step (example: "call", "wait", "invoke")
31
+ */
32
+ stepType: StepType;
33
+ /**
34
+ * call type of the step.
35
+ *
36
+ * in most cases it's `step`. For context.call, it will become `toCallback` and `fromCallback`
37
+ * as the step executes.
38
+ */
39
+ callType: RawStep["callType"];
40
+ /**
41
+ * message id of the step
42
+ */
43
+ messageId: string;
44
+ /**
45
+ * result of the step
46
+ *
47
+ * will be undefined for an unfinished parallel step.
48
+ */
49
+ out: unknown;
50
+ /**
51
+ * number of parallel steps
52
+ *
53
+ * if the step is sequential (non-parallel), will be 1.
54
+ */
55
+ concurrent: number;
56
+ /**
57
+ * state of the step
58
+ */
59
+ state: "STEP_PROGRESS" | "STEP_SUCCESS" | "STEP_RETRY" | "STEP_FAILED";
60
+ /**
61
+ * time when the step was created
62
+ */
63
+ createdAt: number;
64
+ /**
65
+ * headers
66
+ */
67
+ headers: Record<string, string[]>;
68
+ };
69
+ type CallUrlGroup = {
70
+ /**
71
+ * URL called in context.call
72
+ */
73
+ callUrl: string;
74
+ /**
75
+ * Method used in context.call
76
+ */
77
+ callMethod: HTTPMethods;
78
+ /**
79
+ * headers sent in context.call
80
+ */
81
+ callHeaders: Record<string, string[]>;
82
+ /**
83
+ * Body sent in context.call
84
+ */
85
+ callBody: unknown;
86
+ };
87
+ type CallResponseStatusGroup = {
88
+ /**
89
+ * Status code of the context.call response
90
+ */
91
+ callResponseStatus: number;
92
+ /**
93
+ * Response body of the context.call response
94
+ */
95
+ callResponseBody: unknown;
96
+ /**
97
+ * Headers received from the context.call response
98
+ */
99
+ callResponseHeaders: Record<string, string[]>;
100
+ } & CallUrlGroup;
101
+ type InvokedWorkflowGroup = {
102
+ /**
103
+ * id of the workflow run invoked in context.invoke
104
+ */
105
+ invokedWorkflowRunId: string;
106
+ /**
107
+ * URL of the workflow invoked in context.invoke
108
+ */
109
+ invokedWorkflowUrl: string;
110
+ /**
111
+ * Time when the workflow was invoked
112
+ */
113
+ invokedWorkflowCreatedAt: number;
114
+ /**
115
+ * Body sent in context.invoke
116
+ */
117
+ invokedWorkflowRunBody: unknown;
118
+ /**
119
+ * Headers sent in context.invoke
120
+ */
121
+ invokedWorkflowRunHeaders: Record<string, string[]>;
122
+ };
123
+ type WaitEventGroup = {
124
+ /**
125
+ * id of the event waited in context.waitForEvent
126
+ */
127
+ waitEventId: string;
128
+ /**
129
+ * Duration until the time when the event will be triggered due to timeout
130
+ */
131
+ waitTimeoutDuration: string;
132
+ /**
133
+ * Time when the event will be triggered due to timeout
134
+ */
135
+ waitTimeoutDeadline: number;
136
+ /**
137
+ * Whether the event was triggered due to timeout
138
+ */
139
+ waitTimeout: boolean;
140
+ };
141
+ type AsOptional<TType> = TType | {
142
+ [P in keyof TType]?: never;
143
+ };
144
+ type StepLog = BaseStepLog & AsOptional<CallUrlGroup> & AsOptional<CallResponseStatusGroup> & AsOptional<InvokedWorkflowGroup> & AsOptional<WaitEventGroup>;
145
+ type StepLogGroup = {
146
+ /**
147
+ * Log which belongs to a single step
148
+ */
149
+ steps: [StepLog];
150
+ /**
151
+ * Log which belongs to a single step
152
+ */
153
+ type: "sequential";
154
+ } | {
155
+ /**
156
+ * Log which belongs to parallel steps
157
+ */
158
+ steps: StepLog[];
159
+ /**
160
+ * Log which belongs to parallel steps
161
+ */
162
+ type: "parallel";
163
+ } | {
164
+ /**
165
+ * Log which belongs to the next step
166
+ */
167
+ steps: {
168
+ messageId: string;
169
+ state: "STEP_PROGRESS" | "STEP_RETRY" | "STEP_FAILED";
170
+ }[];
171
+ /**
172
+ * Log which belongs to the next step
173
+ */
174
+ type: "next";
175
+ };
176
+ type FailureFunctionLog = {
177
+ /**
178
+ * messageId of the message published for handling the failure
179
+ */
180
+ messageId: string;
181
+ /**
182
+ * URL of the function that handles the failure
183
+ */
184
+ url: string;
185
+ /**
186
+ * State of the message published for failure
187
+ */
188
+ state: State;
189
+ /**
190
+ * Headers received from the step which caused the workflow to fail
191
+ */
192
+ failHeaders: Record<string, string[]>;
193
+ /**
194
+ * Status code of the step which caused the workflow to fail
195
+ */
196
+ failStatus: number;
197
+ /**
198
+ * Response body of the step which caused the workflow to fail
199
+ */
200
+ failResponse: string;
201
+ dlqId: string;
202
+ };
203
+ type WorkflowRunLog = {
204
+ /**
205
+ * Unique identifier for the workflow run
206
+ */
207
+ workflowRunId: string;
208
+ /**
209
+ * URL of the workflow that was run
210
+ */
211
+ workflowUrl: string;
212
+ /**
213
+ * State of the workflow run
214
+ *
215
+ * - RUN_STARTED: Workflow run has started and is in progress
216
+ * - RUN_SUCCESS: Workflow run has completed successfully
217
+ * - RUN_FAILED: Workflow run has failed
218
+ */
219
+ workflowState: "RUN_STARTED" | "RUN_SUCCESS" | "RUN_FAILED" | "RUN_CANCELED";
220
+ /**
221
+ * Time when the workflow run was created
222
+ *
223
+ * in unix milliseconds format
224
+ */
225
+ workflowRunCreatedAt: number;
226
+ /**
227
+ * Time when the workflow run was completed
228
+ *
229
+ * in unix milliseconds format
230
+ */
231
+ workflowRunCompletedAt?: number;
232
+ /**
233
+ * Message published when the workflow fails if failureUrl or failureFunction
234
+ * are set.
235
+ */
236
+ failureFunction?: FailureFunctionLog;
237
+ /**
238
+ *
239
+ */
240
+ steps: StepLogGroup[];
241
+ };
242
+ type WorkflowRunLogs = {
243
+ cursor: string;
244
+ runs: WorkflowRunLog[];
245
+ };
246
+
20
247
  type ClientConfig = ConstructorParameters<typeof Client$1>[0];
21
248
  /**
22
249
  * Workflow client for canceling & notifying workflows and getting waiters of an
@@ -164,6 +391,41 @@ declare class Client {
164
391
  }): Promise<{
165
392
  workflowRunId: string;
166
393
  }>;
394
+ /**
395
+ * Fetches logs for workflow runs.
396
+ *
397
+ * @param workflowRunId - The ID of the workflow run to fetch logs for.
398
+ * @param cursor - The cursor for pagination.
399
+ * @param count - Number of runs to fetch. Default value is 10.
400
+ * @param state - The state of the workflow run.
401
+ * @param workflowUrl - The URL of the workflow. Should be an exact match.
402
+ * @param workflowCreatedAt - The creation time of the workflow. If you have two workflow runs with the same URL, you can use this to filter them.
403
+ * @returns A promise that resolves to either a `WorkflowRunLog` or a `WorkflowRunResponse`.
404
+ *
405
+ * @example
406
+ * Fetch logs for a specific workflow run:
407
+ * ```typescript
408
+ * const { runs } = await client.logs({ workflowRunId: '12345' });
409
+ * const steps = runs[0].steps; // access steps
410
+ * ```
411
+ *
412
+ * @example
413
+ * Fetch logs with pagination:
414
+ * ```typescript
415
+ * const { runs, cursor } = await client.logs();
416
+ * const steps = runs[0].steps // access steps
417
+ *
418
+ * const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
419
+ * ```
420
+ */
421
+ logs(params?: {
422
+ workflowRunId?: WorkflowRunLog["workflowRunId"];
423
+ cursor?: string;
424
+ count?: number;
425
+ state?: WorkflowRunLog["workflowState"];
426
+ workflowUrl?: WorkflowRunLog["workflowUrl"];
427
+ workflowCreatedAt?: WorkflowRunLog["workflowRunCreatedAt"];
428
+ }): Promise<WorkflowRunLogs>;
167
429
  }
168
430
 
169
431
  /**
@@ -192,4 +454,4 @@ declare class WorkflowAbort extends Error {
192
454
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
193
455
  }
194
456
 
195
- export { Client, ExclusiveValidationOptions, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
457
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };