@mastra/ai-sdk 0.0.0-usechat-duplicate-20251016110554 → 0.0.0-vnext-20251104230439
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 +102 -4
- 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 +18 -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 +191 -81
- 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 +191 -82
- package/dist/index.js.map +1 -1
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +15 -13
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts +50 -24
- 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 +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +16 -6
package/dist/index.js
CHANGED
|
@@ -3,6 +3,27 @@ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai';
|
|
|
3
3
|
import { DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core/stream';
|
|
4
4
|
|
|
5
5
|
// src/chat-route.ts
|
|
6
|
+
|
|
7
|
+
// src/utils.ts
|
|
8
|
+
var isDataChunkType = (chunk) => {
|
|
9
|
+
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
|
|
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
|
+
|
|
26
|
+
// src/helpers.ts
|
|
6
27
|
function convertMastraChunkToAISDKv5({
|
|
7
28
|
chunk,
|
|
8
29
|
mode = "stream"
|
|
@@ -208,6 +229,9 @@ function convertMastraChunkToAISDKv5({
|
|
|
208
229
|
...chunk.payload || {}
|
|
209
230
|
};
|
|
210
231
|
}
|
|
232
|
+
if ("type" in chunk && chunk.type?.startsWith("data-")) {
|
|
233
|
+
return chunk;
|
|
234
|
+
}
|
|
211
235
|
return;
|
|
212
236
|
}
|
|
213
237
|
}
|
|
@@ -221,7 +245,7 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
221
245
|
sendFinish,
|
|
222
246
|
responseMessageId
|
|
223
247
|
}) {
|
|
224
|
-
const partType = part
|
|
248
|
+
const partType = part?.type;
|
|
225
249
|
switch (partType) {
|
|
226
250
|
case "text-start": {
|
|
227
251
|
return {
|
|
@@ -378,8 +402,16 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
378
402
|
return;
|
|
379
403
|
}
|
|
380
404
|
default: {
|
|
381
|
-
|
|
382
|
-
|
|
405
|
+
if (isDataChunkType(part)) {
|
|
406
|
+
if (!("data" in part)) {
|
|
407
|
+
throw new Error(
|
|
408
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
409
|
+
${JSON.stringify(part)}`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
return part;
|
|
413
|
+
}
|
|
414
|
+
return;
|
|
383
415
|
}
|
|
384
416
|
}
|
|
385
417
|
}
|
|
@@ -423,7 +455,7 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
423
455
|
}
|
|
424
456
|
});
|
|
425
457
|
}
|
|
426
|
-
function AgentStreamToAISDKTransformer() {
|
|
458
|
+
function AgentStreamToAISDKTransformer(lastMessageId) {
|
|
427
459
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
428
460
|
return new TransformStream({
|
|
429
461
|
transform(chunk, controller) {
|
|
@@ -434,9 +466,9 @@ function AgentStreamToAISDKTransformer() {
|
|
|
434
466
|
sendSources: false,
|
|
435
467
|
sendStart: true,
|
|
436
468
|
sendFinish: true,
|
|
437
|
-
responseMessageId:
|
|
438
|
-
onError() {
|
|
439
|
-
return
|
|
469
|
+
responseMessageId: lastMessageId,
|
|
470
|
+
onError(error) {
|
|
471
|
+
return safeParseErrorObject(error);
|
|
440
472
|
}
|
|
441
473
|
});
|
|
442
474
|
if (transformedChunk) {
|
|
@@ -618,7 +650,9 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
618
650
|
name: payload.payload.id,
|
|
619
651
|
status: payload.payload.status,
|
|
620
652
|
input: payload.payload.payload ?? null,
|
|
621
|
-
output: null
|
|
653
|
+
output: null,
|
|
654
|
+
suspendPayload: null,
|
|
655
|
+
resumePayload: null
|
|
622
656
|
};
|
|
623
657
|
bufferedWorkflows.set(payload.runId, current);
|
|
624
658
|
return {
|
|
@@ -651,6 +685,27 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
651
685
|
}
|
|
652
686
|
};
|
|
653
687
|
}
|
|
688
|
+
case "workflow-step-suspended": {
|
|
689
|
+
const current = bufferedWorkflows.get(payload.runId);
|
|
690
|
+
if (!current) return null;
|
|
691
|
+
current.steps[payload.payload.id] = {
|
|
692
|
+
...current.steps[payload.payload.id],
|
|
693
|
+
status: payload.payload.status,
|
|
694
|
+
suspendPayload: payload.payload.suspendPayload ?? null,
|
|
695
|
+
resumePayload: payload.payload.resumePayload ?? null,
|
|
696
|
+
output: null
|
|
697
|
+
};
|
|
698
|
+
return {
|
|
699
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
700
|
+
id: payload.runId,
|
|
701
|
+
data: {
|
|
702
|
+
name: current.name,
|
|
703
|
+
status: "suspended",
|
|
704
|
+
steps: current.steps,
|
|
705
|
+
output: null
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
654
709
|
case "workflow-finish": {
|
|
655
710
|
const current = bufferedWorkflows.get(payload.runId);
|
|
656
711
|
if (!current) return null;
|
|
@@ -665,87 +720,117 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
665
720
|
}
|
|
666
721
|
};
|
|
667
722
|
}
|
|
668
|
-
default:
|
|
723
|
+
default: {
|
|
724
|
+
if (isDataChunkType(payload)) {
|
|
725
|
+
if (!("data" in payload)) {
|
|
726
|
+
throw new Error(
|
|
727
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
728
|
+
${JSON.stringify(payload)}`
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
return payload;
|
|
732
|
+
}
|
|
669
733
|
return null;
|
|
734
|
+
}
|
|
670
735
|
}
|
|
671
736
|
}
|
|
672
737
|
function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
673
738
|
switch (payload.type) {
|
|
674
739
|
case "routing-agent-start": {
|
|
675
|
-
if (!bufferedNetworks.has(payload.
|
|
676
|
-
bufferedNetworks.set(payload.
|
|
740
|
+
if (!bufferedNetworks.has(payload.runId)) {
|
|
741
|
+
bufferedNetworks.set(payload.runId, {
|
|
677
742
|
name: payload.payload.agentId,
|
|
678
|
-
steps: []
|
|
743
|
+
steps: [],
|
|
744
|
+
usage: null,
|
|
745
|
+
output: null
|
|
679
746
|
});
|
|
680
747
|
}
|
|
681
748
|
return {
|
|
682
749
|
type: isNested ? "data-tool-network" : "data-network",
|
|
683
|
-
id: payload.
|
|
750
|
+
id: payload.runId,
|
|
684
751
|
data: {
|
|
685
|
-
name: bufferedNetworks.get(payload.
|
|
752
|
+
name: bufferedNetworks.get(payload.runId).name,
|
|
686
753
|
status: "running",
|
|
687
|
-
|
|
754
|
+
usage: null,
|
|
755
|
+
steps: bufferedNetworks.get(payload.runId).steps,
|
|
688
756
|
output: null
|
|
689
757
|
}
|
|
690
758
|
};
|
|
691
759
|
}
|
|
760
|
+
case "routing-agent-text-start": {
|
|
761
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
762
|
+
if (!current) return null;
|
|
763
|
+
return {
|
|
764
|
+
type: "text-start",
|
|
765
|
+
id: payload.runId
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
case "routing-agent-text-delta": {
|
|
769
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
770
|
+
if (!current) return null;
|
|
771
|
+
return {
|
|
772
|
+
type: "text-delta",
|
|
773
|
+
id: payload.runId,
|
|
774
|
+
delta: payload.payload.text
|
|
775
|
+
};
|
|
776
|
+
}
|
|
692
777
|
case "agent-execution-start": {
|
|
693
|
-
const current = bufferedNetworks.get(payload.
|
|
778
|
+
const current = bufferedNetworks.get(payload.runId) || { name: "", steps: [], usage: null, output: null };
|
|
694
779
|
current.steps.push({
|
|
695
780
|
name: payload.payload.agentId,
|
|
696
781
|
status: "running",
|
|
697
782
|
input: payload.payload.args || null,
|
|
698
|
-
output: null
|
|
783
|
+
output: null,
|
|
784
|
+
suspendPayload: null,
|
|
785
|
+
resumePayload: null
|
|
699
786
|
});
|
|
700
|
-
bufferedNetworks.set(payload.
|
|
787
|
+
bufferedNetworks.set(payload.runId, current);
|
|
701
788
|
return {
|
|
702
789
|
type: isNested ? "data-tool-network" : "data-network",
|
|
703
|
-
id: payload.
|
|
790
|
+
id: payload.runId,
|
|
704
791
|
data: {
|
|
705
|
-
|
|
706
|
-
status: "running"
|
|
707
|
-
steps: current.steps,
|
|
708
|
-
output: null
|
|
792
|
+
...current,
|
|
793
|
+
status: "running"
|
|
709
794
|
}
|
|
710
795
|
};
|
|
711
796
|
}
|
|
712
797
|
case "workflow-execution-start": {
|
|
713
|
-
const current = bufferedNetworks.get(payload.
|
|
798
|
+
const current = bufferedNetworks.get(payload.runId) || { name: "", steps: [], usage: null, output: null };
|
|
714
799
|
current.steps.push({
|
|
715
800
|
name: payload.payload.name,
|
|
716
801
|
status: "running",
|
|
717
802
|
input: payload.payload.args || null,
|
|
718
|
-
output: null
|
|
803
|
+
output: null,
|
|
804
|
+
suspendPayload: null,
|
|
805
|
+
resumePayload: null
|
|
719
806
|
});
|
|
720
|
-
bufferedNetworks.set(payload.
|
|
807
|
+
bufferedNetworks.set(payload.runId, current);
|
|
721
808
|
return {
|
|
722
809
|
type: isNested ? "data-tool-network" : "data-network",
|
|
723
|
-
id: payload.
|
|
810
|
+
id: payload.runId,
|
|
724
811
|
data: {
|
|
725
|
-
|
|
726
|
-
status: "running"
|
|
727
|
-
steps: current.steps,
|
|
728
|
-
output: null
|
|
812
|
+
...current,
|
|
813
|
+
status: "running"
|
|
729
814
|
}
|
|
730
815
|
};
|
|
731
816
|
}
|
|
732
817
|
case "tool-execution-start": {
|
|
733
|
-
const current = bufferedNetworks.get(payload.
|
|
818
|
+
const current = bufferedNetworks.get(payload.runId) || { name: "", steps: [], usage: null, output: null };
|
|
734
819
|
current.steps.push({
|
|
735
820
|
name: payload.payload.args?.toolName,
|
|
736
821
|
status: "running",
|
|
737
822
|
input: payload.payload.args?.args || null,
|
|
738
|
-
output: null
|
|
823
|
+
output: null,
|
|
824
|
+
suspendPayload: null,
|
|
825
|
+
resumePayload: null
|
|
739
826
|
});
|
|
740
|
-
bufferedNetworks.set(payload.
|
|
827
|
+
bufferedNetworks.set(payload.runId, current);
|
|
741
828
|
return {
|
|
742
829
|
type: isNested ? "data-tool-network" : "data-network",
|
|
743
|
-
id: payload.
|
|
830
|
+
id: payload.runId,
|
|
744
831
|
data: {
|
|
745
|
-
|
|
746
|
-
status: "running"
|
|
747
|
-
steps: current.steps,
|
|
748
|
-
output: null
|
|
832
|
+
...current,
|
|
833
|
+
status: "running"
|
|
749
834
|
}
|
|
750
835
|
};
|
|
751
836
|
}
|
|
@@ -756,16 +841,18 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
756
841
|
name: payload.payload.agentId,
|
|
757
842
|
status: "success",
|
|
758
843
|
input: null,
|
|
759
|
-
output: payload.payload.result
|
|
844
|
+
output: payload.payload.result,
|
|
845
|
+
suspendPayload: null,
|
|
846
|
+
resumePayload: null
|
|
760
847
|
});
|
|
761
848
|
return {
|
|
762
849
|
type: isNested ? "data-tool-network" : "data-network",
|
|
763
850
|
id: payload.runId,
|
|
764
851
|
data: {
|
|
765
|
-
|
|
852
|
+
...current,
|
|
853
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
766
854
|
status: "running",
|
|
767
|
-
|
|
768
|
-
output: payload.payload.result ?? null
|
|
855
|
+
output: payload.payload.result ?? current.output
|
|
769
856
|
}
|
|
770
857
|
};
|
|
771
858
|
}
|
|
@@ -776,16 +863,17 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
776
863
|
name: payload.payload.toolName,
|
|
777
864
|
status: "success",
|
|
778
865
|
input: null,
|
|
779
|
-
output: payload.payload.result
|
|
866
|
+
output: payload.payload.result,
|
|
867
|
+
suspendPayload: null,
|
|
868
|
+
resumePayload: null
|
|
780
869
|
});
|
|
781
870
|
return {
|
|
782
871
|
type: isNested ? "data-tool-network" : "data-network",
|
|
783
872
|
id: payload.runId,
|
|
784
873
|
data: {
|
|
785
|
-
|
|
874
|
+
...current,
|
|
786
875
|
status: "running",
|
|
787
|
-
|
|
788
|
-
output: payload.payload.result ?? null
|
|
876
|
+
output: payload.payload.result ?? current.output
|
|
789
877
|
}
|
|
790
878
|
};
|
|
791
879
|
}
|
|
@@ -796,44 +884,45 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
796
884
|
name: payload.payload.name,
|
|
797
885
|
status: "success",
|
|
798
886
|
input: null,
|
|
799
|
-
output: payload.payload.result
|
|
887
|
+
output: payload.payload.result,
|
|
888
|
+
suspendPayload: null,
|
|
889
|
+
resumePayload: null
|
|
800
890
|
});
|
|
801
891
|
return {
|
|
802
892
|
type: isNested ? "data-tool-network" : "data-network",
|
|
803
893
|
id: payload.runId,
|
|
804
894
|
data: {
|
|
805
|
-
|
|
895
|
+
...current,
|
|
896
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
806
897
|
status: "running",
|
|
807
|
-
|
|
808
|
-
output: payload.payload.result ?? null
|
|
898
|
+
output: payload.payload.result ?? current.output
|
|
809
899
|
}
|
|
810
900
|
};
|
|
811
901
|
}
|
|
812
902
|
case "routing-agent-end": {
|
|
813
|
-
const current = bufferedNetworks.get(payload.
|
|
903
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
814
904
|
if (!current) return null;
|
|
815
905
|
return {
|
|
816
906
|
type: isNested ? "data-tool-network" : "data-network",
|
|
817
|
-
id: payload.
|
|
907
|
+
id: payload.runId,
|
|
818
908
|
data: {
|
|
819
|
-
|
|
909
|
+
...current,
|
|
820
910
|
status: "finished",
|
|
821
|
-
|
|
822
|
-
output: payload.payload?.result ??
|
|
911
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
912
|
+
output: payload.payload?.result ?? current.output
|
|
823
913
|
}
|
|
824
914
|
};
|
|
825
915
|
}
|
|
826
916
|
case "network-execution-event-step-finish": {
|
|
827
|
-
const current = bufferedNetworks.get(payload.
|
|
917
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
828
918
|
if (!current) return null;
|
|
829
919
|
return {
|
|
830
920
|
type: isNested ? "data-tool-network" : "data-network",
|
|
831
|
-
id: payload.
|
|
921
|
+
id: payload.runId,
|
|
832
922
|
data: {
|
|
833
|
-
|
|
923
|
+
...current,
|
|
834
924
|
status: "finished",
|
|
835
|
-
|
|
836
|
-
output: payload.payload?.result ?? null
|
|
925
|
+
output: payload.payload?.result ?? current.output
|
|
837
926
|
}
|
|
838
927
|
};
|
|
839
928
|
}
|
|
@@ -844,20 +933,30 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
844
933
|
type: isNested ? "data-tool-network" : "data-network",
|
|
845
934
|
id: payload.runId,
|
|
846
935
|
data: {
|
|
847
|
-
|
|
936
|
+
...current,
|
|
937
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
848
938
|
status: "finished",
|
|
849
|
-
|
|
850
|
-
output: payload.payload?.result ?? null
|
|
939
|
+
output: payload.payload?.result ?? current.output
|
|
851
940
|
}
|
|
852
941
|
};
|
|
853
942
|
}
|
|
854
|
-
default:
|
|
943
|
+
default: {
|
|
944
|
+
if (isDataChunkType(payload)) {
|
|
945
|
+
if (!("data" in payload)) {
|
|
946
|
+
throw new Error(
|
|
947
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
948
|
+
${JSON.stringify(payload)}`
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
return payload;
|
|
952
|
+
}
|
|
855
953
|
return null;
|
|
954
|
+
}
|
|
856
955
|
}
|
|
857
956
|
}
|
|
858
957
|
|
|
859
|
-
// src/
|
|
860
|
-
function
|
|
958
|
+
// src/convert-streams.ts
|
|
959
|
+
function toAISdkV5Stream(stream, options = { from: "agent" }) {
|
|
861
960
|
const from = options?.from;
|
|
862
961
|
if (from === "workflow") {
|
|
863
962
|
return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
|
|
@@ -866,7 +965,7 @@ function toAISdkFormat(stream, options = { from: "agent" }) {
|
|
|
866
965
|
return stream.pipeThrough(AgentNetworkToAISDKTransformer());
|
|
867
966
|
}
|
|
868
967
|
const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
|
|
869
|
-
return agentReadable.pipeThrough(AgentStreamToAISDKTransformer());
|
|
968
|
+
return agentReadable.pipeThrough(AgentStreamToAISDKTransformer(options?.lastMessageId));
|
|
870
969
|
}
|
|
871
970
|
|
|
872
971
|
// src/chat-route.ts
|
|
@@ -974,7 +1073,7 @@ function chatRoute({
|
|
|
974
1073
|
handler: async (c) => {
|
|
975
1074
|
const { messages, ...rest } = await c.req.json();
|
|
976
1075
|
const mastra = c.get("mastra");
|
|
977
|
-
const
|
|
1076
|
+
const requestContext = c.get("requestContext");
|
|
978
1077
|
let agentToUse = agent;
|
|
979
1078
|
if (!agent) {
|
|
980
1079
|
const agentId = c.req.param("agentId");
|
|
@@ -985,8 +1084,8 @@ function chatRoute({
|
|
|
985
1084
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
986
1085
|
);
|
|
987
1086
|
}
|
|
988
|
-
if (
|
|
989
|
-
mastra.getLogger()?.warn(`"
|
|
1087
|
+
if (requestContext && defaultOptions?.requestContext) {
|
|
1088
|
+
mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
|
|
990
1089
|
}
|
|
991
1090
|
if (!agentToUse) {
|
|
992
1091
|
throw new Error("Agent ID is required");
|
|
@@ -998,12 +1097,16 @@ function chatRoute({
|
|
|
998
1097
|
const result = await agentObj.stream(messages, {
|
|
999
1098
|
...defaultOptions,
|
|
1000
1099
|
...rest,
|
|
1001
|
-
|
|
1100
|
+
requestContext: requestContext || defaultOptions?.requestContext
|
|
1002
1101
|
});
|
|
1102
|
+
let lastMessageId;
|
|
1103
|
+
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1104
|
+
lastMessageId = messages[messages.length - 1].id;
|
|
1105
|
+
}
|
|
1003
1106
|
const uiMessageStream = createUIMessageStream({
|
|
1004
1107
|
originalMessages: messages,
|
|
1005
1108
|
execute: async ({ writer }) => {
|
|
1006
|
-
for await (const part of
|
|
1109
|
+
for await (const part of toAISdkV5Stream(result, { from: "agent", lastMessageId })) {
|
|
1007
1110
|
writer.write(part);
|
|
1008
1111
|
}
|
|
1009
1112
|
}
|
|
@@ -1044,7 +1147,7 @@ function workflowRoute({
|
|
|
1044
1147
|
type: "object",
|
|
1045
1148
|
properties: {
|
|
1046
1149
|
inputData: { type: "object", additionalProperties: true },
|
|
1047
|
-
|
|
1150
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1048
1151
|
tracingOptions: { type: "object", additionalProperties: true }
|
|
1049
1152
|
}
|
|
1050
1153
|
}
|
|
@@ -1063,7 +1166,7 @@ function workflowRoute({
|
|
|
1063
1166
|
}
|
|
1064
1167
|
},
|
|
1065
1168
|
handler: async (c) => {
|
|
1066
|
-
const { inputData, ...rest } = await c.req.json();
|
|
1169
|
+
const { inputData, resumeData, ...rest } = await c.req.json();
|
|
1067
1170
|
const mastra = c.get("mastra");
|
|
1068
1171
|
let workflowToUse = workflow;
|
|
1069
1172
|
if (!workflow) {
|
|
@@ -1082,11 +1185,11 @@ function workflowRoute({
|
|
|
1082
1185
|
if (!workflowObj) {
|
|
1083
1186
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1084
1187
|
}
|
|
1085
|
-
const run = await workflowObj.
|
|
1086
|
-
const stream = run.
|
|
1188
|
+
const run = await workflowObj.createRun();
|
|
1189
|
+
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1087
1190
|
const uiMessageStream = createUIMessageStream({
|
|
1088
1191
|
execute: async ({ writer }) => {
|
|
1089
|
-
for await (const part of
|
|
1192
|
+
for await (const part of toAISdkV5Stream(stream, { from: "workflow" })) {
|
|
1090
1193
|
writer.write(part);
|
|
1091
1194
|
}
|
|
1092
1195
|
}
|
|
@@ -1126,13 +1229,12 @@ function networkRoute({
|
|
|
1126
1229
|
type: "object",
|
|
1127
1230
|
properties: {
|
|
1128
1231
|
messages: { type: "array", items: { type: "object" } },
|
|
1129
|
-
|
|
1232
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1130
1233
|
runId: { type: "string" },
|
|
1131
1234
|
maxSteps: { type: "number" },
|
|
1132
1235
|
threadId: { type: "string" },
|
|
1133
1236
|
resourceId: { type: "string" },
|
|
1134
1237
|
modelSettings: { type: "object", additionalProperties: true },
|
|
1135
|
-
telemetry: { type: "object", additionalProperties: true },
|
|
1136
1238
|
tools: { type: "array", items: { type: "object" } }
|
|
1137
1239
|
},
|
|
1138
1240
|
required: ["messages"]
|
|
@@ -1181,7 +1283,7 @@ function networkRoute({
|
|
|
1181
1283
|
});
|
|
1182
1284
|
const uiMessageStream = createUIMessageStream({
|
|
1183
1285
|
execute: async ({ writer }) => {
|
|
1184
|
-
for await (const part of
|
|
1286
|
+
for await (const part of toAISdkV5Stream(result, { from: "network" })) {
|
|
1185
1287
|
writer.write(part);
|
|
1186
1288
|
}
|
|
1187
1289
|
}
|
|
@@ -1191,6 +1293,13 @@ function networkRoute({
|
|
|
1191
1293
|
});
|
|
1192
1294
|
}
|
|
1193
1295
|
|
|
1194
|
-
|
|
1296
|
+
// src/to-ai-sdk-format.ts
|
|
1297
|
+
function toAISdkFormat() {
|
|
1298
|
+
throw new Error(
|
|
1299
|
+
'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.'
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
export { chatRoute, networkRoute, toAISdkFormat, toAISdkV5Stream as toAISdkStream, workflowRoute };
|
|
1195
1304
|
//# sourceMappingURL=index.js.map
|
|
1196
1305
|
//# sourceMappingURL=index.js.map
|