@mastra/client-js 0.0.0-bundle-dynamic-imports-20250424001248 → 0.0.0-cli-debug-2-20250611100354
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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +590 -2
- package/dist/index.cjs +873 -55
- package/dist/index.d.cts +392 -39
- package/dist/index.d.ts +392 -39
- package/dist/index.js +869 -55
- package/package.json +11 -9
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +200 -4
- package/src/example.ts +29 -30
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +49 -37
- package/src/resources/base.ts +2 -2
- package/src/resources/index.ts +4 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network.ts +6 -12
- package/src/resources/tool.ts +16 -3
- package/src/resources/workflow.ts +234 -96
- package/src/types.ts +127 -17
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +31 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
2
|
+
import type {
|
|
3
|
+
ClientOptions,
|
|
4
|
+
GetWorkflowResponse,
|
|
5
|
+
GetWorkflowRunsResponse,
|
|
6
|
+
GetWorkflowRunsParams,
|
|
7
|
+
WorkflowRunResult,
|
|
8
|
+
WorkflowWatchResult,
|
|
9
|
+
} from '../types';
|
|
2
10
|
|
|
11
|
+
import { parseClientRuntimeContext } from '../utils';
|
|
3
12
|
import { BaseResource } from './base';
|
|
4
13
|
|
|
5
14
|
const RECORD_SEPARATOR = '\x1E';
|
|
@@ -12,6 +21,77 @@ export class Workflow extends BaseResource {
|
|
|
12
21
|
super(options);
|
|
13
22
|
}
|
|
14
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
26
|
+
* separated by the Record Separator character (\x1E)
|
|
27
|
+
*
|
|
28
|
+
* @param stream - The readable stream to process
|
|
29
|
+
* @returns An async generator that yields parsed records
|
|
30
|
+
*/
|
|
31
|
+
private async *streamProcessor(stream: ReadableStream): AsyncGenerator<WorkflowWatchResult, void, unknown> {
|
|
32
|
+
const reader = stream.getReader();
|
|
33
|
+
|
|
34
|
+
// Track if we've finished reading from the stream
|
|
35
|
+
let doneReading = false;
|
|
36
|
+
// Buffer to accumulate partial chunks
|
|
37
|
+
let buffer = '';
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
while (!doneReading) {
|
|
41
|
+
// Read the next chunk from the stream
|
|
42
|
+
const { done, value } = await reader.read();
|
|
43
|
+
doneReading = done;
|
|
44
|
+
|
|
45
|
+
// Skip processing if we're done and there's no value
|
|
46
|
+
if (done && !value) continue;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Decode binary data to text
|
|
50
|
+
const decoded = value ? new TextDecoder().decode(value) : '';
|
|
51
|
+
|
|
52
|
+
// Split the combined buffer and new data by record separator
|
|
53
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
54
|
+
|
|
55
|
+
// The last chunk might be incomplete, so save it for the next iteration
|
|
56
|
+
buffer = chunks.pop() || '';
|
|
57
|
+
|
|
58
|
+
// Process complete chunks
|
|
59
|
+
for (const chunk of chunks) {
|
|
60
|
+
if (chunk) {
|
|
61
|
+
// Only process non-empty chunks
|
|
62
|
+
if (typeof chunk === 'string') {
|
|
63
|
+
try {
|
|
64
|
+
const parsedChunk = JSON.parse(chunk);
|
|
65
|
+
yield parsedChunk;
|
|
66
|
+
} catch {
|
|
67
|
+
// Silently ignore parsing errors to maintain stream processing
|
|
68
|
+
// This allows the stream to continue even if one record is malformed
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
// Silently ignore parsing errors to maintain stream processing
|
|
75
|
+
// This allows the stream to continue even if one record is malformed
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Process any remaining data in the buffer after stream is done
|
|
80
|
+
if (buffer) {
|
|
81
|
+
try {
|
|
82
|
+
yield JSON.parse(buffer);
|
|
83
|
+
} catch {
|
|
84
|
+
// Ignore parsing error for final chunk
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} finally {
|
|
88
|
+
// Always ensure we clean up the reader
|
|
89
|
+
reader.cancel().catch(() => {
|
|
90
|
+
// Ignore cancel errors
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
15
95
|
/**
|
|
16
96
|
* Retrieves details about the workflow
|
|
17
97
|
* @returns Promise containing workflow details including steps and graphs
|
|
@@ -21,21 +101,39 @@ export class Workflow extends BaseResource {
|
|
|
21
101
|
}
|
|
22
102
|
|
|
23
103
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
27
|
-
* @returns Promise containing the workflow execution results
|
|
104
|
+
* Retrieves all runs for a workflow
|
|
105
|
+
* @param params - Parameters for filtering runs
|
|
106
|
+
* @returns Promise containing workflow runs array
|
|
28
107
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
108
|
+
runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse> {
|
|
109
|
+
const searchParams = new URLSearchParams();
|
|
110
|
+
if (params?.fromDate) {
|
|
111
|
+
searchParams.set('fromDate', params.fromDate.toISOString());
|
|
112
|
+
}
|
|
113
|
+
if (params?.toDate) {
|
|
114
|
+
searchParams.set('toDate', params.toDate.toISOString());
|
|
115
|
+
}
|
|
116
|
+
if (params?.limit) {
|
|
117
|
+
searchParams.set('limit', String(params.limit));
|
|
118
|
+
}
|
|
119
|
+
if (params?.offset) {
|
|
120
|
+
searchParams.set('offset', String(params.offset));
|
|
121
|
+
}
|
|
122
|
+
if (params?.resourceId) {
|
|
123
|
+
searchParams.set('resourceId', params.resourceId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (searchParams.size) {
|
|
127
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
128
|
+
} else {
|
|
129
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
130
|
+
}
|
|
34
131
|
}
|
|
35
132
|
|
|
36
133
|
/**
|
|
37
134
|
* Creates a new workflow run
|
|
38
|
-
* @
|
|
135
|
+
* @param params - Optional object containing the optional runId
|
|
136
|
+
* @returns Promise containing the runId of the created run
|
|
39
137
|
*/
|
|
40
138
|
createRun(params?: { runId?: string }): Promise<{ runId: string }> {
|
|
41
139
|
const searchParams = new URLSearchParams();
|
|
@@ -44,150 +142,162 @@ export class Workflow extends BaseResource {
|
|
|
44
142
|
searchParams.set('runId', params.runId);
|
|
45
143
|
}
|
|
46
144
|
|
|
47
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
145
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
48
146
|
method: 'POST',
|
|
49
147
|
});
|
|
50
148
|
}
|
|
51
149
|
|
|
52
150
|
/**
|
|
53
151
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
54
|
-
* @param params - Object containing the runId and
|
|
152
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
55
153
|
* @returns Promise containing success message
|
|
56
154
|
*/
|
|
57
|
-
start(params: {
|
|
155
|
+
start(params: {
|
|
156
|
+
runId: string;
|
|
157
|
+
inputData: Record<string, any>;
|
|
158
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
159
|
+
}): Promise<{ message: string }> {
|
|
160
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
58
161
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
59
162
|
method: 'POST',
|
|
60
|
-
body: params?.
|
|
163
|
+
body: { inputData: params?.inputData, runtimeContext },
|
|
61
164
|
});
|
|
62
165
|
}
|
|
63
166
|
|
|
64
167
|
/**
|
|
65
168
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
66
|
-
* @param
|
|
67
|
-
* @
|
|
68
|
-
* @param context - Context to resume the workflow with
|
|
69
|
-
* @returns Promise containing the workflow resume results
|
|
169
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
170
|
+
* @returns Promise containing success message
|
|
70
171
|
*/
|
|
71
172
|
resume({
|
|
72
|
-
|
|
173
|
+
step,
|
|
73
174
|
runId,
|
|
74
|
-
|
|
175
|
+
resumeData,
|
|
176
|
+
...rest
|
|
75
177
|
}: {
|
|
76
|
-
|
|
178
|
+
step: string | string[];
|
|
77
179
|
runId: string;
|
|
78
|
-
|
|
180
|
+
resumeData?: Record<string, any>;
|
|
181
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
79
182
|
}): Promise<{ message: string }> {
|
|
183
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
80
184
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
81
185
|
method: 'POST',
|
|
186
|
+
stream: true,
|
|
82
187
|
body: {
|
|
83
|
-
|
|
84
|
-
|
|
188
|
+
step,
|
|
189
|
+
resumeData,
|
|
190
|
+
runtimeContext,
|
|
85
191
|
},
|
|
86
192
|
});
|
|
87
193
|
}
|
|
88
194
|
|
|
89
195
|
/**
|
|
90
196
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
91
|
-
* @param params - Object containing the optional runId and
|
|
197
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
92
198
|
* @returns Promise containing the workflow execution results
|
|
93
199
|
*/
|
|
94
|
-
startAsync(params: {
|
|
200
|
+
startAsync(params: {
|
|
201
|
+
runId?: string;
|
|
202
|
+
inputData: Record<string, any>;
|
|
203
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
204
|
+
}): Promise<WorkflowRunResult> {
|
|
95
205
|
const searchParams = new URLSearchParams();
|
|
96
206
|
|
|
97
207
|
if (!!params?.runId) {
|
|
98
208
|
searchParams.set('runId', params.runId);
|
|
99
209
|
}
|
|
100
210
|
|
|
211
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
212
|
+
|
|
101
213
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
102
214
|
method: 'POST',
|
|
103
|
-
body: params
|
|
215
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
104
216
|
});
|
|
105
217
|
}
|
|
106
218
|
|
|
107
219
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param params - Object containing the runId,
|
|
110
|
-
* @returns Promise containing the workflow
|
|
220
|
+
* Starts a vNext workflow run and returns a stream
|
|
221
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
222
|
+
* @returns Promise containing the vNext workflow execution results
|
|
111
223
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
method: 'POST',
|
|
115
|
-
body: {
|
|
116
|
-
stepId: params.stepId,
|
|
117
|
-
context: params.context,
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
}
|
|
224
|
+
async stream(params: { runId?: string; inputData: Record<string, any>; runtimeContext?: RuntimeContext }) {
|
|
225
|
+
const searchParams = new URLSearchParams();
|
|
121
226
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
* @param stream - The readable stream to process
|
|
127
|
-
* @returns An async generator that yields parsed records
|
|
128
|
-
*/
|
|
129
|
-
private async *streamProcessor(stream: ReadableStream): AsyncGenerator<WorkflowRunResult, void, unknown> {
|
|
130
|
-
const reader = stream.getReader();
|
|
227
|
+
if (!!params?.runId) {
|
|
228
|
+
searchParams.set('runId', params.runId);
|
|
229
|
+
}
|
|
131
230
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
231
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
|
|
232
|
+
const response: Response = await this.request(
|
|
233
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
234
|
+
{
|
|
235
|
+
method: 'POST',
|
|
236
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
237
|
+
stream: true,
|
|
238
|
+
},
|
|
239
|
+
);
|
|
136
240
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const { done, value } = await reader.read();
|
|
141
|
-
doneReading = done;
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
243
|
+
}
|
|
142
244
|
|
|
143
|
-
|
|
144
|
-
|
|
245
|
+
if (!response.body) {
|
|
246
|
+
throw new Error('Response body is null');
|
|
247
|
+
}
|
|
145
248
|
|
|
249
|
+
// Create a transform stream that processes the response body
|
|
250
|
+
const transformStream = new TransformStream<ArrayBuffer, WorkflowWatchResult>({
|
|
251
|
+
start() {},
|
|
252
|
+
async transform(chunk, controller) {
|
|
146
253
|
try {
|
|
147
254
|
// Decode binary data to text
|
|
148
|
-
const decoded =
|
|
149
|
-
|
|
150
|
-
// Split the combined buffer and new data by record separator
|
|
151
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
255
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
152
256
|
|
|
153
|
-
//
|
|
154
|
-
|
|
257
|
+
// Split by record separator
|
|
258
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
155
259
|
|
|
156
|
-
// Process
|
|
260
|
+
// Process each chunk
|
|
157
261
|
for (const chunk of chunks) {
|
|
158
262
|
if (chunk) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
} catch {
|
|
165
|
-
// Silently ignore parsing errors to maintain stream processing
|
|
166
|
-
// This allows the stream to continue even if one record is malformed
|
|
167
|
-
}
|
|
263
|
+
try {
|
|
264
|
+
const parsedChunk = JSON.parse(chunk);
|
|
265
|
+
controller.enqueue(parsedChunk);
|
|
266
|
+
} catch {
|
|
267
|
+
// Silently ignore parsing errors
|
|
168
268
|
}
|
|
169
269
|
}
|
|
170
270
|
}
|
|
171
|
-
} catch (error) {
|
|
172
|
-
// Silently ignore parsing errors to maintain stream processing
|
|
173
|
-
// This allows the stream to continue even if one record is malformed
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Process any remaining data in the buffer after stream is done
|
|
178
|
-
if (buffer) {
|
|
179
|
-
try {
|
|
180
|
-
yield JSON.parse(buffer);
|
|
181
271
|
} catch {
|
|
182
|
-
//
|
|
272
|
+
// Silently ignore processing errors
|
|
183
273
|
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Pipe the response body through the transform stream
|
|
278
|
+
return response.body.pipeThrough(transformStream);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
283
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
284
|
+
* @returns Promise containing the workflow resume results
|
|
285
|
+
*/
|
|
286
|
+
resumeAsync(params: {
|
|
287
|
+
runId: string;
|
|
288
|
+
step: string | string[];
|
|
289
|
+
resumeData?: Record<string, any>;
|
|
290
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
291
|
+
}): Promise<WorkflowRunResult> {
|
|
292
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
293
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
294
|
+
method: 'POST',
|
|
295
|
+
body: {
|
|
296
|
+
step: params.step,
|
|
297
|
+
resumeData: params.resumeData,
|
|
298
|
+
runtimeContext,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
191
301
|
}
|
|
192
302
|
|
|
193
303
|
/**
|
|
@@ -195,7 +305,7 @@ export class Workflow extends BaseResource {
|
|
|
195
305
|
* @param runId - Optional run ID to filter the watch stream
|
|
196
306
|
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
197
307
|
*/
|
|
198
|
-
async watch({ runId }: { runId?: string }, onRecord: (record:
|
|
308
|
+
async watch({ runId }: { runId?: string }, onRecord: (record: WorkflowWatchResult) => void) {
|
|
199
309
|
const response: Response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
200
310
|
stream: true,
|
|
201
311
|
});
|
|
@@ -209,7 +319,35 @@ export class Workflow extends BaseResource {
|
|
|
209
319
|
}
|
|
210
320
|
|
|
211
321
|
for await (const record of this.streamProcessor(response.body)) {
|
|
212
|
-
|
|
322
|
+
if (typeof record === 'string') {
|
|
323
|
+
onRecord(JSON.parse(record));
|
|
324
|
+
} else {
|
|
325
|
+
onRecord(record);
|
|
326
|
+
}
|
|
213
327
|
}
|
|
214
328
|
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
332
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
333
|
+
*
|
|
334
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
335
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
336
|
+
*/
|
|
337
|
+
static createRecordStream(records: Iterable<any> | AsyncIterable<any>): ReadableStream {
|
|
338
|
+
const encoder = new TextEncoder();
|
|
339
|
+
return new ReadableStream({
|
|
340
|
+
async start(controller) {
|
|
341
|
+
try {
|
|
342
|
+
for await (const record of records as AsyncIterable<any>) {
|
|
343
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
344
|
+
controller.enqueue(encoder.encode(json));
|
|
345
|
+
}
|
|
346
|
+
controller.close();
|
|
347
|
+
} catch (err) {
|
|
348
|
+
controller.error(err);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
}
|
|
215
353
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
MastraMessageV1,
|
|
3
3
|
AiMessageType,
|
|
4
4
|
CoreMessage,
|
|
5
5
|
QueryResult,
|
|
6
|
-
StepAction,
|
|
7
|
-
StepGraph,
|
|
8
6
|
StorageThreadType,
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
WorkflowRuns,
|
|
8
|
+
LegacyWorkflowRuns,
|
|
11
9
|
} from '@mastra/core';
|
|
10
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
11
|
+
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
12
12
|
|
|
13
|
-
import type {
|
|
13
|
+
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
14
|
+
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
15
|
+
import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
|
|
16
|
+
import type {
|
|
17
|
+
StepAction,
|
|
18
|
+
StepGraph,
|
|
19
|
+
LegacyWorkflowRunResult as CoreLegacyWorkflowRunResult,
|
|
20
|
+
} from '@mastra/core/workflows/legacy';
|
|
14
21
|
import type { JSONSchema7 } from 'json-schema';
|
|
15
22
|
import type { ZodSchema } from 'zod';
|
|
16
23
|
|
|
@@ -36,24 +43,48 @@ export interface RequestOptions {
|
|
|
36
43
|
signal?: AbortSignal;
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
type WithoutMethods<T> = {
|
|
47
|
+
[K in keyof T as T[K] extends (...args: any[]) => any
|
|
48
|
+
? never
|
|
49
|
+
: T[K] extends { (): any }
|
|
50
|
+
? never
|
|
51
|
+
: T[K] extends undefined | ((...args: any[]) => any)
|
|
52
|
+
? never
|
|
53
|
+
: K]: T[K];
|
|
54
|
+
};
|
|
55
|
+
|
|
39
56
|
export interface GetAgentResponse {
|
|
40
57
|
name: string;
|
|
41
58
|
instructions: string;
|
|
42
59
|
tools: Record<string, GetToolResponse>;
|
|
60
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
43
61
|
provider: string;
|
|
44
62
|
modelId: string;
|
|
63
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
64
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
45
65
|
}
|
|
46
66
|
|
|
47
67
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
48
68
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
49
|
-
|
|
69
|
+
output?: T;
|
|
70
|
+
experimental_output?: T;
|
|
71
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
72
|
+
clientTools?: ToolsInput;
|
|
73
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
50
74
|
|
|
51
75
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
52
76
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
53
|
-
|
|
77
|
+
output?: T;
|
|
78
|
+
experimental_output?: T;
|
|
79
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
80
|
+
clientTools?: ToolsInput;
|
|
81
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
54
82
|
|
|
55
83
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
56
84
|
evals: any[];
|
|
85
|
+
instructions: string;
|
|
86
|
+
name: string;
|
|
87
|
+
id: string;
|
|
57
88
|
}
|
|
58
89
|
|
|
59
90
|
export interface GetToolResponse {
|
|
@@ -63,7 +94,7 @@ export interface GetToolResponse {
|
|
|
63
94
|
outputSchema: string;
|
|
64
95
|
}
|
|
65
96
|
|
|
66
|
-
export interface
|
|
97
|
+
export interface GetLegacyWorkflowResponse {
|
|
67
98
|
name: string;
|
|
68
99
|
triggerSchema: string;
|
|
69
100
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -72,12 +103,46 @@ export interface GetWorkflowResponse {
|
|
|
72
103
|
workflowId?: string;
|
|
73
104
|
}
|
|
74
105
|
|
|
75
|
-
export
|
|
106
|
+
export interface GetWorkflowRunsParams {
|
|
107
|
+
fromDate?: Date;
|
|
108
|
+
toDate?: Date;
|
|
109
|
+
limit?: number;
|
|
110
|
+
offset?: number;
|
|
111
|
+
resourceId?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
115
|
+
|
|
116
|
+
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
117
|
+
|
|
118
|
+
export type LegacyWorkflowRunResult = {
|
|
76
119
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
77
|
-
results:
|
|
120
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
78
121
|
timestamp: number;
|
|
79
122
|
runId: string;
|
|
80
123
|
};
|
|
124
|
+
|
|
125
|
+
export interface GetWorkflowResponse {
|
|
126
|
+
name: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
steps: {
|
|
129
|
+
[key: string]: {
|
|
130
|
+
id: string;
|
|
131
|
+
description: string;
|
|
132
|
+
inputSchema: string;
|
|
133
|
+
outputSchema: string;
|
|
134
|
+
resumeSchema: string;
|
|
135
|
+
suspendSchema: string;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
139
|
+
inputSchema: string;
|
|
140
|
+
outputSchema: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
144
|
+
|
|
145
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
81
146
|
export interface UpsertVectorParams {
|
|
82
147
|
indexName: string;
|
|
83
148
|
vectors: number[][];
|
|
@@ -109,17 +174,17 @@ export interface GetVectorIndexResponse {
|
|
|
109
174
|
}
|
|
110
175
|
|
|
111
176
|
export interface SaveMessageToMemoryParams {
|
|
112
|
-
messages:
|
|
177
|
+
messages: MastraMessageV1[];
|
|
113
178
|
agentId: string;
|
|
114
179
|
}
|
|
115
180
|
|
|
116
|
-
export type SaveMessageToMemoryResponse =
|
|
181
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
117
182
|
|
|
118
183
|
export interface CreateMemoryThreadParams {
|
|
119
|
-
title
|
|
120
|
-
metadata
|
|
184
|
+
title?: string;
|
|
185
|
+
metadata?: Record<string, any>;
|
|
121
186
|
resourceId: string;
|
|
122
|
-
threadId
|
|
187
|
+
threadId?: string;
|
|
123
188
|
agentId: string;
|
|
124
189
|
}
|
|
125
190
|
|
|
@@ -138,6 +203,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
138
203
|
resourceId: string;
|
|
139
204
|
}
|
|
140
205
|
|
|
206
|
+
export interface GetMemoryThreadMessagesParams {
|
|
207
|
+
/**
|
|
208
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
209
|
+
*/
|
|
210
|
+
limit?: number;
|
|
211
|
+
}
|
|
212
|
+
|
|
141
213
|
export interface GetMemoryThreadMessagesResponse {
|
|
142
214
|
messages: CoreMessage[];
|
|
143
215
|
uiMessages: AiMessageType[];
|
|
@@ -145,14 +217,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
145
217
|
|
|
146
218
|
export interface GetLogsParams {
|
|
147
219
|
transportId: string;
|
|
220
|
+
fromDate?: Date;
|
|
221
|
+
toDate?: Date;
|
|
222
|
+
logLevel?: LogLevel;
|
|
223
|
+
filters?: Record<string, string>;
|
|
224
|
+
page?: number;
|
|
225
|
+
perPage?: number;
|
|
148
226
|
}
|
|
149
227
|
|
|
150
228
|
export interface GetLogParams {
|
|
151
229
|
runId: string;
|
|
152
230
|
transportId: string;
|
|
231
|
+
fromDate?: Date;
|
|
232
|
+
toDate?: Date;
|
|
233
|
+
logLevel?: LogLevel;
|
|
234
|
+
filters?: Record<string, string>;
|
|
235
|
+
page?: number;
|
|
236
|
+
perPage?: number;
|
|
153
237
|
}
|
|
154
238
|
|
|
155
|
-
export type GetLogsResponse =
|
|
239
|
+
export type GetLogsResponse = {
|
|
240
|
+
logs: BaseLogMessage[];
|
|
241
|
+
total: number;
|
|
242
|
+
page: number;
|
|
243
|
+
perPage: number;
|
|
244
|
+
hasMore: boolean;
|
|
245
|
+
};
|
|
156
246
|
|
|
157
247
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
158
248
|
|
|
@@ -206,6 +296,8 @@ export interface GetTelemetryParams {
|
|
|
206
296
|
page?: number;
|
|
207
297
|
perPage?: number;
|
|
208
298
|
attribute?: Record<string, string>;
|
|
299
|
+
fromDate?: Date;
|
|
300
|
+
toDate?: Date;
|
|
209
301
|
}
|
|
210
302
|
|
|
211
303
|
export interface GetNetworkResponse {
|
|
@@ -222,3 +314,21 @@ export interface GetNetworkResponse {
|
|
|
222
314
|
};
|
|
223
315
|
state?: Record<string, any>;
|
|
224
316
|
}
|
|
317
|
+
|
|
318
|
+
export interface McpServerListResponse {
|
|
319
|
+
servers: ServerInfo[];
|
|
320
|
+
next: string | null;
|
|
321
|
+
total_count: number;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface McpToolInfo {
|
|
325
|
+
id: string;
|
|
326
|
+
name: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
inputSchema: string;
|
|
329
|
+
toolType?: MCPToolType;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export interface McpServerToolListResponse {
|
|
333
|
+
tools: McpToolInfo[];
|
|
334
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
2
|
+
|
|
3
|
+
export function parseClientRuntimeContext(runtimeContext?: RuntimeContext | Record<string, any>) {
|
|
4
|
+
if (runtimeContext) {
|
|
5
|
+
if (runtimeContext instanceof RuntimeContext) {
|
|
6
|
+
return Object.fromEntries(runtimeContext.entries());
|
|
7
|
+
}
|
|
8
|
+
return runtimeContext;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|