@mastra/ai-sdk 0.0.0-fix-9244-clickhouse-metadata-20251105010900 → 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/CHANGELOG.md +178 -3
- package/dist/chat-route.d.ts +52 -2
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/convert-messages.d.ts +1 -1
- package/dist/convert-messages.d.ts.map +1 -1
- package/dist/convert-streams.d.ts +63 -1
- package/dist/convert-streams.d.ts.map +1 -1
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +159 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +159 -15
- package/dist/index.js.map +1 -1
- package/dist/transformers.d.ts +10 -2
- package/dist/transformers.d.ts.map +1 -1
- package/dist/utils.d.ts +7 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +8 -6
package/dist/index.js
CHANGED
|
@@ -22,6 +22,12 @@ function safeParseErrorObject(obj) {
|
|
|
22
22
|
return String(obj);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
var isAgentExecutionDataChunkType = (chunk) => {
|
|
26
|
+
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("agent-execution-event-") && "payload" in chunk && typeof chunk.payload === "object" && "type" in chunk.payload && chunk.payload.type?.startsWith("data-");
|
|
27
|
+
};
|
|
28
|
+
var isWorkflowExecutionDataChunkType = (chunk) => {
|
|
29
|
+
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("workflow-execution-event-") && "payload" in chunk && typeof chunk.payload === "object" && "type" in chunk.payload && chunk.payload.type?.startsWith("data-");
|
|
30
|
+
};
|
|
25
31
|
|
|
26
32
|
// src/helpers.ts
|
|
27
33
|
function convertMastraChunkToAISDKv5({
|
|
@@ -132,6 +138,28 @@ function convertMastraChunkToAISDKv5({
|
|
|
132
138
|
toolName: chunk.payload.toolName,
|
|
133
139
|
input: chunk.payload.args
|
|
134
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
|
+
};
|
|
135
163
|
case "tool-call-input-streaming-start":
|
|
136
164
|
return {
|
|
137
165
|
type: "tool-input-start",
|
|
@@ -222,6 +250,13 @@ function convertMastraChunkToAISDKv5({
|
|
|
222
250
|
type: "object",
|
|
223
251
|
object: chunk.object
|
|
224
252
|
};
|
|
253
|
+
case "tripwire":
|
|
254
|
+
return {
|
|
255
|
+
type: "data-tripwire",
|
|
256
|
+
data: {
|
|
257
|
+
tripwireReason: chunk.payload.tripwireReason
|
|
258
|
+
}
|
|
259
|
+
};
|
|
225
260
|
default:
|
|
226
261
|
if (chunk.type && "payload" in chunk && chunk.payload) {
|
|
227
262
|
return {
|
|
@@ -277,6 +312,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
277
312
|
};
|
|
278
313
|
}
|
|
279
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
|
+
}
|
|
280
323
|
return;
|
|
281
324
|
}
|
|
282
325
|
case "reasoning-end": {
|
|
@@ -294,6 +337,25 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
294
337
|
};
|
|
295
338
|
}
|
|
296
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
|
+
}
|
|
297
359
|
return;
|
|
298
360
|
}
|
|
299
361
|
case "tool-input-start": {
|
|
@@ -351,6 +413,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
351
413
|
toolCallId: part.toolCallId,
|
|
352
414
|
payload: part.output
|
|
353
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;
|
|
354
424
|
}
|
|
355
425
|
return;
|
|
356
426
|
}
|
|
@@ -376,21 +446,23 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
376
446
|
return { type: "finish-step" };
|
|
377
447
|
}
|
|
378
448
|
case "start": {
|
|
379
|
-
{
|
|
449
|
+
if (sendStart) {
|
|
380
450
|
return {
|
|
381
451
|
type: "start",
|
|
382
452
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
|
|
383
453
|
...responseMessageId != null ? { messageId: responseMessageId } : {}
|
|
384
454
|
};
|
|
385
455
|
}
|
|
456
|
+
return;
|
|
386
457
|
}
|
|
387
458
|
case "finish": {
|
|
388
|
-
{
|
|
459
|
+
if (sendFinish) {
|
|
389
460
|
return {
|
|
390
461
|
type: "finish",
|
|
391
462
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
|
|
392
463
|
};
|
|
393
464
|
}
|
|
465
|
+
return;
|
|
394
466
|
}
|
|
395
467
|
case "abort": {
|
|
396
468
|
return part;
|
|
@@ -455,20 +527,37 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
455
527
|
}
|
|
456
528
|
});
|
|
457
529
|
}
|
|
458
|
-
function AgentStreamToAISDKTransformer(
|
|
530
|
+
function AgentStreamToAISDKTransformer({
|
|
531
|
+
lastMessageId,
|
|
532
|
+
sendStart,
|
|
533
|
+
sendFinish,
|
|
534
|
+
sendReasoning,
|
|
535
|
+
sendSources,
|
|
536
|
+
messageMetadata,
|
|
537
|
+
onError
|
|
538
|
+
}) {
|
|
459
539
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
540
|
+
let tripwireOccurred = false;
|
|
541
|
+
let finishEventSent = false;
|
|
460
542
|
return new TransformStream({
|
|
461
543
|
transform(chunk, controller) {
|
|
544
|
+
if (chunk.type === "tripwire") {
|
|
545
|
+
tripwireOccurred = true;
|
|
546
|
+
}
|
|
547
|
+
if (chunk.type === "finish") {
|
|
548
|
+
finishEventSent = true;
|
|
549
|
+
}
|
|
462
550
|
const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
|
|
463
551
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
464
552
|
part,
|
|
465
|
-
sendReasoning
|
|
466
|
-
sendSources
|
|
467
|
-
|
|
468
|
-
|
|
553
|
+
sendReasoning,
|
|
554
|
+
sendSources,
|
|
555
|
+
messageMetadataValue: messageMetadata?.({ part }),
|
|
556
|
+
sendStart,
|
|
557
|
+
sendFinish,
|
|
469
558
|
responseMessageId: lastMessageId,
|
|
470
559
|
onError(error) {
|
|
471
|
-
return safeParseErrorObject(error);
|
|
560
|
+
return onError ? onError(error) : safeParseErrorObject(error);
|
|
472
561
|
}
|
|
473
562
|
});
|
|
474
563
|
if (transformedChunk) {
|
|
@@ -488,6 +577,14 @@ function AgentStreamToAISDKTransformer(lastMessageId) {
|
|
|
488
577
|
controller.enqueue(transformedChunk);
|
|
489
578
|
}
|
|
490
579
|
}
|
|
580
|
+
},
|
|
581
|
+
flush(controller) {
|
|
582
|
+
if (tripwireOccurred && !finishEventSent && sendFinish) {
|
|
583
|
+
controller.enqueue({
|
|
584
|
+
type: "finish",
|
|
585
|
+
finishReason: "other"
|
|
586
|
+
});
|
|
587
|
+
}
|
|
491
588
|
}
|
|
492
589
|
});
|
|
493
590
|
}
|
|
@@ -950,13 +1047,35 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
950
1047
|
}
|
|
951
1048
|
return payload;
|
|
952
1049
|
}
|
|
1050
|
+
if (isAgentExecutionDataChunkType(payload)) {
|
|
1051
|
+
if (!("data" in payload.payload)) {
|
|
1052
|
+
throw new Error(
|
|
1053
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1054
|
+
${JSON.stringify(payload)}`
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
return payload.payload;
|
|
1058
|
+
}
|
|
1059
|
+
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
1060
|
+
if (!("data" in payload.payload)) {
|
|
1061
|
+
throw new Error(
|
|
1062
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1063
|
+
${JSON.stringify(payload)}`
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
return payload.payload;
|
|
1067
|
+
}
|
|
953
1068
|
return null;
|
|
954
1069
|
}
|
|
955
1070
|
}
|
|
956
1071
|
}
|
|
957
1072
|
|
|
958
1073
|
// src/convert-streams.ts
|
|
959
|
-
function toAISdkV5Stream(stream, options = {
|
|
1074
|
+
function toAISdkV5Stream(stream, options = {
|
|
1075
|
+
from: "agent",
|
|
1076
|
+
sendStart: true,
|
|
1077
|
+
sendFinish: true
|
|
1078
|
+
}) {
|
|
960
1079
|
const from = options?.from;
|
|
961
1080
|
if (from === "workflow") {
|
|
962
1081
|
return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
|
|
@@ -965,14 +1084,28 @@ function toAISdkV5Stream(stream, options = { from: "agent" }) {
|
|
|
965
1084
|
return stream.pipeThrough(AgentNetworkToAISDKTransformer());
|
|
966
1085
|
}
|
|
967
1086
|
const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
|
|
968
|
-
return agentReadable.pipeThrough(
|
|
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
|
+
);
|
|
969
1098
|
}
|
|
970
1099
|
|
|
971
1100
|
// src/chat-route.ts
|
|
972
1101
|
function chatRoute({
|
|
973
1102
|
path = "/chat/:agentId",
|
|
974
1103
|
agent,
|
|
975
|
-
defaultOptions
|
|
1104
|
+
defaultOptions,
|
|
1105
|
+
sendStart = true,
|
|
1106
|
+
sendFinish = true,
|
|
1107
|
+
sendReasoning = false,
|
|
1108
|
+
sendSources = false
|
|
976
1109
|
}) {
|
|
977
1110
|
if (!agent && !path.includes("/:agentId")) {
|
|
978
1111
|
throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
|
|
@@ -1106,7 +1239,14 @@ function chatRoute({
|
|
|
1106
1239
|
const uiMessageStream = createUIMessageStream({
|
|
1107
1240
|
originalMessages: messages,
|
|
1108
1241
|
execute: async ({ writer }) => {
|
|
1109
|
-
for await (const part of toAISdkV5Stream(result, {
|
|
1242
|
+
for await (const part of toAISdkV5Stream(result, {
|
|
1243
|
+
from: "agent",
|
|
1244
|
+
lastMessageId,
|
|
1245
|
+
sendStart,
|
|
1246
|
+
sendFinish,
|
|
1247
|
+
sendReasoning,
|
|
1248
|
+
sendSources
|
|
1249
|
+
})) {
|
|
1110
1250
|
writer.write(part);
|
|
1111
1251
|
}
|
|
1112
1252
|
}
|
|
@@ -1146,9 +1286,13 @@ function workflowRoute({
|
|
|
1146
1286
|
schema: {
|
|
1147
1287
|
type: "object",
|
|
1148
1288
|
properties: {
|
|
1289
|
+
runId: { type: "string" },
|
|
1290
|
+
resourceId: { type: "string" },
|
|
1149
1291
|
inputData: { type: "object", additionalProperties: true },
|
|
1292
|
+
resumeData: { type: "object", additionalProperties: true },
|
|
1150
1293
|
requestContext: { type: "object", additionalProperties: true },
|
|
1151
|
-
tracingOptions: { type: "object", additionalProperties: true }
|
|
1294
|
+
tracingOptions: { type: "object", additionalProperties: true },
|
|
1295
|
+
step: { type: "string" }
|
|
1152
1296
|
}
|
|
1153
1297
|
}
|
|
1154
1298
|
}
|
|
@@ -1166,7 +1310,7 @@ function workflowRoute({
|
|
|
1166
1310
|
}
|
|
1167
1311
|
},
|
|
1168
1312
|
handler: async (c) => {
|
|
1169
|
-
const { inputData, resumeData, ...rest } = await c.req.json();
|
|
1313
|
+
const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
|
|
1170
1314
|
const mastra = c.get("mastra");
|
|
1171
1315
|
let workflowToUse = workflow;
|
|
1172
1316
|
if (!workflow) {
|
|
@@ -1185,7 +1329,7 @@ function workflowRoute({
|
|
|
1185
1329
|
if (!workflowObj) {
|
|
1186
1330
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1187
1331
|
}
|
|
1188
|
-
const run = await workflowObj.createRun();
|
|
1332
|
+
const run = await workflowObj.createRun({ runId, resourceId, ...rest });
|
|
1189
1333
|
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1190
1334
|
const uiMessageStream = createUIMessageStream({
|
|
1191
1335
|
execute: async ({ writer }) => {
|