@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.js
CHANGED
|
@@ -8,6 +8,26 @@ import { DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core
|
|
|
8
8
|
var isDataChunkType = (chunk) => {
|
|
9
9
|
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
|
|
10
10
|
};
|
|
11
|
+
function safeParseErrorObject(obj) {
|
|
12
|
+
if (typeof obj !== "object" || obj === null) {
|
|
13
|
+
return String(obj);
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const stringified = JSON.stringify(obj);
|
|
17
|
+
if (stringified === "{}") {
|
|
18
|
+
return String(obj);
|
|
19
|
+
}
|
|
20
|
+
return stringified;
|
|
21
|
+
} catch {
|
|
22
|
+
return String(obj);
|
|
23
|
+
}
|
|
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
|
+
};
|
|
11
31
|
|
|
12
32
|
// src/helpers.ts
|
|
13
33
|
function convertMastraChunkToAISDKv5({
|
|
@@ -118,6 +138,28 @@ function convertMastraChunkToAISDKv5({
|
|
|
118
138
|
toolName: chunk.payload.toolName,
|
|
119
139
|
input: chunk.payload.args
|
|
120
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
|
+
};
|
|
121
163
|
case "tool-call-input-streaming-start":
|
|
122
164
|
return {
|
|
123
165
|
type: "tool-input-start",
|
|
@@ -208,6 +250,13 @@ function convertMastraChunkToAISDKv5({
|
|
|
208
250
|
type: "object",
|
|
209
251
|
object: chunk.object
|
|
210
252
|
};
|
|
253
|
+
case "tripwire":
|
|
254
|
+
return {
|
|
255
|
+
type: "data-tripwire",
|
|
256
|
+
data: {
|
|
257
|
+
tripwireReason: chunk.payload.tripwireReason
|
|
258
|
+
}
|
|
259
|
+
};
|
|
211
260
|
default:
|
|
212
261
|
if (chunk.type && "payload" in chunk && chunk.payload) {
|
|
213
262
|
return {
|
|
@@ -263,6 +312,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
263
312
|
};
|
|
264
313
|
}
|
|
265
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
|
+
}
|
|
266
323
|
return;
|
|
267
324
|
}
|
|
268
325
|
case "reasoning-end": {
|
|
@@ -280,6 +337,25 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
280
337
|
};
|
|
281
338
|
}
|
|
282
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
|
+
}
|
|
283
359
|
return;
|
|
284
360
|
}
|
|
285
361
|
case "tool-input-start": {
|
|
@@ -337,6 +413,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
337
413
|
toolCallId: part.toolCallId,
|
|
338
414
|
payload: part.output
|
|
339
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;
|
|
340
424
|
}
|
|
341
425
|
return;
|
|
342
426
|
}
|
|
@@ -362,21 +446,23 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
362
446
|
return { type: "finish-step" };
|
|
363
447
|
}
|
|
364
448
|
case "start": {
|
|
365
|
-
{
|
|
449
|
+
if (sendStart) {
|
|
366
450
|
return {
|
|
367
451
|
type: "start",
|
|
368
452
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
|
|
369
453
|
...responseMessageId != null ? { messageId: responseMessageId } : {}
|
|
370
454
|
};
|
|
371
455
|
}
|
|
456
|
+
return;
|
|
372
457
|
}
|
|
373
458
|
case "finish": {
|
|
374
|
-
{
|
|
459
|
+
if (sendFinish) {
|
|
375
460
|
return {
|
|
376
461
|
type: "finish",
|
|
377
462
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
|
|
378
463
|
};
|
|
379
464
|
}
|
|
465
|
+
return;
|
|
380
466
|
}
|
|
381
467
|
case "abort": {
|
|
382
468
|
return part;
|
|
@@ -441,20 +527,37 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
441
527
|
}
|
|
442
528
|
});
|
|
443
529
|
}
|
|
444
|
-
function AgentStreamToAISDKTransformer(
|
|
530
|
+
function AgentStreamToAISDKTransformer({
|
|
531
|
+
lastMessageId,
|
|
532
|
+
sendStart,
|
|
533
|
+
sendFinish,
|
|
534
|
+
sendReasoning,
|
|
535
|
+
sendSources,
|
|
536
|
+
messageMetadata,
|
|
537
|
+
onError
|
|
538
|
+
}) {
|
|
445
539
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
540
|
+
let tripwireOccurred = false;
|
|
541
|
+
let finishEventSent = false;
|
|
446
542
|
return new TransformStream({
|
|
447
543
|
transform(chunk, controller) {
|
|
544
|
+
if (chunk.type === "tripwire") {
|
|
545
|
+
tripwireOccurred = true;
|
|
546
|
+
}
|
|
547
|
+
if (chunk.type === "finish") {
|
|
548
|
+
finishEventSent = true;
|
|
549
|
+
}
|
|
448
550
|
const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
|
|
449
551
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
450
552
|
part,
|
|
451
|
-
sendReasoning
|
|
452
|
-
sendSources
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
553
|
+
sendReasoning,
|
|
554
|
+
sendSources,
|
|
555
|
+
messageMetadataValue: messageMetadata?.({ part }),
|
|
556
|
+
sendStart,
|
|
557
|
+
sendFinish,
|
|
558
|
+
responseMessageId: lastMessageId,
|
|
559
|
+
onError(error) {
|
|
560
|
+
return onError ? onError(error) : safeParseErrorObject(error);
|
|
458
561
|
}
|
|
459
562
|
});
|
|
460
563
|
if (transformedChunk) {
|
|
@@ -474,6 +577,14 @@ function AgentStreamToAISDKTransformer() {
|
|
|
474
577
|
controller.enqueue(transformedChunk);
|
|
475
578
|
}
|
|
476
579
|
}
|
|
580
|
+
},
|
|
581
|
+
flush(controller) {
|
|
582
|
+
if (tripwireOccurred && !finishEventSent && sendFinish) {
|
|
583
|
+
controller.enqueue({
|
|
584
|
+
type: "finish",
|
|
585
|
+
finishReason: "other"
|
|
586
|
+
});
|
|
587
|
+
}
|
|
477
588
|
}
|
|
478
589
|
});
|
|
479
590
|
}
|
|
@@ -636,7 +747,9 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
636
747
|
name: payload.payload.id,
|
|
637
748
|
status: payload.payload.status,
|
|
638
749
|
input: payload.payload.payload ?? null,
|
|
639
|
-
output: null
|
|
750
|
+
output: null,
|
|
751
|
+
suspendPayload: null,
|
|
752
|
+
resumePayload: null
|
|
640
753
|
};
|
|
641
754
|
bufferedWorkflows.set(payload.runId, current);
|
|
642
755
|
return {
|
|
@@ -669,6 +782,27 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
669
782
|
}
|
|
670
783
|
};
|
|
671
784
|
}
|
|
785
|
+
case "workflow-step-suspended": {
|
|
786
|
+
const current = bufferedWorkflows.get(payload.runId);
|
|
787
|
+
if (!current) return null;
|
|
788
|
+
current.steps[payload.payload.id] = {
|
|
789
|
+
...current.steps[payload.payload.id],
|
|
790
|
+
status: payload.payload.status,
|
|
791
|
+
suspendPayload: payload.payload.suspendPayload ?? null,
|
|
792
|
+
resumePayload: payload.payload.resumePayload ?? null,
|
|
793
|
+
output: null
|
|
794
|
+
};
|
|
795
|
+
return {
|
|
796
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
797
|
+
id: payload.runId,
|
|
798
|
+
data: {
|
|
799
|
+
name: current.name,
|
|
800
|
+
status: "suspended",
|
|
801
|
+
steps: current.steps,
|
|
802
|
+
output: null
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
}
|
|
672
806
|
case "workflow-finish": {
|
|
673
807
|
const current = bufferedWorkflows.get(payload.runId);
|
|
674
808
|
if (!current) return null;
|
|
@@ -743,7 +877,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
743
877
|
name: payload.payload.agentId,
|
|
744
878
|
status: "running",
|
|
745
879
|
input: payload.payload.args || null,
|
|
746
|
-
output: null
|
|
880
|
+
output: null,
|
|
881
|
+
suspendPayload: null,
|
|
882
|
+
resumePayload: null
|
|
747
883
|
});
|
|
748
884
|
bufferedNetworks.set(payload.runId, current);
|
|
749
885
|
return {
|
|
@@ -761,7 +897,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
761
897
|
name: payload.payload.name,
|
|
762
898
|
status: "running",
|
|
763
899
|
input: payload.payload.args || null,
|
|
764
|
-
output: null
|
|
900
|
+
output: null,
|
|
901
|
+
suspendPayload: null,
|
|
902
|
+
resumePayload: null
|
|
765
903
|
});
|
|
766
904
|
bufferedNetworks.set(payload.runId, current);
|
|
767
905
|
return {
|
|
@@ -779,7 +917,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
779
917
|
name: payload.payload.args?.toolName,
|
|
780
918
|
status: "running",
|
|
781
919
|
input: payload.payload.args?.args || null,
|
|
782
|
-
output: null
|
|
920
|
+
output: null,
|
|
921
|
+
suspendPayload: null,
|
|
922
|
+
resumePayload: null
|
|
783
923
|
});
|
|
784
924
|
bufferedNetworks.set(payload.runId, current);
|
|
785
925
|
return {
|
|
@@ -798,7 +938,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
798
938
|
name: payload.payload.agentId,
|
|
799
939
|
status: "success",
|
|
800
940
|
input: null,
|
|
801
|
-
output: payload.payload.result
|
|
941
|
+
output: payload.payload.result,
|
|
942
|
+
suspendPayload: null,
|
|
943
|
+
resumePayload: null
|
|
802
944
|
});
|
|
803
945
|
return {
|
|
804
946
|
type: isNested ? "data-tool-network" : "data-network",
|
|
@@ -818,7 +960,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
818
960
|
name: payload.payload.toolName,
|
|
819
961
|
status: "success",
|
|
820
962
|
input: null,
|
|
821
|
-
output: payload.payload.result
|
|
963
|
+
output: payload.payload.result,
|
|
964
|
+
suspendPayload: null,
|
|
965
|
+
resumePayload: null
|
|
822
966
|
});
|
|
823
967
|
return {
|
|
824
968
|
type: isNested ? "data-tool-network" : "data-network",
|
|
@@ -837,7 +981,9 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
837
981
|
name: payload.payload.name,
|
|
838
982
|
status: "success",
|
|
839
983
|
input: null,
|
|
840
|
-
output: payload.payload.result
|
|
984
|
+
output: payload.payload.result,
|
|
985
|
+
suspendPayload: null,
|
|
986
|
+
resumePayload: null
|
|
841
987
|
});
|
|
842
988
|
return {
|
|
843
989
|
type: isNested ? "data-tool-network" : "data-network",
|
|
@@ -901,13 +1047,35 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
901
1047
|
}
|
|
902
1048
|
return payload;
|
|
903
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
|
+
}
|
|
904
1068
|
return null;
|
|
905
1069
|
}
|
|
906
1070
|
}
|
|
907
1071
|
}
|
|
908
1072
|
|
|
909
|
-
// src/
|
|
910
|
-
function
|
|
1073
|
+
// src/convert-streams.ts
|
|
1074
|
+
function toAISdkV5Stream(stream, options = {
|
|
1075
|
+
from: "agent",
|
|
1076
|
+
sendStart: true,
|
|
1077
|
+
sendFinish: true
|
|
1078
|
+
}) {
|
|
911
1079
|
const from = options?.from;
|
|
912
1080
|
if (from === "workflow") {
|
|
913
1081
|
return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
|
|
@@ -916,14 +1084,28 @@ function toAISdkFormat(stream, options = { from: "agent" }) {
|
|
|
916
1084
|
return stream.pipeThrough(AgentNetworkToAISDKTransformer());
|
|
917
1085
|
}
|
|
918
1086
|
const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
|
|
919
|
-
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
|
+
);
|
|
920
1098
|
}
|
|
921
1099
|
|
|
922
1100
|
// src/chat-route.ts
|
|
923
1101
|
function chatRoute({
|
|
924
1102
|
path = "/chat/:agentId",
|
|
925
1103
|
agent,
|
|
926
|
-
defaultOptions
|
|
1104
|
+
defaultOptions,
|
|
1105
|
+
sendStart = true,
|
|
1106
|
+
sendFinish = true,
|
|
1107
|
+
sendReasoning = false,
|
|
1108
|
+
sendSources = false
|
|
927
1109
|
}) {
|
|
928
1110
|
if (!agent && !path.includes("/:agentId")) {
|
|
929
1111
|
throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
|
|
@@ -1024,7 +1206,7 @@ function chatRoute({
|
|
|
1024
1206
|
handler: async (c) => {
|
|
1025
1207
|
const { messages, ...rest } = await c.req.json();
|
|
1026
1208
|
const mastra = c.get("mastra");
|
|
1027
|
-
const
|
|
1209
|
+
const requestContext = c.get("requestContext");
|
|
1028
1210
|
let agentToUse = agent;
|
|
1029
1211
|
if (!agent) {
|
|
1030
1212
|
const agentId = c.req.param("agentId");
|
|
@@ -1035,8 +1217,8 @@ function chatRoute({
|
|
|
1035
1217
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
1036
1218
|
);
|
|
1037
1219
|
}
|
|
1038
|
-
if (
|
|
1039
|
-
mastra.getLogger()?.warn(`"
|
|
1220
|
+
if (requestContext && defaultOptions?.requestContext) {
|
|
1221
|
+
mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
|
|
1040
1222
|
}
|
|
1041
1223
|
if (!agentToUse) {
|
|
1042
1224
|
throw new Error("Agent ID is required");
|
|
@@ -1048,12 +1230,23 @@ function chatRoute({
|
|
|
1048
1230
|
const result = await agentObj.stream(messages, {
|
|
1049
1231
|
...defaultOptions,
|
|
1050
1232
|
...rest,
|
|
1051
|
-
|
|
1233
|
+
requestContext: requestContext || defaultOptions?.requestContext
|
|
1052
1234
|
});
|
|
1235
|
+
let lastMessageId;
|
|
1236
|
+
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1237
|
+
lastMessageId = messages[messages.length - 1].id;
|
|
1238
|
+
}
|
|
1053
1239
|
const uiMessageStream = createUIMessageStream({
|
|
1054
1240
|
originalMessages: messages,
|
|
1055
1241
|
execute: async ({ writer }) => {
|
|
1056
|
-
for await (const part of
|
|
1242
|
+
for await (const part of toAISdkV5Stream(result, {
|
|
1243
|
+
from: "agent",
|
|
1244
|
+
lastMessageId,
|
|
1245
|
+
sendStart,
|
|
1246
|
+
sendFinish,
|
|
1247
|
+
sendReasoning,
|
|
1248
|
+
sendSources
|
|
1249
|
+
})) {
|
|
1057
1250
|
writer.write(part);
|
|
1058
1251
|
}
|
|
1059
1252
|
}
|
|
@@ -1093,9 +1286,13 @@ function workflowRoute({
|
|
|
1093
1286
|
schema: {
|
|
1094
1287
|
type: "object",
|
|
1095
1288
|
properties: {
|
|
1289
|
+
runId: { type: "string" },
|
|
1290
|
+
resourceId: { type: "string" },
|
|
1096
1291
|
inputData: { type: "object", additionalProperties: true },
|
|
1097
|
-
|
|
1098
|
-
|
|
1292
|
+
resumeData: { type: "object", additionalProperties: true },
|
|
1293
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1294
|
+
tracingOptions: { type: "object", additionalProperties: true },
|
|
1295
|
+
step: { type: "string" }
|
|
1099
1296
|
}
|
|
1100
1297
|
}
|
|
1101
1298
|
}
|
|
@@ -1113,7 +1310,7 @@ function workflowRoute({
|
|
|
1113
1310
|
}
|
|
1114
1311
|
},
|
|
1115
1312
|
handler: async (c) => {
|
|
1116
|
-
const { inputData, ...rest } = await c.req.json();
|
|
1313
|
+
const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
|
|
1117
1314
|
const mastra = c.get("mastra");
|
|
1118
1315
|
let workflowToUse = workflow;
|
|
1119
1316
|
if (!workflow) {
|
|
@@ -1132,11 +1329,11 @@ function workflowRoute({
|
|
|
1132
1329
|
if (!workflowObj) {
|
|
1133
1330
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1134
1331
|
}
|
|
1135
|
-
const run = await workflowObj.
|
|
1136
|
-
const stream = run.
|
|
1332
|
+
const run = await workflowObj.createRun({ runId, resourceId, ...rest });
|
|
1333
|
+
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1137
1334
|
const uiMessageStream = createUIMessageStream({
|
|
1138
1335
|
execute: async ({ writer }) => {
|
|
1139
|
-
for await (const part of
|
|
1336
|
+
for await (const part of toAISdkV5Stream(stream, { from: "workflow" })) {
|
|
1140
1337
|
writer.write(part);
|
|
1141
1338
|
}
|
|
1142
1339
|
}
|
|
@@ -1176,7 +1373,7 @@ function networkRoute({
|
|
|
1176
1373
|
type: "object",
|
|
1177
1374
|
properties: {
|
|
1178
1375
|
messages: { type: "array", items: { type: "object" } },
|
|
1179
|
-
|
|
1376
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1180
1377
|
runId: { type: "string" },
|
|
1181
1378
|
maxSteps: { type: "number" },
|
|
1182
1379
|
threadId: { type: "string" },
|
|
@@ -1230,7 +1427,7 @@ function networkRoute({
|
|
|
1230
1427
|
});
|
|
1231
1428
|
const uiMessageStream = createUIMessageStream({
|
|
1232
1429
|
execute: async ({ writer }) => {
|
|
1233
|
-
for await (const part of
|
|
1430
|
+
for await (const part of toAISdkV5Stream(result, { from: "network" })) {
|
|
1234
1431
|
writer.write(part);
|
|
1235
1432
|
}
|
|
1236
1433
|
}
|
|
@@ -1240,6 +1437,13 @@ function networkRoute({
|
|
|
1240
1437
|
});
|
|
1241
1438
|
}
|
|
1242
1439
|
|
|
1243
|
-
|
|
1440
|
+
// src/to-ai-sdk-format.ts
|
|
1441
|
+
function toAISdkFormat() {
|
|
1442
|
+
throw new Error(
|
|
1443
|
+
'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.'
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
export { chatRoute, networkRoute, toAISdkFormat, toAISdkV5Stream as toAISdkStream, workflowRoute };
|
|
1244
1448
|
//# sourceMappingURL=index.js.map
|
|
1245
1449
|
//# sourceMappingURL=index.js.map
|