@mastra/client-js 0.0.0-separate-trace-data-from-component-20250501042644 → 0.0.0-share-agent-metadata-with-cloud-20250718110128
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 +19 -0
- package/CHANGELOG.md +924 -2
- package/LICENSE.md +11 -42
- package/README.md +1 -1
- package/dist/index.cjs +1501 -121
- package/dist/index.d.cts +566 -87
- package/dist/index.d.ts +566 -87
- package/dist/index.js +1508 -132
- package/package.json +24 -16
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +317 -23
- package/src/example.ts +59 -29
- package/src/index.test.ts +132 -6
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +648 -52
- package/src/resources/base.ts +3 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +140 -132
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +6 -13
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +273 -95
- package/src/types.ts +199 -23
- 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/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,
|
|
@@ -13,10 +29,16 @@ import type {
|
|
|
13
29
|
GetTelemetryParams,
|
|
14
30
|
GetTelemetryResponse,
|
|
15
31
|
GetToolResponse,
|
|
16
|
-
GetVNextWorkflowResponse,
|
|
17
32
|
GetWorkflowResponse,
|
|
18
33
|
SaveMessageToMemoryParams,
|
|
19
34
|
SaveMessageToMemoryResponse,
|
|
35
|
+
McpServerListResponse,
|
|
36
|
+
McpServerToolListResponse,
|
|
37
|
+
GetLegacyWorkflowResponse,
|
|
38
|
+
GetVNextNetworkResponse,
|
|
39
|
+
GetNetworkMemoryThreadParams,
|
|
40
|
+
CreateNetworkMemoryThreadParams,
|
|
41
|
+
SaveNetworkMessageToMemoryParams,
|
|
20
42
|
} from './types';
|
|
21
43
|
|
|
22
44
|
export class MastraClient extends BaseResource {
|
|
@@ -32,6 +54,25 @@ export class MastraClient extends BaseResource {
|
|
|
32
54
|
return this.request('/api/agents');
|
|
33
55
|
}
|
|
34
56
|
|
|
57
|
+
public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
|
|
58
|
+
const agents = await this.getAgents();
|
|
59
|
+
|
|
60
|
+
return Object.entries(agents).reduce(
|
|
61
|
+
(acc, [agentId]) => {
|
|
62
|
+
const agent = this.getAgent(agentId);
|
|
63
|
+
|
|
64
|
+
acc[agentId] = new AGUIAdapter({
|
|
65
|
+
agentId,
|
|
66
|
+
agent,
|
|
67
|
+
resourceId,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return acc;
|
|
71
|
+
},
|
|
72
|
+
{} as Record<string, AbstractAgent>,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
35
76
|
/**
|
|
36
77
|
* Gets an agent instance by ID
|
|
37
78
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -88,6 +129,53 @@ export class MastraClient extends BaseResource {
|
|
|
88
129
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
89
130
|
}
|
|
90
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves memory threads for a resource
|
|
134
|
+
* @param params - Parameters containing the resource ID
|
|
135
|
+
* @returns Promise containing array of memory threads
|
|
136
|
+
*/
|
|
137
|
+
public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
|
|
138
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a new memory thread
|
|
143
|
+
* @param params - Parameters for creating the memory thread
|
|
144
|
+
* @returns Promise containing the created memory thread
|
|
145
|
+
*/
|
|
146
|
+
public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
|
|
147
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Gets a memory thread instance by ID
|
|
152
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
153
|
+
* @returns MemoryThread instance
|
|
154
|
+
*/
|
|
155
|
+
public getNetworkMemoryThread(threadId: string, networkId: string) {
|
|
156
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Saves messages to memory
|
|
161
|
+
* @param params - Parameters containing messages to save
|
|
162
|
+
* @returns Promise containing the saved messages
|
|
163
|
+
*/
|
|
164
|
+
public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
|
|
165
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
body: params,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets the status of the memory system
|
|
173
|
+
* @returns Promise containing memory system status
|
|
174
|
+
*/
|
|
175
|
+
public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
|
|
176
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
91
179
|
/**
|
|
92
180
|
* Retrieves all available tools
|
|
93
181
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -105,6 +193,23 @@ export class MastraClient extends BaseResource {
|
|
|
105
193
|
return new Tool(this.options, toolId);
|
|
106
194
|
}
|
|
107
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves all available legacy workflows
|
|
198
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
199
|
+
*/
|
|
200
|
+
public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
|
|
201
|
+
return this.request('/api/workflows/legacy');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Gets a legacy workflow instance by ID
|
|
206
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
207
|
+
* @returns Legacy Workflow instance
|
|
208
|
+
*/
|
|
209
|
+
public getLegacyWorkflow(workflowId: string) {
|
|
210
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
211
|
+
}
|
|
212
|
+
|
|
108
213
|
/**
|
|
109
214
|
* Retrieves all available workflows
|
|
110
215
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -122,23 +227,6 @@ export class MastraClient extends BaseResource {
|
|
|
122
227
|
return new Workflow(this.options, workflowId);
|
|
123
228
|
}
|
|
124
229
|
|
|
125
|
-
/**
|
|
126
|
-
* Retrieves all available vNext workflows
|
|
127
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
128
|
-
*/
|
|
129
|
-
public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
|
|
130
|
-
return this.request('/api/workflows/v-next');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Gets a vNext workflow instance by ID
|
|
135
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
136
|
-
* @returns vNext Workflow instance
|
|
137
|
-
*/
|
|
138
|
-
public getVNextWorkflow(workflowId: string) {
|
|
139
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
230
|
/**
|
|
143
231
|
* Gets a vector instance by name
|
|
144
232
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -154,7 +242,43 @@ export class MastraClient extends BaseResource {
|
|
|
154
242
|
* @returns Promise containing array of log messages
|
|
155
243
|
*/
|
|
156
244
|
public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
|
|
157
|
-
|
|
245
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
246
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
247
|
+
|
|
248
|
+
const searchParams = new URLSearchParams();
|
|
249
|
+
if (transportId) {
|
|
250
|
+
searchParams.set('transportId', transportId);
|
|
251
|
+
}
|
|
252
|
+
if (fromDate) {
|
|
253
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
254
|
+
}
|
|
255
|
+
if (toDate) {
|
|
256
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
257
|
+
}
|
|
258
|
+
if (logLevel) {
|
|
259
|
+
searchParams.set('logLevel', logLevel);
|
|
260
|
+
}
|
|
261
|
+
if (page) {
|
|
262
|
+
searchParams.set('page', String(page));
|
|
263
|
+
}
|
|
264
|
+
if (perPage) {
|
|
265
|
+
searchParams.set('perPage', String(perPage));
|
|
266
|
+
}
|
|
267
|
+
if (_filters) {
|
|
268
|
+
if (Array.isArray(_filters)) {
|
|
269
|
+
for (const filter of _filters) {
|
|
270
|
+
searchParams.append('filters', filter);
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
searchParams.set('filters', _filters);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (searchParams.size) {
|
|
278
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
279
|
+
} else {
|
|
280
|
+
return this.request(`/api/logs`);
|
|
281
|
+
}
|
|
158
282
|
}
|
|
159
283
|
|
|
160
284
|
/**
|
|
@@ -163,7 +287,47 @@ export class MastraClient extends BaseResource {
|
|
|
163
287
|
* @returns Promise containing array of log messages
|
|
164
288
|
*/
|
|
165
289
|
public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
|
|
166
|
-
|
|
290
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
291
|
+
|
|
292
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
293
|
+
const searchParams = new URLSearchParams();
|
|
294
|
+
if (runId) {
|
|
295
|
+
searchParams.set('runId', runId);
|
|
296
|
+
}
|
|
297
|
+
if (transportId) {
|
|
298
|
+
searchParams.set('transportId', transportId);
|
|
299
|
+
}
|
|
300
|
+
if (fromDate) {
|
|
301
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
302
|
+
}
|
|
303
|
+
if (toDate) {
|
|
304
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
305
|
+
}
|
|
306
|
+
if (logLevel) {
|
|
307
|
+
searchParams.set('logLevel', logLevel);
|
|
308
|
+
}
|
|
309
|
+
if (page) {
|
|
310
|
+
searchParams.set('page', String(page));
|
|
311
|
+
}
|
|
312
|
+
if (perPage) {
|
|
313
|
+
searchParams.set('perPage', String(perPage));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (_filters) {
|
|
317
|
+
if (Array.isArray(_filters)) {
|
|
318
|
+
for (const filter of _filters) {
|
|
319
|
+
searchParams.append('filters', filter);
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
searchParams.set('filters', _filters);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (searchParams.size) {
|
|
327
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
328
|
+
} else {
|
|
329
|
+
return this.request(`/api/logs/${runId}`);
|
|
330
|
+
}
|
|
167
331
|
}
|
|
168
332
|
|
|
169
333
|
/**
|
|
@@ -180,7 +344,7 @@ export class MastraClient extends BaseResource {
|
|
|
180
344
|
* @returns Promise containing telemetry data
|
|
181
345
|
*/
|
|
182
346
|
public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
|
|
183
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
347
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
184
348
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
185
349
|
|
|
186
350
|
const searchParams = new URLSearchParams();
|
|
@@ -205,6 +369,12 @@ export class MastraClient extends BaseResource {
|
|
|
205
369
|
searchParams.set('attribute', _attribute);
|
|
206
370
|
}
|
|
207
371
|
}
|
|
372
|
+
if (fromDate) {
|
|
373
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
374
|
+
}
|
|
375
|
+
if (toDate) {
|
|
376
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
377
|
+
}
|
|
208
378
|
|
|
209
379
|
if (searchParams.size) {
|
|
210
380
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
@@ -217,10 +387,18 @@ export class MastraClient extends BaseResource {
|
|
|
217
387
|
* Retrieves all available networks
|
|
218
388
|
* @returns Promise containing map of network IDs to network details
|
|
219
389
|
*/
|
|
220
|
-
public getNetworks(): Promise<
|
|
390
|
+
public getNetworks(): Promise<Array<GetNetworkResponse>> {
|
|
221
391
|
return this.request('/api/networks');
|
|
222
392
|
}
|
|
223
393
|
|
|
394
|
+
/**
|
|
395
|
+
* Retrieves all available vNext networks
|
|
396
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
397
|
+
*/
|
|
398
|
+
public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
|
|
399
|
+
return this.request('/api/networks/v-next');
|
|
400
|
+
}
|
|
401
|
+
|
|
224
402
|
/**
|
|
225
403
|
* Gets a network instance by ID
|
|
226
404
|
* @param networkId - ID of the network to retrieve
|
|
@@ -229,4 +407,120 @@ export class MastraClient extends BaseResource {
|
|
|
229
407
|
public getNetwork(networkId: string) {
|
|
230
408
|
return new Network(this.options, networkId);
|
|
231
409
|
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Gets a vNext network instance by ID
|
|
413
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
414
|
+
* @returns vNext Network instance
|
|
415
|
+
*/
|
|
416
|
+
public getVNextNetwork(networkId: string) {
|
|
417
|
+
return new VNextNetwork(this.options, networkId);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Retrieves a list of available MCP servers.
|
|
422
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
423
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
424
|
+
*/
|
|
425
|
+
public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
|
|
426
|
+
const searchParams = new URLSearchParams();
|
|
427
|
+
if (params?.limit !== undefined) {
|
|
428
|
+
searchParams.set('limit', String(params.limit));
|
|
429
|
+
}
|
|
430
|
+
if (params?.offset !== undefined) {
|
|
431
|
+
searchParams.set('offset', String(params.offset));
|
|
432
|
+
}
|
|
433
|
+
const queryString = searchParams.toString();
|
|
434
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Retrieves detailed information for a specific MCP server.
|
|
439
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
440
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
441
|
+
* @returns Promise containing the detailed MCP server information.
|
|
442
|
+
*/
|
|
443
|
+
public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
|
|
444
|
+
const searchParams = new URLSearchParams();
|
|
445
|
+
if (params?.version) {
|
|
446
|
+
searchParams.set('version', params.version);
|
|
447
|
+
}
|
|
448
|
+
const queryString = searchParams.toString();
|
|
449
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
454
|
+
* @param serverId - The ID of the MCP server.
|
|
455
|
+
* @returns Promise containing the list of tools.
|
|
456
|
+
*/
|
|
457
|
+
public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
|
|
458
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
463
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
464
|
+
* @param serverId - The ID of the MCP server.
|
|
465
|
+
* @param toolId - The ID of the tool.
|
|
466
|
+
* @returns MCPTool instance.
|
|
467
|
+
*/
|
|
468
|
+
public getMcpServerTool(serverId: string, toolId: string): MCPTool {
|
|
469
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
474
|
+
* @param agentId - ID of the agent to interact with
|
|
475
|
+
* @returns A2A client instance
|
|
476
|
+
*/
|
|
477
|
+
public getA2A(agentId: string) {
|
|
478
|
+
return new A2A(this.options, agentId);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
483
|
+
* @param agentId - ID of the agent.
|
|
484
|
+
* @param threadId - ID of the thread.
|
|
485
|
+
* @param resourceId - Optional ID of the resource.
|
|
486
|
+
* @returns Working memory for the specified thread or resource.
|
|
487
|
+
*/
|
|
488
|
+
public getWorkingMemory({
|
|
489
|
+
agentId,
|
|
490
|
+
threadId,
|
|
491
|
+
resourceId,
|
|
492
|
+
}: {
|
|
493
|
+
agentId: string;
|
|
494
|
+
threadId: string;
|
|
495
|
+
resourceId?: string;
|
|
496
|
+
}) {
|
|
497
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
502
|
+
* @param agentId - ID of the agent.
|
|
503
|
+
* @param threadId - ID of the thread.
|
|
504
|
+
* @param workingMemory - The new working memory content.
|
|
505
|
+
* @param resourceId - Optional ID of the resource.
|
|
506
|
+
*/
|
|
507
|
+
public updateWorkingMemory({
|
|
508
|
+
agentId,
|
|
509
|
+
threadId,
|
|
510
|
+
workingMemory,
|
|
511
|
+
resourceId,
|
|
512
|
+
}: {
|
|
513
|
+
agentId: string;
|
|
514
|
+
threadId: string;
|
|
515
|
+
workingMemory: string;
|
|
516
|
+
resourceId?: string;
|
|
517
|
+
}) {
|
|
518
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
519
|
+
method: 'POST',
|
|
520
|
+
body: {
|
|
521
|
+
workingMemory,
|
|
522
|
+
resourceId,
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
}
|
|
232
526
|
}
|
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 () => {
|