@mastra/client-js 0.0.0-separate-trace-data-from-component-20250501141108 → 0.0.0-support-d1-client-20250701191943
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 +695 -2
- package/README.md +1 -1
- package/dist/index.cjs +1406 -119
- package/dist/index.d.cts +521 -84
- package/dist/index.d.ts +521 -84
- package/dist/index.js +1405 -122
- 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 -23
- package/src/example.ts +33 -31
- package/src/index.test.ts +121 -1
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +603 -44
- package/src/resources/base.ts +2 -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 +177 -0
- package/src/resources/workflow.ts +256 -95
- package/src/types.ts +192 -22
- 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
|
|
|
@@ -38,21 +44,42 @@ export interface RequestOptions {
|
|
|
38
44
|
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<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
52
75
|
|
|
53
76
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
54
77
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
55
|
-
|
|
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'>>;
|
|
56
83
|
|
|
57
84
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
58
85
|
evals: any[];
|
|
@@ -68,7 +95,7 @@ export interface GetToolResponse {
|
|
|
68
95
|
outputSchema: string;
|
|
69
96
|
}
|
|
70
97
|
|
|
71
|
-
export interface
|
|
98
|
+
export interface GetLegacyWorkflowResponse {
|
|
72
99
|
name: string;
|
|
73
100
|
triggerSchema: string;
|
|
74
101
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -77,17 +104,32 @@ export interface GetWorkflowResponse {
|
|
|
77
104
|
workflowId?: string;
|
|
78
105
|
}
|
|
79
106
|
|
|
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
|
+
|
|
80
117
|
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
81
118
|
|
|
82
|
-
export type
|
|
119
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
120
|
+
|
|
121
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
122
|
+
|
|
123
|
+
export type LegacyWorkflowRunResult = {
|
|
83
124
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
84
|
-
results:
|
|
125
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
85
126
|
timestamp: number;
|
|
86
127
|
runId: string;
|
|
87
128
|
};
|
|
88
129
|
|
|
89
|
-
export interface
|
|
130
|
+
export interface GetWorkflowResponse {
|
|
90
131
|
name: string;
|
|
132
|
+
description?: string;
|
|
91
133
|
steps: {
|
|
92
134
|
[key: string]: {
|
|
93
135
|
id: string;
|
|
@@ -98,14 +140,25 @@ export interface GetVNextWorkflowResponse {
|
|
|
98
140
|
suspendSchema: string;
|
|
99
141
|
};
|
|
100
142
|
};
|
|
101
|
-
|
|
143
|
+
allSteps: {
|
|
144
|
+
[key: string]: {
|
|
145
|
+
id: string;
|
|
146
|
+
description: string;
|
|
147
|
+
inputSchema: string;
|
|
148
|
+
outputSchema: string;
|
|
149
|
+
resumeSchema: string;
|
|
150
|
+
suspendSchema: string;
|
|
151
|
+
isWorkflow: boolean;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
102
155
|
inputSchema: string;
|
|
103
156
|
outputSchema: string;
|
|
104
157
|
}
|
|
105
158
|
|
|
106
|
-
export type
|
|
159
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
107
160
|
|
|
108
|
-
export type
|
|
161
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
109
162
|
export interface UpsertVectorParams {
|
|
110
163
|
indexName: string;
|
|
111
164
|
vectors: number[][];
|
|
@@ -137,20 +190,33 @@ export interface GetVectorIndexResponse {
|
|
|
137
190
|
}
|
|
138
191
|
|
|
139
192
|
export interface SaveMessageToMemoryParams {
|
|
140
|
-
messages:
|
|
193
|
+
messages: MastraMessageV1[];
|
|
141
194
|
agentId: string;
|
|
142
195
|
}
|
|
143
196
|
|
|
144
|
-
export
|
|
197
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
198
|
+
messages: MastraMessageV1[];
|
|
199
|
+
networkId: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
145
203
|
|
|
146
204
|
export interface CreateMemoryThreadParams {
|
|
147
|
-
title
|
|
148
|
-
metadata
|
|
205
|
+
title?: string;
|
|
206
|
+
metadata?: Record<string, any>;
|
|
149
207
|
resourceId: string;
|
|
150
|
-
threadId
|
|
208
|
+
threadId?: string;
|
|
151
209
|
agentId: string;
|
|
152
210
|
}
|
|
153
211
|
|
|
212
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
213
|
+
title?: string;
|
|
214
|
+
metadata?: Record<string, any>;
|
|
215
|
+
resourceId: string;
|
|
216
|
+
threadId?: string;
|
|
217
|
+
networkId: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
154
220
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
155
221
|
|
|
156
222
|
export interface GetMemoryThreadParams {
|
|
@@ -158,6 +224,11 @@ export interface GetMemoryThreadParams {
|
|
|
158
224
|
agentId: string;
|
|
159
225
|
}
|
|
160
226
|
|
|
227
|
+
export interface GetNetworkMemoryThreadParams {
|
|
228
|
+
resourceId: string;
|
|
229
|
+
networkId: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
161
232
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
162
233
|
|
|
163
234
|
export interface UpdateMemoryThreadParams {
|
|
@@ -166,6 +237,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
166
237
|
resourceId: string;
|
|
167
238
|
}
|
|
168
239
|
|
|
240
|
+
export interface GetMemoryThreadMessagesParams {
|
|
241
|
+
/**
|
|
242
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
243
|
+
*/
|
|
244
|
+
limit?: number;
|
|
245
|
+
}
|
|
246
|
+
|
|
169
247
|
export interface GetMemoryThreadMessagesResponse {
|
|
170
248
|
messages: CoreMessage[];
|
|
171
249
|
uiMessages: AiMessageType[];
|
|
@@ -173,14 +251,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
173
251
|
|
|
174
252
|
export interface GetLogsParams {
|
|
175
253
|
transportId: string;
|
|
254
|
+
fromDate?: Date;
|
|
255
|
+
toDate?: Date;
|
|
256
|
+
logLevel?: LogLevel;
|
|
257
|
+
filters?: Record<string, string>;
|
|
258
|
+
page?: number;
|
|
259
|
+
perPage?: number;
|
|
176
260
|
}
|
|
177
261
|
|
|
178
262
|
export interface GetLogParams {
|
|
179
263
|
runId: string;
|
|
180
264
|
transportId: string;
|
|
265
|
+
fromDate?: Date;
|
|
266
|
+
toDate?: Date;
|
|
267
|
+
logLevel?: LogLevel;
|
|
268
|
+
filters?: Record<string, string>;
|
|
269
|
+
page?: number;
|
|
270
|
+
perPage?: number;
|
|
181
271
|
}
|
|
182
272
|
|
|
183
|
-
export type GetLogsResponse =
|
|
273
|
+
export type GetLogsResponse = {
|
|
274
|
+
logs: BaseLogMessage[];
|
|
275
|
+
total: number;
|
|
276
|
+
page: number;
|
|
277
|
+
perPage: number;
|
|
278
|
+
hasMore: boolean;
|
|
279
|
+
};
|
|
184
280
|
|
|
185
281
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
186
282
|
|
|
@@ -234,9 +330,12 @@ export interface GetTelemetryParams {
|
|
|
234
330
|
page?: number;
|
|
235
331
|
perPage?: number;
|
|
236
332
|
attribute?: Record<string, string>;
|
|
333
|
+
fromDate?: Date;
|
|
334
|
+
toDate?: Date;
|
|
237
335
|
}
|
|
238
336
|
|
|
239
337
|
export interface GetNetworkResponse {
|
|
338
|
+
id: string;
|
|
240
339
|
name: string;
|
|
241
340
|
instructions: string;
|
|
242
341
|
agents: Array<{
|
|
@@ -250,3 +349,74 @@ export interface GetNetworkResponse {
|
|
|
250
349
|
};
|
|
251
350
|
state?: Record<string, any>;
|
|
252
351
|
}
|
|
352
|
+
|
|
353
|
+
export interface GetVNextNetworkResponse {
|
|
354
|
+
id: string;
|
|
355
|
+
name: string;
|
|
356
|
+
instructions: string;
|
|
357
|
+
agents: Array<{
|
|
358
|
+
name: string;
|
|
359
|
+
provider: string;
|
|
360
|
+
modelId: string;
|
|
361
|
+
}>;
|
|
362
|
+
routingModel: {
|
|
363
|
+
provider: string;
|
|
364
|
+
modelId: string;
|
|
365
|
+
};
|
|
366
|
+
workflows: Array<{
|
|
367
|
+
name: string;
|
|
368
|
+
description: string;
|
|
369
|
+
inputSchema: string | undefined;
|
|
370
|
+
outputSchema: string | undefined;
|
|
371
|
+
}>;
|
|
372
|
+
tools: Array<{
|
|
373
|
+
id: string;
|
|
374
|
+
description: string;
|
|
375
|
+
}>;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface GenerateVNextNetworkResponse {
|
|
379
|
+
task: string;
|
|
380
|
+
result: string;
|
|
381
|
+
resourceId: string;
|
|
382
|
+
resourceType: 'none' | 'tool' | 'agent' | 'workflow';
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface GenerateOrStreamVNextNetworkParams {
|
|
386
|
+
message: string;
|
|
387
|
+
threadId?: string;
|
|
388
|
+
resourceId?: string;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface LoopStreamVNextNetworkParams {
|
|
392
|
+
message: string;
|
|
393
|
+
threadId?: string;
|
|
394
|
+
resourceId?: string;
|
|
395
|
+
maxIterations?: number;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface LoopVNextNetworkResponse {
|
|
399
|
+
status: 'success';
|
|
400
|
+
result: {
|
|
401
|
+
text: string;
|
|
402
|
+
};
|
|
403
|
+
steps: WorkflowResult<any, any>['steps'];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface McpServerListResponse {
|
|
407
|
+
servers: ServerInfo[];
|
|
408
|
+
next: string | null;
|
|
409
|
+
total_count: number;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export interface McpToolInfo {
|
|
413
|
+
id: string;
|
|
414
|
+
name: string;
|
|
415
|
+
description?: string;
|
|
416
|
+
inputSchema: string;
|
|
417
|
+
toolType?: MCPToolType;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export interface McpServerToolListResponse {
|
|
421
|
+
tools: McpToolInfo[];
|
|
422
|
+
}
|
|
@@ -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
|
+
}
|