@mastra/client-js 0.0.0-switch-to-core-20250424015131 → 0.0.0-taofeeq-fix-tool-call-showing-after-message-20250806184630
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/.turbo/turbo-build.log +18 -0
- package/CHANGELOG.md +1356 -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 +1785 -82
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -585
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1785 -86
- 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 +32 -19
- package/src/adapters/agui.test.ts +322 -0
- package/src/adapters/agui.ts +257 -0
- package/src/client.ts +414 -5
- package/src/example.ts +59 -29
- package/src/index.test.ts +526 -10
- package/src/index.ts +1 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +629 -49
- package/src/resources/base.ts +8 -2
- package/src/resources/index.ts +4 -1
- package/src/resources/legacy-workflow.ts +242 -0
- 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 +11 -17
- package/src/resources/tool.ts +16 -3
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +289 -94
- package/src/types.ts +298 -20
- 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 +17 -0
- package/dist/index.d.cts +0 -585
package/src/client.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
2
18
|
import type {
|
|
3
19
|
ClientOptions,
|
|
4
20
|
CreateMemoryThreadParams,
|
|
@@ -16,6 +32,20 @@ import type {
|
|
|
16
32
|
GetWorkflowResponse,
|
|
17
33
|
SaveMessageToMemoryParams,
|
|
18
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,
|
|
19
49
|
} from './types';
|
|
20
50
|
|
|
21
51
|
export class MastraClient extends BaseResource {
|
|
@@ -31,6 +61,25 @@ export class MastraClient extends BaseResource {
|
|
|
31
61
|
return this.request('/api/agents');
|
|
32
62
|
}
|
|
33
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
|
+
|
|
34
83
|
/**
|
|
35
84
|
* Gets an agent instance by ID
|
|
36
85
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -87,6 +136,53 @@ export class MastraClient extends BaseResource {
|
|
|
87
136
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
88
137
|
}
|
|
89
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
|
+
|
|
90
186
|
/**
|
|
91
187
|
* Retrieves all available tools
|
|
92
188
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -104,6 +200,23 @@ export class MastraClient extends BaseResource {
|
|
|
104
200
|
return new Tool(this.options, toolId);
|
|
105
201
|
}
|
|
106
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
|
+
|
|
107
220
|
/**
|
|
108
221
|
* Retrieves all available workflows
|
|
109
222
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -136,7 +249,43 @@ export class MastraClient extends BaseResource {
|
|
|
136
249
|
* @returns Promise containing array of log messages
|
|
137
250
|
*/
|
|
138
251
|
public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
|
|
139
|
-
|
|
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
|
+
}
|
|
140
289
|
}
|
|
141
290
|
|
|
142
291
|
/**
|
|
@@ -145,7 +294,47 @@ export class MastraClient extends BaseResource {
|
|
|
145
294
|
* @returns Promise containing array of log messages
|
|
146
295
|
*/
|
|
147
296
|
public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
|
|
148
|
-
|
|
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
|
+
}
|
|
149
338
|
}
|
|
150
339
|
|
|
151
340
|
/**
|
|
@@ -162,7 +351,7 @@ export class MastraClient extends BaseResource {
|
|
|
162
351
|
* @returns Promise containing telemetry data
|
|
163
352
|
*/
|
|
164
353
|
public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
|
|
165
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
354
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
166
355
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
167
356
|
|
|
168
357
|
const searchParams = new URLSearchParams();
|
|
@@ -187,6 +376,12 @@ export class MastraClient extends BaseResource {
|
|
|
187
376
|
searchParams.set('attribute', _attribute);
|
|
188
377
|
}
|
|
189
378
|
}
|
|
379
|
+
if (fromDate) {
|
|
380
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
381
|
+
}
|
|
382
|
+
if (toDate) {
|
|
383
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
384
|
+
}
|
|
190
385
|
|
|
191
386
|
if (searchParams.size) {
|
|
192
387
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
@@ -199,10 +394,18 @@ export class MastraClient extends BaseResource {
|
|
|
199
394
|
* Retrieves all available networks
|
|
200
395
|
* @returns Promise containing map of network IDs to network details
|
|
201
396
|
*/
|
|
202
|
-
public getNetworks(): Promise<
|
|
397
|
+
public getNetworks(): Promise<Array<GetNetworkResponse>> {
|
|
203
398
|
return this.request('/api/networks');
|
|
204
399
|
}
|
|
205
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
|
+
|
|
206
409
|
/**
|
|
207
410
|
* Gets a network instance by ID
|
|
208
411
|
* @param networkId - ID of the network to retrieve
|
|
@@ -211,4 +414,210 @@ export class MastraClient extends BaseResource {
|
|
|
211
414
|
public getNetwork(networkId: string) {
|
|
212
415
|
return new Network(this.options, networkId);
|
|
213
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
|
+
}
|
|
214
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 () => {
|