@mastra/client-js 0.0.0-extend-clickhouse-20250418135620 → 0.0.0-feat-support-ai-sdk-5-again-20250813225910
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 +18 -0
- package/CHANGELOG.md +1483 -2
- package/LICENSE.md +11 -42
- package/README.md +2 -1
- package/dist/adapters/agui.d.ts +22 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +270 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +1812 -80
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -585
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1807 -79
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +41 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +123 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +427 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +17 -0
- package/integration-tests/src/mastra/index.ts +38 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +33 -18
- package/src/adapters/agui.test.ts +322 -0
- package/src/adapters/agui.ts +263 -0
- package/src/client.ts +422 -14
- package/src/example.ts +59 -29
- package/src/index.test.ts +526 -10
- package/src/resources/a2a.ts +98 -0
- package/src/resources/agent.ts +637 -49
- package/src/resources/base.ts +9 -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.test.ts +285 -0
- package/src/resources/memory-thread.ts +45 -5
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +81 -0
- package/src/resources/network.ts +11 -17
- package/src/resources/tool.ts +16 -3
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +289 -94
- package/src/types.ts +306 -24
- 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/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/index.d.cts +0 -585
package/src/types.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
+
import type { UIMessage } from 'ai';
|
|
1
2
|
import type {
|
|
2
|
-
|
|
3
|
-
AiMessageType,
|
|
3
|
+
MastraMessageV1,
|
|
4
4
|
CoreMessage,
|
|
5
5
|
QueryResult,
|
|
6
|
-
StepAction,
|
|
7
|
-
StepGraph,
|
|
8
6
|
StorageThreadType,
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
WorkflowRuns,
|
|
8
|
+
WorkflowRun,
|
|
9
|
+
LegacyWorkflowRuns,
|
|
10
|
+
StorageGetMessagesArg,
|
|
11
|
+
PaginationInfo,
|
|
12
|
+
MastraMessageV2,
|
|
11
13
|
} from '@mastra/core';
|
|
14
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
15
|
+
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
12
16
|
|
|
13
|
-
import type {
|
|
17
|
+
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
18
|
+
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
19
|
+
import type { MastraScorer, MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';
|
|
20
|
+
import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
|
|
21
|
+
import type {
|
|
22
|
+
StepAction,
|
|
23
|
+
StepGraph,
|
|
24
|
+
LegacyWorkflowRunResult as CoreLegacyWorkflowRunResult,
|
|
25
|
+
} from '@mastra/core/workflows/legacy';
|
|
14
26
|
import type { JSONSchema7 } from 'json-schema';
|
|
15
27
|
import type { ZodSchema } from 'zod';
|
|
16
28
|
|
|
@@ -26,6 +38,7 @@ export interface ClientOptions {
|
|
|
26
38
|
/** Custom headers to include with requests */
|
|
27
39
|
headers?: Record<string, string>;
|
|
28
40
|
/** Abort signal for request */
|
|
41
|
+
abortSignal?: AbortSignal;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
export interface RequestOptions {
|
|
@@ -33,27 +46,54 @@ export interface RequestOptions {
|
|
|
33
46
|
headers?: Record<string, string>;
|
|
34
47
|
body?: any;
|
|
35
48
|
stream?: boolean;
|
|
36
|
-
signal?: AbortSignal;
|
|
37
49
|
}
|
|
38
50
|
|
|
51
|
+
type WithoutMethods<T> = {
|
|
52
|
+
[K in keyof T as T[K] extends (...args: any[]) => any
|
|
53
|
+
? never
|
|
54
|
+
: T[K] extends { (): any }
|
|
55
|
+
? never
|
|
56
|
+
: T[K] extends undefined | ((...args: any[]) => any)
|
|
57
|
+
? never
|
|
58
|
+
: K]: T[K];
|
|
59
|
+
};
|
|
60
|
+
|
|
39
61
|
export interface GetAgentResponse {
|
|
40
62
|
name: string;
|
|
41
63
|
instructions: string;
|
|
42
64
|
tools: Record<string, GetToolResponse>;
|
|
65
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
43
66
|
provider: string;
|
|
44
67
|
modelId: string;
|
|
68
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
69
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
45
70
|
}
|
|
46
71
|
|
|
47
72
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
48
|
-
messages: string | string[] | CoreMessage[] |
|
|
49
|
-
|
|
73
|
+
messages: string | string[] | CoreMessage[] | UIMessage[];
|
|
74
|
+
output?: T;
|
|
75
|
+
experimental_output?: T;
|
|
76
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
77
|
+
clientTools?: ToolsInput;
|
|
78
|
+
} & WithoutMethods<
|
|
79
|
+
Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
|
|
80
|
+
>;
|
|
50
81
|
|
|
51
82
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
52
|
-
messages: string | string[] | CoreMessage[] |
|
|
53
|
-
|
|
83
|
+
messages: string | string[] | CoreMessage[] | UIMessage[];
|
|
84
|
+
output?: T;
|
|
85
|
+
experimental_output?: T;
|
|
86
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
87
|
+
clientTools?: ToolsInput;
|
|
88
|
+
} & WithoutMethods<
|
|
89
|
+
Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
|
|
90
|
+
>;
|
|
54
91
|
|
|
55
92
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
56
93
|
evals: any[];
|
|
94
|
+
instructions: string;
|
|
95
|
+
name: string;
|
|
96
|
+
id: string;
|
|
57
97
|
}
|
|
58
98
|
|
|
59
99
|
export interface GetToolResponse {
|
|
@@ -63,7 +103,7 @@ export interface GetToolResponse {
|
|
|
63
103
|
outputSchema: string;
|
|
64
104
|
}
|
|
65
105
|
|
|
66
|
-
export interface
|
|
106
|
+
export interface GetLegacyWorkflowResponse {
|
|
67
107
|
name: string;
|
|
68
108
|
triggerSchema: string;
|
|
69
109
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -72,12 +112,61 @@ export interface GetWorkflowResponse {
|
|
|
72
112
|
workflowId?: string;
|
|
73
113
|
}
|
|
74
114
|
|
|
75
|
-
export
|
|
115
|
+
export interface GetWorkflowRunsParams {
|
|
116
|
+
fromDate?: Date;
|
|
117
|
+
toDate?: Date;
|
|
118
|
+
limit?: number;
|
|
119
|
+
offset?: number;
|
|
120
|
+
resourceId?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
124
|
+
|
|
125
|
+
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
126
|
+
|
|
127
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
128
|
+
|
|
129
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
130
|
+
|
|
131
|
+
export type LegacyWorkflowRunResult = {
|
|
76
132
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
77
|
-
results:
|
|
133
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
78
134
|
timestamp: number;
|
|
79
135
|
runId: string;
|
|
80
136
|
};
|
|
137
|
+
|
|
138
|
+
export interface GetWorkflowResponse {
|
|
139
|
+
name: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
steps: {
|
|
142
|
+
[key: string]: {
|
|
143
|
+
id: string;
|
|
144
|
+
description: string;
|
|
145
|
+
inputSchema: string;
|
|
146
|
+
outputSchema: string;
|
|
147
|
+
resumeSchema: string;
|
|
148
|
+
suspendSchema: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
allSteps: {
|
|
152
|
+
[key: string]: {
|
|
153
|
+
id: string;
|
|
154
|
+
description: string;
|
|
155
|
+
inputSchema: string;
|
|
156
|
+
outputSchema: string;
|
|
157
|
+
resumeSchema: string;
|
|
158
|
+
suspendSchema: string;
|
|
159
|
+
isWorkflow: boolean;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
163
|
+
inputSchema: string;
|
|
164
|
+
outputSchema: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
168
|
+
|
|
169
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
81
170
|
export interface UpsertVectorParams {
|
|
82
171
|
indexName: string;
|
|
83
172
|
vectors: number[][];
|
|
@@ -109,20 +198,33 @@ export interface GetVectorIndexResponse {
|
|
|
109
198
|
}
|
|
110
199
|
|
|
111
200
|
export interface SaveMessageToMemoryParams {
|
|
112
|
-
messages:
|
|
201
|
+
messages: (MastraMessageV1 | MastraMessageV2)[];
|
|
113
202
|
agentId: string;
|
|
114
203
|
}
|
|
115
204
|
|
|
116
|
-
export
|
|
205
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
206
|
+
messages: (MastraMessageV1 | MastraMessageV2)[];
|
|
207
|
+
networkId: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type SaveMessageToMemoryResponse = (MastraMessageV1 | MastraMessageV2)[];
|
|
117
211
|
|
|
118
212
|
export interface CreateMemoryThreadParams {
|
|
119
|
-
title
|
|
120
|
-
metadata
|
|
121
|
-
|
|
122
|
-
threadId
|
|
213
|
+
title?: string;
|
|
214
|
+
metadata?: Record<string, any>;
|
|
215
|
+
resourceId: string;
|
|
216
|
+
threadId?: string;
|
|
123
217
|
agentId: string;
|
|
124
218
|
}
|
|
125
219
|
|
|
220
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
221
|
+
title?: string;
|
|
222
|
+
metadata?: Record<string, any>;
|
|
223
|
+
resourceId: string;
|
|
224
|
+
threadId?: string;
|
|
225
|
+
networkId: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
126
228
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
127
229
|
|
|
128
230
|
export interface GetMemoryThreadParams {
|
|
@@ -130,29 +232,69 @@ export interface GetMemoryThreadParams {
|
|
|
130
232
|
agentId: string;
|
|
131
233
|
}
|
|
132
234
|
|
|
235
|
+
export interface GetNetworkMemoryThreadParams {
|
|
236
|
+
resourceId: string;
|
|
237
|
+
networkId: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
133
240
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
134
241
|
|
|
135
242
|
export interface UpdateMemoryThreadParams {
|
|
136
243
|
title: string;
|
|
137
244
|
metadata: Record<string, any>;
|
|
138
|
-
|
|
245
|
+
resourceId: string;
|
|
139
246
|
}
|
|
140
247
|
|
|
248
|
+
export interface GetMemoryThreadMessagesParams {
|
|
249
|
+
/**
|
|
250
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
251
|
+
*/
|
|
252
|
+
limit?: number;
|
|
253
|
+
/**
|
|
254
|
+
* Format of UI messages to return (default: aiv5)
|
|
255
|
+
*/
|
|
256
|
+
format?: 'aiv4' | 'aiv5';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
|
|
260
|
+
|
|
141
261
|
export interface GetMemoryThreadMessagesResponse {
|
|
142
262
|
messages: CoreMessage[];
|
|
143
|
-
uiMessages:
|
|
263
|
+
uiMessages: UIMessage[];
|
|
144
264
|
}
|
|
145
265
|
|
|
266
|
+
export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
|
|
267
|
+
messages: MastraMessageV1[] | MastraMessageV2[];
|
|
268
|
+
};
|
|
269
|
+
|
|
146
270
|
export interface GetLogsParams {
|
|
147
271
|
transportId: string;
|
|
272
|
+
fromDate?: Date;
|
|
273
|
+
toDate?: Date;
|
|
274
|
+
logLevel?: LogLevel;
|
|
275
|
+
filters?: Record<string, string>;
|
|
276
|
+
page?: number;
|
|
277
|
+
perPage?: number;
|
|
148
278
|
}
|
|
149
279
|
|
|
150
280
|
export interface GetLogParams {
|
|
151
281
|
runId: string;
|
|
152
282
|
transportId: string;
|
|
283
|
+
fromDate?: Date;
|
|
284
|
+
toDate?: Date;
|
|
285
|
+
logLevel?: LogLevel;
|
|
286
|
+
filters?: Record<string, string>;
|
|
287
|
+
page?: number;
|
|
288
|
+
perPage?: number;
|
|
153
289
|
}
|
|
154
290
|
|
|
155
|
-
export type GetLogsResponse =
|
|
291
|
+
export type GetLogsResponse = {
|
|
292
|
+
logs: BaseLogMessage[];
|
|
293
|
+
total: number;
|
|
294
|
+
page: number;
|
|
295
|
+
perPage: number;
|
|
296
|
+
hasMore: boolean;
|
|
297
|
+
};
|
|
156
298
|
|
|
157
299
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
158
300
|
|
|
@@ -206,9 +348,12 @@ export interface GetTelemetryParams {
|
|
|
206
348
|
page?: number;
|
|
207
349
|
perPage?: number;
|
|
208
350
|
attribute?: Record<string, string>;
|
|
351
|
+
fromDate?: Date;
|
|
352
|
+
toDate?: Date;
|
|
209
353
|
}
|
|
210
354
|
|
|
211
355
|
export interface GetNetworkResponse {
|
|
356
|
+
id: string;
|
|
212
357
|
name: string;
|
|
213
358
|
instructions: string;
|
|
214
359
|
agents: Array<{
|
|
@@ -222,3 +367,140 @@ export interface GetNetworkResponse {
|
|
|
222
367
|
};
|
|
223
368
|
state?: Record<string, any>;
|
|
224
369
|
}
|
|
370
|
+
|
|
371
|
+
export interface GetVNextNetworkResponse {
|
|
372
|
+
id: string;
|
|
373
|
+
name: string;
|
|
374
|
+
instructions: string;
|
|
375
|
+
agents: Array<{
|
|
376
|
+
name: string;
|
|
377
|
+
provider: string;
|
|
378
|
+
modelId: string;
|
|
379
|
+
}>;
|
|
380
|
+
routingModel: {
|
|
381
|
+
provider: string;
|
|
382
|
+
modelId: string;
|
|
383
|
+
};
|
|
384
|
+
workflows: Array<{
|
|
385
|
+
name: string;
|
|
386
|
+
description: string;
|
|
387
|
+
inputSchema: string | undefined;
|
|
388
|
+
outputSchema: string | undefined;
|
|
389
|
+
}>;
|
|
390
|
+
tools: Array<{
|
|
391
|
+
id: string;
|
|
392
|
+
description: string;
|
|
393
|
+
}>;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface GenerateVNextNetworkResponse {
|
|
397
|
+
task: string;
|
|
398
|
+
result: string;
|
|
399
|
+
resourceId: string;
|
|
400
|
+
resourceType: 'none' | 'tool' | 'agent' | 'workflow';
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface GenerateOrStreamVNextNetworkParams {
|
|
404
|
+
message: string;
|
|
405
|
+
threadId?: string;
|
|
406
|
+
resourceId?: string;
|
|
407
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export interface LoopStreamVNextNetworkParams {
|
|
411
|
+
message: string;
|
|
412
|
+
threadId?: string;
|
|
413
|
+
resourceId?: string;
|
|
414
|
+
maxIterations?: number;
|
|
415
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export interface LoopVNextNetworkResponse {
|
|
419
|
+
status: 'success';
|
|
420
|
+
result: {
|
|
421
|
+
task: string;
|
|
422
|
+
resourceId: string;
|
|
423
|
+
resourceType: 'agent' | 'workflow' | 'none' | 'tool';
|
|
424
|
+
result: string;
|
|
425
|
+
iteration: number;
|
|
426
|
+
isOneOff: boolean;
|
|
427
|
+
prompt: string;
|
|
428
|
+
threadId?: string | undefined;
|
|
429
|
+
threadResourceId?: string | undefined;
|
|
430
|
+
isComplete?: boolean | undefined;
|
|
431
|
+
completionReason?: string | undefined;
|
|
432
|
+
};
|
|
433
|
+
steps: WorkflowResult<any, any>['steps'];
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export interface McpServerListResponse {
|
|
437
|
+
servers: ServerInfo[];
|
|
438
|
+
next: string | null;
|
|
439
|
+
total_count: number;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export interface McpToolInfo {
|
|
443
|
+
id: string;
|
|
444
|
+
name: string;
|
|
445
|
+
description?: string;
|
|
446
|
+
inputSchema: string;
|
|
447
|
+
toolType?: MCPToolType;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export interface McpServerToolListResponse {
|
|
451
|
+
tools: McpToolInfo[];
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export type ClientScoreRowData = Omit<ScoreRowData, 'createdAt' | 'updatedAt'> & {
|
|
455
|
+
createdAt: string;
|
|
456
|
+
updatedAt: string;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// Scores-related types
|
|
460
|
+
export interface GetScoresByRunIdParams {
|
|
461
|
+
runId: string;
|
|
462
|
+
page?: number;
|
|
463
|
+
perPage?: number;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export interface GetScoresByScorerIdParams {
|
|
467
|
+
scorerId: string;
|
|
468
|
+
entityId?: string;
|
|
469
|
+
entityType?: string;
|
|
470
|
+
page?: number;
|
|
471
|
+
perPage?: number;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export interface GetScoresByEntityIdParams {
|
|
475
|
+
entityId: string;
|
|
476
|
+
entityType: string;
|
|
477
|
+
page?: number;
|
|
478
|
+
perPage?: number;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface SaveScoreParams {
|
|
482
|
+
score: Omit<ScoreRowData, 'id' | 'createdAt' | 'updatedAt'>;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export interface GetScoresResponse {
|
|
486
|
+
pagination: {
|
|
487
|
+
total: number;
|
|
488
|
+
page: number;
|
|
489
|
+
perPage: number;
|
|
490
|
+
hasMore: boolean;
|
|
491
|
+
};
|
|
492
|
+
scores: ClientScoreRowData[];
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export interface SaveScoreResponse {
|
|
496
|
+
score: ClientScoreRowData;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export type GetScorerResponse = MastraScorerEntry & {
|
|
500
|
+
agentIds: string[];
|
|
501
|
+
workflowIds: string[];
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
export interface GetScorersResponse {
|
|
505
|
+
scorers: Array<GetScorerResponse>;
|
|
506
|
+
}
|
|
@@ -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/is-vercel-tool';
|
|
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
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : 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
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import type { MastraMessageV1, MastraMessageV2 } from '@mastra/core';
|
|
3
|
+
import { MastraClient } from './client';
|
|
4
|
+
|
|
5
|
+
describe('V2 Message Format Support', () => {
|
|
6
|
+
let client: MastraClient;
|
|
7
|
+
const agentId = 'test-agent';
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
global.fetch = vi.fn();
|
|
11
|
+
client = new MastraClient({
|
|
12
|
+
baseUrl: 'http://localhost:3000',
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should send v1 messages successfully', async () => {
|
|
17
|
+
const v1Messages: MastraMessageV1[] = [
|
|
18
|
+
{
|
|
19
|
+
id: 'msg-v1-1',
|
|
20
|
+
role: 'user',
|
|
21
|
+
content: 'Hello from v1!',
|
|
22
|
+
type: 'text',
|
|
23
|
+
createdAt: new Date(),
|
|
24
|
+
threadId: 'thread-123',
|
|
25
|
+
resourceId: 'resource-123',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
30
|
+
ok: true,
|
|
31
|
+
json: async () => v1Messages,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const result = await client.saveMessageToMemory({
|
|
35
|
+
agentId,
|
|
36
|
+
messages: v1Messages,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(result).toEqual(v1Messages);
|
|
40
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
41
|
+
expect.stringContaining('/api/memory/save-messages'),
|
|
42
|
+
expect.objectContaining({
|
|
43
|
+
method: 'POST',
|
|
44
|
+
body: JSON.stringify({ agentId, messages: v1Messages }),
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should send v2 messages successfully', async () => {
|
|
50
|
+
const v2Messages: MastraMessageV2[] = [
|
|
51
|
+
{
|
|
52
|
+
id: 'msg-v2-1',
|
|
53
|
+
role: 'assistant',
|
|
54
|
+
createdAt: new Date(),
|
|
55
|
+
threadId: 'thread-123',
|
|
56
|
+
resourceId: 'resource-123',
|
|
57
|
+
content: {
|
|
58
|
+
format: 2,
|
|
59
|
+
parts: [{ type: 'text', text: 'Hello from v2!' }],
|
|
60
|
+
content: 'Hello from v2!',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
66
|
+
ok: true,
|
|
67
|
+
json: async () => v2Messages,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const result = await client.saveMessageToMemory({
|
|
71
|
+
agentId,
|
|
72
|
+
messages: v2Messages,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(result).toEqual(v2Messages);
|
|
76
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
77
|
+
expect.stringContaining('/api/memory/save-messages'),
|
|
78
|
+
expect.objectContaining({
|
|
79
|
+
method: 'POST',
|
|
80
|
+
body: JSON.stringify({ agentId, messages: v2Messages }),
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should send mixed v1 and v2 messages successfully', async () => {
|
|
86
|
+
const mixedMessages: (MastraMessageV1 | MastraMessageV2)[] = [
|
|
87
|
+
{
|
|
88
|
+
id: 'msg-v1-1',
|
|
89
|
+
role: 'user',
|
|
90
|
+
content: 'Question in v1 format',
|
|
91
|
+
type: 'text',
|
|
92
|
+
createdAt: new Date(),
|
|
93
|
+
threadId: 'thread-123',
|
|
94
|
+
resourceId: 'resource-123',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'msg-v2-1',
|
|
98
|
+
role: 'assistant',
|
|
99
|
+
createdAt: new Date(),
|
|
100
|
+
threadId: 'thread-123',
|
|
101
|
+
resourceId: 'resource-123',
|
|
102
|
+
content: {
|
|
103
|
+
format: 2,
|
|
104
|
+
parts: [
|
|
105
|
+
{ type: 'text', text: 'Answer in v2 format' },
|
|
106
|
+
{
|
|
107
|
+
type: 'tool-invocation',
|
|
108
|
+
toolInvocation: {
|
|
109
|
+
state: 'result' as const,
|
|
110
|
+
toolCallId: 'call-123',
|
|
111
|
+
toolName: 'calculator',
|
|
112
|
+
args: { a: 1, b: 2 },
|
|
113
|
+
result: '3',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
toolInvocations: [
|
|
118
|
+
{
|
|
119
|
+
state: 'result' as const,
|
|
120
|
+
toolCallId: 'call-123',
|
|
121
|
+
toolName: 'calculator',
|
|
122
|
+
args: { a: 1, b: 2 },
|
|
123
|
+
result: '3',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
131
|
+
ok: true,
|
|
132
|
+
json: async () => mixedMessages,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const result = await client.saveMessageToMemory({
|
|
136
|
+
agentId,
|
|
137
|
+
messages: mixedMessages,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(result).toEqual(mixedMessages);
|
|
141
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
142
|
+
expect.stringContaining('/api/memory/save-messages'),
|
|
143
|
+
expect.objectContaining({
|
|
144
|
+
method: 'POST',
|
|
145
|
+
body: JSON.stringify({ agentId, messages: mixedMessages }),
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should handle v2 messages with attachments', async () => {
|
|
151
|
+
const v2MessageWithAttachments: MastraMessageV2 = {
|
|
152
|
+
id: 'msg-v2-att',
|
|
153
|
+
role: 'user',
|
|
154
|
+
createdAt: new Date(),
|
|
155
|
+
threadId: 'thread-123',
|
|
156
|
+
resourceId: 'resource-123',
|
|
157
|
+
content: {
|
|
158
|
+
format: 2,
|
|
159
|
+
parts: [
|
|
160
|
+
{ type: 'text', text: 'Check out this image:' },
|
|
161
|
+
{ type: 'file', data: 'data:image/png;base64,iVBORw0...', mimeType: 'image/png' },
|
|
162
|
+
],
|
|
163
|
+
experimental_attachments: [{ url: 'data:image/png;base64,iVBORw0...', contentType: 'image/png' }],
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
168
|
+
ok: true,
|
|
169
|
+
json: async () => [v2MessageWithAttachments],
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const result = await client.saveMessageToMemory({
|
|
173
|
+
agentId,
|
|
174
|
+
messages: [v2MessageWithAttachments],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(result).toHaveLength(1);
|
|
178
|
+
expect(result[0]).toEqual(v2MessageWithAttachments);
|
|
179
|
+
});
|
|
180
|
+
});
|
package/tsconfig.json
CHANGED