@mastra/client-js 0.0.0-storage-20250225005900 → 0.0.0-vnextWorkflows-20250417075051
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 +742 -3
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +6 -3
- package/dist/index.cjs +729 -0
- package/dist/{index.d.mts → index.d.cts} +202 -22
- package/dist/index.d.ts +585 -0
- package/dist/{index.mjs → index.js} +256 -16
- package/package.json +25 -19
- 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 -16
|
@@ -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,45 @@ 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: Span[];
|
|
121
167
|
}
|
|
122
168
|
interface GetTelemetryParams {
|
|
123
169
|
name?: string;
|
|
@@ -126,6 +172,20 @@ interface GetTelemetryParams {
|
|
|
126
172
|
perPage?: number;
|
|
127
173
|
attribute?: Record<string, string>;
|
|
128
174
|
}
|
|
175
|
+
interface GetNetworkResponse {
|
|
176
|
+
name: string;
|
|
177
|
+
instructions: string;
|
|
178
|
+
agents: Array<{
|
|
179
|
+
name: string;
|
|
180
|
+
provider: string;
|
|
181
|
+
modelId: string;
|
|
182
|
+
}>;
|
|
183
|
+
routingModel: {
|
|
184
|
+
provider: string;
|
|
185
|
+
modelId: string;
|
|
186
|
+
};
|
|
187
|
+
state?: Record<string, any>;
|
|
188
|
+
}
|
|
129
189
|
|
|
130
190
|
declare class BaseResource {
|
|
131
191
|
readonly options: ClientOptions;
|
|
@@ -139,8 +199,38 @@ declare class BaseResource {
|
|
|
139
199
|
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
140
200
|
}
|
|
141
201
|
|
|
202
|
+
declare class AgentVoice extends BaseResource {
|
|
203
|
+
private agentId;
|
|
204
|
+
constructor(options: ClientOptions, agentId: string);
|
|
205
|
+
/**
|
|
206
|
+
* Convert text to speech using the agent's voice provider
|
|
207
|
+
* @param text - Text to convert to speech
|
|
208
|
+
* @param options - Optional provider-specific options for speech generation
|
|
209
|
+
* @returns Promise containing the audio data
|
|
210
|
+
*/
|
|
211
|
+
speak(text: string, options?: {
|
|
212
|
+
speaker?: string;
|
|
213
|
+
[key: string]: any;
|
|
214
|
+
}): Promise<Response>;
|
|
215
|
+
/**
|
|
216
|
+
* Convert speech to text using the agent's voice provider
|
|
217
|
+
* @param audio - Audio data to transcribe
|
|
218
|
+
* @param options - Optional provider-specific options
|
|
219
|
+
* @returns Promise containing the transcribed text
|
|
220
|
+
*/
|
|
221
|
+
listen(audio: Blob, options?: Record<string, any>): Promise<Response>;
|
|
222
|
+
/**
|
|
223
|
+
* Get available speakers for the agent's voice provider
|
|
224
|
+
* @returns Promise containing list of available speakers
|
|
225
|
+
*/
|
|
226
|
+
getSpeakers(): Promise<Array<{
|
|
227
|
+
voiceId: string;
|
|
228
|
+
[key: string]: any;
|
|
229
|
+
}>>;
|
|
230
|
+
}
|
|
142
231
|
declare class Agent extends BaseResource {
|
|
143
232
|
private agentId;
|
|
233
|
+
readonly voice: AgentVoice;
|
|
144
234
|
constructor(options: ClientOptions, agentId: string);
|
|
145
235
|
/**
|
|
146
236
|
* Retrieves details about the agent
|
|
@@ -156,9 +246,11 @@ declare class Agent extends BaseResource {
|
|
|
156
246
|
/**
|
|
157
247
|
* Streams a response from the agent
|
|
158
248
|
* @param params - Stream parameters including prompt
|
|
159
|
-
* @returns Promise containing the
|
|
249
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
160
250
|
*/
|
|
161
|
-
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response
|
|
251
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response & {
|
|
252
|
+
processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
|
|
253
|
+
}>;
|
|
162
254
|
/**
|
|
163
255
|
* Gets details about a specific tool available to the agent
|
|
164
256
|
* @param toolId - ID of the tool to retrieve
|
|
@@ -177,6 +269,30 @@ declare class Agent extends BaseResource {
|
|
|
177
269
|
liveEvals(): Promise<GetEvalsByAgentIdResponse>;
|
|
178
270
|
}
|
|
179
271
|
|
|
272
|
+
declare class Network extends BaseResource {
|
|
273
|
+
private networkId;
|
|
274
|
+
constructor(options: ClientOptions, networkId: string);
|
|
275
|
+
/**
|
|
276
|
+
* Retrieves details about the network
|
|
277
|
+
* @returns Promise containing network details
|
|
278
|
+
*/
|
|
279
|
+
details(): Promise<GetNetworkResponse>;
|
|
280
|
+
/**
|
|
281
|
+
* Generates a response from the agent
|
|
282
|
+
* @param params - Generation parameters including prompt
|
|
283
|
+
* @returns Promise containing the generated response
|
|
284
|
+
*/
|
|
285
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
|
|
286
|
+
/**
|
|
287
|
+
* Streams a response from the agent
|
|
288
|
+
* @param params - Stream parameters including prompt
|
|
289
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
290
|
+
*/
|
|
291
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response & {
|
|
292
|
+
processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
|
|
293
|
+
}>;
|
|
294
|
+
}
|
|
295
|
+
|
|
180
296
|
declare class MemoryThread extends BaseResource {
|
|
181
297
|
private threadId;
|
|
182
298
|
private agentId;
|
|
@@ -261,13 +377,34 @@ declare class Workflow extends BaseResource {
|
|
|
261
377
|
*/
|
|
262
378
|
details(): Promise<GetWorkflowResponse>;
|
|
263
379
|
/**
|
|
380
|
+
* @deprecated Use `startAsync` instead
|
|
264
381
|
* Executes the workflow with the provided parameters
|
|
265
382
|
* @param params - Parameters required for workflow execution
|
|
266
383
|
* @returns Promise containing the workflow execution results
|
|
267
384
|
*/
|
|
268
|
-
execute(params: Record<string, any>): Promise<
|
|
385
|
+
execute(params: Record<string, any>): Promise<WorkflowRunResult>;
|
|
269
386
|
/**
|
|
270
|
-
*
|
|
387
|
+
* Creates a new workflow run
|
|
388
|
+
* @returns Promise containing the generated run ID
|
|
389
|
+
*/
|
|
390
|
+
createRun(params?: {
|
|
391
|
+
runId?: string;
|
|
392
|
+
}): Promise<{
|
|
393
|
+
runId: string;
|
|
394
|
+
}>;
|
|
395
|
+
/**
|
|
396
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
397
|
+
* @param params - Object containing the runId and triggerData
|
|
398
|
+
* @returns Promise containing success message
|
|
399
|
+
*/
|
|
400
|
+
start(params: {
|
|
401
|
+
runId: string;
|
|
402
|
+
triggerData: Record<string, any>;
|
|
403
|
+
}): Promise<{
|
|
404
|
+
message: string;
|
|
405
|
+
}>;
|
|
406
|
+
/**
|
|
407
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
271
408
|
* @param stepId - ID of the step to resume
|
|
272
409
|
* @param runId - ID of the workflow run
|
|
273
410
|
* @param context - Context to resume the workflow with
|
|
@@ -277,12 +414,44 @@ declare class Workflow extends BaseResource {
|
|
|
277
414
|
stepId: string;
|
|
278
415
|
runId: string;
|
|
279
416
|
context: Record<string, any>;
|
|
280
|
-
}): Promise<
|
|
417
|
+
}): Promise<{
|
|
418
|
+
message: string;
|
|
419
|
+
}>;
|
|
420
|
+
/**
|
|
421
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
422
|
+
* @param params - Object containing the optional runId and triggerData
|
|
423
|
+
* @returns Promise containing the workflow execution results
|
|
424
|
+
*/
|
|
425
|
+
startAsync(params: {
|
|
426
|
+
runId?: string;
|
|
427
|
+
triggerData: Record<string, any>;
|
|
428
|
+
}): Promise<WorkflowRunResult>;
|
|
429
|
+
/**
|
|
430
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
431
|
+
* @param params - Object containing the runId, stepId, and context
|
|
432
|
+
* @returns Promise containing the workflow resume results
|
|
433
|
+
*/
|
|
434
|
+
resumeAsync(params: {
|
|
435
|
+
runId: string;
|
|
436
|
+
stepId: string;
|
|
437
|
+
context: Record<string, any>;
|
|
438
|
+
}): Promise<WorkflowRunResult>;
|
|
439
|
+
/**
|
|
440
|
+
* Creates an async generator that processes a readable stream and yields records
|
|
441
|
+
* separated by the Record Separator character (\x1E)
|
|
442
|
+
*
|
|
443
|
+
* @param stream - The readable stream to process
|
|
444
|
+
* @returns An async generator that yields parsed records
|
|
445
|
+
*/
|
|
446
|
+
private streamProcessor;
|
|
281
447
|
/**
|
|
282
448
|
* Watches workflow transitions in real-time
|
|
283
|
-
* @
|
|
449
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
450
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
284
451
|
*/
|
|
285
|
-
watch(
|
|
452
|
+
watch({ runId }: {
|
|
453
|
+
runId?: string;
|
|
454
|
+
}, onRecord: (record: WorkflowRunResult) => void): Promise<void>;
|
|
286
455
|
}
|
|
287
456
|
|
|
288
457
|
declare class Tool extends BaseResource {
|
|
@@ -400,6 +569,17 @@ declare class MastraClient extends BaseResource {
|
|
|
400
569
|
* @returns Promise containing telemetry data
|
|
401
570
|
*/
|
|
402
571
|
getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse>;
|
|
572
|
+
/**
|
|
573
|
+
* Retrieves all available networks
|
|
574
|
+
* @returns Promise containing map of network IDs to network details
|
|
575
|
+
*/
|
|
576
|
+
getNetworks(): Promise<Record<string, GetNetworkResponse>>;
|
|
577
|
+
/**
|
|
578
|
+
* Gets a network instance by ID
|
|
579
|
+
* @param networkId - ID of the network to retrieve
|
|
580
|
+
* @returns Network instance
|
|
581
|
+
*/
|
|
582
|
+
getNetwork(networkId: string): Network;
|
|
403
583
|
}
|
|
404
584
|
|
|
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 };
|
|
585
|
+
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 };
|