@mastra/client-js 0.0.0-separate-trace-data-from-component-20250501141108 → 0.0.0-share-agent-metadata-with-cloud-20250718123411
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 +924 -2
- package/LICENSE.md +11 -42
- package/README.md +1 -1
- package/dist/index.cjs +1501 -121
- package/dist/index.d.cts +566 -87
- package/dist/index.d.ts +566 -87
- package/dist/index.js +1508 -132
- package/package.json +24 -16
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +317 -23
- package/src/example.ts +59 -29
- package/src/index.test.ts +132 -6
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +648 -52
- package/src/resources/base.ts +3 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +140 -132
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +6 -13
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +273 -95
- package/src/types.ts +199 -23
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/src/types.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
MastraMessageV1,
|
|
3
3
|
AiMessageType,
|
|
4
4
|
CoreMessage,
|
|
5
5
|
QueryResult,
|
|
6
|
-
StepAction,
|
|
7
|
-
StepGraph,
|
|
8
6
|
StorageThreadType,
|
|
9
|
-
BaseLogMessage,
|
|
10
|
-
WorkflowRunResult as CoreWorkflowRunResult,
|
|
11
7
|
WorkflowRuns,
|
|
8
|
+
WorkflowRun,
|
|
9
|
+
LegacyWorkflowRuns,
|
|
12
10
|
} from '@mastra/core';
|
|
11
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
12
|
+
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
import type {
|
|
14
|
+
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
15
|
+
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
16
|
+
import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
|
|
17
|
+
import type {
|
|
18
|
+
StepAction,
|
|
19
|
+
StepGraph,
|
|
20
|
+
LegacyWorkflowRunResult as CoreLegacyWorkflowRunResult,
|
|
21
|
+
} from '@mastra/core/workflows/legacy';
|
|
16
22
|
import type { JSONSchema7 } from 'json-schema';
|
|
17
23
|
import type { ZodSchema } from 'zod';
|
|
18
24
|
|
|
@@ -28,6 +34,7 @@ export interface ClientOptions {
|
|
|
28
34
|
/** Custom headers to include with requests */
|
|
29
35
|
headers?: Record<string, string>;
|
|
30
36
|
/** Abort signal for request */
|
|
37
|
+
abortSignal?: AbortSignal;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
export interface RequestOptions {
|
|
@@ -35,24 +42,48 @@ export interface RequestOptions {
|
|
|
35
42
|
headers?: Record<string, string>;
|
|
36
43
|
body?: any;
|
|
37
44
|
stream?: boolean;
|
|
38
|
-
signal?: AbortSignal;
|
|
39
45
|
}
|
|
40
46
|
|
|
47
|
+
type WithoutMethods<T> = {
|
|
48
|
+
[K in keyof T as T[K] extends (...args: any[]) => any
|
|
49
|
+
? never
|
|
50
|
+
: T[K] extends { (): any }
|
|
51
|
+
? never
|
|
52
|
+
: T[K] extends undefined | ((...args: any[]) => any)
|
|
53
|
+
? never
|
|
54
|
+
: K]: T[K];
|
|
55
|
+
};
|
|
56
|
+
|
|
41
57
|
export interface GetAgentResponse {
|
|
42
58
|
name: string;
|
|
43
59
|
instructions: string;
|
|
44
60
|
tools: Record<string, GetToolResponse>;
|
|
61
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
45
62
|
provider: string;
|
|
46
63
|
modelId: string;
|
|
64
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
65
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
50
69
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
51
|
-
|
|
70
|
+
output?: T;
|
|
71
|
+
experimental_output?: T;
|
|
72
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
73
|
+
clientTools?: ToolsInput;
|
|
74
|
+
} & WithoutMethods<
|
|
75
|
+
Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
|
|
76
|
+
>;
|
|
52
77
|
|
|
53
78
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
54
79
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
55
|
-
|
|
80
|
+
output?: T;
|
|
81
|
+
experimental_output?: T;
|
|
82
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
83
|
+
clientTools?: ToolsInput;
|
|
84
|
+
} & WithoutMethods<
|
|
85
|
+
Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
|
|
86
|
+
>;
|
|
56
87
|
|
|
57
88
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
58
89
|
evals: any[];
|
|
@@ -68,7 +99,7 @@ export interface GetToolResponse {
|
|
|
68
99
|
outputSchema: string;
|
|
69
100
|
}
|
|
70
101
|
|
|
71
|
-
export interface
|
|
102
|
+
export interface GetLegacyWorkflowResponse {
|
|
72
103
|
name: string;
|
|
73
104
|
triggerSchema: string;
|
|
74
105
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -77,17 +108,32 @@ export interface GetWorkflowResponse {
|
|
|
77
108
|
workflowId?: string;
|
|
78
109
|
}
|
|
79
110
|
|
|
111
|
+
export interface GetWorkflowRunsParams {
|
|
112
|
+
fromDate?: Date;
|
|
113
|
+
toDate?: Date;
|
|
114
|
+
limit?: number;
|
|
115
|
+
offset?: number;
|
|
116
|
+
resourceId?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
120
|
+
|
|
80
121
|
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
81
122
|
|
|
82
|
-
export type
|
|
123
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
124
|
+
|
|
125
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
126
|
+
|
|
127
|
+
export type LegacyWorkflowRunResult = {
|
|
83
128
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
84
|
-
results:
|
|
129
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
85
130
|
timestamp: number;
|
|
86
131
|
runId: string;
|
|
87
132
|
};
|
|
88
133
|
|
|
89
|
-
export interface
|
|
134
|
+
export interface GetWorkflowResponse {
|
|
90
135
|
name: string;
|
|
136
|
+
description?: string;
|
|
91
137
|
steps: {
|
|
92
138
|
[key: string]: {
|
|
93
139
|
id: string;
|
|
@@ -98,14 +144,25 @@ export interface GetVNextWorkflowResponse {
|
|
|
98
144
|
suspendSchema: string;
|
|
99
145
|
};
|
|
100
146
|
};
|
|
101
|
-
|
|
147
|
+
allSteps: {
|
|
148
|
+
[key: string]: {
|
|
149
|
+
id: string;
|
|
150
|
+
description: string;
|
|
151
|
+
inputSchema: string;
|
|
152
|
+
outputSchema: string;
|
|
153
|
+
resumeSchema: string;
|
|
154
|
+
suspendSchema: string;
|
|
155
|
+
isWorkflow: boolean;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
102
159
|
inputSchema: string;
|
|
103
160
|
outputSchema: string;
|
|
104
161
|
}
|
|
105
162
|
|
|
106
|
-
export type
|
|
163
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
107
164
|
|
|
108
|
-
export type
|
|
165
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
109
166
|
export interface UpsertVectorParams {
|
|
110
167
|
indexName: string;
|
|
111
168
|
vectors: number[][];
|
|
@@ -137,20 +194,33 @@ export interface GetVectorIndexResponse {
|
|
|
137
194
|
}
|
|
138
195
|
|
|
139
196
|
export interface SaveMessageToMemoryParams {
|
|
140
|
-
messages:
|
|
197
|
+
messages: MastraMessageV1[];
|
|
141
198
|
agentId: string;
|
|
142
199
|
}
|
|
143
200
|
|
|
144
|
-
export
|
|
201
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
202
|
+
messages: MastraMessageV1[];
|
|
203
|
+
networkId: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
145
207
|
|
|
146
208
|
export interface CreateMemoryThreadParams {
|
|
147
|
-
title
|
|
148
|
-
metadata
|
|
209
|
+
title?: string;
|
|
210
|
+
metadata?: Record<string, any>;
|
|
149
211
|
resourceId: string;
|
|
150
|
-
threadId
|
|
212
|
+
threadId?: string;
|
|
151
213
|
agentId: string;
|
|
152
214
|
}
|
|
153
215
|
|
|
216
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
217
|
+
title?: string;
|
|
218
|
+
metadata?: Record<string, any>;
|
|
219
|
+
resourceId: string;
|
|
220
|
+
threadId?: string;
|
|
221
|
+
networkId: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
154
224
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
155
225
|
|
|
156
226
|
export interface GetMemoryThreadParams {
|
|
@@ -158,6 +228,11 @@ export interface GetMemoryThreadParams {
|
|
|
158
228
|
agentId: string;
|
|
159
229
|
}
|
|
160
230
|
|
|
231
|
+
export interface GetNetworkMemoryThreadParams {
|
|
232
|
+
resourceId: string;
|
|
233
|
+
networkId: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
161
236
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
162
237
|
|
|
163
238
|
export interface UpdateMemoryThreadParams {
|
|
@@ -166,6 +241,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
166
241
|
resourceId: string;
|
|
167
242
|
}
|
|
168
243
|
|
|
244
|
+
export interface GetMemoryThreadMessagesParams {
|
|
245
|
+
/**
|
|
246
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
247
|
+
*/
|
|
248
|
+
limit?: number;
|
|
249
|
+
}
|
|
250
|
+
|
|
169
251
|
export interface GetMemoryThreadMessagesResponse {
|
|
170
252
|
messages: CoreMessage[];
|
|
171
253
|
uiMessages: AiMessageType[];
|
|
@@ -173,14 +255,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
173
255
|
|
|
174
256
|
export interface GetLogsParams {
|
|
175
257
|
transportId: string;
|
|
258
|
+
fromDate?: Date;
|
|
259
|
+
toDate?: Date;
|
|
260
|
+
logLevel?: LogLevel;
|
|
261
|
+
filters?: Record<string, string>;
|
|
262
|
+
page?: number;
|
|
263
|
+
perPage?: number;
|
|
176
264
|
}
|
|
177
265
|
|
|
178
266
|
export interface GetLogParams {
|
|
179
267
|
runId: string;
|
|
180
268
|
transportId: string;
|
|
269
|
+
fromDate?: Date;
|
|
270
|
+
toDate?: Date;
|
|
271
|
+
logLevel?: LogLevel;
|
|
272
|
+
filters?: Record<string, string>;
|
|
273
|
+
page?: number;
|
|
274
|
+
perPage?: number;
|
|
181
275
|
}
|
|
182
276
|
|
|
183
|
-
export type GetLogsResponse =
|
|
277
|
+
export type GetLogsResponse = {
|
|
278
|
+
logs: BaseLogMessage[];
|
|
279
|
+
total: number;
|
|
280
|
+
page: number;
|
|
281
|
+
perPage: number;
|
|
282
|
+
hasMore: boolean;
|
|
283
|
+
};
|
|
184
284
|
|
|
185
285
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
186
286
|
|
|
@@ -234,9 +334,12 @@ export interface GetTelemetryParams {
|
|
|
234
334
|
page?: number;
|
|
235
335
|
perPage?: number;
|
|
236
336
|
attribute?: Record<string, string>;
|
|
337
|
+
fromDate?: Date;
|
|
338
|
+
toDate?: Date;
|
|
237
339
|
}
|
|
238
340
|
|
|
239
341
|
export interface GetNetworkResponse {
|
|
342
|
+
id: string;
|
|
240
343
|
name: string;
|
|
241
344
|
instructions: string;
|
|
242
345
|
agents: Array<{
|
|
@@ -250,3 +353,76 @@ export interface GetNetworkResponse {
|
|
|
250
353
|
};
|
|
251
354
|
state?: Record<string, any>;
|
|
252
355
|
}
|
|
356
|
+
|
|
357
|
+
export interface GetVNextNetworkResponse {
|
|
358
|
+
id: string;
|
|
359
|
+
name: string;
|
|
360
|
+
instructions: string;
|
|
361
|
+
agents: Array<{
|
|
362
|
+
name: string;
|
|
363
|
+
provider: string;
|
|
364
|
+
modelId: string;
|
|
365
|
+
}>;
|
|
366
|
+
routingModel: {
|
|
367
|
+
provider: string;
|
|
368
|
+
modelId: string;
|
|
369
|
+
};
|
|
370
|
+
workflows: Array<{
|
|
371
|
+
name: string;
|
|
372
|
+
description: string;
|
|
373
|
+
inputSchema: string | undefined;
|
|
374
|
+
outputSchema: string | undefined;
|
|
375
|
+
}>;
|
|
376
|
+
tools: Array<{
|
|
377
|
+
id: string;
|
|
378
|
+
description: string;
|
|
379
|
+
}>;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export interface GenerateVNextNetworkResponse {
|
|
383
|
+
task: string;
|
|
384
|
+
result: string;
|
|
385
|
+
resourceId: string;
|
|
386
|
+
resourceType: 'none' | 'tool' | 'agent' | 'workflow';
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface GenerateOrStreamVNextNetworkParams {
|
|
390
|
+
message: string;
|
|
391
|
+
threadId?: string;
|
|
392
|
+
resourceId?: string;
|
|
393
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface LoopStreamVNextNetworkParams {
|
|
397
|
+
message: string;
|
|
398
|
+
threadId?: string;
|
|
399
|
+
resourceId?: string;
|
|
400
|
+
maxIterations?: number;
|
|
401
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export interface LoopVNextNetworkResponse {
|
|
405
|
+
status: 'success';
|
|
406
|
+
result: {
|
|
407
|
+
text: string;
|
|
408
|
+
};
|
|
409
|
+
steps: WorkflowResult<any, any>['steps'];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export interface McpServerListResponse {
|
|
413
|
+
servers: ServerInfo[];
|
|
414
|
+
next: string | null;
|
|
415
|
+
total_count: number;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export interface McpToolInfo {
|
|
419
|
+
id: string;
|
|
420
|
+
name: string;
|
|
421
|
+
description?: string;
|
|
422
|
+
inputSchema: string;
|
|
423
|
+
toolType?: MCPToolType;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export interface McpServerToolListResponse {
|
|
427
|
+
tools: McpToolInfo[];
|
|
428
|
+
}
|
|
@@ -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,32 @@
|
|
|
1
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
2
|
+
import { zodToJsonSchema } from './zod-to-json-schema';
|
|
3
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
4
|
+
|
|
5
|
+
export function processClientTools(clientTools: ToolsInput | undefined): ToolsInput | undefined {
|
|
6
|
+
if (!clientTools) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return Object.fromEntries(
|
|
11
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
12
|
+
if (isVercelTool(value)) {
|
|
13
|
+
return [
|
|
14
|
+
key,
|
|
15
|
+
{
|
|
16
|
+
...value,
|
|
17
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : undefined,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
} else {
|
|
21
|
+
return [
|
|
22
|
+
key,
|
|
23
|
+
{
|
|
24
|
+
...value,
|
|
25
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : undefined,
|
|
26
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : undefined,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -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
|
+
}
|