@mastra/client-js 0.0.0-tsconfig-compile-20250703214351 → 0.0.0-update-scorers-api-20250801170445

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +401 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +1 -0
  4. package/dist/adapters/agui.d.ts +23 -0
  5. package/dist/adapters/agui.d.ts.map +1 -0
  6. package/dist/client.d.ts +265 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/example.d.ts +2 -0
  9. package/dist/example.d.ts.map +1 -0
  10. package/dist/index.cjs +269 -67
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -1164
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +268 -66
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +44 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +112 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/tool.d.ts +23 -0
  35. package/dist/resources/tool.d.ts.map +1 -0
  36. package/dist/resources/vNextNetwork.d.ts +42 -0
  37. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  38. package/dist/resources/vector.d.ts +48 -0
  39. package/dist/resources/vector.d.ts.map +1 -0
  40. package/dist/resources/workflow.d.ts +154 -0
  41. package/dist/resources/workflow.d.ts.map +1 -0
  42. package/dist/types.d.ts +422 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/utils/index.d.ts +3 -0
  45. package/dist/utils/index.d.ts.map +1 -0
  46. package/dist/utils/process-client-tools.d.ts +3 -0
  47. package/dist/utils/process-client-tools.d.ts.map +1 -0
  48. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  49. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  50. package/integration-tests/agui-adapter.test.ts +122 -0
  51. package/integration-tests/package.json +18 -0
  52. package/integration-tests/src/mastra/index.ts +35 -0
  53. package/integration-tests/vitest.config.ts +9 -0
  54. package/package.json +12 -8
  55. package/src/adapters/agui.test.ts +145 -3
  56. package/src/client.ts +145 -2
  57. package/src/example.ts +45 -17
  58. package/src/index.test.ts +402 -6
  59. package/src/index.ts +1 -0
  60. package/src/resources/agent.ts +46 -24
  61. package/src/resources/base.ts +6 -1
  62. package/src/resources/memory-thread.test.ts +285 -0
  63. package/src/resources/memory-thread.ts +36 -0
  64. package/src/resources/network-memory-thread.test.ts +269 -0
  65. package/src/resources/network-memory-thread.ts +18 -0
  66. package/src/resources/network.ts +4 -3
  67. package/src/resources/vNextNetwork.ts +22 -5
  68. package/src/resources/workflow.ts +17 -3
  69. package/src/types.ts +90 -10
  70. package/src/utils/process-client-tools.ts +1 -1
  71. package/src/v2-messages.test.ts +180 -0
  72. package/tsconfig.build.json +9 -0
  73. package/tsconfig.json +1 -1
  74. package/tsup.config.ts +22 -0
  75. package/.turbo/turbo-build.log +0 -19
  76. package/dist/index.d.cts +0 -1164
@@ -190,6 +190,15 @@ export class Workflow extends BaseResource {
190
190
  });
191
191
  }
192
192
 
193
+ /**
194
+ * Creates a new workflow run (alias for createRun)
195
+ * @param params - Optional object containing the optional runId
196
+ * @returns Promise containing the runId of the created run
197
+ */
198
+ createRunAsync(params?: { runId?: string }): Promise<{ runId: string }> {
199
+ return this.createRun(params);
200
+ }
201
+
193
202
  /**
194
203
  * Starts a workflow run synchronously without waiting for the workflow to complete
195
204
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -289,6 +298,9 @@ export class Workflow extends BaseResource {
289
298
  throw new Error('Response body is null');
290
299
  }
291
300
 
301
+ //using undefined instead of empty string to avoid parsing errors
302
+ let failedChunk: string | undefined = undefined;
303
+
292
304
  // Create a transform stream that processes the response body
293
305
  const transformStream = new TransformStream<ArrayBuffer, { type: string; payload: any }>({
294
306
  start() {},
@@ -303,11 +315,13 @@ export class Workflow extends BaseResource {
303
315
  // Process each chunk
304
316
  for (const chunk of chunks) {
305
317
  if (chunk) {
318
+ const newChunk: string = failedChunk ? failedChunk + chunk : chunk;
306
319
  try {
307
- const parsedChunk = JSON.parse(chunk);
320
+ const parsedChunk = JSON.parse(newChunk);
308
321
  controller.enqueue(parsedChunk);
309
- } catch {
310
- // Silently ignore parsing errors
322
+ failedChunk = undefined;
323
+ } catch (error) {
324
+ failedChunk = newChunk;
311
325
  }
312
326
  }
313
327
  }
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
- import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
14
+ import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput, UIMessageWithMetadata } 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,
@@ -34,6 +38,7 @@ export interface ClientOptions {
34
38
  /** Custom headers to include with requests */
35
39
  headers?: Record<string, string>;
36
40
  /** Abort signal for request */
41
+ abortSignal?: AbortSignal;
37
42
  }
38
43
 
39
44
  export interface RequestOptions {
@@ -41,7 +46,6 @@ export interface RequestOptions {
41
46
  headers?: Record<string, string>;
42
47
  body?: any;
43
48
  stream?: boolean;
44
- signal?: AbortSignal;
45
49
  }
46
50
 
47
51
  type WithoutMethods<T> = {
@@ -66,20 +70,24 @@ export interface GetAgentResponse {
66
70
  }
67
71
 
68
72
  export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
69
- messages: string | string[] | CoreMessage[] | AiMessageType[];
73
+ messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
70
74
  output?: T;
71
75
  experimental_output?: T;
72
76
  runtimeContext?: RuntimeContext | Record<string, any>;
73
77
  clientTools?: ToolsInput;
74
- } & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
78
+ } & WithoutMethods<
79
+ Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
80
+ >;
75
81
 
76
82
  export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
77
- messages: string | string[] | CoreMessage[] | AiMessageType[];
83
+ messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
78
84
  output?: T;
79
85
  experimental_output?: T;
80
86
  runtimeContext?: RuntimeContext | Record<string, any>;
81
87
  clientTools?: ToolsInput;
82
- } & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
88
+ } & WithoutMethods<
89
+ Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
90
+ >;
83
91
 
84
92
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
85
93
  evals: any[];
@@ -190,16 +198,16 @@ export interface GetVectorIndexResponse {
190
198
  }
191
199
 
192
200
  export interface SaveMessageToMemoryParams {
193
- messages: MastraMessageV1[];
201
+ messages: (MastraMessageV1 | MastraMessageV2)[];
194
202
  agentId: string;
195
203
  }
196
204
 
197
205
  export interface SaveNetworkMessageToMemoryParams {
198
- messages: MastraMessageV1[];
206
+ messages: (MastraMessageV1 | MastraMessageV2)[];
199
207
  networkId: string;
200
208
  }
201
209
 
202
- export type SaveMessageToMemoryResponse = MastraMessageV1[];
210
+ export type SaveMessageToMemoryResponse = (MastraMessageV1 | MastraMessageV2)[];
203
211
 
204
212
  export interface CreateMemoryThreadParams {
205
213
  title?: string;
@@ -244,11 +252,17 @@ export interface GetMemoryThreadMessagesParams {
244
252
  limit?: number;
245
253
  }
246
254
 
255
+ export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
256
+
247
257
  export interface GetMemoryThreadMessagesResponse {
248
258
  messages: CoreMessage[];
249
259
  uiMessages: AiMessageType[];
250
260
  }
251
261
 
262
+ export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
263
+ messages: MastraMessageV1[] | MastraMessageV2[];
264
+ };
265
+
252
266
  export interface GetLogsParams {
253
267
  transportId: string;
254
268
  fromDate?: Date;
@@ -386,6 +400,7 @@ export interface GenerateOrStreamVNextNetworkParams {
386
400
  message: string;
387
401
  threadId?: string;
388
402
  resourceId?: string;
403
+ runtimeContext?: RuntimeContext | Record<string, any>;
389
404
  }
390
405
 
391
406
  export interface LoopStreamVNextNetworkParams {
@@ -393,12 +408,23 @@ export interface LoopStreamVNextNetworkParams {
393
408
  threadId?: string;
394
409
  resourceId?: string;
395
410
  maxIterations?: number;
411
+ runtimeContext?: RuntimeContext | Record<string, any>;
396
412
  }
397
413
 
398
414
  export interface LoopVNextNetworkResponse {
399
415
  status: 'success';
400
416
  result: {
401
- text: string;
417
+ task: string;
418
+ resourceId: string;
419
+ resourceType: 'agent' | 'workflow' | 'none' | 'tool';
420
+ result: string;
421
+ iteration: number;
422
+ isOneOff: boolean;
423
+ prompt: string;
424
+ threadId?: string | undefined;
425
+ threadResourceId?: string | undefined;
426
+ isComplete?: boolean | undefined;
427
+ completionReason?: string | undefined;
402
428
  };
403
429
  steps: WorkflowResult<any, any>['steps'];
404
430
  }
@@ -420,3 +446,57 @@ export interface McpToolInfo {
420
446
  export interface McpServerToolListResponse {
421
447
  tools: McpToolInfo[];
422
448
  }
449
+
450
+ export type ClientScoreRowData = Omit<ScoreRowData, 'createdAt' | 'updatedAt'> & {
451
+ createdAt: string;
452
+ updatedAt: string;
453
+ };
454
+
455
+ // Scores-related types
456
+ export interface GetScoresByRunIdParams {
457
+ runId: string;
458
+ page?: number;
459
+ perPage?: number;
460
+ }
461
+
462
+ export interface GetScoresByScorerIdParams {
463
+ scorerId: string;
464
+ entityId?: string;
465
+ entityType?: string;
466
+ page?: number;
467
+ perPage?: number;
468
+ }
469
+
470
+ export interface GetScoresByEntityIdParams {
471
+ entityId: string;
472
+ entityType: string;
473
+ page?: number;
474
+ perPage?: number;
475
+ }
476
+
477
+ export interface SaveScoreParams {
478
+ score: Omit<ScoreRowData, 'id' | 'createdAt' | 'updatedAt'>;
479
+ }
480
+
481
+ export interface GetScoresResponse {
482
+ pagination: {
483
+ total: number;
484
+ page: number;
485
+ perPage: number;
486
+ hasMore: boolean;
487
+ };
488
+ scores: ClientScoreRowData[];
489
+ }
490
+
491
+ export interface SaveScoreResponse {
492
+ score: ClientScoreRowData;
493
+ }
494
+
495
+ export type GetScorerResponse = MastraScorerEntry & {
496
+ agentIds: string[];
497
+ workflowIds: string[];
498
+ };
499
+
500
+ export interface GetScorersResponse {
501
+ scorers: Array<GetScorerResponse>;
502
+ }
@@ -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
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { spawn } from 'child_process';
2
+ import { promisify } from 'util';
3
+ import { defineConfig } from 'tsup';
4
+
5
+ const exec = promisify(spawn);
6
+
7
+ export default defineConfig({
8
+ entry: ['src/index.ts'],
9
+ format: ['esm', 'cjs'],
10
+ clean: true,
11
+ dts: false,
12
+ splitting: true,
13
+ treeshake: {
14
+ preset: 'smallest',
15
+ },
16
+ sourcemap: true,
17
+ onSuccess: async () => {
18
+ await exec('pnpm', ['tsc', '-p', 'tsconfig.build.json'], {
19
+ stdio: 'inherit',
20
+ });
21
+ },
22
+ });
@@ -1,19 +0,0 @@
1
-
2
- > @mastra/client-js@0.10.9 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
- ESM dist/index.js 68.47 KB
13
- ESM ⚡️ Build success in 2727ms
14
- CJS dist/index.cjs 68.75 KB
15
- CJS ⚡️ Build success in 2732ms
16
- DTS Build start
17
- DTS ⚡️ Build success in 18202ms
18
- DTS dist/index.d.ts 40.58 KB
19
- DTS dist/index.d.cts 40.58 KB