@upstash/workflow 0.2.8-rc-invoke → 0.2.9

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.mjs CHANGED
@@ -1,11 +1,8 @@
1
- import {
2
- createInvokeCallback,
3
- serveManyBase
4
- } from "./chunk-LCZMBGEM.mjs";
5
1
  import {
6
2
  SDK_TELEMETRY,
7
- serveBase
8
- } from "./chunk-IWAW7GIG.mjs";
3
+ serveBase,
4
+ serveManyBase
5
+ } from "./chunk-IPXJZU3K.mjs";
9
6
 
10
7
  // platforms/svelte.ts
11
8
  var telemetry = {
@@ -23,21 +20,22 @@ var serve = (routeFunction, options) => {
23
20
  return { POST: handler };
24
21
  };
25
22
  var createWorkflow = (...params) => {
26
- const { POST } = serve(...params);
23
+ const [routeFunction, options = {}] = params;
27
24
  return {
28
- callback: createInvokeCallback(telemetry),
29
- handler: POST,
30
- workflowId: void 0
25
+ workflowId: void 0,
26
+ routeFunction,
27
+ options
31
28
  };
32
29
  };
33
- var serveMany = (workflows) => {
30
+ var serveMany = (workflows, options) => {
34
31
  return {
35
32
  POST: serveManyBase({
36
33
  workflows,
37
- getWorkflowId(params) {
38
- const components = params.url.toString().split("/");
39
- return components[components.length - 1];
40
- }
34
+ getUrl(params) {
35
+ return params.url.toString();
36
+ },
37
+ options,
38
+ serveMethod: (...params) => serve(...params).POST
41
39
  }).handler
42
40
  };
43
41
  };
@@ -1,5 +1,5 @@
1
- import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
- import { z } from 'zod';
1
+ import { PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
+ import { ZodType, z } from 'zod';
3
3
  import * as ai from 'ai';
4
4
  import { CoreTool, generateText } from 'ai';
5
5
  import * as _ai_sdk_openai from '@ai-sdk/openai';
@@ -33,11 +33,6 @@ declare abstract class BaseLazyStep<TResult = unknown> {
33
33
  */
34
34
  abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
35
35
  }
36
- type LazyInvokeStepParams<TInitiaPayload, TResult> = {
37
- workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult, unknown[]>, "callback" | "workflowId">;
38
- body: TInitiaPayload;
39
- workflowRunId?: string;
40
- } & Pick<CallSettings, "retries" | "headers">;
41
36
 
42
37
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
43
38
  type LogLevel = (typeof LOG_LEVELS)[number];
@@ -72,11 +67,12 @@ declare class AutoExecutor {
72
67
  private readonly nonPlanStepCount;
73
68
  private readonly steps;
74
69
  private indexInCurrentList;
70
+ private invokeCount;
75
71
  private telemetry?;
76
72
  stepCount: number;
77
73
  planStepCount: number;
78
74
  protected executingStep: string | false;
79
- constructor(context: WorkflowContext, steps: Step[], telemetry?: Telemetry, debug?: WorkflowLogger);
75
+ constructor(context: WorkflowContext, steps: Step[], telemetry?: Telemetry, invokeCount?: number, debug?: WorkflowLogger);
80
76
  /**
81
77
  * Adds the step function to the list of step functions to run in
82
78
  * parallel. After adding the function, defers the execution, so
@@ -408,6 +404,60 @@ declare const createWorkflowOpenAI: (context: WorkflowContext, config?: {
408
404
  baseURL?: string;
409
405
  apiKey?: string;
410
406
  }) => _ai_sdk_openai.OpenAIProvider;
407
+ declare class WorkflowTool<TSchema extends ZodType = ZodType> implements LangchainTool {
408
+ /**
409
+ * description of the tool
410
+ */
411
+ readonly description: string;
412
+ /**
413
+ * schema of the tool
414
+ */
415
+ readonly schema: TSchema;
416
+ /**
417
+ * function to invoke the tool
418
+ */
419
+ readonly invoke: (params: z.infer<TSchema>) => any;
420
+ /**
421
+ * whether the invoke method of the tool is to be wrapped with `context.run`
422
+ */
423
+ readonly executeAsStep: boolean;
424
+ /**
425
+ *
426
+ * @param description description of the tool
427
+ * @param schema schema of the tool
428
+ * @param invoke function to invoke the tool
429
+ * @param executeAsStep whether the invoke method of the tool is to be wrapped with `context.run`
430
+ */
431
+ constructor(params: {
432
+ /**
433
+ * description of the tool
434
+ */
435
+ description: string;
436
+ /**
437
+ * schema of the tool
438
+ */
439
+ schema: TSchema;
440
+ /**
441
+ * invoke function to invoke the tool
442
+ */
443
+ invoke: (params: z.infer<TSchema>) => any;
444
+ /**
445
+ * whether the invoke method is to be wrapped with `context.run`.
446
+ *
447
+ * When you pass a LangChain, AI SDK tool or a WorkflowTool to your agent,
448
+ * the execute/invoke method of the tool is wrapped with `context.run` by default.
449
+ *
450
+ * This option allows you to disable this behavior.
451
+ *
452
+ * You may want to disable wrapping with context.run if you want to run context.run,
453
+ * context.call or any other workflow step yourself in the execute/invoke method
454
+ * of the tool.
455
+ *
456
+ * @default true
457
+ */
458
+ executeAsStep?: boolean;
459
+ });
460
+ }
411
461
 
412
462
  type AISDKTool = CoreTool;
413
463
  type LangchainTool = {
@@ -417,7 +467,7 @@ type LangchainTool = {
417
467
  };
418
468
  type GenerateTextParams = Parameters<typeof generateText>[0];
419
469
  type Model = GenerateTextParams["model"];
420
- type AgentParameters<TTool extends AISDKTool | LangchainTool = AISDKTool> = {
470
+ type AgentParameters<TTool extends AISDKTool | LangchainTool | WorkflowTool = AISDKTool> = {
421
471
  /**
422
472
  * number of times the agent can call the LLM at most. If
423
473
  * the agent abruptly stops execution after calling tools, you may need
@@ -766,7 +816,12 @@ declare class WorkflowContext<TInitialPayload = unknown> {
766
816
  * Number of retries
767
817
  */
768
818
  readonly retries: number;
769
- constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, telemetry, }: {
819
+ /**
820
+ * Settings for controlling the number of active requests
821
+ * and number of requests per second with the same key.
822
+ */
823
+ readonly flowControl?: FlowControl;
824
+ constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, telemetry, invokeCount, flowControl, }: {
770
825
  qstashClient: WorkflowClient;
771
826
  workflowRunId: string;
772
827
  headers: Headers;
@@ -778,6 +833,8 @@ declare class WorkflowContext<TInitialPayload = unknown> {
778
833
  env?: Record<string, string | undefined>;
779
834
  retries?: number;
780
835
  telemetry?: Telemetry;
836
+ invokeCount?: number;
837
+ flowControl?: FlowControl;
781
838
  });
782
839
  /**
783
840
  * Executes a workflow step
@@ -923,7 +980,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
923
980
  */
924
981
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
925
982
  invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
926
- body: any;
983
+ body: TResult;
927
984
  isCanceled?: boolean;
928
985
  isFailed?: boolean;
929
986
  }>;
@@ -1095,7 +1152,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1095
1152
  * @returns void
1096
1153
  */
1097
1154
  failureFunction?: (failureData: {
1098
- context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api">;
1155
+ context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api" | "invoke" | "agents">;
1099
1156
  failStatus: number;
1100
1157
  failResponse: string;
1101
1158
  failHeaders: Record<string, string[]>;
@@ -1123,7 +1180,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1123
1180
  /**
1124
1181
  * Number of retries to use in workflow requests
1125
1182
  *
1126
- * 3 by default
1183
+ * @default 3
1127
1184
  */
1128
1185
  retries?: number;
1129
1186
  /**
@@ -1137,8 +1194,15 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1137
1194
  * By default, Workflow SDK sends telemetry about SDK version, framework or runtime.
1138
1195
  *
1139
1196
  * Set `disableTelemetry` to disable this behavior.
1197
+ *
1198
+ * @default false
1140
1199
  */
1141
1200
  disableTelemetry?: boolean;
1201
+ /**
1202
+ * Settings for controlling the number of active requests
1203
+ * and number of requests per second with the same key.
1204
+ */
1205
+ flowControl?: FlowControl;
1142
1206
  } & ValidationOptions<TInitialPayload>;
1143
1207
  type ValidationOptions<TInitialPayload> = {
1144
1208
  schema?: z.ZodType<TInitialPayload>;
@@ -1258,6 +1322,7 @@ type CallSettings<TBody = unknown> = {
1258
1322
  headers?: Record<string, string>;
1259
1323
  retries?: number;
1260
1324
  timeout?: Duration | number;
1325
+ flowControl?: FlowControl;
1261
1326
  };
1262
1327
  type HeaderParams = {
1263
1328
  /**
@@ -1290,6 +1355,15 @@ type HeaderParams = {
1290
1355
  * Only needed/used when the step is a waitForEvent step
1291
1356
  */
1292
1357
  telemetry?: Telemetry;
1358
+ /**
1359
+ * invoke count to include in headers
1360
+ */
1361
+ invokeCount?: number;
1362
+ /**
1363
+ * Settings for controlling the number of active requests
1364
+ * and number of requests per second with the same key.
1365
+ */
1366
+ flowControl?: FlowControl;
1293
1367
  } & ({
1294
1368
  /**
1295
1369
  * step to generate headers for
@@ -1303,6 +1377,13 @@ type HeaderParams = {
1303
1377
  * timeout duration in context.call
1304
1378
  */
1305
1379
  callTimeout?: number | Duration;
1380
+ /**
1381
+ * Settings for controlling the number of active requests
1382
+ * and number of requests per second with the same key.
1383
+ *
1384
+ * will be passed in context.call.
1385
+ */
1386
+ callFlowControl?: FlowControl;
1306
1387
  } | {
1307
1388
  /**
1308
1389
  * step not passed. Either first invocation or simply getting headers for
@@ -1321,6 +1402,13 @@ type HeaderParams = {
1321
1402
  * set to never because this is not a context.call step
1322
1403
  */
1323
1404
  callTimeout?: never;
1405
+ /**
1406
+ * Settings for controlling the number of active requests
1407
+ * and number of requests per second with the same key.
1408
+ *
1409
+ * will be passed in context.call.
1410
+ */
1411
+ callFlowControl?: never;
1324
1412
  });
1325
1413
  type InvokeWorkflowRequest = {
1326
1414
  workflowUrl: string;
@@ -1329,16 +1417,20 @@ type InvokeWorkflowRequest = {
1329
1417
  step: Step;
1330
1418
  body: string;
1331
1419
  };
1420
+ type LazyInvokeStepParams<TInitiaPayload, TResult> = {
1421
+ workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult>, "routeFunction" | "workflowId" | "options">;
1422
+ body: TInitiaPayload;
1423
+ workflowRunId?: string;
1424
+ } & Pick<CallSettings, "retries" | "headers" | "flowControl">;
1332
1425
  type InvokeStepResponse<TBody> = {
1333
1426
  body: TBody;
1334
1427
  isCanceled?: boolean;
1335
1428
  isFailed?: boolean;
1336
1429
  };
1337
- type InvokeCallback<TInitiaPayload, TResult> = (settings: LazyInvokeStepParams<TInitiaPayload, TResult>, invokeStep: Step, context: WorkflowContext) => Promise<TResult>;
1338
- type InvokableWorkflow<TInitialPayload, TResult, THandlerParams extends unknown[]> = {
1339
- handler: (...args: THandlerParams) => any;
1340
- callback: InvokeCallback<TInitialPayload, TResult>;
1430
+ type InvokableWorkflow<TInitialPayload, TResult> = {
1431
+ routeFunction: RouteFunction<TInitialPayload, TResult>;
1432
+ options: WorkflowServeOptions<Response, TInitialPayload>;
1341
1433
  workflowId?: string;
1342
1434
  };
1343
1435
 
1344
- 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 LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type InvokeStepResponse as r, type InvokeCallback as s, type InvokableWorkflow as t, type WorkflowLoggerOptions as u, WorkflowLogger as v };
1436
+ 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 };
@@ -1,5 +1,5 @@
1
- import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
- import { z } from 'zod';
1
+ import { PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
+ import { ZodType, z } from 'zod';
3
3
  import * as ai from 'ai';
4
4
  import { CoreTool, generateText } from 'ai';
5
5
  import * as _ai_sdk_openai from '@ai-sdk/openai';
@@ -33,11 +33,6 @@ declare abstract class BaseLazyStep<TResult = unknown> {
33
33
  */
34
34
  abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
35
35
  }
36
- type LazyInvokeStepParams<TInitiaPayload, TResult> = {
37
- workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult, unknown[]>, "callback" | "workflowId">;
38
- body: TInitiaPayload;
39
- workflowRunId?: string;
40
- } & Pick<CallSettings, "retries" | "headers">;
41
36
 
42
37
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
43
38
  type LogLevel = (typeof LOG_LEVELS)[number];
@@ -72,11 +67,12 @@ declare class AutoExecutor {
72
67
  private readonly nonPlanStepCount;
73
68
  private readonly steps;
74
69
  private indexInCurrentList;
70
+ private invokeCount;
75
71
  private telemetry?;
76
72
  stepCount: number;
77
73
  planStepCount: number;
78
74
  protected executingStep: string | false;
79
- constructor(context: WorkflowContext, steps: Step[], telemetry?: Telemetry, debug?: WorkflowLogger);
75
+ constructor(context: WorkflowContext, steps: Step[], telemetry?: Telemetry, invokeCount?: number, debug?: WorkflowLogger);
80
76
  /**
81
77
  * Adds the step function to the list of step functions to run in
82
78
  * parallel. After adding the function, defers the execution, so
@@ -408,6 +404,60 @@ declare const createWorkflowOpenAI: (context: WorkflowContext, config?: {
408
404
  baseURL?: string;
409
405
  apiKey?: string;
410
406
  }) => _ai_sdk_openai.OpenAIProvider;
407
+ declare class WorkflowTool<TSchema extends ZodType = ZodType> implements LangchainTool {
408
+ /**
409
+ * description of the tool
410
+ */
411
+ readonly description: string;
412
+ /**
413
+ * schema of the tool
414
+ */
415
+ readonly schema: TSchema;
416
+ /**
417
+ * function to invoke the tool
418
+ */
419
+ readonly invoke: (params: z.infer<TSchema>) => any;
420
+ /**
421
+ * whether the invoke method of the tool is to be wrapped with `context.run`
422
+ */
423
+ readonly executeAsStep: boolean;
424
+ /**
425
+ *
426
+ * @param description description of the tool
427
+ * @param schema schema of the tool
428
+ * @param invoke function to invoke the tool
429
+ * @param executeAsStep whether the invoke method of the tool is to be wrapped with `context.run`
430
+ */
431
+ constructor(params: {
432
+ /**
433
+ * description of the tool
434
+ */
435
+ description: string;
436
+ /**
437
+ * schema of the tool
438
+ */
439
+ schema: TSchema;
440
+ /**
441
+ * invoke function to invoke the tool
442
+ */
443
+ invoke: (params: z.infer<TSchema>) => any;
444
+ /**
445
+ * whether the invoke method is to be wrapped with `context.run`.
446
+ *
447
+ * When you pass a LangChain, AI SDK tool or a WorkflowTool to your agent,
448
+ * the execute/invoke method of the tool is wrapped with `context.run` by default.
449
+ *
450
+ * This option allows you to disable this behavior.
451
+ *
452
+ * You may want to disable wrapping with context.run if you want to run context.run,
453
+ * context.call or any other workflow step yourself in the execute/invoke method
454
+ * of the tool.
455
+ *
456
+ * @default true
457
+ */
458
+ executeAsStep?: boolean;
459
+ });
460
+ }
411
461
 
412
462
  type AISDKTool = CoreTool;
413
463
  type LangchainTool = {
@@ -417,7 +467,7 @@ type LangchainTool = {
417
467
  };
418
468
  type GenerateTextParams = Parameters<typeof generateText>[0];
419
469
  type Model = GenerateTextParams["model"];
420
- type AgentParameters<TTool extends AISDKTool | LangchainTool = AISDKTool> = {
470
+ type AgentParameters<TTool extends AISDKTool | LangchainTool | WorkflowTool = AISDKTool> = {
421
471
  /**
422
472
  * number of times the agent can call the LLM at most. If
423
473
  * the agent abruptly stops execution after calling tools, you may need
@@ -766,7 +816,12 @@ declare class WorkflowContext<TInitialPayload = unknown> {
766
816
  * Number of retries
767
817
  */
768
818
  readonly retries: number;
769
- constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, telemetry, }: {
819
+ /**
820
+ * Settings for controlling the number of active requests
821
+ * and number of requests per second with the same key.
822
+ */
823
+ readonly flowControl?: FlowControl;
824
+ constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, telemetry, invokeCount, flowControl, }: {
770
825
  qstashClient: WorkflowClient;
771
826
  workflowRunId: string;
772
827
  headers: Headers;
@@ -778,6 +833,8 @@ declare class WorkflowContext<TInitialPayload = unknown> {
778
833
  env?: Record<string, string | undefined>;
779
834
  retries?: number;
780
835
  telemetry?: Telemetry;
836
+ invokeCount?: number;
837
+ flowControl?: FlowControl;
781
838
  });
782
839
  /**
783
840
  * Executes a workflow step
@@ -923,7 +980,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
923
980
  */
924
981
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
925
982
  invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
926
- body: any;
983
+ body: TResult;
927
984
  isCanceled?: boolean;
928
985
  isFailed?: boolean;
929
986
  }>;
@@ -1095,7 +1152,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1095
1152
  * @returns void
1096
1153
  */
1097
1154
  failureFunction?: (failureData: {
1098
- context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api">;
1155
+ context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api" | "invoke" | "agents">;
1099
1156
  failStatus: number;
1100
1157
  failResponse: string;
1101
1158
  failHeaders: Record<string, string[]>;
@@ -1123,7 +1180,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1123
1180
  /**
1124
1181
  * Number of retries to use in workflow requests
1125
1182
  *
1126
- * 3 by default
1183
+ * @default 3
1127
1184
  */
1128
1185
  retries?: number;
1129
1186
  /**
@@ -1137,8 +1194,15 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1137
1194
  * By default, Workflow SDK sends telemetry about SDK version, framework or runtime.
1138
1195
  *
1139
1196
  * Set `disableTelemetry` to disable this behavior.
1197
+ *
1198
+ * @default false
1140
1199
  */
1141
1200
  disableTelemetry?: boolean;
1201
+ /**
1202
+ * Settings for controlling the number of active requests
1203
+ * and number of requests per second with the same key.
1204
+ */
1205
+ flowControl?: FlowControl;
1142
1206
  } & ValidationOptions<TInitialPayload>;
1143
1207
  type ValidationOptions<TInitialPayload> = {
1144
1208
  schema?: z.ZodType<TInitialPayload>;
@@ -1258,6 +1322,7 @@ type CallSettings<TBody = unknown> = {
1258
1322
  headers?: Record<string, string>;
1259
1323
  retries?: number;
1260
1324
  timeout?: Duration | number;
1325
+ flowControl?: FlowControl;
1261
1326
  };
1262
1327
  type HeaderParams = {
1263
1328
  /**
@@ -1290,6 +1355,15 @@ type HeaderParams = {
1290
1355
  * Only needed/used when the step is a waitForEvent step
1291
1356
  */
1292
1357
  telemetry?: Telemetry;
1358
+ /**
1359
+ * invoke count to include in headers
1360
+ */
1361
+ invokeCount?: number;
1362
+ /**
1363
+ * Settings for controlling the number of active requests
1364
+ * and number of requests per second with the same key.
1365
+ */
1366
+ flowControl?: FlowControl;
1293
1367
  } & ({
1294
1368
  /**
1295
1369
  * step to generate headers for
@@ -1303,6 +1377,13 @@ type HeaderParams = {
1303
1377
  * timeout duration in context.call
1304
1378
  */
1305
1379
  callTimeout?: number | Duration;
1380
+ /**
1381
+ * Settings for controlling the number of active requests
1382
+ * and number of requests per second with the same key.
1383
+ *
1384
+ * will be passed in context.call.
1385
+ */
1386
+ callFlowControl?: FlowControl;
1306
1387
  } | {
1307
1388
  /**
1308
1389
  * step not passed. Either first invocation or simply getting headers for
@@ -1321,6 +1402,13 @@ type HeaderParams = {
1321
1402
  * set to never because this is not a context.call step
1322
1403
  */
1323
1404
  callTimeout?: never;
1405
+ /**
1406
+ * Settings for controlling the number of active requests
1407
+ * and number of requests per second with the same key.
1408
+ *
1409
+ * will be passed in context.call.
1410
+ */
1411
+ callFlowControl?: never;
1324
1412
  });
1325
1413
  type InvokeWorkflowRequest = {
1326
1414
  workflowUrl: string;
@@ -1329,16 +1417,20 @@ type InvokeWorkflowRequest = {
1329
1417
  step: Step;
1330
1418
  body: string;
1331
1419
  };
1420
+ type LazyInvokeStepParams<TInitiaPayload, TResult> = {
1421
+ workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult>, "routeFunction" | "workflowId" | "options">;
1422
+ body: TInitiaPayload;
1423
+ workflowRunId?: string;
1424
+ } & Pick<CallSettings, "retries" | "headers" | "flowControl">;
1332
1425
  type InvokeStepResponse<TBody> = {
1333
1426
  body: TBody;
1334
1427
  isCanceled?: boolean;
1335
1428
  isFailed?: boolean;
1336
1429
  };
1337
- type InvokeCallback<TInitiaPayload, TResult> = (settings: LazyInvokeStepParams<TInitiaPayload, TResult>, invokeStep: Step, context: WorkflowContext) => Promise<TResult>;
1338
- type InvokableWorkflow<TInitialPayload, TResult, THandlerParams extends unknown[]> = {
1339
- handler: (...args: THandlerParams) => any;
1340
- callback: InvokeCallback<TInitialPayload, TResult>;
1430
+ type InvokableWorkflow<TInitialPayload, TResult> = {
1431
+ routeFunction: RouteFunction<TInitialPayload, TResult>;
1432
+ options: WorkflowServeOptions<Response, TInitialPayload>;
1341
1433
  workflowId?: string;
1342
1434
  };
1343
1435
 
1344
- 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 LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type InvokeStepResponse as r, type InvokeCallback as s, type InvokableWorkflow as t, type WorkflowLoggerOptions as u, WorkflowLogger as v };
1436
+ 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 };
@@ -1,95 +0,0 @@
1
- import {
2
- WorkflowError,
3
- getHeaders,
4
- getWorkflowRunId
5
- } from "./chunk-IWAW7GIG.mjs";
6
-
7
- // src/serve/serve-many.ts
8
- var serveManyBase = ({
9
- workflows,
10
- getWorkflowId
11
- }) => {
12
- const workflowIds = [];
13
- const workflowMap = Object.fromEntries(
14
- Object.entries(workflows).map((workflow) => {
15
- const workflowId = workflow[0];
16
- if (workflowIds.includes(workflowId)) {
17
- throw new WorkflowError(
18
- `Duplicate workflow name found: '${workflowId}'. Please set different workflow names in serveMany.`
19
- );
20
- }
21
- if (workflowId.includes("/")) {
22
- throw new WorkflowError(
23
- `Invalid workflow name found: '${workflowId}'. Workflow name cannot contain '/'.`
24
- );
25
- }
26
- workflowIds.push(workflowId);
27
- workflow[1].workflowId = workflowId;
28
- return [workflowId, workflow[1].handler];
29
- })
30
- );
31
- return {
32
- handler: async (...params) => {
33
- const pickedWorkflowId = getWorkflowId(...params);
34
- if (!pickedWorkflowId) {
35
- throw new WorkflowError(`Unexpected request in serveMany. workflowId not set. Please update the URL of your request.`);
36
- }
37
- const workflow = workflowMap[pickedWorkflowId];
38
- if (!workflow) {
39
- throw new WorkflowError(`No workflows in serveMany found for '${pickedWorkflowId}'. Please update the URL of your request.`);
40
- }
41
- return await workflow(...params);
42
- }
43
- };
44
- };
45
- var createInvokeCallback = (telemetry) => {
46
- const invokeCallback = async (settings, invokeStep, context) => {
47
- const { body, workflow, headers = {}, workflowRunId = getWorkflowRunId(), retries } = settings;
48
- const { workflowId } = workflow;
49
- if (!workflowId) {
50
- throw new WorkflowError("You can only invoke workflow which has a workflowId");
51
- }
52
- const { headers: invokerHeaders } = getHeaders({
53
- initHeaderValue: "false",
54
- workflowRunId: context.workflowRunId,
55
- workflowUrl: context.url,
56
- userHeaders: context.headers,
57
- failureUrl: context.failureUrl,
58
- retries: context.retries,
59
- telemetry
60
- });
61
- invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
62
- const newUrl = context.url.replace(/[^/]+$/, workflowId);
63
- const { headers: triggerHeaders } = getHeaders({
64
- initHeaderValue: "true",
65
- workflowRunId,
66
- workflowUrl: newUrl,
67
- userHeaders: new Headers(headers),
68
- retries,
69
- telemetry
70
- });
71
- triggerHeaders["Upstash-Workflow-Invoke"] = "true";
72
- const request = {
73
- body: JSON.stringify(body),
74
- headers: Object.fromEntries(
75
- Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
76
- ),
77
- workflowRunId,
78
- workflowUrl: context.url,
79
- step: invokeStep
80
- };
81
- await context.qstashClient.publish({
82
- headers: triggerHeaders,
83
- method: "POST",
84
- body: JSON.stringify(request),
85
- url: newUrl
86
- });
87
- return void 0;
88
- };
89
- return invokeCallback;
90
- };
91
-
92
- export {
93
- serveManyBase,
94
- createInvokeCallback
95
- };
@@ -1,10 +0,0 @@
1
- import { t as InvokableWorkflow } from './types-C7Y7WUQd.mjs';
2
-
3
- declare const serveManyBase: <TServe extends (...params: any[]) => any, THandlerParams extends Parameters<TServe> = Parameters<TServe>, TInvokableWorkflow extends InvokableWorkflow<any, any, THandlerParams> = InvokableWorkflow<any, any, THandlerParams>>({ workflows, getWorkflowId, }: {
4
- workflows: Record<string, TInvokableWorkflow>;
5
- getWorkflowId: (...params: THandlerParams) => string;
6
- }) => {
7
- handler: (...params: THandlerParams) => Promise<any>;
8
- };
9
-
10
- export { serveManyBase as s };
@@ -1,10 +0,0 @@
1
- import { t as InvokableWorkflow } from './types-C7Y7WUQd.js';
2
-
3
- declare const serveManyBase: <TServe extends (...params: any[]) => any, THandlerParams extends Parameters<TServe> = Parameters<TServe>, TInvokableWorkflow extends InvokableWorkflow<any, any, THandlerParams> = InvokableWorkflow<any, any, THandlerParams>>({ workflows, getWorkflowId, }: {
4
- workflows: Record<string, TInvokableWorkflow>;
5
- getWorkflowId: (...params: THandlerParams) => string;
6
- }) => {
7
- handler: (...params: THandlerParams) => Promise<any>;
8
- };
9
-
10
- export { serveManyBase as s };