@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-trigger-playground-ui-package-20250506151043",
3
+ "version": "0.0.0-tsconfig-compile-20250703214351",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -19,30 +19,35 @@
19
19
  },
20
20
  "./package.json": "./package.json"
21
21
  },
22
- "repository": "github:mastra-ai/client-js",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/mastra-ai/mastra.git",
25
+ "directory": "client-sdks/client-js"
26
+ },
27
+ "homepage": "https://github.com/mastra-ai/mastra/tree/main/client-sdks/client-js#readme",
23
28
  "license": "Elastic-2.0",
24
29
  "dependencies": {
25
30
  "@ag-ui/client": "^0.0.27",
26
- "@ai-sdk/ui-utils": "^1.1.19",
31
+ "@ai-sdk/ui-utils": "^1.2.11",
27
32
  "json-schema": "^0.4.0",
28
33
  "rxjs": "7.8.1",
29
- "zod": "^3.24.2",
30
- "zod-to-json-schema": "^3.24.3",
31
- "@mastra/core": "0.0.0-trigger-playground-ui-package-20250506151043"
34
+ "zod": "^3.25.67",
35
+ "zod-to-json-schema": "^3.24.5",
36
+ "@mastra/core": "0.0.0-tsconfig-compile-20250703214351"
32
37
  },
33
38
  "peerDependencies": {
34
- "zod": "^3.24.2"
39
+ "zod": "^3.0.0"
35
40
  },
36
41
  "devDependencies": {
37
- "@babel/preset-env": "^7.26.9",
38
- "@babel/preset-typescript": "^7.27.0",
39
- "@tsconfig/recommended": "^1.0.8",
42
+ "@babel/preset-env": "^7.27.2",
43
+ "@babel/preset-typescript": "^7.27.1",
44
+ "@tsconfig/recommended": "^1.0.9",
40
45
  "@types/json-schema": "^7.0.15",
41
- "@types/node": "^20.17.27",
42
- "tsup": "^8.4.0",
43
- "typescript": "^5.8.2",
44
- "vitest": "^3.1.2",
45
- "@internal/lint": "0.0.0-trigger-playground-ui-package-20250506151043"
46
+ "@types/node": "^20.19.0",
47
+ "tsup": "^8.5.0",
48
+ "typescript": "^5.8.3",
49
+ "vitest": "^3.2.4",
50
+ "@internal/lint": "0.0.0-tsconfig-compile-20250703214351"
46
51
  },
47
52
  "scripts": {
48
53
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
@@ -91,6 +91,17 @@ describe('convertMessagesToMastraMessages', () => {
91
91
  },
92
92
  ],
93
93
  },
94
+ {
95
+ role: 'tool',
96
+ content: [
97
+ {
98
+ type: 'tool-result',
99
+ toolCallId: 'tool-call-1',
100
+ toolName: 'getWeather',
101
+ result: { location: 'San Francisco' },
102
+ },
103
+ ],
104
+ },
94
105
  ]);
95
106
  });
96
107
 
@@ -143,12 +154,6 @@ describe('convertMessagesToMastraMessages', () => {
143
154
  },
144
155
  ],
145
156
  },
146
- {
147
- id: '3',
148
- role: 'tool',
149
- toolCallId: 'tool-call-1',
150
- content: '{"temperature":72,"unit":"F"}',
151
- },
152
157
  {
153
158
  id: '4',
154
159
  role: 'assistant',
@@ -162,6 +167,14 @@ describe('convertMessagesToMastraMessages', () => {
162
167
  expect(result[0].role).toBe('user');
163
168
  expect(result[1].role).toBe('assistant');
164
169
  expect(result[2].role).toBe('tool');
170
+ expect(result[2].content).toEqual([
171
+ {
172
+ type: 'tool-result',
173
+ toolCallId: 'tool-call-1',
174
+ toolName: 'getWeather',
175
+ result: { location: 'San Francisco' },
176
+ },
177
+ ]);
165
178
  expect(result[3].role).toBe('assistant');
166
179
  });
167
180
  });
@@ -1,19 +1,19 @@
1
1
  // Cross-platform UUID generation function
2
- import { AbstractAgent, EventType } from '@ag-ui/client';
3
2
  import type {
3
+ AgentConfig,
4
4
  BaseEvent,
5
+ Message,
5
6
  RunAgentInput,
6
- AgentConfig,
7
- RunStartedEvent,
8
7
  RunFinishedEvent,
9
- TextMessageStartEvent,
8
+ RunStartedEvent,
10
9
  TextMessageContentEvent,
11
10
  TextMessageEndEvent,
12
- Message,
13
- ToolCallStartEvent,
11
+ TextMessageStartEvent,
14
12
  ToolCallArgsEvent,
15
13
  ToolCallEndEvent,
14
+ ToolCallStartEvent,
16
15
  } from '@ag-ui/client';
16
+ import { AbstractAgent, EventType } from '@ag-ui/client';
17
17
  import type { CoreMessage } from '@mastra/core';
18
18
  import { Observable } from 'rxjs';
19
19
  import type { Agent } from '../resources/agent';
@@ -39,7 +39,6 @@ export class AGUIAdapter extends AbstractAgent {
39
39
  protected run(input: RunAgentInput): Observable<BaseEvent> {
40
40
  return new Observable<BaseEvent>(subscriber => {
41
41
  const convertedMessages = convertMessagesToMastraMessages(input.messages);
42
-
43
42
  subscriber.next({
44
43
  type: EventType.RUN_STARTED,
45
44
  threadId: input.threadId,
@@ -66,17 +65,18 @@ export class AGUIAdapter extends AbstractAgent {
66
65
  })
67
66
  .then(response => {
68
67
  let currentMessageId: string | undefined = undefined;
68
+ let isInTextMessage = false;
69
69
  return response.processDataStream({
70
70
  onTextPart: text => {
71
71
  if (currentMessageId === undefined) {
72
72
  currentMessageId = generateUUID();
73
-
74
73
  const message: TextMessageStartEvent = {
75
74
  type: EventType.TEXT_MESSAGE_START,
76
75
  messageId: currentMessageId,
77
76
  role: 'assistant',
78
77
  };
79
78
  subscriber.next(message);
79
+ isInTextMessage = true;
80
80
  }
81
81
 
82
82
  const message: TextMessageContentEvent = {
@@ -86,14 +86,14 @@ export class AGUIAdapter extends AbstractAgent {
86
86
  };
87
87
  subscriber.next(message);
88
88
  },
89
- onFinishMessagePart: message => {
90
- console.log('onFinishMessagePart', message);
89
+ onFinishMessagePart: () => {
91
90
  if (currentMessageId !== undefined) {
92
91
  const message: TextMessageEndEvent = {
93
92
  type: EventType.TEXT_MESSAGE_END,
94
93
  messageId: currentMessageId,
95
94
  };
96
95
  subscriber.next(message);
96
+ isInTextMessage = false;
97
97
  }
98
98
  // Emit run finished event
99
99
  subscriber.next({
@@ -107,6 +107,15 @@ export class AGUIAdapter extends AbstractAgent {
107
107
  },
108
108
  onToolCallPart(streamPart) {
109
109
  const parentMessageId = currentMessageId || generateUUID();
110
+ if (isInTextMessage) {
111
+ const message: TextMessageEndEvent = {
112
+ type: EventType.TEXT_MESSAGE_END,
113
+ messageId: parentMessageId,
114
+ };
115
+ subscriber.next(message);
116
+ isInTextMessage = false;
117
+ }
118
+
110
119
  subscriber.next({
111
120
  type: EventType.TOOL_CALL_START,
112
121
  toolCallId: streamPart.toolCallId,
@@ -130,7 +139,7 @@ export class AGUIAdapter extends AbstractAgent {
130
139
  });
131
140
  })
132
141
  .catch(error => {
133
- console.log('error', error);
142
+ console.error('error', error);
134
143
  // Handle error
135
144
  subscriber.error(error);
136
145
  });
@@ -195,6 +204,17 @@ export function convertMessagesToMastraMessages(messages: Message[]): CoreMessag
195
204
  role: 'assistant',
196
205
  content: parts,
197
206
  });
207
+ if (message.toolCalls?.length) {
208
+ result.push({
209
+ role: 'tool',
210
+ content: message.toolCalls.map(toolCall => ({
211
+ type: 'tool-result',
212
+ toolCallId: toolCall.id,
213
+ toolName: toolCall.function.name,
214
+ result: JSON.parse(toolCall.function.arguments),
215
+ })),
216
+ });
217
+ }
198
218
  } else if (message.role === 'user') {
199
219
  result.push({
200
220
  role: 'user',
package/src/client.ts CHANGED
@@ -1,6 +1,18 @@
1
1
  import type { AbstractAgent } from '@ag-ui/client';
2
+ import type { ServerDetailInfo } from '@mastra/core/mcp';
2
3
  import { AGUIAdapter } from './adapters/agui';
3
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
4
+ import {
5
+ Agent,
6
+ MemoryThread,
7
+ Tool,
8
+ Workflow,
9
+ Vector,
10
+ BaseResource,
11
+ Network,
12
+ A2A,
13
+ MCPTool,
14
+ LegacyWorkflow,
15
+ } from './resources';
4
16
  import type {
5
17
  ClientOptions,
6
18
  CreateMemoryThreadParams,
@@ -15,11 +27,19 @@ import type {
15
27
  GetTelemetryParams,
16
28
  GetTelemetryResponse,
17
29
  GetToolResponse,
18
- GetVNextWorkflowResponse,
19
30
  GetWorkflowResponse,
20
31
  SaveMessageToMemoryParams,
21
32
  SaveMessageToMemoryResponse,
33
+ McpServerListResponse,
34
+ McpServerToolListResponse,
35
+ GetLegacyWorkflowResponse,
36
+ GetVNextNetworkResponse,
37
+ GetNetworkMemoryThreadParams,
38
+ CreateNetworkMemoryThreadParams,
39
+ SaveNetworkMessageToMemoryParams,
22
40
  } from './types';
41
+ import { VNextNetwork } from './resources/vNextNetwork';
42
+ import { NetworkMemoryThread } from './resources/network-memory-thread';
23
43
 
24
44
  export class MastraClient extends BaseResource {
25
45
  constructor(options: ClientOptions) {
@@ -109,6 +129,53 @@ export class MastraClient extends BaseResource {
109
129
  return this.request(`/api/memory/status?agentId=${agentId}`);
110
130
  }
111
131
 
132
+ /**
133
+ * Retrieves memory threads for a resource
134
+ * @param params - Parameters containing the resource ID
135
+ * @returns Promise containing array of memory threads
136
+ */
137
+ public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
138
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
139
+ }
140
+
141
+ /**
142
+ * Creates a new memory thread
143
+ * @param params - Parameters for creating the memory thread
144
+ * @returns Promise containing the created memory thread
145
+ */
146
+ public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
147
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
148
+ }
149
+
150
+ /**
151
+ * Gets a memory thread instance by ID
152
+ * @param threadId - ID of the memory thread to retrieve
153
+ * @returns MemoryThread instance
154
+ */
155
+ public getNetworkMemoryThread(threadId: string, networkId: string) {
156
+ return new NetworkMemoryThread(this.options, threadId, networkId);
157
+ }
158
+
159
+ /**
160
+ * Saves messages to memory
161
+ * @param params - Parameters containing messages to save
162
+ * @returns Promise containing the saved messages
163
+ */
164
+ public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
165
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
166
+ method: 'POST',
167
+ body: params,
168
+ });
169
+ }
170
+
171
+ /**
172
+ * Gets the status of the memory system
173
+ * @returns Promise containing memory system status
174
+ */
175
+ public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
176
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
177
+ }
178
+
112
179
  /**
113
180
  * Retrieves all available tools
114
181
  * @returns Promise containing map of tool IDs to tool details
@@ -126,6 +193,23 @@ export class MastraClient extends BaseResource {
126
193
  return new Tool(this.options, toolId);
127
194
  }
128
195
 
196
+ /**
197
+ * Retrieves all available legacy workflows
198
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
199
+ */
200
+ public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
201
+ return this.request('/api/workflows/legacy');
202
+ }
203
+
204
+ /**
205
+ * Gets a legacy workflow instance by ID
206
+ * @param workflowId - ID of the legacy workflow to retrieve
207
+ * @returns Legacy Workflow instance
208
+ */
209
+ public getLegacyWorkflow(workflowId: string) {
210
+ return new LegacyWorkflow(this.options, workflowId);
211
+ }
212
+
129
213
  /**
130
214
  * Retrieves all available workflows
131
215
  * @returns Promise containing map of workflow IDs to workflow details
@@ -143,23 +227,6 @@ export class MastraClient extends BaseResource {
143
227
  return new Workflow(this.options, workflowId);
144
228
  }
145
229
 
146
- /**
147
- * Retrieves all available vNext workflows
148
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
149
- */
150
- public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
151
- return this.request('/api/workflows/v-next');
152
- }
153
-
154
- /**
155
- * Gets a vNext workflow instance by ID
156
- * @param workflowId - ID of the vNext workflow to retrieve
157
- * @returns vNext Workflow instance
158
- */
159
- public getVNextWorkflow(workflowId: string) {
160
- return new VNextWorkflow(this.options, workflowId);
161
- }
162
-
163
230
  /**
164
231
  * Gets a vector instance by name
165
232
  * @param vectorName - Name of the vector to retrieve
@@ -175,7 +242,43 @@ export class MastraClient extends BaseResource {
175
242
  * @returns Promise containing array of log messages
176
243
  */
177
244
  public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
178
- return this.request(`/api/logs?transportId=${params.transportId}`);
245
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
246
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
247
+
248
+ const searchParams = new URLSearchParams();
249
+ if (transportId) {
250
+ searchParams.set('transportId', transportId);
251
+ }
252
+ if (fromDate) {
253
+ searchParams.set('fromDate', fromDate.toISOString());
254
+ }
255
+ if (toDate) {
256
+ searchParams.set('toDate', toDate.toISOString());
257
+ }
258
+ if (logLevel) {
259
+ searchParams.set('logLevel', logLevel);
260
+ }
261
+ if (page) {
262
+ searchParams.set('page', String(page));
263
+ }
264
+ if (perPage) {
265
+ searchParams.set('perPage', String(perPage));
266
+ }
267
+ if (_filters) {
268
+ if (Array.isArray(_filters)) {
269
+ for (const filter of _filters) {
270
+ searchParams.append('filters', filter);
271
+ }
272
+ } else {
273
+ searchParams.set('filters', _filters);
274
+ }
275
+ }
276
+
277
+ if (searchParams.size) {
278
+ return this.request(`/api/logs?${searchParams}`);
279
+ } else {
280
+ return this.request(`/api/logs`);
281
+ }
179
282
  }
180
283
 
181
284
  /**
@@ -184,7 +287,47 @@ export class MastraClient extends BaseResource {
184
287
  * @returns Promise containing array of log messages
185
288
  */
186
289
  public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
187
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
290
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
291
+
292
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
293
+ const searchParams = new URLSearchParams();
294
+ if (runId) {
295
+ searchParams.set('runId', runId);
296
+ }
297
+ if (transportId) {
298
+ searchParams.set('transportId', transportId);
299
+ }
300
+ if (fromDate) {
301
+ searchParams.set('fromDate', fromDate.toISOString());
302
+ }
303
+ if (toDate) {
304
+ searchParams.set('toDate', toDate.toISOString());
305
+ }
306
+ if (logLevel) {
307
+ searchParams.set('logLevel', logLevel);
308
+ }
309
+ if (page) {
310
+ searchParams.set('page', String(page));
311
+ }
312
+ if (perPage) {
313
+ searchParams.set('perPage', String(perPage));
314
+ }
315
+
316
+ if (_filters) {
317
+ if (Array.isArray(_filters)) {
318
+ for (const filter of _filters) {
319
+ searchParams.append('filters', filter);
320
+ }
321
+ } else {
322
+ searchParams.set('filters', _filters);
323
+ }
324
+ }
325
+
326
+ if (searchParams.size) {
327
+ return this.request(`/api/logs/${runId}?${searchParams}`);
328
+ } else {
329
+ return this.request(`/api/logs/${runId}`);
330
+ }
188
331
  }
189
332
 
190
333
  /**
@@ -244,10 +387,18 @@ export class MastraClient extends BaseResource {
244
387
  * Retrieves all available networks
245
388
  * @returns Promise containing map of network IDs to network details
246
389
  */
247
- public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
390
+ public getNetworks(): Promise<Array<GetNetworkResponse>> {
248
391
  return this.request('/api/networks');
249
392
  }
250
393
 
394
+ /**
395
+ * Retrieves all available vNext networks
396
+ * @returns Promise containing map of vNext network IDs to vNext network details
397
+ */
398
+ public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
399
+ return this.request('/api/networks/v-next');
400
+ }
401
+
251
402
  /**
252
403
  * Gets a network instance by ID
253
404
  * @param networkId - ID of the network to retrieve
@@ -256,4 +407,74 @@ export class MastraClient extends BaseResource {
256
407
  public getNetwork(networkId: string) {
257
408
  return new Network(this.options, networkId);
258
409
  }
410
+
411
+ /**
412
+ * Gets a vNext network instance by ID
413
+ * @param networkId - ID of the vNext network to retrieve
414
+ * @returns vNext Network instance
415
+ */
416
+ public getVNextNetwork(networkId: string) {
417
+ return new VNextNetwork(this.options, networkId);
418
+ }
419
+
420
+ /**
421
+ * Retrieves a list of available MCP servers.
422
+ * @param params - Optional parameters for pagination (limit, offset).
423
+ * @returns Promise containing the list of MCP servers and pagination info.
424
+ */
425
+ public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
426
+ const searchParams = new URLSearchParams();
427
+ if (params?.limit !== undefined) {
428
+ searchParams.set('limit', String(params.limit));
429
+ }
430
+ if (params?.offset !== undefined) {
431
+ searchParams.set('offset', String(params.offset));
432
+ }
433
+ const queryString = searchParams.toString();
434
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
435
+ }
436
+
437
+ /**
438
+ * Retrieves detailed information for a specific MCP server.
439
+ * @param serverId - The ID of the MCP server to retrieve.
440
+ * @param params - Optional parameters, e.g., specific version.
441
+ * @returns Promise containing the detailed MCP server information.
442
+ */
443
+ public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
444
+ const searchParams = new URLSearchParams();
445
+ if (params?.version) {
446
+ searchParams.set('version', params.version);
447
+ }
448
+ const queryString = searchParams.toString();
449
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
450
+ }
451
+
452
+ /**
453
+ * Retrieves a list of tools for a specific MCP server.
454
+ * @param serverId - The ID of the MCP server.
455
+ * @returns Promise containing the list of tools.
456
+ */
457
+ public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
458
+ return this.request(`/api/mcp/${serverId}/tools`);
459
+ }
460
+
461
+ /**
462
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
463
+ * This instance can then be used to fetch details or execute the tool.
464
+ * @param serverId - The ID of the MCP server.
465
+ * @param toolId - The ID of the tool.
466
+ * @returns MCPTool instance.
467
+ */
468
+ public getMcpServerTool(serverId: string, toolId: string): MCPTool {
469
+ return new MCPTool(this.options, serverId, toolId);
470
+ }
471
+
472
+ /**
473
+ * Gets an A2A client for interacting with an agent via the A2A protocol
474
+ * @param agentId - ID of the agent to interact with
475
+ * @returns A2A client instance
476
+ */
477
+ public getA2A(agentId: string) {
478
+ return new A2A(this.options, agentId);
479
+ }
259
480
  }
package/src/example.ts CHANGED
@@ -1,40 +1,42 @@
1
- // import { MastraClient } from './client';
1
+ import { MastraClient } from './client';
2
+ import z from 'zod';
2
3
  // import type { WorkflowRunResult } from './types';
3
4
 
4
5
  // Agent
6
+ (async () => {
7
+ const client = new MastraClient({
8
+ baseUrl: 'http://localhost:4111',
9
+ });
5
10
 
6
- // (async () => {
7
- // const client = new MastraClient({
8
- // baseUrl: 'http://localhost:4111',
9
- // });
10
-
11
- // console.log('Starting agent...');
12
-
13
- // try {
14
- // const agent = client.getAgent('weatherAgent');
15
- // const response = await agent.stream({
16
- // messages: 'what is the weather in new york?',
17
- // })
11
+ console.log('Starting agent...');
18
12
 
19
- // response.processDataStream({
20
- // onTextPart: (text) => {
21
- // process.stdout.write(text);
22
- // },
23
- // onFilePart: (file) => {
24
- // console.log(file);
25
- // },
26
- // onDataPart: (data) => {
27
- // console.log(data);
28
- // },
29
- // onErrorPart: (error) => {
30
- // console.error(error);
31
- // },
32
- // });
13
+ try {
14
+ const agent = client.getAgent('weatherAgent');
15
+ const response = await agent.stream({
16
+ messages: 'what is the weather in new york?',
17
+ });
33
18
 
34
- // } catch (error) {
35
- // console.error(error);
36
- // }
37
- // })();
19
+ response.processDataStream({
20
+ onTextPart: text => {
21
+ process.stdout.write(text);
22
+ },
23
+ onFilePart: file => {
24
+ console.log(file);
25
+ },
26
+ onDataPart: data => {
27
+ console.log(data);
28
+ },
29
+ onErrorPart: error => {
30
+ console.error(error);
31
+ },
32
+ onToolCallPart(streamPart) {
33
+ console.log(streamPart);
34
+ },
35
+ });
36
+ } catch (error) {
37
+ console.error(error);
38
+ }
39
+ })();
38
40
 
39
41
  // Workflow
40
42
  // (async () => {