@mastra/client-js 0.1.18 → 0.1.19-alpha.1

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @mastra/client-js@0.1.18-alpha.8 build /home/runner/work/mastra/mastra/client-sdks/client-js
2
+ > @mastra/client-js@0.1.19-alpha.1 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
3
  > tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,11 +9,11 @@
9
9
  CLI Cleaning output folder
10
10
  ESM Build start
11
11
  CJS Build start
12
- CJS dist/index.cjs 21.79 KB
13
- CJS ⚡️ Build success in 1200ms
14
- ESM dist/index.js 21.61 KB
15
- ESM ⚡️ Build success in 1215ms
12
+ ESM dist/index.js 27.12 KB
13
+ ESM ⚡️ Build success in 995ms
14
+ CJS dist/index.cjs 27.30 KB
15
+ CJS ⚡️ Build success in 995ms
16
16
  DTS Build start
17
- DTS ⚡️ Build success in 13586ms
18
- DTS dist/index.d.ts 19.77 KB
19
- DTS dist/index.d.cts 19.77 KB
17
+ DTS ⚡️ Build success in 12809ms
18
+ DTS dist/index.d.ts 23.89 KB
19
+ DTS dist/index.d.cts 23.89 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 0.1.19-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b50b9b7: Add vNext workflow to client-js
8
+ - 11d4485: Show VNext workflows on the playground
9
+ Show running status for step in vNext workflowState
10
+ - Updated dependencies [20275d4]
11
+ - Updated dependencies [7d1892c]
12
+ - Updated dependencies [a90a082]
13
+ - Updated dependencies [35955b0]
14
+ - Updated dependencies [c1409ef]
15
+ - Updated dependencies [11d4485]
16
+ - Updated dependencies [2d4001d]
17
+ - @mastra/core@0.9.1-alpha.1
18
+
19
+ ## 0.1.19-alpha.0
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [81fb7f6]
24
+ - @mastra/core@0.9.1-alpha.0
25
+
3
26
  ## 0.1.18
4
27
 
5
28
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -550,6 +550,162 @@ var Tool = class extends BaseResource {
550
550
  }
551
551
  };
552
552
 
553
+ // src/resources/vnext-workflow.ts
554
+ var RECORD_SEPARATOR2 = "";
555
+ var VNextWorkflow = class extends BaseResource {
556
+ constructor(options, workflowId) {
557
+ super(options);
558
+ this.workflowId = workflowId;
559
+ }
560
+ /**
561
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
562
+ * separated by the Record Separator character (\x1E)
563
+ *
564
+ * @param stream - The readable stream to process
565
+ * @returns An async generator that yields parsed records
566
+ */
567
+ async *streamProcessor(stream) {
568
+ const reader = stream.getReader();
569
+ let doneReading = false;
570
+ let buffer = "";
571
+ try {
572
+ while (!doneReading) {
573
+ const { done, value } = await reader.read();
574
+ doneReading = done;
575
+ if (done && !value) continue;
576
+ try {
577
+ const decoded = value ? new TextDecoder().decode(value) : "";
578
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
579
+ buffer = chunks.pop() || "";
580
+ for (const chunk of chunks) {
581
+ if (chunk) {
582
+ if (typeof chunk === "string") {
583
+ try {
584
+ const parsedChunk = JSON.parse(chunk);
585
+ yield parsedChunk;
586
+ } catch {
587
+ }
588
+ }
589
+ }
590
+ }
591
+ } catch (error) {
592
+ }
593
+ }
594
+ if (buffer) {
595
+ try {
596
+ yield JSON.parse(buffer);
597
+ } catch {
598
+ }
599
+ }
600
+ } finally {
601
+ reader.cancel().catch(() => {
602
+ });
603
+ }
604
+ }
605
+ /**
606
+ * Retrieves details about the vNext workflow
607
+ * @returns Promise containing vNext workflow details including steps and graphs
608
+ */
609
+ details() {
610
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
611
+ }
612
+ /**
613
+ * Creates a new vNext workflow run
614
+ * @param params - Optional object containing the optional runId
615
+ * @returns Promise containing the runId of the created run
616
+ */
617
+ createRun(params) {
618
+ const searchParams = new URLSearchParams();
619
+ if (!!params?.runId) {
620
+ searchParams.set("runId", params.runId);
621
+ }
622
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
623
+ method: "POST"
624
+ });
625
+ }
626
+ /**
627
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
628
+ * @param params - Object containing the runId, inputData and runtimeContext
629
+ * @returns Promise containing success message
630
+ */
631
+ start(params) {
632
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
633
+ method: "POST",
634
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
635
+ });
636
+ }
637
+ /**
638
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
639
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
640
+ * @returns Promise containing success message
641
+ */
642
+ resume({
643
+ step,
644
+ runId,
645
+ resumeData,
646
+ runtimeContext
647
+ }) {
648
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
649
+ method: "POST",
650
+ stream: true,
651
+ body: {
652
+ step,
653
+ resumeData,
654
+ runtimeContext
655
+ }
656
+ });
657
+ }
658
+ /**
659
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
660
+ * @param params - Object containing the optional runId, inputData and runtimeContext
661
+ * @returns Promise containing the vNext workflow execution results
662
+ */
663
+ startAsync(params) {
664
+ const searchParams = new URLSearchParams();
665
+ if (!!params?.runId) {
666
+ searchParams.set("runId", params.runId);
667
+ }
668
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
669
+ method: "POST",
670
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
671
+ });
672
+ }
673
+ /**
674
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
675
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
676
+ * @returns Promise containing the vNext workflow resume results
677
+ */
678
+ resumeAsync(params) {
679
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
680
+ method: "POST",
681
+ body: {
682
+ step: params.step,
683
+ resumeData: params.resumeData,
684
+ runtimeContext: params.runtimeContext
685
+ }
686
+ });
687
+ }
688
+ /**
689
+ * Watches vNext workflow transitions in real-time
690
+ * @param runId - Optional run ID to filter the watch stream
691
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
692
+ */
693
+ async watch({ runId }, onRecord) {
694
+ const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
695
+ stream: true
696
+ });
697
+ if (!response.ok) {
698
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
699
+ }
700
+ if (!response.body) {
701
+ throw new Error("Response body is null");
702
+ }
703
+ for await (const record of this.streamProcessor(response.body)) {
704
+ onRecord(record);
705
+ }
706
+ }
707
+ };
708
+
553
709
  // src/client.ts
554
710
  var MastraClient = class extends BaseResource {
555
711
  constructor(options) {
@@ -642,6 +798,21 @@ var MastraClient = class extends BaseResource {
642
798
  getWorkflow(workflowId) {
643
799
  return new Workflow(this.options, workflowId);
644
800
  }
801
+ /**
802
+ * Retrieves all available vNext workflows
803
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
804
+ */
805
+ getVNextWorkflows() {
806
+ return this.request("/api/workflows/v-next");
807
+ }
808
+ /**
809
+ * Gets a vNext workflow instance by ID
810
+ * @param workflowId - ID of the vNext workflow to retrieve
811
+ * @returns vNext Workflow instance
812
+ */
813
+ getVNextWorkflow(workflowId) {
814
+ return new VNextWorkflow(this.options, workflowId);
815
+ }
645
816
  /**
646
817
  * Gets a vector instance by name
647
818
  * @param vectorName - Name of the vector to retrieve
package/dist/index.d.cts CHANGED
@@ -3,6 +3,8 @@ import { JSONSchema7 } from 'json-schema';
3
3
  import { ZodSchema } from 'zod';
4
4
  import { processDataStream } from '@ai-sdk/ui-utils';
5
5
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
6
+ import { NewWorkflow, WorkflowResult, WatchEvent } from '@mastra/core/workflows/vNext';
7
+ import { RuntimeContext } from '@mastra/core/runtime-context';
6
8
 
7
9
  interface ClientOptions {
8
10
  /** Base URL for API requests */
@@ -63,6 +65,17 @@ type WorkflowRunResult = {
63
65
  timestamp: number;
64
66
  runId: string;
65
67
  };
68
+ interface GetVNextWorkflowResponse {
69
+ name: string;
70
+ steps: NewWorkflow['steps'];
71
+ stepGraph: NewWorkflow['stepGraph'];
72
+ inputSchema: string;
73
+ outputSchema: string;
74
+ }
75
+ type VNextWorkflowWatchResult = WatchEvent & {
76
+ runId: string;
77
+ };
78
+ type VNextWorkflowRunResult = WorkflowResult<any, any>;
66
79
  interface UpsertVectorParams {
67
80
  indexName: string;
68
81
  vectors: number[][];
@@ -472,6 +485,88 @@ declare class Tool extends BaseResource {
472
485
  }): Promise<any>;
473
486
  }
474
487
 
488
+ declare class VNextWorkflow extends BaseResource {
489
+ private workflowId;
490
+ constructor(options: ClientOptions, workflowId: string);
491
+ /**
492
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
493
+ * separated by the Record Separator character (\x1E)
494
+ *
495
+ * @param stream - The readable stream to process
496
+ * @returns An async generator that yields parsed records
497
+ */
498
+ private streamProcessor;
499
+ /**
500
+ * Retrieves details about the vNext workflow
501
+ * @returns Promise containing vNext workflow details including steps and graphs
502
+ */
503
+ details(): Promise<GetVNextWorkflowResponse>;
504
+ /**
505
+ * Creates a new vNext workflow run
506
+ * @param params - Optional object containing the optional runId
507
+ * @returns Promise containing the runId of the created run
508
+ */
509
+ createRun(params?: {
510
+ runId?: string;
511
+ }): Promise<{
512
+ runId: string;
513
+ }>;
514
+ /**
515
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
516
+ * @param params - Object containing the runId, inputData and runtimeContext
517
+ * @returns Promise containing success message
518
+ */
519
+ start(params: {
520
+ runId: string;
521
+ inputData: Record<string, any>;
522
+ runtimeContext?: RuntimeContext;
523
+ }): Promise<{
524
+ message: string;
525
+ }>;
526
+ /**
527
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
528
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
529
+ * @returns Promise containing success message
530
+ */
531
+ resume({ step, runId, resumeData, runtimeContext, }: {
532
+ step: string | string[];
533
+ runId: string;
534
+ resumeData?: Record<string, any>;
535
+ runtimeContext?: RuntimeContext;
536
+ }): Promise<{
537
+ message: string;
538
+ }>;
539
+ /**
540
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
541
+ * @param params - Object containing the optional runId, inputData and runtimeContext
542
+ * @returns Promise containing the vNext workflow execution results
543
+ */
544
+ startAsync(params: {
545
+ runId?: string;
546
+ inputData: Record<string, any>;
547
+ runtimeContext?: RuntimeContext;
548
+ }): Promise<VNextWorkflowRunResult>;
549
+ /**
550
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
551
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
552
+ * @returns Promise containing the vNext workflow resume results
553
+ */
554
+ resumeAsync(params: {
555
+ runId: string;
556
+ step: string | string[];
557
+ resumeData?: Record<string, any>;
558
+ runtimeContext?: RuntimeContext;
559
+ }): Promise<VNextWorkflowRunResult>;
560
+ /**
561
+ * Watches vNext workflow transitions in real-time
562
+ * @param runId - Optional run ID to filter the watch stream
563
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
564
+ */
565
+ watch({ runId }: {
566
+ runId?: string;
567
+ }, onRecord: (record: VNextWorkflowWatchResult) => void): Promise<void>;
568
+ }
569
+
475
570
  declare class MastraClient extends BaseResource {
476
571
  constructor(options: ClientOptions);
477
572
  /**
@@ -538,6 +633,17 @@ declare class MastraClient extends BaseResource {
538
633
  * @returns Workflow instance
539
634
  */
540
635
  getWorkflow(workflowId: string): Workflow;
636
+ /**
637
+ * Retrieves all available vNext workflows
638
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
639
+ */
640
+ getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>>;
641
+ /**
642
+ * Gets a vNext workflow instance by ID
643
+ * @param workflowId - ID of the vNext workflow to retrieve
644
+ * @returns vNext Workflow instance
645
+ */
646
+ getVNextWorkflow(workflowId: string): VNextWorkflow;
541
647
  /**
542
648
  * Gets a vector instance by name
543
649
  * @param vectorName - Name of the vector to retrieve
@@ -582,4 +688,4 @@ declare class MastraClient extends BaseResource {
582
688
  getNetwork(networkId: string): Network;
583
689
  }
584
690
 
585
- export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult };
691
+ export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ import { JSONSchema7 } from 'json-schema';
3
3
  import { ZodSchema } from 'zod';
4
4
  import { processDataStream } from '@ai-sdk/ui-utils';
5
5
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
6
+ import { NewWorkflow, WorkflowResult, WatchEvent } from '@mastra/core/workflows/vNext';
7
+ import { RuntimeContext } from '@mastra/core/runtime-context';
6
8
 
7
9
  interface ClientOptions {
8
10
  /** Base URL for API requests */
@@ -63,6 +65,17 @@ type WorkflowRunResult = {
63
65
  timestamp: number;
64
66
  runId: string;
65
67
  };
68
+ interface GetVNextWorkflowResponse {
69
+ name: string;
70
+ steps: NewWorkflow['steps'];
71
+ stepGraph: NewWorkflow['stepGraph'];
72
+ inputSchema: string;
73
+ outputSchema: string;
74
+ }
75
+ type VNextWorkflowWatchResult = WatchEvent & {
76
+ runId: string;
77
+ };
78
+ type VNextWorkflowRunResult = WorkflowResult<any, any>;
66
79
  interface UpsertVectorParams {
67
80
  indexName: string;
68
81
  vectors: number[][];
@@ -472,6 +485,88 @@ declare class Tool extends BaseResource {
472
485
  }): Promise<any>;
473
486
  }
474
487
 
488
+ declare class VNextWorkflow extends BaseResource {
489
+ private workflowId;
490
+ constructor(options: ClientOptions, workflowId: string);
491
+ /**
492
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
493
+ * separated by the Record Separator character (\x1E)
494
+ *
495
+ * @param stream - The readable stream to process
496
+ * @returns An async generator that yields parsed records
497
+ */
498
+ private streamProcessor;
499
+ /**
500
+ * Retrieves details about the vNext workflow
501
+ * @returns Promise containing vNext workflow details including steps and graphs
502
+ */
503
+ details(): Promise<GetVNextWorkflowResponse>;
504
+ /**
505
+ * Creates a new vNext workflow run
506
+ * @param params - Optional object containing the optional runId
507
+ * @returns Promise containing the runId of the created run
508
+ */
509
+ createRun(params?: {
510
+ runId?: string;
511
+ }): Promise<{
512
+ runId: string;
513
+ }>;
514
+ /**
515
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
516
+ * @param params - Object containing the runId, inputData and runtimeContext
517
+ * @returns Promise containing success message
518
+ */
519
+ start(params: {
520
+ runId: string;
521
+ inputData: Record<string, any>;
522
+ runtimeContext?: RuntimeContext;
523
+ }): Promise<{
524
+ message: string;
525
+ }>;
526
+ /**
527
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
528
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
529
+ * @returns Promise containing success message
530
+ */
531
+ resume({ step, runId, resumeData, runtimeContext, }: {
532
+ step: string | string[];
533
+ runId: string;
534
+ resumeData?: Record<string, any>;
535
+ runtimeContext?: RuntimeContext;
536
+ }): Promise<{
537
+ message: string;
538
+ }>;
539
+ /**
540
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
541
+ * @param params - Object containing the optional runId, inputData and runtimeContext
542
+ * @returns Promise containing the vNext workflow execution results
543
+ */
544
+ startAsync(params: {
545
+ runId?: string;
546
+ inputData: Record<string, any>;
547
+ runtimeContext?: RuntimeContext;
548
+ }): Promise<VNextWorkflowRunResult>;
549
+ /**
550
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
551
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
552
+ * @returns Promise containing the vNext workflow resume results
553
+ */
554
+ resumeAsync(params: {
555
+ runId: string;
556
+ step: string | string[];
557
+ resumeData?: Record<string, any>;
558
+ runtimeContext?: RuntimeContext;
559
+ }): Promise<VNextWorkflowRunResult>;
560
+ /**
561
+ * Watches vNext workflow transitions in real-time
562
+ * @param runId - Optional run ID to filter the watch stream
563
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
564
+ */
565
+ watch({ runId }: {
566
+ runId?: string;
567
+ }, onRecord: (record: VNextWorkflowWatchResult) => void): Promise<void>;
568
+ }
569
+
475
570
  declare class MastraClient extends BaseResource {
476
571
  constructor(options: ClientOptions);
477
572
  /**
@@ -538,6 +633,17 @@ declare class MastraClient extends BaseResource {
538
633
  * @returns Workflow instance
539
634
  */
540
635
  getWorkflow(workflowId: string): Workflow;
636
+ /**
637
+ * Retrieves all available vNext workflows
638
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
639
+ */
640
+ getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>>;
641
+ /**
642
+ * Gets a vNext workflow instance by ID
643
+ * @param workflowId - ID of the vNext workflow to retrieve
644
+ * @returns vNext Workflow instance
645
+ */
646
+ getVNextWorkflow(workflowId: string): VNextWorkflow;
541
647
  /**
542
648
  * Gets a vector instance by name
543
649
  * @param vectorName - Name of the vector to retrieve
@@ -582,4 +688,4 @@ declare class MastraClient extends BaseResource {
582
688
  getNetwork(networkId: string): Network;
583
689
  }
584
690
 
585
- export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult };
691
+ export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
package/dist/index.js CHANGED
@@ -548,6 +548,162 @@ var Tool = class extends BaseResource {
548
548
  }
549
549
  };
550
550
 
551
+ // src/resources/vnext-workflow.ts
552
+ var RECORD_SEPARATOR2 = "";
553
+ var VNextWorkflow = class extends BaseResource {
554
+ constructor(options, workflowId) {
555
+ super(options);
556
+ this.workflowId = workflowId;
557
+ }
558
+ /**
559
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
560
+ * separated by the Record Separator character (\x1E)
561
+ *
562
+ * @param stream - The readable stream to process
563
+ * @returns An async generator that yields parsed records
564
+ */
565
+ async *streamProcessor(stream) {
566
+ const reader = stream.getReader();
567
+ let doneReading = false;
568
+ let buffer = "";
569
+ try {
570
+ while (!doneReading) {
571
+ const { done, value } = await reader.read();
572
+ doneReading = done;
573
+ if (done && !value) continue;
574
+ try {
575
+ const decoded = value ? new TextDecoder().decode(value) : "";
576
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
577
+ buffer = chunks.pop() || "";
578
+ for (const chunk of chunks) {
579
+ if (chunk) {
580
+ if (typeof chunk === "string") {
581
+ try {
582
+ const parsedChunk = JSON.parse(chunk);
583
+ yield parsedChunk;
584
+ } catch {
585
+ }
586
+ }
587
+ }
588
+ }
589
+ } catch (error) {
590
+ }
591
+ }
592
+ if (buffer) {
593
+ try {
594
+ yield JSON.parse(buffer);
595
+ } catch {
596
+ }
597
+ }
598
+ } finally {
599
+ reader.cancel().catch(() => {
600
+ });
601
+ }
602
+ }
603
+ /**
604
+ * Retrieves details about the vNext workflow
605
+ * @returns Promise containing vNext workflow details including steps and graphs
606
+ */
607
+ details() {
608
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
609
+ }
610
+ /**
611
+ * Creates a new vNext workflow run
612
+ * @param params - Optional object containing the optional runId
613
+ * @returns Promise containing the runId of the created run
614
+ */
615
+ createRun(params) {
616
+ const searchParams = new URLSearchParams();
617
+ if (!!params?.runId) {
618
+ searchParams.set("runId", params.runId);
619
+ }
620
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
621
+ method: "POST"
622
+ });
623
+ }
624
+ /**
625
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
626
+ * @param params - Object containing the runId, inputData and runtimeContext
627
+ * @returns Promise containing success message
628
+ */
629
+ start(params) {
630
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
631
+ method: "POST",
632
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
633
+ });
634
+ }
635
+ /**
636
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
637
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
638
+ * @returns Promise containing success message
639
+ */
640
+ resume({
641
+ step,
642
+ runId,
643
+ resumeData,
644
+ runtimeContext
645
+ }) {
646
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
647
+ method: "POST",
648
+ stream: true,
649
+ body: {
650
+ step,
651
+ resumeData,
652
+ runtimeContext
653
+ }
654
+ });
655
+ }
656
+ /**
657
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
658
+ * @param params - Object containing the optional runId, inputData and runtimeContext
659
+ * @returns Promise containing the vNext workflow execution results
660
+ */
661
+ startAsync(params) {
662
+ const searchParams = new URLSearchParams();
663
+ if (!!params?.runId) {
664
+ searchParams.set("runId", params.runId);
665
+ }
666
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
667
+ method: "POST",
668
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
669
+ });
670
+ }
671
+ /**
672
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
673
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
674
+ * @returns Promise containing the vNext workflow resume results
675
+ */
676
+ resumeAsync(params) {
677
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
678
+ method: "POST",
679
+ body: {
680
+ step: params.step,
681
+ resumeData: params.resumeData,
682
+ runtimeContext: params.runtimeContext
683
+ }
684
+ });
685
+ }
686
+ /**
687
+ * Watches vNext workflow transitions in real-time
688
+ * @param runId - Optional run ID to filter the watch stream
689
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
690
+ */
691
+ async watch({ runId }, onRecord) {
692
+ const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
693
+ stream: true
694
+ });
695
+ if (!response.ok) {
696
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
697
+ }
698
+ if (!response.body) {
699
+ throw new Error("Response body is null");
700
+ }
701
+ for await (const record of this.streamProcessor(response.body)) {
702
+ onRecord(record);
703
+ }
704
+ }
705
+ };
706
+
551
707
  // src/client.ts
552
708
  var MastraClient = class extends BaseResource {
553
709
  constructor(options) {
@@ -640,6 +796,21 @@ var MastraClient = class extends BaseResource {
640
796
  getWorkflow(workflowId) {
641
797
  return new Workflow(this.options, workflowId);
642
798
  }
799
+ /**
800
+ * Retrieves all available vNext workflows
801
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
802
+ */
803
+ getVNextWorkflows() {
804
+ return this.request("/api/workflows/v-next");
805
+ }
806
+ /**
807
+ * Gets a vNext workflow instance by ID
808
+ * @param workflowId - ID of the vNext workflow to retrieve
809
+ * @returns vNext Workflow instance
810
+ */
811
+ getVNextWorkflow(workflowId) {
812
+ return new VNextWorkflow(this.options, workflowId);
813
+ }
643
814
  /**
644
815
  * Gets a vector instance by name
645
816
  * @param vectorName - Name of the vector to retrieve
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.18",
3
+ "version": "0.1.19-alpha.1",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -26,7 +26,10 @@
26
26
  "json-schema": "^0.4.0",
27
27
  "zod": "^3.24.2",
28
28
  "zod-to-json-schema": "^3.24.3",
29
- "@mastra/core": "^0.9.0"
29
+ "@mastra/core": "^0.9.1-alpha.1"
30
+ },
31
+ "peerDependencies": {
32
+ "zod": "^3.24.2"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@babel/preset-env": "^7.26.9",
package/src/client.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network } from './resources';
1
+ import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
2
2
  import type {
3
3
  ClientOptions,
4
4
  CreateMemoryThreadParams,
@@ -13,6 +13,7 @@ import type {
13
13
  GetTelemetryParams,
14
14
  GetTelemetryResponse,
15
15
  GetToolResponse,
16
+ GetVNextWorkflowResponse,
16
17
  GetWorkflowResponse,
17
18
  SaveMessageToMemoryParams,
18
19
  SaveMessageToMemoryResponse,
@@ -121,6 +122,23 @@ export class MastraClient extends BaseResource {
121
122
  return new Workflow(this.options, workflowId);
122
123
  }
123
124
 
125
+ /**
126
+ * Retrieves all available vNext workflows
127
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
128
+ */
129
+ public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
130
+ return this.request('/api/workflows/v-next');
131
+ }
132
+
133
+ /**
134
+ * Gets a vNext workflow instance by ID
135
+ * @param workflowId - ID of the vNext workflow to retrieve
136
+ * @returns vNext Workflow instance
137
+ */
138
+ public getVNextWorkflow(workflowId: string) {
139
+ return new VNextWorkflow(this.options, workflowId);
140
+ }
141
+
124
142
  /**
125
143
  * Gets a vector instance by name
126
144
  * @param vectorName - Name of the vector to retrieve
@@ -5,3 +5,4 @@ export * from './vector';
5
5
  export * from './workflow';
6
6
  export * from './tool';
7
7
  export * from './base';
8
+ export * from './vnext-workflow';
@@ -0,0 +1,225 @@
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
2
+ import type {
3
+ ClientOptions,
4
+ GetVNextWorkflowResponse,
5
+ VNextWorkflowRunResult,
6
+ VNextWorkflowWatchResult,
7
+ } from '../types';
8
+
9
+ import { BaseResource } from './base';
10
+
11
+ const RECORD_SEPARATOR = '\x1E';
12
+
13
+ export class VNextWorkflow extends BaseResource {
14
+ constructor(
15
+ options: ClientOptions,
16
+ private workflowId: string,
17
+ ) {
18
+ super(options);
19
+ }
20
+
21
+ /**
22
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
23
+ * separated by the Record Separator character (\x1E)
24
+ *
25
+ * @param stream - The readable stream to process
26
+ * @returns An async generator that yields parsed records
27
+ */
28
+ private async *streamProcessor(stream: ReadableStream): AsyncGenerator<VNextWorkflowWatchResult, void, unknown> {
29
+ const reader = stream.getReader();
30
+
31
+ // Track if we've finished reading from the stream
32
+ let doneReading = false;
33
+ // Buffer to accumulate partial chunks
34
+ let buffer = '';
35
+
36
+ try {
37
+ while (!doneReading) {
38
+ // Read the next chunk from the stream
39
+ const { done, value } = await reader.read();
40
+ doneReading = done;
41
+
42
+ // Skip processing if we're done and there's no value
43
+ if (done && !value) continue;
44
+
45
+ try {
46
+ // Decode binary data to text
47
+ const decoded = value ? new TextDecoder().decode(value) : '';
48
+
49
+ // Split the combined buffer and new data by record separator
50
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
51
+
52
+ // The last chunk might be incomplete, so save it for the next iteration
53
+ buffer = chunks.pop() || '';
54
+
55
+ // Process complete chunks
56
+ for (const chunk of chunks) {
57
+ if (chunk) {
58
+ // Only process non-empty chunks
59
+ if (typeof chunk === 'string') {
60
+ try {
61
+ const parsedChunk = JSON.parse(chunk);
62
+ yield parsedChunk;
63
+ } catch {
64
+ // Silently ignore parsing errors to maintain stream processing
65
+ // This allows the stream to continue even if one record is malformed
66
+ }
67
+ }
68
+ }
69
+ }
70
+ } catch (error) {
71
+ // Silently ignore parsing errors to maintain stream processing
72
+ // This allows the stream to continue even if one record is malformed
73
+ }
74
+ }
75
+
76
+ // Process any remaining data in the buffer after stream is done
77
+ if (buffer) {
78
+ try {
79
+ yield JSON.parse(buffer);
80
+ } catch {
81
+ // Ignore parsing error for final chunk
82
+ }
83
+ }
84
+ } finally {
85
+ // Always ensure we clean up the reader
86
+ reader.cancel().catch(() => {
87
+ // Ignore cancel errors
88
+ });
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Retrieves details about the vNext workflow
94
+ * @returns Promise containing vNext workflow details including steps and graphs
95
+ */
96
+ details(): Promise<GetVNextWorkflowResponse> {
97
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
98
+ }
99
+
100
+ /**
101
+ * Creates a new vNext workflow run
102
+ * @param params - Optional object containing the optional runId
103
+ * @returns Promise containing the runId of the created run
104
+ */
105
+ createRun(params?: { runId?: string }): Promise<{ runId: string }> {
106
+ const searchParams = new URLSearchParams();
107
+
108
+ if (!!params?.runId) {
109
+ searchParams.set('runId', params.runId);
110
+ }
111
+
112
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
113
+ method: 'POST',
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
119
+ * @param params - Object containing the runId, inputData and runtimeContext
120
+ * @returns Promise containing success message
121
+ */
122
+ start(params: {
123
+ runId: string;
124
+ inputData: Record<string, any>;
125
+ runtimeContext?: RuntimeContext;
126
+ }): Promise<{ message: string }> {
127
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
128
+ method: 'POST',
129
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext },
130
+ });
131
+ }
132
+
133
+ /**
134
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
135
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
136
+ * @returns Promise containing success message
137
+ */
138
+ resume({
139
+ step,
140
+ runId,
141
+ resumeData,
142
+ runtimeContext,
143
+ }: {
144
+ step: string | string[];
145
+ runId: string;
146
+ resumeData?: Record<string, any>;
147
+ runtimeContext?: RuntimeContext;
148
+ }): Promise<{ message: string }> {
149
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
150
+ method: 'POST',
151
+ stream: true,
152
+ body: {
153
+ step,
154
+ resumeData,
155
+ runtimeContext,
156
+ },
157
+ });
158
+ }
159
+
160
+ /**
161
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
162
+ * @param params - Object containing the optional runId, inputData and runtimeContext
163
+ * @returns Promise containing the vNext workflow execution results
164
+ */
165
+ startAsync(params: {
166
+ runId?: string;
167
+ inputData: Record<string, any>;
168
+ runtimeContext?: RuntimeContext;
169
+ }): Promise<VNextWorkflowRunResult> {
170
+ const searchParams = new URLSearchParams();
171
+
172
+ if (!!params?.runId) {
173
+ searchParams.set('runId', params.runId);
174
+ }
175
+
176
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
177
+ method: 'POST',
178
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext },
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
184
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
185
+ * @returns Promise containing the vNext workflow resume results
186
+ */
187
+ resumeAsync(params: {
188
+ runId: string;
189
+ step: string | string[];
190
+ resumeData?: Record<string, any>;
191
+ runtimeContext?: RuntimeContext;
192
+ }): Promise<VNextWorkflowRunResult> {
193
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
194
+ method: 'POST',
195
+ body: {
196
+ step: params.step,
197
+ resumeData: params.resumeData,
198
+ runtimeContext: params.runtimeContext,
199
+ },
200
+ });
201
+ }
202
+
203
+ /**
204
+ * Watches vNext workflow transitions in real-time
205
+ * @param runId - Optional run ID to filter the watch stream
206
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
207
+ */
208
+ async watch({ runId }: { runId?: string }, onRecord: (record: VNextWorkflowWatchResult) => void) {
209
+ const response: Response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
210
+ stream: true,
211
+ });
212
+
213
+ if (!response.ok) {
214
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
215
+ }
216
+
217
+ if (!response.body) {
218
+ throw new Error('Response body is null');
219
+ }
220
+
221
+ for await (const record of this.streamProcessor(response.body)) {
222
+ onRecord(record);
223
+ }
224
+ }
225
+ }
package/src/types.ts CHANGED
@@ -11,6 +11,7 @@ import type {
11
11
  } from '@mastra/core';
12
12
 
13
13
  import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
14
+ import type { NewWorkflow, WatchEvent, WorkflowResult as VNextWorkflowResult } from '@mastra/core/workflows/vNext';
14
15
  import type { JSONSchema7 } from 'json-schema';
15
16
  import type { ZodSchema } from 'zod';
16
17
 
@@ -78,6 +79,18 @@ export type WorkflowRunResult = {
78
79
  timestamp: number;
79
80
  runId: string;
80
81
  };
82
+
83
+ export interface GetVNextWorkflowResponse {
84
+ name: string;
85
+ steps: NewWorkflow['steps'];
86
+ stepGraph: NewWorkflow['stepGraph'];
87
+ inputSchema: string;
88
+ outputSchema: string;
89
+ }
90
+
91
+ export type VNextWorkflowWatchResult = WatchEvent & { runId: string };
92
+
93
+ export type VNextWorkflowRunResult = VNextWorkflowResult<any, any>;
81
94
  export interface UpsertVectorParams {
82
95
  indexName: string;
83
96
  vectors: number[][];