@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 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.
- package/CHANGELOG.md +1110 -2
- package/LICENSE.md +11 -42
- package/README.md +2 -1
- package/dist/adapters/agui.d.ts +23 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +265 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +1403 -131
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -730
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1401 -133
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +44 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +112 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +422 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +18 -0
- package/integration-tests/src/mastra/index.ts +35 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +28 -19
- package/src/adapters/agui.test.ts +164 -9
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +386 -22
- package/src/example.ts +59 -29
- package/src/index.test.ts +522 -6
- package/src/index.ts +1 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +629 -48
- package/src/resources/base.ts +7 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +49 -3
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +81 -0
- package/src/resources/network.ts +10 -16
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +255 -96
- package/src/types.ts +265 -25
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/index.d.cts +0 -730
package/src/client.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
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 {
|
|
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';
|
|
4
18
|
import type {
|
|
5
19
|
ClientOptions,
|
|
6
20
|
CreateMemoryThreadParams,
|
|
@@ -15,10 +29,23 @@ import type {
|
|
|
15
29
|
GetTelemetryParams,
|
|
16
30
|
GetTelemetryResponse,
|
|
17
31
|
GetToolResponse,
|
|
18
|
-
GetVNextWorkflowResponse,
|
|
19
32
|
GetWorkflowResponse,
|
|
20
33
|
SaveMessageToMemoryParams,
|
|
21
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,
|
|
22
49
|
} from './types';
|
|
23
50
|
|
|
24
51
|
export class MastraClient extends BaseResource {
|
|
@@ -109,6 +136,53 @@ export class MastraClient extends BaseResource {
|
|
|
109
136
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
110
137
|
}
|
|
111
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
|
+
|
|
112
186
|
/**
|
|
113
187
|
* Retrieves all available tools
|
|
114
188
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -126,6 +200,23 @@ export class MastraClient extends BaseResource {
|
|
|
126
200
|
return new Tool(this.options, toolId);
|
|
127
201
|
}
|
|
128
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
|
+
|
|
129
220
|
/**
|
|
130
221
|
* Retrieves all available workflows
|
|
131
222
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -143,23 +234,6 @@ export class MastraClient extends BaseResource {
|
|
|
143
234
|
return new Workflow(this.options, workflowId);
|
|
144
235
|
}
|
|
145
236
|
|
|
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
237
|
/**
|
|
164
238
|
* Gets a vector instance by name
|
|
165
239
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -175,7 +249,43 @@ export class MastraClient extends BaseResource {
|
|
|
175
249
|
* @returns Promise containing array of log messages
|
|
176
250
|
*/
|
|
177
251
|
public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
|
|
178
|
-
|
|
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
|
+
}
|
|
179
289
|
}
|
|
180
290
|
|
|
181
291
|
/**
|
|
@@ -184,7 +294,47 @@ export class MastraClient extends BaseResource {
|
|
|
184
294
|
* @returns Promise containing array of log messages
|
|
185
295
|
*/
|
|
186
296
|
public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
|
|
187
|
-
|
|
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
|
+
}
|
|
188
338
|
}
|
|
189
339
|
|
|
190
340
|
/**
|
|
@@ -244,10 +394,18 @@ export class MastraClient extends BaseResource {
|
|
|
244
394
|
* Retrieves all available networks
|
|
245
395
|
* @returns Promise containing map of network IDs to network details
|
|
246
396
|
*/
|
|
247
|
-
public getNetworks(): Promise<
|
|
397
|
+
public getNetworks(): Promise<Array<GetNetworkResponse>> {
|
|
248
398
|
return this.request('/api/networks');
|
|
249
399
|
}
|
|
250
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
|
+
|
|
251
409
|
/**
|
|
252
410
|
* Gets a network instance by ID
|
|
253
411
|
* @param networkId - ID of the network to retrieve
|
|
@@ -256,4 +414,210 @@ export class MastraClient extends BaseResource {
|
|
|
256
414
|
public getNetwork(networkId: string) {
|
|
257
415
|
return new Network(this.options, networkId);
|
|
258
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
|
+
}
|
|
259
623
|
}
|
package/src/example.ts
CHANGED
|
@@ -1,40 +1,70 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
7
|
-
// const client = new MastraClient({
|
|
8
|
-
// baseUrl: 'http://localhost:4111',
|
|
9
|
-
// });
|
|
11
|
+
console.log('Starting agent...');
|
|
10
12
|
|
|
11
|
-
|
|
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
|
+
});
|
|
12
27
|
|
|
13
|
-
//
|
|
14
|
-
// const agent = client.getAgent('weatherAgent');
|
|
15
|
-
// const response = await agent.stream({
|
|
16
|
-
// messages: 'what is the weather in new york?',
|
|
17
|
-
// })
|
|
28
|
+
// Process data stream - unstructured output
|
|
18
29
|
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
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
|
+
// });
|
|
33
47
|
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
//
|
|
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
|
+
})();
|
|
38
68
|
|
|
39
69
|
// Workflow
|
|
40
70
|
// (async () => {
|