@mastra/ai-sdk 0.0.0-sidebar-window-undefined-fix-20251029233656 → 0.0.0-span-scorring-test-20251124132129
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 +195 -3
- package/dist/chat-route.d.ts +52 -2
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/convert-messages.d.ts +10 -0
- package/dist/convert-messages.d.ts.map +1 -0
- package/dist/convert-streams.d.ts +80 -0
- package/dist/convert-streams.d.ts.map +1 -0
- package/dist/helpers.d.ts +2 -3
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +239 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +239 -35
- package/dist/index.js.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +15 -16
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts +21 -2
- package/dist/transformers.d.ts.map +1 -1
- package/dist/ui.cjs +16 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.ts +2 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +13 -0
- package/dist/ui.js.map +1 -0
- package/dist/utils.d.ts +8 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +21 -6
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,26 @@ var stream = require('@mastra/core/stream');
|
|
|
10
10
|
var isDataChunkType = (chunk) => {
|
|
11
11
|
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
|
|
12
12
|
};
|
|
13
|
+
function safeParseErrorObject(obj) {
|
|
14
|
+
if (typeof obj !== "object" || obj === null) {
|
|
15
|
+
return String(obj);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const stringified = JSON.stringify(obj);
|
|
19
|
+
if (stringified === "{}") {
|
|
20
|
+
return String(obj);
|
|
21
|
+
}
|
|
22
|
+
return stringified;
|
|
23
|
+
} catch {
|
|
24
|
+
return String(obj);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
var isAgentExecutionDataChunkType = (chunk) => {
|
|
28
|
+
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-");
|
|
29
|
+
};
|
|
30
|
+
var isWorkflowExecutionDataChunkType = (chunk) => {
|
|
31
|
+
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-");
|
|
32
|
+
};
|
|
13
33
|
|
|
14
34
|
// src/helpers.ts
|
|
15
35
|
function convertMastraChunkToAISDKv5({
|
|
@@ -120,6 +140,28 @@ function convertMastraChunkToAISDKv5({
|
|
|
120
140
|
toolName: chunk.payload.toolName,
|
|
121
141
|
input: chunk.payload.args
|
|
122
142
|
};
|
|
143
|
+
case "tool-call-approval":
|
|
144
|
+
return {
|
|
145
|
+
type: "data-tool-call-approval",
|
|
146
|
+
id: chunk.payload.toolCallId,
|
|
147
|
+
data: {
|
|
148
|
+
runId: chunk.runId,
|
|
149
|
+
toolCallId: chunk.payload.toolCallId,
|
|
150
|
+
toolName: chunk.payload.toolName,
|
|
151
|
+
args: chunk.payload.args
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
case "tool-call-suspended":
|
|
155
|
+
return {
|
|
156
|
+
type: "data-tool-call-suspended",
|
|
157
|
+
id: chunk.payload.toolCallId,
|
|
158
|
+
data: {
|
|
159
|
+
runId: chunk.runId,
|
|
160
|
+
toolCallId: chunk.payload.toolCallId,
|
|
161
|
+
toolName: chunk.payload.toolName,
|
|
162
|
+
suspendPayload: chunk.payload.suspendPayload
|
|
163
|
+
}
|
|
164
|
+
};
|
|
123
165
|
case "tool-call-input-streaming-start":
|
|
124
166
|
return {
|
|
125
167
|
type: "tool-input-start",
|
|
@@ -210,6 +252,13 @@ function convertMastraChunkToAISDKv5({
|
|
|
210
252
|
type: "object",
|
|
211
253
|
object: chunk.object
|
|
212
254
|
};
|
|
255
|
+
case "tripwire":
|
|
256
|
+
return {
|
|
257
|
+
type: "data-tripwire",
|
|
258
|
+
data: {
|
|
259
|
+
tripwireReason: chunk.payload.tripwireReason
|
|
260
|
+
}
|
|
261
|
+
};
|
|
213
262
|
default:
|
|
214
263
|
if (chunk.type && "payload" in chunk && chunk.payload) {
|
|
215
264
|
return {
|
|
@@ -265,6 +314,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
265
314
|
};
|
|
266
315
|
}
|
|
267
316
|
case "reasoning-delta": {
|
|
317
|
+
if (sendReasoning) {
|
|
318
|
+
return {
|
|
319
|
+
type: "reasoning-delta",
|
|
320
|
+
id: part.id,
|
|
321
|
+
delta: part.text,
|
|
322
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
268
325
|
return;
|
|
269
326
|
}
|
|
270
327
|
case "reasoning-end": {
|
|
@@ -282,6 +339,25 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
282
339
|
};
|
|
283
340
|
}
|
|
284
341
|
case "source": {
|
|
342
|
+
if (sendSources && part.sourceType === "url") {
|
|
343
|
+
return {
|
|
344
|
+
type: "source-url",
|
|
345
|
+
sourceId: part.id,
|
|
346
|
+
url: part.url,
|
|
347
|
+
title: part.title,
|
|
348
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if (sendSources && part.sourceType === "document") {
|
|
352
|
+
return {
|
|
353
|
+
type: "source-document",
|
|
354
|
+
sourceId: part.id,
|
|
355
|
+
mediaType: part.mediaType,
|
|
356
|
+
title: part.title,
|
|
357
|
+
filename: part.filename,
|
|
358
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
285
361
|
return;
|
|
286
362
|
}
|
|
287
363
|
case "tool-input-start": {
|
|
@@ -339,6 +415,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
339
415
|
toolCallId: part.toolCallId,
|
|
340
416
|
payload: part.output
|
|
341
417
|
};
|
|
418
|
+
} else if (isDataChunkType(part.output)) {
|
|
419
|
+
if (!("data" in part.output)) {
|
|
420
|
+
throw new Error(
|
|
421
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
422
|
+
${JSON.stringify(part)}`
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
return part.output;
|
|
342
426
|
}
|
|
343
427
|
return;
|
|
344
428
|
}
|
|
@@ -364,21 +448,23 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
364
448
|
return { type: "finish-step" };
|
|
365
449
|
}
|
|
366
450
|
case "start": {
|
|
367
|
-
{
|
|
451
|
+
if (sendStart) {
|
|
368
452
|
return {
|
|
369
453
|
type: "start",
|
|
370
454
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
|
|
371
455
|
...responseMessageId != null ? { messageId: responseMessageId } : {}
|
|
372
456
|
};
|
|
373
457
|
}
|
|
458
|
+
return;
|
|
374
459
|
}
|
|
375
460
|
case "finish": {
|
|
376
|
-
{
|
|
461
|
+
if (sendFinish) {
|
|
377
462
|
return {
|
|
378
463
|
type: "finish",
|
|
379
464
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
|
|
380
465
|
};
|
|
381
466
|
}
|
|
467
|
+
return;
|
|
382
468
|
}
|
|
383
469
|
case "abort": {
|
|
384
470
|
return part;
|
|
@@ -443,20 +529,37 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
443
529
|
}
|
|
444
530
|
});
|
|
445
531
|
}
|
|
446
|
-
function AgentStreamToAISDKTransformer(
|
|
532
|
+
function AgentStreamToAISDKTransformer({
|
|
533
|
+
lastMessageId,
|
|
534
|
+
sendStart,
|
|
535
|
+
sendFinish,
|
|
536
|
+
sendReasoning,
|
|
537
|
+
sendSources,
|
|
538
|
+
messageMetadata,
|
|
539
|
+
onError
|
|
540
|
+
}) {
|
|
447
541
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
542
|
+
let tripwireOccurred = false;
|
|
543
|
+
let finishEventSent = false;
|
|
448
544
|
return new TransformStream({
|
|
449
545
|
transform(chunk, controller) {
|
|
546
|
+
if (chunk.type === "tripwire") {
|
|
547
|
+
tripwireOccurred = true;
|
|
548
|
+
}
|
|
549
|
+
if (chunk.type === "finish") {
|
|
550
|
+
finishEventSent = true;
|
|
551
|
+
}
|
|
450
552
|
const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
|
|
451
553
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
452
554
|
part,
|
|
453
|
-
sendReasoning
|
|
454
|
-
sendSources
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
555
|
+
sendReasoning,
|
|
556
|
+
sendSources,
|
|
557
|
+
messageMetadataValue: messageMetadata?.({ part }),
|
|
558
|
+
sendStart,
|
|
559
|
+
sendFinish,
|
|
560
|
+
responseMessageId: lastMessageId,
|
|
561
|
+
onError(error) {
|
|
562
|
+
return onError ? onError(error) : safeParseErrorObject(error);
|
|
460
563
|
}
|
|
461
564
|
});
|
|
462
565
|
if (transformedChunk) {
|
|
@@ -476,6 +579,14 @@ function AgentStreamToAISDKTransformer() {
|
|
|
476
579
|
controller.enqueue(transformedChunk);
|
|
477
580
|
}
|
|
478
581
|
}
|
|
582
|
+
},
|
|
583
|
+
flush(controller) {
|
|
584
|
+
if (tripwireOccurred && !finishEventSent && sendFinish) {
|
|
585
|
+
controller.enqueue({
|
|
586
|
+
type: "finish",
|
|
587
|
+
finishReason: "other"
|
|
588
|
+
});
|
|
589
|
+
}
|
|
479
590
|
}
|
|
480
591
|
});
|
|
481
592
|
}
|
|
@@ -638,7 +749,9 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
638
749
|
name: payload.payload.id,
|
|
639
750
|
status: payload.payload.status,
|
|
640
751
|
input: payload.payload.payload ?? null,
|
|
641
|
-
output: null
|
|
752
|
+
output: null,
|
|
753
|
+
suspendPayload: null,
|
|
754
|
+
resumePayload: null
|
|
642
755
|
};
|
|
643
756
|
bufferedWorkflows.set(payload.runId, current);
|
|
644
757
|
return {
|
|
@@ -671,6 +784,27 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
671
784
|
}
|
|
672
785
|
};
|
|
673
786
|
}
|
|
787
|
+
case "workflow-step-suspended": {
|
|
788
|
+
const current = bufferedWorkflows.get(payload.runId);
|
|
789
|
+
if (!current) return null;
|
|
790
|
+
current.steps[payload.payload.id] = {
|
|
791
|
+
...current.steps[payload.payload.id],
|
|
792
|
+
status: payload.payload.status,
|
|
793
|
+
suspendPayload: payload.payload.suspendPayload ?? null,
|
|
794
|
+
resumePayload: payload.payload.resumePayload ?? null,
|
|
795
|
+
output: null
|
|
796
|
+
};
|
|
797
|
+
return {
|
|
798
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
799
|
+
id: payload.runId,
|
|
800
|
+
data: {
|
|
801
|
+
name: current.name,
|
|
802
|
+
status: "suspended",
|
|
803
|
+
steps: current.steps,
|
|
804
|
+
output: null
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
}
|
|
674
808
|
case "workflow-finish": {
|
|
675
809
|
const current = bufferedWorkflows.get(payload.runId);
|
|
676
810
|
if (!current) return null;
|
|
@@ -745,7 +879,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
745
879
|
name: payload.payload.agentId,
|
|
746
880
|
status: "running",
|
|
747
881
|
input: payload.payload.args || null,
|
|
748
|
-
output: null
|
|
882
|
+
output: null,
|
|
883
|
+
suspendPayload: null,
|
|
884
|
+
resumePayload: null
|
|
749
885
|
});
|
|
750
886
|
bufferedNetworks.set(payload.runId, current);
|
|
751
887
|
return {
|
|
@@ -763,7 +899,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
763
899
|
name: payload.payload.name,
|
|
764
900
|
status: "running",
|
|
765
901
|
input: payload.payload.args || null,
|
|
766
|
-
output: null
|
|
902
|
+
output: null,
|
|
903
|
+
suspendPayload: null,
|
|
904
|
+
resumePayload: null
|
|
767
905
|
});
|
|
768
906
|
bufferedNetworks.set(payload.runId, current);
|
|
769
907
|
return {
|
|
@@ -781,7 +919,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
781
919
|
name: payload.payload.args?.toolName,
|
|
782
920
|
status: "running",
|
|
783
921
|
input: payload.payload.args?.args || null,
|
|
784
|
-
output: null
|
|
922
|
+
output: null,
|
|
923
|
+
suspendPayload: null,
|
|
924
|
+
resumePayload: null
|
|
785
925
|
});
|
|
786
926
|
bufferedNetworks.set(payload.runId, current);
|
|
787
927
|
return {
|
|
@@ -800,7 +940,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
800
940
|
name: payload.payload.agentId,
|
|
801
941
|
status: "success",
|
|
802
942
|
input: null,
|
|
803
|
-
output: payload.payload.result
|
|
943
|
+
output: payload.payload.result,
|
|
944
|
+
suspendPayload: null,
|
|
945
|
+
resumePayload: null
|
|
804
946
|
});
|
|
805
947
|
return {
|
|
806
948
|
type: isNested ? "data-tool-network" : "data-network",
|
|
@@ -820,7 +962,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
820
962
|
name: payload.payload.toolName,
|
|
821
963
|
status: "success",
|
|
822
964
|
input: null,
|
|
823
|
-
output: payload.payload.result
|
|
965
|
+
output: payload.payload.result,
|
|
966
|
+
suspendPayload: null,
|
|
967
|
+
resumePayload: null
|
|
824
968
|
});
|
|
825
969
|
return {
|
|
826
970
|
type: isNested ? "data-tool-network" : "data-network",
|
|
@@ -839,7 +983,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
839
983
|
name: payload.payload.name,
|
|
840
984
|
status: "success",
|
|
841
985
|
input: null,
|
|
842
|
-
output: payload.payload.result
|
|
986
|
+
output: payload.payload.result,
|
|
987
|
+
suspendPayload: null,
|
|
988
|
+
resumePayload: null
|
|
843
989
|
});
|
|
844
990
|
return {
|
|
845
991
|
type: isNested ? "data-tool-network" : "data-network",
|
|
@@ -903,13 +1049,35 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
903
1049
|
}
|
|
904
1050
|
return payload;
|
|
905
1051
|
}
|
|
1052
|
+
if (isAgentExecutionDataChunkType(payload)) {
|
|
1053
|
+
if (!("data" in payload.payload)) {
|
|
1054
|
+
throw new Error(
|
|
1055
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1056
|
+
${JSON.stringify(payload)}`
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
return payload.payload;
|
|
1060
|
+
}
|
|
1061
|
+
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
1062
|
+
if (!("data" in payload.payload)) {
|
|
1063
|
+
throw new Error(
|
|
1064
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1065
|
+
${JSON.stringify(payload)}`
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
return payload.payload;
|
|
1069
|
+
}
|
|
906
1070
|
return null;
|
|
907
1071
|
}
|
|
908
1072
|
}
|
|
909
1073
|
}
|
|
910
1074
|
|
|
911
|
-
// src/
|
|
912
|
-
function
|
|
1075
|
+
// src/convert-streams.ts
|
|
1076
|
+
function toAISdkV5Stream(stream, options = {
|
|
1077
|
+
from: "agent",
|
|
1078
|
+
sendStart: true,
|
|
1079
|
+
sendFinish: true
|
|
1080
|
+
}) {
|
|
913
1081
|
const from = options?.from;
|
|
914
1082
|
if (from === "workflow") {
|
|
915
1083
|
return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
|
|
@@ -918,14 +1086,28 @@ function toAISdkFormat(stream, options = { from: "agent" }) {
|
|
|
918
1086
|
return stream.pipeThrough(AgentNetworkToAISDKTransformer());
|
|
919
1087
|
}
|
|
920
1088
|
const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
|
|
921
|
-
return agentReadable.pipeThrough(
|
|
1089
|
+
return agentReadable.pipeThrough(
|
|
1090
|
+
AgentStreamToAISDKTransformer({
|
|
1091
|
+
lastMessageId: options?.lastMessageId,
|
|
1092
|
+
sendStart: options?.sendStart,
|
|
1093
|
+
sendFinish: options?.sendFinish,
|
|
1094
|
+
sendReasoning: options?.sendReasoning,
|
|
1095
|
+
sendSources: options?.sendSources,
|
|
1096
|
+
messageMetadata: options?.messageMetadata,
|
|
1097
|
+
onError: options?.onError
|
|
1098
|
+
})
|
|
1099
|
+
);
|
|
922
1100
|
}
|
|
923
1101
|
|
|
924
1102
|
// src/chat-route.ts
|
|
925
1103
|
function chatRoute({
|
|
926
1104
|
path = "/chat/:agentId",
|
|
927
1105
|
agent,
|
|
928
|
-
defaultOptions
|
|
1106
|
+
defaultOptions,
|
|
1107
|
+
sendStart = true,
|
|
1108
|
+
sendFinish = true,
|
|
1109
|
+
sendReasoning = false,
|
|
1110
|
+
sendSources = false
|
|
929
1111
|
}) {
|
|
930
1112
|
if (!agent && !path.includes("/:agentId")) {
|
|
931
1113
|
throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
|
|
@@ -1026,7 +1208,7 @@ function chatRoute({
|
|
|
1026
1208
|
handler: async (c) => {
|
|
1027
1209
|
const { messages, ...rest } = await c.req.json();
|
|
1028
1210
|
const mastra = c.get("mastra");
|
|
1029
|
-
const
|
|
1211
|
+
const requestContext = c.get("requestContext");
|
|
1030
1212
|
let agentToUse = agent;
|
|
1031
1213
|
if (!agent) {
|
|
1032
1214
|
const agentId = c.req.param("agentId");
|
|
@@ -1037,8 +1219,8 @@ function chatRoute({
|
|
|
1037
1219
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
1038
1220
|
);
|
|
1039
1221
|
}
|
|
1040
|
-
if (
|
|
1041
|
-
mastra.getLogger()?.warn(`"
|
|
1222
|
+
if (requestContext && defaultOptions?.requestContext) {
|
|
1223
|
+
mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
|
|
1042
1224
|
}
|
|
1043
1225
|
if (!agentToUse) {
|
|
1044
1226
|
throw new Error("Agent ID is required");
|
|
@@ -1050,12 +1232,23 @@ function chatRoute({
|
|
|
1050
1232
|
const result = await agentObj.stream(messages, {
|
|
1051
1233
|
...defaultOptions,
|
|
1052
1234
|
...rest,
|
|
1053
|
-
|
|
1235
|
+
requestContext: requestContext || defaultOptions?.requestContext
|
|
1054
1236
|
});
|
|
1237
|
+
let lastMessageId;
|
|
1238
|
+
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1239
|
+
lastMessageId = messages[messages.length - 1].id;
|
|
1240
|
+
}
|
|
1055
1241
|
const uiMessageStream = ai.createUIMessageStream({
|
|
1056
1242
|
originalMessages: messages,
|
|
1057
1243
|
execute: async ({ writer }) => {
|
|
1058
|
-
for await (const part of
|
|
1244
|
+
for await (const part of toAISdkV5Stream(result, {
|
|
1245
|
+
from: "agent",
|
|
1246
|
+
lastMessageId,
|
|
1247
|
+
sendStart,
|
|
1248
|
+
sendFinish,
|
|
1249
|
+
sendReasoning,
|
|
1250
|
+
sendSources
|
|
1251
|
+
})) {
|
|
1059
1252
|
writer.write(part);
|
|
1060
1253
|
}
|
|
1061
1254
|
}
|
|
@@ -1095,9 +1288,13 @@ function workflowRoute({
|
|
|
1095
1288
|
schema: {
|
|
1096
1289
|
type: "object",
|
|
1097
1290
|
properties: {
|
|
1291
|
+
runId: { type: "string" },
|
|
1292
|
+
resourceId: { type: "string" },
|
|
1098
1293
|
inputData: { type: "object", additionalProperties: true },
|
|
1099
|
-
|
|
1100
|
-
|
|
1294
|
+
resumeData: { type: "object", additionalProperties: true },
|
|
1295
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1296
|
+
tracingOptions: { type: "object", additionalProperties: true },
|
|
1297
|
+
step: { type: "string" }
|
|
1101
1298
|
}
|
|
1102
1299
|
}
|
|
1103
1300
|
}
|
|
@@ -1115,7 +1312,7 @@ function workflowRoute({
|
|
|
1115
1312
|
}
|
|
1116
1313
|
},
|
|
1117
1314
|
handler: async (c) => {
|
|
1118
|
-
const { inputData, ...rest } = await c.req.json();
|
|
1315
|
+
const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
|
|
1119
1316
|
const mastra = c.get("mastra");
|
|
1120
1317
|
let workflowToUse = workflow;
|
|
1121
1318
|
if (!workflow) {
|
|
@@ -1134,11 +1331,11 @@ function workflowRoute({
|
|
|
1134
1331
|
if (!workflowObj) {
|
|
1135
1332
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1136
1333
|
}
|
|
1137
|
-
const run = await workflowObj.
|
|
1138
|
-
const stream = run.
|
|
1334
|
+
const run = await workflowObj.createRun({ runId, resourceId, ...rest });
|
|
1335
|
+
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1139
1336
|
const uiMessageStream = ai.createUIMessageStream({
|
|
1140
1337
|
execute: async ({ writer }) => {
|
|
1141
|
-
for await (const part of
|
|
1338
|
+
for await (const part of toAISdkV5Stream(stream, { from: "workflow" })) {
|
|
1142
1339
|
writer.write(part);
|
|
1143
1340
|
}
|
|
1144
1341
|
}
|
|
@@ -1178,7 +1375,7 @@ function networkRoute({
|
|
|
1178
1375
|
type: "object",
|
|
1179
1376
|
properties: {
|
|
1180
1377
|
messages: { type: "array", items: { type: "object" } },
|
|
1181
|
-
|
|
1378
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1182
1379
|
runId: { type: "string" },
|
|
1183
1380
|
maxSteps: { type: "number" },
|
|
1184
1381
|
threadId: { type: "string" },
|
|
@@ -1232,7 +1429,7 @@ function networkRoute({
|
|
|
1232
1429
|
});
|
|
1233
1430
|
const uiMessageStream = ai.createUIMessageStream({
|
|
1234
1431
|
execute: async ({ writer }) => {
|
|
1235
|
-
for await (const part of
|
|
1432
|
+
for await (const part of toAISdkV5Stream(result, { from: "network" })) {
|
|
1236
1433
|
writer.write(part);
|
|
1237
1434
|
}
|
|
1238
1435
|
}
|
|
@@ -1242,9 +1439,17 @@ function networkRoute({
|
|
|
1242
1439
|
});
|
|
1243
1440
|
}
|
|
1244
1441
|
|
|
1442
|
+
// src/to-ai-sdk-format.ts
|
|
1443
|
+
function toAISdkFormat() {
|
|
1444
|
+
throw new Error(
|
|
1445
|
+
'toAISdkFormat() has been deprecated. Please use toAISdkStream() instead.\n\nMigration:\n import { toAISdkFormat } from "@mastra/ai-sdk";\n // Change to:\n import { toAISdkStream } from "@mastra/ai-sdk";\n\nThe function signature remains the same.'
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1245
1449
|
exports.chatRoute = chatRoute;
|
|
1246
1450
|
exports.networkRoute = networkRoute;
|
|
1247
1451
|
exports.toAISdkFormat = toAISdkFormat;
|
|
1452
|
+
exports.toAISdkStream = toAISdkV5Stream;
|
|
1248
1453
|
exports.workflowRoute = workflowRoute;
|
|
1249
1454
|
//# sourceMappingURL=index.cjs.map
|
|
1250
1455
|
//# sourceMappingURL=index.cjs.map
|