@mastra/client-js 0.0.0-commonjs-20250227130920 → 0.0.0-default-storage-virtual-file-20250410035748
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 +609 -4
- package/README.md +6 -3
- package/dist/index.cjs +256 -16
- package/dist/index.d.cts +204 -22
- package/dist/index.d.ts +204 -22
- package/dist/index.js +256 -16
- package/package.json +14 -13
- package/src/client.ts +19 -1
- package/src/example.ts +65 -43
- package/src/index.test.ts +170 -57
- package/src/resources/agent.ts +93 -4
- package/src/resources/base.ts +4 -2
- package/src/resources/index.ts +1 -0
- package/src/resources/network.ts +92 -0
- package/src/resources/workflow.ts +156 -9
- package/src/types.ts +76 -15
- package/.turbo/turbo-build.log +0 -19
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
var zodToJsonSchema = require('zod-to-json-schema');
|
|
5
|
+
var uiUtils = require('@ai-sdk/ui-utils');
|
|
5
6
|
|
|
6
7
|
// src/resources/agent.ts
|
|
7
8
|
|
|
@@ -26,11 +27,12 @@ var BaseResource = class {
|
|
|
26
27
|
const response = await fetch(`${baseUrl}${path}`, {
|
|
27
28
|
...options,
|
|
28
29
|
headers: {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
30
|
...headers,
|
|
31
31
|
...options.headers
|
|
32
|
+
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
33
|
+
// 'x-mastra-client-type': 'js',
|
|
32
34
|
},
|
|
33
|
-
body: options.body ? JSON.stringify(options.body) : void 0
|
|
35
|
+
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
34
36
|
});
|
|
35
37
|
if (!response.ok) {
|
|
36
38
|
const errorBody = await response.text();
|
|
@@ -64,11 +66,60 @@ var BaseResource = class {
|
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
// src/resources/agent.ts
|
|
69
|
+
var AgentVoice = class extends BaseResource {
|
|
70
|
+
constructor(options, agentId) {
|
|
71
|
+
super(options);
|
|
72
|
+
this.agentId = agentId;
|
|
73
|
+
this.agentId = agentId;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert text to speech using the agent's voice provider
|
|
77
|
+
* @param text - Text to convert to speech
|
|
78
|
+
* @param options - Optional provider-specific options for speech generation
|
|
79
|
+
* @returns Promise containing the audio data
|
|
80
|
+
*/
|
|
81
|
+
async speak(text, options) {
|
|
82
|
+
return this.request(`/api/agents/${this.agentId}/voice/speak`, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": "application/json"
|
|
86
|
+
},
|
|
87
|
+
body: { input: text, options },
|
|
88
|
+
stream: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Convert speech to text using the agent's voice provider
|
|
93
|
+
* @param audio - Audio data to transcribe
|
|
94
|
+
* @param options - Optional provider-specific options
|
|
95
|
+
* @returns Promise containing the transcribed text
|
|
96
|
+
*/
|
|
97
|
+
listen(audio, options) {
|
|
98
|
+
const formData = new FormData();
|
|
99
|
+
formData.append("audio", audio);
|
|
100
|
+
if (options) {
|
|
101
|
+
formData.append("options", JSON.stringify(options));
|
|
102
|
+
}
|
|
103
|
+
return this.request(`/api/agents/${this.agentId}/voice/listen`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
body: formData
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get available speakers for the agent's voice provider
|
|
110
|
+
* @returns Promise containing list of available speakers
|
|
111
|
+
*/
|
|
112
|
+
getSpeakers() {
|
|
113
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
67
116
|
var Agent = class extends BaseResource {
|
|
68
117
|
constructor(options, agentId) {
|
|
69
118
|
super(options);
|
|
70
119
|
this.agentId = agentId;
|
|
120
|
+
this.voice = new AgentVoice(options, this.agentId);
|
|
71
121
|
}
|
|
122
|
+
voice;
|
|
72
123
|
/**
|
|
73
124
|
* Retrieves details about the agent
|
|
74
125
|
* @returns Promise containing agent details including model and instructions
|
|
@@ -84,7 +135,8 @@ var Agent = class extends BaseResource {
|
|
|
84
135
|
generate(params) {
|
|
85
136
|
const processedParams = {
|
|
86
137
|
...params,
|
|
87
|
-
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output
|
|
138
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
139
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
88
140
|
};
|
|
89
141
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
90
142
|
method: "POST",
|
|
@@ -94,18 +146,29 @@ var Agent = class extends BaseResource {
|
|
|
94
146
|
/**
|
|
95
147
|
* Streams a response from the agent
|
|
96
148
|
* @param params - Stream parameters including prompt
|
|
97
|
-
* @returns Promise containing the
|
|
149
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
98
150
|
*/
|
|
99
|
-
stream(params) {
|
|
151
|
+
async stream(params) {
|
|
100
152
|
const processedParams = {
|
|
101
153
|
...params,
|
|
102
|
-
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output
|
|
154
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
155
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
103
156
|
};
|
|
104
|
-
|
|
157
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
105
158
|
method: "POST",
|
|
106
159
|
body: processedParams,
|
|
107
160
|
stream: true
|
|
108
161
|
});
|
|
162
|
+
if (!response.body) {
|
|
163
|
+
throw new Error("No response body");
|
|
164
|
+
}
|
|
165
|
+
response.processDataStream = async (options = {}) => {
|
|
166
|
+
await uiUtils.processDataStream({
|
|
167
|
+
stream: response.body,
|
|
168
|
+
...options
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
return response;
|
|
109
172
|
}
|
|
110
173
|
/**
|
|
111
174
|
* Gets details about a specific tool available to the agent
|
|
@@ -130,6 +193,62 @@ var Agent = class extends BaseResource {
|
|
|
130
193
|
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
131
194
|
}
|
|
132
195
|
};
|
|
196
|
+
var Network = class extends BaseResource {
|
|
197
|
+
constructor(options, networkId) {
|
|
198
|
+
super(options);
|
|
199
|
+
this.networkId = networkId;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Retrieves details about the network
|
|
203
|
+
* @returns Promise containing network details
|
|
204
|
+
*/
|
|
205
|
+
details() {
|
|
206
|
+
return this.request(`/api/networks/${this.networkId}`);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Generates a response from the agent
|
|
210
|
+
* @param params - Generation parameters including prompt
|
|
211
|
+
* @returns Promise containing the generated response
|
|
212
|
+
*/
|
|
213
|
+
generate(params) {
|
|
214
|
+
const processedParams = {
|
|
215
|
+
...params,
|
|
216
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
217
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
218
|
+
};
|
|
219
|
+
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
220
|
+
method: "POST",
|
|
221
|
+
body: processedParams
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Streams a response from the agent
|
|
226
|
+
* @param params - Stream parameters including prompt
|
|
227
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
228
|
+
*/
|
|
229
|
+
async stream(params) {
|
|
230
|
+
const processedParams = {
|
|
231
|
+
...params,
|
|
232
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
233
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
234
|
+
};
|
|
235
|
+
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
236
|
+
method: "POST",
|
|
237
|
+
body: processedParams,
|
|
238
|
+
stream: true
|
|
239
|
+
});
|
|
240
|
+
if (!response.body) {
|
|
241
|
+
throw new Error("No response body");
|
|
242
|
+
}
|
|
243
|
+
response.processDataStream = async (options = {}) => {
|
|
244
|
+
await uiUtils.processDataStream({
|
|
245
|
+
stream: response.body,
|
|
246
|
+
...options
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
return response;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
133
252
|
|
|
134
253
|
// src/resources/memory-thread.ts
|
|
135
254
|
var MemoryThread = class extends BaseResource {
|
|
@@ -241,6 +360,7 @@ var Vector = class extends BaseResource {
|
|
|
241
360
|
};
|
|
242
361
|
|
|
243
362
|
// src/resources/workflow.ts
|
|
363
|
+
var RECORD_SEPARATOR = "";
|
|
244
364
|
var Workflow = class extends BaseResource {
|
|
245
365
|
constructor(options, workflowId) {
|
|
246
366
|
super(options);
|
|
@@ -254,6 +374,7 @@ var Workflow = class extends BaseResource {
|
|
|
254
374
|
return this.request(`/api/workflows/${this.workflowId}`);
|
|
255
375
|
}
|
|
256
376
|
/**
|
|
377
|
+
* @deprecated Use `startAsync` instead
|
|
257
378
|
* Executes the workflow with the provided parameters
|
|
258
379
|
* @param params - Parameters required for workflow execution
|
|
259
380
|
* @returns Promise containing the workflow execution results
|
|
@@ -265,7 +386,31 @@ var Workflow = class extends BaseResource {
|
|
|
265
386
|
});
|
|
266
387
|
}
|
|
267
388
|
/**
|
|
268
|
-
*
|
|
389
|
+
* Creates a new workflow run
|
|
390
|
+
* @returns Promise containing the generated run ID
|
|
391
|
+
*/
|
|
392
|
+
createRun(params) {
|
|
393
|
+
const searchParams = new URLSearchParams();
|
|
394
|
+
if (!!params?.runId) {
|
|
395
|
+
searchParams.set("runId", params.runId);
|
|
396
|
+
}
|
|
397
|
+
return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
|
|
398
|
+
method: "POST"
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
403
|
+
* @param params - Object containing the runId and triggerData
|
|
404
|
+
* @returns Promise containing success message
|
|
405
|
+
*/
|
|
406
|
+
start(params) {
|
|
407
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
408
|
+
method: "POST",
|
|
409
|
+
body: params?.triggerData
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
269
414
|
* @param stepId - ID of the step to resume
|
|
270
415
|
* @param runId - ID of the workflow run
|
|
271
416
|
* @param context - Context to resume the workflow with
|
|
@@ -276,23 +421,106 @@ var Workflow = class extends BaseResource {
|
|
|
276
421
|
runId,
|
|
277
422
|
context
|
|
278
423
|
}) {
|
|
279
|
-
return this.request(`/api/workflows/${this.workflowId}/resume`, {
|
|
424
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
280
425
|
method: "POST",
|
|
281
426
|
body: {
|
|
282
427
|
stepId,
|
|
283
|
-
runId,
|
|
284
428
|
context
|
|
285
429
|
}
|
|
286
430
|
});
|
|
287
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
434
|
+
* @param params - Object containing the optional runId and triggerData
|
|
435
|
+
* @returns Promise containing the workflow execution results
|
|
436
|
+
*/
|
|
437
|
+
startAsync(params) {
|
|
438
|
+
const searchParams = new URLSearchParams();
|
|
439
|
+
if (!!params?.runId) {
|
|
440
|
+
searchParams.set("runId", params.runId);
|
|
441
|
+
}
|
|
442
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
443
|
+
method: "POST",
|
|
444
|
+
body: params?.triggerData
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
449
|
+
* @param params - Object containing the runId, stepId, and context
|
|
450
|
+
* @returns Promise containing the workflow resume results
|
|
451
|
+
*/
|
|
452
|
+
resumeAsync(params) {
|
|
453
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
454
|
+
method: "POST",
|
|
455
|
+
body: {
|
|
456
|
+
stepId: params.stepId,
|
|
457
|
+
context: params.context
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Creates an async generator that processes a readable stream and yields records
|
|
463
|
+
* separated by the Record Separator character (\x1E)
|
|
464
|
+
*
|
|
465
|
+
* @param stream - The readable stream to process
|
|
466
|
+
* @returns An async generator that yields parsed records
|
|
467
|
+
*/
|
|
468
|
+
async *streamProcessor(stream) {
|
|
469
|
+
const reader = stream.getReader();
|
|
470
|
+
let doneReading = false;
|
|
471
|
+
let buffer = "";
|
|
472
|
+
try {
|
|
473
|
+
while (!doneReading) {
|
|
474
|
+
const { done, value } = await reader.read();
|
|
475
|
+
doneReading = done;
|
|
476
|
+
if (done && !value) continue;
|
|
477
|
+
try {
|
|
478
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
479
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
480
|
+
buffer = chunks.pop() || "";
|
|
481
|
+
for (const chunk of chunks) {
|
|
482
|
+
if (chunk) {
|
|
483
|
+
if (typeof chunk === "string") {
|
|
484
|
+
try {
|
|
485
|
+
const parsedChunk = JSON.parse(chunk);
|
|
486
|
+
yield parsedChunk;
|
|
487
|
+
} catch {
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
} catch (error) {
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (buffer) {
|
|
496
|
+
try {
|
|
497
|
+
yield JSON.parse(buffer);
|
|
498
|
+
} catch {
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
} finally {
|
|
502
|
+
reader.cancel().catch(() => {
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
288
506
|
/**
|
|
289
507
|
* Watches workflow transitions in real-time
|
|
290
|
-
* @
|
|
508
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
509
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
291
510
|
*/
|
|
292
|
-
watch() {
|
|
293
|
-
|
|
511
|
+
async watch({ runId }, onRecord) {
|
|
512
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
294
513
|
stream: true
|
|
295
514
|
});
|
|
515
|
+
if (!response.ok) {
|
|
516
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
517
|
+
}
|
|
518
|
+
if (!response.body) {
|
|
519
|
+
throw new Error("Response body is null");
|
|
520
|
+
}
|
|
521
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
522
|
+
onRecord(record);
|
|
523
|
+
}
|
|
296
524
|
}
|
|
297
525
|
};
|
|
298
526
|
|
|
@@ -453,9 +681,6 @@ var MastraClient = class extends BaseResource {
|
|
|
453
681
|
getTelemetry(params) {
|
|
454
682
|
const { name, scope, page, perPage, attribute } = params || {};
|
|
455
683
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
456
|
-
({
|
|
457
|
-
..._attribute?.length ? { attribute: _attribute } : {}
|
|
458
|
-
});
|
|
459
684
|
const searchParams = new URLSearchParams();
|
|
460
685
|
if (name) {
|
|
461
686
|
searchParams.set("name", name);
|
|
@@ -484,6 +709,21 @@ var MastraClient = class extends BaseResource {
|
|
|
484
709
|
return this.request(`/api/telemetry`);
|
|
485
710
|
}
|
|
486
711
|
}
|
|
712
|
+
/**
|
|
713
|
+
* Retrieves all available networks
|
|
714
|
+
* @returns Promise containing map of network IDs to network details
|
|
715
|
+
*/
|
|
716
|
+
getNetworks() {
|
|
717
|
+
return this.request("/api/networks");
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Gets a network instance by ID
|
|
721
|
+
* @param networkId - ID of the network to retrieve
|
|
722
|
+
* @returns Network instance
|
|
723
|
+
*/
|
|
724
|
+
getNetwork(networkId) {
|
|
725
|
+
return new Network(this.options, networkId);
|
|
726
|
+
}
|
|
487
727
|
};
|
|
488
728
|
|
|
489
729
|
exports.MastraClient = MastraClient;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { CoreMessage,
|
|
1
|
+
import { CoreMessage, AiMessageType, StorageThreadType, MessageType, StepAction, StepGraph, WorkflowRunResult as WorkflowRunResult$1, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
|
|
2
2
|
import { JSONSchema7 } from 'json-schema';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
|
+
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
5
|
+
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
4
6
|
|
|
5
7
|
interface ClientOptions {
|
|
6
8
|
/** Base URL for API requests */
|
|
@@ -19,25 +21,21 @@ interface RequestOptions {
|
|
|
19
21
|
headers?: Record<string, string>;
|
|
20
22
|
body?: any;
|
|
21
23
|
stream?: boolean;
|
|
24
|
+
signal?: AbortSignal;
|
|
22
25
|
}
|
|
23
26
|
interface GetAgentResponse {
|
|
24
27
|
name: string;
|
|
25
28
|
instructions: string;
|
|
26
29
|
tools: Record<string, GetToolResponse>;
|
|
27
30
|
provider: string;
|
|
31
|
+
modelId: string;
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
messages: string | string[] | CoreMessage[];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
|
|
36
|
-
messages: string | string[] | CoreMessage[];
|
|
37
|
-
threadId?: string;
|
|
38
|
-
resourceid?: string;
|
|
39
|
-
output?: OutputType | T;
|
|
40
|
-
}
|
|
33
|
+
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
34
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
35
|
+
} & Partial<AgentGenerateOptions<T>>;
|
|
36
|
+
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
37
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
38
|
+
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry'>;
|
|
41
39
|
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
42
40
|
evals: any[];
|
|
43
41
|
}
|
|
@@ -53,7 +51,18 @@ interface GetWorkflowResponse {
|
|
|
53
51
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
54
52
|
stepGraph: StepGraph;
|
|
55
53
|
stepSubscriberGraph: Record<string, StepGraph>;
|
|
54
|
+
workflowId?: string;
|
|
56
55
|
}
|
|
56
|
+
type WorkflowRunResult = {
|
|
57
|
+
activePaths: Record<string, {
|
|
58
|
+
status: string;
|
|
59
|
+
suspendPayload?: any;
|
|
60
|
+
stepPath: string[];
|
|
61
|
+
}>;
|
|
62
|
+
results: WorkflowRunResult$1<any, any, any>['results'];
|
|
63
|
+
timestamp: number;
|
|
64
|
+
runId: string;
|
|
65
|
+
};
|
|
57
66
|
interface UpsertVectorParams {
|
|
58
67
|
indexName: string;
|
|
59
68
|
vectors: number[][];
|
|
@@ -116,8 +125,47 @@ interface GetLogParams {
|
|
|
116
125
|
}
|
|
117
126
|
type GetLogsResponse = BaseLogMessage[];
|
|
118
127
|
type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
128
|
+
type SpanStatus = {
|
|
129
|
+
code: number;
|
|
130
|
+
};
|
|
131
|
+
type SpanOther = {
|
|
132
|
+
droppedAttributesCount: number;
|
|
133
|
+
droppedEventsCount: number;
|
|
134
|
+
droppedLinksCount: number;
|
|
135
|
+
};
|
|
136
|
+
type SpanEventAttributes = {
|
|
137
|
+
key: string;
|
|
138
|
+
value: {
|
|
139
|
+
[key: string]: string | number | boolean | null;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
type SpanEvent = {
|
|
143
|
+
attributes: SpanEventAttributes[];
|
|
144
|
+
name: string;
|
|
145
|
+
timeUnixNano: string;
|
|
146
|
+
droppedAttributesCount: number;
|
|
147
|
+
};
|
|
148
|
+
type Span = {
|
|
149
|
+
id: string;
|
|
150
|
+
parentSpanId: string | null;
|
|
151
|
+
traceId: string;
|
|
152
|
+
name: string;
|
|
153
|
+
scope: string;
|
|
154
|
+
kind: number;
|
|
155
|
+
status: SpanStatus;
|
|
156
|
+
events: SpanEvent[];
|
|
157
|
+
links: any[];
|
|
158
|
+
attributes: Record<string, string | number | boolean | null>;
|
|
159
|
+
startTime: number;
|
|
160
|
+
endTime: number;
|
|
161
|
+
duration: number;
|
|
162
|
+
other: SpanOther;
|
|
163
|
+
createdAt: string;
|
|
164
|
+
};
|
|
119
165
|
interface GetTelemetryResponse {
|
|
120
|
-
traces:
|
|
166
|
+
traces: {
|
|
167
|
+
traces: Span[];
|
|
168
|
+
};
|
|
121
169
|
}
|
|
122
170
|
interface GetTelemetryParams {
|
|
123
171
|
name?: string;
|
|
@@ -126,6 +174,20 @@ interface GetTelemetryParams {
|
|
|
126
174
|
perPage?: number;
|
|
127
175
|
attribute?: Record<string, string>;
|
|
128
176
|
}
|
|
177
|
+
interface GetNetworkResponse {
|
|
178
|
+
name: string;
|
|
179
|
+
instructions: string;
|
|
180
|
+
agents: Array<{
|
|
181
|
+
name: string;
|
|
182
|
+
provider: string;
|
|
183
|
+
modelId: string;
|
|
184
|
+
}>;
|
|
185
|
+
routingModel: {
|
|
186
|
+
provider: string;
|
|
187
|
+
modelId: string;
|
|
188
|
+
};
|
|
189
|
+
state?: Record<string, any>;
|
|
190
|
+
}
|
|
129
191
|
|
|
130
192
|
declare class BaseResource {
|
|
131
193
|
readonly options: ClientOptions;
|
|
@@ -139,8 +201,38 @@ declare class BaseResource {
|
|
|
139
201
|
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
140
202
|
}
|
|
141
203
|
|
|
204
|
+
declare class AgentVoice extends BaseResource {
|
|
205
|
+
private agentId;
|
|
206
|
+
constructor(options: ClientOptions, agentId: string);
|
|
207
|
+
/**
|
|
208
|
+
* Convert text to speech using the agent's voice provider
|
|
209
|
+
* @param text - Text to convert to speech
|
|
210
|
+
* @param options - Optional provider-specific options for speech generation
|
|
211
|
+
* @returns Promise containing the audio data
|
|
212
|
+
*/
|
|
213
|
+
speak(text: string, options?: {
|
|
214
|
+
speaker?: string;
|
|
215
|
+
[key: string]: any;
|
|
216
|
+
}): Promise<Response>;
|
|
217
|
+
/**
|
|
218
|
+
* Convert speech to text using the agent's voice provider
|
|
219
|
+
* @param audio - Audio data to transcribe
|
|
220
|
+
* @param options - Optional provider-specific options
|
|
221
|
+
* @returns Promise containing the transcribed text
|
|
222
|
+
*/
|
|
223
|
+
listen(audio: Blob, options?: Record<string, any>): Promise<Response>;
|
|
224
|
+
/**
|
|
225
|
+
* Get available speakers for the agent's voice provider
|
|
226
|
+
* @returns Promise containing list of available speakers
|
|
227
|
+
*/
|
|
228
|
+
getSpeakers(): Promise<Array<{
|
|
229
|
+
voiceId: string;
|
|
230
|
+
[key: string]: any;
|
|
231
|
+
}>>;
|
|
232
|
+
}
|
|
142
233
|
declare class Agent extends BaseResource {
|
|
143
234
|
private agentId;
|
|
235
|
+
readonly voice: AgentVoice;
|
|
144
236
|
constructor(options: ClientOptions, agentId: string);
|
|
145
237
|
/**
|
|
146
238
|
* Retrieves details about the agent
|
|
@@ -156,9 +248,11 @@ declare class Agent extends BaseResource {
|
|
|
156
248
|
/**
|
|
157
249
|
* Streams a response from the agent
|
|
158
250
|
* @param params - Stream parameters including prompt
|
|
159
|
-
* @returns Promise containing the
|
|
251
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
160
252
|
*/
|
|
161
|
-
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response
|
|
253
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response & {
|
|
254
|
+
processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
|
|
255
|
+
}>;
|
|
162
256
|
/**
|
|
163
257
|
* Gets details about a specific tool available to the agent
|
|
164
258
|
* @param toolId - ID of the tool to retrieve
|
|
@@ -177,6 +271,30 @@ declare class Agent extends BaseResource {
|
|
|
177
271
|
liveEvals(): Promise<GetEvalsByAgentIdResponse>;
|
|
178
272
|
}
|
|
179
273
|
|
|
274
|
+
declare class Network extends BaseResource {
|
|
275
|
+
private networkId;
|
|
276
|
+
constructor(options: ClientOptions, networkId: string);
|
|
277
|
+
/**
|
|
278
|
+
* Retrieves details about the network
|
|
279
|
+
* @returns Promise containing network details
|
|
280
|
+
*/
|
|
281
|
+
details(): Promise<GetNetworkResponse>;
|
|
282
|
+
/**
|
|
283
|
+
* Generates a response from the agent
|
|
284
|
+
* @param params - Generation parameters including prompt
|
|
285
|
+
* @returns Promise containing the generated response
|
|
286
|
+
*/
|
|
287
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
|
|
288
|
+
/**
|
|
289
|
+
* Streams a response from the agent
|
|
290
|
+
* @param params - Stream parameters including prompt
|
|
291
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
292
|
+
*/
|
|
293
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response & {
|
|
294
|
+
processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
|
|
295
|
+
}>;
|
|
296
|
+
}
|
|
297
|
+
|
|
180
298
|
declare class MemoryThread extends BaseResource {
|
|
181
299
|
private threadId;
|
|
182
300
|
private agentId;
|
|
@@ -261,13 +379,34 @@ declare class Workflow extends BaseResource {
|
|
|
261
379
|
*/
|
|
262
380
|
details(): Promise<GetWorkflowResponse>;
|
|
263
381
|
/**
|
|
382
|
+
* @deprecated Use `startAsync` instead
|
|
264
383
|
* Executes the workflow with the provided parameters
|
|
265
384
|
* @param params - Parameters required for workflow execution
|
|
266
385
|
* @returns Promise containing the workflow execution results
|
|
267
386
|
*/
|
|
268
|
-
execute(params: Record<string, any>): Promise<
|
|
387
|
+
execute(params: Record<string, any>): Promise<WorkflowRunResult>;
|
|
269
388
|
/**
|
|
270
|
-
*
|
|
389
|
+
* Creates a new workflow run
|
|
390
|
+
* @returns Promise containing the generated run ID
|
|
391
|
+
*/
|
|
392
|
+
createRun(params?: {
|
|
393
|
+
runId?: string;
|
|
394
|
+
}): Promise<{
|
|
395
|
+
runId: string;
|
|
396
|
+
}>;
|
|
397
|
+
/**
|
|
398
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
399
|
+
* @param params - Object containing the runId and triggerData
|
|
400
|
+
* @returns Promise containing success message
|
|
401
|
+
*/
|
|
402
|
+
start(params: {
|
|
403
|
+
runId: string;
|
|
404
|
+
triggerData: Record<string, any>;
|
|
405
|
+
}): Promise<{
|
|
406
|
+
message: string;
|
|
407
|
+
}>;
|
|
408
|
+
/**
|
|
409
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
271
410
|
* @param stepId - ID of the step to resume
|
|
272
411
|
* @param runId - ID of the workflow run
|
|
273
412
|
* @param context - Context to resume the workflow with
|
|
@@ -277,12 +416,44 @@ declare class Workflow extends BaseResource {
|
|
|
277
416
|
stepId: string;
|
|
278
417
|
runId: string;
|
|
279
418
|
context: Record<string, any>;
|
|
280
|
-
}): Promise<
|
|
419
|
+
}): Promise<{
|
|
420
|
+
message: string;
|
|
421
|
+
}>;
|
|
422
|
+
/**
|
|
423
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
424
|
+
* @param params - Object containing the optional runId and triggerData
|
|
425
|
+
* @returns Promise containing the workflow execution results
|
|
426
|
+
*/
|
|
427
|
+
startAsync(params: {
|
|
428
|
+
runId?: string;
|
|
429
|
+
triggerData: Record<string, any>;
|
|
430
|
+
}): Promise<WorkflowRunResult>;
|
|
431
|
+
/**
|
|
432
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
433
|
+
* @param params - Object containing the runId, stepId, and context
|
|
434
|
+
* @returns Promise containing the workflow resume results
|
|
435
|
+
*/
|
|
436
|
+
resumeAsync(params: {
|
|
437
|
+
runId: string;
|
|
438
|
+
stepId: string;
|
|
439
|
+
context: Record<string, any>;
|
|
440
|
+
}): Promise<WorkflowRunResult>;
|
|
441
|
+
/**
|
|
442
|
+
* Creates an async generator that processes a readable stream and yields records
|
|
443
|
+
* separated by the Record Separator character (\x1E)
|
|
444
|
+
*
|
|
445
|
+
* @param stream - The readable stream to process
|
|
446
|
+
* @returns An async generator that yields parsed records
|
|
447
|
+
*/
|
|
448
|
+
private streamProcessor;
|
|
281
449
|
/**
|
|
282
450
|
* Watches workflow transitions in real-time
|
|
283
|
-
* @
|
|
451
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
452
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
284
453
|
*/
|
|
285
|
-
watch(
|
|
454
|
+
watch({ runId }: {
|
|
455
|
+
runId?: string;
|
|
456
|
+
}, onRecord: (record: WorkflowRunResult) => void): Promise<void>;
|
|
286
457
|
}
|
|
287
458
|
|
|
288
459
|
declare class Tool extends BaseResource {
|
|
@@ -400,6 +571,17 @@ declare class MastraClient extends BaseResource {
|
|
|
400
571
|
* @returns Promise containing telemetry data
|
|
401
572
|
*/
|
|
402
573
|
getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse>;
|
|
574
|
+
/**
|
|
575
|
+
* Retrieves all available networks
|
|
576
|
+
* @returns Promise containing map of network IDs to network details
|
|
577
|
+
*/
|
|
578
|
+
getNetworks(): Promise<Record<string, GetNetworkResponse>>;
|
|
579
|
+
/**
|
|
580
|
+
* Gets a network instance by ID
|
|
581
|
+
* @param networkId - ID of the network to retrieve
|
|
582
|
+
* @returns Network instance
|
|
583
|
+
*/
|
|
584
|
+
getNetwork(networkId: string): Network;
|
|
403
585
|
}
|
|
404
586
|
|
|
405
|
-
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 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 };
|
|
587
|
+
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 };
|