@mastra/client-js 0.0.0-update-scorers-api-20250801170445 → 0.0.0-usechat-duplicate-20251016110554

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 (89) hide show
  1. package/CHANGELOG.md +1050 -3
  2. package/README.md +6 -8
  3. package/dist/client.d.ts +57 -44
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +1735 -850
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1734 -851
  10. package/dist/index.js.map +1 -1
  11. package/dist/resources/a2a.d.ts +15 -18
  12. package/dist/resources/a2a.d.ts.map +1 -1
  13. package/dist/resources/agent-builder.d.ts +160 -0
  14. package/dist/resources/agent-builder.d.ts.map +1 -0
  15. package/dist/resources/agent.d.ts +89 -17
  16. package/dist/resources/agent.d.ts.map +1 -1
  17. package/dist/resources/base.d.ts +1 -1
  18. package/dist/resources/base.d.ts.map +1 -1
  19. package/dist/resources/index.d.ts +10 -10
  20. package/dist/resources/index.d.ts.map +1 -1
  21. package/dist/resources/mcp-tool.d.ts +4 -3
  22. package/dist/resources/mcp-tool.d.ts.map +1 -1
  23. package/dist/resources/memory-thread.d.ts +3 -3
  24. package/dist/resources/memory-thread.d.ts.map +1 -1
  25. package/dist/resources/network-memory-thread.d.ts +3 -3
  26. package/dist/resources/network-memory-thread.d.ts.map +1 -1
  27. package/dist/resources/observability.d.ts +35 -0
  28. package/dist/resources/observability.d.ts.map +1 -0
  29. package/dist/resources/tool.d.ts +4 -3
  30. package/dist/resources/tool.d.ts.map +1 -1
  31. package/dist/resources/vector.d.ts +7 -4
  32. package/dist/resources/vector.d.ts.map +1 -1
  33. package/dist/resources/workflow.d.ts +129 -14
  34. package/dist/resources/workflow.d.ts.map +1 -1
  35. package/dist/tools.d.ts +22 -0
  36. package/dist/tools.d.ts.map +1 -0
  37. package/dist/types.d.ts +100 -43
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/utils/index.d.ts +2 -0
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist/utils/process-client-tools.d.ts.map +1 -1
  42. package/dist/utils/process-mastra-stream.d.ts +11 -0
  43. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  44. package/dist/utils/zod-to-json-schema.d.ts +2 -104
  45. package/dist/utils/zod-to-json-schema.d.ts.map +1 -1
  46. package/package.json +24 -16
  47. package/dist/adapters/agui.d.ts +0 -23
  48. package/dist/adapters/agui.d.ts.map +0 -1
  49. package/dist/resources/legacy-workflow.d.ts +0 -87
  50. package/dist/resources/legacy-workflow.d.ts.map +0 -1
  51. package/dist/resources/network.d.ts +0 -30
  52. package/dist/resources/network.d.ts.map +0 -1
  53. package/dist/resources/vNextNetwork.d.ts +0 -42
  54. package/dist/resources/vNextNetwork.d.ts.map +0 -1
  55. package/eslint.config.js +0 -6
  56. package/integration-tests/agui-adapter.test.ts +0 -122
  57. package/integration-tests/package.json +0 -18
  58. package/integration-tests/src/mastra/index.ts +0 -35
  59. package/integration-tests/vitest.config.ts +0 -9
  60. package/src/adapters/agui.test.ts +0 -322
  61. package/src/adapters/agui.ts +0 -239
  62. package/src/client.ts +0 -623
  63. package/src/example.ts +0 -95
  64. package/src/index.test.ts +0 -1226
  65. package/src/index.ts +0 -3
  66. package/src/resources/a2a.ts +0 -88
  67. package/src/resources/agent.ts +0 -785
  68. package/src/resources/base.ts +0 -76
  69. package/src/resources/index.ts +0 -10
  70. package/src/resources/legacy-workflow.ts +0 -242
  71. package/src/resources/mcp-tool.ts +0 -48
  72. package/src/resources/memory-thread.test.ts +0 -285
  73. package/src/resources/memory-thread.ts +0 -99
  74. package/src/resources/network-memory-thread.test.ts +0 -269
  75. package/src/resources/network-memory-thread.ts +0 -81
  76. package/src/resources/network.ts +0 -86
  77. package/src/resources/tool.ts +0 -45
  78. package/src/resources/vNextNetwork.ts +0 -194
  79. package/src/resources/vector.ts +0 -83
  80. package/src/resources/workflow.ts +0 -410
  81. package/src/types.ts +0 -502
  82. package/src/utils/index.ts +0 -11
  83. package/src/utils/process-client-tools.ts +0 -32
  84. package/src/utils/zod-to-json-schema.ts +0 -10
  85. package/src/v2-messages.test.ts +0 -180
  86. package/tsconfig.build.json +0 -9
  87. package/tsconfig.json +0 -5
  88. package/tsup.config.ts +0 -22
  89. package/vitest.config.js +0 -8
package/src/client.ts DELETED
@@ -1,623 +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 { NetworkMemoryThread } from './resources/network-memory-thread';
17
- import { VNextNetwork } from './resources/vNextNetwork';
18
- import type {
19
- ClientOptions,
20
- CreateMemoryThreadParams,
21
- CreateMemoryThreadResponse,
22
- GetAgentResponse,
23
- GetLogParams,
24
- GetLogsParams,
25
- GetLogsResponse,
26
- GetMemoryThreadParams,
27
- GetMemoryThreadResponse,
28
- GetNetworkResponse,
29
- GetTelemetryParams,
30
- GetTelemetryResponse,
31
- GetToolResponse,
32
- GetWorkflowResponse,
33
- SaveMessageToMemoryParams,
34
- SaveMessageToMemoryResponse,
35
- McpServerListResponse,
36
- McpServerToolListResponse,
37
- GetLegacyWorkflowResponse,
38
- GetVNextNetworkResponse,
39
- GetNetworkMemoryThreadParams,
40
- CreateNetworkMemoryThreadParams,
41
- SaveNetworkMessageToMemoryParams,
42
- GetScorerResponse,
43
- GetScoresByScorerIdParams,
44
- GetScoresResponse,
45
- GetScoresByRunIdParams,
46
- GetScoresByEntityIdParams,
47
- SaveScoreParams,
48
- SaveScoreResponse,
49
- } from './types';
50
-
51
- export class MastraClient extends BaseResource {
52
- constructor(options: ClientOptions) {
53
- super(options);
54
- }
55
-
56
- /**
57
- * Retrieves all available agents
58
- * @returns Promise containing map of agent IDs to agent details
59
- */
60
- public getAgents(): Promise<Record<string, GetAgentResponse>> {
61
- return this.request('/api/agents');
62
- }
63
-
64
- public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
65
- const agents = await this.getAgents();
66
-
67
- return Object.entries(agents).reduce(
68
- (acc, [agentId]) => {
69
- const agent = this.getAgent(agentId);
70
-
71
- acc[agentId] = new AGUIAdapter({
72
- agentId,
73
- agent,
74
- resourceId,
75
- });
76
-
77
- return acc;
78
- },
79
- {} as Record<string, AbstractAgent>,
80
- );
81
- }
82
-
83
- /**
84
- * Gets an agent instance by ID
85
- * @param agentId - ID of the agent to retrieve
86
- * @returns Agent instance
87
- */
88
- public getAgent(agentId: string) {
89
- return new Agent(this.options, agentId);
90
- }
91
-
92
- /**
93
- * Retrieves memory threads for a resource
94
- * @param params - Parameters containing the resource ID
95
- * @returns Promise containing array of memory threads
96
- */
97
- public getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse> {
98
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
99
- }
100
-
101
- /**
102
- * Creates a new memory thread
103
- * @param params - Parameters for creating the memory thread
104
- * @returns Promise containing the created memory thread
105
- */
106
- public createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
107
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: 'POST', body: params });
108
- }
109
-
110
- /**
111
- * Gets a memory thread instance by ID
112
- * @param threadId - ID of the memory thread to retrieve
113
- * @returns MemoryThread instance
114
- */
115
- public getMemoryThread(threadId: string, agentId: string) {
116
- return new MemoryThread(this.options, threadId, agentId);
117
- }
118
-
119
- /**
120
- * Saves messages to memory
121
- * @param params - Parameters containing messages to save
122
- * @returns Promise containing the saved messages
123
- */
124
- public saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
125
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
126
- method: 'POST',
127
- body: params,
128
- });
129
- }
130
-
131
- /**
132
- * Gets the status of the memory system
133
- * @returns Promise containing memory system status
134
- */
135
- public getMemoryStatus(agentId: string): Promise<{ result: boolean }> {
136
- return this.request(`/api/memory/status?agentId=${agentId}`);
137
- }
138
-
139
- /**
140
- * Retrieves memory threads for a resource
141
- * @param params - Parameters containing the resource ID
142
- * @returns Promise containing array of memory threads
143
- */
144
- public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
145
- return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
146
- }
147
-
148
- /**
149
- * Creates a new memory thread
150
- * @param params - Parameters for creating the memory thread
151
- * @returns Promise containing the created memory thread
152
- */
153
- public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
154
- return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
155
- }
156
-
157
- /**
158
- * Gets a memory thread instance by ID
159
- * @param threadId - ID of the memory thread to retrieve
160
- * @returns MemoryThread instance
161
- */
162
- public getNetworkMemoryThread(threadId: string, networkId: string) {
163
- return new NetworkMemoryThread(this.options, threadId, networkId);
164
- }
165
-
166
- /**
167
- * Saves messages to memory
168
- * @param params - Parameters containing messages to save
169
- * @returns Promise containing the saved messages
170
- */
171
- public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
172
- return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
173
- method: 'POST',
174
- body: params,
175
- });
176
- }
177
-
178
- /**
179
- * Gets the status of the memory system
180
- * @returns Promise containing memory system status
181
- */
182
- public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
183
- return this.request(`/api/memory/network/status?networkId=${networkId}`);
184
- }
185
-
186
- /**
187
- * Retrieves all available tools
188
- * @returns Promise containing map of tool IDs to tool details
189
- */
190
- public getTools(): Promise<Record<string, GetToolResponse>> {
191
- return this.request('/api/tools');
192
- }
193
-
194
- /**
195
- * Gets a tool instance by ID
196
- * @param toolId - ID of the tool to retrieve
197
- * @returns Tool instance
198
- */
199
- public getTool(toolId: string) {
200
- return new Tool(this.options, toolId);
201
- }
202
-
203
- /**
204
- * Retrieves all available legacy workflows
205
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
206
- */
207
- public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
208
- return this.request('/api/workflows/legacy');
209
- }
210
-
211
- /**
212
- * Gets a legacy workflow instance by ID
213
- * @param workflowId - ID of the legacy workflow to retrieve
214
- * @returns Legacy Workflow instance
215
- */
216
- public getLegacyWorkflow(workflowId: string) {
217
- return new LegacyWorkflow(this.options, workflowId);
218
- }
219
-
220
- /**
221
- * Retrieves all available workflows
222
- * @returns Promise containing map of workflow IDs to workflow details
223
- */
224
- public getWorkflows(): Promise<Record<string, GetWorkflowResponse>> {
225
- return this.request('/api/workflows');
226
- }
227
-
228
- /**
229
- * Gets a workflow instance by ID
230
- * @param workflowId - ID of the workflow to retrieve
231
- * @returns Workflow instance
232
- */
233
- public getWorkflow(workflowId: string) {
234
- return new Workflow(this.options, workflowId);
235
- }
236
-
237
- /**
238
- * Gets a vector instance by name
239
- * @param vectorName - Name of the vector to retrieve
240
- * @returns Vector instance
241
- */
242
- public getVector(vectorName: string) {
243
- return new Vector(this.options, vectorName);
244
- }
245
-
246
- /**
247
- * Retrieves logs
248
- * @param params - Parameters for filtering logs
249
- * @returns Promise containing array of log messages
250
- */
251
- public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
252
- const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
253
- const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
254
-
255
- const searchParams = new URLSearchParams();
256
- if (transportId) {
257
- searchParams.set('transportId', transportId);
258
- }
259
- if (fromDate) {
260
- searchParams.set('fromDate', fromDate.toISOString());
261
- }
262
- if (toDate) {
263
- searchParams.set('toDate', toDate.toISOString());
264
- }
265
- if (logLevel) {
266
- searchParams.set('logLevel', logLevel);
267
- }
268
- if (page) {
269
- searchParams.set('page', String(page));
270
- }
271
- if (perPage) {
272
- searchParams.set('perPage', String(perPage));
273
- }
274
- if (_filters) {
275
- if (Array.isArray(_filters)) {
276
- for (const filter of _filters) {
277
- searchParams.append('filters', filter);
278
- }
279
- } else {
280
- searchParams.set('filters', _filters);
281
- }
282
- }
283
-
284
- if (searchParams.size) {
285
- return this.request(`/api/logs?${searchParams}`);
286
- } else {
287
- return this.request(`/api/logs`);
288
- }
289
- }
290
-
291
- /**
292
- * Gets logs for a specific run
293
- * @param params - Parameters containing run ID to retrieve
294
- * @returns Promise containing array of log messages
295
- */
296
- public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
297
- const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
298
-
299
- const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
300
- const searchParams = new URLSearchParams();
301
- if (runId) {
302
- searchParams.set('runId', runId);
303
- }
304
- if (transportId) {
305
- searchParams.set('transportId', transportId);
306
- }
307
- if (fromDate) {
308
- searchParams.set('fromDate', fromDate.toISOString());
309
- }
310
- if (toDate) {
311
- searchParams.set('toDate', toDate.toISOString());
312
- }
313
- if (logLevel) {
314
- searchParams.set('logLevel', logLevel);
315
- }
316
- if (page) {
317
- searchParams.set('page', String(page));
318
- }
319
- if (perPage) {
320
- searchParams.set('perPage', String(perPage));
321
- }
322
-
323
- if (_filters) {
324
- if (Array.isArray(_filters)) {
325
- for (const filter of _filters) {
326
- searchParams.append('filters', filter);
327
- }
328
- } else {
329
- searchParams.set('filters', _filters);
330
- }
331
- }
332
-
333
- if (searchParams.size) {
334
- return this.request(`/api/logs/${runId}?${searchParams}`);
335
- } else {
336
- return this.request(`/api/logs/${runId}`);
337
- }
338
- }
339
-
340
- /**
341
- * List of all log transports
342
- * @returns Promise containing list of log transports
343
- */
344
- public getLogTransports(): Promise<{ transports: string[] }> {
345
- return this.request('/api/logs/transports');
346
- }
347
-
348
- /**
349
- * List of all traces (paged)
350
- * @param params - Parameters for filtering traces
351
- * @returns Promise containing telemetry data
352
- */
353
- public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
354
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
355
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
356
-
357
- const searchParams = new URLSearchParams();
358
- if (name) {
359
- searchParams.set('name', name);
360
- }
361
- if (scope) {
362
- searchParams.set('scope', scope);
363
- }
364
- if (page) {
365
- searchParams.set('page', String(page));
366
- }
367
- if (perPage) {
368
- searchParams.set('perPage', String(perPage));
369
- }
370
- if (_attribute) {
371
- if (Array.isArray(_attribute)) {
372
- for (const attr of _attribute) {
373
- searchParams.append('attribute', attr);
374
- }
375
- } else {
376
- searchParams.set('attribute', _attribute);
377
- }
378
- }
379
- if (fromDate) {
380
- searchParams.set('fromDate', fromDate.toISOString());
381
- }
382
- if (toDate) {
383
- searchParams.set('toDate', toDate.toISOString());
384
- }
385
-
386
- if (searchParams.size) {
387
- return this.request(`/api/telemetry?${searchParams}`);
388
- } else {
389
- return this.request(`/api/telemetry`);
390
- }
391
- }
392
-
393
- /**
394
- * Retrieves all available networks
395
- * @returns Promise containing map of network IDs to network details
396
- */
397
- public getNetworks(): Promise<Array<GetNetworkResponse>> {
398
- return this.request('/api/networks');
399
- }
400
-
401
- /**
402
- * Retrieves all available vNext networks
403
- * @returns Promise containing map of vNext network IDs to vNext network details
404
- */
405
- public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
406
- return this.request('/api/networks/v-next');
407
- }
408
-
409
- /**
410
- * Gets a network instance by ID
411
- * @param networkId - ID of the network to retrieve
412
- * @returns Network instance
413
- */
414
- public getNetwork(networkId: string) {
415
- return new Network(this.options, networkId);
416
- }
417
-
418
- /**
419
- * Gets a vNext network instance by ID
420
- * @param networkId - ID of the vNext network to retrieve
421
- * @returns vNext Network instance
422
- */
423
- public getVNextNetwork(networkId: string) {
424
- return new VNextNetwork(this.options, networkId);
425
- }
426
-
427
- /**
428
- * Retrieves a list of available MCP servers.
429
- * @param params - Optional parameters for pagination (limit, offset).
430
- * @returns Promise containing the list of MCP servers and pagination info.
431
- */
432
- public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
433
- const searchParams = new URLSearchParams();
434
- if (params?.limit !== undefined) {
435
- searchParams.set('limit', String(params.limit));
436
- }
437
- if (params?.offset !== undefined) {
438
- searchParams.set('offset', String(params.offset));
439
- }
440
- const queryString = searchParams.toString();
441
- return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
442
- }
443
-
444
- /**
445
- * Retrieves detailed information for a specific MCP server.
446
- * @param serverId - The ID of the MCP server to retrieve.
447
- * @param params - Optional parameters, e.g., specific version.
448
- * @returns Promise containing the detailed MCP server information.
449
- */
450
- public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
451
- const searchParams = new URLSearchParams();
452
- if (params?.version) {
453
- searchParams.set('version', params.version);
454
- }
455
- const queryString = searchParams.toString();
456
- return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
457
- }
458
-
459
- /**
460
- * Retrieves a list of tools for a specific MCP server.
461
- * @param serverId - The ID of the MCP server.
462
- * @returns Promise containing the list of tools.
463
- */
464
- public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
465
- return this.request(`/api/mcp/${serverId}/tools`);
466
- }
467
-
468
- /**
469
- * Gets an MCPTool resource instance for a specific tool on an MCP server.
470
- * This instance can then be used to fetch details or execute the tool.
471
- * @param serverId - The ID of the MCP server.
472
- * @param toolId - The ID of the tool.
473
- * @returns MCPTool instance.
474
- */
475
- public getMcpServerTool(serverId: string, toolId: string): MCPTool {
476
- return new MCPTool(this.options, serverId, toolId);
477
- }
478
-
479
- /**
480
- * Gets an A2A client for interacting with an agent via the A2A protocol
481
- * @param agentId - ID of the agent to interact with
482
- * @returns A2A client instance
483
- */
484
- public getA2A(agentId: string) {
485
- return new A2A(this.options, agentId);
486
- }
487
-
488
- /**
489
- * Retrieves the working memory for a specific thread (optionally resource-scoped).
490
- * @param agentId - ID of the agent.
491
- * @param threadId - ID of the thread.
492
- * @param resourceId - Optional ID of the resource.
493
- * @returns Working memory for the specified thread or resource.
494
- */
495
- public getWorkingMemory({
496
- agentId,
497
- threadId,
498
- resourceId,
499
- }: {
500
- agentId: string;
501
- threadId: string;
502
- resourceId?: string;
503
- }) {
504
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
505
- }
506
-
507
- /**
508
- * Updates the working memory for a specific thread (optionally resource-scoped).
509
- * @param agentId - ID of the agent.
510
- * @param threadId - ID of the thread.
511
- * @param workingMemory - The new working memory content.
512
- * @param resourceId - Optional ID of the resource.
513
- */
514
- public updateWorkingMemory({
515
- agentId,
516
- threadId,
517
- workingMemory,
518
- resourceId,
519
- }: {
520
- agentId: string;
521
- threadId: string;
522
- workingMemory: string;
523
- resourceId?: string;
524
- }) {
525
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
526
- method: 'POST',
527
- body: {
528
- workingMemory,
529
- resourceId,
530
- },
531
- });
532
- }
533
-
534
- /**
535
- * Retrieves all available scorers
536
- * @returns Promise containing list of available scorers
537
- */
538
- public getScorers(): Promise<Record<string, GetScorerResponse>> {
539
- return this.request('/api/scores/scorers');
540
- }
541
-
542
- /**
543
- * Retrieves a scorer by ID
544
- * @param scorerId - ID of the scorer to retrieve
545
- * @returns Promise containing the scorer
546
- */
547
- public getScorer(scorerId: string): Promise<GetScorerResponse> {
548
- return this.request(`/api/scores/scorers/${scorerId}`);
549
- }
550
-
551
- public getScoresByScorerId(params: GetScoresByScorerIdParams): Promise<GetScoresResponse> {
552
- const { page, perPage, scorerId, entityId, entityType } = params;
553
- const searchParams = new URLSearchParams();
554
-
555
- if (entityId) {
556
- searchParams.set('entityId', entityId);
557
- }
558
- if (entityType) {
559
- searchParams.set('entityType', entityType);
560
- }
561
-
562
- if (page !== undefined) {
563
- searchParams.set('page', String(page));
564
- }
565
- if (perPage !== undefined) {
566
- searchParams.set('perPage', String(perPage));
567
- }
568
- const queryString = searchParams.toString();
569
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ''}`);
570
- }
571
-
572
- /**
573
- * Retrieves scores by run ID
574
- * @param params - Parameters containing run ID and pagination options
575
- * @returns Promise containing scores and pagination info
576
- */
577
- public getScoresByRunId(params: GetScoresByRunIdParams): Promise<GetScoresResponse> {
578
- const { runId, page, perPage } = params;
579
- const searchParams = new URLSearchParams();
580
-
581
- if (page !== undefined) {
582
- searchParams.set('page', String(page));
583
- }
584
- if (perPage !== undefined) {
585
- searchParams.set('perPage', String(perPage));
586
- }
587
-
588
- const queryString = searchParams.toString();
589
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ''}`);
590
- }
591
-
592
- /**
593
- * Retrieves scores by entity ID and type
594
- * @param params - Parameters containing entity ID, type, and pagination options
595
- * @returns Promise containing scores and pagination info
596
- */
597
- public getScoresByEntityId(params: GetScoresByEntityIdParams): Promise<GetScoresResponse> {
598
- const { entityId, entityType, page, perPage } = params;
599
- const searchParams = new URLSearchParams();
600
-
601
- if (page !== undefined) {
602
- searchParams.set('page', String(page));
603
- }
604
- if (perPage !== undefined) {
605
- searchParams.set('perPage', String(perPage));
606
- }
607
-
608
- const queryString = searchParams.toString();
609
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ''}`);
610
- }
611
-
612
- /**
613
- * Saves a score
614
- * @param params - Parameters containing the score data to save
615
- * @returns Promise containing the saved score
616
- */
617
- public saveScore(params: SaveScoreParams): Promise<SaveScoreResponse> {
618
- return this.request('/api/scores', {
619
- method: 'POST',
620
- body: params,
621
- });
622
- }
623
- }
package/src/example.ts DELETED
@@ -1,95 +0,0 @@
1
- import { MastraClient } from './client';
2
- import z from 'zod';
3
- // import type { WorkflowRunResult } from './types';
4
-
5
- // Agent
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
- output: z.object({
18
- weather: z.string(),
19
- temperature: z.number(),
20
- humidity: z.number(),
21
- windSpeed: z.number(),
22
- windDirection: z.string(),
23
- windGust: z.number(),
24
- windChill: z.number(),
25
- }),
26
- });
27
-
28
- // Process data stream - unstructured output
29
-
30
- // response.processDataStream({
31
- // onTextPart: text => {
32
- // process.stdout.write(text);
33
- // },
34
- // onFilePart: file => {
35
- // console.log(file);
36
- // },
37
- // onDataPart: data => {
38
- // console.log(data);
39
- // },
40
- // onErrorPart: error => {
41
- // console.error(error);
42
- // },
43
- // onToolCallPart(streamPart) {
44
- // console.log(streamPart);
45
- // },
46
- // });
47
-
48
- // Process text stream - structured output
49
-
50
- // response.processTextStream({
51
- // onTextPart: text => {
52
- // process.stdout.write(text);
53
- // },
54
- // });
55
-
56
- // read the response body directly
57
-
58
- // const reader = response.body!.getReader();
59
- // while (true) {
60
- // const { done, value } = await reader.read();
61
- // if (done) break;
62
- // console.log(new TextDecoder().decode(value));
63
- // }
64
- } catch (error) {
65
- console.error(error);
66
- }
67
- })();
68
-
69
- // Workflow
70
- // (async () => {
71
- // const client = new MastraClient({
72
- // baseUrl: 'http://localhost:4111',
73
- // });
74
-
75
- // try {
76
- // const workflowId = 'myWorkflow';
77
- // const workflow = client.getWorkflow(workflowId);
78
-
79
- // const { runId } = await workflow.createRun();
80
-
81
- // workflow.watch({ runId }, record => {
82
- // console.log(new Date().toTimeString(), record);
83
- // });
84
-
85
- // await workflow.start({
86
- // runId,
87
- // triggerData: {
88
- // city: 'New York',
89
- // },
90
- // });
91
-
92
- // } catch (e) {
93
- // console.error('Workflow error:', e);
94
- // }
95
- // })();