@mastra/client-js 0.0.0-switch-to-core-20250424015131 → 0.0.0-tool-call-parts-20250630193309
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 +813 -2
- package/README.md +1 -1
- package/dist/index.cjs +1546 -93
- package/dist/index.d.cts +588 -40
- package/dist/index.d.ts +588 -40
- package/dist/index.js +1545 -96
- package/package.json +22 -15
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +271 -5
- package/src/example.ts +33 -31
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +585 -45
- package/src/resources/base.ts +3 -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-memory-thread.ts +63 -0
- package/src/resources/network.ts +7 -14
- package/src/resources/tool.ts +16 -3
- package/src/resources/vNextNetwork.ts +177 -0
- package/src/resources/workflow.ts +254 -96
- package/src/types.ts +204 -17
- 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,16 +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
|
-
|
|
10
|
-
|
|
7
|
+
WorkflowRuns,
|
|
8
|
+
WorkflowRun,
|
|
9
|
+
LegacyWorkflowRuns,
|
|
11
10
|
} from '@mastra/core';
|
|
11
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
12
|
+
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
12
13
|
|
|
13
|
-
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';
|
|
14
22
|
import type { JSONSchema7 } from 'json-schema';
|
|
15
23
|
import type { ZodSchema } from 'zod';
|
|
16
24
|
|
|
@@ -36,24 +44,48 @@ export interface RequestOptions {
|
|
|
36
44
|
signal?: AbortSignal;
|
|
37
45
|
}
|
|
38
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
|
+
|
|
39
57
|
export interface GetAgentResponse {
|
|
40
58
|
name: string;
|
|
41
59
|
instructions: string;
|
|
42
60
|
tools: Record<string, GetToolResponse>;
|
|
61
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
43
62
|
provider: string;
|
|
44
63
|
modelId: string;
|
|
64
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
65
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
45
66
|
}
|
|
46
67
|
|
|
47
68
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
48
69
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
49
|
-
|
|
70
|
+
output?: T;
|
|
71
|
+
experimental_output?: T;
|
|
72
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
73
|
+
clientTools?: ToolsInput;
|
|
74
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
50
75
|
|
|
51
76
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
52
77
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
53
|
-
|
|
78
|
+
output?: T;
|
|
79
|
+
experimental_output?: T;
|
|
80
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
81
|
+
clientTools?: ToolsInput;
|
|
82
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
54
83
|
|
|
55
84
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
56
85
|
evals: any[];
|
|
86
|
+
instructions: string;
|
|
87
|
+
name: string;
|
|
88
|
+
id: string;
|
|
57
89
|
}
|
|
58
90
|
|
|
59
91
|
export interface GetToolResponse {
|
|
@@ -63,7 +95,7 @@ export interface GetToolResponse {
|
|
|
63
95
|
outputSchema: string;
|
|
64
96
|
}
|
|
65
97
|
|
|
66
|
-
export interface
|
|
98
|
+
export interface GetLegacyWorkflowResponse {
|
|
67
99
|
name: string;
|
|
68
100
|
triggerSchema: string;
|
|
69
101
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -72,12 +104,50 @@ export interface GetWorkflowResponse {
|
|
|
72
104
|
workflowId?: string;
|
|
73
105
|
}
|
|
74
106
|
|
|
75
|
-
export
|
|
107
|
+
export interface GetWorkflowRunsParams {
|
|
108
|
+
fromDate?: Date;
|
|
109
|
+
toDate?: Date;
|
|
110
|
+
limit?: number;
|
|
111
|
+
offset?: number;
|
|
112
|
+
resourceId?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
116
|
+
|
|
117
|
+
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
118
|
+
|
|
119
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
120
|
+
|
|
121
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
122
|
+
|
|
123
|
+
export type LegacyWorkflowRunResult = {
|
|
76
124
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
77
|
-
results:
|
|
125
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
78
126
|
timestamp: number;
|
|
79
127
|
runId: string;
|
|
80
128
|
};
|
|
129
|
+
|
|
130
|
+
export interface GetWorkflowResponse {
|
|
131
|
+
name: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
steps: {
|
|
134
|
+
[key: string]: {
|
|
135
|
+
id: string;
|
|
136
|
+
description: string;
|
|
137
|
+
inputSchema: string;
|
|
138
|
+
outputSchema: string;
|
|
139
|
+
resumeSchema: string;
|
|
140
|
+
suspendSchema: string;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
144
|
+
inputSchema: string;
|
|
145
|
+
outputSchema: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
149
|
+
|
|
150
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
81
151
|
export interface UpsertVectorParams {
|
|
82
152
|
indexName: string;
|
|
83
153
|
vectors: number[][];
|
|
@@ -109,20 +179,33 @@ export interface GetVectorIndexResponse {
|
|
|
109
179
|
}
|
|
110
180
|
|
|
111
181
|
export interface SaveMessageToMemoryParams {
|
|
112
|
-
messages:
|
|
182
|
+
messages: MastraMessageV1[];
|
|
113
183
|
agentId: string;
|
|
114
184
|
}
|
|
115
185
|
|
|
116
|
-
export
|
|
186
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
187
|
+
messages: MastraMessageV1[];
|
|
188
|
+
networkId: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
117
192
|
|
|
118
193
|
export interface CreateMemoryThreadParams {
|
|
119
|
-
title
|
|
120
|
-
metadata
|
|
194
|
+
title?: string;
|
|
195
|
+
metadata?: Record<string, any>;
|
|
121
196
|
resourceId: string;
|
|
122
|
-
threadId
|
|
197
|
+
threadId?: string;
|
|
123
198
|
agentId: string;
|
|
124
199
|
}
|
|
125
200
|
|
|
201
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
202
|
+
title?: string;
|
|
203
|
+
metadata?: Record<string, any>;
|
|
204
|
+
resourceId: string;
|
|
205
|
+
threadId?: string;
|
|
206
|
+
networkId: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
126
209
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
127
210
|
|
|
128
211
|
export interface GetMemoryThreadParams {
|
|
@@ -130,6 +213,11 @@ export interface GetMemoryThreadParams {
|
|
|
130
213
|
agentId: string;
|
|
131
214
|
}
|
|
132
215
|
|
|
216
|
+
export interface GetNetworkMemoryThreadParams {
|
|
217
|
+
resourceId: string;
|
|
218
|
+
networkId: string;
|
|
219
|
+
}
|
|
220
|
+
|
|
133
221
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
134
222
|
|
|
135
223
|
export interface UpdateMemoryThreadParams {
|
|
@@ -138,6 +226,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
138
226
|
resourceId: string;
|
|
139
227
|
}
|
|
140
228
|
|
|
229
|
+
export interface GetMemoryThreadMessagesParams {
|
|
230
|
+
/**
|
|
231
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
232
|
+
*/
|
|
233
|
+
limit?: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
141
236
|
export interface GetMemoryThreadMessagesResponse {
|
|
142
237
|
messages: CoreMessage[];
|
|
143
238
|
uiMessages: AiMessageType[];
|
|
@@ -145,14 +240,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
145
240
|
|
|
146
241
|
export interface GetLogsParams {
|
|
147
242
|
transportId: string;
|
|
243
|
+
fromDate?: Date;
|
|
244
|
+
toDate?: Date;
|
|
245
|
+
logLevel?: LogLevel;
|
|
246
|
+
filters?: Record<string, string>;
|
|
247
|
+
page?: number;
|
|
248
|
+
perPage?: number;
|
|
148
249
|
}
|
|
149
250
|
|
|
150
251
|
export interface GetLogParams {
|
|
151
252
|
runId: string;
|
|
152
253
|
transportId: string;
|
|
254
|
+
fromDate?: Date;
|
|
255
|
+
toDate?: Date;
|
|
256
|
+
logLevel?: LogLevel;
|
|
257
|
+
filters?: Record<string, string>;
|
|
258
|
+
page?: number;
|
|
259
|
+
perPage?: number;
|
|
153
260
|
}
|
|
154
261
|
|
|
155
|
-
export type GetLogsResponse =
|
|
262
|
+
export type GetLogsResponse = {
|
|
263
|
+
logs: BaseLogMessage[];
|
|
264
|
+
total: number;
|
|
265
|
+
page: number;
|
|
266
|
+
perPage: number;
|
|
267
|
+
hasMore: boolean;
|
|
268
|
+
};
|
|
156
269
|
|
|
157
270
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
158
271
|
|
|
@@ -206,9 +319,12 @@ export interface GetTelemetryParams {
|
|
|
206
319
|
page?: number;
|
|
207
320
|
perPage?: number;
|
|
208
321
|
attribute?: Record<string, string>;
|
|
322
|
+
fromDate?: Date;
|
|
323
|
+
toDate?: Date;
|
|
209
324
|
}
|
|
210
325
|
|
|
211
326
|
export interface GetNetworkResponse {
|
|
327
|
+
id: string;
|
|
212
328
|
name: string;
|
|
213
329
|
instructions: string;
|
|
214
330
|
agents: Array<{
|
|
@@ -222,3 +338,74 @@ export interface GetNetworkResponse {
|
|
|
222
338
|
};
|
|
223
339
|
state?: Record<string, any>;
|
|
224
340
|
}
|
|
341
|
+
|
|
342
|
+
export interface GetVNextNetworkResponse {
|
|
343
|
+
id: string;
|
|
344
|
+
name: string;
|
|
345
|
+
instructions: string;
|
|
346
|
+
agents: Array<{
|
|
347
|
+
name: string;
|
|
348
|
+
provider: string;
|
|
349
|
+
modelId: string;
|
|
350
|
+
}>;
|
|
351
|
+
routingModel: {
|
|
352
|
+
provider: string;
|
|
353
|
+
modelId: string;
|
|
354
|
+
};
|
|
355
|
+
workflows: Array<{
|
|
356
|
+
name: string;
|
|
357
|
+
description: string;
|
|
358
|
+
inputSchema: string | undefined;
|
|
359
|
+
outputSchema: string | undefined;
|
|
360
|
+
}>;
|
|
361
|
+
tools: Array<{
|
|
362
|
+
id: string;
|
|
363
|
+
description: string;
|
|
364
|
+
}>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface GenerateVNextNetworkResponse {
|
|
368
|
+
task: string;
|
|
369
|
+
result: string;
|
|
370
|
+
resourceId: string;
|
|
371
|
+
resourceType: 'none' | 'tool' | 'agent' | 'workflow';
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export interface GenerateOrStreamVNextNetworkParams {
|
|
375
|
+
message: string;
|
|
376
|
+
threadId?: string;
|
|
377
|
+
resourceId?: string;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface LoopStreamVNextNetworkParams {
|
|
381
|
+
message: string;
|
|
382
|
+
threadId?: string;
|
|
383
|
+
resourceId?: string;
|
|
384
|
+
maxIterations?: number;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface LoopVNextNetworkResponse {
|
|
388
|
+
status: 'success';
|
|
389
|
+
result: {
|
|
390
|
+
text: string;
|
|
391
|
+
};
|
|
392
|
+
steps: WorkflowResult<any, any>['steps'];
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export interface McpServerListResponse {
|
|
396
|
+
servers: ServerInfo[];
|
|
397
|
+
next: string | null;
|
|
398
|
+
total_count: number;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface McpToolInfo {
|
|
402
|
+
id: string;
|
|
403
|
+
name: string;
|
|
404
|
+
description?: string;
|
|
405
|
+
inputSchema: string;
|
|
406
|
+
toolType?: MCPToolType;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface McpServerToolListResponse {
|
|
410
|
+
tools: McpToolInfo[];
|
|
411
|
+
}
|
|
@@ -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
|
+
}
|