@mastra/playground-ui 5.0.3-alpha.0 → 5.0.3

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.cjs.js CHANGED
@@ -4067,13 +4067,16 @@ function MastraRuntimeProvider({
4067
4067
  if (message?.toolInvocations?.length > 0) {
4068
4068
  return {
4069
4069
  ...message,
4070
- content: message.toolInvocations.map((toolInvocation) => ({
4071
- type: "tool-call",
4072
- toolCallId: toolInvocation?.toolCallId,
4073
- toolName: toolInvocation?.toolName,
4074
- args: toolInvocation?.args,
4075
- result: toolInvocation?.result
4076
- }))
4070
+ content: [
4071
+ ...typeof message.content === "string" ? [{ type: "text", text: message.content }] : [],
4072
+ ...message.toolInvocations.map((toolInvocation) => ({
4073
+ type: "tool-call",
4074
+ toolCallId: toolInvocation?.toolCallId,
4075
+ toolName: toolInvocation?.toolName,
4076
+ args: toolInvocation?.args,
4077
+ result: toolInvocation?.result
4078
+ }))
4079
+ ]
4077
4080
  };
4078
4081
  }
4079
4082
  return message;
@@ -4188,6 +4191,13 @@ function MastraRuntimeProvider({
4188
4191
  };
4189
4192
  if (!assistantMessageAdded) {
4190
4193
  assistantMessageAdded = true;
4194
+ if (assistantToolCallAddedForUpdater) {
4195
+ assistantToolCallAddedForUpdater = false;
4196
+ }
4197
+ return [...currentConversation, message2];
4198
+ }
4199
+ if (assistantToolCallAddedForUpdater) {
4200
+ assistantToolCallAddedForUpdater = false;
4191
4201
  return [...currentConversation, message2];
4192
4202
  }
4193
4203
  return [...currentConversation.slice(0, -1), message2];
@@ -4215,22 +4225,18 @@ function MastraRuntimeProvider({
4215
4225
  if (!response.body) {
4216
4226
  throw new Error("No response body");
4217
4227
  }
4218
- const parts = [];
4219
4228
  let content = "";
4220
- let currentTextPart = null;
4221
4229
  let assistantMessageAdded = false;
4230
+ let assistantToolCallAddedForUpdater = false;
4231
+ let assistantToolCallAddedForContent = false;
4222
4232
  await response.processDataStream({
4223
4233
  onTextPart(value) {
4224
- if (currentTextPart == null) {
4225
- currentTextPart = {
4226
- type: "text",
4227
- text: value
4228
- };
4229
- parts.push(currentTextPart);
4234
+ if (assistantToolCallAddedForContent) {
4235
+ assistantToolCallAddedForContent = false;
4236
+ content = value;
4230
4237
  } else {
4231
- currentTextPart.text += value;
4238
+ content += value;
4232
4239
  }
4233
- content += value;
4234
4240
  updater();
4235
4241
  },
4236
4242
  async onToolCallPart(value) {
@@ -4257,6 +4263,8 @@ function MastraRuntimeProvider({
4257
4263
  }
4258
4264
  ]
4259
4265
  };
4266
+ assistantToolCallAddedForUpdater = true;
4267
+ assistantToolCallAddedForContent = true;
4260
4268
  return [...currentConversation.slice(0, -1), updatedMessage];
4261
4269
  }
4262
4270
  const newMessage = {
@@ -4271,6 +4279,8 @@ function MastraRuntimeProvider({
4271
4279
  }
4272
4280
  ]
4273
4281
  };
4282
+ assistantToolCallAddedForUpdater = true;
4283
+ assistantToolCallAddedForContent = true;
4274
4284
  return [...currentConversation, newMessage];
4275
4285
  });
4276
4286
  },