@mastra/core 0.1.27-alpha.9 → 0.1.27-unstable.2

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.
Files changed (52) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/index.d.ts +20 -2
  3. package/dist/core.cjs.development.js +597 -208
  4. package/dist/core.cjs.development.js.map +1 -1
  5. package/dist/core.cjs.production.min.js +1 -1
  6. package/dist/core.cjs.production.min.js.map +1 -1
  7. package/dist/core.esm.js +596 -209
  8. package/dist/core.esm.js.map +1 -1
  9. package/dist/engine/index.d.ts +3 -4
  10. package/dist/engine/schema.d.ts +0 -1
  11. package/dist/engine/types.d.ts +1 -2
  12. package/dist/engine/utils.d.ts +0 -1
  13. package/dist/index.d.ts +1 -2
  14. package/dist/integration/index.d.ts +0 -1
  15. package/dist/integration/test-integration.d.ts +12 -0
  16. package/dist/llm/index.d.ts +32 -2
  17. package/dist/llm/types.d.ts +33 -1
  18. package/dist/logger/index.d.ts +0 -1
  19. package/dist/mastra/index.d.ts +4 -4
  20. package/dist/mastra/types.d.ts +1 -0
  21. package/dist/sync/index.d.ts +2 -0
  22. package/dist/sync/types.d.ts +23 -11
  23. package/dist/tools/index.d.ts +0 -1
  24. package/dist/tools/types.d.ts +3 -3
  25. package/dist/utils.d.ts +0 -1
  26. package/dist/vector/index.d.ts +0 -1
  27. package/dist/workflows/index.d.ts +2 -2
  28. package/dist/workflows/step.d.ts +15 -0
  29. package/dist/workflows/types.d.ts +25 -24
  30. package/dist/workflows/utils.d.ts +0 -1
  31. package/dist/workflows/{main.d.ts → workflow.d.ts} +13 -13
  32. package/package.json +16 -8
  33. package/dist/agent/index.d.ts.map +0 -1
  34. package/dist/engine/index.d.ts.map +0 -1
  35. package/dist/engine/schema.d.ts.map +0 -1
  36. package/dist/engine/types.d.ts.map +0 -1
  37. package/dist/engine/utils.d.ts.map +0 -1
  38. package/dist/index.d.ts.map +0 -1
  39. package/dist/integration/index.d.ts.map +0 -1
  40. package/dist/llm/index.d.ts.map +0 -1
  41. package/dist/llm/types.d.ts.map +0 -1
  42. package/dist/logger/index.d.ts.map +0 -1
  43. package/dist/mastra/index.d.ts.map +0 -1
  44. package/dist/sync/types.d.ts.map +0 -1
  45. package/dist/tools/index.d.ts.map +0 -1
  46. package/dist/tools/types.d.ts.map +0 -1
  47. package/dist/utils.d.ts.map +0 -1
  48. package/dist/vector/index.d.ts.map +0 -1
  49. package/dist/workflows/index.d.ts.map +0 -1
  50. package/dist/workflows/main.d.ts.map +0 -1
  51. package/dist/workflows/types.d.ts.map +0 -1
  52. package/dist/workflows/utils.d.ts.map +0 -1
package/dist/core.esm.js CHANGED
@@ -10,7 +10,7 @@ import { createAzure } from '@ai-sdk/azure';
10
10
  import { createXai } from '@ai-sdk/xai';
11
11
  import { createCohere } from '@ai-sdk/cohere';
12
12
  import { createAnthropicVertex } from 'anthropic-vertex-ai';
13
- import { tool, generateText, streamText } from 'ai';
13
+ import { embed, embedMany, tool, generateText, generateObject, streamText, streamObject } from 'ai';
14
14
  import { z } from 'zod';
15
15
  import sift from 'sift';
16
16
  import { setup, assign, fromPromise, createActor } from 'xstate';
@@ -843,6 +843,7 @@ var LLM = /*#__PURE__*/function () {
843
843
  COHERE: 'cohere',
844
844
  AZURE: 'azure',
845
845
  AMAZON: 'amazon',
846
+ //
846
847
  ANTHROPIC_VERTEX: 'anthropic-vertex'
847
848
  };
848
849
  var type = (_providerToType$model = providerToType[model.provider]) != null ? _providerToType$model : model.provider;
@@ -999,16 +1000,79 @@ var LLM = /*#__PURE__*/function () {
999
1000
  }
1000
1001
  return modelDef;
1001
1002
  };
1002
- _proto.getParams = /*#__PURE__*/function () {
1003
- var _getParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
1004
- var tools, resultTool, model, toolsConverted, answerTool, modelDef;
1003
+ _proto.createEmbedding = /*#__PURE__*/function () {
1004
+ var _createEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
1005
+ var model, value, maxRetries, embeddingModel, openai, cohere;
1005
1006
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1006
1007
  while (1) switch (_context.prev = _context.next) {
1007
1008
  case 0:
1008
- tools = _ref3.tools, resultTool = _ref3.resultTool, model = _ref3.model;
1009
- toolsConverted = Object.entries(tools).reduce(function (memo, _ref4) {
1010
- var key = _ref4[0],
1011
- val = _ref4[1];
1009
+ model = _ref3.model, value = _ref3.value, maxRetries = _ref3.maxRetries;
1010
+ if (!(model.provider === 'OPEN_AI')) {
1011
+ _context.next = 6;
1012
+ break;
1013
+ }
1014
+ openai = createOpenAI({
1015
+ apiKey: process.env.OPENAI_API_KEY
1016
+ });
1017
+ embeddingModel = openai.embedding(model.name);
1018
+ _context.next = 12;
1019
+ break;
1020
+ case 6:
1021
+ if (!(model.provider === 'COHERE')) {
1022
+ _context.next = 11;
1023
+ break;
1024
+ }
1025
+ cohere = createCohere({
1026
+ apiKey: process.env.COHERE_API_KEY
1027
+ });
1028
+ embeddingModel = cohere.embedding(model.name);
1029
+ _context.next = 12;
1030
+ break;
1031
+ case 11:
1032
+ throw new Error("Invalid embedding model");
1033
+ case 12:
1034
+ if (!(value instanceof Array)) {
1035
+ _context.next = 16;
1036
+ break;
1037
+ }
1038
+ _context.next = 15;
1039
+ return embedMany({
1040
+ model: embeddingModel,
1041
+ values: value,
1042
+ maxRetries: maxRetries
1043
+ });
1044
+ case 15:
1045
+ return _context.abrupt("return", _context.sent);
1046
+ case 16:
1047
+ _context.next = 18;
1048
+ return embed({
1049
+ model: embeddingModel,
1050
+ value: value,
1051
+ maxRetries: maxRetries
1052
+ });
1053
+ case 18:
1054
+ return _context.abrupt("return", _context.sent);
1055
+ case 19:
1056
+ case "end":
1057
+ return _context.stop();
1058
+ }
1059
+ }, _callee);
1060
+ }));
1061
+ function createEmbedding(_x) {
1062
+ return _createEmbedding.apply(this, arguments);
1063
+ }
1064
+ return createEmbedding;
1065
+ }();
1066
+ _proto.getParams = /*#__PURE__*/function () {
1067
+ var _getParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
1068
+ var tools, resultTool, model, toolsConverted, answerTool, modelDef;
1069
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1070
+ while (1) switch (_context2.prev = _context2.next) {
1071
+ case 0:
1072
+ tools = _ref4.tools, resultTool = _ref4.resultTool, model = _ref4.model;
1073
+ toolsConverted = Object.entries(tools).reduce(function (memo, _ref5) {
1074
+ var key = _ref5[0],
1075
+ val = _ref5[1];
1012
1076
  memo[key] = tool(val);
1013
1077
  return memo;
1014
1078
  }, {});
@@ -1019,29 +1083,29 @@ var LLM = /*#__PURE__*/function () {
1019
1083
  };
1020
1084
  }
1021
1085
  if (!('type' in model)) {
1022
- _context.next = 8;
1086
+ _context2.next = 8;
1023
1087
  break;
1024
1088
  }
1025
1089
  modelDef = this.createModelDef({
1026
1090
  model: model
1027
1091
  });
1028
- _context.next = 15;
1092
+ _context2.next = 15;
1029
1093
  break;
1030
1094
  case 8:
1031
1095
  if (!(model.model instanceof Function)) {
1032
- _context.next = 14;
1096
+ _context2.next = 14;
1033
1097
  break;
1034
1098
  }
1035
- _context.next = 11;
1099
+ _context2.next = 11;
1036
1100
  return model.model();
1037
1101
  case 11:
1038
- modelDef = _context.sent;
1039
- _context.next = 15;
1102
+ modelDef = _context2.sent;
1103
+ _context2.next = 15;
1040
1104
  break;
1041
1105
  case 14:
1042
1106
  modelDef = model.model;
1043
1107
  case 15:
1044
- return _context.abrupt("return", {
1108
+ return _context2.abrupt("return", {
1045
1109
  toolsConverted: toolsConverted,
1046
1110
  modelDef: modelDef,
1047
1111
  answerTool: answerTool,
@@ -1049,11 +1113,11 @@ var LLM = /*#__PURE__*/function () {
1049
1113
  });
1050
1114
  case 16:
1051
1115
  case "end":
1052
- return _context.stop();
1116
+ return _context2.stop();
1053
1117
  }
1054
- }, _callee, this);
1118
+ }, _callee2, this);
1055
1119
  }));
1056
- function getParams(_x) {
1120
+ function getParams(_x2) {
1057
1121
  return _getParams.apply(this, arguments);
1058
1122
  }
1059
1123
  return getParams;
@@ -1078,14 +1142,59 @@ var LLM = /*#__PURE__*/function () {
1078
1142
  this.logger.debug("Converted tools for LLM", converted);
1079
1143
  return converted;
1080
1144
  };
1145
+ _proto.isBaseOutputType = function isBaseOutputType(outputType) {
1146
+ return outputType === 'string' || outputType === 'number' || outputType === 'boolean' || outputType === 'date';
1147
+ };
1148
+ _proto.baseOutputTypeSchema = function baseOutputTypeSchema(outputType) {
1149
+ switch (outputType) {
1150
+ case 'string':
1151
+ return z.string();
1152
+ case 'number':
1153
+ return z.number();
1154
+ case 'boolean':
1155
+ return z["boolean"]();
1156
+ case 'date':
1157
+ return z.string().datetime();
1158
+ default:
1159
+ return z.string();
1160
+ }
1161
+ };
1162
+ _proto.createOutputSchema = function createOutputSchema(output) {
1163
+ var _this2 = this;
1164
+ var schema = Object.entries(output).reduce(function (memo, _ref6) {
1165
+ var k = _ref6[0],
1166
+ v = _ref6[1];
1167
+ if (_this2.isBaseOutputType(v.type)) {
1168
+ memo[k] = _this2.baseOutputTypeSchema(v.type);
1169
+ }
1170
+ if (v.type === 'object') {
1171
+ var objectItem = v.items;
1172
+ var objectItemSchema = _this2.createOutputSchema(objectItem);
1173
+ memo[k] = objectItemSchema;
1174
+ }
1175
+ if (v.type === 'array') {
1176
+ var arrayItem = v.items;
1177
+ if (_this2.isBaseOutputType(arrayItem.type)) {
1178
+ var itemSchema = _this2.baseOutputTypeSchema(arrayItem.type);
1179
+ memo[k] = z.array(itemSchema);
1180
+ }
1181
+ if (arrayItem.type === 'object') {
1182
+ var objectInArrayItemSchema = _this2.createOutputSchema(arrayItem.items);
1183
+ memo[k] = z.array(objectInArrayItemSchema);
1184
+ }
1185
+ }
1186
+ return memo;
1187
+ }, {});
1188
+ return z.object(schema);
1189
+ };
1081
1190
  _proto.text = /*#__PURE__*/function () {
1082
- var _text = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref5) {
1083
- var _this2 = this;
1084
- var model, messages, _onStepFinish, _ref5$maxSteps, maxSteps, enabledTools, modelToPass, params, argsForExecute;
1085
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1086
- while (1) switch (_context3.prev = _context3.next) {
1191
+ var _text = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref7) {
1192
+ var _this3 = this;
1193
+ var model, messages, _onStepFinish, _ref7$maxSteps, maxSteps, enabledTools, modelToPass, params, argsForExecute;
1194
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1195
+ while (1) switch (_context4.prev = _context4.next) {
1087
1196
  case 0:
1088
- model = _ref5.model, messages = _ref5.messages, _onStepFinish = _ref5.onStepFinish, _ref5$maxSteps = _ref5.maxSteps, maxSteps = _ref5$maxSteps === void 0 ? 5 : _ref5$maxSteps, enabledTools = _ref5.enabledTools;
1197
+ model = _ref7.model, messages = _ref7.messages, _onStepFinish = _ref7.onStepFinish, _ref7$maxSteps = _ref7.maxSteps, maxSteps = _ref7$maxSteps === void 0 ? 5 : _ref7$maxSteps, enabledTools = _ref7.enabledTools;
1089
1198
  if ('name' in model) {
1090
1199
  modelToPass = {
1091
1200
  type: this.getModelType(model),
@@ -1098,70 +1207,70 @@ var LLM = /*#__PURE__*/function () {
1098
1207
  } else {
1099
1208
  modelToPass = model;
1100
1209
  }
1101
- _context3.next = 4;
1210
+ _context4.next = 4;
1102
1211
  return this.getParams({
1103
1212
  tools: this.convertTools(enabledTools || {}),
1104
1213
  model: modelToPass
1105
1214
  });
1106
1215
  case 4:
1107
- params = _context3.sent;
1216
+ params = _context4.sent;
1108
1217
  argsForExecute = {
1109
1218
  model: params.modelDef,
1110
1219
  tools: _extends({}, params.toolsConverted, params.answerTool),
1111
1220
  toolChoice: params.toolChoice,
1112
1221
  maxSteps: maxSteps,
1113
1222
  onStepFinish: function () {
1114
- var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(props) {
1223
+ var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(props) {
1115
1224
  var _props$response, _props$response2;
1116
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1117
- while (1) switch (_context2.prev = _context2.next) {
1225
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1226
+ while (1) switch (_context3.prev = _context3.next) {
1118
1227
  case 0:
1119
1228
  _onStepFinish == null || _onStepFinish(JSON.stringify(props, null, 2));
1120
1229
  if (!(props != null && (_props$response = props.response) != null && (_props$response = _props$response.headers) != null && _props$response['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response2 = props.response) == null || (_props$response2 = _props$response2.headers) == null ? void 0 : _props$response2['x-ratelimit-remaining-tokens'], 10) < 2000)) {
1121
- _context2.next = 5;
1230
+ _context3.next = 5;
1122
1231
  break;
1123
1232
  }
1124
- _this2.logger.warn('Rate limit approaching, waiting 10 seconds');
1125
- _context2.next = 5;
1233
+ _this3.logger.warn('Rate limit approaching, waiting 10 seconds');
1234
+ _context3.next = 5;
1126
1235
  return delay(10 * 1000);
1127
1236
  case 5:
1128
1237
  case "end":
1129
- return _context2.stop();
1238
+ return _context3.stop();
1130
1239
  }
1131
- }, _callee2);
1240
+ }, _callee3);
1132
1241
  }));
1133
- function onStepFinish(_x3) {
1242
+ function onStepFinish(_x4) {
1134
1243
  return _onStepFinish2.apply(this, arguments);
1135
1244
  }
1136
1245
  return onStepFinish;
1137
1246
  }()
1138
1247
  };
1139
1248
  this.logger.debug("Generating text with " + messages.length + " messages");
1140
- _context3.next = 9;
1249
+ _context4.next = 9;
1141
1250
  return generateText(_extends({
1142
1251
  messages: messages
1143
1252
  }, argsForExecute));
1144
1253
  case 9:
1145
- return _context3.abrupt("return", _context3.sent);
1254
+ return _context4.abrupt("return", _context4.sent);
1146
1255
  case 10:
1147
1256
  case "end":
1148
- return _context3.stop();
1257
+ return _context4.stop();
1149
1258
  }
1150
- }, _callee3, this);
1259
+ }, _callee4, this);
1151
1260
  }));
1152
- function text(_x2) {
1261
+ function text(_x3) {
1153
1262
  return _text.apply(this, arguments);
1154
1263
  }
1155
1264
  return text;
1156
1265
  }();
1157
- _proto.stream = /*#__PURE__*/function () {
1158
- var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6) {
1159
- var _this3 = this;
1160
- var model, messages, _onStepFinish3, _onFinish, _ref6$maxSteps, maxSteps, enabledTools, modelToPass, params, argsForExecute;
1266
+ _proto.textObject = /*#__PURE__*/function () {
1267
+ var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref8) {
1268
+ var _this4 = this;
1269
+ var model, messages, _onStepFinish3, _ref8$maxSteps, maxSteps, enabledTools, structuredOutput, modelToPass, params, argsForExecute, schema;
1161
1270
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1162
1271
  while (1) switch (_context6.prev = _context6.next) {
1163
1272
  case 0:
1164
- model = _ref6.model, messages = _ref6.messages, _onStepFinish3 = _ref6.onStepFinish, _onFinish = _ref6.onFinish, _ref6$maxSteps = _ref6.maxSteps, maxSteps = _ref6$maxSteps === void 0 ? 5 : _ref6$maxSteps, enabledTools = _ref6.enabledTools;
1273
+ model = _ref8.model, messages = _ref8.messages, _onStepFinish3 = _ref8.onStepFinish, _ref8$maxSteps = _ref8.maxSteps, maxSteps = _ref8$maxSteps === void 0 ? 5 : _ref8$maxSteps, enabledTools = _ref8.enabledTools, structuredOutput = _ref8.structuredOutput;
1165
1274
  if ('name' in model) {
1166
1275
  modelToPass = {
1167
1276
  type: this.getModelType(model),
@@ -1176,7 +1285,7 @@ var LLM = /*#__PURE__*/function () {
1176
1285
  }
1177
1286
  _context6.next = 4;
1178
1287
  return this.getParams({
1179
- tools: this.convertTools(enabledTools),
1288
+ tools: this.convertTools(enabledTools || {}),
1180
1289
  model: modelToPass
1181
1290
  });
1182
1291
  case 4:
@@ -1187,66 +1296,243 @@ var LLM = /*#__PURE__*/function () {
1187
1296
  toolChoice: params.toolChoice,
1188
1297
  maxSteps: maxSteps,
1189
1298
  onStepFinish: function () {
1190
- var _onStepFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props) {
1299
+ var _onStepFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(props) {
1191
1300
  var _props$response3, _props$response4;
1192
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1193
- while (1) switch (_context4.prev = _context4.next) {
1301
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1302
+ while (1) switch (_context5.prev = _context5.next) {
1194
1303
  case 0:
1195
1304
  _onStepFinish3 == null || _onStepFinish3(JSON.stringify(props, null, 2));
1196
1305
  if (!(props != null && (_props$response3 = props.response) != null && (_props$response3 = _props$response3.headers) != null && _props$response3['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response4 = props.response) == null || (_props$response4 = _props$response4.headers) == null ? void 0 : _props$response4['x-ratelimit-remaining-tokens'], 10) < 2000)) {
1197
- _context4.next = 5;
1306
+ _context5.next = 5;
1198
1307
  break;
1199
1308
  }
1200
- _this3.logger.warn('Rate limit approaching, waiting 10 seconds');
1201
- _context4.next = 5;
1309
+ _this4.logger.warn('Rate limit approaching, waiting 10 seconds');
1310
+ _context5.next = 5;
1202
1311
  return delay(10 * 1000);
1203
1312
  case 5:
1204
1313
  case "end":
1205
- return _context4.stop();
1314
+ return _context5.stop();
1206
1315
  }
1207
- }, _callee4);
1316
+ }, _callee5);
1208
1317
  }));
1209
- function onStepFinish(_x5) {
1318
+ function onStepFinish(_x6) {
1210
1319
  return _onStepFinish4.apply(this, arguments);
1211
1320
  }
1212
1321
  return onStepFinish;
1322
+ }()
1323
+ };
1324
+ this.logger.debug("Generating text with " + messages.length + " messages");
1325
+ schema = this.createOutputSchema(structuredOutput);
1326
+ _context6.next = 10;
1327
+ return generateObject(_extends({
1328
+ messages: messages
1329
+ }, argsForExecute, {
1330
+ output: 'object',
1331
+ schema: schema
1332
+ }));
1333
+ case 10:
1334
+ return _context6.abrupt("return", _context6.sent);
1335
+ case 11:
1336
+ case "end":
1337
+ return _context6.stop();
1338
+ }
1339
+ }, _callee6, this);
1340
+ }));
1341
+ function textObject(_x5) {
1342
+ return _textObject.apply(this, arguments);
1343
+ }
1344
+ return textObject;
1345
+ }();
1346
+ _proto.stream = /*#__PURE__*/function () {
1347
+ var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref9) {
1348
+ var _this5 = this;
1349
+ var model, messages, _onStepFinish5, _onFinish, _ref9$maxSteps, maxSteps, enabledTools, modelToPass, params, argsForExecute;
1350
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1351
+ while (1) switch (_context9.prev = _context9.next) {
1352
+ case 0:
1353
+ model = _ref9.model, messages = _ref9.messages, _onStepFinish5 = _ref9.onStepFinish, _onFinish = _ref9.onFinish, _ref9$maxSteps = _ref9.maxSteps, maxSteps = _ref9$maxSteps === void 0 ? 5 : _ref9$maxSteps, enabledTools = _ref9.enabledTools;
1354
+ if ('name' in model) {
1355
+ modelToPass = {
1356
+ type: this.getModelType(model),
1357
+ name: model.name,
1358
+ toolChoice: model.toolChoice,
1359
+ apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
1360
+ baseURL: model.provider === 'LM_STUDIO' ? model.baseURL : undefined,
1361
+ fetch: model.provider === 'BASETEN' ? model.fetch : undefined
1362
+ };
1363
+ } else {
1364
+ modelToPass = model;
1365
+ }
1366
+ _context9.next = 4;
1367
+ return this.getParams({
1368
+ tools: this.convertTools(enabledTools),
1369
+ model: modelToPass
1370
+ });
1371
+ case 4:
1372
+ params = _context9.sent;
1373
+ argsForExecute = {
1374
+ model: params.modelDef,
1375
+ tools: _extends({}, params.toolsConverted, params.answerTool),
1376
+ toolChoice: params.toolChoice,
1377
+ maxSteps: maxSteps,
1378
+ onStepFinish: function () {
1379
+ var _onStepFinish6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(props) {
1380
+ var _props$response5, _props$response6;
1381
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1382
+ while (1) switch (_context7.prev = _context7.next) {
1383
+ case 0:
1384
+ _onStepFinish5 == null || _onStepFinish5(JSON.stringify(props, null, 2));
1385
+ if (!(props != null && (_props$response5 = props.response) != null && (_props$response5 = _props$response5.headers) != null && _props$response5['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response6 = props.response) == null || (_props$response6 = _props$response6.headers) == null ? void 0 : _props$response6['x-ratelimit-remaining-tokens'], 10) < 2000)) {
1386
+ _context7.next = 5;
1387
+ break;
1388
+ }
1389
+ _this5.logger.warn('Rate limit approaching, waiting 10 seconds');
1390
+ _context7.next = 5;
1391
+ return delay(10 * 1000);
1392
+ case 5:
1393
+ case "end":
1394
+ return _context7.stop();
1395
+ }
1396
+ }, _callee7);
1397
+ }));
1398
+ function onStepFinish(_x8) {
1399
+ return _onStepFinish6.apply(this, arguments);
1400
+ }
1401
+ return onStepFinish;
1213
1402
  }(),
1214
1403
  onFinish: function () {
1215
- var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(props) {
1216
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1217
- while (1) switch (_context5.prev = _context5.next) {
1404
+ var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(props) {
1405
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1406
+ while (1) switch (_context8.prev = _context8.next) {
1218
1407
  case 0:
1219
1408
  _onFinish == null || _onFinish(JSON.stringify(props, null, 2));
1220
1409
  case 1:
1221
1410
  case "end":
1222
- return _context5.stop();
1411
+ return _context8.stop();
1223
1412
  }
1224
- }, _callee5);
1413
+ }, _callee8);
1225
1414
  }));
1226
- function onFinish(_x6) {
1415
+ function onFinish(_x9) {
1227
1416
  return _onFinish2.apply(this, arguments);
1228
1417
  }
1229
1418
  return onFinish;
1230
1419
  }()
1231
1420
  };
1232
1421
  this.logger.debug("Streaming text with " + messages.length + " messages");
1233
- _context6.next = 9;
1422
+ _context9.next = 9;
1234
1423
  return streamText(_extends({
1235
1424
  messages: messages
1236
1425
  }, argsForExecute));
1237
1426
  case 9:
1238
- return _context6.abrupt("return", _context6.sent);
1427
+ return _context9.abrupt("return", _context9.sent);
1239
1428
  case 10:
1240
1429
  case "end":
1241
- return _context6.stop();
1430
+ return _context9.stop();
1242
1431
  }
1243
- }, _callee6, this);
1432
+ }, _callee9, this);
1244
1433
  }));
1245
- function stream(_x4) {
1434
+ function stream(_x7) {
1246
1435
  return _stream.apply(this, arguments);
1247
1436
  }
1248
1437
  return stream;
1249
1438
  }();
1439
+ _proto.streamObject = /*#__PURE__*/function () {
1440
+ var _streamObject2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref10) {
1441
+ var _this6 = this;
1442
+ var model, messages, _onStepFinish7, _onFinish3, _ref10$maxSteps, maxSteps, enabledTools, structuredOutput, modelToPass, params, argsForExecute, schema;
1443
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1444
+ while (1) switch (_context12.prev = _context12.next) {
1445
+ case 0:
1446
+ model = _ref10.model, messages = _ref10.messages, _onStepFinish7 = _ref10.onStepFinish, _onFinish3 = _ref10.onFinish, _ref10$maxSteps = _ref10.maxSteps, maxSteps = _ref10$maxSteps === void 0 ? 5 : _ref10$maxSteps, enabledTools = _ref10.enabledTools, structuredOutput = _ref10.structuredOutput;
1447
+ if ('name' in model) {
1448
+ modelToPass = {
1449
+ type: this.getModelType(model),
1450
+ name: model.name,
1451
+ toolChoice: model.toolChoice,
1452
+ apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
1453
+ baseURL: model.provider === 'LM_STUDIO' ? model.baseURL : undefined,
1454
+ fetch: model.provider === 'BASETEN' ? model.fetch : undefined
1455
+ };
1456
+ } else {
1457
+ modelToPass = model;
1458
+ }
1459
+ _context12.next = 4;
1460
+ return this.getParams({
1461
+ tools: this.convertTools(enabledTools),
1462
+ model: modelToPass
1463
+ });
1464
+ case 4:
1465
+ params = _context12.sent;
1466
+ argsForExecute = {
1467
+ model: params.modelDef,
1468
+ tools: _extends({}, params.toolsConverted, params.answerTool),
1469
+ toolChoice: params.toolChoice,
1470
+ maxSteps: maxSteps,
1471
+ onStepFinish: function () {
1472
+ var _onStepFinish8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(props) {
1473
+ var _props$response7, _props$response8;
1474
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1475
+ while (1) switch (_context10.prev = _context10.next) {
1476
+ case 0:
1477
+ _onStepFinish7 == null || _onStepFinish7(JSON.stringify(props, null, 2));
1478
+ if (!(props != null && (_props$response7 = props.response) != null && (_props$response7 = _props$response7.headers) != null && _props$response7['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response8 = props.response) == null || (_props$response8 = _props$response8.headers) == null ? void 0 : _props$response8['x-ratelimit-remaining-tokens'], 10) < 2000)) {
1479
+ _context10.next = 5;
1480
+ break;
1481
+ }
1482
+ _this6.logger.warn('Rate limit approaching, waiting 10 seconds');
1483
+ _context10.next = 5;
1484
+ return delay(10 * 1000);
1485
+ case 5:
1486
+ case "end":
1487
+ return _context10.stop();
1488
+ }
1489
+ }, _callee10);
1490
+ }));
1491
+ function onStepFinish(_x11) {
1492
+ return _onStepFinish8.apply(this, arguments);
1493
+ }
1494
+ return onStepFinish;
1495
+ }(),
1496
+ onFinish: function () {
1497
+ var _onFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(props) {
1498
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1499
+ while (1) switch (_context11.prev = _context11.next) {
1500
+ case 0:
1501
+ _onFinish3 == null || _onFinish3(JSON.stringify(props, null, 2));
1502
+ case 1:
1503
+ case "end":
1504
+ return _context11.stop();
1505
+ }
1506
+ }, _callee11);
1507
+ }));
1508
+ function onFinish(_x12) {
1509
+ return _onFinish4.apply(this, arguments);
1510
+ }
1511
+ return onFinish;
1512
+ }()
1513
+ };
1514
+ this.logger.debug("Streaming text with " + messages.length + " messages");
1515
+ schema = this.createOutputSchema(structuredOutput);
1516
+ _context12.next = 10;
1517
+ return streamObject(_extends({
1518
+ messages: messages
1519
+ }, argsForExecute, {
1520
+ output: 'object',
1521
+ schema: schema
1522
+ }));
1523
+ case 10:
1524
+ return _context12.abrupt("return", _context12.sent);
1525
+ case 11:
1526
+ case "end":
1527
+ return _context12.stop();
1528
+ }
1529
+ }, _callee12, this);
1530
+ }));
1531
+ function streamObject$1(_x10) {
1532
+ return _streamObject2.apply(this, arguments);
1533
+ }
1534
+ return streamObject$1;
1535
+ }();
1250
1536
  return LLM;
1251
1537
  }();
1252
1538
 
@@ -1322,13 +1608,51 @@ var Agent = /*#__PURE__*/function () {
1322
1608
  }
1323
1609
  return text;
1324
1610
  }();
1325
- _proto.stream = /*#__PURE__*/function () {
1326
- var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
1327
- var messages, onStepFinish, onFinish, _ref2$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
1611
+ _proto.textObject = /*#__PURE__*/function () {
1612
+ var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
1613
+ var messages, structuredOutput, onStepFinish, _ref2$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
1328
1614
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1329
1615
  while (1) switch (_context2.prev = _context2.next) {
1330
1616
  case 0:
1331
- messages = _ref2.messages, onStepFinish = _ref2.onStepFinish, onFinish = _ref2.onFinish, _ref2$maxSteps = _ref2.maxSteps, maxSteps = _ref2$maxSteps === void 0 ? 5 : _ref2$maxSteps;
1617
+ messages = _ref2.messages, structuredOutput = _ref2.structuredOutput, onStepFinish = _ref2.onStepFinish, _ref2$maxSteps = _ref2.maxSteps, maxSteps = _ref2$maxSteps === void 0 ? 5 : _ref2$maxSteps;
1618
+ this.logger.info("Starting text generation for agent " + this.name);
1619
+ systemMessage = {
1620
+ role: 'system',
1621
+ content: this.instructions
1622
+ };
1623
+ userMessages = messages.map(function (content) {
1624
+ return {
1625
+ role: 'user',
1626
+ content: content
1627
+ };
1628
+ });
1629
+ messageObjects = [systemMessage].concat(userMessages);
1630
+ return _context2.abrupt("return", this.llm.textObject({
1631
+ model: this.model,
1632
+ messages: messageObjects,
1633
+ structuredOutput: structuredOutput,
1634
+ enabledTools: this.enabledTools,
1635
+ onStepFinish: onStepFinish,
1636
+ maxSteps: maxSteps
1637
+ }));
1638
+ case 6:
1639
+ case "end":
1640
+ return _context2.stop();
1641
+ }
1642
+ }, _callee2, this);
1643
+ }));
1644
+ function textObject(_x2) {
1645
+ return _textObject.apply(this, arguments);
1646
+ }
1647
+ return textObject;
1648
+ }();
1649
+ _proto.stream = /*#__PURE__*/function () {
1650
+ var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
1651
+ var messages, onStepFinish, onFinish, _ref3$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
1652
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1653
+ while (1) switch (_context3.prev = _context3.next) {
1654
+ case 0:
1655
+ messages = _ref3.messages, onStepFinish = _ref3.onStepFinish, onFinish = _ref3.onFinish, _ref3$maxSteps = _ref3.maxSteps, maxSteps = _ref3$maxSteps === void 0 ? 5 : _ref3$maxSteps;
1332
1656
  this.logger.info("Starting stream generation for agent " + this.name);
1333
1657
  systemMessage = {
1334
1658
  role: 'system',
@@ -1341,7 +1665,7 @@ var Agent = /*#__PURE__*/function () {
1341
1665
  };
1342
1666
  });
1343
1667
  messageObjects = [systemMessage].concat(userMessages);
1344
- return _context2.abrupt("return", this.llm.stream({
1668
+ return _context3.abrupt("return", this.llm.stream({
1345
1669
  messages: messageObjects,
1346
1670
  model: this.model,
1347
1671
  enabledTools: this.enabledTools,
@@ -1351,19 +1675,57 @@ var Agent = /*#__PURE__*/function () {
1351
1675
  }));
1352
1676
  case 6:
1353
1677
  case "end":
1354
- return _context2.stop();
1678
+ return _context3.stop();
1355
1679
  }
1356
- }, _callee2, this);
1680
+ }, _callee3, this);
1357
1681
  }));
1358
- function stream(_x2) {
1682
+ function stream(_x3) {
1359
1683
  return _stream.apply(this, arguments);
1360
1684
  }
1361
1685
  return stream;
1362
1686
  }();
1687
+ _proto.streamObject = /*#__PURE__*/function () {
1688
+ var _streamObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4) {
1689
+ var messages, structuredOutput, onStepFinish, onFinish, _ref4$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
1690
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1691
+ while (1) switch (_context4.prev = _context4.next) {
1692
+ case 0:
1693
+ messages = _ref4.messages, structuredOutput = _ref4.structuredOutput, onStepFinish = _ref4.onStepFinish, onFinish = _ref4.onFinish, _ref4$maxSteps = _ref4.maxSteps, maxSteps = _ref4$maxSteps === void 0 ? 5 : _ref4$maxSteps;
1694
+ this.logger.info("Starting stream generation for agent " + this.name);
1695
+ systemMessage = {
1696
+ role: 'system',
1697
+ content: this.instructions
1698
+ };
1699
+ userMessages = messages.map(function (content) {
1700
+ return {
1701
+ role: 'user',
1702
+ content: content
1703
+ };
1704
+ });
1705
+ messageObjects = [systemMessage].concat(userMessages);
1706
+ return _context4.abrupt("return", this.llm.streamObject({
1707
+ messages: messageObjects,
1708
+ structuredOutput: structuredOutput,
1709
+ model: this.model,
1710
+ enabledTools: this.enabledTools,
1711
+ onStepFinish: onStepFinish,
1712
+ onFinish: onFinish,
1713
+ maxSteps: maxSteps
1714
+ }));
1715
+ case 6:
1716
+ case "end":
1717
+ return _context4.stop();
1718
+ }
1719
+ }, _callee4, this);
1720
+ }));
1721
+ function streamObject(_x4) {
1722
+ return _streamObject.apply(this, arguments);
1723
+ }
1724
+ return streamObject;
1725
+ }();
1363
1726
  return Agent;
1364
1727
  }();
1365
1728
 
1366
- // TODO: Passing the In/out generics works but seems to break on plugin to mastra, fix.
1367
1729
  function createTool(opts) {
1368
1730
  return opts;
1369
1731
  }
@@ -1590,6 +1952,10 @@ function MastraEngine(config) {};
1590
1952
 
1591
1953
  var MastraVector = function MastraVector() {};
1592
1954
 
1955
+ function createSync(opts) {
1956
+ return opts;
1957
+ }
1958
+
1593
1959
  var Mastra = /*#__PURE__*/function () {
1594
1960
  function Mastra(config) {
1595
1961
  var _config$integrations,
@@ -1641,8 +2007,12 @@ var Mastra = /*#__PURE__*/function () {
1641
2007
  memo[key] = _extends({}, val, {
1642
2008
  executor: function executor(params) {
1643
2009
  return val.executor(_extends({}, params, {
1644
- getIntegration: function getIntegration(name) {
1645
- return _this.getIntegration(name);
2010
+ integrationsRegistry: function integrationsRegistry() {
2011
+ return {
2012
+ get: function get(name) {
2013
+ return _this.getIntegration(name);
2014
+ }
2015
+ };
1646
2016
  },
1647
2017
  agents: _this.agents,
1648
2018
  llm: _this.llm,
@@ -1687,8 +2057,9 @@ var Mastra = /*#__PURE__*/function () {
1687
2057
  var _proto = Mastra.prototype;
1688
2058
  _proto.sync = /*#__PURE__*/function () {
1689
2059
  var _sync = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, params) {
1690
- var _this$syncs;
1691
- var syncFn;
2060
+ var _this$syncs,
2061
+ _this2 = this;
2062
+ var sync, syncFn;
1692
2063
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1693
2064
  while (1) switch (_context.prev = _context.next) {
1694
2065
  case 0:
@@ -1696,25 +2067,47 @@ var Mastra = /*#__PURE__*/function () {
1696
2067
  _context.next = 2;
1697
2068
  break;
1698
2069
  }
1699
- throw new Error("Sync function " + key + " not found");
2070
+ throw new Error("Engine is required to run syncs");
1700
2071
  case 2:
1701
- syncFn = (_this$syncs = this.syncs) == null ? void 0 : _this$syncs[key];
1702
- if (syncFn) {
2072
+ sync = (_this$syncs = this.syncs) == null ? void 0 : _this$syncs[key];
2073
+ if (sync) {
1703
2074
  _context.next = 5;
1704
2075
  break;
1705
2076
  }
1706
2077
  throw new Error("Sync function " + key + " not found");
1707
2078
  case 5:
1708
- _context.next = 7;
2079
+ syncFn = sync['executor'];
2080
+ if (syncFn) {
2081
+ _context.next = 8;
2082
+ break;
2083
+ }
2084
+ throw new Error("Sync function " + key + " not found");
2085
+ case 8:
2086
+ _context.next = 10;
1709
2087
  return syncFn({
1710
- tools: this.tools,
1711
- params: params,
2088
+ data: params,
1712
2089
  engine: this.engine,
1713
2090
  agents: this.agents,
1714
2091
  vectors: this.vectors,
1715
- llm: this.llm
2092
+ llm: this.llm,
2093
+ integrationsRegistry: function integrationsRegistry() {
2094
+ return {
2095
+ get: function get(name) {
2096
+ return _this2.getIntegration(name);
2097
+ }
2098
+ };
2099
+ },
2100
+ toolsRegistry: function toolsRegistry() {
2101
+ return {
2102
+ get: function get(name) {
2103
+ return _this2.getTool(name);
2104
+ }
2105
+ };
2106
+ }
1716
2107
  });
1717
- case 7:
2108
+ case 10:
2109
+ return _context.abrupt("return", _context.sent);
2110
+ case 11:
1718
2111
  case "end":
1719
2112
  return _context.stop();
1720
2113
  }
@@ -1741,7 +2134,7 @@ var Mastra = /*#__PURE__*/function () {
1741
2134
  return integration;
1742
2135
  };
1743
2136
  _proto.getTool = function getTool(name) {
1744
- var _this2 = this;
2137
+ var _this3 = this;
1745
2138
  var tool = this.tools[name];
1746
2139
  if (!tool) {
1747
2140
  throw new Error("Tool with name " + String(name) + " not found");
@@ -1757,13 +2150,13 @@ var Mastra = /*#__PURE__*/function () {
1757
2150
  integrationsRegistry: function integrationsRegistry() {
1758
2151
  return {
1759
2152
  get: function get(name) {
1760
- return _this2.getIntegration(name);
2153
+ return _this3.getIntegration(name);
1761
2154
  }
1762
2155
  };
1763
2156
  },
1764
- agents: _this2.agents,
1765
- llm: _this2.llm,
1766
- engine: _this2.engine
2157
+ agents: _this3.agents,
2158
+ llm: _this3.llm,
2159
+ engine: _this3.engine
1767
2160
  }));
1768
2161
  case 1:
1769
2162
  case "end":
@@ -1810,13 +2203,14 @@ function isTransitionEvent(stateEvent) {
1810
2203
  }
1811
2204
 
1812
2205
  var _logger = /*#__PURE__*/_classPrivateFieldLooseKey("logger");
2206
+ var _triggerSchema = /*#__PURE__*/_classPrivateFieldLooseKey("triggerSchema");
1813
2207
  var _steps = /*#__PURE__*/_classPrivateFieldLooseKey("steps");
2208
+ var _transitions = /*#__PURE__*/_classPrivateFieldLooseKey("transitions");
1814
2209
  var _machine = /*#__PURE__*/_classPrivateFieldLooseKey("machine");
1815
2210
  var _actor = /*#__PURE__*/_classPrivateFieldLooseKey("actor");
1816
2211
  var _log = /*#__PURE__*/_classPrivateFieldLooseKey("log");
1817
2212
  var _buildStateHierarchy = /*#__PURE__*/_classPrivateFieldLooseKey("buildStateHierarchy");
1818
2213
  var _isVariableReference = /*#__PURE__*/_classPrivateFieldLooseKey("isVariableReference");
1819
- var _createStepId = /*#__PURE__*/_classPrivateFieldLooseKey("createStepId");
1820
2214
  var _resolveVariables = /*#__PURE__*/_classPrivateFieldLooseKey("resolveVariables");
1821
2215
  var _cleanup = /*#__PURE__*/_classPrivateFieldLooseKey("cleanup");
1822
2216
  var _evaluateCondition = /*#__PURE__*/_classPrivateFieldLooseKey("evaluateCondition");
@@ -1830,7 +2224,11 @@ var Workflow = /*#__PURE__*/function () {
1830
2224
  * @param name - Identifier for the workflow (not necessarily unique)
1831
2225
  * @param logger - Optional logger instance
1832
2226
  */
1833
- function Workflow(name, logger) {
2227
+ function Workflow(_ref) {
2228
+ var name = _ref.name,
2229
+ logger = _ref.logger,
2230
+ steps = _ref.steps,
2231
+ triggerSchema = _ref.triggerSchema;
1834
2232
  /**
1835
2233
  * Detects unreachable steps in the workflow
1836
2234
  * @returns Array of ValidationError objects
@@ -1881,15 +2279,6 @@ var Workflow = /*#__PURE__*/function () {
1881
2279
  Object.defineProperty(this, _resolveVariables, {
1882
2280
  value: _resolveVariables2
1883
2281
  });
1884
- /**
1885
- * Creates a validated step ID, ensuring uniqueness within the workflow
1886
- * @param id - Proposed step ID
1887
- * @returns The validated and branded step ID
1888
- * @throws Error if ID is invalid or duplicate
1889
- */
1890
- Object.defineProperty(this, _createStepId, {
1891
- value: _createStepId2
1892
- });
1893
2282
  /**
1894
2283
  * Type guard to check if a value is a valid VariableReference
1895
2284
  * @param value - Value to check
@@ -1920,10 +2309,17 @@ var Workflow = /*#__PURE__*/function () {
1920
2309
  writable: true,
1921
2310
  value: void 0
1922
2311
  });
1923
- this.triggerSchema = void 0;
2312
+ Object.defineProperty(this, _triggerSchema, {
2313
+ writable: true,
2314
+ value: void 0
2315
+ });
1924
2316
  Object.defineProperty(this, _steps, {
1925
2317
  writable: true,
1926
- value: []
2318
+ value: void 0
2319
+ });
2320
+ Object.defineProperty(this, _transitions, {
2321
+ writable: true,
2322
+ value: {}
1927
2323
  });
1928
2324
  /** XState machine instance that orchestrates the workflow execution */
1929
2325
  Object.defineProperty(this, _machine, {
@@ -1937,6 +2333,8 @@ var Workflow = /*#__PURE__*/function () {
1937
2333
  });
1938
2334
  this.name = name;
1939
2335
  _classPrivateFieldLooseBase(this, _logger)[_logger] = logger;
2336
+ _classPrivateFieldLooseBase(this, _steps)[_steps] = steps;
2337
+ _classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema] = triggerSchema;
1940
2338
  this.initializeMachine();
1941
2339
  }
1942
2340
  var _proto = Workflow.prototype;
@@ -1953,10 +2351,10 @@ var Workflow = /*#__PURE__*/function () {
1953
2351
  types: {},
1954
2352
  actions: {
1955
2353
  updateStepResult: assign({
1956
- stepResults: function stepResults(_ref) {
2354
+ stepResults: function stepResults(_ref2) {
1957
2355
  var _event$output, _event$output2;
1958
- var context = _ref.context,
1959
- event = _ref.event;
2356
+ var context = _ref2.context,
2357
+ event = _ref2.event;
1960
2358
  if (!isTransitionEvent(event)) return context.stepResults;
1961
2359
  var stepId = (_event$output = event.output) == null ? void 0 : _event$output.stepId;
1962
2360
  if (!stepId) return context.stepResults;
@@ -1966,9 +2364,7 @@ var Workflow = /*#__PURE__*/function () {
1966
2364
  var _extends2;
1967
2365
  var newResults = _extends({}, context.stepResults, (_extends2 = {}, _extends2[stepId] = result, _extends2));
1968
2366
  // Get the step configuration
1969
- var step = _classPrivateFieldLooseBase(_this, _steps)[_steps].find(function (s) {
1970
- return s.id === stepId;
1971
- });
2367
+ var step = _classPrivateFieldLooseBase(_this, _transitions)[_transitions][stepId];
1972
2368
  // Evaluate transitions and send events
1973
2369
  if (step != null && step.transitions) {
1974
2370
  var fullContext = _extends({}, context, {
@@ -1976,12 +2372,12 @@ var Workflow = /*#__PURE__*/function () {
1976
2372
  });
1977
2373
  var hasMatchingCondition = false;
1978
2374
  _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, 'Evaluating transitions with context:', fullContext);
1979
- Object.entries(step.transitions).forEach(function (_ref2) {
1980
- var targetId = _ref2[0],
1981
- config = _ref2[1];
2375
+ Object.entries(step.transitions).forEach(function (_ref3) {
2376
+ var targetId = _ref3[0],
2377
+ config = _ref3[1];
1982
2378
  _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "Checking transition to: " + targetId);
1983
- _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "With condition: " + config.condition);
1984
- if (!config.condition || _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](config.condition, fullContext)) {
2379
+ _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "With condition: " + (config == null ? void 0 : config.condition));
2380
+ if (!(config != null && config.condition) || _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](config == null ? void 0 : config.condition, fullContext)) {
1985
2381
  hasMatchingCondition = true;
1986
2382
  _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, 'Condition passed, sending transition to:', targetId);
1987
2383
  Promise.resolve().then(function () {
@@ -2010,16 +2406,16 @@ var Workflow = /*#__PURE__*/function () {
2010
2406
  }
2011
2407
  }),
2012
2408
  setError: assign({
2013
- error: function error(_ref3) {
2014
- var event = _ref3.event;
2409
+ error: function error(_ref4) {
2410
+ var event = _ref4.event;
2015
2411
  if (!isErrorEvent(event)) return null;
2016
2412
  _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.ERROR, "Workflow error", event.error);
2017
2413
  return event.error;
2018
2414
  }
2019
2415
  }),
2020
2416
  initializeTriggerData: assign({
2021
- triggerData: function triggerData(_ref4) {
2022
- var context = _ref4.context;
2417
+ triggerData: function triggerData(_ref5) {
2418
+ var context = _ref5.context;
2023
2419
  _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.INFO, 'Workflow started', context == null ? void 0 : context.triggerData);
2024
2420
  return context == null ? void 0 : context.triggerData;
2025
2421
  }
@@ -2027,20 +2423,20 @@ var Workflow = /*#__PURE__*/function () {
2027
2423
  },
2028
2424
  actors: {
2029
2425
  resolverFunction: fromPromise(/*#__PURE__*/function () {
2030
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref5) {
2031
- var input, step, context, resolvedData, result;
2426
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
2427
+ var input, step, context, stepId, resolvedData, result;
2032
2428
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2033
2429
  while (1) switch (_context.prev = _context.next) {
2034
2430
  case 0:
2035
- input = _ref5.input;
2036
- step = input.step, context = input.context;
2431
+ input = _ref6.input;
2432
+ step = input.step, context = input.context, stepId = input.stepId;
2037
2433
  resolvedData = _classPrivateFieldLooseBase(_this, _resolveVariables)[_resolveVariables](step, context);
2038
2434
  _context.next = 5;
2039
2435
  return step.handler(resolvedData);
2040
2436
  case 5:
2041
2437
  result = _context.sent;
2042
2438
  return _context.abrupt("return", {
2043
- stepId: step.id,
2439
+ stepId: stepId,
2044
2440
  result: result
2045
2441
  });
2046
2442
  case 7:
@@ -2050,15 +2446,15 @@ var Workflow = /*#__PURE__*/function () {
2050
2446
  }, _callee);
2051
2447
  }));
2052
2448
  return function (_x) {
2053
- return _ref6.apply(this, arguments);
2449
+ return _ref7.apply(this, arguments);
2054
2450
  };
2055
2451
  }())
2056
2452
  }
2057
2453
  }).createMachine({
2058
2454
  id: this.name,
2059
2455
  initial: ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _steps)[_steps][0]) == null ? void 0 : _classPrivateFieldLoo.id) || 'idle',
2060
- context: function context(_ref7) {
2061
- var input = _ref7.input;
2456
+ context: function context(_ref8) {
2457
+ var input = _ref8.input;
2062
2458
  return _extends({}, input, {
2063
2459
  stepResults: {},
2064
2460
  error: null
@@ -2075,18 +2471,12 @@ var Workflow = /*#__PURE__*/function () {
2075
2471
  *
2076
2472
  * This is the last step of a workflow builder method chain
2077
2473
  * @throws Error if validation fails
2474
+ *
2475
+ * @returns this instance for method chaining
2078
2476
  */;
2079
2477
  _proto.commit = function commit() {
2080
2478
  _classPrivateFieldLooseBase(this, _validateWorkflow)[_validateWorkflow]();
2081
2479
  this.initializeMachine();
2082
- };
2083
- /**
2084
- * Sets the schema for validating trigger data
2085
- * @param schema - Zod schema for trigger data validation
2086
- * @returns this instance for method chaining
2087
- */
2088
- _proto.setTriggerSchema = function setTriggerSchema(schema) {
2089
- this.triggerSchema = schema;
2090
2480
  return this;
2091
2481
  };
2092
2482
  /**
@@ -2096,27 +2486,13 @@ var Workflow = /*#__PURE__*/function () {
2096
2486
  * @returns this instance for method chaining (builder pattern baybyyyy)
2097
2487
  * @throws Error if step ID is duplicate or variable resolution fails
2098
2488
  */
2099
- _proto.addStep = function addStep(id, config) {
2489
+ _proto.step = function step(id, config) {
2100
2490
  var _this2 = this;
2101
- var stepId = _classPrivateFieldLooseBase(this, _createStepId)[_createStepId](id);
2102
- var action = config.action,
2103
- inputSchema = config.inputSchema,
2104
- _config$variables = config.variables,
2105
- variables = _config$variables === void 0 ? {} : _config$variables,
2106
- _config$payload = config.payload,
2107
- payload = _config$payload === void 0 ? {} : _config$payload,
2108
- transitions = config.transitions;
2109
- // Validate transitions reference existing steps
2110
- if (transitions) {
2111
- Object.keys(transitions).forEach(function (targetId) {
2112
- // Skip validation for steps that will be added later
2113
- if (!_classPrivateFieldLooseBase(_this2, _steps)[_steps].some(function (s) {
2114
- return s.id === targetId;
2115
- })) {
2116
- _classPrivateFieldLooseBase(_this2, _log)[_log](LogLevel.DEBUG, "Step " + targetId + " not found yet, will be validated when workflow starts");
2117
- }
2118
- });
2119
- }
2491
+ var _ref9 = config || {},
2492
+ _ref9$variables = _ref9.variables,
2493
+ variables = _ref9$variables === void 0 ? {} : _ref9$variables,
2494
+ _ref9$transitions = _ref9.transitions,
2495
+ transitions = _ref9$transitions === void 0 ? undefined : _ref9$transitions;
2120
2496
  var requiredData = {};
2121
2497
  // Add valid variables to requiredData
2122
2498
  for (var _i = 0, _Object$entries = Object.entries(variables); _i < _Object$entries.length; _i++) {
@@ -2127,21 +2503,30 @@ var Workflow = /*#__PURE__*/function () {
2127
2503
  requiredData[key] = variable;
2128
2504
  }
2129
2505
  }
2130
- // Create step config
2131
- var stepConfig = {
2132
- id: stepId,
2506
+ _classPrivateFieldLooseBase(this, _transitions)[_transitions][id] = {
2507
+ transitions: transitions,
2508
+ data: requiredData,
2133
2509
  handler: function () {
2134
2510
  var _handler = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
2135
- var mergedData, validatedData;
2511
+ var step, inputSchema, payload, action, mergedData, validatedData;
2136
2512
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2137
2513
  while (1) switch (_context2.prev = _context2.next) {
2138
2514
  case 0:
2139
- // Merge static payload with dynamically resolved variables
2515
+ step = _classPrivateFieldLooseBase(_this2, _steps)[_steps].find(function (s) {
2516
+ return s.id === id;
2517
+ });
2518
+ if (step) {
2519
+ _context2.next = 3;
2520
+ break;
2521
+ }
2522
+ throw new Error("Step " + id + " not found");
2523
+ case 3:
2524
+ inputSchema = step.inputSchema, payload = step.payload, action = step.action; // Merge static payload with dynamically resolved variables
2140
2525
  // Variables take precedence over payload values
2141
2526
  mergedData = _extends({}, payload, data); // Validate complete input data
2142
2527
  validatedData = inputSchema ? inputSchema.parse(mergedData) : mergedData;
2143
- return _context2.abrupt("return", action(validatedData));
2144
- case 3:
2528
+ return _context2.abrupt("return", action ? action(validatedData) : {});
2529
+ case 7:
2145
2530
  case "end":
2146
2531
  return _context2.stop();
2147
2532
  }
@@ -2151,12 +2536,8 @@ var Workflow = /*#__PURE__*/function () {
2151
2536
  return _handler.apply(this, arguments);
2152
2537
  }
2153
2538
  return handler;
2154
- }(),
2155
- inputSchema: inputSchema,
2156
- requiredData: requiredData,
2157
- transitions: transitions
2539
+ }()
2158
2540
  };
2159
- _classPrivateFieldLooseBase(this, _steps)[_steps].push(stepConfig);
2160
2541
  return this;
2161
2542
  };
2162
2543
  /**
@@ -2165,10 +2546,10 @@ var Workflow = /*#__PURE__*/function () {
2165
2546
  * @returns Promise resolving to workflow results or rejecting with error
2166
2547
  * @throws Error if trigger schema validation fails
2167
2548
  */
2168
- _proto.executeWorkflow =
2549
+ _proto.execute =
2169
2550
  /*#__PURE__*/
2170
2551
  function () {
2171
- var _executeWorkflow = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(triggerData) {
2552
+ var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(triggerData) {
2172
2553
  var _this3 = this;
2173
2554
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2174
2555
  while (1) switch (_context3.prev = _context3.next) {
@@ -2178,12 +2559,12 @@ var Workflow = /*#__PURE__*/function () {
2178
2559
  triggerData: triggerData
2179
2560
  });
2180
2561
  case 2:
2181
- if (!this.triggerSchema) {
2562
+ if (!_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema]) {
2182
2563
  _context3.next = 14;
2183
2564
  break;
2184
2565
  }
2185
2566
  _context3.prev = 3;
2186
- this.triggerSchema.parse(triggerData);
2567
+ _classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema].parse(triggerData);
2187
2568
  _context3.next = 7;
2188
2569
  return _classPrivateFieldLooseBase(this, _log)[_log](LogLevel.DEBUG, 'Trigger schema validation passed');
2189
2570
  case 7:
@@ -2240,10 +2621,10 @@ var Workflow = /*#__PURE__*/function () {
2240
2621
  }
2241
2622
  }, _callee3, this, [[3, 9]]);
2242
2623
  }));
2243
- function executeWorkflow(_x3) {
2244
- return _executeWorkflow.apply(this, arguments);
2624
+ function execute(_x3) {
2625
+ return _execute.apply(this, arguments);
2245
2626
  }
2246
- return executeWorkflow;
2627
+ return execute;
2247
2628
  }();
2248
2629
  return Workflow;
2249
2630
  }();
@@ -2252,7 +2633,7 @@ function _log2(_x4, _x5, _x6, _x7) {
2252
2633
  }
2253
2634
  function _log3() {
2254
2635
  _log3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(level, message, data, stepId) {
2255
- var _classPrivateFieldLoo2, _classPrivateFieldLoo3;
2636
+ var _classPrivateFieldLoo5, _classPrivateFieldLoo6;
2256
2637
  var logMessage, logMethod;
2257
2638
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2258
2639
  while (1) switch (_context4.prev = _context4.next) {
@@ -2273,7 +2654,7 @@ function _log3() {
2273
2654
  };
2274
2655
  logMethod = level.toLowerCase();
2275
2656
  _context4.next = 6;
2276
- return (_classPrivateFieldLoo2 = (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _logger)[_logger])[logMethod]) == null ? void 0 : _classPrivateFieldLoo2.call(_classPrivateFieldLoo3, logMessage);
2657
+ return (_classPrivateFieldLoo5 = (_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(this, _logger)[_logger])[logMethod]) == null ? void 0 : _classPrivateFieldLoo5.call(_classPrivateFieldLoo6, logMessage);
2277
2658
  case 6:
2278
2659
  case "end":
2279
2660
  return _context4.stop();
@@ -2295,6 +2676,7 @@ function _buildStateHierarchy2() {
2295
2676
  };
2296
2677
  // Helper to build nested state structure
2297
2678
  var buildState = function buildState(currentStepId, visited) {
2679
+ var _classPrivateFieldLoo2, _classPrivateFieldLoo3;
2298
2680
  if (visited.has(currentStepId)) return null;
2299
2681
  visited.add(currentStepId);
2300
2682
  var currentStep = _classPrivateFieldLooseBase(_this4, _steps)[_steps].find(function (s) {
@@ -2304,17 +2686,18 @@ function _buildStateHierarchy2() {
2304
2686
  var state = {
2305
2687
  invoke: {
2306
2688
  src: 'resolverFunction',
2307
- input: function input(_ref8) {
2308
- var context = _ref8.context;
2689
+ input: function input(_ref10) {
2690
+ var context = _ref10.context;
2309
2691
  return {
2310
- step: currentStep,
2311
- context: context
2692
+ context: context,
2693
+ stepId: currentStepId,
2694
+ step: _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]
2312
2695
  };
2313
2696
  },
2314
2697
  onDone: {
2315
2698
  actions: ['updateStepResult'],
2316
2699
  // If no transitions, go to success state
2317
- target: currentStep.transitions ? undefined : 'success'
2700
+ target: (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) != null && _classPrivateFieldLoo2.transitions ? undefined : 'success'
2318
2701
  },
2319
2702
  onError: {
2320
2703
  target: 'failure',
@@ -2335,16 +2718,17 @@ function _buildStateHierarchy2() {
2335
2718
  }
2336
2719
  };
2337
2720
  // Handle transitions
2338
- if (currentStep.transitions) {
2339
- Object.entries(currentStep.transitions).forEach(function (_ref9) {
2340
- var targetId = _ref9[0],
2341
- config = _ref9[1];
2721
+ if ((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) != null && _classPrivateFieldLoo3.transitions) {
2722
+ var _classPrivateFieldLoo4;
2723
+ Object.entries((_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) == null ? void 0 : _classPrivateFieldLoo4.transitions).forEach(function (_ref11) {
2724
+ var targetId = _ref11[0],
2725
+ config = _ref11[1];
2342
2726
  // Create flat state structure with transitions
2343
2727
  state.on["TRANSITION_" + targetId] = {
2344
2728
  target: targetId,
2345
- guard: function guard(_ref10) {
2346
- var context = _ref10.context;
2347
- return !config.condition || _classPrivateFieldLooseBase(_this4, _evaluateCondition)[_evaluateCondition](config.condition, context);
2729
+ guard: function guard(_ref12) {
2730
+ var context = _ref12.context;
2731
+ return !(config != null && config.condition) || _classPrivateFieldLooseBase(_this4, _evaluateCondition)[_evaluateCondition](config == null ? void 0 : config.condition, context);
2348
2732
  }
2349
2733
  };
2350
2734
  });
@@ -2364,18 +2748,9 @@ function _buildStateHierarchy2() {
2364
2748
  function _isVariableReference2(value) {
2365
2749
  return typeof value === 'object' && 'stepId' in value && 'path' in value;
2366
2750
  }
2367
- function _createStepId2(id) {
2368
- // Check for duplicates
2369
- if (_classPrivateFieldLooseBase(this, _steps)[_steps].some(function (step) {
2370
- return step.id === id;
2371
- })) {
2372
- throw new Error("Step with ID \"" + id + "\" already exists in workflow \"" + this.name + "\"");
2373
- }
2374
- return id;
2375
- }
2376
2751
  function _resolveVariables2(stepConfig, context) {
2377
2752
  var resolvedData = {};
2378
- for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.requiredData); _i2 < _Object$entries2.length; _i2++) {
2753
+ for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.data); _i2 < _Object$entries2.length; _i2++) {
2379
2754
  var _Object$entries2$_i = _Object$entries2[_i2],
2380
2755
  key = _Object$entries2$_i[0],
2381
2756
  variable = _Object$entries2$_i[1];
@@ -2458,9 +2833,7 @@ function _detectCircularDependencies2() {
2458
2833
  return;
2459
2834
  }
2460
2835
  stack.push(stepId);
2461
- var step = _classPrivateFieldLooseBase(_this6, _steps)[_steps].find(function (s) {
2462
- return s.id === stepId;
2463
- });
2836
+ var step = _classPrivateFieldLooseBase(_this6, _transitions)[_transitions][stepId];
2464
2837
  if (step != null && step.transitions) {
2465
2838
  Object.keys(step.transitions).forEach(function (targetId) {
2466
2839
  _dfs(targetId);
@@ -2486,9 +2859,7 @@ function _validateTerminalPaths2() {
2486
2859
  if (hasTerminalPath.has(stepId)) return true;
2487
2860
  if (visited.has(stepId) && !hasTerminalPath.has(stepId)) return false;
2488
2861
  visited.add(stepId);
2489
- var step = _classPrivateFieldLooseBase(_this7, _steps)[_steps].find(function (s) {
2490
- return s.id === stepId;
2491
- });
2862
+ var step = _classPrivateFieldLooseBase(_this7, _transitions)[_transitions][stepId];
2492
2863
  if (!step) return false;
2493
2864
  // Terminal step
2494
2865
  if (!step.transitions) {
@@ -2531,9 +2902,7 @@ function _detectUnreachableSteps2() {
2531
2902
  var _dfs3 = function dfs(stepId) {
2532
2903
  if (reachableSteps.has(stepId)) return;
2533
2904
  reachableSteps.add(stepId);
2534
- var step = _classPrivateFieldLooseBase(_this8, _steps)[_steps].find(function (s) {
2535
- return s.id === stepId;
2536
- });
2905
+ var step = _classPrivateFieldLooseBase(_this8, _transitions)[_transitions][stepId];
2537
2906
  if (step != null && step.transitions) {
2538
2907
  Object.keys(step.transitions).forEach(function (targetId) {
2539
2908
  _dfs3(targetId);
@@ -2559,5 +2928,23 @@ function _detectUnreachableSteps2() {
2559
2928
  return errors;
2560
2929
  }
2561
2930
 
2562
- export { Agent, BaseLogger, FieldTypePrimitiveMap, FilterOperators, Integration, LogLevel, Mastra, MastraEngine, MastraVector, MultiLogger, PropertyType, RegisteredLogger, Workflow, buildQueryString, createLogger, createMultiLogger, createTool, filterQuerySchema, getJSONField, sortQuerySchema, splitAndStripQuotes, transformFilterValueArray, transformFilterValueBoolean };
2931
+ var Step = function Step(_ref) {
2932
+ var id = _ref.id,
2933
+ inputSchema = _ref.inputSchema,
2934
+ outputSchema = _ref.outputSchema,
2935
+ payload = _ref.payload,
2936
+ action = _ref.action;
2937
+ this.id = void 0;
2938
+ this.inputSchema = void 0;
2939
+ this.outputSchema = void 0;
2940
+ this.payload = void 0;
2941
+ this.action = void 0;
2942
+ this.id = id;
2943
+ this.inputSchema = inputSchema;
2944
+ this.payload = payload;
2945
+ this.outputSchema = outputSchema;
2946
+ this.action = action;
2947
+ };
2948
+
2949
+ export { Agent, BaseLogger, FieldTypePrimitiveMap, FilterOperators, Integration, LogLevel, Mastra, MastraEngine, MastraVector, MultiLogger, PropertyType, RegisteredLogger, Step, Workflow, buildQueryString, createLogger, createMultiLogger, createSync, createTool, filterQuerySchema, getJSONField, sortQuerySchema, splitAndStripQuotes, transformFilterValueArray, transformFilterValueBoolean };
2563
2950
  //# sourceMappingURL=core.esm.js.map