@upstash/workflow 0.2.14 → 0.2.15

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/svelte.js CHANGED
@@ -91,7 +91,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
91
91
  var DEFAULT_CONTENT_TYPE = "application/json";
92
92
  var NO_CONCURRENCY = 1;
93
93
  var DEFAULT_RETRIES = 3;
94
- var VERSION = "v0.2.14";
94
+ var VERSION = "v0.2.15";
95
95
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
96
96
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
97
97
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -129,6 +129,16 @@ var WorkflowAbort = class extends Error {
129
129
  this.cancelWorkflow = cancelWorkflow;
130
130
  }
131
131
  };
132
+ var WorkflowNonRetryableError = class extends WorkflowAbort {
133
+ /**
134
+ * @param message error message to be displayed
135
+ */
136
+ constructor(message) {
137
+ super("fail", void 0, false);
138
+ this.name = "WorkflowNonRetryableError";
139
+ if (message) this.message = message;
140
+ }
141
+ };
132
142
  var formatWorkflowError = (error) => {
133
143
  return error instanceof Error ? {
134
144
  error: error.name,
@@ -693,6 +703,8 @@ var triggerRouteFunction = async ({
693
703
  return ok("workflow-was-finished");
694
704
  } else if (!(error_ instanceof WorkflowAbort)) {
695
705
  return err(error_);
706
+ } else if (error_ instanceof WorkflowNonRetryableError) {
707
+ return ok(error_);
696
708
  } else if (error_.cancelWorkflow) {
697
709
  await onCancel();
698
710
  return ok("workflow-finished");
@@ -854,7 +866,7 @@ ${atob(callbackMessage.body ?? "")}`
854
866
  var getTelemetryHeaders = (telemetry2) => {
855
867
  return {
856
868
  [TELEMETRY_HEADER_SDK]: telemetry2.sdk,
857
- [TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework,
869
+ [TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework ?? "unknown",
858
870
  [TELEMETRY_HEADER_RUNTIME]: telemetry2.runtime ?? "unknown"
859
871
  };
860
872
  };
@@ -2966,10 +2978,10 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2966
2978
  throw new WorkflowAbort(_DisabledWorkflowContext.disabledMessage);
2967
2979
  }
2968
2980
  /**
2969
- * overwrite cancel method to do nothing
2981
+ * overwrite cancel method to throw WorkflowAbort with the disabledMessage
2970
2982
  */
2971
2983
  async cancel() {
2972
- return;
2984
+ throw new WorkflowAbort(_DisabledWorkflowContext.disabledMessage);
2973
2985
  }
2974
2986
  /**
2975
2987
  * copies the passed context to create a DisabledWorkflowContext. Then, runs the
@@ -3001,7 +3013,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
3001
3013
  try {
3002
3014
  await routeFunction(disabledContext);
3003
3015
  } catch (error) {
3004
- if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage) {
3016
+ if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage || error instanceof WorkflowNonRetryableError) {
3005
3017
  return ok("step-found");
3006
3018
  }
3007
3019
  return err(error);
@@ -3222,6 +3234,13 @@ var processOptions = (options) => {
3222
3234
  status: 400
3223
3235
  }
3224
3236
  );
3237
+ } else if (finishCondition instanceof WorkflowNonRetryableError) {
3238
+ return new Response(JSON.stringify(formatWorkflowError(finishCondition)), {
3239
+ headers: {
3240
+ "Upstash-NonRetryable-Error": "true"
3241
+ },
3242
+ status: 489
3243
+ });
3225
3244
  }
3226
3245
  return new Response(JSON.stringify({ workflowRunId }), {
3227
3246
  status: 200
@@ -3414,6 +3433,9 @@ var serveBase = (routeFunction, telemetry2, options) => {
3414
3433
  },
3415
3434
  debug
3416
3435
  });
3436
+ if (result.isOk() && result.value instanceof WorkflowNonRetryableError) {
3437
+ return onStepFinish(workflowRunId, result.value);
3438
+ }
3417
3439
  if (result.isErr()) {
3418
3440
  await debug?.log("ERROR", "ERROR", { error: result.error.message });
3419
3441
  throw result.error;
package/svelte.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-RMS2NQ3K.mjs";
5
+ } from "./chunk-AC5CQCN3.mjs";
6
6
 
7
7
  // platforms/svelte.ts
8
8
  var telemetry = {
@@ -1,9 +1,44 @@
1
- import { PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
1
+ import { QstashError, PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
2
  import { ZodType, z } from 'zod';
3
3
  import * as ai from 'ai';
4
4
  import { CoreTool, generateText } from 'ai';
5
5
  import { createOpenAI } from '@ai-sdk/openai';
6
6
 
7
+ /**
8
+ * Error raised during Workflow execution
9
+ */
10
+ declare class WorkflowError extends QstashError {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * Raised when the workflow executes a function successfully
15
+ * and aborts to end the execution
16
+ */
17
+ declare class WorkflowAbort extends Error {
18
+ stepInfo?: Step;
19
+ stepName: string;
20
+ /**
21
+ * whether workflow is to be canceled on abort
22
+ */
23
+ cancelWorkflow: boolean;
24
+ /**
25
+ *
26
+ * @param stepName name of the aborting step
27
+ * @param stepInfo step information
28
+ * @param cancelWorkflow
29
+ */
30
+ constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
31
+ }
32
+ /**
33
+ * Raised when the workflow is failed due to a non-retryable error
34
+ */
35
+ declare class WorkflowNonRetryableError extends WorkflowAbort {
36
+ /**
37
+ * @param message error message to be displayed
38
+ */
39
+ constructor(message?: string);
40
+ }
41
+
7
42
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
8
43
  type LogLevel = (typeof LOG_LEVELS)[number];
9
44
  type ChatLogEntry = {
@@ -1133,7 +1168,7 @@ type AsyncStepFunction<TResult> = () => Promise<TResult>;
1133
1168
  type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
1134
1169
  type ParallelCallState = "first" | "partial" | "discard" | "last";
1135
1170
  type RouteFunction<TInitialPayload, TResult = unknown> = (context: WorkflowContext<TInitialPayload>) => Promise<TResult>;
1136
- type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended";
1171
+ type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended" | WorkflowNonRetryableError;
1137
1172
  type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = ValidationOptions<TInitialPayload> & {
1138
1173
  /**
1139
1174
  * QStash client
@@ -1260,7 +1295,7 @@ type Telemetry = {
1260
1295
  /**
1261
1296
  * platform (such as nextjs/cloudflare)
1262
1297
  */
1263
- framework: string;
1298
+ framework?: string;
1264
1299
  /**
1265
1300
  * node version
1266
1301
  */
@@ -1470,4 +1505,4 @@ type InvokableWorkflow<TInitialPayload, TResult> = {
1470
1505
  workflowId?: string;
1471
1506
  };
1472
1507
 
1473
- export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, type Step as c, WorkflowTool as d, WorkflowContext as e, type WorkflowClient as f, type WorkflowReceiver as g, StepTypes as h, type SyncStepFunction as i, type StepFunction as j, type PublicServeOptions as k, type FailureFunctionPayload as l, type RequiredExceptFields as m, type WaitRequest as n, type WaitStepResponse as o, type NotifyStepResponse as p, type WaitEventOptions as q, type CallSettings as r, type InvokeStepResponse as s, type InvokableWorkflow as t, type LogLevel as u, type WorkflowLoggerOptions as v, WorkflowLogger as w };
1508
+ export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, WorkflowError as c, WorkflowAbort as d, WorkflowNonRetryableError as e, WorkflowTool as f, WorkflowContext as g, type WorkflowClient as h, type WorkflowReceiver as i, StepTypes as j, type Step as k, type SyncStepFunction as l, type StepFunction as m, type PublicServeOptions as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type WaitEventOptions as t, type CallSettings as u, type InvokeStepResponse as v, type InvokableWorkflow as w, type LogLevel as x, type WorkflowLoggerOptions as y, WorkflowLogger as z };
@@ -1,9 +1,44 @@
1
- import { PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
1
+ import { QstashError, PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
2
  import { ZodType, z } from 'zod';
3
3
  import * as ai from 'ai';
4
4
  import { CoreTool, generateText } from 'ai';
5
5
  import { createOpenAI } from '@ai-sdk/openai';
6
6
 
7
+ /**
8
+ * Error raised during Workflow execution
9
+ */
10
+ declare class WorkflowError extends QstashError {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * Raised when the workflow executes a function successfully
15
+ * and aborts to end the execution
16
+ */
17
+ declare class WorkflowAbort extends Error {
18
+ stepInfo?: Step;
19
+ stepName: string;
20
+ /**
21
+ * whether workflow is to be canceled on abort
22
+ */
23
+ cancelWorkflow: boolean;
24
+ /**
25
+ *
26
+ * @param stepName name of the aborting step
27
+ * @param stepInfo step information
28
+ * @param cancelWorkflow
29
+ */
30
+ constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
31
+ }
32
+ /**
33
+ * Raised when the workflow is failed due to a non-retryable error
34
+ */
35
+ declare class WorkflowNonRetryableError extends WorkflowAbort {
36
+ /**
37
+ * @param message error message to be displayed
38
+ */
39
+ constructor(message?: string);
40
+ }
41
+
7
42
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
8
43
  type LogLevel = (typeof LOG_LEVELS)[number];
9
44
  type ChatLogEntry = {
@@ -1133,7 +1168,7 @@ type AsyncStepFunction<TResult> = () => Promise<TResult>;
1133
1168
  type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
1134
1169
  type ParallelCallState = "first" | "partial" | "discard" | "last";
1135
1170
  type RouteFunction<TInitialPayload, TResult = unknown> = (context: WorkflowContext<TInitialPayload>) => Promise<TResult>;
1136
- type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended";
1171
+ type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended" | WorkflowNonRetryableError;
1137
1172
  type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = ValidationOptions<TInitialPayload> & {
1138
1173
  /**
1139
1174
  * QStash client
@@ -1260,7 +1295,7 @@ type Telemetry = {
1260
1295
  /**
1261
1296
  * platform (such as nextjs/cloudflare)
1262
1297
  */
1263
- framework: string;
1298
+ framework?: string;
1264
1299
  /**
1265
1300
  * node version
1266
1301
  */
@@ -1470,4 +1505,4 @@ type InvokableWorkflow<TInitialPayload, TResult> = {
1470
1505
  workflowId?: string;
1471
1506
  };
1472
1507
 
1473
- export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, type Step as c, WorkflowTool as d, WorkflowContext as e, type WorkflowClient as f, type WorkflowReceiver as g, StepTypes as h, type SyncStepFunction as i, type StepFunction as j, type PublicServeOptions as k, type FailureFunctionPayload as l, type RequiredExceptFields as m, type WaitRequest as n, type WaitStepResponse as o, type NotifyStepResponse as p, type WaitEventOptions as q, type CallSettings as r, type InvokeStepResponse as s, type InvokableWorkflow as t, type LogLevel as u, type WorkflowLoggerOptions as v, WorkflowLogger as w };
1508
+ export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, WorkflowError as c, WorkflowAbort as d, WorkflowNonRetryableError as e, WorkflowTool as f, WorkflowContext as g, type WorkflowClient as h, type WorkflowReceiver as i, StepTypes as j, type Step as k, type SyncStepFunction as l, type StepFunction as m, type PublicServeOptions as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type WaitEventOptions as t, type CallSettings as u, type InvokeStepResponse as v, type InvokableWorkflow as w, type LogLevel as x, type WorkflowLoggerOptions as y, WorkflowLogger as z };