@mastra/client-js 0.0.0-storage-20250225005900 → 0.0.0-taofeeqInngest-20250603090617
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 -16
- package/CHANGELOG.md +1305 -3
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +6 -3
- package/dist/index.cjs +1451 -0
- package/dist/index.d.cts +907 -0
- package/dist/index.d.ts +907 -0
- package/dist/index.js +1445 -0
- package/package.json +31 -19
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +140 -11
- package/src/example.ts +47 -26
- package/src/index.test.ts +293 -60
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +104 -15
- package/src/resources/base.ts +6 -4
- package/src/resources/index.ts +5 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +8 -5
- package/src/resources/network.ts +86 -0
- package/src/resources/tool.ts +16 -3
- package/src/resources/workflow.ts +309 -24
- package/src/types.ts +178 -27
- package/src/utils/index.ts +11 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/dist/index.d.mts +0 -405
- package/dist/index.mjs +0 -487
|
@@ -1,7 +1,18 @@
|
|
|
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
|
|
|
14
|
+
const RECORD_SEPARATOR = '\x1E';
|
|
15
|
+
|
|
5
16
|
export class Workflow extends BaseResource {
|
|
6
17
|
constructor(
|
|
7
18
|
options: ClientOptions,
|
|
@@ -10,6 +21,77 @@ export class Workflow extends BaseResource {
|
|
|
10
21
|
super(options);
|
|
11
22
|
}
|
|
12
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
|
+
|
|
13
95
|
/**
|
|
14
96
|
* Retrieves details about the workflow
|
|
15
97
|
* @returns Promise containing workflow details including steps and graphs
|
|
@@ -19,50 +101,253 @@ export class Workflow extends BaseResource {
|
|
|
19
101
|
}
|
|
20
102
|
|
|
21
103
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param params - Parameters
|
|
24
|
-
* @returns Promise containing
|
|
104
|
+
* Retrieves all runs for a workflow
|
|
105
|
+
* @param params - Parameters for filtering runs
|
|
106
|
+
* @returns Promise containing workflow runs array
|
|
107
|
+
*/
|
|
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
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Creates a new workflow run
|
|
135
|
+
* @param params - Optional object containing the optional runId
|
|
136
|
+
* @returns Promise containing the runId of the created run
|
|
25
137
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
138
|
+
createRun(params?: { runId?: string }): Promise<{ runId: string }> {
|
|
139
|
+
const searchParams = new URLSearchParams();
|
|
140
|
+
|
|
141
|
+
if (!!params?.runId) {
|
|
142
|
+
searchParams.set('runId', params.runId);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
28
146
|
method: 'POST',
|
|
29
|
-
body: params,
|
|
30
147
|
});
|
|
31
148
|
}
|
|
32
149
|
|
|
33
150
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
37
|
-
|
|
38
|
-
|
|
151
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
152
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
153
|
+
* @returns Promise containing success message
|
|
154
|
+
*/
|
|
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);
|
|
161
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
body: { inputData: params?.inputData, runtimeContext },
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
169
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
170
|
+
* @returns Promise containing success message
|
|
39
171
|
*/
|
|
40
172
|
resume({
|
|
41
|
-
|
|
173
|
+
step,
|
|
42
174
|
runId,
|
|
43
|
-
|
|
175
|
+
resumeData,
|
|
176
|
+
...rest
|
|
44
177
|
}: {
|
|
45
|
-
|
|
178
|
+
step: string | string[];
|
|
179
|
+
runId: string;
|
|
180
|
+
resumeData?: Record<string, any>;
|
|
181
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
182
|
+
}): Promise<{ message: string }> {
|
|
183
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
184
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
stream: true,
|
|
187
|
+
body: {
|
|
188
|
+
step,
|
|
189
|
+
resumeData,
|
|
190
|
+
runtimeContext,
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
197
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
198
|
+
* @returns Promise containing the workflow execution results
|
|
199
|
+
*/
|
|
200
|
+
startAsync(params: {
|
|
201
|
+
runId?: string;
|
|
202
|
+
inputData: Record<string, any>;
|
|
203
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
204
|
+
}): Promise<WorkflowRunResult> {
|
|
205
|
+
const searchParams = new URLSearchParams();
|
|
206
|
+
|
|
207
|
+
if (!!params?.runId) {
|
|
208
|
+
searchParams.set('runId', params.runId);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
212
|
+
|
|
213
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
214
|
+
method: 'POST',
|
|
215
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
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
|
|
223
|
+
*/
|
|
224
|
+
async stream(params: { runId?: string; inputData: Record<string, any>; runtimeContext?: RuntimeContext }) {
|
|
225
|
+
const searchParams = new URLSearchParams();
|
|
226
|
+
|
|
227
|
+
if (!!params?.runId) {
|
|
228
|
+
searchParams.set('runId', params.runId);
|
|
229
|
+
}
|
|
230
|
+
|
|
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
|
+
);
|
|
240
|
+
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!response.body) {
|
|
246
|
+
throw new Error('Response body is null');
|
|
247
|
+
}
|
|
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) {
|
|
253
|
+
try {
|
|
254
|
+
// Decode binary data to text
|
|
255
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
256
|
+
|
|
257
|
+
// Split by record separator
|
|
258
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
259
|
+
|
|
260
|
+
// Process each chunk
|
|
261
|
+
for (const chunk of chunks) {
|
|
262
|
+
if (chunk) {
|
|
263
|
+
try {
|
|
264
|
+
const parsedChunk = JSON.parse(chunk);
|
|
265
|
+
controller.enqueue(parsedChunk);
|
|
266
|
+
} catch {
|
|
267
|
+
// Silently ignore parsing errors
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
// Silently ignore processing errors
|
|
273
|
+
}
|
|
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: {
|
|
46
287
|
runId: string;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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}`, {
|
|
50
294
|
method: 'POST',
|
|
51
295
|
body: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
296
|
+
step: params.step,
|
|
297
|
+
resumeData: params.resumeData,
|
|
298
|
+
runtimeContext,
|
|
55
299
|
},
|
|
56
300
|
});
|
|
57
301
|
}
|
|
58
302
|
|
|
59
303
|
/**
|
|
60
304
|
* Watches workflow transitions in real-time
|
|
61
|
-
* @
|
|
305
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
306
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
62
307
|
*/
|
|
63
|
-
watch(
|
|
64
|
-
|
|
308
|
+
async watch({ runId }: { runId?: string }, onRecord: (record: WorkflowWatchResult) => void) {
|
|
309
|
+
const response: Response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
65
310
|
stream: true,
|
|
66
311
|
});
|
|
312
|
+
|
|
313
|
+
if (!response.ok) {
|
|
314
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (!response.body) {
|
|
318
|
+
throw new Error('Response body is null');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
322
|
+
if (typeof record === 'string') {
|
|
323
|
+
onRecord(JSON.parse(record));
|
|
324
|
+
} else {
|
|
325
|
+
onRecord(record);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
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
|
+
});
|
|
67
352
|
}
|
|
68
353
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
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 } from '@mastra/core/agent';
|
|
11
|
+
import type { BaseLogMessage } from '@mastra/core/logger';
|
|
12
|
+
|
|
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';
|
|
12
21
|
import type { JSONSchema7 } from 'json-schema';
|
|
13
|
-
import { ZodSchema } from 'zod';
|
|
22
|
+
import type { ZodSchema } from 'zod';
|
|
14
23
|
|
|
15
24
|
export interface ClientOptions {
|
|
16
25
|
/** Base URL for API requests */
|
|
@@ -23,6 +32,7 @@ export interface ClientOptions {
|
|
|
23
32
|
maxBackoffMs?: number;
|
|
24
33
|
/** Custom headers to include with requests */
|
|
25
34
|
headers?: Record<string, string>;
|
|
35
|
+
/** Abort signal for request */
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
export interface RequestOptions {
|
|
@@ -30,31 +40,49 @@ export interface RequestOptions {
|
|
|
30
40
|
headers?: Record<string, string>;
|
|
31
41
|
body?: any;
|
|
32
42
|
stream?: boolean;
|
|
43
|
+
signal?: AbortSignal;
|
|
33
44
|
}
|
|
34
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
|
+
|
|
35
56
|
export interface GetAgentResponse {
|
|
36
57
|
name: string;
|
|
37
58
|
instructions: string;
|
|
38
59
|
tools: Record<string, GetToolResponse>;
|
|
60
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
39
61
|
provider: string;
|
|
62
|
+
modelId: string;
|
|
63
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
64
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
40
65
|
}
|
|
41
66
|
|
|
42
|
-
export
|
|
43
|
-
messages: string | string[] | CoreMessage[];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
67
|
+
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
68
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
69
|
+
output?: T;
|
|
70
|
+
experimental_output?: T;
|
|
71
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
72
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
|
|
48
73
|
|
|
49
|
-
export
|
|
50
|
-
messages: string | string[] | CoreMessage[];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
74
|
+
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
75
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
76
|
+
output?: T;
|
|
77
|
+
experimental_output?: T;
|
|
78
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
79
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
|
|
55
80
|
|
|
56
81
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
57
82
|
evals: any[];
|
|
83
|
+
instructions: string;
|
|
84
|
+
name: string;
|
|
85
|
+
id: string;
|
|
58
86
|
}
|
|
59
87
|
|
|
60
88
|
export interface GetToolResponse {
|
|
@@ -64,14 +92,55 @@ export interface GetToolResponse {
|
|
|
64
92
|
outputSchema: string;
|
|
65
93
|
}
|
|
66
94
|
|
|
67
|
-
export interface
|
|
95
|
+
export interface GetLegacyWorkflowResponse {
|
|
68
96
|
name: string;
|
|
69
97
|
triggerSchema: string;
|
|
70
98
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
71
99
|
stepGraph: StepGraph;
|
|
72
100
|
stepSubscriberGraph: Record<string, StepGraph>;
|
|
101
|
+
workflowId?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface GetWorkflowRunsParams {
|
|
105
|
+
fromDate?: Date;
|
|
106
|
+
toDate?: Date;
|
|
107
|
+
limit?: number;
|
|
108
|
+
offset?: number;
|
|
109
|
+
resourceId?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
113
|
+
|
|
114
|
+
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
115
|
+
|
|
116
|
+
export type LegacyWorkflowRunResult = {
|
|
117
|
+
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
118
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
119
|
+
timestamp: number;
|
|
120
|
+
runId: string;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export interface GetWorkflowResponse {
|
|
124
|
+
name: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
steps: {
|
|
127
|
+
[key: string]: {
|
|
128
|
+
id: string;
|
|
129
|
+
description: string;
|
|
130
|
+
inputSchema: string;
|
|
131
|
+
outputSchema: string;
|
|
132
|
+
resumeSchema: string;
|
|
133
|
+
suspendSchema: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
137
|
+
inputSchema: string;
|
|
138
|
+
outputSchema: string;
|
|
73
139
|
}
|
|
74
140
|
|
|
141
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
142
|
+
|
|
143
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
75
144
|
export interface UpsertVectorParams {
|
|
76
145
|
indexName: string;
|
|
77
146
|
vectors: number[][];
|
|
@@ -103,17 +172,17 @@ export interface GetVectorIndexResponse {
|
|
|
103
172
|
}
|
|
104
173
|
|
|
105
174
|
export interface SaveMessageToMemoryParams {
|
|
106
|
-
messages:
|
|
175
|
+
messages: MastraMessageV1[];
|
|
107
176
|
agentId: string;
|
|
108
177
|
}
|
|
109
178
|
|
|
110
|
-
export type SaveMessageToMemoryResponse =
|
|
179
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
111
180
|
|
|
112
181
|
export interface CreateMemoryThreadParams {
|
|
113
|
-
title
|
|
114
|
-
metadata
|
|
115
|
-
|
|
116
|
-
threadId
|
|
182
|
+
title?: string;
|
|
183
|
+
metadata?: Record<string, any>;
|
|
184
|
+
resourceId: string;
|
|
185
|
+
threadId?: string;
|
|
117
186
|
agentId: string;
|
|
118
187
|
}
|
|
119
188
|
|
|
@@ -129,7 +198,14 @@ export type GetMemoryThreadResponse = StorageThreadType[];
|
|
|
129
198
|
export interface UpdateMemoryThreadParams {
|
|
130
199
|
title: string;
|
|
131
200
|
metadata: Record<string, any>;
|
|
132
|
-
|
|
201
|
+
resourceId: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface GetMemoryThreadMessagesParams {
|
|
205
|
+
/**
|
|
206
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
207
|
+
*/
|
|
208
|
+
limit?: number;
|
|
133
209
|
}
|
|
134
210
|
|
|
135
211
|
export interface GetMemoryThreadMessagesResponse {
|
|
@@ -150,8 +226,48 @@ export type GetLogsResponse = BaseLogMessage[];
|
|
|
150
226
|
|
|
151
227
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
152
228
|
|
|
229
|
+
type SpanStatus = {
|
|
230
|
+
code: number;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
type SpanOther = {
|
|
234
|
+
droppedAttributesCount: number;
|
|
235
|
+
droppedEventsCount: number;
|
|
236
|
+
droppedLinksCount: number;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
type SpanEventAttributes = {
|
|
240
|
+
key: string;
|
|
241
|
+
value: { [key: string]: string | number | boolean | null };
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
type SpanEvent = {
|
|
245
|
+
attributes: SpanEventAttributes[];
|
|
246
|
+
name: string;
|
|
247
|
+
timeUnixNano: string;
|
|
248
|
+
droppedAttributesCount: number;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
type Span = {
|
|
252
|
+
id: string;
|
|
253
|
+
parentSpanId: string | null;
|
|
254
|
+
traceId: string;
|
|
255
|
+
name: string;
|
|
256
|
+
scope: string;
|
|
257
|
+
kind: number;
|
|
258
|
+
status: SpanStatus;
|
|
259
|
+
events: SpanEvent[];
|
|
260
|
+
links: any[];
|
|
261
|
+
attributes: Record<string, string | number | boolean | null>;
|
|
262
|
+
startTime: number;
|
|
263
|
+
endTime: number;
|
|
264
|
+
duration: number;
|
|
265
|
+
other: SpanOther;
|
|
266
|
+
createdAt: string;
|
|
267
|
+
};
|
|
268
|
+
|
|
153
269
|
export interface GetTelemetryResponse {
|
|
154
|
-
traces:
|
|
270
|
+
traces: Span[];
|
|
155
271
|
}
|
|
156
272
|
|
|
157
273
|
export interface GetTelemetryParams {
|
|
@@ -160,4 +276,39 @@ export interface GetTelemetryParams {
|
|
|
160
276
|
page?: number;
|
|
161
277
|
perPage?: number;
|
|
162
278
|
attribute?: Record<string, string>;
|
|
279
|
+
fromDate?: Date;
|
|
280
|
+
toDate?: Date;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface GetNetworkResponse {
|
|
284
|
+
name: string;
|
|
285
|
+
instructions: string;
|
|
286
|
+
agents: Array<{
|
|
287
|
+
name: string;
|
|
288
|
+
provider: string;
|
|
289
|
+
modelId: string;
|
|
290
|
+
}>;
|
|
291
|
+
routingModel: {
|
|
292
|
+
provider: string;
|
|
293
|
+
modelId: string;
|
|
294
|
+
};
|
|
295
|
+
state?: Record<string, any>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface McpServerListResponse {
|
|
299
|
+
servers: ServerInfo[];
|
|
300
|
+
next: string | null;
|
|
301
|
+
total_count: number;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface McpToolInfo {
|
|
305
|
+
id: string;
|
|
306
|
+
name: string;
|
|
307
|
+
description?: string;
|
|
308
|
+
inputSchema: string;
|
|
309
|
+
toolType?: MCPToolType;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface McpServerToolListResponse {
|
|
313
|
+
tools: McpToolInfo[];
|
|
163
314
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
3
|
+
|
|
4
|
+
export function zodToJsonSchema<T extends ZodSchema | any>(zodSchema: T) {
|
|
5
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
6
|
+
return zodSchema;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: 'none' });
|
|
10
|
+
}
|