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