@mastra/ai-sdk 0.0.0-fix-thread-list-20251105222841 → 0.0.0-fix-ai-sdk-dependency-20251124104209

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
@@ -138,6 +138,28 @@ function convertMastraChunkToAISDKv5({
138
138
  toolName: chunk.payload.toolName,
139
139
  input: chunk.payload.args
140
140
  };
141
+ case "tool-call-approval":
142
+ return {
143
+ type: "data-tool-call-approval",
144
+ id: chunk.payload.toolCallId,
145
+ data: {
146
+ runId: chunk.runId,
147
+ toolCallId: chunk.payload.toolCallId,
148
+ toolName: chunk.payload.toolName,
149
+ args: chunk.payload.args
150
+ }
151
+ };
152
+ case "tool-call-suspended":
153
+ return {
154
+ type: "data-tool-call-suspended",
155
+ id: chunk.payload.toolCallId,
156
+ data: {
157
+ runId: chunk.runId,
158
+ toolCallId: chunk.payload.toolCallId,
159
+ toolName: chunk.payload.toolName,
160
+ suspendPayload: chunk.payload.suspendPayload
161
+ }
162
+ };
141
163
  case "tool-call-input-streaming-start":
142
164
  return {
143
165
  type: "tool-input-start",
@@ -228,6 +250,13 @@ function convertMastraChunkToAISDKv5({
228
250
  type: "object",
229
251
  object: chunk.object
230
252
  };
253
+ case "tripwire":
254
+ return {
255
+ type: "data-tripwire",
256
+ data: {
257
+ tripwireReason: chunk.payload.tripwireReason
258
+ }
259
+ };
231
260
  default:
232
261
  if (chunk.type && "payload" in chunk && chunk.payload) {
233
262
  return {
@@ -283,6 +312,14 @@ function convertFullStreamChunkToUIMessageStream({
283
312
  };
284
313
  }
285
314
  case "reasoning-delta": {
315
+ if (sendReasoning) {
316
+ return {
317
+ type: "reasoning-delta",
318
+ id: part.id,
319
+ delta: part.text,
320
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
321
+ };
322
+ }
286
323
  return;
287
324
  }
288
325
  case "reasoning-end": {
@@ -300,6 +337,25 @@ function convertFullStreamChunkToUIMessageStream({
300
337
  };
301
338
  }
302
339
  case "source": {
340
+ if (sendSources && part.sourceType === "url") {
341
+ return {
342
+ type: "source-url",
343
+ sourceId: part.id,
344
+ url: part.url,
345
+ title: part.title,
346
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
347
+ };
348
+ }
349
+ if (sendSources && part.sourceType === "document") {
350
+ return {
351
+ type: "source-document",
352
+ sourceId: part.id,
353
+ mediaType: part.mediaType,
354
+ title: part.title,
355
+ filename: part.filename,
356
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
357
+ };
358
+ }
303
359
  return;
304
360
  }
305
361
  case "tool-input-start": {
@@ -357,6 +413,14 @@ function convertFullStreamChunkToUIMessageStream({
357
413
  toolCallId: part.toolCallId,
358
414
  payload: part.output
359
415
  };
416
+ } else if (isDataChunkType(part.output)) {
417
+ if (!("data" in part.output)) {
418
+ throw new Error(
419
+ `UI Messages require a data property when using data- prefixed chunks
420
+ ${JSON.stringify(part)}`
421
+ );
422
+ }
423
+ return part.output;
360
424
  }
361
425
  return;
362
426
  }
@@ -382,21 +446,23 @@ function convertFullStreamChunkToUIMessageStream({
382
446
  return { type: "finish-step" };
383
447
  }
384
448
  case "start": {
385
- {
449
+ if (sendStart) {
386
450
  return {
387
451
  type: "start",
388
452
  ...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
389
453
  ...responseMessageId != null ? { messageId: responseMessageId } : {}
390
454
  };
391
455
  }
456
+ return;
392
457
  }
393
458
  case "finish": {
394
- {
459
+ if (sendFinish) {
395
460
  return {
396
461
  type: "finish",
397
462
  ...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
398
463
  };
399
464
  }
465
+ return;
400
466
  }
401
467
  case "abort": {
402
468
  return part;
@@ -461,20 +527,37 @@ function AgentNetworkToAISDKTransformer() {
461
527
  }
462
528
  });
463
529
  }
464
- function AgentStreamToAISDKTransformer(lastMessageId) {
530
+ function AgentStreamToAISDKTransformer({
531
+ lastMessageId,
532
+ sendStart,
533
+ sendFinish,
534
+ sendReasoning,
535
+ sendSources,
536
+ messageMetadata,
537
+ onError
538
+ }) {
465
539
  let bufferedSteps = /* @__PURE__ */ new Map();
540
+ let tripwireOccurred = false;
541
+ let finishEventSent = false;
466
542
  return new TransformStream({
467
543
  transform(chunk, controller) {
544
+ if (chunk.type === "tripwire") {
545
+ tripwireOccurred = true;
546
+ }
547
+ if (chunk.type === "finish") {
548
+ finishEventSent = true;
549
+ }
468
550
  const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
469
551
  const transformedChunk = convertFullStreamChunkToUIMessageStream({
470
552
  part,
471
- sendReasoning: false,
472
- sendSources: false,
473
- sendStart: true,
474
- sendFinish: true,
553
+ sendReasoning,
554
+ sendSources,
555
+ messageMetadataValue: messageMetadata?.({ part }),
556
+ sendStart,
557
+ sendFinish,
475
558
  responseMessageId: lastMessageId,
476
559
  onError(error) {
477
- return safeParseErrorObject(error);
560
+ return onError ? onError(error) : safeParseErrorObject(error);
478
561
  }
479
562
  });
480
563
  if (transformedChunk) {
@@ -494,6 +577,14 @@ function AgentStreamToAISDKTransformer(lastMessageId) {
494
577
  controller.enqueue(transformedChunk);
495
578
  }
496
579
  }
580
+ },
581
+ flush(controller) {
582
+ if (tripwireOccurred && !finishEventSent && sendFinish) {
583
+ controller.enqueue({
584
+ type: "finish",
585
+ finishReason: "other"
586
+ });
587
+ }
497
588
  }
498
589
  });
499
590
  }
@@ -980,7 +1071,11 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
980
1071
  }
981
1072
 
982
1073
  // src/convert-streams.ts
983
- function toAISdkV5Stream(stream, options = { from: "agent" }) {
1074
+ function toAISdkV5Stream(stream, options = {
1075
+ from: "agent",
1076
+ sendStart: true,
1077
+ sendFinish: true
1078
+ }) {
984
1079
  const from = options?.from;
985
1080
  if (from === "workflow") {
986
1081
  return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
@@ -989,14 +1084,28 @@ function toAISdkV5Stream(stream, options = { from: "agent" }) {
989
1084
  return stream.pipeThrough(AgentNetworkToAISDKTransformer());
990
1085
  }
991
1086
  const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
992
- return agentReadable.pipeThrough(AgentStreamToAISDKTransformer(options?.lastMessageId));
1087
+ return agentReadable.pipeThrough(
1088
+ AgentStreamToAISDKTransformer({
1089
+ lastMessageId: options?.lastMessageId,
1090
+ sendStart: options?.sendStart,
1091
+ sendFinish: options?.sendFinish,
1092
+ sendReasoning: options?.sendReasoning,
1093
+ sendSources: options?.sendSources,
1094
+ messageMetadata: options?.messageMetadata,
1095
+ onError: options?.onError
1096
+ })
1097
+ );
993
1098
  }
994
1099
 
995
1100
  // src/chat-route.ts
996
1101
  function chatRoute({
997
1102
  path = "/chat/:agentId",
998
1103
  agent,
999
- defaultOptions
1104
+ defaultOptions,
1105
+ sendStart = true,
1106
+ sendFinish = true,
1107
+ sendReasoning = false,
1108
+ sendSources = false
1000
1109
  }) {
1001
1110
  if (!agent && !path.includes("/:agentId")) {
1002
1111
  throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
@@ -1130,7 +1239,14 @@ function chatRoute({
1130
1239
  const uiMessageStream = createUIMessageStream({
1131
1240
  originalMessages: messages,
1132
1241
  execute: async ({ writer }) => {
1133
- for await (const part of toAISdkV5Stream(result, { from: "agent", lastMessageId })) {
1242
+ for await (const part of toAISdkV5Stream(result, {
1243
+ from: "agent",
1244
+ lastMessageId,
1245
+ sendStart,
1246
+ sendFinish,
1247
+ sendReasoning,
1248
+ sendSources
1249
+ })) {
1134
1250
  writer.write(part);
1135
1251
  }
1136
1252
  }
@@ -1170,9 +1286,13 @@ function workflowRoute({
1170
1286
  schema: {
1171
1287
  type: "object",
1172
1288
  properties: {
1289
+ runId: { type: "string" },
1290
+ resourceId: { type: "string" },
1173
1291
  inputData: { type: "object", additionalProperties: true },
1292
+ resumeData: { type: "object", additionalProperties: true },
1174
1293
  requestContext: { type: "object", additionalProperties: true },
1175
- tracingOptions: { type: "object", additionalProperties: true }
1294
+ tracingOptions: { type: "object", additionalProperties: true },
1295
+ step: { type: "string" }
1176
1296
  }
1177
1297
  }
1178
1298
  }
@@ -1190,7 +1310,7 @@ function workflowRoute({
1190
1310
  }
1191
1311
  },
1192
1312
  handler: async (c) => {
1193
- const { inputData, resumeData, ...rest } = await c.req.json();
1313
+ const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
1194
1314
  const mastra = c.get("mastra");
1195
1315
  let workflowToUse = workflow;
1196
1316
  if (!workflow) {
@@ -1209,7 +1329,7 @@ function workflowRoute({
1209
1329
  if (!workflowObj) {
1210
1330
  throw new Error(`Workflow ${workflowToUse} not found`);
1211
1331
  }
1212
- const run = await workflowObj.createRun();
1332
+ const run = await workflowObj.createRun({ runId, resourceId, ...rest });
1213
1333
  const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
1214
1334
  const uiMessageStream = createUIMessageStream({
1215
1335
  execute: async ({ writer }) => {