@mastra/core 0.6.1-alpha.1 → 0.6.1-alpha.2
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/dist/agent/index.d.cts +3 -1
- package/dist/agent/index.d.ts +3 -1
- package/dist/{base-D8JxJ6GC.d.cts → base-BNtyxqTf.d.cts} +463 -10
- package/dist/{base-CnxSa6Qc.d.ts → base-C1_KzNZ3.d.ts} +463 -10
- package/dist/{chunk-U4EAGYCS.js → chunk-2BT7KDXB.js} +247 -124
- package/dist/{chunk-MEPD3EOI.cjs → chunk-VA3TRXPD.cjs} +247 -124
- package/dist/eval/index.d.cts +3 -1
- package/dist/eval/index.d.ts +3 -1
- package/dist/index.cjs +17 -17
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -2
- package/dist/integration/index.d.cts +3 -1
- package/dist/integration/index.d.ts +3 -1
- package/dist/llm/index.d.cts +3 -1
- package/dist/llm/index.d.ts +3 -1
- package/dist/mastra/index.d.cts +3 -1
- package/dist/mastra/index.d.ts +3 -1
- package/dist/memory/index.d.cts +3 -1
- package/dist/memory/index.d.ts +3 -1
- package/dist/relevance/index.d.cts +3 -1
- package/dist/relevance/index.d.ts +3 -1
- package/dist/storage/index.d.cts +3 -1
- package/dist/storage/index.d.ts +3 -1
- package/dist/storage/libsql/index.d.cts +3 -1
- package/dist/storage/libsql/index.d.ts +3 -1
- package/dist/telemetry/index.d.cts +3 -1
- package/dist/telemetry/index.d.ts +3 -1
- package/dist/tools/index.d.cts +4 -2
- package/dist/tools/index.d.ts +4 -2
- package/dist/utils.d.cts +4 -2
- package/dist/utils.d.ts +4 -2
- package/dist/voice/index.d.cts +3 -1
- package/dist/voice/index.d.ts +3 -1
- package/dist/workflows/index.cjs +17 -17
- package/dist/workflows/index.d.cts +4 -2
- package/dist/workflows/index.d.ts +4 -2
- package/dist/workflows/index.js +1 -1
- package/package.json +1 -1
package/dist/agent/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent, l as AgentConfig, aD as AgentGenerateOptions, aE as AgentStreamOptions, aw as MastraLanguageModel, a as ToolsInput, aC as ToolsetsInput } from '../base-
|
|
4
|
+
export { A as Agent, l as AgentConfig, aD as AgentGenerateOptions, aE as AgentStreamOptions, aw as MastraLanguageModel, a as ToolsInput, aC as ToolsetsInput } from '../base-BNtyxqTf.cjs';
|
|
5
5
|
import '../base-DboIg_Cd.cjs';
|
|
6
6
|
import '../types-CwTG2XyQ.cjs';
|
|
7
7
|
import 'sift';
|
|
@@ -14,4 +14,6 @@ import '@opentelemetry/api';
|
|
|
14
14
|
import '@opentelemetry/sdk-trace-base';
|
|
15
15
|
import '../vector/index.cjs';
|
|
16
16
|
import '../vector/filter/index.cjs';
|
|
17
|
+
import 'xstate';
|
|
18
|
+
import 'node:events';
|
|
17
19
|
import '../tts/index.cjs';
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent, l as AgentConfig, aD as AgentGenerateOptions, aE as AgentStreamOptions, aw as MastraLanguageModel, a as ToolsInput, aC as ToolsetsInput } from '../base-
|
|
4
|
+
export { A as Agent, l as AgentConfig, aD as AgentGenerateOptions, aE as AgentStreamOptions, aw as MastraLanguageModel, a as ToolsInput, aC as ToolsetsInput } from '../base-C1_KzNZ3.js';
|
|
5
5
|
import '../base-BZViaFTt.js';
|
|
6
6
|
import '../types-CwTG2XyQ.js';
|
|
7
7
|
import 'sift';
|
|
@@ -14,4 +14,6 @@ import '@opentelemetry/api';
|
|
|
14
14
|
import '@opentelemetry/sdk-trace-base';
|
|
15
15
|
import '../vector/index.js';
|
|
16
16
|
import '../vector/filter/index.js';
|
|
17
|
+
import 'xstate';
|
|
18
|
+
import 'node:events';
|
|
17
19
|
import '../tts/index.js';
|
|
@@ -9,6 +9,9 @@ import { B as BaseLogMessage, R as RegisteredLogger, L as Logger, d as Run } fro
|
|
|
9
9
|
import { MastraDeployer } from './deployer/index.cjs';
|
|
10
10
|
import { MastraVector } from './vector/index.cjs';
|
|
11
11
|
import { Span } from '@opentelemetry/api';
|
|
12
|
+
import * as xstate from 'xstate';
|
|
13
|
+
import { Snapshot } from 'xstate';
|
|
14
|
+
import EventEmitter from 'node:events';
|
|
12
15
|
import { MastraTTS } from './tts/index.cjs';
|
|
13
16
|
|
|
14
17
|
type VercelTool = Tool;
|
|
@@ -189,7 +192,9 @@ interface WorkflowOptions<TTriggerSchema extends z.ZodObject<any> = any> {
|
|
|
189
192
|
mastra?: Mastra;
|
|
190
193
|
}
|
|
191
194
|
interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
|
|
192
|
-
context: TSchemaIn extends z.ZodSchema ?
|
|
195
|
+
context: TSchemaIn extends z.ZodSchema ? {
|
|
196
|
+
inputData: z.infer<TSchemaIn>;
|
|
197
|
+
} & TContext : TContext;
|
|
193
198
|
suspend: (payload?: unknown) => Promise<void>;
|
|
194
199
|
runId: string;
|
|
195
200
|
mastra?: MastraUnion;
|
|
@@ -258,6 +263,8 @@ type StepDef<TStepId extends TSteps[number]['id'], TSteps extends StepAction<any
|
|
|
258
263
|
mastra?: Mastra;
|
|
259
264
|
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
260
265
|
serializedWhen?: Condition<any, any> | string;
|
|
266
|
+
loopLabel?: string;
|
|
267
|
+
loopType?: 'when' | 'until';
|
|
261
268
|
data: TSchemaIn;
|
|
262
269
|
handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
|
|
263
270
|
}>;
|
|
@@ -283,6 +290,14 @@ interface StepConfig<TStep extends StepAction<any, any, any, any>, CondStep exte
|
|
|
283
290
|
variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference<VarStep, TTriggerSchema>> : {
|
|
284
291
|
[K in keyof StepInputType<TStep, 'inputSchema'>]?: VariableReference<VarStep, TTriggerSchema>;
|
|
285
292
|
};
|
|
293
|
+
'#internal'?: {
|
|
294
|
+
when?: Condition<CondStep, TTriggerSchema> | ((args: {
|
|
295
|
+
context: WorkflowContext<TTriggerSchema, TSteps>;
|
|
296
|
+
mastra?: Mastra;
|
|
297
|
+
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
298
|
+
loopLabel?: string;
|
|
299
|
+
loopType?: 'when' | 'until';
|
|
300
|
+
};
|
|
286
301
|
}
|
|
287
302
|
type StepSuccess<T> = {
|
|
288
303
|
status: 'success';
|
|
@@ -319,13 +334,13 @@ interface WorkflowRunResult<T extends z.ZodType<any>, TSteps extends Step<string
|
|
|
319
334
|
suspendPayload?: any;
|
|
320
335
|
}>;
|
|
321
336
|
}
|
|
322
|
-
interface WorkflowContext<TTrigger extends z.ZodObject<any> = any, TSteps extends Step<string, any, any, any>[] = Step<string, any, any, any>[]> {
|
|
337
|
+
interface WorkflowContext<TTrigger extends z.ZodObject<any> = any, TSteps extends Step<string, any, any, any>[] = Step<string, any, any, any>[], TInputData extends Record<string, any> = Record<string, any>> {
|
|
323
338
|
mastra?: MastraUnion;
|
|
324
339
|
steps: {
|
|
325
340
|
[K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
|
|
326
341
|
};
|
|
327
342
|
triggerData: z.infer<TTrigger>;
|
|
328
|
-
|
|
343
|
+
inputData: TInputData;
|
|
329
344
|
attempts: Record<string, number>;
|
|
330
345
|
getStepResult(stepId: 'trigger'): z.infer<TTrigger>;
|
|
331
346
|
getStepResult<T extends keyof StepsRecord<TSteps> | unknown>(stepId: T extends keyof StepsRecord<TSteps> ? T : string): T extends keyof StepsRecord<TSteps> ? StepsRecord<TSteps>[T]['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<StepsRecord<TSteps>[T]['outputSchema']>> : T;
|
|
@@ -526,11 +541,441 @@ type WorkflowResumeResult<TTriggerSchema extends z.ZodObject<any>> = {
|
|
|
526
541
|
results: Record<string, StepResult<any>>;
|
|
527
542
|
};
|
|
528
543
|
|
|
544
|
+
declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any> extends EventEmitter {
|
|
545
|
+
#private;
|
|
546
|
+
logger: Logger;
|
|
547
|
+
name: string;
|
|
548
|
+
constructor({ logger, mastra, workflowInstance, executionSpan, name, runId, steps, stepGraph, retryConfig, startStepId, }: {
|
|
549
|
+
logger: Logger;
|
|
550
|
+
mastra?: Mastra;
|
|
551
|
+
workflowInstance: WorkflowInstance;
|
|
552
|
+
executionSpan?: Span;
|
|
553
|
+
name: string;
|
|
554
|
+
runId: string;
|
|
555
|
+
steps: Record<string, TSteps[0]>;
|
|
556
|
+
stepGraph: StepGraph;
|
|
557
|
+
retryConfig?: RetryConfig;
|
|
558
|
+
startStepId: string;
|
|
559
|
+
});
|
|
560
|
+
get startStepId(): string;
|
|
561
|
+
execute({ stepId, input, snapshot, resumeData, }?: {
|
|
562
|
+
stepId?: string;
|
|
563
|
+
input?: any;
|
|
564
|
+
snapshot?: Snapshot<any>;
|
|
565
|
+
resumeData?: any;
|
|
566
|
+
}): Promise<Pick<WorkflowRunResult<TTriggerSchema, TSteps>, 'results' | 'activePaths'>>;
|
|
567
|
+
private initializeMachine;
|
|
568
|
+
getSnapshot(): xstate.MachineSnapshot<Omit<WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>, "getStepResult">, {
|
|
569
|
+
type: "RESET_TO_PENDING";
|
|
570
|
+
stepId: string;
|
|
571
|
+
} | {
|
|
572
|
+
type: "CONDITIONS_MET";
|
|
573
|
+
stepId: string;
|
|
574
|
+
} | {
|
|
575
|
+
type: "CONDITION_FAILED";
|
|
576
|
+
stepId: string;
|
|
577
|
+
error: string;
|
|
578
|
+
} | {
|
|
579
|
+
type: "SUSPENDED";
|
|
580
|
+
stepId: string;
|
|
581
|
+
suspendPayload?: any;
|
|
582
|
+
} | {
|
|
583
|
+
type: "WAITING";
|
|
584
|
+
stepId: string;
|
|
585
|
+
} | {
|
|
586
|
+
type: `xstate.error.actor.${string}`;
|
|
587
|
+
error: Error;
|
|
588
|
+
} | {
|
|
589
|
+
type: `xstate.done.actor.${string}`;
|
|
590
|
+
output: ResolverFunctionOutput;
|
|
591
|
+
}, {
|
|
592
|
+
[x: string]: xstate.ActorRefFromLogic<xstate.PromiseActorLogic<{
|
|
593
|
+
type: "CONDITIONS_MET";
|
|
594
|
+
error?: undefined;
|
|
595
|
+
} | {
|
|
596
|
+
type: "CONDITIONS_SKIP_TO_COMPLETED";
|
|
597
|
+
error?: undefined;
|
|
598
|
+
} | {
|
|
599
|
+
type: "CONDITIONS_LIMBO";
|
|
600
|
+
error?: undefined;
|
|
601
|
+
} | {
|
|
602
|
+
type: "CONDITIONS_SKIPPED";
|
|
603
|
+
error?: undefined;
|
|
604
|
+
} | {
|
|
605
|
+
type: "CONDITION_FAILED";
|
|
606
|
+
error: string;
|
|
607
|
+
}, {
|
|
608
|
+
context: WorkflowContext;
|
|
609
|
+
stepNode: StepNode;
|
|
610
|
+
}, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<{
|
|
611
|
+
type: "STEP_FAILED";
|
|
612
|
+
error: string;
|
|
613
|
+
stepId: any;
|
|
614
|
+
result?: undefined;
|
|
615
|
+
} | {
|
|
616
|
+
type: "STEP_WAITING";
|
|
617
|
+
stepId: any;
|
|
618
|
+
error?: undefined;
|
|
619
|
+
result?: undefined;
|
|
620
|
+
} | {
|
|
621
|
+
type: "STEP_SUCCESS";
|
|
622
|
+
result: any;
|
|
623
|
+
stepId: any;
|
|
624
|
+
error?: undefined;
|
|
625
|
+
}, ResolverFunctionInput, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<{
|
|
626
|
+
steps: {};
|
|
627
|
+
}, {
|
|
628
|
+
parentStepId: string;
|
|
629
|
+
context: WorkflowContext;
|
|
630
|
+
}, xstate.EventObject>> | undefined;
|
|
631
|
+
}, {
|
|
632
|
+
[x: string]: {} | {
|
|
633
|
+
[x: string]: {} | /*elided*/ any | {
|
|
634
|
+
[x: string]: {} | /*elided*/ any | /*elided*/ any;
|
|
635
|
+
};
|
|
636
|
+
} | {
|
|
637
|
+
[x: string]: {} | {
|
|
638
|
+
[x: string]: {} | /*elided*/ any | /*elided*/ any;
|
|
639
|
+
} | /*elided*/ any;
|
|
640
|
+
};
|
|
641
|
+
}, string, xstate.NonReducibleUnknown, xstate.MetaObject, {
|
|
642
|
+
readonly id: string;
|
|
643
|
+
readonly type: "parallel";
|
|
644
|
+
readonly context: ({ input }: {
|
|
645
|
+
spawn: {
|
|
646
|
+
<TSrc extends "conditionCheck" | "resolverFunction" | "spawnSubscriberFunction">(logic: TSrc, ...[options]: ({
|
|
647
|
+
src: "conditionCheck";
|
|
648
|
+
logic: xstate.PromiseActorLogic<{
|
|
649
|
+
type: "CONDITIONS_MET";
|
|
650
|
+
error?: undefined;
|
|
651
|
+
} | {
|
|
652
|
+
type: "CONDITIONS_SKIP_TO_COMPLETED";
|
|
653
|
+
error?: undefined;
|
|
654
|
+
} | {
|
|
655
|
+
type: "CONDITIONS_LIMBO";
|
|
656
|
+
error?: undefined;
|
|
657
|
+
} | {
|
|
658
|
+
type: "CONDITIONS_SKIPPED";
|
|
659
|
+
error?: undefined;
|
|
660
|
+
} | {
|
|
661
|
+
type: "CONDITION_FAILED";
|
|
662
|
+
error: string;
|
|
663
|
+
}, {
|
|
664
|
+
context: WorkflowContext;
|
|
665
|
+
stepNode: StepNode;
|
|
666
|
+
}, xstate.EventObject>;
|
|
667
|
+
id: string | undefined;
|
|
668
|
+
} extends infer T ? T extends {
|
|
669
|
+
src: "conditionCheck";
|
|
670
|
+
logic: xstate.PromiseActorLogic<{
|
|
671
|
+
type: "CONDITIONS_MET";
|
|
672
|
+
error?: undefined;
|
|
673
|
+
} | {
|
|
674
|
+
type: "CONDITIONS_SKIP_TO_COMPLETED";
|
|
675
|
+
error?: undefined;
|
|
676
|
+
} | {
|
|
677
|
+
type: "CONDITIONS_LIMBO";
|
|
678
|
+
error?: undefined;
|
|
679
|
+
} | {
|
|
680
|
+
type: "CONDITIONS_SKIPPED";
|
|
681
|
+
error?: undefined;
|
|
682
|
+
} | {
|
|
683
|
+
type: "CONDITION_FAILED";
|
|
684
|
+
error: string;
|
|
685
|
+
}, {
|
|
686
|
+
context: WorkflowContext;
|
|
687
|
+
stepNode: StepNode;
|
|
688
|
+
}, xstate.EventObject>;
|
|
689
|
+
id: string | undefined;
|
|
690
|
+
} ? T extends {
|
|
691
|
+
src: TSrc;
|
|
692
|
+
} ? xstate.ConditionalRequired<[options?: ({
|
|
693
|
+
id?: T["id"] | undefined;
|
|
694
|
+
systemId?: string;
|
|
695
|
+
input?: xstate.InputFrom<T["logic"]> | undefined;
|
|
696
|
+
syncSnapshot?: boolean;
|
|
697
|
+
} & { [K in xstate.RequiredActorOptions<T>]: unknown; }) | undefined], xstate.IsNotNever<xstate.RequiredActorOptions<T>>> : never : never : never) | ({
|
|
698
|
+
src: "resolverFunction";
|
|
699
|
+
logic: xstate.PromiseActorLogic<{
|
|
700
|
+
type: "STEP_FAILED";
|
|
701
|
+
error: string;
|
|
702
|
+
stepId: any;
|
|
703
|
+
result?: undefined;
|
|
704
|
+
} | {
|
|
705
|
+
type: "STEP_WAITING";
|
|
706
|
+
stepId: any;
|
|
707
|
+
error?: undefined;
|
|
708
|
+
result?: undefined;
|
|
709
|
+
} | {
|
|
710
|
+
type: "STEP_SUCCESS";
|
|
711
|
+
result: any;
|
|
712
|
+
stepId: any;
|
|
713
|
+
error?: undefined;
|
|
714
|
+
}, ResolverFunctionInput, xstate.EventObject>;
|
|
715
|
+
id: string | undefined;
|
|
716
|
+
} extends infer T_1 ? T_1 extends {
|
|
717
|
+
src: "resolverFunction";
|
|
718
|
+
logic: xstate.PromiseActorLogic<{
|
|
719
|
+
type: "STEP_FAILED";
|
|
720
|
+
error: string;
|
|
721
|
+
stepId: any;
|
|
722
|
+
result?: undefined;
|
|
723
|
+
} | {
|
|
724
|
+
type: "STEP_WAITING";
|
|
725
|
+
stepId: any;
|
|
726
|
+
error?: undefined;
|
|
727
|
+
result?: undefined;
|
|
728
|
+
} | {
|
|
729
|
+
type: "STEP_SUCCESS";
|
|
730
|
+
result: any;
|
|
731
|
+
stepId: any;
|
|
732
|
+
error?: undefined;
|
|
733
|
+
}, ResolverFunctionInput, xstate.EventObject>;
|
|
734
|
+
id: string | undefined;
|
|
735
|
+
} ? T_1 extends {
|
|
736
|
+
src: TSrc;
|
|
737
|
+
} ? xstate.ConditionalRequired<[options?: ({
|
|
738
|
+
id?: T_1["id"] | undefined;
|
|
739
|
+
systemId?: string;
|
|
740
|
+
input?: xstate.InputFrom<T_1["logic"]> | undefined;
|
|
741
|
+
syncSnapshot?: boolean;
|
|
742
|
+
} & { [K_1 in xstate.RequiredActorOptions<T_1>]: unknown; }) | undefined], xstate.IsNotNever<xstate.RequiredActorOptions<T_1>>> : never : never : never) | ({
|
|
743
|
+
src: "spawnSubscriberFunction";
|
|
744
|
+
logic: xstate.PromiseActorLogic<{
|
|
745
|
+
steps: {};
|
|
746
|
+
}, {
|
|
747
|
+
parentStepId: string;
|
|
748
|
+
context: WorkflowContext;
|
|
749
|
+
}, xstate.EventObject>;
|
|
750
|
+
id: string | undefined;
|
|
751
|
+
} extends infer T_2 ? T_2 extends {
|
|
752
|
+
src: "spawnSubscriberFunction";
|
|
753
|
+
logic: xstate.PromiseActorLogic<{
|
|
754
|
+
steps: {};
|
|
755
|
+
}, {
|
|
756
|
+
parentStepId: string;
|
|
757
|
+
context: WorkflowContext;
|
|
758
|
+
}, xstate.EventObject>;
|
|
759
|
+
id: string | undefined;
|
|
760
|
+
} ? T_2 extends {
|
|
761
|
+
src: TSrc;
|
|
762
|
+
} ? xstate.ConditionalRequired<[options?: ({
|
|
763
|
+
id?: T_2["id"] | undefined;
|
|
764
|
+
systemId?: string;
|
|
765
|
+
input?: xstate.InputFrom<T_2["logic"]> | undefined;
|
|
766
|
+
syncSnapshot?: boolean;
|
|
767
|
+
} & { [K_2 in xstate.RequiredActorOptions<T_2>]: unknown; }) | undefined], xstate.IsNotNever<xstate.RequiredActorOptions<T_2>>> : never : never : never)): xstate.ActorRefFromLogic<xstate.GetConcreteByKey<xstate.Values<{
|
|
768
|
+
conditionCheck: {
|
|
769
|
+
src: "conditionCheck";
|
|
770
|
+
logic: xstate.PromiseActorLogic<{
|
|
771
|
+
type: "CONDITIONS_MET";
|
|
772
|
+
error?: undefined;
|
|
773
|
+
} | {
|
|
774
|
+
type: "CONDITIONS_SKIP_TO_COMPLETED";
|
|
775
|
+
error?: undefined;
|
|
776
|
+
} | {
|
|
777
|
+
type: "CONDITIONS_LIMBO";
|
|
778
|
+
error?: undefined;
|
|
779
|
+
} | {
|
|
780
|
+
type: "CONDITIONS_SKIPPED";
|
|
781
|
+
error?: undefined;
|
|
782
|
+
} | {
|
|
783
|
+
type: "CONDITION_FAILED";
|
|
784
|
+
error: string;
|
|
785
|
+
}, {
|
|
786
|
+
context: WorkflowContext;
|
|
787
|
+
stepNode: StepNode;
|
|
788
|
+
}, xstate.EventObject>;
|
|
789
|
+
id: string | undefined;
|
|
790
|
+
};
|
|
791
|
+
resolverFunction: {
|
|
792
|
+
src: "resolverFunction";
|
|
793
|
+
logic: xstate.PromiseActorLogic<{
|
|
794
|
+
type: "STEP_FAILED";
|
|
795
|
+
error: string;
|
|
796
|
+
stepId: any;
|
|
797
|
+
result?: undefined;
|
|
798
|
+
} | {
|
|
799
|
+
type: "STEP_WAITING";
|
|
800
|
+
stepId: any;
|
|
801
|
+
error?: undefined;
|
|
802
|
+
result?: undefined;
|
|
803
|
+
} | {
|
|
804
|
+
type: "STEP_SUCCESS";
|
|
805
|
+
result: any;
|
|
806
|
+
stepId: any;
|
|
807
|
+
error?: undefined;
|
|
808
|
+
}, ResolverFunctionInput, xstate.EventObject>;
|
|
809
|
+
id: string | undefined;
|
|
810
|
+
};
|
|
811
|
+
spawnSubscriberFunction: {
|
|
812
|
+
src: "spawnSubscriberFunction";
|
|
813
|
+
logic: xstate.PromiseActorLogic<{
|
|
814
|
+
steps: {};
|
|
815
|
+
}, {
|
|
816
|
+
parentStepId: string;
|
|
817
|
+
context: WorkflowContext;
|
|
818
|
+
}, xstate.EventObject>;
|
|
819
|
+
id: string | undefined;
|
|
820
|
+
};
|
|
821
|
+
}>, "src", TSrc>["logic"]>;
|
|
822
|
+
<TLogic extends xstate.AnyActorLogic>(src: TLogic, ...[options]: xstate.ConditionalRequired<[options?: ({
|
|
823
|
+
id?: never;
|
|
824
|
+
systemId?: string;
|
|
825
|
+
input?: xstate.InputFrom<TLogic> | undefined;
|
|
826
|
+
syncSnapshot?: boolean;
|
|
827
|
+
} & { [K in xstate.RequiredLogicInput<TLogic>]: unknown; }) | undefined], xstate.IsNotNever<xstate.RequiredLogicInput<TLogic>>>): xstate.ActorRefFromLogic<TLogic>;
|
|
828
|
+
};
|
|
829
|
+
input: Omit<WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>, "getStepResult">;
|
|
830
|
+
self: xstate.ActorRef<xstate.MachineSnapshot<Omit<WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>, "getStepResult">, {
|
|
831
|
+
type: "RESET_TO_PENDING";
|
|
832
|
+
stepId: string;
|
|
833
|
+
} | {
|
|
834
|
+
type: "CONDITIONS_MET";
|
|
835
|
+
stepId: string;
|
|
836
|
+
} | {
|
|
837
|
+
type: "CONDITION_FAILED";
|
|
838
|
+
stepId: string;
|
|
839
|
+
error: string;
|
|
840
|
+
} | {
|
|
841
|
+
type: "SUSPENDED";
|
|
842
|
+
stepId: string;
|
|
843
|
+
suspendPayload?: any;
|
|
844
|
+
} | {
|
|
845
|
+
type: "WAITING";
|
|
846
|
+
stepId: string;
|
|
847
|
+
} | {
|
|
848
|
+
type: `xstate.error.actor.${string}`;
|
|
849
|
+
error: Error;
|
|
850
|
+
} | {
|
|
851
|
+
type: `xstate.done.actor.${string}`;
|
|
852
|
+
output: ResolverFunctionOutput;
|
|
853
|
+
}, Record<string, xstate.AnyActorRef | undefined>, xstate.StateValue, string, unknown, any, any>, {
|
|
854
|
+
type: "RESET_TO_PENDING";
|
|
855
|
+
stepId: string;
|
|
856
|
+
} | {
|
|
857
|
+
type: "CONDITIONS_MET";
|
|
858
|
+
stepId: string;
|
|
859
|
+
} | {
|
|
860
|
+
type: "CONDITION_FAILED";
|
|
861
|
+
stepId: string;
|
|
862
|
+
error: string;
|
|
863
|
+
} | {
|
|
864
|
+
type: "SUSPENDED";
|
|
865
|
+
stepId: string;
|
|
866
|
+
suspendPayload?: any;
|
|
867
|
+
} | {
|
|
868
|
+
type: "WAITING";
|
|
869
|
+
stepId: string;
|
|
870
|
+
} | {
|
|
871
|
+
type: `xstate.error.actor.${string}`;
|
|
872
|
+
error: Error;
|
|
873
|
+
} | {
|
|
874
|
+
type: `xstate.done.actor.${string}`;
|
|
875
|
+
output: ResolverFunctionOutput;
|
|
876
|
+
}, xstate.AnyEventObject>;
|
|
877
|
+
}) => {
|
|
878
|
+
mastra?: MastraUnion | undefined;
|
|
879
|
+
steps: {
|
|
880
|
+
[x: string]: {
|
|
881
|
+
status: "failed";
|
|
882
|
+
error: string;
|
|
883
|
+
} | {
|
|
884
|
+
status: "suspended";
|
|
885
|
+
suspendPayload?: any;
|
|
886
|
+
} | {
|
|
887
|
+
status: "waiting";
|
|
888
|
+
} | {
|
|
889
|
+
status: "skipped";
|
|
890
|
+
} | {
|
|
891
|
+
status: "success";
|
|
892
|
+
output: unknown;
|
|
893
|
+
} | {
|
|
894
|
+
status: "success";
|
|
895
|
+
output: any;
|
|
896
|
+
};
|
|
897
|
+
};
|
|
898
|
+
triggerData: any;
|
|
899
|
+
inputData: Record<string, any>;
|
|
900
|
+
attempts: Record<string, number>;
|
|
901
|
+
};
|
|
902
|
+
readonly states: any;
|
|
903
|
+
}> | undefined;
|
|
904
|
+
}
|
|
905
|
+
|
|
529
906
|
interface WorkflowResultReturn<T extends z.ZodType<any>, TSteps extends Step<any, any, any>[]> {
|
|
530
907
|
runId: string;
|
|
531
908
|
start: (props?: {
|
|
532
909
|
triggerData?: z.infer<T>;
|
|
533
910
|
} | undefined) => Promise<WorkflowRunResult<T, TSteps>>;
|
|
911
|
+
watch: (onTransition: (state: WorkflowRunState) => void) => () => void;
|
|
912
|
+
resume: (props: {
|
|
913
|
+
stepId: string;
|
|
914
|
+
context?: Record<string, any>;
|
|
915
|
+
}) => Promise<Omit<WorkflowRunResult<T, TSteps>, 'runId'> | undefined>;
|
|
916
|
+
resumeWithEvent: (eventName: string, data: any) => Promise<Omit<WorkflowRunResult<T, TSteps>, 'runId'> | undefined>;
|
|
917
|
+
}
|
|
918
|
+
declare class WorkflowInstance<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any> implements WorkflowResultReturn<TTriggerSchema, TSteps> {
|
|
919
|
+
#private;
|
|
920
|
+
name: string;
|
|
921
|
+
logger: Logger;
|
|
922
|
+
events?: Record<string, {
|
|
923
|
+
schema: z.ZodObject<any>;
|
|
924
|
+
}>;
|
|
925
|
+
constructor({ name, logger, steps, runId, retryConfig, mastra, stepGraph, stepSubscriberGraph, onFinish, onStepTransition, events, }: {
|
|
926
|
+
name: string;
|
|
927
|
+
logger: Logger;
|
|
928
|
+
steps: Record<string, StepAction<any, any, any, any>>;
|
|
929
|
+
mastra?: Mastra;
|
|
930
|
+
retryConfig?: RetryConfig;
|
|
931
|
+
runId?: string;
|
|
932
|
+
stepGraph: StepGraph;
|
|
933
|
+
stepSubscriberGraph: Record<string, StepGraph>;
|
|
934
|
+
onFinish?: () => void;
|
|
935
|
+
onStepTransition?: Set<(state: WorkflowRunState) => void | Promise<void>>;
|
|
936
|
+
events?: Record<string, {
|
|
937
|
+
schema: z.ZodObject<any>;
|
|
938
|
+
}>;
|
|
939
|
+
});
|
|
940
|
+
setState(state: any): void;
|
|
941
|
+
get runId(): string;
|
|
942
|
+
get executionSpan(): Span | undefined;
|
|
943
|
+
watch(onTransition: (state: WorkflowRunState) => void): () => void;
|
|
944
|
+
start({ triggerData }?: {
|
|
945
|
+
triggerData?: z.infer<TTriggerSchema>;
|
|
946
|
+
}): Promise<{
|
|
947
|
+
runId: string;
|
|
948
|
+
triggerData?: z.TypeOf<TTriggerSchema> | undefined;
|
|
949
|
+
results: { [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]["outputSchema"] extends undefined ? StepResult<unknown> : StepResult<z.TypeOf<NonNullable<StepsRecord<TSteps>[K]["outputSchema"]>>>; };
|
|
950
|
+
activePaths: Map<TSteps[number]["id"], {
|
|
951
|
+
status: string;
|
|
952
|
+
suspendPayload?: any;
|
|
953
|
+
}>;
|
|
954
|
+
}>;
|
|
955
|
+
private isCompoundDependencyMet;
|
|
956
|
+
execute({ triggerData, snapshot, stepId, resumeData, }?: {
|
|
957
|
+
stepId?: string;
|
|
958
|
+
triggerData?: z.infer<TTriggerSchema>;
|
|
959
|
+
snapshot?: Snapshot<any>;
|
|
960
|
+
resumeData?: any;
|
|
961
|
+
}): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, 'runId'>>;
|
|
962
|
+
hasSubscribers(stepId: string): boolean;
|
|
963
|
+
runMachine(parentStepId: string, input: any): Promise<(Pick<WorkflowRunResult<any, any>, "results" | "activePaths"> | undefined)[]>;
|
|
964
|
+
suspend(stepId: string, machine: Machine<TSteps, TTriggerSchema>): Promise<void>;
|
|
965
|
+
/**
|
|
966
|
+
* Persists the workflow state to the database
|
|
967
|
+
*/
|
|
968
|
+
persistWorkflowSnapshot(): Promise<void>;
|
|
969
|
+
getState(): Promise<WorkflowRunState | null>;
|
|
970
|
+
resumeWithEvent(eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
|
|
971
|
+
resume({ stepId, context: resumeContext }: {
|
|
972
|
+
stepId: string;
|
|
973
|
+
context?: Record<string, any>;
|
|
974
|
+
}): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
|
|
975
|
+
_resume({ stepId, context: resumeContext }: {
|
|
976
|
+
stepId: string;
|
|
977
|
+
context?: Record<string, any>;
|
|
978
|
+
}): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
|
|
534
979
|
}
|
|
535
980
|
|
|
536
981
|
declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TTriggerSchema extends z.ZodObject<any> = any> extends MastraBase {
|
|
@@ -561,7 +1006,18 @@ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, an
|
|
|
561
1006
|
* @returns Promise resolving to workflow results or rejecting with error
|
|
562
1007
|
* @throws Error if trigger schema validation fails
|
|
563
1008
|
*/
|
|
564
|
-
createRun(
|
|
1009
|
+
createRun({ runId, events, }?: {
|
|
1010
|
+
runId?: string;
|
|
1011
|
+
events?: Record<string, {
|
|
1012
|
+
schema: z.ZodObject<any>;
|
|
1013
|
+
}>;
|
|
1014
|
+
}): WorkflowResultReturn<TTriggerSchema, TSteps>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Gets a workflow run instance by ID
|
|
1017
|
+
* @param runId - ID of the run to retrieve
|
|
1018
|
+
* @returns The workflow run instance if found, undefined otherwise
|
|
1019
|
+
*/
|
|
1020
|
+
getRun(runId: string): WorkflowInstance<TSteps, TTriggerSchema> | undefined;
|
|
565
1021
|
/**
|
|
566
1022
|
* Rebuilds the machine with the current steps configuration and validates the workflow
|
|
567
1023
|
*
|
|
@@ -573,22 +1029,19 @@ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, an
|
|
|
573
1029
|
commit(): this;
|
|
574
1030
|
getExecutionSpan(runId: string): Span | undefined;
|
|
575
1031
|
getState(runId: string): Promise<WorkflowRunState | null>;
|
|
576
|
-
watch(onTransition: (state: WorkflowRunState) => void): () => void;
|
|
577
1032
|
resume({ runId, stepId, context: resumeContext, }: {
|
|
578
1033
|
runId: string;
|
|
579
1034
|
stepId: string;
|
|
580
1035
|
context?: Record<string, any>;
|
|
581
1036
|
}): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
|
|
582
|
-
|
|
583
|
-
runId: string;
|
|
584
|
-
stepId: string;
|
|
585
|
-
context?: Record<string, any>;
|
|
586
|
-
}): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
|
|
1037
|
+
watch(onTransition: (state: WorkflowRunState) => void): () => void;
|
|
587
1038
|
resumeWithEvent(runId: string, eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
|
|
588
1039
|
__registerMastra(mastra: Mastra): void;
|
|
589
1040
|
__registerPrimitives(p: MastraPrimitives): void;
|
|
590
1041
|
get stepGraph(): StepGraph;
|
|
591
1042
|
get stepSubscriberGraph(): Record<string, StepGraph>;
|
|
1043
|
+
get serializedStepGraph(): StepGraph;
|
|
1044
|
+
get serializedStepSubscriberGraph(): Record<string, StepGraph>;
|
|
592
1045
|
get steps(): Record<string, StepAction<any, any, any, any>>;
|
|
593
1046
|
}
|
|
594
1047
|
|