@mastra/ai-sdk 0.0.0-fix-ai-sdk-dependency-20251124104209 → 0.0.0-fix-backport-setserver-20251201144151

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.stream.d.ts","sourceRoot":"","sources":["../../../src/__tests__/__fixtures__/network.stream.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAu9FhC,CAAC"}
package/dist/helpers.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { PartialSchemaOutput, OutputSchema, DataChunkType, ChunkType } from '@mastra/core/stream';
1
+ import type { ChunkType, PartialSchemaOutput, OutputSchema, DataChunkType } from '@mastra/core/stream';
2
2
  import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage } from 'ai';
3
3
  export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | DataChunkType | undefined;
4
4
  export type ToolAgentChunkType = {
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvG,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB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BAA2B,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACnF,KAAK,EACL,IAAe,GAChB,EAAE;IACD,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CAC9B,GAAG,eAAe,CAAC,MAAM,CAAC,CAiP1B;AAED,wBAAgB,uCAAuC,CAAC,UAAU,SAAS,SAAS,EAAE,EACpF,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,iBAAiB,GAClB,EAAE;IAED,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,aAAa,GAAG;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC;IACzG,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,mBAAmB,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,SAAS,CAyOlH"}
package/dist/index.cjs CHANGED
@@ -10,6 +10,31 @@ 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
+ var isMastraTextStreamChunk = (chunk) => {
14
+ return chunk && typeof chunk === "object" && "type" in chunk && typeof chunk.type === "string" && [
15
+ "text-start",
16
+ "text-delta",
17
+ "text-end",
18
+ "reasoning-start",
19
+ "reasoning-delta",
20
+ "reasoning-end",
21
+ "file",
22
+ "source",
23
+ "tool-input-start",
24
+ "tool-input-delta",
25
+ "tool-call",
26
+ "tool-result",
27
+ "tool-error",
28
+ "error",
29
+ "start-step",
30
+ "finish-step",
31
+ "start",
32
+ "finish",
33
+ "abort",
34
+ "tool-input-end",
35
+ "raw"
36
+ ].includes(chunk.type);
37
+ };
13
38
  function safeParseErrorObject(obj) {
14
39
  if (typeof obj !== "object" || obj === null) {
15
40
  return String(obj);
@@ -491,7 +516,10 @@ function convertFullStreamChunkToUIMessageStream({
491
516
  }
492
517
 
493
518
  // src/transformers.ts
494
- function WorkflowStreamToAISDKTransformer() {
519
+ var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
520
+ function WorkflowStreamToAISDKTransformer({
521
+ includeTextStreamParts
522
+ } = {}) {
495
523
  const bufferedWorkflows = /* @__PURE__ */ new Map();
496
524
  return new TransformStream({
497
525
  start(controller) {
@@ -505,7 +533,7 @@ function WorkflowStreamToAISDKTransformer() {
505
533
  });
506
534
  },
507
535
  transform(chunk, controller) {
508
- const transformed = transformWorkflow(chunk, bufferedWorkflows);
536
+ const transformed = transformWorkflow(chunk, bufferedWorkflows, false, includeTextStreamParts);
509
537
  if (transformed) controller.enqueue(transformed);
510
538
  }
511
539
  });
@@ -726,7 +754,7 @@ function transformAgent(payload, bufferedSteps) {
726
754
  }
727
755
  return null;
728
756
  }
729
- function transformWorkflow(payload, bufferedWorkflows, isNested) {
757
+ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStreamParts) {
730
758
  switch (payload.type) {
731
759
  case "workflow-start":
732
760
  bufferedWorkflows.set(payload.runId, {
@@ -819,6 +847,29 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
819
847
  }
820
848
  };
821
849
  }
850
+ case "workflow-step-output": {
851
+ const output = payload.payload.output;
852
+ if (includeTextStreamParts && output && isMastraTextStreamChunk(output)) {
853
+ const part = convertMastraChunkToAISDKv5({ chunk: output, mode: "stream" });
854
+ const transformedChunk = convertFullStreamChunkToUIMessageStream({
855
+ part,
856
+ onError(error) {
857
+ return safeParseErrorObject(error);
858
+ }
859
+ });
860
+ return transformedChunk;
861
+ }
862
+ if (output && isDataChunkType(output)) {
863
+ if (!("data" in output)) {
864
+ throw new Error(
865
+ `UI Messages require a data property when using data- prefixed chunks
866
+ ${JSON.stringify(output)}`
867
+ );
868
+ }
869
+ return output;
870
+ }
871
+ return null;
872
+ }
822
873
  default: {
823
874
  if (isDataChunkType(payload)) {
824
875
  if (!("data" in payload)) {
@@ -838,12 +889,29 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
838
889
  case "routing-agent-start": {
839
890
  if (!bufferedNetworks.has(payload.runId)) {
840
891
  bufferedNetworks.set(payload.runId, {
841
- name: payload.payload.agentId,
892
+ name: payload.payload.networkId,
842
893
  steps: [],
843
894
  usage: null,
844
895
  output: null
845
896
  });
846
897
  }
898
+ const current = bufferedNetworks.get(payload.runId);
899
+ current.steps.push({
900
+ id: payload.payload.runId,
901
+ name: payload.payload.agentId,
902
+ status: "running",
903
+ iteration: payload.payload.inputData.iteration,
904
+ input: {
905
+ task: payload.payload.inputData.task,
906
+ threadId: payload.payload.inputData.threadId,
907
+ threadResourceId: payload.payload.inputData.threadResourceId
908
+ },
909
+ output: "",
910
+ task: null,
911
+ suspendPayload: null,
912
+ resumePayload: null,
913
+ [PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
914
+ });
847
915
  return {
848
916
  type: isNested ? "data-tool-network" : "data-network",
849
917
  id: payload.runId,
@@ -874,14 +942,19 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
874
942
  };
875
943
  }
876
944
  case "agent-execution-start": {
877
- const current = bufferedNetworks.get(payload.runId) || { name: "", steps: [], usage: null, output: null };
945
+ const current = bufferedNetworks.get(payload.runId);
946
+ if (!current) return null;
878
947
  current.steps.push({
948
+ id: payload.payload.runId,
879
949
  name: payload.payload.agentId,
880
950
  status: "running",
881
- input: payload.payload.args || null,
951
+ iteration: payload.payload.args?.iteration ?? 0,
952
+ input: { prompt: payload.payload.args?.prompt ?? "" },
882
953
  output: null,
954
+ task: null,
883
955
  suspendPayload: null,
884
- resumePayload: null
956
+ resumePayload: null,
957
+ [PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
885
958
  });
886
959
  bufferedNetworks.set(payload.runId, current);
887
960
  return {
@@ -894,14 +967,19 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
894
967
  };
895
968
  }
896
969
  case "workflow-execution-start": {
897
- const current = bufferedNetworks.get(payload.runId) || { name: "", steps: [], usage: null, output: null };
970
+ const current = bufferedNetworks.get(payload.runId);
971
+ if (!current) return null;
898
972
  current.steps.push({
899
- name: payload.payload.name,
973
+ id: payload.payload.runId,
974
+ name: payload.payload.workflowId,
900
975
  status: "running",
901
- input: payload.payload.args || null,
976
+ iteration: payload.payload.args?.iteration ?? 0,
977
+ input: { prompt: payload.payload.args?.prompt ?? "" },
902
978
  output: null,
979
+ task: null,
903
980
  suspendPayload: null,
904
- resumePayload: null
981
+ resumePayload: null,
982
+ [PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
905
983
  });
906
984
  bufferedNetworks.set(payload.runId, current);
907
985
  return {
@@ -914,14 +992,21 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
914
992
  };
915
993
  }
916
994
  case "tool-execution-start": {
917
- const current = bufferedNetworks.get(payload.runId) || { name: "", steps: [], usage: null, output: null };
995
+ const current = bufferedNetworks.get(payload.runId);
996
+ if (!current) return null;
918
997
  current.steps.push({
998
+ id: payload.payload.args.toolCallId,
919
999
  name: payload.payload.args?.toolName,
920
1000
  status: "running",
1001
+ iteration: payload.payload.args?.iteration ? Number(payload.payload.args.iteration) : 0,
1002
+ task: {
1003
+ id: payload.payload.args?.toolName
1004
+ },
921
1005
  input: payload.payload.args?.args || null,
922
1006
  output: null,
923
1007
  suspendPayload: null,
924
- resumePayload: null
1008
+ resumePayload: null,
1009
+ [PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
925
1010
  });
926
1011
  bufferedNetworks.set(payload.runId, current);
927
1012
  return {
@@ -936,14 +1021,13 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
936
1021
  case "agent-execution-end": {
937
1022
  const current = bufferedNetworks.get(payload.runId);
938
1023
  if (!current) return null;
939
- current.steps.push({
940
- name: payload.payload.agentId,
941
- status: "success",
942
- input: null,
943
- output: payload.payload.result,
944
- suspendPayload: null,
945
- resumePayload: null
946
- });
1024
+ const stepId = payload.payload.runId;
1025
+ const step = current.steps.find((step2) => step2.id === stepId);
1026
+ if (!step) {
1027
+ return null;
1028
+ }
1029
+ step.status = "success";
1030
+ step.output = payload.payload.result;
947
1031
  return {
948
1032
  type: isNested ? "data-tool-network" : "data-network",
949
1033
  id: payload.runId,
@@ -958,14 +1042,13 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
958
1042
  case "tool-execution-end": {
959
1043
  const current = bufferedNetworks.get(payload.runId);
960
1044
  if (!current) return null;
961
- current.steps.push({
962
- name: payload.payload.toolName,
963
- status: "success",
964
- input: null,
965
- output: payload.payload.result,
966
- suspendPayload: null,
967
- resumePayload: null
968
- });
1045
+ const stepId = payload.payload.toolCallId;
1046
+ const step = current.steps.find((step2) => step2.id === stepId);
1047
+ if (!step) {
1048
+ return null;
1049
+ }
1050
+ step.status = "success";
1051
+ step.output = payload.payload.result;
969
1052
  return {
970
1053
  type: isNested ? "data-tool-network" : "data-network",
971
1054
  id: payload.runId,
@@ -979,14 +1062,13 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
979
1062
  case "workflow-execution-end": {
980
1063
  const current = bufferedNetworks.get(payload.runId);
981
1064
  if (!current) return null;
982
- current.steps.push({
983
- name: payload.payload.name,
984
- status: "success",
985
- input: null,
986
- output: payload.payload.result,
987
- suspendPayload: null,
988
- resumePayload: null
989
- });
1065
+ const stepId = payload.payload.runId;
1066
+ const step = current.steps.find((step2) => step2.id === stepId);
1067
+ if (!step) {
1068
+ return null;
1069
+ }
1070
+ step.status = "success";
1071
+ step.output = payload.payload.result;
990
1072
  return {
991
1073
  type: isNested ? "data-tool-network" : "data-network",
992
1074
  id: payload.runId,
@@ -1001,12 +1083,24 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
1001
1083
  case "routing-agent-end": {
1002
1084
  const current = bufferedNetworks.get(payload.runId);
1003
1085
  if (!current) return null;
1086
+ const stepId = payload.payload.runId;
1087
+ const step = current.steps.find((step2) => step2.id === stepId);
1088
+ if (!step) {
1089
+ return null;
1090
+ }
1091
+ step.status = "success";
1092
+ step.task = {
1093
+ id: payload.payload.primitiveId,
1094
+ type: payload.payload.primitiveType,
1095
+ name: payload.payload.task,
1096
+ reason: payload.payload.selectionReason
1097
+ };
1098
+ step.output = payload.payload.result;
1004
1099
  return {
1005
1100
  type: isNested ? "data-tool-network" : "data-network",
1006
1101
  id: payload.runId,
1007
1102
  data: {
1008
1103
  ...current,
1009
- status: "finished",
1010
1104
  usage: payload.payload?.usage ?? current.usage,
1011
1105
  output: payload.payload?.result ?? current.output
1012
1106
  }
@@ -1040,6 +1134,39 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
1040
1134
  };
1041
1135
  }
1042
1136
  default: {
1137
+ if (payload.type.startsWith("agent-execution-event-")) {
1138
+ const stepId = payload.payload.runId;
1139
+ const current = bufferedNetworks.get(payload.runId);
1140
+ if (!current) return null;
1141
+ const step = current.steps.find((step2) => step2.id === stepId);
1142
+ if (!step) {
1143
+ return null;
1144
+ }
1145
+ step[PRIMITIVE_CACHE_SYMBOL] = step[PRIMITIVE_CACHE_SYMBOL] || /* @__PURE__ */ new Map();
1146
+ const result = transformAgent(payload.payload, step[PRIMITIVE_CACHE_SYMBOL]);
1147
+ if (result) {
1148
+ const { request, response, ...data } = result.data;
1149
+ step.task = data;
1150
+ }
1151
+ }
1152
+ if (payload.type.startsWith("workflow-execution-event-")) {
1153
+ const stepId = payload.payload.runId;
1154
+ const current = bufferedNetworks.get(payload.runId);
1155
+ if (!current) return null;
1156
+ const step = current.steps.find((step2) => step2.id === stepId);
1157
+ if (!step) {
1158
+ return null;
1159
+ }
1160
+ step[PRIMITIVE_CACHE_SYMBOL] = step[PRIMITIVE_CACHE_SYMBOL] || /* @__PURE__ */ new Map();
1161
+ const result = transformWorkflow(payload.payload, step[PRIMITIVE_CACHE_SYMBOL]);
1162
+ if (result && "data" in result) {
1163
+ const data = result.data;
1164
+ step.task = data;
1165
+ if (data.name && step.task) {
1166
+ step.task.id = data.name;
1167
+ }
1168
+ }
1169
+ }
1043
1170
  if (isDataChunkType(payload)) {
1044
1171
  if (!("data" in payload)) {
1045
1172
  throw new Error(
@@ -1047,7 +1174,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
1047
1174
  ${JSON.stringify(payload)}`
1048
1175
  );
1049
1176
  }
1050
- return payload;
1177
+ const { type, data } = payload;
1178
+ return { type, data };
1051
1179
  }
1052
1180
  if (isAgentExecutionDataChunkType(payload)) {
1053
1181
  if (!("data" in payload.payload)) {
@@ -1056,7 +1184,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
1056
1184
  ${JSON.stringify(payload)}`
1057
1185
  );
1058
1186
  }
1059
- return payload.payload;
1187
+ const { type, data } = payload.payload;
1188
+ return { type, data };
1060
1189
  }
1061
1190
  if (isWorkflowExecutionDataChunkType(payload)) {
1062
1191
  if (!("data" in payload.payload)) {
@@ -1065,22 +1194,26 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
1065
1194
  ${JSON.stringify(payload)}`
1066
1195
  );
1067
1196
  }
1068
- return payload.payload;
1197
+ const { type, data } = payload.payload;
1198
+ return { type, data };
1069
1199
  }
1070
1200
  return null;
1071
1201
  }
1072
1202
  }
1073
1203
  }
1074
1204
 
1075
- // src/convert-streams.ts
1076
- function toAISdkV5Stream(stream, options = {
1205
+ // src/to-ai-sdk-format.ts
1206
+ function toAISdkFormat(stream, options = {
1077
1207
  from: "agent",
1078
1208
  sendStart: true,
1079
1209
  sendFinish: true
1080
1210
  }) {
1081
1211
  const from = options?.from;
1082
1212
  if (from === "workflow") {
1083
- return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
1213
+ const includeTextStreamParts = options?.includeTextStreamParts ?? false;
1214
+ return stream.pipeThrough(
1215
+ WorkflowStreamToAISDKTransformer({ includeTextStreamParts })
1216
+ );
1084
1217
  }
1085
1218
  if (from === "network") {
1086
1219
  return stream.pipeThrough(AgentNetworkToAISDKTransformer());
@@ -1208,7 +1341,7 @@ function chatRoute({
1208
1341
  handler: async (c) => {
1209
1342
  const { messages, ...rest } = await c.req.json();
1210
1343
  const mastra = c.get("mastra");
1211
- const requestContext = c.get("requestContext");
1344
+ const runtimeContext = c.get("runtimeContext");
1212
1345
  let agentToUse = agent;
1213
1346
  if (!agent) {
1214
1347
  const agentId = c.req.param("agentId");
@@ -1219,20 +1352,20 @@ function chatRoute({
1219
1352
  `Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
1220
1353
  );
1221
1354
  }
1222
- if (requestContext && defaultOptions?.requestContext) {
1223
- mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
1355
+ if (runtimeContext && defaultOptions?.runtimeContext) {
1356
+ mastra.getLogger()?.warn(`"runtimeContext" set in the route options will be overridden by the request's "runtimeContext".`);
1224
1357
  }
1225
1358
  if (!agentToUse) {
1226
1359
  throw new Error("Agent ID is required");
1227
1360
  }
1228
- const agentObj = mastra.getAgent(agentToUse);
1361
+ const agentObj = mastra.getAgentById(agentToUse);
1229
1362
  if (!agentObj) {
1230
1363
  throw new Error(`Agent ${agentToUse} not found`);
1231
1364
  }
1232
1365
  const result = await agentObj.stream(messages, {
1233
1366
  ...defaultOptions,
1234
1367
  ...rest,
1235
- requestContext: requestContext || defaultOptions?.requestContext
1368
+ runtimeContext: runtimeContext || defaultOptions?.runtimeContext
1236
1369
  });
1237
1370
  let lastMessageId;
1238
1371
  if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
@@ -1241,7 +1374,7 @@ function chatRoute({
1241
1374
  const uiMessageStream = ai.createUIMessageStream({
1242
1375
  originalMessages: messages,
1243
1376
  execute: async ({ writer }) => {
1244
- for await (const part of toAISdkV5Stream(result, {
1377
+ for await (const part of toAISdkFormat(result, {
1245
1378
  from: "agent",
1246
1379
  lastMessageId,
1247
1380
  sendStart,
@@ -1261,7 +1394,8 @@ function chatRoute({
1261
1394
  }
1262
1395
  function workflowRoute({
1263
1396
  path = "/api/workflows/:workflowId/stream",
1264
- workflow
1397
+ workflow,
1398
+ includeTextStreamParts = false
1265
1399
  }) {
1266
1400
  if (!workflow && !path.includes("/:workflowId")) {
1267
1401
  throw new Error("Path must include :workflowId to route to the correct workflow or pass the workflow explicitly");
@@ -1292,7 +1426,7 @@ function workflowRoute({
1292
1426
  resourceId: { type: "string" },
1293
1427
  inputData: { type: "object", additionalProperties: true },
1294
1428
  resumeData: { type: "object", additionalProperties: true },
1295
- requestContext: { type: "object", additionalProperties: true },
1429
+ runtimeContext: { type: "object", additionalProperties: true },
1296
1430
  tracingOptions: { type: "object", additionalProperties: true },
1297
1431
  step: { type: "string" }
1298
1432
  }
@@ -1314,6 +1448,7 @@ function workflowRoute({
1314
1448
  handler: async (c) => {
1315
1449
  const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
1316
1450
  const mastra = c.get("mastra");
1451
+ const runtimeContext = c.get("runtimeContext");
1317
1452
  let workflowToUse = workflow;
1318
1453
  if (!workflow) {
1319
1454
  const workflowId = c.req.param("workflowId");
@@ -1327,15 +1462,20 @@ function workflowRoute({
1327
1462
  if (!workflowToUse) {
1328
1463
  throw new Error("Workflow ID is required");
1329
1464
  }
1330
- const workflowObj = mastra.getWorkflow(workflowToUse);
1465
+ const workflowObj = mastra.getWorkflowById(workflowToUse);
1331
1466
  if (!workflowObj) {
1332
1467
  throw new Error(`Workflow ${workflowToUse} not found`);
1333
1468
  }
1334
- const run = await workflowObj.createRun({ runId, resourceId, ...rest });
1335
- const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
1469
+ if (runtimeContext && rest.runtimeContext) {
1470
+ mastra.getLogger()?.warn(
1471
+ `"runtimeContext" from the request body will be ignored because "runtimeContext" is already set in the route options.`
1472
+ );
1473
+ }
1474
+ const run = await workflowObj.createRunAsync({ runId, resourceId, ...rest });
1475
+ const stream = resumeData ? run.resumeStream({ resumeData, ...rest, runtimeContext: runtimeContext || rest.runtimeContext }) : run.stream({ inputData, ...rest, runtimeContext: runtimeContext || rest.runtimeContext });
1336
1476
  const uiMessageStream = ai.createUIMessageStream({
1337
1477
  execute: async ({ writer }) => {
1338
- for await (const part of toAISdkV5Stream(stream, { from: "workflow" })) {
1478
+ for await (const part of toAISdkFormat(stream, { from: "workflow", includeTextStreamParts })) {
1339
1479
  writer.write(part);
1340
1480
  }
1341
1481
  }
@@ -1375,12 +1515,13 @@ function networkRoute({
1375
1515
  type: "object",
1376
1516
  properties: {
1377
1517
  messages: { type: "array", items: { type: "object" } },
1378
- requestContext: { type: "object", additionalProperties: true },
1518
+ runtimeContext: { type: "object", additionalProperties: true },
1379
1519
  runId: { type: "string" },
1380
1520
  maxSteps: { type: "number" },
1381
1521
  threadId: { type: "string" },
1382
1522
  resourceId: { type: "string" },
1383
1523
  modelSettings: { type: "object", additionalProperties: true },
1524
+ telemetry: { type: "object", additionalProperties: true },
1384
1525
  tools: { type: "array", items: { type: "object" } }
1385
1526
  },
1386
1527
  required: ["messages"]
@@ -1419,7 +1560,7 @@ function networkRoute({
1419
1560
  if (!agentToUse) {
1420
1561
  throw new Error("Agent ID is required");
1421
1562
  }
1422
- const agentObj = mastra.getAgent(agentToUse);
1563
+ const agentObj = mastra.getAgentById(agentToUse);
1423
1564
  if (!agentObj) {
1424
1565
  throw new Error(`Agent ${agentToUse} not found`);
1425
1566
  }
@@ -1429,7 +1570,7 @@ function networkRoute({
1429
1570
  });
1430
1571
  const uiMessageStream = ai.createUIMessageStream({
1431
1572
  execute: async ({ writer }) => {
1432
- for await (const part of toAISdkV5Stream(result, { from: "network" })) {
1573
+ for await (const part of toAISdkFormat(result, { from: "network" })) {
1433
1574
  writer.write(part);
1434
1575
  }
1435
1576
  }
@@ -1439,17 +1580,9 @@ function networkRoute({
1439
1580
  });
1440
1581
  }
1441
1582
 
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
-
1449
1583
  exports.chatRoute = chatRoute;
1450
1584
  exports.networkRoute = networkRoute;
1451
1585
  exports.toAISdkFormat = toAISdkFormat;
1452
- exports.toAISdkStream = toAISdkV5Stream;
1453
1586
  exports.workflowRoute = workflowRoute;
1454
1587
  //# sourceMappingURL=index.cjs.map
1455
1588
  //# sourceMappingURL=index.cjs.map