@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-tsconfig-compile-20250703214351
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 +711 -2
- package/README.md +1 -1
- package/dist/index.cjs +1211 -141
- package/dist/index.d.cts +517 -83
- package/dist/index.d.ts +517 -83
- package/dist/index.js +1210 -144
- package/package.json +20 -15
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +243 -22
- 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} +124 -139
- 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 +241 -96
- package/src/types.ts +182 -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>>;
|
|
@@ -85,17 +112,24 @@ export interface GetWorkflowRunsParams {
|
|
|
85
112
|
resourceId?: string;
|
|
86
113
|
}
|
|
87
114
|
|
|
115
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
116
|
+
|
|
88
117
|
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
89
118
|
|
|
90
|
-
export type
|
|
119
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
120
|
+
|
|
121
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
122
|
+
|
|
123
|
+
export type LegacyWorkflowRunResult = {
|
|
91
124
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
92
|
-
results:
|
|
125
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
93
126
|
timestamp: number;
|
|
94
127
|
runId: string;
|
|
95
128
|
};
|
|
96
129
|
|
|
97
|
-
export interface
|
|
130
|
+
export interface GetWorkflowResponse {
|
|
98
131
|
name: string;
|
|
132
|
+
description?: string;
|
|
99
133
|
steps: {
|
|
100
134
|
[key: string]: {
|
|
101
135
|
id: string;
|
|
@@ -106,14 +140,25 @@ export interface GetVNextWorkflowResponse {
|
|
|
106
140
|
suspendSchema: string;
|
|
107
141
|
};
|
|
108
142
|
};
|
|
109
|
-
|
|
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'];
|
|
110
155
|
inputSchema: string;
|
|
111
156
|
outputSchema: string;
|
|
112
157
|
}
|
|
113
158
|
|
|
114
|
-
export type
|
|
159
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
115
160
|
|
|
116
|
-
export type
|
|
161
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
117
162
|
export interface UpsertVectorParams {
|
|
118
163
|
indexName: string;
|
|
119
164
|
vectors: number[][];
|
|
@@ -145,20 +190,33 @@ export interface GetVectorIndexResponse {
|
|
|
145
190
|
}
|
|
146
191
|
|
|
147
192
|
export interface SaveMessageToMemoryParams {
|
|
148
|
-
messages:
|
|
193
|
+
messages: MastraMessageV1[];
|
|
149
194
|
agentId: string;
|
|
150
195
|
}
|
|
151
196
|
|
|
152
|
-
export
|
|
197
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
198
|
+
messages: MastraMessageV1[];
|
|
199
|
+
networkId: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
153
203
|
|
|
154
204
|
export interface CreateMemoryThreadParams {
|
|
155
|
-
title
|
|
156
|
-
metadata
|
|
205
|
+
title?: string;
|
|
206
|
+
metadata?: Record<string, any>;
|
|
157
207
|
resourceId: string;
|
|
158
|
-
threadId
|
|
208
|
+
threadId?: string;
|
|
159
209
|
agentId: string;
|
|
160
210
|
}
|
|
161
211
|
|
|
212
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
213
|
+
title?: string;
|
|
214
|
+
metadata?: Record<string, any>;
|
|
215
|
+
resourceId: string;
|
|
216
|
+
threadId?: string;
|
|
217
|
+
networkId: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
162
220
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
163
221
|
|
|
164
222
|
export interface GetMemoryThreadParams {
|
|
@@ -166,6 +224,11 @@ export interface GetMemoryThreadParams {
|
|
|
166
224
|
agentId: string;
|
|
167
225
|
}
|
|
168
226
|
|
|
227
|
+
export interface GetNetworkMemoryThreadParams {
|
|
228
|
+
resourceId: string;
|
|
229
|
+
networkId: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
169
232
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
170
233
|
|
|
171
234
|
export interface UpdateMemoryThreadParams {
|
|
@@ -174,6 +237,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
174
237
|
resourceId: string;
|
|
175
238
|
}
|
|
176
239
|
|
|
240
|
+
export interface GetMemoryThreadMessagesParams {
|
|
241
|
+
/**
|
|
242
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
243
|
+
*/
|
|
244
|
+
limit?: number;
|
|
245
|
+
}
|
|
246
|
+
|
|
177
247
|
export interface GetMemoryThreadMessagesResponse {
|
|
178
248
|
messages: CoreMessage[];
|
|
179
249
|
uiMessages: AiMessageType[];
|
|
@@ -181,14 +251,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
181
251
|
|
|
182
252
|
export interface GetLogsParams {
|
|
183
253
|
transportId: string;
|
|
254
|
+
fromDate?: Date;
|
|
255
|
+
toDate?: Date;
|
|
256
|
+
logLevel?: LogLevel;
|
|
257
|
+
filters?: Record<string, string>;
|
|
258
|
+
page?: number;
|
|
259
|
+
perPage?: number;
|
|
184
260
|
}
|
|
185
261
|
|
|
186
262
|
export interface GetLogParams {
|
|
187
263
|
runId: string;
|
|
188
264
|
transportId: string;
|
|
265
|
+
fromDate?: Date;
|
|
266
|
+
toDate?: Date;
|
|
267
|
+
logLevel?: LogLevel;
|
|
268
|
+
filters?: Record<string, string>;
|
|
269
|
+
page?: number;
|
|
270
|
+
perPage?: number;
|
|
189
271
|
}
|
|
190
272
|
|
|
191
|
-
export type GetLogsResponse =
|
|
273
|
+
export type GetLogsResponse = {
|
|
274
|
+
logs: BaseLogMessage[];
|
|
275
|
+
total: number;
|
|
276
|
+
page: number;
|
|
277
|
+
perPage: number;
|
|
278
|
+
hasMore: boolean;
|
|
279
|
+
};
|
|
192
280
|
|
|
193
281
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
194
282
|
|
|
@@ -247,6 +335,7 @@ export interface GetTelemetryParams {
|
|
|
247
335
|
}
|
|
248
336
|
|
|
249
337
|
export interface GetNetworkResponse {
|
|
338
|
+
id: string;
|
|
250
339
|
name: string;
|
|
251
340
|
instructions: string;
|
|
252
341
|
agents: Array<{
|
|
@@ -260,3 +349,74 @@ export interface GetNetworkResponse {
|
|
|
260
349
|
};
|
|
261
350
|
state?: Record<string, any>;
|
|
262
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
|
+
}
|