@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-vector-sources-20250516175436

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { AbstractAgent, EventType } from '@ag-ui/client';
2
2
  import { Observable } from 'rxjs';
3
3
  import { processDataStream } from '@ai-sdk/ui-utils';
4
4
  import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from 'zod-to-json-schema';
5
+ import originalZodToJsonSchema from 'zod-to-json-schema';
6
6
 
7
7
  // src/adapters/agui.ts
8
8
  var AGUIAdapter = class extends AbstractAgent {
@@ -42,6 +42,7 @@ var AGUIAdapter = class extends AbstractAgent {
42
42
  )
43
43
  }).then((response) => {
44
44
  let currentMessageId = void 0;
45
+ let isInTextMessage = false;
45
46
  return response.processDataStream({
46
47
  onTextPart: (text) => {
47
48
  if (currentMessageId === void 0) {
@@ -52,6 +53,7 @@ var AGUIAdapter = class extends AbstractAgent {
52
53
  role: "assistant"
53
54
  };
54
55
  subscriber.next(message2);
56
+ isInTextMessage = true;
55
57
  }
56
58
  const message = {
57
59
  type: EventType.TEXT_MESSAGE_CONTENT,
@@ -60,14 +62,14 @@ var AGUIAdapter = class extends AbstractAgent {
60
62
  };
61
63
  subscriber.next(message);
62
64
  },
63
- onFinishMessagePart: (message) => {
64
- console.log("onFinishMessagePart", message);
65
+ onFinishMessagePart: () => {
65
66
  if (currentMessageId !== void 0) {
66
- const message2 = {
67
+ const message = {
67
68
  type: EventType.TEXT_MESSAGE_END,
68
69
  messageId: currentMessageId
69
70
  };
70
- subscriber.next(message2);
71
+ subscriber.next(message);
72
+ isInTextMessage = false;
71
73
  }
72
74
  subscriber.next({
73
75
  type: EventType.RUN_FINISHED,
@@ -78,6 +80,14 @@ var AGUIAdapter = class extends AbstractAgent {
78
80
  },
79
81
  onToolCallPart(streamPart) {
80
82
  const parentMessageId = currentMessageId || generateUUID();
83
+ if (isInTextMessage) {
84
+ const message = {
85
+ type: EventType.TEXT_MESSAGE_END,
86
+ messageId: parentMessageId
87
+ };
88
+ subscriber.next(message);
89
+ isInTextMessage = false;
90
+ }
81
91
  subscriber.next({
82
92
  type: EventType.TOOL_CALL_START,
83
93
  toolCallId: streamPart.toolCallId,
@@ -98,7 +108,7 @@ var AGUIAdapter = class extends AbstractAgent {
98
108
  }
99
109
  });
100
110
  }).catch((error) => {
101
- console.log("error", error);
111
+ console.error("error", error);
102
112
  subscriber.error(error);
103
113
  });
104
114
  return () => {
@@ -147,6 +157,17 @@ function convertMessagesToMastraMessages(messages) {
147
157
  role: "assistant",
148
158
  content: parts
149
159
  });
160
+ if (message.toolCalls?.length) {
161
+ result.push({
162
+ role: "tool",
163
+ content: message.toolCalls.map((toolCall) => ({
164
+ type: "tool-result",
165
+ toolCallId: toolCall.id,
166
+ toolName: toolCall.function.name,
167
+ result: JSON.parse(toolCall.function.arguments)
168
+ }))
169
+ });
170
+ }
150
171
  } else if (message.role === "user") {
151
172
  result.push({
152
173
  role: "user",
@@ -168,6 +189,12 @@ function convertMessagesToMastraMessages(messages) {
168
189
  }
169
190
  return result;
170
191
  }
192
+ function zodToJsonSchema(zodSchema) {
193
+ if (!(zodSchema instanceof ZodSchema)) {
194
+ return zodSchema;
195
+ }
196
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
197
+ }
171
198
 
172
199
  // src/resources/base.ts
173
200
  var BaseResource = class {
@@ -187,7 +214,7 @@ var BaseResource = class {
187
214
  let delay = backoffMs;
188
215
  for (let attempt = 0; attempt <= retries; attempt++) {
189
216
  try {
190
- const response = await fetch(`${baseUrl}${path}`, {
217
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
191
218
  ...options,
192
219
  headers: {
193
220
  ...headers,
@@ -298,8 +325,9 @@ var Agent = class extends BaseResource {
298
325
  generate(params) {
299
326
  const processedParams = {
300
327
  ...params,
301
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
302
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
328
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
329
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
330
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
303
331
  };
304
332
  return this.request(`/api/agents/${this.agentId}/generate`, {
305
333
  method: "POST",
@@ -314,8 +342,9 @@ var Agent = class extends BaseResource {
314
342
  async stream(params) {
315
343
  const processedParams = {
316
344
  ...params,
317
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
318
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
345
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
346
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
347
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
319
348
  };
320
349
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
321
350
  method: "POST",
@@ -341,6 +370,22 @@ var Agent = class extends BaseResource {
341
370
  getTool(toolId) {
342
371
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
343
372
  }
373
+ /**
374
+ * Executes a tool for the agent
375
+ * @param toolId - ID of the tool to execute
376
+ * @param params - Parameters required for tool execution
377
+ * @returns Promise containing the tool execution results
378
+ */
379
+ executeTool(toolId, params) {
380
+ const body = {
381
+ data: params.data,
382
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
383
+ };
384
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
385
+ method: "POST",
386
+ body
387
+ });
388
+ }
344
389
  /**
345
390
  * Retrieves evaluation results for the agent
346
391
  * @returns Promise containing agent evaluations
@@ -376,8 +421,8 @@ var Network = class extends BaseResource {
376
421
  generate(params) {
377
422
  const processedParams = {
378
423
  ...params,
379
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
380
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
424
+ output: zodToJsonSchema(params.output),
425
+ experimental_output: zodToJsonSchema(params.experimental_output)
381
426
  };
382
427
  return this.request(`/api/networks/${this.networkId}/generate`, {
383
428
  method: "POST",
@@ -392,8 +437,8 @@ var Network = class extends BaseResource {
392
437
  async stream(params) {
393
438
  const processedParams = {
394
439
  ...params,
395
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
396
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
440
+ output: zodToJsonSchema(params.output),
441
+ experimental_output: zodToJsonSchema(params.experimental_output)
397
442
  };
398
443
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
399
444
  method: "POST",
@@ -449,10 +494,15 @@ var MemoryThread = class extends BaseResource {
449
494
  }
450
495
  /**
451
496
  * Retrieves messages associated with the thread
497
+ * @param params - Optional parameters including limit for number of messages to retrieve
452
498
  * @returns Promise containing thread messages and UI messages
453
499
  */
454
- getMessages() {
455
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
500
+ getMessages(params) {
501
+ const query = new URLSearchParams({
502
+ agentId: this.agentId,
503
+ ...params?.limit ? { limit: params.limit.toString() } : {}
504
+ });
505
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
456
506
  }
457
507
  };
458
508
 
@@ -738,9 +788,13 @@ var Tool = class extends BaseResource {
738
788
  if (params.runId) {
739
789
  url.set("runId", params.runId);
740
790
  }
791
+ const body = {
792
+ data: params.data,
793
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
794
+ };
741
795
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
742
796
  method: "POST",
743
- body: params.data
797
+ body
744
798
  });
745
799
  }
746
800
  };
@@ -852,9 +906,10 @@ var VNextWorkflow = class extends BaseResource {
852
906
  * @returns Promise containing success message
853
907
  */
854
908
  start(params) {
909
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
855
910
  return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
856
911
  method: "POST",
857
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
912
+ body: { inputData: params?.inputData, runtimeContext }
858
913
  });
859
914
  }
860
915
  /**
@@ -866,8 +921,9 @@ var VNextWorkflow = class extends BaseResource {
866
921
  step,
867
922
  runId,
868
923
  resumeData,
869
- runtimeContext
924
+ ...rest
870
925
  }) {
926
+ const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : void 0;
871
927
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
872
928
  method: "POST",
873
929
  stream: true,
@@ -888,9 +944,10 @@ var VNextWorkflow = class extends BaseResource {
888
944
  if (!!params?.runId) {
889
945
  searchParams.set("runId", params.runId);
890
946
  }
947
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
891
948
  return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
892
949
  method: "POST",
893
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
950
+ body: { inputData: params.inputData, runtimeContext }
894
951
  });
895
952
  }
896
953
  /**
@@ -899,12 +956,13 @@ var VNextWorkflow = class extends BaseResource {
899
956
  * @returns Promise containing the vNext workflow resume results
900
957
  */
901
958
  resumeAsync(params) {
959
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
902
960
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
903
961
  method: "POST",
904
962
  body: {
905
963
  step: params.step,
906
964
  resumeData: params.resumeData,
907
- runtimeContext: params.runtimeContext
965
+ runtimeContext
908
966
  }
909
967
  });
910
968
  }
@@ -929,6 +987,114 @@ var VNextWorkflow = class extends BaseResource {
929
987
  }
930
988
  };
931
989
 
990
+ // src/resources/a2a.ts
991
+ var A2A = class extends BaseResource {
992
+ constructor(options, agentId) {
993
+ super(options);
994
+ this.agentId = agentId;
995
+ }
996
+ /**
997
+ * Get the agent card with metadata about the agent
998
+ * @returns Promise containing the agent card information
999
+ */
1000
+ async getCard() {
1001
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1002
+ }
1003
+ /**
1004
+ * Send a message to the agent and get a response
1005
+ * @param params - Parameters for the task
1006
+ * @returns Promise containing the task response
1007
+ */
1008
+ async sendMessage(params) {
1009
+ const response = await this.request(`/a2a/${this.agentId}`, {
1010
+ method: "POST",
1011
+ body: {
1012
+ method: "tasks/send",
1013
+ params
1014
+ }
1015
+ });
1016
+ return { task: response.result };
1017
+ }
1018
+ /**
1019
+ * Get the status and result of a task
1020
+ * @param params - Parameters for querying the task
1021
+ * @returns Promise containing the task response
1022
+ */
1023
+ async getTask(params) {
1024
+ const response = await this.request(`/a2a/${this.agentId}`, {
1025
+ method: "POST",
1026
+ body: {
1027
+ method: "tasks/get",
1028
+ params
1029
+ }
1030
+ });
1031
+ return response.result;
1032
+ }
1033
+ /**
1034
+ * Cancel a running task
1035
+ * @param params - Parameters identifying the task to cancel
1036
+ * @returns Promise containing the task response
1037
+ */
1038
+ async cancelTask(params) {
1039
+ return this.request(`/a2a/${this.agentId}`, {
1040
+ method: "POST",
1041
+ body: {
1042
+ method: "tasks/cancel",
1043
+ params
1044
+ }
1045
+ });
1046
+ }
1047
+ /**
1048
+ * Send a message and subscribe to streaming updates (not fully implemented)
1049
+ * @param params - Parameters for the task
1050
+ * @returns Promise containing the task response
1051
+ */
1052
+ async sendAndSubscribe(params) {
1053
+ return this.request(`/a2a/${this.agentId}`, {
1054
+ method: "POST",
1055
+ body: {
1056
+ method: "tasks/sendSubscribe",
1057
+ params
1058
+ },
1059
+ stream: true
1060
+ });
1061
+ }
1062
+ };
1063
+
1064
+ // src/resources/mcp-tool.ts
1065
+ var MCPTool = class extends BaseResource {
1066
+ serverId;
1067
+ toolId;
1068
+ constructor(options, serverId, toolId) {
1069
+ super(options);
1070
+ this.serverId = serverId;
1071
+ this.toolId = toolId;
1072
+ }
1073
+ /**
1074
+ * Retrieves details about this specific tool from the MCP server.
1075
+ * @returns Promise containing the tool's information (name, description, schema).
1076
+ */
1077
+ details() {
1078
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1079
+ }
1080
+ /**
1081
+ * Executes this specific tool on the MCP server.
1082
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1083
+ * @returns Promise containing the result of the tool execution.
1084
+ */
1085
+ execute(params) {
1086
+ const body = {};
1087
+ if (params.data !== void 0) body.data = params.data;
1088
+ if (params.runtimeContext !== void 0) {
1089
+ body.runtimeContext = params.runtimeContext;
1090
+ }
1091
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1092
+ method: "POST",
1093
+ body: Object.keys(body).length > 0 ? body : void 0
1094
+ });
1095
+ }
1096
+ };
1097
+
932
1098
  // src/client.ts
933
1099
  var MastraClient = class extends BaseResource {
934
1100
  constructor(options) {
@@ -1139,6 +1305,62 @@ var MastraClient = class extends BaseResource {
1139
1305
  getNetwork(networkId) {
1140
1306
  return new Network(this.options, networkId);
1141
1307
  }
1308
+ /**
1309
+ * Retrieves a list of available MCP servers.
1310
+ * @param params - Optional parameters for pagination (limit, offset).
1311
+ * @returns Promise containing the list of MCP servers and pagination info.
1312
+ */
1313
+ getMcpServers(params) {
1314
+ const searchParams = new URLSearchParams();
1315
+ if (params?.limit !== void 0) {
1316
+ searchParams.set("limit", String(params.limit));
1317
+ }
1318
+ if (params?.offset !== void 0) {
1319
+ searchParams.set("offset", String(params.offset));
1320
+ }
1321
+ const queryString = searchParams.toString();
1322
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1323
+ }
1324
+ /**
1325
+ * Retrieves detailed information for a specific MCP server.
1326
+ * @param serverId - The ID of the MCP server to retrieve.
1327
+ * @param params - Optional parameters, e.g., specific version.
1328
+ * @returns Promise containing the detailed MCP server information.
1329
+ */
1330
+ getMcpServerDetails(serverId, params) {
1331
+ const searchParams = new URLSearchParams();
1332
+ if (params?.version) {
1333
+ searchParams.set("version", params.version);
1334
+ }
1335
+ const queryString = searchParams.toString();
1336
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1337
+ }
1338
+ /**
1339
+ * Retrieves a list of tools for a specific MCP server.
1340
+ * @param serverId - The ID of the MCP server.
1341
+ * @returns Promise containing the list of tools.
1342
+ */
1343
+ getMcpServerTools(serverId) {
1344
+ return this.request(`/api/mcp/${serverId}/tools`);
1345
+ }
1346
+ /**
1347
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1348
+ * This instance can then be used to fetch details or execute the tool.
1349
+ * @param serverId - The ID of the MCP server.
1350
+ * @param toolId - The ID of the tool.
1351
+ * @returns MCPTool instance.
1352
+ */
1353
+ getMcpServerTool(serverId, toolId) {
1354
+ return new MCPTool(this.options, serverId, toolId);
1355
+ }
1356
+ /**
1357
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1358
+ * @param agentId - ID of the agent to interact with
1359
+ * @returns A2A client instance
1360
+ */
1361
+ getA2A(agentId) {
1362
+ return new A2A(this.options, agentId);
1363
+ }
1142
1364
  };
1143
1365
 
1144
1366
  export { MastraClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-trigger-playground-ui-package-20250506151043",
3
+ "version": "0.0.0-vector-sources-20250516175436",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -26,12 +26,12 @@
26
26
  "@ai-sdk/ui-utils": "^1.1.19",
27
27
  "json-schema": "^0.4.0",
28
28
  "rxjs": "7.8.1",
29
- "zod": "^3.24.2",
30
- "zod-to-json-schema": "^3.24.3",
31
- "@mastra/core": "0.0.0-trigger-playground-ui-package-20250506151043"
29
+ "zod": "^3.24.3",
30
+ "zod-to-json-schema": "^3.24.5",
31
+ "@mastra/core": "0.0.0-vector-sources-20250516175436"
32
32
  },
33
33
  "peerDependencies": {
34
- "zod": "^3.24.2"
34
+ "zod": "^3.0.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@babel/preset-env": "^7.26.9",
@@ -42,7 +42,7 @@
42
42
  "tsup": "^8.4.0",
43
43
  "typescript": "^5.8.2",
44
44
  "vitest": "^3.1.2",
45
- "@internal/lint": "0.0.0-trigger-playground-ui-package-20250506151043"
45
+ "@internal/lint": "0.0.0-vector-sources-20250516175436"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
@@ -91,6 +91,17 @@ describe('convertMessagesToMastraMessages', () => {
91
91
  },
92
92
  ],
93
93
  },
94
+ {
95
+ role: 'tool',
96
+ content: [
97
+ {
98
+ type: 'tool-result',
99
+ toolCallId: 'tool-call-1',
100
+ toolName: 'getWeather',
101
+ result: { location: 'San Francisco' },
102
+ },
103
+ ],
104
+ },
94
105
  ]);
95
106
  });
96
107
 
@@ -143,12 +154,6 @@ describe('convertMessagesToMastraMessages', () => {
143
154
  },
144
155
  ],
145
156
  },
146
- {
147
- id: '3',
148
- role: 'tool',
149
- toolCallId: 'tool-call-1',
150
- content: '{"temperature":72,"unit":"F"}',
151
- },
152
157
  {
153
158
  id: '4',
154
159
  role: 'assistant',
@@ -162,6 +167,14 @@ describe('convertMessagesToMastraMessages', () => {
162
167
  expect(result[0].role).toBe('user');
163
168
  expect(result[1].role).toBe('assistant');
164
169
  expect(result[2].role).toBe('tool');
170
+ expect(result[2].content).toEqual([
171
+ {
172
+ type: 'tool-result',
173
+ toolCallId: 'tool-call-1',
174
+ toolName: 'getWeather',
175
+ result: { location: 'San Francisco' },
176
+ },
177
+ ]);
165
178
  expect(result[3].role).toBe('assistant');
166
179
  });
167
180
  });
@@ -1,19 +1,19 @@
1
1
  // Cross-platform UUID generation function
2
- import { AbstractAgent, EventType } from '@ag-ui/client';
3
2
  import type {
3
+ AgentConfig,
4
4
  BaseEvent,
5
+ Message,
5
6
  RunAgentInput,
6
- AgentConfig,
7
- RunStartedEvent,
8
7
  RunFinishedEvent,
9
- TextMessageStartEvent,
8
+ RunStartedEvent,
10
9
  TextMessageContentEvent,
11
10
  TextMessageEndEvent,
12
- Message,
13
- ToolCallStartEvent,
11
+ TextMessageStartEvent,
14
12
  ToolCallArgsEvent,
15
13
  ToolCallEndEvent,
14
+ ToolCallStartEvent,
16
15
  } from '@ag-ui/client';
16
+ import { AbstractAgent, EventType } from '@ag-ui/client';
17
17
  import type { CoreMessage } from '@mastra/core';
18
18
  import { Observable } from 'rxjs';
19
19
  import type { Agent } from '../resources/agent';
@@ -39,7 +39,6 @@ export class AGUIAdapter extends AbstractAgent {
39
39
  protected run(input: RunAgentInput): Observable<BaseEvent> {
40
40
  return new Observable<BaseEvent>(subscriber => {
41
41
  const convertedMessages = convertMessagesToMastraMessages(input.messages);
42
-
43
42
  subscriber.next({
44
43
  type: EventType.RUN_STARTED,
45
44
  threadId: input.threadId,
@@ -66,17 +65,18 @@ export class AGUIAdapter extends AbstractAgent {
66
65
  })
67
66
  .then(response => {
68
67
  let currentMessageId: string | undefined = undefined;
68
+ let isInTextMessage = false;
69
69
  return response.processDataStream({
70
70
  onTextPart: text => {
71
71
  if (currentMessageId === undefined) {
72
72
  currentMessageId = generateUUID();
73
-
74
73
  const message: TextMessageStartEvent = {
75
74
  type: EventType.TEXT_MESSAGE_START,
76
75
  messageId: currentMessageId,
77
76
  role: 'assistant',
78
77
  };
79
78
  subscriber.next(message);
79
+ isInTextMessage = true;
80
80
  }
81
81
 
82
82
  const message: TextMessageContentEvent = {
@@ -86,14 +86,14 @@ export class AGUIAdapter extends AbstractAgent {
86
86
  };
87
87
  subscriber.next(message);
88
88
  },
89
- onFinishMessagePart: message => {
90
- console.log('onFinishMessagePart', message);
89
+ onFinishMessagePart: () => {
91
90
  if (currentMessageId !== undefined) {
92
91
  const message: TextMessageEndEvent = {
93
92
  type: EventType.TEXT_MESSAGE_END,
94
93
  messageId: currentMessageId,
95
94
  };
96
95
  subscriber.next(message);
96
+ isInTextMessage = false;
97
97
  }
98
98
  // Emit run finished event
99
99
  subscriber.next({
@@ -107,6 +107,15 @@ export class AGUIAdapter extends AbstractAgent {
107
107
  },
108
108
  onToolCallPart(streamPart) {
109
109
  const parentMessageId = currentMessageId || generateUUID();
110
+ if (isInTextMessage) {
111
+ const message: TextMessageEndEvent = {
112
+ type: EventType.TEXT_MESSAGE_END,
113
+ messageId: parentMessageId,
114
+ };
115
+ subscriber.next(message);
116
+ isInTextMessage = false;
117
+ }
118
+
110
119
  subscriber.next({
111
120
  type: EventType.TOOL_CALL_START,
112
121
  toolCallId: streamPart.toolCallId,
@@ -130,7 +139,7 @@ export class AGUIAdapter extends AbstractAgent {
130
139
  });
131
140
  })
132
141
  .catch(error => {
133
- console.log('error', error);
142
+ console.error('error', error);
134
143
  // Handle error
135
144
  subscriber.error(error);
136
145
  });
@@ -195,6 +204,17 @@ export function convertMessagesToMastraMessages(messages: Message[]): CoreMessag
195
204
  role: 'assistant',
196
205
  content: parts,
197
206
  });
207
+ if (message.toolCalls?.length) {
208
+ result.push({
209
+ role: 'tool',
210
+ content: message.toolCalls.map(toolCall => ({
211
+ type: 'tool-result',
212
+ toolCallId: toolCall.id,
213
+ toolName: toolCall.function.name,
214
+ result: JSON.parse(toolCall.function.arguments),
215
+ })),
216
+ });
217
+ }
198
218
  } else if (message.role === 'user') {
199
219
  result.push({
200
220
  role: 'user',