@mastra/client-js 0.0.0-mcp-server-update-20250421162713 → 0.0.0-mcp-schema-serializer-20250430202337

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.
@@ -0,0 +1,234 @@
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
2
+ import type {
3
+ ClientOptions,
4
+ GetVNextWorkflowResponse,
5
+ GetWorkflowRunsResponse,
6
+ VNextWorkflowRunResult,
7
+ VNextWorkflowWatchResult,
8
+ } from '../types';
9
+
10
+ import { BaseResource } from './base';
11
+
12
+ const RECORD_SEPARATOR = '\x1E';
13
+
14
+ export class VNextWorkflow extends BaseResource {
15
+ constructor(
16
+ options: ClientOptions,
17
+ private workflowId: string,
18
+ ) {
19
+ super(options);
20
+ }
21
+
22
+ /**
23
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
24
+ * separated by the Record Separator character (\x1E)
25
+ *
26
+ * @param stream - The readable stream to process
27
+ * @returns An async generator that yields parsed records
28
+ */
29
+ private async *streamProcessor(stream: ReadableStream): AsyncGenerator<VNextWorkflowWatchResult, void, unknown> {
30
+ const reader = stream.getReader();
31
+
32
+ // Track if we've finished reading from the stream
33
+ let doneReading = false;
34
+ // Buffer to accumulate partial chunks
35
+ let buffer = '';
36
+
37
+ try {
38
+ while (!doneReading) {
39
+ // Read the next chunk from the stream
40
+ const { done, value } = await reader.read();
41
+ doneReading = done;
42
+
43
+ // Skip processing if we're done and there's no value
44
+ if (done && !value) continue;
45
+
46
+ try {
47
+ // Decode binary data to text
48
+ const decoded = value ? new TextDecoder().decode(value) : '';
49
+
50
+ // Split the combined buffer and new data by record separator
51
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
52
+
53
+ // The last chunk might be incomplete, so save it for the next iteration
54
+ buffer = chunks.pop() || '';
55
+
56
+ // Process complete chunks
57
+ for (const chunk of chunks) {
58
+ if (chunk) {
59
+ // Only process non-empty chunks
60
+ if (typeof chunk === 'string') {
61
+ try {
62
+ const parsedChunk = JSON.parse(chunk);
63
+ yield parsedChunk;
64
+ } catch {
65
+ // Silently ignore parsing errors to maintain stream processing
66
+ // This allows the stream to continue even if one record is malformed
67
+ }
68
+ }
69
+ }
70
+ }
71
+ } catch {
72
+ // Silently ignore parsing errors to maintain stream processing
73
+ // This allows the stream to continue even if one record is malformed
74
+ }
75
+ }
76
+
77
+ // Process any remaining data in the buffer after stream is done
78
+ if (buffer) {
79
+ try {
80
+ yield JSON.parse(buffer);
81
+ } catch {
82
+ // Ignore parsing error for final chunk
83
+ }
84
+ }
85
+ } finally {
86
+ // Always ensure we clean up the reader
87
+ reader.cancel().catch(() => {
88
+ // Ignore cancel errors
89
+ });
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Retrieves details about the vNext workflow
95
+ * @returns Promise containing vNext workflow details including steps and graphs
96
+ */
97
+ details(): Promise<GetVNextWorkflowResponse> {
98
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
99
+ }
100
+
101
+ /**
102
+ * Retrieves all runs for a vNext workflow
103
+ * @returns Promise containing vNext workflow runs array
104
+ */
105
+ runs(): Promise<GetWorkflowRunsResponse> {
106
+ return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
107
+ }
108
+
109
+ /**
110
+ * Creates a new vNext workflow run
111
+ * @param params - Optional object containing the optional runId
112
+ * @returns Promise containing the runId of the created run
113
+ */
114
+ createRun(params?: { runId?: string }): Promise<{ runId: string }> {
115
+ const searchParams = new URLSearchParams();
116
+
117
+ if (!!params?.runId) {
118
+ searchParams.set('runId', params.runId);
119
+ }
120
+
121
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
122
+ method: 'POST',
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
128
+ * @param params - Object containing the runId, inputData and runtimeContext
129
+ * @returns Promise containing success message
130
+ */
131
+ start(params: {
132
+ runId: string;
133
+ inputData: Record<string, any>;
134
+ runtimeContext?: RuntimeContext;
135
+ }): Promise<{ message: string }> {
136
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
137
+ method: 'POST',
138
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext },
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
144
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
145
+ * @returns Promise containing success message
146
+ */
147
+ resume({
148
+ step,
149
+ runId,
150
+ resumeData,
151
+ runtimeContext,
152
+ }: {
153
+ step: string | string[];
154
+ runId: string;
155
+ resumeData?: Record<string, any>;
156
+ runtimeContext?: RuntimeContext;
157
+ }): Promise<{ message: string }> {
158
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
159
+ method: 'POST',
160
+ stream: true,
161
+ body: {
162
+ step,
163
+ resumeData,
164
+ runtimeContext,
165
+ },
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
171
+ * @param params - Object containing the optional runId, inputData and runtimeContext
172
+ * @returns Promise containing the vNext workflow execution results
173
+ */
174
+ startAsync(params: {
175
+ runId?: string;
176
+ inputData: Record<string, any>;
177
+ runtimeContext?: RuntimeContext;
178
+ }): Promise<VNextWorkflowRunResult> {
179
+ const searchParams = new URLSearchParams();
180
+
181
+ if (!!params?.runId) {
182
+ searchParams.set('runId', params.runId);
183
+ }
184
+
185
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
186
+ method: 'POST',
187
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext },
188
+ });
189
+ }
190
+
191
+ /**
192
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
193
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
194
+ * @returns Promise containing the vNext workflow resume results
195
+ */
196
+ resumeAsync(params: {
197
+ runId: string;
198
+ step: string | string[];
199
+ resumeData?: Record<string, any>;
200
+ runtimeContext?: RuntimeContext;
201
+ }): Promise<VNextWorkflowRunResult> {
202
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
203
+ method: 'POST',
204
+ body: {
205
+ step: params.step,
206
+ resumeData: params.resumeData,
207
+ runtimeContext: params.runtimeContext,
208
+ },
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Watches vNext workflow transitions in real-time
214
+ * @param runId - Optional run ID to filter the watch stream
215
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
216
+ */
217
+ async watch({ runId }: { runId?: string }, onRecord: (record: VNextWorkflowWatchResult) => void) {
218
+ const response: Response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
219
+ stream: true,
220
+ });
221
+
222
+ if (!response.ok) {
223
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
224
+ }
225
+
226
+ if (!response.body) {
227
+ throw new Error('Response body is null');
228
+ }
229
+
230
+ for await (const record of this.streamProcessor(response.body)) {
231
+ onRecord(record);
232
+ }
233
+ }
234
+ }
@@ -1,4 +1,4 @@
1
- import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult } from '../types';
1
+ import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult, GetWorkflowRunsResponse } from '../types';
2
2
 
3
3
  import { BaseResource } from './base';
4
4
 
@@ -20,6 +20,14 @@ export class Workflow extends BaseResource {
20
20
  return this.request(`/api/workflows/${this.workflowId}`);
21
21
  }
22
22
 
23
+ /**
24
+ * Retrieves all runs for a workflow
25
+ * @returns Promise containing workflow runs array
26
+ */
27
+ runs(): Promise<GetWorkflowRunsResponse> {
28
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
29
+ }
30
+
23
31
  /**
24
32
  * @deprecated Use `startAsync` instead
25
33
  * Executes the workflow with the provided parameters
@@ -168,7 +176,7 @@ export class Workflow extends BaseResource {
168
176
  }
169
177
  }
170
178
  }
171
- } catch (error) {
179
+ } catch {
172
180
  // Silently ignore parsing errors to maintain stream processing
173
181
  // This allows the stream to continue even if one record is malformed
174
182
  }
package/src/types.ts CHANGED
@@ -8,9 +8,11 @@ import type {
8
8
  StorageThreadType,
9
9
  BaseLogMessage,
10
10
  WorkflowRunResult as CoreWorkflowRunResult,
11
+ WorkflowRuns,
11
12
  } from '@mastra/core';
12
13
 
13
14
  import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
15
+ import type { NewWorkflow, WatchEvent, WorkflowResult as VNextWorkflowResult } from '@mastra/core/workflows/vNext';
14
16
  import type { JSONSchema7 } from 'json-schema';
15
17
  import type { ZodSchema } from 'zod';
16
18
 
@@ -54,6 +56,9 @@ export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefin
54
56
 
55
57
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
56
58
  evals: any[];
59
+ instructions: string;
60
+ name: string;
61
+ id: string;
57
62
  }
58
63
 
59
64
  export interface GetToolResponse {
@@ -72,12 +77,35 @@ export interface GetWorkflowResponse {
72
77
  workflowId?: string;
73
78
  }
74
79
 
80
+ export type GetWorkflowRunsResponse = WorkflowRuns;
81
+
75
82
  export type WorkflowRunResult = {
76
83
  activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
77
84
  results: CoreWorkflowRunResult<any, any, any>['results'];
78
85
  timestamp: number;
79
86
  runId: string;
80
87
  };
88
+
89
+ export interface GetVNextWorkflowResponse {
90
+ name: string;
91
+ steps: {
92
+ [key: string]: {
93
+ id: string;
94
+ description: string;
95
+ inputSchema: string;
96
+ outputSchema: string;
97
+ resumeSchema: string;
98
+ suspendSchema: string;
99
+ };
100
+ };
101
+ stepGraph: NewWorkflow['serializedStepGraph'];
102
+ inputSchema: string;
103
+ outputSchema: string;
104
+ }
105
+
106
+ export type VNextWorkflowWatchResult = WatchEvent & { runId: string };
107
+
108
+ export type VNextWorkflowRunResult = VNextWorkflowResult<any, any>;
81
109
  export interface UpsertVectorParams {
82
110
  indexName: string;
83
111
  vectors: number[][];
@@ -118,7 +146,7 @@ export type SaveMessageToMemoryResponse = MessageType[];
118
146
  export interface CreateMemoryThreadParams {
119
147
  title: string;
120
148
  metadata: Record<string, any>;
121
- resourceid: string;
149
+ resourceId: string;
122
150
  threadId: string;
123
151
  agentId: string;
124
152
  }
@@ -135,7 +163,7 @@ export type GetMemoryThreadResponse = StorageThreadType[];
135
163
  export interface UpdateMemoryThreadParams {
136
164
  title: string;
137
165
  metadata: Record<string, any>;
138
- resourceid: string;
166
+ resourceId: string;
139
167
  }
140
168
 
141
169
  export interface GetMemoryThreadMessagesResponse {