@mastra/client-js 0.0.0-inject-middleware-20250528222017 → 0.0.0-interpolate-reporter-url-20250910180021

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 (78) hide show
  1. package/CHANGELOG.md +1423 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +7 -4
  4. package/dist/client.d.ts +280 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/example.d.ts +2 -0
  7. package/dist/example.d.ts.map +1 -0
  8. package/dist/index.cjs +2222 -375
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +4 -900
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2224 -377
  13. package/dist/index.js.map +1 -0
  14. package/dist/resources/a2a.d.ts +41 -0
  15. package/dist/resources/a2a.d.ts.map +1 -0
  16. package/dist/resources/agent-builder.d.ts +161 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +155 -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 +13 -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/observability.d.ts +19 -0
  35. package/dist/resources/observability.d.ts.map +1 -0
  36. package/dist/resources/tool.d.ts +23 -0
  37. package/dist/resources/tool.d.ts.map +1 -0
  38. package/dist/resources/vNextNetwork.d.ts +42 -0
  39. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  40. package/dist/resources/vector.d.ts +48 -0
  41. package/dist/resources/vector.d.ts.map +1 -0
  42. package/dist/resources/workflow.d.ts +169 -0
  43. package/dist/resources/workflow.d.ts.map +1 -0
  44. package/dist/types.d.ts +462 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/utils/index.d.ts +3 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/utils/process-client-tools.d.ts +3 -0
  49. package/dist/utils/process-client-tools.d.ts.map +1 -0
  50. package/dist/utils/process-mastra-stream.d.ts +7 -0
  51. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  52. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  53. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  54. package/package.json +38 -21
  55. package/dist/index.d.cts +0 -900
  56. package/eslint.config.js +0 -6
  57. package/src/adapters/agui.test.ts +0 -180
  58. package/src/adapters/agui.ts +0 -239
  59. package/src/client.ts +0 -334
  60. package/src/example.ts +0 -64
  61. package/src/index.test.ts +0 -830
  62. package/src/index.ts +0 -2
  63. package/src/resources/a2a.ts +0 -88
  64. package/src/resources/agent.ts +0 -197
  65. package/src/resources/base.ts +0 -70
  66. package/src/resources/index.ts +0 -10
  67. package/src/resources/legacy-workflow.ts +0 -242
  68. package/src/resources/mcp-tool.ts +0 -48
  69. package/src/resources/memory-thread.ts +0 -63
  70. package/src/resources/network.ts +0 -86
  71. package/src/resources/tool.ts +0 -45
  72. package/src/resources/vector.ts +0 -83
  73. package/src/resources/workflow.ts +0 -353
  74. package/src/types.ts +0 -314
  75. package/src/utils/index.ts +0 -11
  76. package/src/utils/zod-to-json-schema.ts +0 -10
  77. package/tsconfig.json +0 -5
  78. package/vitest.config.js +0 -8
package/src/client.ts DELETED
@@ -1,334 +0,0 @@
1
- import type { AbstractAgent } from '@ag-ui/client';
2
- import type { ServerDetailInfo } from '@mastra/core/mcp';
3
- import { AGUIAdapter } from './adapters/agui';
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';
16
- import type {
17
- ClientOptions,
18
- CreateMemoryThreadParams,
19
- CreateMemoryThreadResponse,
20
- GetAgentResponse,
21
- GetLogParams,
22
- GetLogsParams,
23
- GetLogsResponse,
24
- GetMemoryThreadParams,
25
- GetMemoryThreadResponse,
26
- GetNetworkResponse,
27
- GetTelemetryParams,
28
- GetTelemetryResponse,
29
- GetToolResponse,
30
- GetWorkflowResponse,
31
- SaveMessageToMemoryParams,
32
- SaveMessageToMemoryResponse,
33
- McpServerListResponse,
34
- McpServerToolListResponse,
35
- GetLegacyWorkflowResponse,
36
- } from './types';
37
-
38
- export class MastraClient extends BaseResource {
39
- constructor(options: ClientOptions) {
40
- super(options);
41
- }
42
-
43
- /**
44
- * Retrieves all available agents
45
- * @returns Promise containing map of agent IDs to agent details
46
- */
47
- public getAgents(): Promise<Record<string, GetAgentResponse>> {
48
- return this.request('/api/agents');
49
- }
50
-
51
- public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
52
- const agents = await this.getAgents();
53
-
54
- return Object.entries(agents).reduce(
55
- (acc, [agentId]) => {
56
- const agent = this.getAgent(agentId);
57
-
58
- acc[agentId] = new AGUIAdapter({
59
- agentId,
60
- agent,
61
- resourceId,
62
- });
63
-
64
- return acc;
65
- },
66
- {} as Record<string, AbstractAgent>,
67
- );
68
- }
69
-
70
- /**
71
- * Gets an agent instance by ID
72
- * @param agentId - ID of the agent to retrieve
73
- * @returns Agent instance
74
- */
75
- public getAgent(agentId: string) {
76
- return new Agent(this.options, agentId);
77
- }
78
-
79
- /**
80
- * Retrieves memory threads for a resource
81
- * @param params - Parameters containing the resource ID
82
- * @returns Promise containing array of memory threads
83
- */
84
- public getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse> {
85
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
86
- }
87
-
88
- /**
89
- * Creates a new memory thread
90
- * @param params - Parameters for creating the memory thread
91
- * @returns Promise containing the created memory thread
92
- */
93
- public createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
94
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: 'POST', body: params });
95
- }
96
-
97
- /**
98
- * Gets a memory thread instance by ID
99
- * @param threadId - ID of the memory thread to retrieve
100
- * @returns MemoryThread instance
101
- */
102
- public getMemoryThread(threadId: string, agentId: string) {
103
- return new MemoryThread(this.options, threadId, agentId);
104
- }
105
-
106
- /**
107
- * Saves messages to memory
108
- * @param params - Parameters containing messages to save
109
- * @returns Promise containing the saved messages
110
- */
111
- public saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
112
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
113
- method: 'POST',
114
- body: params,
115
- });
116
- }
117
-
118
- /**
119
- * Gets the status of the memory system
120
- * @returns Promise containing memory system status
121
- */
122
- public getMemoryStatus(agentId: string): Promise<{ result: boolean }> {
123
- return this.request(`/api/memory/status?agentId=${agentId}`);
124
- }
125
-
126
- /**
127
- * Retrieves all available tools
128
- * @returns Promise containing map of tool IDs to tool details
129
- */
130
- public getTools(): Promise<Record<string, GetToolResponse>> {
131
- return this.request('/api/tools');
132
- }
133
-
134
- /**
135
- * Gets a tool instance by ID
136
- * @param toolId - ID of the tool to retrieve
137
- * @returns Tool instance
138
- */
139
- public getTool(toolId: string) {
140
- return new Tool(this.options, toolId);
141
- }
142
-
143
- /**
144
- * Retrieves all available legacy workflows
145
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
146
- */
147
- public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
148
- return this.request('/api/workflows/legacy');
149
- }
150
-
151
- /**
152
- * Gets a legacy workflow instance by ID
153
- * @param workflowId - ID of the legacy workflow to retrieve
154
- * @returns Legacy Workflow instance
155
- */
156
- public getLegacyWorkflow(workflowId: string) {
157
- return new LegacyWorkflow(this.options, workflowId);
158
- }
159
-
160
- /**
161
- * Retrieves all available workflows
162
- * @returns Promise containing map of workflow IDs to workflow details
163
- */
164
- public getWorkflows(): Promise<Record<string, GetWorkflowResponse>> {
165
- return this.request('/api/workflows');
166
- }
167
-
168
- /**
169
- * Gets a workflow instance by ID
170
- * @param workflowId - ID of the workflow to retrieve
171
- * @returns Workflow instance
172
- */
173
- public getWorkflow(workflowId: string) {
174
- return new Workflow(this.options, workflowId);
175
- }
176
-
177
- /**
178
- * Gets a vector instance by name
179
- * @param vectorName - Name of the vector to retrieve
180
- * @returns Vector instance
181
- */
182
- public getVector(vectorName: string) {
183
- return new Vector(this.options, vectorName);
184
- }
185
-
186
- /**
187
- * Retrieves logs
188
- * @param params - Parameters for filtering logs
189
- * @returns Promise containing array of log messages
190
- */
191
- public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
192
- return this.request(`/api/logs?transportId=${params.transportId}`);
193
- }
194
-
195
- /**
196
- * Gets logs for a specific run
197
- * @param params - Parameters containing run ID to retrieve
198
- * @returns Promise containing array of log messages
199
- */
200
- public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
201
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
202
- }
203
-
204
- /**
205
- * List of all log transports
206
- * @returns Promise containing list of log transports
207
- */
208
- public getLogTransports(): Promise<{ transports: string[] }> {
209
- return this.request('/api/logs/transports');
210
- }
211
-
212
- /**
213
- * List of all traces (paged)
214
- * @param params - Parameters for filtering traces
215
- * @returns Promise containing telemetry data
216
- */
217
- public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
218
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
219
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
220
-
221
- const searchParams = new URLSearchParams();
222
- if (name) {
223
- searchParams.set('name', name);
224
- }
225
- if (scope) {
226
- searchParams.set('scope', scope);
227
- }
228
- if (page) {
229
- searchParams.set('page', String(page));
230
- }
231
- if (perPage) {
232
- searchParams.set('perPage', String(perPage));
233
- }
234
- if (_attribute) {
235
- if (Array.isArray(_attribute)) {
236
- for (const attr of _attribute) {
237
- searchParams.append('attribute', attr);
238
- }
239
- } else {
240
- searchParams.set('attribute', _attribute);
241
- }
242
- }
243
- if (fromDate) {
244
- searchParams.set('fromDate', fromDate.toISOString());
245
- }
246
- if (toDate) {
247
- searchParams.set('toDate', toDate.toISOString());
248
- }
249
-
250
- if (searchParams.size) {
251
- return this.request(`/api/telemetry?${searchParams}`);
252
- } else {
253
- return this.request(`/api/telemetry`);
254
- }
255
- }
256
-
257
- /**
258
- * Retrieves all available networks
259
- * @returns Promise containing map of network IDs to network details
260
- */
261
- public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
262
- return this.request('/api/networks');
263
- }
264
-
265
- /**
266
- * Gets a network instance by ID
267
- * @param networkId - ID of the network to retrieve
268
- * @returns Network instance
269
- */
270
- public getNetwork(networkId: string) {
271
- return new Network(this.options, networkId);
272
- }
273
-
274
- /**
275
- * Retrieves a list of available MCP servers.
276
- * @param params - Optional parameters for pagination (limit, offset).
277
- * @returns Promise containing the list of MCP servers and pagination info.
278
- */
279
- public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
280
- const searchParams = new URLSearchParams();
281
- if (params?.limit !== undefined) {
282
- searchParams.set('limit', String(params.limit));
283
- }
284
- if (params?.offset !== undefined) {
285
- searchParams.set('offset', String(params.offset));
286
- }
287
- const queryString = searchParams.toString();
288
- return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
289
- }
290
-
291
- /**
292
- * Retrieves detailed information for a specific MCP server.
293
- * @param serverId - The ID of the MCP server to retrieve.
294
- * @param params - Optional parameters, e.g., specific version.
295
- * @returns Promise containing the detailed MCP server information.
296
- */
297
- public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
298
- const searchParams = new URLSearchParams();
299
- if (params?.version) {
300
- searchParams.set('version', params.version);
301
- }
302
- const queryString = searchParams.toString();
303
- return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
304
- }
305
-
306
- /**
307
- * Retrieves a list of tools for a specific MCP server.
308
- * @param serverId - The ID of the MCP server.
309
- * @returns Promise containing the list of tools.
310
- */
311
- public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
312
- return this.request(`/api/mcp/${serverId}/tools`);
313
- }
314
-
315
- /**
316
- * Gets an MCPTool resource instance for a specific tool on an MCP server.
317
- * This instance can then be used to fetch details or execute the tool.
318
- * @param serverId - The ID of the MCP server.
319
- * @param toolId - The ID of the tool.
320
- * @returns MCPTool instance.
321
- */
322
- public getMcpServerTool(serverId: string, toolId: string): MCPTool {
323
- return new MCPTool(this.options, serverId, toolId);
324
- }
325
-
326
- /**
327
- * Gets an A2A client for interacting with an agent via the A2A protocol
328
- * @param agentId - ID of the agent to interact with
329
- * @returns A2A client instance
330
- */
331
- public getA2A(agentId: string) {
332
- return new A2A(this.options, agentId);
333
- }
334
- }
package/src/example.ts DELETED
@@ -1,64 +0,0 @@
1
- import { MastraClient } from './client';
2
- // import type { WorkflowRunResult } from './types';
3
-
4
- // Agent
5
-
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
- });
18
-
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
- });
33
- } catch (error) {
34
- console.error(error);
35
- }
36
- })();
37
-
38
- // Workflow
39
- // (async () => {
40
- // const client = new MastraClient({
41
- // baseUrl: 'http://localhost:4111',
42
- // });
43
-
44
- // try {
45
- // const workflowId = 'myWorkflow';
46
- // const workflow = client.getWorkflow(workflowId);
47
-
48
- // const { runId } = await workflow.createRun();
49
-
50
- // workflow.watch({ runId }, record => {
51
- // console.log(new Date().toTimeString(), record);
52
- // });
53
-
54
- // await workflow.start({
55
- // runId,
56
- // triggerData: {
57
- // city: 'New York',
58
- // },
59
- // });
60
-
61
- // } catch (e) {
62
- // console.error('Workflow error:', e);
63
- // }
64
- // })();