@upstash/workflow 0.2.8 → 0.2.10-hono-generics

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/hono.mjs CHANGED
@@ -1,30 +1,48 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
- serveBase
4
- } from "./chunk-BPUSHNSD.mjs";
3
+ serveBase,
4
+ serveManyBase
5
+ } from "./chunk-IPXJZU3K.mjs";
5
6
 
6
7
  // platforms/hono.ts
8
+ var telemetry = {
9
+ sdk: SDK_TELEMETRY,
10
+ framework: "hono"
11
+ };
7
12
  var serve = (routeFunction, options) => {
8
13
  const handler = async (context) => {
9
14
  const environment = context.env;
10
15
  const request = context.req.raw;
11
- const { handler: serveHandler } = serveBase(
12
- routeFunction,
13
- {
14
- sdk: SDK_TELEMETRY,
15
- framework: "hono"
16
- },
17
- {
18
- // when hono is used without cf workers, it sends a DebugHTTPServer
19
- // object in `context.env`. don't pass env if this is the case:
20
- env: "QSTASH_TOKEN" in environment ? environment : void 0,
21
- ...options
22
- }
23
- );
16
+ const { handler: serveHandler } = serveBase(routeFunction, telemetry, {
17
+ // when hono is used without cf workers, it sends a DebugHTTPServer
18
+ // object in `context.env`. don't pass env if this is the case:
19
+ env: "QSTASH_TOKEN" in environment ? environment : void 0,
20
+ ...options
21
+ });
24
22
  return await serveHandler(request);
25
23
  };
26
24
  return handler;
27
25
  };
26
+ var createWorkflow = (...params) => {
27
+ const [routeFunction, options = {}] = params;
28
+ return {
29
+ routeFunction,
30
+ options,
31
+ workflowId: void 0
32
+ };
33
+ };
34
+ var serveMany = (workflows, options) => {
35
+ return serveManyBase({
36
+ workflows,
37
+ getUrl(params) {
38
+ return params.req.url;
39
+ },
40
+ serveMethod: (...params) => serve(...params),
41
+ options
42
+ }).handler;
43
+ };
28
44
  export {
29
- serve
45
+ createWorkflow,
46
+ serve,
47
+ serveMany
30
48
  };
package/index.d.mts CHANGED
@@ -1,6 +1,6 @@
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';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter, c as Step } from './types-CYhDXnf8.mjs';
2
+ export { A as AsyncStepFunction, C as CallResponse, r as CallSettings, D as Duration, l as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, t as InvokableWorkflow, s as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, u as LogLevel, p as NotifyStepResponse, P as ParallelCallState, k as PublicServeOptions, m as RequiredExceptFields, j as StepFunction, h as StepTypes, i as SyncStepFunction, q as WaitEventOptions, n as WaitRequest, o as WaitStepResponse, f as WorkflowClient, e as WorkflowContext, w as WorkflowLogger, v as WorkflowLoggerOptions, g as WorkflowReceiver, d as WorkflowTool } from './types-CYhDXnf8.mjs';
3
+ import { HTTPMethods, State, FlowControl, Client as Client$1, QstashError } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -9,13 +9,26 @@ import '@ai-sdk/openai';
9
9
  * Creates an async method that handles incoming requests and runs the provided
10
10
  * route function as a workflow.
11
11
  *
12
+ * Not exported in the package. Instead, used in framework specific serve implementations.
13
+ *
14
+ * Only difference from regular serve is the `useJSONContent` parameter.
15
+ *
12
16
  * @param routeFunction - A function that uses WorkflowContext as a parameter and runs a workflow.
13
17
  * @param options - Options including the client, onFinish callback, and initialPayloadParser.
14
18
  * @returns An async method that consumes incoming requests and runs the workflow.
15
19
  */
16
- declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>) => {
20
+ declare const serveBase: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, telemetry?: Telemetry, options?: WorkflowServeOptions<TResponse, TInitialPayload>) => {
17
21
  handler: (request: TRequest) => Promise<TResponse>;
18
22
  };
23
+ /**
24
+ * Creates an async method that handles incoming requests and runs the provided
25
+ * route function as a workflow.
26
+ *
27
+ * @param routeFunction - A function that uses WorkflowContext as a parameter and runs a workflow.
28
+ * @param options - Options including the client, onFinish callback, and initialPayloadParser.
29
+ * @returns An async method that consumes incoming requests and runs the workflow.
30
+ */
31
+ declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>) => ReturnType<typeof serveBase<TInitialPayload, TRequest, TResponse, TResult>>;
19
32
 
20
33
  type BaseStepLog = {
21
34
  /**
@@ -81,7 +94,7 @@ type CallUrlGroup = {
81
94
  callHeaders: Record<string, string[]>;
82
95
  /**
83
96
  * Body sent in context.call
84
- */
97
+ */
85
98
  callBody: unknown;
86
99
  };
87
100
  type CallResponseStatusGroup = {
@@ -382,42 +395,43 @@ declare class Client {
382
395
  * the workflow, `retries` option of the `serve` will be used.
383
396
  * @returns workflow run id
384
397
  */
385
- trigger({ url, body, headers, workflowRunId, retries, }: {
398
+ trigger({ url, body, headers, workflowRunId, retries, flowControl, }: {
386
399
  url: string;
387
400
  body?: unknown;
388
401
  headers?: Record<string, string>;
389
402
  workflowRunId?: string;
390
403
  retries?: number;
404
+ flowControl?: FlowControl;
391
405
  }): Promise<{
392
406
  workflowRunId: string;
393
407
  }>;
394
408
  /**
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
- */
409
+ * Fetches logs for workflow runs.
410
+ *
411
+ * @param workflowRunId - The ID of the workflow run to fetch logs for.
412
+ * @param cursor - The cursor for pagination.
413
+ * @param count - Number of runs to fetch. Default value is 10.
414
+ * @param state - The state of the workflow run.
415
+ * @param workflowUrl - The URL of the workflow. Should be an exact match.
416
+ * @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.
417
+ * @returns A promise that resolves to either a `WorkflowRunLog` or a `WorkflowRunResponse`.
418
+ *
419
+ * @example
420
+ * Fetch logs for a specific workflow run:
421
+ * ```typescript
422
+ * const { runs } = await client.logs({ workflowRunId: '12345' });
423
+ * const steps = runs[0].steps; // access steps
424
+ * ```
425
+ *
426
+ * @example
427
+ * Fetch logs with pagination:
428
+ * ```typescript
429
+ * const { runs, cursor } = await client.logs();
430
+ * const steps = runs[0].steps // access steps
431
+ *
432
+ * const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
433
+ * ```
434
+ */
421
435
  logs(params?: {
422
436
  workflowRunId?: WorkflowRunLog["workflowRunId"];
423
437
  cursor?: string;
@@ -454,4 +468,4 @@ declare class WorkflowAbort extends Error {
454
468
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
455
469
  }
456
470
 
457
- export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
471
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, 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, 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';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter, c as Step } from './types-CYhDXnf8.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, r as CallSettings, D as Duration, l as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, t as InvokableWorkflow, s as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, u as LogLevel, p as NotifyStepResponse, P as ParallelCallState, k as PublicServeOptions, m as RequiredExceptFields, j as StepFunction, h as StepTypes, i as SyncStepFunction, q as WaitEventOptions, n as WaitRequest, o as WaitStepResponse, f as WorkflowClient, e as WorkflowContext, w as WorkflowLogger, v as WorkflowLoggerOptions, g as WorkflowReceiver, d as WorkflowTool } from './types-CYhDXnf8.js';
3
+ import { HTTPMethods, State, FlowControl, Client as Client$1, QstashError } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -9,13 +9,26 @@ import '@ai-sdk/openai';
9
9
  * Creates an async method that handles incoming requests and runs the provided
10
10
  * route function as a workflow.
11
11
  *
12
+ * Not exported in the package. Instead, used in framework specific serve implementations.
13
+ *
14
+ * Only difference from regular serve is the `useJSONContent` parameter.
15
+ *
12
16
  * @param routeFunction - A function that uses WorkflowContext as a parameter and runs a workflow.
13
17
  * @param options - Options including the client, onFinish callback, and initialPayloadParser.
14
18
  * @returns An async method that consumes incoming requests and runs the workflow.
15
19
  */
16
- declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>) => {
20
+ declare const serveBase: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, telemetry?: Telemetry, options?: WorkflowServeOptions<TResponse, TInitialPayload>) => {
17
21
  handler: (request: TRequest) => Promise<TResponse>;
18
22
  };
23
+ /**
24
+ * Creates an async method that handles incoming requests and runs the provided
25
+ * route function as a workflow.
26
+ *
27
+ * @param routeFunction - A function that uses WorkflowContext as a parameter and runs a workflow.
28
+ * @param options - Options including the client, onFinish callback, and initialPayloadParser.
29
+ * @returns An async method that consumes incoming requests and runs the workflow.
30
+ */
31
+ declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>) => ReturnType<typeof serveBase<TInitialPayload, TRequest, TResponse, TResult>>;
19
32
 
20
33
  type BaseStepLog = {
21
34
  /**
@@ -81,7 +94,7 @@ type CallUrlGroup = {
81
94
  callHeaders: Record<string, string[]>;
82
95
  /**
83
96
  * Body sent in context.call
84
- */
97
+ */
85
98
  callBody: unknown;
86
99
  };
87
100
  type CallResponseStatusGroup = {
@@ -382,42 +395,43 @@ declare class Client {
382
395
  * the workflow, `retries` option of the `serve` will be used.
383
396
  * @returns workflow run id
384
397
  */
385
- trigger({ url, body, headers, workflowRunId, retries, }: {
398
+ trigger({ url, body, headers, workflowRunId, retries, flowControl, }: {
386
399
  url: string;
387
400
  body?: unknown;
388
401
  headers?: Record<string, string>;
389
402
  workflowRunId?: string;
390
403
  retries?: number;
404
+ flowControl?: FlowControl;
391
405
  }): Promise<{
392
406
  workflowRunId: string;
393
407
  }>;
394
408
  /**
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
- */
409
+ * Fetches logs for workflow runs.
410
+ *
411
+ * @param workflowRunId - The ID of the workflow run to fetch logs for.
412
+ * @param cursor - The cursor for pagination.
413
+ * @param count - Number of runs to fetch. Default value is 10.
414
+ * @param state - The state of the workflow run.
415
+ * @param workflowUrl - The URL of the workflow. Should be an exact match.
416
+ * @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.
417
+ * @returns A promise that resolves to either a `WorkflowRunLog` or a `WorkflowRunResponse`.
418
+ *
419
+ * @example
420
+ * Fetch logs for a specific workflow run:
421
+ * ```typescript
422
+ * const { runs } = await client.logs({ workflowRunId: '12345' });
423
+ * const steps = runs[0].steps; // access steps
424
+ * ```
425
+ *
426
+ * @example
427
+ * Fetch logs with pagination:
428
+ * ```typescript
429
+ * const { runs, cursor } = await client.logs();
430
+ * const steps = runs[0].steps // access steps
431
+ *
432
+ * const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
433
+ * ```
434
+ */
421
435
  logs(params?: {
422
436
  workflowRunId?: WorkflowRunLog["workflowRunId"];
423
437
  cursor?: string;
@@ -454,4 +468,4 @@ declare class WorkflowAbort extends Error {
454
468
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
455
469
  }
456
470
 
457
- export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
471
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };