@mastra/client-js 0.0.0-storage-20250225005900 → 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 -16
- package/CHANGELOG.md +1631 -3
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +7 -4
- package/dist/index.cjs +2205 -0
- package/dist/index.d.cts +1152 -0
- package/dist/index.d.ts +1152 -0
- package/dist/index.js +2199 -0
- package/package.json +36 -20
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +288 -13
- package/src/example.ts +50 -26
- package/src/index.test.ts +293 -60
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +664 -17
- package/src/resources/base.ts +7 -4
- package/src/resources/index.ts +5 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +8 -5
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +85 -0
- package/src/resources/tool.ts +16 -3
- package/src/resources/vNextNetwork.ts +177 -0
- package/src/resources/workflow.ts +340 -24
- package/src/types.ts +287 -28
- 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/dist/index.d.mts +0 -405
- package/dist/index.mjs +0 -487
package/src/types.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
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';
|
|
13
|
+
|
|
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';
|
|
12
22
|
import type { JSONSchema7 } from 'json-schema';
|
|
13
|
-
import { ZodSchema } from 'zod';
|
|
23
|
+
import type { ZodSchema } from 'zod';
|
|
14
24
|
|
|
15
25
|
export interface ClientOptions {
|
|
16
26
|
/** Base URL for API requests */
|
|
@@ -23,6 +33,7 @@ export interface ClientOptions {
|
|
|
23
33
|
maxBackoffMs?: number;
|
|
24
34
|
/** Custom headers to include with requests */
|
|
25
35
|
headers?: Record<string, string>;
|
|
36
|
+
/** Abort signal for request */
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
export interface RequestOptions {
|
|
@@ -30,31 +41,51 @@ export interface RequestOptions {
|
|
|
30
41
|
headers?: Record<string, string>;
|
|
31
42
|
body?: any;
|
|
32
43
|
stream?: boolean;
|
|
44
|
+
signal?: AbortSignal;
|
|
33
45
|
}
|
|
34
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
|
+
|
|
35
57
|
export interface GetAgentResponse {
|
|
36
58
|
name: string;
|
|
37
59
|
instructions: string;
|
|
38
60
|
tools: Record<string, GetToolResponse>;
|
|
61
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
39
62
|
provider: string;
|
|
63
|
+
modelId: string;
|
|
64
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
65
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
40
66
|
}
|
|
41
67
|
|
|
42
|
-
export
|
|
43
|
-
messages: string | string[] | CoreMessage[];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
69
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
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'>>;
|
|
48
75
|
|
|
49
|
-
export
|
|
50
|
-
messages: string | string[] | CoreMessage[];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
77
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
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'>>;
|
|
55
83
|
|
|
56
84
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
57
85
|
evals: any[];
|
|
86
|
+
instructions: string;
|
|
87
|
+
name: string;
|
|
88
|
+
id: string;
|
|
58
89
|
}
|
|
59
90
|
|
|
60
91
|
export interface GetToolResponse {
|
|
@@ -64,14 +95,70 @@ export interface GetToolResponse {
|
|
|
64
95
|
outputSchema: string;
|
|
65
96
|
}
|
|
66
97
|
|
|
67
|
-
export interface
|
|
98
|
+
export interface GetLegacyWorkflowResponse {
|
|
68
99
|
name: string;
|
|
69
100
|
triggerSchema: string;
|
|
70
101
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
71
102
|
stepGraph: StepGraph;
|
|
72
103
|
stepSubscriberGraph: Record<string, StepGraph>;
|
|
104
|
+
workflowId?: string;
|
|
105
|
+
}
|
|
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
|
+
|
|
117
|
+
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
118
|
+
|
|
119
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
120
|
+
|
|
121
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
122
|
+
|
|
123
|
+
export type LegacyWorkflowRunResult = {
|
|
124
|
+
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
125
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
126
|
+
timestamp: number;
|
|
127
|
+
runId: string;
|
|
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
|
+
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'];
|
|
155
|
+
inputSchema: string;
|
|
156
|
+
outputSchema: string;
|
|
73
157
|
}
|
|
74
158
|
|
|
159
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
160
|
+
|
|
161
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
75
162
|
export interface UpsertVectorParams {
|
|
76
163
|
indexName: string;
|
|
77
164
|
vectors: number[][];
|
|
@@ -103,20 +190,33 @@ export interface GetVectorIndexResponse {
|
|
|
103
190
|
}
|
|
104
191
|
|
|
105
192
|
export interface SaveMessageToMemoryParams {
|
|
106
|
-
messages:
|
|
193
|
+
messages: MastraMessageV1[];
|
|
107
194
|
agentId: string;
|
|
108
195
|
}
|
|
109
196
|
|
|
110
|
-
export
|
|
197
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
198
|
+
messages: MastraMessageV1[];
|
|
199
|
+
networkId: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
111
203
|
|
|
112
204
|
export interface CreateMemoryThreadParams {
|
|
113
|
-
title
|
|
114
|
-
metadata
|
|
115
|
-
|
|
116
|
-
threadId
|
|
205
|
+
title?: string;
|
|
206
|
+
metadata?: Record<string, any>;
|
|
207
|
+
resourceId: string;
|
|
208
|
+
threadId?: string;
|
|
117
209
|
agentId: string;
|
|
118
210
|
}
|
|
119
211
|
|
|
212
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
213
|
+
title?: string;
|
|
214
|
+
metadata?: Record<string, any>;
|
|
215
|
+
resourceId: string;
|
|
216
|
+
threadId?: string;
|
|
217
|
+
networkId: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
120
220
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
121
221
|
|
|
122
222
|
export interface GetMemoryThreadParams {
|
|
@@ -124,12 +224,24 @@ export interface GetMemoryThreadParams {
|
|
|
124
224
|
agentId: string;
|
|
125
225
|
}
|
|
126
226
|
|
|
227
|
+
export interface GetNetworkMemoryThreadParams {
|
|
228
|
+
resourceId: string;
|
|
229
|
+
networkId: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
127
232
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
128
233
|
|
|
129
234
|
export interface UpdateMemoryThreadParams {
|
|
130
235
|
title: string;
|
|
131
236
|
metadata: Record<string, any>;
|
|
132
|
-
|
|
237
|
+
resourceId: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface GetMemoryThreadMessagesParams {
|
|
241
|
+
/**
|
|
242
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
243
|
+
*/
|
|
244
|
+
limit?: number;
|
|
133
245
|
}
|
|
134
246
|
|
|
135
247
|
export interface GetMemoryThreadMessagesResponse {
|
|
@@ -139,19 +251,77 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
139
251
|
|
|
140
252
|
export interface GetLogsParams {
|
|
141
253
|
transportId: string;
|
|
254
|
+
fromDate?: Date;
|
|
255
|
+
toDate?: Date;
|
|
256
|
+
logLevel?: LogLevel;
|
|
257
|
+
filters?: Record<string, string>;
|
|
258
|
+
page?: number;
|
|
259
|
+
perPage?: number;
|
|
142
260
|
}
|
|
143
261
|
|
|
144
262
|
export interface GetLogParams {
|
|
145
263
|
runId: string;
|
|
146
264
|
transportId: string;
|
|
265
|
+
fromDate?: Date;
|
|
266
|
+
toDate?: Date;
|
|
267
|
+
logLevel?: LogLevel;
|
|
268
|
+
filters?: Record<string, string>;
|
|
269
|
+
page?: number;
|
|
270
|
+
perPage?: number;
|
|
147
271
|
}
|
|
148
272
|
|
|
149
|
-
export type GetLogsResponse =
|
|
273
|
+
export type GetLogsResponse = {
|
|
274
|
+
logs: BaseLogMessage[];
|
|
275
|
+
total: number;
|
|
276
|
+
page: number;
|
|
277
|
+
perPage: number;
|
|
278
|
+
hasMore: boolean;
|
|
279
|
+
};
|
|
150
280
|
|
|
151
281
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
152
282
|
|
|
283
|
+
type SpanStatus = {
|
|
284
|
+
code: number;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
type SpanOther = {
|
|
288
|
+
droppedAttributesCount: number;
|
|
289
|
+
droppedEventsCount: number;
|
|
290
|
+
droppedLinksCount: number;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
type SpanEventAttributes = {
|
|
294
|
+
key: string;
|
|
295
|
+
value: { [key: string]: string | number | boolean | null };
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
type SpanEvent = {
|
|
299
|
+
attributes: SpanEventAttributes[];
|
|
300
|
+
name: string;
|
|
301
|
+
timeUnixNano: string;
|
|
302
|
+
droppedAttributesCount: number;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
type Span = {
|
|
306
|
+
id: string;
|
|
307
|
+
parentSpanId: string | null;
|
|
308
|
+
traceId: string;
|
|
309
|
+
name: string;
|
|
310
|
+
scope: string;
|
|
311
|
+
kind: number;
|
|
312
|
+
status: SpanStatus;
|
|
313
|
+
events: SpanEvent[];
|
|
314
|
+
links: any[];
|
|
315
|
+
attributes: Record<string, string | number | boolean | null>;
|
|
316
|
+
startTime: number;
|
|
317
|
+
endTime: number;
|
|
318
|
+
duration: number;
|
|
319
|
+
other: SpanOther;
|
|
320
|
+
createdAt: string;
|
|
321
|
+
};
|
|
322
|
+
|
|
153
323
|
export interface GetTelemetryResponse {
|
|
154
|
-
traces:
|
|
324
|
+
traces: Span[];
|
|
155
325
|
}
|
|
156
326
|
|
|
157
327
|
export interface GetTelemetryParams {
|
|
@@ -160,4 +330,93 @@ export interface GetTelemetryParams {
|
|
|
160
330
|
page?: number;
|
|
161
331
|
perPage?: number;
|
|
162
332
|
attribute?: Record<string, string>;
|
|
333
|
+
fromDate?: Date;
|
|
334
|
+
toDate?: Date;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export interface GetNetworkResponse {
|
|
338
|
+
id: string;
|
|
339
|
+
name: string;
|
|
340
|
+
instructions: string;
|
|
341
|
+
agents: Array<{
|
|
342
|
+
name: string;
|
|
343
|
+
provider: string;
|
|
344
|
+
modelId: string;
|
|
345
|
+
}>;
|
|
346
|
+
routingModel: {
|
|
347
|
+
provider: string;
|
|
348
|
+
modelId: string;
|
|
349
|
+
};
|
|
350
|
+
state?: Record<string, any>;
|
|
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[];
|
|
163
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
|
+
}
|