@mastra/client-js 0.0.0-ai-v5-20250718021026 → 0.0.0-ai-v5-20250729181825

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/src/types.ts CHANGED
@@ -7,12 +7,16 @@ import type {
7
7
  WorkflowRuns,
8
8
  WorkflowRun,
9
9
  LegacyWorkflowRuns,
10
+ StorageGetMessagesArg,
11
+ PaginationInfo,
12
+ MastraMessageV2,
10
13
  } from '@mastra/core';
11
14
  import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
12
15
  import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
13
16
 
14
17
  import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
15
18
  import type { RuntimeContext } from '@mastra/core/runtime-context';
19
+ import type { MastraScorer, MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';
16
20
  import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
17
21
  import type {
18
22
  StepAction,
@@ -194,16 +198,16 @@ export interface GetVectorIndexResponse {
194
198
  }
195
199
 
196
200
  export interface SaveMessageToMemoryParams {
197
- messages: MastraMessageV1[];
201
+ messages: (MastraMessageV1 | MastraMessageV2)[];
198
202
  agentId: string;
199
203
  }
200
204
 
201
205
  export interface SaveNetworkMessageToMemoryParams {
202
- messages: MastraMessageV1[];
206
+ messages: (MastraMessageV1 | MastraMessageV2)[];
203
207
  networkId: string;
204
208
  }
205
209
 
206
- export type SaveMessageToMemoryResponse = MastraMessageV1[];
210
+ export type SaveMessageToMemoryResponse = (MastraMessageV1 | MastraMessageV2)[];
207
211
 
208
212
  export interface CreateMemoryThreadParams {
209
213
  title?: string;
@@ -252,11 +256,17 @@ export interface GetMemoryThreadMessagesParams {
252
256
  format?: 'aiv4' | 'aiv5';
253
257
  }
254
258
 
259
+ export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
260
+
255
261
  export interface GetMemoryThreadMessagesResponse {
256
262
  messages: CoreMessage[];
257
263
  uiMessages: UIMessage[];
258
264
  }
259
265
 
266
+ export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
267
+ messages: MastraMessageV1[] | MastraMessageV2[];
268
+ };
269
+
260
270
  export interface GetLogsParams {
261
271
  transportId: string;
262
272
  fromDate?: Date;
@@ -408,7 +418,17 @@ export interface LoopStreamVNextNetworkParams {
408
418
  export interface LoopVNextNetworkResponse {
409
419
  status: 'success';
410
420
  result: {
411
- text: string;
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;
412
432
  };
413
433
  steps: WorkflowResult<any, any>['steps'];
414
434
  }
@@ -430,3 +450,57 @@ export interface McpToolInfo {
430
450
  export interface McpServerToolListResponse {
431
451
  tools: McpToolInfo[];
432
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
+ }
@@ -1,4 +1,4 @@
1
- import { isVercelTool } from '@mastra/core/tools';
1
+ import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
2
2
  import { zodToJsonSchema } from './zod-to-json-schema';
3
3
  import type { ToolsInput } from '@mastra/core/agent';
4
4
 
@@ -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
+ });
@@ -1,19 +0,0 @@
1
-
2
- > @mastra/client-js@0.10.15-alpha.1 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
- > tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.0
8
- CLI Target: es2022
9
- CLI Cleaning output folder
10
- ESM Build start
11
- CJS Build start
12
- DTS Build start
13
- ESM dist/index.js 71.36 KB
14
- ESM ⚡️ Build success in 2104ms
15
- CJS dist/index.cjs 71.66 KB
16
- CJS ⚡️ Build success in 2109ms
17
- DTS ⚡️ Build success in 18106ms
18
- DTS dist/index.d.ts 42.03 KB
19
- DTS dist/index.d.cts 42.03 KB