@upstash/workflow 0.2.10 → 0.2.12

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.
@@ -14,6 +14,7 @@ import * as _ai_sdk_openai from '@ai-sdk/openai';
14
14
  declare abstract class BaseLazyStep<TResult = unknown> {
15
15
  readonly stepName: string;
16
16
  abstract readonly stepType: StepType;
17
+ protected abstract readonly allowUndefinedOut: boolean;
17
18
  constructor(stepName: string);
18
19
  /**
19
20
  * plan step to submit when step will run parallel with other
@@ -32,6 +33,17 @@ declare abstract class BaseLazyStep<TResult = unknown> {
32
33
  * @param stepId
33
34
  */
34
35
  abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
36
+ /**
37
+ * parse the out field of a step result.
38
+ *
39
+ * will be called when returning the steps to the context from auto executor
40
+ *
41
+ * @param out field of the step
42
+ * @returns parsed out field
43
+ */
44
+ parseOut(out: unknown): TResult;
45
+ protected safeParseOut(out: string): TResult;
46
+ protected static tryParsing(stepOut: unknown): any;
35
47
  }
36
48
 
37
49
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
@@ -393,6 +405,47 @@ declare class WorkflowApi extends BaseWorkflowApi {
393
405
  get anthropic(): AnthropicAPI;
394
406
  }
395
407
 
408
+ /**
409
+ * An Agent which utilizes the model and tools available to it
410
+ * to achieve a given task
411
+ *
412
+ * @param name Name of the agent
413
+ * @param background Background of the agent
414
+ * @param model LLM model to use
415
+ * @param tools tools available to the agent
416
+ * @param maxSteps number of times the agent can call the LLM at most. If
417
+ * the agent abruptly stops execution after calling tools, you may need
418
+ * to increase maxSteps
419
+ * @param temparature temparature used when calling the LLM
420
+ */
421
+ declare class Agent {
422
+ readonly name: AgentParameters["name"];
423
+ readonly tools: AgentParameters["tools"];
424
+ readonly maxSteps: AgentParameters["maxSteps"];
425
+ readonly background: AgentParameters["background"];
426
+ readonly model: AgentParameters["model"];
427
+ readonly temparature: AgentParameters["temparature"];
428
+ private readonly context;
429
+ constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
430
+ /**
431
+ * Trigger the agent by passing a prompt
432
+ *
433
+ * @param prompt task to assign to the agent
434
+ * @returns Response as `{ text: string }`
435
+ */
436
+ call({ prompt }: {
437
+ prompt: string;
438
+ }): Promise<{
439
+ text: string;
440
+ }>;
441
+ /**
442
+ * Convert the agent to a tool which can be used by other agents.
443
+ *
444
+ * @returns the agent as a tool
445
+ */
446
+ asTool(): AISDKTool;
447
+ }
448
+
396
449
  /**
397
450
  * creates an AI SDK openai client with a custom
398
451
  * fetch implementation which uses context.call.
@@ -535,47 +588,9 @@ type CustomModelSettings = ModelParams["1"] & {
535
588
  apiKey?: string;
536
589
  };
537
590
  type CustomModelParams = [ModelParams[0], CustomModelSettings?];
538
-
539
- /**
540
- * An Agent which utilizes the model and tools available to it
541
- * to achieve a given task
542
- *
543
- * @param name Name of the agent
544
- * @param background Background of the agent
545
- * @param model LLM model to use
546
- * @param tools tools available to the agent
547
- * @param maxSteps number of times the agent can call the LLM at most. If
548
- * the agent abruptly stops execution after calling tools, you may need
549
- * to increase maxSteps
550
- * @param temparature temparature used when calling the LLM
551
- */
552
- declare class Agent {
553
- readonly name: AgentParameters["name"];
554
- readonly tools: AgentParameters["tools"];
555
- readonly maxSteps: AgentParameters["maxSteps"];
556
- readonly background: AgentParameters["background"];
557
- readonly model: AgentParameters["model"];
558
- readonly temparature: AgentParameters["temparature"];
559
- private readonly context;
560
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
561
- /**
562
- * Trigger the agent by passing a prompt
563
- *
564
- * @param prompt task to assign to the agent
565
- * @returns Response as `{ text: string }`
566
- */
567
- call({ prompt }: {
568
- prompt: string;
569
- }): Promise<{
570
- text: string;
571
- }>;
572
- /**
573
- * Convert the agent to a tool which can be used by other agents.
574
- *
575
- * @returns the agent as a tool
576
- */
577
- asTool(): AISDKTool;
578
- }
591
+ type ProviderFunction = (params: {
592
+ fetch: typeof fetch;
593
+ }) => any;
579
594
 
580
595
  /**
581
596
  * An Agent Task
@@ -688,6 +703,11 @@ declare class WorkflowAgents {
688
703
  * creates an openai model for agents
689
704
  */
690
705
  openai(...params: CustomModelParams): ai.LanguageModelV1;
706
+ AISDKModel: <TProvider extends ProviderFunction>({ context, provider, providerParams, }: {
707
+ context: WorkflowContext;
708
+ provider: TProvider;
709
+ providerParams?: Omit<Required<Parameters<TProvider>>[0], "fetch">;
710
+ }) => ReturnType<TProvider>;
691
711
  }
692
712
 
693
713
  /**
@@ -979,11 +999,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
979
999
  * @returns notify response which has event id, event data and list of waiters which were notified
980
1000
  */
981
1001
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
982
- invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
983
- body: TResult;
984
- isCanceled?: boolean;
985
- isFailed?: boolean;
986
- }>;
1002
+ invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
987
1003
  /**
988
1004
  * Cancel the current workflow run
989
1005
  *
@@ -1006,6 +1022,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
1006
1022
  * Neeeded to resolve import issues
1007
1023
  */
1008
1024
  type WorkflowClient = {
1025
+ batch: InstanceType<typeof Client>["batch"];
1009
1026
  batchJSON: InstanceType<typeof Client>["batchJSON"];
1010
1027
  publishJSON: InstanceType<typeof Client>["publishJSON"];
1011
1028
  publish: InstanceType<typeof Client>["publish"];
@@ -1141,6 +1158,13 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1141
1158
  * Url to call if QStash retries are exhausted while executing the workflow
1142
1159
  */
1143
1160
  failureUrl?: string;
1161
+ /**
1162
+ * Error handler called when an error occurs in the workflow. This is
1163
+ * different from `failureFunction` in that it is called when an error
1164
+ * occurs in the workflow, while `failureFunction` is called when QStash
1165
+ * retries are exhausted.
1166
+ */
1167
+ onError?: (error: Error) => void;
1144
1168
  /**
1145
1169
  * Failure function called when QStash retries are exhausted while executing
1146
1170
  * the workflow. Will overwrite `failureUrl` parameter with the workflow
@@ -14,6 +14,7 @@ import * as _ai_sdk_openai from '@ai-sdk/openai';
14
14
  declare abstract class BaseLazyStep<TResult = unknown> {
15
15
  readonly stepName: string;
16
16
  abstract readonly stepType: StepType;
17
+ protected abstract readonly allowUndefinedOut: boolean;
17
18
  constructor(stepName: string);
18
19
  /**
19
20
  * plan step to submit when step will run parallel with other
@@ -32,6 +33,17 @@ declare abstract class BaseLazyStep<TResult = unknown> {
32
33
  * @param stepId
33
34
  */
34
35
  abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
36
+ /**
37
+ * parse the out field of a step result.
38
+ *
39
+ * will be called when returning the steps to the context from auto executor
40
+ *
41
+ * @param out field of the step
42
+ * @returns parsed out field
43
+ */
44
+ parseOut(out: unknown): TResult;
45
+ protected safeParseOut(out: string): TResult;
46
+ protected static tryParsing(stepOut: unknown): any;
35
47
  }
36
48
 
37
49
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
@@ -393,6 +405,47 @@ declare class WorkflowApi extends BaseWorkflowApi {
393
405
  get anthropic(): AnthropicAPI;
394
406
  }
395
407
 
408
+ /**
409
+ * An Agent which utilizes the model and tools available to it
410
+ * to achieve a given task
411
+ *
412
+ * @param name Name of the agent
413
+ * @param background Background of the agent
414
+ * @param model LLM model to use
415
+ * @param tools tools available to the agent
416
+ * @param maxSteps number of times the agent can call the LLM at most. If
417
+ * the agent abruptly stops execution after calling tools, you may need
418
+ * to increase maxSteps
419
+ * @param temparature temparature used when calling the LLM
420
+ */
421
+ declare class Agent {
422
+ readonly name: AgentParameters["name"];
423
+ readonly tools: AgentParameters["tools"];
424
+ readonly maxSteps: AgentParameters["maxSteps"];
425
+ readonly background: AgentParameters["background"];
426
+ readonly model: AgentParameters["model"];
427
+ readonly temparature: AgentParameters["temparature"];
428
+ private readonly context;
429
+ constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
430
+ /**
431
+ * Trigger the agent by passing a prompt
432
+ *
433
+ * @param prompt task to assign to the agent
434
+ * @returns Response as `{ text: string }`
435
+ */
436
+ call({ prompt }: {
437
+ prompt: string;
438
+ }): Promise<{
439
+ text: string;
440
+ }>;
441
+ /**
442
+ * Convert the agent to a tool which can be used by other agents.
443
+ *
444
+ * @returns the agent as a tool
445
+ */
446
+ asTool(): AISDKTool;
447
+ }
448
+
396
449
  /**
397
450
  * creates an AI SDK openai client with a custom
398
451
  * fetch implementation which uses context.call.
@@ -535,47 +588,9 @@ type CustomModelSettings = ModelParams["1"] & {
535
588
  apiKey?: string;
536
589
  };
537
590
  type CustomModelParams = [ModelParams[0], CustomModelSettings?];
538
-
539
- /**
540
- * An Agent which utilizes the model and tools available to it
541
- * to achieve a given task
542
- *
543
- * @param name Name of the agent
544
- * @param background Background of the agent
545
- * @param model LLM model to use
546
- * @param tools tools available to the agent
547
- * @param maxSteps number of times the agent can call the LLM at most. If
548
- * the agent abruptly stops execution after calling tools, you may need
549
- * to increase maxSteps
550
- * @param temparature temparature used when calling the LLM
551
- */
552
- declare class Agent {
553
- readonly name: AgentParameters["name"];
554
- readonly tools: AgentParameters["tools"];
555
- readonly maxSteps: AgentParameters["maxSteps"];
556
- readonly background: AgentParameters["background"];
557
- readonly model: AgentParameters["model"];
558
- readonly temparature: AgentParameters["temparature"];
559
- private readonly context;
560
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
561
- /**
562
- * Trigger the agent by passing a prompt
563
- *
564
- * @param prompt task to assign to the agent
565
- * @returns Response as `{ text: string }`
566
- */
567
- call({ prompt }: {
568
- prompt: string;
569
- }): Promise<{
570
- text: string;
571
- }>;
572
- /**
573
- * Convert the agent to a tool which can be used by other agents.
574
- *
575
- * @returns the agent as a tool
576
- */
577
- asTool(): AISDKTool;
578
- }
591
+ type ProviderFunction = (params: {
592
+ fetch: typeof fetch;
593
+ }) => any;
579
594
 
580
595
  /**
581
596
  * An Agent Task
@@ -688,6 +703,11 @@ declare class WorkflowAgents {
688
703
  * creates an openai model for agents
689
704
  */
690
705
  openai(...params: CustomModelParams): ai.LanguageModelV1;
706
+ AISDKModel: <TProvider extends ProviderFunction>({ context, provider, providerParams, }: {
707
+ context: WorkflowContext;
708
+ provider: TProvider;
709
+ providerParams?: Omit<Required<Parameters<TProvider>>[0], "fetch">;
710
+ }) => ReturnType<TProvider>;
691
711
  }
692
712
 
693
713
  /**
@@ -979,11 +999,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
979
999
  * @returns notify response which has event id, event data and list of waiters which were notified
980
1000
  */
981
1001
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
982
- invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
983
- body: TResult;
984
- isCanceled?: boolean;
985
- isFailed?: boolean;
986
- }>;
1002
+ invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
987
1003
  /**
988
1004
  * Cancel the current workflow run
989
1005
  *
@@ -1006,6 +1022,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
1006
1022
  * Neeeded to resolve import issues
1007
1023
  */
1008
1024
  type WorkflowClient = {
1025
+ batch: InstanceType<typeof Client>["batch"];
1009
1026
  batchJSON: InstanceType<typeof Client>["batchJSON"];
1010
1027
  publishJSON: InstanceType<typeof Client>["publishJSON"];
1011
1028
  publish: InstanceType<typeof Client>["publish"];
@@ -1141,6 +1158,13 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1141
1158
  * Url to call if QStash retries are exhausted while executing the workflow
1142
1159
  */
1143
1160
  failureUrl?: string;
1161
+ /**
1162
+ * Error handler called when an error occurs in the workflow. This is
1163
+ * different from `failureFunction` in that it is called when an error
1164
+ * occurs in the workflow, while `failureFunction` is called when QStash
1165
+ * retries are exhausted.
1166
+ */
1167
+ onError?: (error: Error) => void;
1144
1168
  /**
1145
1169
  * Failure function called when QStash retries are exhausted while executing
1146
1170
  * the workflow. Will overwrite `failureUrl` parameter with the workflow