@upstash/workflow 0.2.22-rc → 0.3.0-rc

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/tanstack.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-CAQSUCHB.mjs";
5
+ } from "./chunk-AGYYZKP7.mjs";
6
6
 
7
7
  // platforms/tanstack.ts
8
8
  var telemetry = {
@@ -1,8 +1,5 @@
1
- import { QstashError, PublishRequest, FlowControl, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
- import { ZodType, z } from 'zod';
3
- import * as ai from 'ai';
4
- import { CoreTool, generateText } from 'ai';
5
- import { createOpenAI } from '@ai-sdk/openai';
1
+ import { QstashError, PublishRequest, FlowControl, HTTPMethods as HTTPMethods$1, Client, Receiver } from '@upstash/qstash';
2
+ import { z } from 'zod';
6
3
 
7
4
  /**
8
5
  * Error raised during Workflow execution
@@ -38,6 +35,14 @@ declare class WorkflowNonRetryableError extends WorkflowAbort {
38
35
  */
39
36
  constructor(message?: string);
40
37
  }
38
+ declare class WorkflowRetryAfterError extends WorkflowAbort {
39
+ retryAfter: number | Duration;
40
+ /**
41
+ * @param retryAfter time in seconds after which the workflow should be retried
42
+ * @param message error message to be displayed
43
+ */
44
+ constructor(message: string, retryAfter: number | Duration);
45
+ }
41
46
 
42
47
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
43
48
  type LogLevel = (typeof LOG_LEVELS)[number];
@@ -453,304 +458,6 @@ declare class WorkflowApi extends BaseWorkflowApi {
453
458
  get anthropic(): AnthropicAPI;
454
459
  }
455
460
 
456
- /**
457
- * An Agent which utilizes the model and tools available to it
458
- * to achieve a given task
459
- *
460
- * @param name Name of the agent
461
- * @param background Background of the agent
462
- * @param model LLM model to use
463
- * @param tools tools available to the agent
464
- * @param maxSteps number of times the agent can call the LLM at most. If
465
- * the agent abruptly stops execution after calling tools, you may need
466
- * to increase maxSteps
467
- * @param temparature temparature used when calling the LLM
468
- */
469
- declare class Agent {
470
- readonly name: AgentParameters["name"];
471
- readonly tools: AgentParameters["tools"];
472
- readonly maxSteps: AgentParameters["maxSteps"];
473
- readonly background: AgentParameters["background"];
474
- readonly model: AgentParameters["model"];
475
- readonly temparature: AgentParameters["temparature"];
476
- private readonly context;
477
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
478
- /**
479
- * Trigger the agent by passing a prompt
480
- *
481
- * @param prompt task to assign to the agent
482
- * @returns Response as `{ text: string }`
483
- */
484
- call({ prompt }: {
485
- prompt: string;
486
- }): Promise<{
487
- text: string;
488
- }>;
489
- /**
490
- * Convert the agent to a tool which can be used by other agents.
491
- *
492
- * @returns the agent as a tool
493
- */
494
- asTool(): AISDKTool;
495
- }
496
-
497
- declare class WorkflowTool<TSchema extends ZodType = ZodType> implements LangchainTool {
498
- /**
499
- * description of the tool
500
- */
501
- readonly description: string;
502
- /**
503
- * schema of the tool
504
- */
505
- readonly schema: TSchema;
506
- /**
507
- * function to invoke the tool
508
- */
509
- readonly invoke: (params: z.infer<TSchema>) => any;
510
- /**
511
- * whether the invoke method of the tool is to be wrapped with `context.run`
512
- */
513
- readonly executeAsStep: boolean;
514
- /**
515
- *
516
- * @param description description of the tool
517
- * @param schema schema of the tool
518
- * @param invoke function to invoke the tool
519
- * @param executeAsStep whether the invoke method of the tool is to be wrapped with `context.run`
520
- */
521
- constructor(params: {
522
- /**
523
- * description of the tool
524
- */
525
- description: string;
526
- /**
527
- * schema of the tool
528
- */
529
- schema: TSchema;
530
- /**
531
- * invoke function to invoke the tool
532
- */
533
- invoke: (params: z.infer<TSchema>) => any;
534
- /**
535
- * whether the invoke method is to be wrapped with `context.run`.
536
- *
537
- * When you pass a LangChain, AI SDK tool or a WorkflowTool to your agent,
538
- * the execute/invoke method of the tool is wrapped with `context.run` by default.
539
- *
540
- * This option allows you to disable this behavior.
541
- *
542
- * You may want to disable wrapping with context.run if you want to run context.run,
543
- * context.call or any other workflow step yourself in the execute/invoke method
544
- * of the tool.
545
- *
546
- * @default true
547
- */
548
- executeAsStep?: boolean;
549
- });
550
- }
551
-
552
- type AISDKTool = CoreTool;
553
- type LangchainTool = {
554
- description: string;
555
- schema: AISDKTool["parameters"];
556
- invoke: (...params: any[]) => any;
557
- };
558
- type GenerateTextParams = Parameters<typeof generateText>[0];
559
- type Model = GenerateTextParams["model"];
560
- type AgentParameters<TTool extends AISDKTool | LangchainTool | WorkflowTool = AISDKTool> = {
561
- /**
562
- * number of times the agent can call the LLM at most. If
563
- * the agent abruptly stops execution after calling tools, you may need
564
- * to increase maxSteps
565
- */
566
- maxSteps: number;
567
- /**
568
- * Background of the agent
569
- */
570
- background: string;
571
- /**
572
- * tools available to the agent
573
- */
574
- tools: Record<string, TTool>;
575
- /**
576
- * Name of the agent
577
- */
578
- name: string;
579
- /**
580
- * LLM model to use
581
- */
582
- model: Model;
583
- /**
584
- * temparature used when calling the LLM
585
- *
586
- * @default 0.1
587
- */
588
- temparature?: number;
589
- };
590
- type TaskParams = {
591
- /**
592
- * task assigned to the agent
593
- */
594
- prompt: string;
595
- };
596
- type SingleAgentTaskParams = TaskParams & {
597
- /**
598
- * agent to perform the task
599
- */
600
- agent: Agent;
601
- };
602
- type MultiAgentTaskParams = TaskParams & {
603
- /**
604
- * Agents which will collaborate to achieve the task
605
- */
606
- agents: Agent[];
607
- /**
608
- * number of times the manager agent can call the LLM at most.
609
- * If the agent abruptly stops execution after calling other agents, you may
610
- * need to increase maxSteps
611
- */
612
- maxSteps: number;
613
- /**
614
- * LLM model to use
615
- */
616
- model: Model;
617
- /**
618
- * Background of the agent. If not passed, default will be used.
619
- */
620
- background?: string;
621
- };
622
- type ModelParams = Parameters<ReturnType<typeof createOpenAI>>;
623
- type AgentCallParams = Pick<CallSettings, "flowControl" | "retries" | "timeout" | "retryDelay">;
624
- type CustomModelSettings = ModelParams["1"] & {
625
- baseURL?: string;
626
- apiKey?: string;
627
- } & {
628
- callSettings: AgentCallParams;
629
- };
630
- type CustomModelParams = [ModelParams[0], CustomModelSettings?];
631
- type ProviderFunction = (params: {
632
- fetch: typeof fetch;
633
- }) => any;
634
-
635
- /**
636
- * An Agent Task
637
- *
638
- * Can be run to make the agent(s) complete it using the tools available to them
639
- *
640
- * Can consist of a single agent or multiple agents.
641
- *
642
- * Single agent:
643
- *
644
- * ```ts
645
- * const task = context.agents.task({
646
- * agent: researcherAgent,
647
- * prompt: "Tell me about 5 topics in advanced physics.",
648
- * });
649
- * const { text } = await task.run();
650
- * ```
651
- *
652
- * Multi Agent:
653
- *
654
- * ```ts
655
- * const task = context.agents.task({
656
- * model,
657
- * maxSteps: 3,
658
- * agents: [researcherAgent, mathAgent],
659
- * prompt: "Tell me about 3 cities in Japan and calculate the sum of their populations",
660
- * });
661
- * const { text } = await task.run();
662
- * ```
663
- */
664
- declare class Task {
665
- private readonly context;
666
- private readonly taskParameters;
667
- constructor({ context, taskParameters, }: {
668
- context: WorkflowContext;
669
- taskParameters: SingleAgentTaskParams | MultiAgentTaskParams;
670
- });
671
- /**
672
- * Run the agents to complete the task
673
- *
674
- * @returns Result of the task as { text: string }
675
- */
676
- run(): Promise<{
677
- text: string;
678
- }>;
679
- }
680
-
681
- /**
682
- * Workflow Agents API
683
- *
684
- * https://upstash.com/docs/workflow/agents/overview
685
- *
686
- * Allows defining agents which can complete a given task
687
- * using tools available to them.
688
- */
689
- declare class WorkflowAgents {
690
- private context;
691
- constructor({ context }: {
692
- context: WorkflowContext;
693
- });
694
- /**
695
- * Defines an agent
696
- *
697
- * ```ts
698
- * const researcherAgent = context.agents.agent({
699
- * model,
700
- * name: 'academic',
701
- * maxSteps: 2,
702
- * tools: {
703
- * wikiTool: new WikipediaQueryRun({
704
- * topKResults: 1,
705
- * maxDocContentLength: 500,
706
- * })
707
- * },
708
- * background:
709
- * 'You are researcher agent with access to Wikipedia. ' +
710
- * 'Utilize Wikipedia as much as possible for correct information',
711
- * });
712
- * ```
713
- *
714
- * @param params agent parameters
715
- * @returns
716
- */
717
- agent(params: AgentParameters<AISDKTool | LangchainTool>): Agent;
718
- /**
719
- * Defines a task to be executed by a single agent
720
- *
721
- * ```ts
722
- * const task = context.agents.task({
723
- * agent: researcherAgent,
724
- * prompt: "Tell me about 5 topics in advanced physics.",
725
- * });
726
- * ```
727
- */
728
- task(taskParameters: SingleAgentTaskParams): Task;
729
- /**
730
- * Defines a task to be executed by multiple collaborating agents
731
- *
732
- * ```ts
733
- * const task = context.agents.task({
734
- * model,
735
- * maxSteps: 3,
736
- * agents: [researcherAgent, mathAgent],
737
- * prompt: "Tell me about 3 cities in Japan and calculate the sum of their populations",
738
- * });
739
- * ```
740
- */
741
- task(taskParameters: MultiAgentTaskParams): Task;
742
- /**
743
- * creates an openai model for agents
744
- */
745
- openai(...params: CustomModelParams): ai.LanguageModelV1;
746
- AISDKModel: <TProvider extends ProviderFunction>({ context, provider, providerParams, agentCallParams, }: {
747
- context: WorkflowContext;
748
- provider: TProvider;
749
- providerParams?: Omit<Required<Parameters<TProvider>>[0], "fetch">;
750
- agentCallParams?: AgentCallParams;
751
- }) => ReturnType<TProvider>;
752
- }
753
-
754
461
  /**
755
462
  * Upstash Workflow context
756
463
  *
@@ -1109,7 +816,6 @@ declare class WorkflowContext<TInitialPayload = unknown> {
1109
816
  */
1110
817
  protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
1111
818
  get api(): WorkflowApi;
1112
- get agents(): WorkflowAgents;
1113
819
  }
1114
820
 
1115
821
  /**
@@ -1223,6 +929,9 @@ type DetailedFinishCondition = {
1223
929
  } | {
1224
930
  condition: "non-retryable-error";
1225
931
  result: WorkflowNonRetryableError;
932
+ } | {
933
+ condition: "retry-after-error";
934
+ result: WorkflowRetryAfterError;
1226
935
  } | {
1227
936
  condition: "failure-callback";
1228
937
  result: string | void;
@@ -1282,7 +991,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1282
991
  * @returns void
1283
992
  */
1284
993
  failureFunction?: (failureData: {
1285
- context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api" | "invoke" | "agents">;
994
+ context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api" | "invoke">;
1286
995
  failStatus: number;
1287
996
  failResponse: string;
1288
997
  failHeaders: Record<string, string[]>;
@@ -1628,4 +1337,4 @@ type InvokableWorkflow<TInitialPayload, TResult> = {
1628
1337
  workflowId?: string;
1629
1338
  };
1630
1339
 
1631
- export { type AsyncStepFunction as A, type WorkflowLoggerOptions as B, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, WorkflowLogger as G, 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 Duration as t, type WaitEventOptions as u, type StringifyBody as v, type CallSettings as w, type InvokeStepResponse as x, type InvokableWorkflow as y, type LogLevel as z };
1340
+ export { type AsyncStepFunction as A, type WorkflowLoggerOptions as B, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, WorkflowLogger as G, 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, WorkflowRetryAfterError 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 Duration as t, type WaitEventOptions as u, type StringifyBody as v, type CallSettings as w, type InvokeStepResponse as x, type InvokableWorkflow as y, type LogLevel as z };