@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.
- package/README.md +1 -1
- package/dist/agent/index.d.ts +20 -2
- package/dist/core.cjs.development.js +597 -208
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +596 -209
- package/dist/core.esm.js.map +1 -1
- package/dist/engine/index.d.ts +3 -4
- package/dist/engine/schema.d.ts +0 -1
- package/dist/engine/types.d.ts +1 -2
- package/dist/engine/utils.d.ts +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/integration/index.d.ts +0 -1
- package/dist/integration/test-integration.d.ts +12 -0
- package/dist/llm/index.d.ts +32 -2
- package/dist/llm/types.d.ts +33 -1
- package/dist/logger/index.d.ts +0 -1
- package/dist/mastra/index.d.ts +4 -4
- package/dist/mastra/types.d.ts +1 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/types.d.ts +23 -11
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/types.d.ts +3 -3
- package/dist/utils.d.ts +0 -1
- package/dist/vector/index.d.ts +0 -1
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/step.d.ts +15 -0
- package/dist/workflows/types.d.ts +25 -24
- package/dist/workflows/utils.d.ts +0 -1
- package/dist/workflows/{main.d.ts → workflow.d.ts} +13 -13
- package/package.json +16 -8
- package/dist/agent/index.d.ts.map +0 -1
- package/dist/engine/index.d.ts.map +0 -1
- package/dist/engine/schema.d.ts.map +0 -1
- package/dist/engine/types.d.ts.map +0 -1
- package/dist/engine/utils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/integration/index.d.ts.map +0 -1
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/types.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/mastra/index.d.ts.map +0 -1
- package/dist/sync/types.d.ts.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/vector/index.d.ts.map +0 -1
- package/dist/workflows/index.d.ts.map +0 -1
- package/dist/workflows/main.d.ts.map +0 -1
- package/dist/workflows/types.d.ts.map +0 -1
- package/dist/workflows/utils.d.ts.map +0 -1
|
@@ -18,7 +18,7 @@ var ai = require('ai');
|
|
|
18
18
|
var zod = require('zod');
|
|
19
19
|
var sift = require('sift');
|
|
20
20
|
var xstate = require('xstate');
|
|
21
|
-
var get = require('lodash/get');
|
|
21
|
+
var get = require('lodash-es/get');
|
|
22
22
|
|
|
23
23
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
24
24
|
try {
|
|
@@ -847,6 +847,7 @@ var LLM = /*#__PURE__*/function () {
|
|
|
847
847
|
COHERE: 'cohere',
|
|
848
848
|
AZURE: 'azure',
|
|
849
849
|
AMAZON: 'amazon',
|
|
850
|
+
//
|
|
850
851
|
ANTHROPIC_VERTEX: 'anthropic-vertex'
|
|
851
852
|
};
|
|
852
853
|
var type = (_providerToType$model = providerToType[model.provider]) != null ? _providerToType$model : model.provider;
|
|
@@ -1003,16 +1004,79 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1003
1004
|
}
|
|
1004
1005
|
return modelDef;
|
|
1005
1006
|
};
|
|
1006
|
-
_proto.
|
|
1007
|
-
var
|
|
1008
|
-
var
|
|
1007
|
+
_proto.createEmbedding = /*#__PURE__*/function () {
|
|
1008
|
+
var _createEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
|
|
1009
|
+
var model, value, maxRetries, embeddingModel, openai$1, cohere$1;
|
|
1009
1010
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1010
1011
|
while (1) switch (_context.prev = _context.next) {
|
|
1011
1012
|
case 0:
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1013
|
+
model = _ref3.model, value = _ref3.value, maxRetries = _ref3.maxRetries;
|
|
1014
|
+
if (!(model.provider === 'OPEN_AI')) {
|
|
1015
|
+
_context.next = 6;
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
1018
|
+
openai$1 = openai.createOpenAI({
|
|
1019
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
1020
|
+
});
|
|
1021
|
+
embeddingModel = openai$1.embedding(model.name);
|
|
1022
|
+
_context.next = 12;
|
|
1023
|
+
break;
|
|
1024
|
+
case 6:
|
|
1025
|
+
if (!(model.provider === 'COHERE')) {
|
|
1026
|
+
_context.next = 11;
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
cohere$1 = cohere.createCohere({
|
|
1030
|
+
apiKey: process.env.COHERE_API_KEY
|
|
1031
|
+
});
|
|
1032
|
+
embeddingModel = cohere$1.embedding(model.name);
|
|
1033
|
+
_context.next = 12;
|
|
1034
|
+
break;
|
|
1035
|
+
case 11:
|
|
1036
|
+
throw new Error("Invalid embedding model");
|
|
1037
|
+
case 12:
|
|
1038
|
+
if (!(value instanceof Array)) {
|
|
1039
|
+
_context.next = 16;
|
|
1040
|
+
break;
|
|
1041
|
+
}
|
|
1042
|
+
_context.next = 15;
|
|
1043
|
+
return ai.embedMany({
|
|
1044
|
+
model: embeddingModel,
|
|
1045
|
+
values: value,
|
|
1046
|
+
maxRetries: maxRetries
|
|
1047
|
+
});
|
|
1048
|
+
case 15:
|
|
1049
|
+
return _context.abrupt("return", _context.sent);
|
|
1050
|
+
case 16:
|
|
1051
|
+
_context.next = 18;
|
|
1052
|
+
return ai.embed({
|
|
1053
|
+
model: embeddingModel,
|
|
1054
|
+
value: value,
|
|
1055
|
+
maxRetries: maxRetries
|
|
1056
|
+
});
|
|
1057
|
+
case 18:
|
|
1058
|
+
return _context.abrupt("return", _context.sent);
|
|
1059
|
+
case 19:
|
|
1060
|
+
case "end":
|
|
1061
|
+
return _context.stop();
|
|
1062
|
+
}
|
|
1063
|
+
}, _callee);
|
|
1064
|
+
}));
|
|
1065
|
+
function createEmbedding(_x) {
|
|
1066
|
+
return _createEmbedding.apply(this, arguments);
|
|
1067
|
+
}
|
|
1068
|
+
return createEmbedding;
|
|
1069
|
+
}();
|
|
1070
|
+
_proto.getParams = /*#__PURE__*/function () {
|
|
1071
|
+
var _getParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
|
|
1072
|
+
var tools, resultTool, model, toolsConverted, answerTool, modelDef;
|
|
1073
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1074
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1075
|
+
case 0:
|
|
1076
|
+
tools = _ref4.tools, resultTool = _ref4.resultTool, model = _ref4.model;
|
|
1077
|
+
toolsConverted = Object.entries(tools).reduce(function (memo, _ref5) {
|
|
1078
|
+
var key = _ref5[0],
|
|
1079
|
+
val = _ref5[1];
|
|
1016
1080
|
memo[key] = ai.tool(val);
|
|
1017
1081
|
return memo;
|
|
1018
1082
|
}, {});
|
|
@@ -1023,29 +1087,29 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1023
1087
|
};
|
|
1024
1088
|
}
|
|
1025
1089
|
if (!('type' in model)) {
|
|
1026
|
-
|
|
1090
|
+
_context2.next = 8;
|
|
1027
1091
|
break;
|
|
1028
1092
|
}
|
|
1029
1093
|
modelDef = this.createModelDef({
|
|
1030
1094
|
model: model
|
|
1031
1095
|
});
|
|
1032
|
-
|
|
1096
|
+
_context2.next = 15;
|
|
1033
1097
|
break;
|
|
1034
1098
|
case 8:
|
|
1035
1099
|
if (!(model.model instanceof Function)) {
|
|
1036
|
-
|
|
1100
|
+
_context2.next = 14;
|
|
1037
1101
|
break;
|
|
1038
1102
|
}
|
|
1039
|
-
|
|
1103
|
+
_context2.next = 11;
|
|
1040
1104
|
return model.model();
|
|
1041
1105
|
case 11:
|
|
1042
|
-
modelDef =
|
|
1043
|
-
|
|
1106
|
+
modelDef = _context2.sent;
|
|
1107
|
+
_context2.next = 15;
|
|
1044
1108
|
break;
|
|
1045
1109
|
case 14:
|
|
1046
1110
|
modelDef = model.model;
|
|
1047
1111
|
case 15:
|
|
1048
|
-
return
|
|
1112
|
+
return _context2.abrupt("return", {
|
|
1049
1113
|
toolsConverted: toolsConverted,
|
|
1050
1114
|
modelDef: modelDef,
|
|
1051
1115
|
answerTool: answerTool,
|
|
@@ -1053,11 +1117,11 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1053
1117
|
});
|
|
1054
1118
|
case 16:
|
|
1055
1119
|
case "end":
|
|
1056
|
-
return
|
|
1120
|
+
return _context2.stop();
|
|
1057
1121
|
}
|
|
1058
|
-
},
|
|
1122
|
+
}, _callee2, this);
|
|
1059
1123
|
}));
|
|
1060
|
-
function getParams(
|
|
1124
|
+
function getParams(_x2) {
|
|
1061
1125
|
return _getParams.apply(this, arguments);
|
|
1062
1126
|
}
|
|
1063
1127
|
return getParams;
|
|
@@ -1082,14 +1146,59 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1082
1146
|
this.logger.debug("Converted tools for LLM", converted);
|
|
1083
1147
|
return converted;
|
|
1084
1148
|
};
|
|
1149
|
+
_proto.isBaseOutputType = function isBaseOutputType(outputType) {
|
|
1150
|
+
return outputType === 'string' || outputType === 'number' || outputType === 'boolean' || outputType === 'date';
|
|
1151
|
+
};
|
|
1152
|
+
_proto.baseOutputTypeSchema = function baseOutputTypeSchema(outputType) {
|
|
1153
|
+
switch (outputType) {
|
|
1154
|
+
case 'string':
|
|
1155
|
+
return zod.z.string();
|
|
1156
|
+
case 'number':
|
|
1157
|
+
return zod.z.number();
|
|
1158
|
+
case 'boolean':
|
|
1159
|
+
return zod.z["boolean"]();
|
|
1160
|
+
case 'date':
|
|
1161
|
+
return zod.z.string().datetime();
|
|
1162
|
+
default:
|
|
1163
|
+
return zod.z.string();
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
_proto.createOutputSchema = function createOutputSchema(output) {
|
|
1167
|
+
var _this2 = this;
|
|
1168
|
+
var schema = Object.entries(output).reduce(function (memo, _ref6) {
|
|
1169
|
+
var k = _ref6[0],
|
|
1170
|
+
v = _ref6[1];
|
|
1171
|
+
if (_this2.isBaseOutputType(v.type)) {
|
|
1172
|
+
memo[k] = _this2.baseOutputTypeSchema(v.type);
|
|
1173
|
+
}
|
|
1174
|
+
if (v.type === 'object') {
|
|
1175
|
+
var objectItem = v.items;
|
|
1176
|
+
var objectItemSchema = _this2.createOutputSchema(objectItem);
|
|
1177
|
+
memo[k] = objectItemSchema;
|
|
1178
|
+
}
|
|
1179
|
+
if (v.type === 'array') {
|
|
1180
|
+
var arrayItem = v.items;
|
|
1181
|
+
if (_this2.isBaseOutputType(arrayItem.type)) {
|
|
1182
|
+
var itemSchema = _this2.baseOutputTypeSchema(arrayItem.type);
|
|
1183
|
+
memo[k] = zod.z.array(itemSchema);
|
|
1184
|
+
}
|
|
1185
|
+
if (arrayItem.type === 'object') {
|
|
1186
|
+
var objectInArrayItemSchema = _this2.createOutputSchema(arrayItem.items);
|
|
1187
|
+
memo[k] = zod.z.array(objectInArrayItemSchema);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return memo;
|
|
1191
|
+
}, {});
|
|
1192
|
+
return zod.z.object(schema);
|
|
1193
|
+
};
|
|
1085
1194
|
_proto.text = /*#__PURE__*/function () {
|
|
1086
|
-
var _text = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1087
|
-
var
|
|
1088
|
-
var model, messages, _onStepFinish,
|
|
1089
|
-
return _regeneratorRuntime().wrap(function
|
|
1090
|
-
while (1) switch (
|
|
1195
|
+
var _text = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref7) {
|
|
1196
|
+
var _this3 = this;
|
|
1197
|
+
var model, messages, _onStepFinish, _ref7$maxSteps, maxSteps, enabledTools, modelToPass, params, argsForExecute;
|
|
1198
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1199
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
1091
1200
|
case 0:
|
|
1092
|
-
model =
|
|
1201
|
+
model = _ref7.model, messages = _ref7.messages, _onStepFinish = _ref7.onStepFinish, _ref7$maxSteps = _ref7.maxSteps, maxSteps = _ref7$maxSteps === void 0 ? 5 : _ref7$maxSteps, enabledTools = _ref7.enabledTools;
|
|
1093
1202
|
if ('name' in model) {
|
|
1094
1203
|
modelToPass = {
|
|
1095
1204
|
type: this.getModelType(model),
|
|
@@ -1102,70 +1211,70 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1102
1211
|
} else {
|
|
1103
1212
|
modelToPass = model;
|
|
1104
1213
|
}
|
|
1105
|
-
|
|
1214
|
+
_context4.next = 4;
|
|
1106
1215
|
return this.getParams({
|
|
1107
1216
|
tools: this.convertTools(enabledTools || {}),
|
|
1108
1217
|
model: modelToPass
|
|
1109
1218
|
});
|
|
1110
1219
|
case 4:
|
|
1111
|
-
params =
|
|
1220
|
+
params = _context4.sent;
|
|
1112
1221
|
argsForExecute = {
|
|
1113
1222
|
model: params.modelDef,
|
|
1114
1223
|
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1115
1224
|
toolChoice: params.toolChoice,
|
|
1116
1225
|
maxSteps: maxSteps,
|
|
1117
1226
|
onStepFinish: function () {
|
|
1118
|
-
var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1227
|
+
var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(props) {
|
|
1119
1228
|
var _props$response, _props$response2;
|
|
1120
|
-
return _regeneratorRuntime().wrap(function
|
|
1121
|
-
while (1) switch (
|
|
1229
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1230
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1122
1231
|
case 0:
|
|
1123
1232
|
_onStepFinish == null || _onStepFinish(JSON.stringify(props, null, 2));
|
|
1124
1233
|
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)) {
|
|
1125
|
-
|
|
1234
|
+
_context3.next = 5;
|
|
1126
1235
|
break;
|
|
1127
1236
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1237
|
+
_this3.logger.warn('Rate limit approaching, waiting 10 seconds');
|
|
1238
|
+
_context3.next = 5;
|
|
1130
1239
|
return delay(10 * 1000);
|
|
1131
1240
|
case 5:
|
|
1132
1241
|
case "end":
|
|
1133
|
-
return
|
|
1242
|
+
return _context3.stop();
|
|
1134
1243
|
}
|
|
1135
|
-
},
|
|
1244
|
+
}, _callee3);
|
|
1136
1245
|
}));
|
|
1137
|
-
function onStepFinish(
|
|
1246
|
+
function onStepFinish(_x4) {
|
|
1138
1247
|
return _onStepFinish2.apply(this, arguments);
|
|
1139
1248
|
}
|
|
1140
1249
|
return onStepFinish;
|
|
1141
1250
|
}()
|
|
1142
1251
|
};
|
|
1143
1252
|
this.logger.debug("Generating text with " + messages.length + " messages");
|
|
1144
|
-
|
|
1253
|
+
_context4.next = 9;
|
|
1145
1254
|
return ai.generateText(_extends({
|
|
1146
1255
|
messages: messages
|
|
1147
1256
|
}, argsForExecute));
|
|
1148
1257
|
case 9:
|
|
1149
|
-
return
|
|
1258
|
+
return _context4.abrupt("return", _context4.sent);
|
|
1150
1259
|
case 10:
|
|
1151
1260
|
case "end":
|
|
1152
|
-
return
|
|
1261
|
+
return _context4.stop();
|
|
1153
1262
|
}
|
|
1154
|
-
},
|
|
1263
|
+
}, _callee4, this);
|
|
1155
1264
|
}));
|
|
1156
|
-
function text(
|
|
1265
|
+
function text(_x3) {
|
|
1157
1266
|
return _text.apply(this, arguments);
|
|
1158
1267
|
}
|
|
1159
1268
|
return text;
|
|
1160
1269
|
}();
|
|
1161
|
-
_proto.
|
|
1162
|
-
var
|
|
1163
|
-
var
|
|
1164
|
-
var model, messages, _onStepFinish3,
|
|
1270
|
+
_proto.textObject = /*#__PURE__*/function () {
|
|
1271
|
+
var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref8) {
|
|
1272
|
+
var _this4 = this;
|
|
1273
|
+
var model, messages, _onStepFinish3, _ref8$maxSteps, maxSteps, enabledTools, structuredOutput, modelToPass, params, argsForExecute, schema;
|
|
1165
1274
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
1166
1275
|
while (1) switch (_context6.prev = _context6.next) {
|
|
1167
1276
|
case 0:
|
|
1168
|
-
model =
|
|
1277
|
+
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;
|
|
1169
1278
|
if ('name' in model) {
|
|
1170
1279
|
modelToPass = {
|
|
1171
1280
|
type: this.getModelType(model),
|
|
@@ -1180,7 +1289,7 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1180
1289
|
}
|
|
1181
1290
|
_context6.next = 4;
|
|
1182
1291
|
return this.getParams({
|
|
1183
|
-
tools: this.convertTools(enabledTools),
|
|
1292
|
+
tools: this.convertTools(enabledTools || {}),
|
|
1184
1293
|
model: modelToPass
|
|
1185
1294
|
});
|
|
1186
1295
|
case 4:
|
|
@@ -1191,66 +1300,243 @@ var LLM = /*#__PURE__*/function () {
|
|
|
1191
1300
|
toolChoice: params.toolChoice,
|
|
1192
1301
|
maxSteps: maxSteps,
|
|
1193
1302
|
onStepFinish: function () {
|
|
1194
|
-
var _onStepFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1303
|
+
var _onStepFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(props) {
|
|
1195
1304
|
var _props$response3, _props$response4;
|
|
1196
|
-
return _regeneratorRuntime().wrap(function
|
|
1197
|
-
while (1) switch (
|
|
1305
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
1306
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
1198
1307
|
case 0:
|
|
1199
1308
|
_onStepFinish3 == null || _onStepFinish3(JSON.stringify(props, null, 2));
|
|
1200
1309
|
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)) {
|
|
1201
|
-
|
|
1310
|
+
_context5.next = 5;
|
|
1202
1311
|
break;
|
|
1203
1312
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1313
|
+
_this4.logger.warn('Rate limit approaching, waiting 10 seconds');
|
|
1314
|
+
_context5.next = 5;
|
|
1206
1315
|
return delay(10 * 1000);
|
|
1207
1316
|
case 5:
|
|
1208
1317
|
case "end":
|
|
1209
|
-
return
|
|
1318
|
+
return _context5.stop();
|
|
1210
1319
|
}
|
|
1211
|
-
},
|
|
1320
|
+
}, _callee5);
|
|
1212
1321
|
}));
|
|
1213
|
-
function onStepFinish(
|
|
1322
|
+
function onStepFinish(_x6) {
|
|
1214
1323
|
return _onStepFinish4.apply(this, arguments);
|
|
1215
1324
|
}
|
|
1216
1325
|
return onStepFinish;
|
|
1326
|
+
}()
|
|
1327
|
+
};
|
|
1328
|
+
this.logger.debug("Generating text with " + messages.length + " messages");
|
|
1329
|
+
schema = this.createOutputSchema(structuredOutput);
|
|
1330
|
+
_context6.next = 10;
|
|
1331
|
+
return ai.generateObject(_extends({
|
|
1332
|
+
messages: messages
|
|
1333
|
+
}, argsForExecute, {
|
|
1334
|
+
output: 'object',
|
|
1335
|
+
schema: schema
|
|
1336
|
+
}));
|
|
1337
|
+
case 10:
|
|
1338
|
+
return _context6.abrupt("return", _context6.sent);
|
|
1339
|
+
case 11:
|
|
1340
|
+
case "end":
|
|
1341
|
+
return _context6.stop();
|
|
1342
|
+
}
|
|
1343
|
+
}, _callee6, this);
|
|
1344
|
+
}));
|
|
1345
|
+
function textObject(_x5) {
|
|
1346
|
+
return _textObject.apply(this, arguments);
|
|
1347
|
+
}
|
|
1348
|
+
return textObject;
|
|
1349
|
+
}();
|
|
1350
|
+
_proto.stream = /*#__PURE__*/function () {
|
|
1351
|
+
var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref9) {
|
|
1352
|
+
var _this5 = this;
|
|
1353
|
+
var model, messages, _onStepFinish5, _onFinish, _ref9$maxSteps, maxSteps, enabledTools, modelToPass, params, argsForExecute;
|
|
1354
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1355
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1356
|
+
case 0:
|
|
1357
|
+
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;
|
|
1358
|
+
if ('name' in model) {
|
|
1359
|
+
modelToPass = {
|
|
1360
|
+
type: this.getModelType(model),
|
|
1361
|
+
name: model.name,
|
|
1362
|
+
toolChoice: model.toolChoice,
|
|
1363
|
+
apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
|
|
1364
|
+
baseURL: model.provider === 'LM_STUDIO' ? model.baseURL : undefined,
|
|
1365
|
+
fetch: model.provider === 'BASETEN' ? model.fetch : undefined
|
|
1366
|
+
};
|
|
1367
|
+
} else {
|
|
1368
|
+
modelToPass = model;
|
|
1369
|
+
}
|
|
1370
|
+
_context9.next = 4;
|
|
1371
|
+
return this.getParams({
|
|
1372
|
+
tools: this.convertTools(enabledTools),
|
|
1373
|
+
model: modelToPass
|
|
1374
|
+
});
|
|
1375
|
+
case 4:
|
|
1376
|
+
params = _context9.sent;
|
|
1377
|
+
argsForExecute = {
|
|
1378
|
+
model: params.modelDef,
|
|
1379
|
+
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1380
|
+
toolChoice: params.toolChoice,
|
|
1381
|
+
maxSteps: maxSteps,
|
|
1382
|
+
onStepFinish: function () {
|
|
1383
|
+
var _onStepFinish6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(props) {
|
|
1384
|
+
var _props$response5, _props$response6;
|
|
1385
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1386
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1387
|
+
case 0:
|
|
1388
|
+
_onStepFinish5 == null || _onStepFinish5(JSON.stringify(props, null, 2));
|
|
1389
|
+
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)) {
|
|
1390
|
+
_context7.next = 5;
|
|
1391
|
+
break;
|
|
1392
|
+
}
|
|
1393
|
+
_this5.logger.warn('Rate limit approaching, waiting 10 seconds');
|
|
1394
|
+
_context7.next = 5;
|
|
1395
|
+
return delay(10 * 1000);
|
|
1396
|
+
case 5:
|
|
1397
|
+
case "end":
|
|
1398
|
+
return _context7.stop();
|
|
1399
|
+
}
|
|
1400
|
+
}, _callee7);
|
|
1401
|
+
}));
|
|
1402
|
+
function onStepFinish(_x8) {
|
|
1403
|
+
return _onStepFinish6.apply(this, arguments);
|
|
1404
|
+
}
|
|
1405
|
+
return onStepFinish;
|
|
1217
1406
|
}(),
|
|
1218
1407
|
onFinish: function () {
|
|
1219
|
-
var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1220
|
-
return _regeneratorRuntime().wrap(function
|
|
1221
|
-
while (1) switch (
|
|
1408
|
+
var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(props) {
|
|
1409
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1410
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1222
1411
|
case 0:
|
|
1223
1412
|
_onFinish == null || _onFinish(JSON.stringify(props, null, 2));
|
|
1224
1413
|
case 1:
|
|
1225
1414
|
case "end":
|
|
1226
|
-
return
|
|
1415
|
+
return _context8.stop();
|
|
1227
1416
|
}
|
|
1228
|
-
},
|
|
1417
|
+
}, _callee8);
|
|
1229
1418
|
}));
|
|
1230
|
-
function onFinish(
|
|
1419
|
+
function onFinish(_x9) {
|
|
1231
1420
|
return _onFinish2.apply(this, arguments);
|
|
1232
1421
|
}
|
|
1233
1422
|
return onFinish;
|
|
1234
1423
|
}()
|
|
1235
1424
|
};
|
|
1236
1425
|
this.logger.debug("Streaming text with " + messages.length + " messages");
|
|
1237
|
-
|
|
1426
|
+
_context9.next = 9;
|
|
1238
1427
|
return ai.streamText(_extends({
|
|
1239
1428
|
messages: messages
|
|
1240
1429
|
}, argsForExecute));
|
|
1241
1430
|
case 9:
|
|
1242
|
-
return
|
|
1431
|
+
return _context9.abrupt("return", _context9.sent);
|
|
1243
1432
|
case 10:
|
|
1244
1433
|
case "end":
|
|
1245
|
-
return
|
|
1434
|
+
return _context9.stop();
|
|
1246
1435
|
}
|
|
1247
|
-
},
|
|
1436
|
+
}, _callee9, this);
|
|
1248
1437
|
}));
|
|
1249
|
-
function stream(
|
|
1438
|
+
function stream(_x7) {
|
|
1250
1439
|
return _stream.apply(this, arguments);
|
|
1251
1440
|
}
|
|
1252
1441
|
return stream;
|
|
1253
1442
|
}();
|
|
1443
|
+
_proto.streamObject = /*#__PURE__*/function () {
|
|
1444
|
+
var _streamObject2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref10) {
|
|
1445
|
+
var _this6 = this;
|
|
1446
|
+
var model, messages, _onStepFinish7, _onFinish3, _ref10$maxSteps, maxSteps, enabledTools, structuredOutput, modelToPass, params, argsForExecute, schema;
|
|
1447
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1448
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1449
|
+
case 0:
|
|
1450
|
+
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;
|
|
1451
|
+
if ('name' in model) {
|
|
1452
|
+
modelToPass = {
|
|
1453
|
+
type: this.getModelType(model),
|
|
1454
|
+
name: model.name,
|
|
1455
|
+
toolChoice: model.toolChoice,
|
|
1456
|
+
apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
|
|
1457
|
+
baseURL: model.provider === 'LM_STUDIO' ? model.baseURL : undefined,
|
|
1458
|
+
fetch: model.provider === 'BASETEN' ? model.fetch : undefined
|
|
1459
|
+
};
|
|
1460
|
+
} else {
|
|
1461
|
+
modelToPass = model;
|
|
1462
|
+
}
|
|
1463
|
+
_context12.next = 4;
|
|
1464
|
+
return this.getParams({
|
|
1465
|
+
tools: this.convertTools(enabledTools),
|
|
1466
|
+
model: modelToPass
|
|
1467
|
+
});
|
|
1468
|
+
case 4:
|
|
1469
|
+
params = _context12.sent;
|
|
1470
|
+
argsForExecute = {
|
|
1471
|
+
model: params.modelDef,
|
|
1472
|
+
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1473
|
+
toolChoice: params.toolChoice,
|
|
1474
|
+
maxSteps: maxSteps,
|
|
1475
|
+
onStepFinish: function () {
|
|
1476
|
+
var _onStepFinish8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(props) {
|
|
1477
|
+
var _props$response7, _props$response8;
|
|
1478
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1479
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1480
|
+
case 0:
|
|
1481
|
+
_onStepFinish7 == null || _onStepFinish7(JSON.stringify(props, null, 2));
|
|
1482
|
+
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)) {
|
|
1483
|
+
_context10.next = 5;
|
|
1484
|
+
break;
|
|
1485
|
+
}
|
|
1486
|
+
_this6.logger.warn('Rate limit approaching, waiting 10 seconds');
|
|
1487
|
+
_context10.next = 5;
|
|
1488
|
+
return delay(10 * 1000);
|
|
1489
|
+
case 5:
|
|
1490
|
+
case "end":
|
|
1491
|
+
return _context10.stop();
|
|
1492
|
+
}
|
|
1493
|
+
}, _callee10);
|
|
1494
|
+
}));
|
|
1495
|
+
function onStepFinish(_x11) {
|
|
1496
|
+
return _onStepFinish8.apply(this, arguments);
|
|
1497
|
+
}
|
|
1498
|
+
return onStepFinish;
|
|
1499
|
+
}(),
|
|
1500
|
+
onFinish: function () {
|
|
1501
|
+
var _onFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(props) {
|
|
1502
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1503
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1504
|
+
case 0:
|
|
1505
|
+
_onFinish3 == null || _onFinish3(JSON.stringify(props, null, 2));
|
|
1506
|
+
case 1:
|
|
1507
|
+
case "end":
|
|
1508
|
+
return _context11.stop();
|
|
1509
|
+
}
|
|
1510
|
+
}, _callee11);
|
|
1511
|
+
}));
|
|
1512
|
+
function onFinish(_x12) {
|
|
1513
|
+
return _onFinish4.apply(this, arguments);
|
|
1514
|
+
}
|
|
1515
|
+
return onFinish;
|
|
1516
|
+
}()
|
|
1517
|
+
};
|
|
1518
|
+
this.logger.debug("Streaming text with " + messages.length + " messages");
|
|
1519
|
+
schema = this.createOutputSchema(structuredOutput);
|
|
1520
|
+
_context12.next = 10;
|
|
1521
|
+
return ai.streamObject(_extends({
|
|
1522
|
+
messages: messages
|
|
1523
|
+
}, argsForExecute, {
|
|
1524
|
+
output: 'object',
|
|
1525
|
+
schema: schema
|
|
1526
|
+
}));
|
|
1527
|
+
case 10:
|
|
1528
|
+
return _context12.abrupt("return", _context12.sent);
|
|
1529
|
+
case 11:
|
|
1530
|
+
case "end":
|
|
1531
|
+
return _context12.stop();
|
|
1532
|
+
}
|
|
1533
|
+
}, _callee12, this);
|
|
1534
|
+
}));
|
|
1535
|
+
function streamObject(_x10) {
|
|
1536
|
+
return _streamObject2.apply(this, arguments);
|
|
1537
|
+
}
|
|
1538
|
+
return streamObject;
|
|
1539
|
+
}();
|
|
1254
1540
|
return LLM;
|
|
1255
1541
|
}();
|
|
1256
1542
|
|
|
@@ -1326,13 +1612,51 @@ var Agent = /*#__PURE__*/function () {
|
|
|
1326
1612
|
}
|
|
1327
1613
|
return text;
|
|
1328
1614
|
}();
|
|
1329
|
-
_proto.
|
|
1330
|
-
var
|
|
1331
|
-
var messages,
|
|
1615
|
+
_proto.textObject = /*#__PURE__*/function () {
|
|
1616
|
+
var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
1617
|
+
var messages, structuredOutput, onStepFinish, _ref2$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
|
|
1332
1618
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1333
1619
|
while (1) switch (_context2.prev = _context2.next) {
|
|
1334
1620
|
case 0:
|
|
1335
|
-
messages = _ref2.messages,
|
|
1621
|
+
messages = _ref2.messages, structuredOutput = _ref2.structuredOutput, onStepFinish = _ref2.onStepFinish, _ref2$maxSteps = _ref2.maxSteps, maxSteps = _ref2$maxSteps === void 0 ? 5 : _ref2$maxSteps;
|
|
1622
|
+
this.logger.info("Starting text generation for agent " + this.name);
|
|
1623
|
+
systemMessage = {
|
|
1624
|
+
role: 'system',
|
|
1625
|
+
content: this.instructions
|
|
1626
|
+
};
|
|
1627
|
+
userMessages = messages.map(function (content) {
|
|
1628
|
+
return {
|
|
1629
|
+
role: 'user',
|
|
1630
|
+
content: content
|
|
1631
|
+
};
|
|
1632
|
+
});
|
|
1633
|
+
messageObjects = [systemMessage].concat(userMessages);
|
|
1634
|
+
return _context2.abrupt("return", this.llm.textObject({
|
|
1635
|
+
model: this.model,
|
|
1636
|
+
messages: messageObjects,
|
|
1637
|
+
structuredOutput: structuredOutput,
|
|
1638
|
+
enabledTools: this.enabledTools,
|
|
1639
|
+
onStepFinish: onStepFinish,
|
|
1640
|
+
maxSteps: maxSteps
|
|
1641
|
+
}));
|
|
1642
|
+
case 6:
|
|
1643
|
+
case "end":
|
|
1644
|
+
return _context2.stop();
|
|
1645
|
+
}
|
|
1646
|
+
}, _callee2, this);
|
|
1647
|
+
}));
|
|
1648
|
+
function textObject(_x2) {
|
|
1649
|
+
return _textObject.apply(this, arguments);
|
|
1650
|
+
}
|
|
1651
|
+
return textObject;
|
|
1652
|
+
}();
|
|
1653
|
+
_proto.stream = /*#__PURE__*/function () {
|
|
1654
|
+
var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
|
|
1655
|
+
var messages, onStepFinish, onFinish, _ref3$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
|
|
1656
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1657
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1658
|
+
case 0:
|
|
1659
|
+
messages = _ref3.messages, onStepFinish = _ref3.onStepFinish, onFinish = _ref3.onFinish, _ref3$maxSteps = _ref3.maxSteps, maxSteps = _ref3$maxSteps === void 0 ? 5 : _ref3$maxSteps;
|
|
1336
1660
|
this.logger.info("Starting stream generation for agent " + this.name);
|
|
1337
1661
|
systemMessage = {
|
|
1338
1662
|
role: 'system',
|
|
@@ -1345,7 +1669,7 @@ var Agent = /*#__PURE__*/function () {
|
|
|
1345
1669
|
};
|
|
1346
1670
|
});
|
|
1347
1671
|
messageObjects = [systemMessage].concat(userMessages);
|
|
1348
|
-
return
|
|
1672
|
+
return _context3.abrupt("return", this.llm.stream({
|
|
1349
1673
|
messages: messageObjects,
|
|
1350
1674
|
model: this.model,
|
|
1351
1675
|
enabledTools: this.enabledTools,
|
|
@@ -1355,19 +1679,57 @@ var Agent = /*#__PURE__*/function () {
|
|
|
1355
1679
|
}));
|
|
1356
1680
|
case 6:
|
|
1357
1681
|
case "end":
|
|
1358
|
-
return
|
|
1682
|
+
return _context3.stop();
|
|
1359
1683
|
}
|
|
1360
|
-
},
|
|
1684
|
+
}, _callee3, this);
|
|
1361
1685
|
}));
|
|
1362
|
-
function stream(
|
|
1686
|
+
function stream(_x3) {
|
|
1363
1687
|
return _stream.apply(this, arguments);
|
|
1364
1688
|
}
|
|
1365
1689
|
return stream;
|
|
1366
1690
|
}();
|
|
1691
|
+
_proto.streamObject = /*#__PURE__*/function () {
|
|
1692
|
+
var _streamObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4) {
|
|
1693
|
+
var messages, structuredOutput, onStepFinish, onFinish, _ref4$maxSteps, maxSteps, systemMessage, userMessages, messageObjects;
|
|
1694
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1695
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
1696
|
+
case 0:
|
|
1697
|
+
messages = _ref4.messages, structuredOutput = _ref4.structuredOutput, onStepFinish = _ref4.onStepFinish, onFinish = _ref4.onFinish, _ref4$maxSteps = _ref4.maxSteps, maxSteps = _ref4$maxSteps === void 0 ? 5 : _ref4$maxSteps;
|
|
1698
|
+
this.logger.info("Starting stream generation for agent " + this.name);
|
|
1699
|
+
systemMessage = {
|
|
1700
|
+
role: 'system',
|
|
1701
|
+
content: this.instructions
|
|
1702
|
+
};
|
|
1703
|
+
userMessages = messages.map(function (content) {
|
|
1704
|
+
return {
|
|
1705
|
+
role: 'user',
|
|
1706
|
+
content: content
|
|
1707
|
+
};
|
|
1708
|
+
});
|
|
1709
|
+
messageObjects = [systemMessage].concat(userMessages);
|
|
1710
|
+
return _context4.abrupt("return", this.llm.streamObject({
|
|
1711
|
+
messages: messageObjects,
|
|
1712
|
+
structuredOutput: structuredOutput,
|
|
1713
|
+
model: this.model,
|
|
1714
|
+
enabledTools: this.enabledTools,
|
|
1715
|
+
onStepFinish: onStepFinish,
|
|
1716
|
+
onFinish: onFinish,
|
|
1717
|
+
maxSteps: maxSteps
|
|
1718
|
+
}));
|
|
1719
|
+
case 6:
|
|
1720
|
+
case "end":
|
|
1721
|
+
return _context4.stop();
|
|
1722
|
+
}
|
|
1723
|
+
}, _callee4, this);
|
|
1724
|
+
}));
|
|
1725
|
+
function streamObject(_x4) {
|
|
1726
|
+
return _streamObject.apply(this, arguments);
|
|
1727
|
+
}
|
|
1728
|
+
return streamObject;
|
|
1729
|
+
}();
|
|
1367
1730
|
return Agent;
|
|
1368
1731
|
}();
|
|
1369
1732
|
|
|
1370
|
-
// TODO: Passing the In/out generics works but seems to break on plugin to mastra, fix.
|
|
1371
1733
|
function createTool(opts) {
|
|
1372
1734
|
return opts;
|
|
1373
1735
|
}
|
|
@@ -1594,6 +1956,10 @@ function MastraEngine(config) {};
|
|
|
1594
1956
|
|
|
1595
1957
|
var MastraVector = function MastraVector() {};
|
|
1596
1958
|
|
|
1959
|
+
function createSync(opts) {
|
|
1960
|
+
return opts;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1597
1963
|
var Mastra = /*#__PURE__*/function () {
|
|
1598
1964
|
function Mastra(config) {
|
|
1599
1965
|
var _config$integrations,
|
|
@@ -1645,8 +2011,12 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
1645
2011
|
memo[key] = _extends({}, val, {
|
|
1646
2012
|
executor: function executor(params) {
|
|
1647
2013
|
return val.executor(_extends({}, params, {
|
|
1648
|
-
|
|
1649
|
-
return
|
|
2014
|
+
integrationsRegistry: function integrationsRegistry() {
|
|
2015
|
+
return {
|
|
2016
|
+
get: function get(name) {
|
|
2017
|
+
return _this.getIntegration(name);
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
1650
2020
|
},
|
|
1651
2021
|
agents: _this.agents,
|
|
1652
2022
|
llm: _this.llm,
|
|
@@ -1691,8 +2061,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
1691
2061
|
var _proto = Mastra.prototype;
|
|
1692
2062
|
_proto.sync = /*#__PURE__*/function () {
|
|
1693
2063
|
var _sync = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, params) {
|
|
1694
|
-
var _this$syncs
|
|
1695
|
-
|
|
2064
|
+
var _this$syncs,
|
|
2065
|
+
_this2 = this;
|
|
2066
|
+
var sync, syncFn;
|
|
1696
2067
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1697
2068
|
while (1) switch (_context.prev = _context.next) {
|
|
1698
2069
|
case 0:
|
|
@@ -1700,25 +2071,47 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
1700
2071
|
_context.next = 2;
|
|
1701
2072
|
break;
|
|
1702
2073
|
}
|
|
1703
|
-
throw new Error("
|
|
2074
|
+
throw new Error("Engine is required to run syncs");
|
|
1704
2075
|
case 2:
|
|
1705
|
-
|
|
1706
|
-
if (
|
|
2076
|
+
sync = (_this$syncs = this.syncs) == null ? void 0 : _this$syncs[key];
|
|
2077
|
+
if (sync) {
|
|
1707
2078
|
_context.next = 5;
|
|
1708
2079
|
break;
|
|
1709
2080
|
}
|
|
1710
2081
|
throw new Error("Sync function " + key + " not found");
|
|
1711
2082
|
case 5:
|
|
1712
|
-
|
|
2083
|
+
syncFn = sync['executor'];
|
|
2084
|
+
if (syncFn) {
|
|
2085
|
+
_context.next = 8;
|
|
2086
|
+
break;
|
|
2087
|
+
}
|
|
2088
|
+
throw new Error("Sync function " + key + " not found");
|
|
2089
|
+
case 8:
|
|
2090
|
+
_context.next = 10;
|
|
1713
2091
|
return syncFn({
|
|
1714
|
-
|
|
1715
|
-
params: params,
|
|
2092
|
+
data: params,
|
|
1716
2093
|
engine: this.engine,
|
|
1717
2094
|
agents: this.agents,
|
|
1718
2095
|
vectors: this.vectors,
|
|
1719
|
-
llm: this.llm
|
|
2096
|
+
llm: this.llm,
|
|
2097
|
+
integrationsRegistry: function integrationsRegistry() {
|
|
2098
|
+
return {
|
|
2099
|
+
get: function get(name) {
|
|
2100
|
+
return _this2.getIntegration(name);
|
|
2101
|
+
}
|
|
2102
|
+
};
|
|
2103
|
+
},
|
|
2104
|
+
toolsRegistry: function toolsRegistry() {
|
|
2105
|
+
return {
|
|
2106
|
+
get: function get(name) {
|
|
2107
|
+
return _this2.getTool(name);
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
1720
2111
|
});
|
|
1721
|
-
case
|
|
2112
|
+
case 10:
|
|
2113
|
+
return _context.abrupt("return", _context.sent);
|
|
2114
|
+
case 11:
|
|
1722
2115
|
case "end":
|
|
1723
2116
|
return _context.stop();
|
|
1724
2117
|
}
|
|
@@ -1745,7 +2138,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
1745
2138
|
return integration;
|
|
1746
2139
|
};
|
|
1747
2140
|
_proto.getTool = function getTool(name) {
|
|
1748
|
-
var
|
|
2141
|
+
var _this3 = this;
|
|
1749
2142
|
var tool = this.tools[name];
|
|
1750
2143
|
if (!tool) {
|
|
1751
2144
|
throw new Error("Tool with name " + String(name) + " not found");
|
|
@@ -1761,13 +2154,13 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
1761
2154
|
integrationsRegistry: function integrationsRegistry() {
|
|
1762
2155
|
return {
|
|
1763
2156
|
get: function get(name) {
|
|
1764
|
-
return
|
|
2157
|
+
return _this3.getIntegration(name);
|
|
1765
2158
|
}
|
|
1766
2159
|
};
|
|
1767
2160
|
},
|
|
1768
|
-
agents:
|
|
1769
|
-
llm:
|
|
1770
|
-
engine:
|
|
2161
|
+
agents: _this3.agents,
|
|
2162
|
+
llm: _this3.llm,
|
|
2163
|
+
engine: _this3.engine
|
|
1771
2164
|
}));
|
|
1772
2165
|
case 1:
|
|
1773
2166
|
case "end":
|
|
@@ -1814,13 +2207,14 @@ function isTransitionEvent(stateEvent) {
|
|
|
1814
2207
|
}
|
|
1815
2208
|
|
|
1816
2209
|
var _logger = /*#__PURE__*/_classPrivateFieldLooseKey("logger");
|
|
2210
|
+
var _triggerSchema = /*#__PURE__*/_classPrivateFieldLooseKey("triggerSchema");
|
|
1817
2211
|
var _steps = /*#__PURE__*/_classPrivateFieldLooseKey("steps");
|
|
2212
|
+
var _transitions = /*#__PURE__*/_classPrivateFieldLooseKey("transitions");
|
|
1818
2213
|
var _machine = /*#__PURE__*/_classPrivateFieldLooseKey("machine");
|
|
1819
2214
|
var _actor = /*#__PURE__*/_classPrivateFieldLooseKey("actor");
|
|
1820
2215
|
var _log = /*#__PURE__*/_classPrivateFieldLooseKey("log");
|
|
1821
2216
|
var _buildStateHierarchy = /*#__PURE__*/_classPrivateFieldLooseKey("buildStateHierarchy");
|
|
1822
2217
|
var _isVariableReference = /*#__PURE__*/_classPrivateFieldLooseKey("isVariableReference");
|
|
1823
|
-
var _createStepId = /*#__PURE__*/_classPrivateFieldLooseKey("createStepId");
|
|
1824
2218
|
var _resolveVariables = /*#__PURE__*/_classPrivateFieldLooseKey("resolveVariables");
|
|
1825
2219
|
var _cleanup = /*#__PURE__*/_classPrivateFieldLooseKey("cleanup");
|
|
1826
2220
|
var _evaluateCondition = /*#__PURE__*/_classPrivateFieldLooseKey("evaluateCondition");
|
|
@@ -1834,7 +2228,11 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1834
2228
|
* @param name - Identifier for the workflow (not necessarily unique)
|
|
1835
2229
|
* @param logger - Optional logger instance
|
|
1836
2230
|
*/
|
|
1837
|
-
function Workflow(
|
|
2231
|
+
function Workflow(_ref) {
|
|
2232
|
+
var name = _ref.name,
|
|
2233
|
+
logger = _ref.logger,
|
|
2234
|
+
steps = _ref.steps,
|
|
2235
|
+
triggerSchema = _ref.triggerSchema;
|
|
1838
2236
|
/**
|
|
1839
2237
|
* Detects unreachable steps in the workflow
|
|
1840
2238
|
* @returns Array of ValidationError objects
|
|
@@ -1885,15 +2283,6 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1885
2283
|
Object.defineProperty(this, _resolveVariables, {
|
|
1886
2284
|
value: _resolveVariables2
|
|
1887
2285
|
});
|
|
1888
|
-
/**
|
|
1889
|
-
* Creates a validated step ID, ensuring uniqueness within the workflow
|
|
1890
|
-
* @param id - Proposed step ID
|
|
1891
|
-
* @returns The validated and branded step ID
|
|
1892
|
-
* @throws Error if ID is invalid or duplicate
|
|
1893
|
-
*/
|
|
1894
|
-
Object.defineProperty(this, _createStepId, {
|
|
1895
|
-
value: _createStepId2
|
|
1896
|
-
});
|
|
1897
2286
|
/**
|
|
1898
2287
|
* Type guard to check if a value is a valid VariableReference
|
|
1899
2288
|
* @param value - Value to check
|
|
@@ -1924,10 +2313,17 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1924
2313
|
writable: true,
|
|
1925
2314
|
value: void 0
|
|
1926
2315
|
});
|
|
1927
|
-
this
|
|
2316
|
+
Object.defineProperty(this, _triggerSchema, {
|
|
2317
|
+
writable: true,
|
|
2318
|
+
value: void 0
|
|
2319
|
+
});
|
|
1928
2320
|
Object.defineProperty(this, _steps, {
|
|
1929
2321
|
writable: true,
|
|
1930
|
-
value:
|
|
2322
|
+
value: void 0
|
|
2323
|
+
});
|
|
2324
|
+
Object.defineProperty(this, _transitions, {
|
|
2325
|
+
writable: true,
|
|
2326
|
+
value: {}
|
|
1931
2327
|
});
|
|
1932
2328
|
/** XState machine instance that orchestrates the workflow execution */
|
|
1933
2329
|
Object.defineProperty(this, _machine, {
|
|
@@ -1941,6 +2337,8 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1941
2337
|
});
|
|
1942
2338
|
this.name = name;
|
|
1943
2339
|
_classPrivateFieldLooseBase(this, _logger)[_logger] = logger;
|
|
2340
|
+
_classPrivateFieldLooseBase(this, _steps)[_steps] = steps;
|
|
2341
|
+
_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema] = triggerSchema;
|
|
1944
2342
|
this.initializeMachine();
|
|
1945
2343
|
}
|
|
1946
2344
|
var _proto = Workflow.prototype;
|
|
@@ -1957,10 +2355,10 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1957
2355
|
types: {},
|
|
1958
2356
|
actions: {
|
|
1959
2357
|
updateStepResult: xstate.assign({
|
|
1960
|
-
stepResults: function stepResults(
|
|
2358
|
+
stepResults: function stepResults(_ref2) {
|
|
1961
2359
|
var _event$output, _event$output2;
|
|
1962
|
-
var context =
|
|
1963
|
-
event =
|
|
2360
|
+
var context = _ref2.context,
|
|
2361
|
+
event = _ref2.event;
|
|
1964
2362
|
if (!isTransitionEvent(event)) return context.stepResults;
|
|
1965
2363
|
var stepId = (_event$output = event.output) == null ? void 0 : _event$output.stepId;
|
|
1966
2364
|
if (!stepId) return context.stepResults;
|
|
@@ -1970,9 +2368,7 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1970
2368
|
var _extends2;
|
|
1971
2369
|
var newResults = _extends({}, context.stepResults, (_extends2 = {}, _extends2[stepId] = result, _extends2));
|
|
1972
2370
|
// Get the step configuration
|
|
1973
|
-
var step = _classPrivateFieldLooseBase(_this,
|
|
1974
|
-
return s.id === stepId;
|
|
1975
|
-
});
|
|
2371
|
+
var step = _classPrivateFieldLooseBase(_this, _transitions)[_transitions][stepId];
|
|
1976
2372
|
// Evaluate transitions and send events
|
|
1977
2373
|
if (step != null && step.transitions) {
|
|
1978
2374
|
var fullContext = _extends({}, context, {
|
|
@@ -1980,12 +2376,12 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
1980
2376
|
});
|
|
1981
2377
|
var hasMatchingCondition = false;
|
|
1982
2378
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, 'Evaluating transitions with context:', fullContext);
|
|
1983
|
-
Object.entries(step.transitions).forEach(function (
|
|
1984
|
-
var targetId =
|
|
1985
|
-
config =
|
|
2379
|
+
Object.entries(step.transitions).forEach(function (_ref3) {
|
|
2380
|
+
var targetId = _ref3[0],
|
|
2381
|
+
config = _ref3[1];
|
|
1986
2382
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "Checking transition to: " + targetId);
|
|
1987
|
-
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "With condition: " + config.condition);
|
|
1988
|
-
if (!config.condition || _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](config.condition, fullContext)) {
|
|
2383
|
+
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "With condition: " + (config == null ? void 0 : config.condition));
|
|
2384
|
+
if (!(config != null && config.condition) || _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](config == null ? void 0 : config.condition, fullContext)) {
|
|
1989
2385
|
hasMatchingCondition = true;
|
|
1990
2386
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, 'Condition passed, sending transition to:', targetId);
|
|
1991
2387
|
Promise.resolve().then(function () {
|
|
@@ -2014,16 +2410,16 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2014
2410
|
}
|
|
2015
2411
|
}),
|
|
2016
2412
|
setError: xstate.assign({
|
|
2017
|
-
error: function error(
|
|
2018
|
-
var event =
|
|
2413
|
+
error: function error(_ref4) {
|
|
2414
|
+
var event = _ref4.event;
|
|
2019
2415
|
if (!isErrorEvent(event)) return null;
|
|
2020
2416
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.ERROR, "Workflow error", event.error);
|
|
2021
2417
|
return event.error;
|
|
2022
2418
|
}
|
|
2023
2419
|
}),
|
|
2024
2420
|
initializeTriggerData: xstate.assign({
|
|
2025
|
-
triggerData: function triggerData(
|
|
2026
|
-
var context =
|
|
2421
|
+
triggerData: function triggerData(_ref5) {
|
|
2422
|
+
var context = _ref5.context;
|
|
2027
2423
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.INFO, 'Workflow started', context == null ? void 0 : context.triggerData);
|
|
2028
2424
|
return context == null ? void 0 : context.triggerData;
|
|
2029
2425
|
}
|
|
@@ -2031,20 +2427,20 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2031
2427
|
},
|
|
2032
2428
|
actors: {
|
|
2033
2429
|
resolverFunction: xstate.fromPromise(/*#__PURE__*/function () {
|
|
2034
|
-
var
|
|
2035
|
-
var input, step, context, resolvedData, result;
|
|
2430
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
|
|
2431
|
+
var input, step, context, stepId, resolvedData, result;
|
|
2036
2432
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2037
2433
|
while (1) switch (_context.prev = _context.next) {
|
|
2038
2434
|
case 0:
|
|
2039
|
-
input =
|
|
2040
|
-
step = input.step, context = input.context;
|
|
2435
|
+
input = _ref6.input;
|
|
2436
|
+
step = input.step, context = input.context, stepId = input.stepId;
|
|
2041
2437
|
resolvedData = _classPrivateFieldLooseBase(_this, _resolveVariables)[_resolveVariables](step, context);
|
|
2042
2438
|
_context.next = 5;
|
|
2043
2439
|
return step.handler(resolvedData);
|
|
2044
2440
|
case 5:
|
|
2045
2441
|
result = _context.sent;
|
|
2046
2442
|
return _context.abrupt("return", {
|
|
2047
|
-
stepId:
|
|
2443
|
+
stepId: stepId,
|
|
2048
2444
|
result: result
|
|
2049
2445
|
});
|
|
2050
2446
|
case 7:
|
|
@@ -2054,15 +2450,15 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2054
2450
|
}, _callee);
|
|
2055
2451
|
}));
|
|
2056
2452
|
return function (_x) {
|
|
2057
|
-
return
|
|
2453
|
+
return _ref7.apply(this, arguments);
|
|
2058
2454
|
};
|
|
2059
2455
|
}())
|
|
2060
2456
|
}
|
|
2061
2457
|
}).createMachine({
|
|
2062
2458
|
id: this.name,
|
|
2063
2459
|
initial: ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _steps)[_steps][0]) == null ? void 0 : _classPrivateFieldLoo.id) || 'idle',
|
|
2064
|
-
context: function context(
|
|
2065
|
-
var input =
|
|
2460
|
+
context: function context(_ref8) {
|
|
2461
|
+
var input = _ref8.input;
|
|
2066
2462
|
return _extends({}, input, {
|
|
2067
2463
|
stepResults: {},
|
|
2068
2464
|
error: null
|
|
@@ -2079,18 +2475,12 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2079
2475
|
*
|
|
2080
2476
|
* This is the last step of a workflow builder method chain
|
|
2081
2477
|
* @throws Error if validation fails
|
|
2478
|
+
*
|
|
2479
|
+
* @returns this instance for method chaining
|
|
2082
2480
|
*/;
|
|
2083
2481
|
_proto.commit = function commit() {
|
|
2084
2482
|
_classPrivateFieldLooseBase(this, _validateWorkflow)[_validateWorkflow]();
|
|
2085
2483
|
this.initializeMachine();
|
|
2086
|
-
};
|
|
2087
|
-
/**
|
|
2088
|
-
* Sets the schema for validating trigger data
|
|
2089
|
-
* @param schema - Zod schema for trigger data validation
|
|
2090
|
-
* @returns this instance for method chaining
|
|
2091
|
-
*/
|
|
2092
|
-
_proto.setTriggerSchema = function setTriggerSchema(schema) {
|
|
2093
|
-
this.triggerSchema = schema;
|
|
2094
2484
|
return this;
|
|
2095
2485
|
};
|
|
2096
2486
|
/**
|
|
@@ -2100,27 +2490,13 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2100
2490
|
* @returns this instance for method chaining (builder pattern baybyyyy)
|
|
2101
2491
|
* @throws Error if step ID is duplicate or variable resolution fails
|
|
2102
2492
|
*/
|
|
2103
|
-
_proto.
|
|
2493
|
+
_proto.step = function step(id, config) {
|
|
2104
2494
|
var _this2 = this;
|
|
2105
|
-
var
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
_config$payload = config.payload,
|
|
2111
|
-
payload = _config$payload === void 0 ? {} : _config$payload,
|
|
2112
|
-
transitions = config.transitions;
|
|
2113
|
-
// Validate transitions reference existing steps
|
|
2114
|
-
if (transitions) {
|
|
2115
|
-
Object.keys(transitions).forEach(function (targetId) {
|
|
2116
|
-
// Skip validation for steps that will be added later
|
|
2117
|
-
if (!_classPrivateFieldLooseBase(_this2, _steps)[_steps].some(function (s) {
|
|
2118
|
-
return s.id === targetId;
|
|
2119
|
-
})) {
|
|
2120
|
-
_classPrivateFieldLooseBase(_this2, _log)[_log](LogLevel.DEBUG, "Step " + targetId + " not found yet, will be validated when workflow starts");
|
|
2121
|
-
}
|
|
2122
|
-
});
|
|
2123
|
-
}
|
|
2495
|
+
var _ref9 = config || {},
|
|
2496
|
+
_ref9$variables = _ref9.variables,
|
|
2497
|
+
variables = _ref9$variables === void 0 ? {} : _ref9$variables,
|
|
2498
|
+
_ref9$transitions = _ref9.transitions,
|
|
2499
|
+
transitions = _ref9$transitions === void 0 ? undefined : _ref9$transitions;
|
|
2124
2500
|
var requiredData = {};
|
|
2125
2501
|
// Add valid variables to requiredData
|
|
2126
2502
|
for (var _i = 0, _Object$entries = Object.entries(variables); _i < _Object$entries.length; _i++) {
|
|
@@ -2131,21 +2507,30 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2131
2507
|
requiredData[key] = variable;
|
|
2132
2508
|
}
|
|
2133
2509
|
}
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2510
|
+
_classPrivateFieldLooseBase(this, _transitions)[_transitions][id] = {
|
|
2511
|
+
transitions: transitions,
|
|
2512
|
+
data: requiredData,
|
|
2137
2513
|
handler: function () {
|
|
2138
2514
|
var _handler = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
|
|
2139
|
-
var mergedData, validatedData;
|
|
2515
|
+
var step, inputSchema, payload, action, mergedData, validatedData;
|
|
2140
2516
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
2141
2517
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2142
2518
|
case 0:
|
|
2143
|
-
|
|
2519
|
+
step = _classPrivateFieldLooseBase(_this2, _steps)[_steps].find(function (s) {
|
|
2520
|
+
return s.id === id;
|
|
2521
|
+
});
|
|
2522
|
+
if (step) {
|
|
2523
|
+
_context2.next = 3;
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
throw new Error("Step " + id + " not found");
|
|
2527
|
+
case 3:
|
|
2528
|
+
inputSchema = step.inputSchema, payload = step.payload, action = step.action; // Merge static payload with dynamically resolved variables
|
|
2144
2529
|
// Variables take precedence over payload values
|
|
2145
2530
|
mergedData = _extends({}, payload, data); // Validate complete input data
|
|
2146
2531
|
validatedData = inputSchema ? inputSchema.parse(mergedData) : mergedData;
|
|
2147
|
-
return _context2.abrupt("return", action(validatedData));
|
|
2148
|
-
case
|
|
2532
|
+
return _context2.abrupt("return", action ? action(validatedData) : {});
|
|
2533
|
+
case 7:
|
|
2149
2534
|
case "end":
|
|
2150
2535
|
return _context2.stop();
|
|
2151
2536
|
}
|
|
@@ -2155,12 +2540,8 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2155
2540
|
return _handler.apply(this, arguments);
|
|
2156
2541
|
}
|
|
2157
2542
|
return handler;
|
|
2158
|
-
}()
|
|
2159
|
-
inputSchema: inputSchema,
|
|
2160
|
-
requiredData: requiredData,
|
|
2161
|
-
transitions: transitions
|
|
2543
|
+
}()
|
|
2162
2544
|
};
|
|
2163
|
-
_classPrivateFieldLooseBase(this, _steps)[_steps].push(stepConfig);
|
|
2164
2545
|
return this;
|
|
2165
2546
|
};
|
|
2166
2547
|
/**
|
|
@@ -2169,10 +2550,10 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2169
2550
|
* @returns Promise resolving to workflow results or rejecting with error
|
|
2170
2551
|
* @throws Error if trigger schema validation fails
|
|
2171
2552
|
*/
|
|
2172
|
-
_proto.
|
|
2553
|
+
_proto.execute =
|
|
2173
2554
|
/*#__PURE__*/
|
|
2174
2555
|
function () {
|
|
2175
|
-
var
|
|
2556
|
+
var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(triggerData) {
|
|
2176
2557
|
var _this3 = this;
|
|
2177
2558
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
2178
2559
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -2182,12 +2563,12 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2182
2563
|
triggerData: triggerData
|
|
2183
2564
|
});
|
|
2184
2565
|
case 2:
|
|
2185
|
-
if (!this
|
|
2566
|
+
if (!_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema]) {
|
|
2186
2567
|
_context3.next = 14;
|
|
2187
2568
|
break;
|
|
2188
2569
|
}
|
|
2189
2570
|
_context3.prev = 3;
|
|
2190
|
-
this.
|
|
2571
|
+
_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema].parse(triggerData);
|
|
2191
2572
|
_context3.next = 7;
|
|
2192
2573
|
return _classPrivateFieldLooseBase(this, _log)[_log](LogLevel.DEBUG, 'Trigger schema validation passed');
|
|
2193
2574
|
case 7:
|
|
@@ -2244,10 +2625,10 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2244
2625
|
}
|
|
2245
2626
|
}, _callee3, this, [[3, 9]]);
|
|
2246
2627
|
}));
|
|
2247
|
-
function
|
|
2248
|
-
return
|
|
2628
|
+
function execute(_x3) {
|
|
2629
|
+
return _execute.apply(this, arguments);
|
|
2249
2630
|
}
|
|
2250
|
-
return
|
|
2631
|
+
return execute;
|
|
2251
2632
|
}();
|
|
2252
2633
|
return Workflow;
|
|
2253
2634
|
}();
|
|
@@ -2256,7 +2637,7 @@ function _log2(_x4, _x5, _x6, _x7) {
|
|
|
2256
2637
|
}
|
|
2257
2638
|
function _log3() {
|
|
2258
2639
|
_log3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(level, message, data, stepId) {
|
|
2259
|
-
var
|
|
2640
|
+
var _classPrivateFieldLoo5, _classPrivateFieldLoo6;
|
|
2260
2641
|
var logMessage, logMethod;
|
|
2261
2642
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
2262
2643
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -2277,7 +2658,7 @@ function _log3() {
|
|
|
2277
2658
|
};
|
|
2278
2659
|
logMethod = level.toLowerCase();
|
|
2279
2660
|
_context4.next = 6;
|
|
2280
|
-
return (
|
|
2661
|
+
return (_classPrivateFieldLoo5 = (_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(this, _logger)[_logger])[logMethod]) == null ? void 0 : _classPrivateFieldLoo5.call(_classPrivateFieldLoo6, logMessage);
|
|
2281
2662
|
case 6:
|
|
2282
2663
|
case "end":
|
|
2283
2664
|
return _context4.stop();
|
|
@@ -2299,6 +2680,7 @@ function _buildStateHierarchy2() {
|
|
|
2299
2680
|
};
|
|
2300
2681
|
// Helper to build nested state structure
|
|
2301
2682
|
var buildState = function buildState(currentStepId, visited) {
|
|
2683
|
+
var _classPrivateFieldLoo2, _classPrivateFieldLoo3;
|
|
2302
2684
|
if (visited.has(currentStepId)) return null;
|
|
2303
2685
|
visited.add(currentStepId);
|
|
2304
2686
|
var currentStep = _classPrivateFieldLooseBase(_this4, _steps)[_steps].find(function (s) {
|
|
@@ -2308,17 +2690,18 @@ function _buildStateHierarchy2() {
|
|
|
2308
2690
|
var state = {
|
|
2309
2691
|
invoke: {
|
|
2310
2692
|
src: 'resolverFunction',
|
|
2311
|
-
input: function input(
|
|
2312
|
-
var context =
|
|
2693
|
+
input: function input(_ref10) {
|
|
2694
|
+
var context = _ref10.context;
|
|
2313
2695
|
return {
|
|
2314
|
-
|
|
2315
|
-
|
|
2696
|
+
context: context,
|
|
2697
|
+
stepId: currentStepId,
|
|
2698
|
+
step: _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]
|
|
2316
2699
|
};
|
|
2317
2700
|
},
|
|
2318
2701
|
onDone: {
|
|
2319
2702
|
actions: ['updateStepResult'],
|
|
2320
2703
|
// If no transitions, go to success state
|
|
2321
|
-
target:
|
|
2704
|
+
target: (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) != null && _classPrivateFieldLoo2.transitions ? undefined : 'success'
|
|
2322
2705
|
},
|
|
2323
2706
|
onError: {
|
|
2324
2707
|
target: 'failure',
|
|
@@ -2339,16 +2722,17 @@ function _buildStateHierarchy2() {
|
|
|
2339
2722
|
}
|
|
2340
2723
|
};
|
|
2341
2724
|
// Handle transitions
|
|
2342
|
-
if (
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2725
|
+
if ((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) != null && _classPrivateFieldLoo3.transitions) {
|
|
2726
|
+
var _classPrivateFieldLoo4;
|
|
2727
|
+
Object.entries((_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) == null ? void 0 : _classPrivateFieldLoo4.transitions).forEach(function (_ref11) {
|
|
2728
|
+
var targetId = _ref11[0],
|
|
2729
|
+
config = _ref11[1];
|
|
2346
2730
|
// Create flat state structure with transitions
|
|
2347
2731
|
state.on["TRANSITION_" + targetId] = {
|
|
2348
2732
|
target: targetId,
|
|
2349
|
-
guard: function guard(
|
|
2350
|
-
var context =
|
|
2351
|
-
return !config.condition || _classPrivateFieldLooseBase(_this4, _evaluateCondition)[_evaluateCondition](config.condition, context);
|
|
2733
|
+
guard: function guard(_ref12) {
|
|
2734
|
+
var context = _ref12.context;
|
|
2735
|
+
return !(config != null && config.condition) || _classPrivateFieldLooseBase(_this4, _evaluateCondition)[_evaluateCondition](config == null ? void 0 : config.condition, context);
|
|
2352
2736
|
}
|
|
2353
2737
|
};
|
|
2354
2738
|
});
|
|
@@ -2368,18 +2752,9 @@ function _buildStateHierarchy2() {
|
|
|
2368
2752
|
function _isVariableReference2(value) {
|
|
2369
2753
|
return typeof value === 'object' && 'stepId' in value && 'path' in value;
|
|
2370
2754
|
}
|
|
2371
|
-
function _createStepId2(id) {
|
|
2372
|
-
// Check for duplicates
|
|
2373
|
-
if (_classPrivateFieldLooseBase(this, _steps)[_steps].some(function (step) {
|
|
2374
|
-
return step.id === id;
|
|
2375
|
-
})) {
|
|
2376
|
-
throw new Error("Step with ID \"" + id + "\" already exists in workflow \"" + this.name + "\"");
|
|
2377
|
-
}
|
|
2378
|
-
return id;
|
|
2379
|
-
}
|
|
2380
2755
|
function _resolveVariables2(stepConfig, context) {
|
|
2381
2756
|
var resolvedData = {};
|
|
2382
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.
|
|
2757
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.data); _i2 < _Object$entries2.length; _i2++) {
|
|
2383
2758
|
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
2384
2759
|
key = _Object$entries2$_i[0],
|
|
2385
2760
|
variable = _Object$entries2$_i[1];
|
|
@@ -2462,9 +2837,7 @@ function _detectCircularDependencies2() {
|
|
|
2462
2837
|
return;
|
|
2463
2838
|
}
|
|
2464
2839
|
stack.push(stepId);
|
|
2465
|
-
var step = _classPrivateFieldLooseBase(_this6,
|
|
2466
|
-
return s.id === stepId;
|
|
2467
|
-
});
|
|
2840
|
+
var step = _classPrivateFieldLooseBase(_this6, _transitions)[_transitions][stepId];
|
|
2468
2841
|
if (step != null && step.transitions) {
|
|
2469
2842
|
Object.keys(step.transitions).forEach(function (targetId) {
|
|
2470
2843
|
_dfs(targetId);
|
|
@@ -2490,9 +2863,7 @@ function _validateTerminalPaths2() {
|
|
|
2490
2863
|
if (hasTerminalPath.has(stepId)) return true;
|
|
2491
2864
|
if (visited.has(stepId) && !hasTerminalPath.has(stepId)) return false;
|
|
2492
2865
|
visited.add(stepId);
|
|
2493
|
-
var step = _classPrivateFieldLooseBase(_this7,
|
|
2494
|
-
return s.id === stepId;
|
|
2495
|
-
});
|
|
2866
|
+
var step = _classPrivateFieldLooseBase(_this7, _transitions)[_transitions][stepId];
|
|
2496
2867
|
if (!step) return false;
|
|
2497
2868
|
// Terminal step
|
|
2498
2869
|
if (!step.transitions) {
|
|
@@ -2535,9 +2906,7 @@ function _detectUnreachableSteps2() {
|
|
|
2535
2906
|
var _dfs3 = function dfs(stepId) {
|
|
2536
2907
|
if (reachableSteps.has(stepId)) return;
|
|
2537
2908
|
reachableSteps.add(stepId);
|
|
2538
|
-
var step = _classPrivateFieldLooseBase(_this8,
|
|
2539
|
-
return s.id === stepId;
|
|
2540
|
-
});
|
|
2909
|
+
var step = _classPrivateFieldLooseBase(_this8, _transitions)[_transitions][stepId];
|
|
2541
2910
|
if (step != null && step.transitions) {
|
|
2542
2911
|
Object.keys(step.transitions).forEach(function (targetId) {
|
|
2543
2912
|
_dfs3(targetId);
|
|
@@ -2563,6 +2932,24 @@ function _detectUnreachableSteps2() {
|
|
|
2563
2932
|
return errors;
|
|
2564
2933
|
}
|
|
2565
2934
|
|
|
2935
|
+
var Step = function Step(_ref) {
|
|
2936
|
+
var id = _ref.id,
|
|
2937
|
+
inputSchema = _ref.inputSchema,
|
|
2938
|
+
outputSchema = _ref.outputSchema,
|
|
2939
|
+
payload = _ref.payload,
|
|
2940
|
+
action = _ref.action;
|
|
2941
|
+
this.id = void 0;
|
|
2942
|
+
this.inputSchema = void 0;
|
|
2943
|
+
this.outputSchema = void 0;
|
|
2944
|
+
this.payload = void 0;
|
|
2945
|
+
this.action = void 0;
|
|
2946
|
+
this.id = id;
|
|
2947
|
+
this.inputSchema = inputSchema;
|
|
2948
|
+
this.payload = payload;
|
|
2949
|
+
this.outputSchema = outputSchema;
|
|
2950
|
+
this.action = action;
|
|
2951
|
+
};
|
|
2952
|
+
|
|
2566
2953
|
exports.Agent = Agent;
|
|
2567
2954
|
exports.BaseLogger = BaseLogger;
|
|
2568
2955
|
exports.FieldTypePrimitiveMap = FieldTypePrimitiveMap;
|
|
@@ -2573,10 +2960,12 @@ exports.MastraEngine = MastraEngine;
|
|
|
2573
2960
|
exports.MastraVector = MastraVector;
|
|
2574
2961
|
exports.MultiLogger = MultiLogger;
|
|
2575
2962
|
exports.RegisteredLogger = RegisteredLogger;
|
|
2963
|
+
exports.Step = Step;
|
|
2576
2964
|
exports.Workflow = Workflow;
|
|
2577
2965
|
exports.buildQueryString = buildQueryString;
|
|
2578
2966
|
exports.createLogger = createLogger;
|
|
2579
2967
|
exports.createMultiLogger = createMultiLogger;
|
|
2968
|
+
exports.createSync = createSync;
|
|
2580
2969
|
exports.createTool = createTool;
|
|
2581
2970
|
exports.filterQuerySchema = filterQuerySchema;
|
|
2582
2971
|
exports.getJSONField = getJSONField;
|