@mastra/core 0.1.21 → 0.1.23

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/dist/core.esm.js CHANGED
@@ -1869,7 +1869,8 @@ var makeCallback = function makeCallback(framework) {
1869
1869
  var APP_ID = 'mastra';
1870
1870
  var client$1 = /*#__PURE__*/new Inngest({
1871
1871
  id: APP_ID,
1872
- eventKey: process.env.INNGEST_EVENT_KEY
1872
+ eventKey: process.env.INNGEST_EVENT_KEY,
1873
+ baseUrl: process.env.INNGEST_URL
1873
1874
  });
1874
1875
 
1875
1876
  function readBlueprintSync(filePath) {
@@ -2020,7 +2021,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref3) {
2020
2021
  event: 'workflow/run-automations'
2021
2022
  }, /*#__PURE__*/function () {
2022
2023
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
2023
- var event, step, _event$data, trigger, payload, connectionId, getBlueprintsDirPath, blueprints, triggeredAndPublishedBlueprints, runs;
2024
+ var event, step, _event$data, trigger, payload, connectionId, getBlueprintsDirPath, blueprints, triggeredAndPublishedBlueprints, runs, data;
2024
2025
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2025
2026
  while (1) switch (_context3.prev = _context3.next) {
2026
2027
  case 0:
@@ -2086,22 +2087,24 @@ var createWorkflowHandler = function createWorkflowHandler(_ref3) {
2086
2087
  _context3.next = 12;
2087
2088
  return Promise.all(runs);
2088
2089
  case 12:
2090
+ data = _context3.sent;
2089
2091
  return _context3.abrupt("return", {
2090
2092
  event: event,
2091
- body: "sync completed"
2093
+ body: "sync completed",
2094
+ data: data
2092
2095
  });
2093
- case 15:
2094
- _context3.prev = 15;
2096
+ case 16:
2097
+ _context3.prev = 16;
2095
2098
  _context3.t0 = _context3["catch"](1);
2096
2099
  return _context3.abrupt("return", {
2097
2100
  event: event,
2098
2101
  body: "error occurred while running sync: " + _context3.t0
2099
2102
  });
2100
- case 18:
2103
+ case 19:
2101
2104
  case "end":
2102
2105
  return _context3.stop();
2103
2106
  }
2104
- }, _callee3, null, [[1, 15]]);
2107
+ }, _callee3, null, [[1, 16]]);
2105
2108
  }));
2106
2109
  return function (_x3) {
2107
2110
  return _ref5.apply(this, arguments);
@@ -4187,11 +4190,11 @@ function runActionsRecursively(_x) {
4187
4190
  }
4188
4191
  function _runActionsRecursively() {
4189
4192
  _runActionsRecursively = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref7) {
4190
- var blueprintActions, frameworkApis, frameworkEvents, dataContext, blueprintId, runId, ctx, blueprintActionKVMap, logger, _loop, _ret, _iterator2, _step2;
4193
+ var blueprintActions, frameworkApis, frameworkEvents, dataContext, blueprintId, runId, ctx, blueprintActionKVMap, logger, order, _loop, _ret, _iterator2, _step2;
4191
4194
  return _regeneratorRuntime().wrap(function _callee$(_context3) {
4192
4195
  while (1) switch (_context3.prev = _context3.next) {
4193
4196
  case 0:
4194
- blueprintActions = _ref7.blueprintActions, frameworkApis = _ref7.frameworkApis, frameworkEvents = _ref7.frameworkEvents, dataContext = _ref7.dataContext, blueprintId = _ref7.blueprintId, runId = _ref7.runId, ctx = _ref7.ctx, blueprintActionKVMap = _ref7.blueprintActionKVMap, logger = _ref7.logger;
4197
+ blueprintActions = _ref7.blueprintActions, frameworkApis = _ref7.frameworkApis, frameworkEvents = _ref7.frameworkEvents, dataContext = _ref7.dataContext, blueprintId = _ref7.blueprintId, runId = _ref7.runId, ctx = _ref7.ctx, blueprintActionKVMap = _ref7.blueprintActionKVMap, logger = _ref7.logger, order = _ref7.order;
4195
4198
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
4196
4199
  var _action$subActions;
4197
4200
  var action, concreteAction, hasValidBranch, _loop2, _ret2, _iterator3, _step3, defaultCondition, defaultAction, actionExecutor, _ref9, mastraConnectionId, actionPayload, resolvedPayload, resolvedSchema, data, executorResult, _ctx, subActions;
@@ -4287,7 +4290,8 @@ function _runActionsRecursively() {
4287
4290
  runId: runId,
4288
4291
  ctx: ctx,
4289
4292
  blueprintActionKVMap: blueprintActionKVMap,
4290
- logger: logger
4293
+ logger: logger,
4294
+ order: order + 1
4291
4295
  });
4292
4296
  case 22:
4293
4297
  executorResult = _context.sent;
@@ -4369,7 +4373,8 @@ function _runActionsRecursively() {
4369
4373
  ctx: ctx,
4370
4374
  blueprintId: blueprintId,
4371
4375
  blueprintActionKVMap: blueprintActionKVMap,
4372
- logger: logger
4376
+ logger: logger,
4377
+ order: order + 1
4373
4378
  });
4374
4379
  case 26:
4375
4380
  _context2.t1 = _context2.sent;
@@ -4462,7 +4467,9 @@ function _runActionsRecursively() {
4462
4467
  v: false
4463
4468
  });
4464
4469
  case 57:
4465
- dataContext[action.id] = executorResult;
4470
+ dataContext[action.id] = _extends({}, executorResult, {
4471
+ workflowStepOrder: order
4472
+ });
4466
4473
  if (!(action.type === "CONDITIONS" || (_action$subActions = action.subActions) != null && _action$subActions.length)) {
4467
4474
  _context2.next = 65;
4468
4475
  break;
@@ -4482,7 +4489,8 @@ function _runActionsRecursively() {
4482
4489
  ctx: ctx,
4483
4490
  blueprintId: blueprintId,
4484
4491
  blueprintActionKVMap: blueprintActionKVMap,
4485
- logger: logger
4492
+ logger: logger,
4493
+ order: order + 1
4486
4494
  });
4487
4495
  case 63:
4488
4496
  _context2.t3 = _context2.sent;
@@ -4590,7 +4598,9 @@ function _blueprintRunner() {
4590
4598
  message: 'Workflow run skipped'
4591
4599
  })
4592
4600
  });
4593
- return _context4.abrupt("return");
4601
+ return _context4.abrupt("return", {
4602
+ fullCtx: null
4603
+ });
4594
4604
  case 16:
4595
4605
  blueprintActionKVMap = constructWorkflowContextBluePrint(blueprint);
4596
4606
  _context4.next = 19;
@@ -4603,28 +4613,37 @@ function _blueprintRunner() {
4603
4613
  blueprintActionKVMap: blueprintActionKVMap,
4604
4614
  blueprintId: blueprint.id,
4605
4615
  runId: '',
4606
- logger: logger
4616
+ logger: logger,
4617
+ order: 0
4607
4618
  });
4608
4619
  case 19:
4609
4620
  ranSuccessfully = _context4.sent;
4610
- if (ranSuccessfully) {
4611
- logger.info({
4612
- type: RegisteredLogger.WORKFLOW,
4613
- destinationPath: "" + blueprint.id,
4614
- message: JSON.stringify({
4615
- message: 'Workflow run completed'
4616
- })
4617
- });
4618
- } else {
4619
- logger.error({
4620
- type: RegisteredLogger.WORKFLOW,
4621
- destinationPath: "" + blueprint.id,
4622
- message: JSON.stringify({
4623
- message: 'Workflow run failed'
4624
- })
4625
- });
4621
+ if (!ranSuccessfully) {
4622
+ _context4.next = 25;
4623
+ break;
4626
4624
  }
4627
- case 21:
4625
+ logger.info({
4626
+ type: RegisteredLogger.WORKFLOW,
4627
+ destinationPath: "" + blueprint.id,
4628
+ message: JSON.stringify({
4629
+ message: 'Workflow run completed'
4630
+ })
4631
+ });
4632
+ return _context4.abrupt("return", {
4633
+ fullCtx: fullCtx
4634
+ });
4635
+ case 25:
4636
+ logger.error({
4637
+ type: RegisteredLogger.WORKFLOW,
4638
+ destinationPath: "" + blueprint.id,
4639
+ message: JSON.stringify({
4640
+ message: 'Workflow run failed'
4641
+ })
4642
+ });
4643
+ return _context4.abrupt("return", {
4644
+ fullCtx: null
4645
+ });
4646
+ case 27:
4628
4647
  case "end":
4629
4648
  return _context4.stop();
4630
4649
  }
@@ -5704,7 +5723,6 @@ function _syncAndWriteVectorProviderIndexesToLocal() {
5704
5723
  while (1) switch (_context15.prev = _context15.next) {
5705
5724
  case 0:
5706
5725
  mastra = _ref14.mastra;
5707
- // TODO: Return in prod ? or do somethif different
5708
5726
  vectorProviders = mastra.config.agents.vectorProvider;
5709
5727
  pullVectorProviderIndexes = /*#__PURE__*/function () {
5710
5728
  var _ref16 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref15) {
@@ -5843,9 +5861,9 @@ function getAgentSystemApis(_ref) {
5843
5861
  case 19:
5844
5862
  run = _context.sent;
5845
5863
  message = run == null || (_run$content = run.content) == null || (_run$content = _run$content[0]) == null || (_run$content = _run$content.text) == null ? void 0 : _run$content.value;
5846
- _answer2 = run == null || (_run$content2 = run.content) == null ? void 0 : _run$content2.find(function (m) {
5864
+ _answer2 = run == null || (_run$content2 = run.content) == null || (_run$content2 = _run$content2.find(function (m) {
5847
5865
  return m.toolName === 'answer';
5848
- }).args;
5866
+ })) == null ? void 0 : _run$content2.args;
5849
5867
  return _context.abrupt("return", {
5850
5868
  message: message,
5851
5869
  answer: _answer2
@@ -5923,7 +5941,8 @@ function updateAssistantAgentHandler(logger) {
5923
5941
  while (1) switch (_context2.prev = _context2.next) {
5924
5942
  case 0:
5925
5943
  assistantId = _ref2.assistantId, name = _ref2.name, instructions = _ref2.instructions, model = _ref2.model, tools = _ref2.tools, response_format = _ref2.response_format;
5926
- _context2.next = 3;
5944
+ console.log('response_format', response_format);
5945
+ _context2.next = 4;
5927
5946
  return client.beta.assistants.update(assistantId, {
5928
5947
  name: name,
5929
5948
  model: model,
@@ -5931,7 +5950,7 @@ function updateAssistantAgentHandler(logger) {
5931
5950
  tools: tools,
5932
5951
  response_format: response_format
5933
5952
  });
5934
- case 3:
5953
+ case 4:
5935
5954
  assistant = _context2.sent;
5936
5955
  logger == null || logger.info({
5937
5956
  destinationPath: "" + assistant.id,
@@ -5948,7 +5967,7 @@ function updateAssistantAgentHandler(logger) {
5948
5967
  }
5949
5968
  }, null, 2)
5950
5969
  });
5951
- case 5:
5970
+ case 6:
5952
5971
  case "end":
5953
5972
  return _context2.stop();
5954
5973
  }
@@ -5974,11 +5993,11 @@ function getAssistantAgentHandler(logger) {
5974
5993
  agent = _context11.sent;
5975
5994
  handleRunStatus = /*#__PURE__*/function () {
5976
5995
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
5977
- var threadId, run, _messages$data, messages;
5996
+ var threadId, run, callback, _messages$data, messages;
5978
5997
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
5979
5998
  while (1) switch (_context3.prev = _context3.next) {
5980
5999
  case 0:
5981
- threadId = _ref4.threadId, run = _ref4.run;
6000
+ threadId = _ref4.threadId, run = _ref4.run, callback = _ref4.callback;
5982
6001
  if (!(run.status === 'completed')) {
5983
6002
  _context3.next = 8;
5984
6003
  break;
@@ -5990,17 +6009,19 @@ function getAssistantAgentHandler(logger) {
5990
6009
  return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
5991
6010
  case 8:
5992
6011
  if (!(run.status === 'requires_action')) {
5993
- _context3.next = 14;
6012
+ _context3.next = 15;
5994
6013
  break;
5995
6014
  }
5996
- _context3.next = 11;
6015
+ callback == null || callback(run);
6016
+ _context3.next = 12;
5997
6017
  return handleRequiresAction({
5998
6018
  run: run,
5999
- threadId: threadId
6019
+ threadId: threadId,
6020
+ callback: callback
6000
6021
  });
6001
- case 11:
6022
+ case 12:
6002
6023
  return _context3.abrupt("return", _context3.sent);
6003
- case 14:
6024
+ case 15:
6004
6025
  console.error('Run did not complete:', run);
6005
6026
  logger == null || logger.error({
6006
6027
  destinationPath: "" + id,
@@ -6015,7 +6036,7 @@ function getAssistantAgentHandler(logger) {
6015
6036
  }, null, 2)
6016
6037
  });
6017
6038
  return _context3.abrupt("return", run == null ? void 0 : run.last_error);
6018
- case 17:
6039
+ case 18:
6019
6040
  case "end":
6020
6041
  return _context3.stop();
6021
6042
  }
@@ -6027,13 +6048,13 @@ function getAssistantAgentHandler(logger) {
6027
6048
  }();
6028
6049
  handleRequiresAction = /*#__PURE__*/function () {
6029
6050
  var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
6030
- var threadId, run, toolOutputs;
6051
+ var threadId, run, callback, toolOutputs;
6031
6052
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
6032
6053
  while (1) switch (_context5.prev = _context5.next) {
6033
6054
  case 0:
6034
- threadId = _ref6.threadId, run = _ref6.run;
6055
+ threadId = _ref6.threadId, run = _ref6.run, callback = _ref6.callback;
6035
6056
  if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
6036
- _context5.next = 23;
6057
+ _context5.next = 22;
6037
6058
  break;
6038
6059
  }
6039
6060
  _context5.t0 = compact;
@@ -6150,19 +6171,19 @@ function getAssistantAgentHandler(logger) {
6150
6171
  });
6151
6172
  return _context5.abrupt("return", handleRunStatus({
6152
6173
  threadId: threadId,
6153
- run: run
6174
+ run: run,
6175
+ callback: callback
6154
6176
  }));
6155
6177
  case 11:
6156
6178
  if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
6157
- _context5.next = 20;
6179
+ _context5.next = 19;
6158
6180
  break;
6159
6181
  }
6160
- console.log(toolOutputs, '###### YOOOOOO');
6161
- _context5.next = 15;
6182
+ _context5.next = 14;
6162
6183
  return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
6163
6184
  tool_outputs: toolOutputs
6164
6185
  });
6165
- case 15:
6186
+ case 14:
6166
6187
  run = _context5.sent;
6167
6188
  logger == null || logger.info({
6168
6189
  destinationPath: "" + id,
@@ -6176,9 +6197,9 @@ function getAssistantAgentHandler(logger) {
6176
6197
  }, null, 2)
6177
6198
  });
6178
6199
  console.log('Tool outputs submitted successfully.');
6179
- _context5.next = 22;
6200
+ _context5.next = 21;
6180
6201
  break;
6181
- case 20:
6202
+ case 19:
6182
6203
  logger == null || logger.info({
6183
6204
  destinationPath: "" + id,
6184
6205
  statusCode: 404,
@@ -6189,12 +6210,13 @@ function getAssistantAgentHandler(logger) {
6189
6210
  }, null, 2)
6190
6211
  });
6191
6212
  console.log('No tool outputs to submit.');
6192
- case 22:
6213
+ case 21:
6193
6214
  return _context5.abrupt("return", handleRunStatus({
6194
6215
  threadId: threadId,
6195
- run: run
6216
+ run: run,
6217
+ callback: callback
6196
6218
  }));
6197
- case 23:
6219
+ case 22:
6198
6220
  case "end":
6199
6221
  return _context5.stop();
6200
6222
  }
@@ -6304,11 +6326,11 @@ function getAssistantAgentHandler(logger) {
6304
6326
  }(),
6305
6327
  watchRun: function () {
6306
6328
  var _watchRun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref13) {
6307
- var runId, threadId, run;
6329
+ var runId, threadId, callback, run;
6308
6330
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
6309
6331
  while (1) switch (_context10.prev = _context10.next) {
6310
6332
  case 0:
6311
- runId = _ref13.runId, threadId = _ref13.threadId;
6333
+ runId = _ref13.runId, threadId = _ref13.threadId, callback = _ref13.callback;
6312
6334
  if (!runId) {
6313
6335
  _context10.next = 7;
6314
6336
  break;
@@ -6347,7 +6369,8 @@ function getAssistantAgentHandler(logger) {
6347
6369
  case 11:
6348
6370
  return _context10.abrupt("return", handleRunStatus({
6349
6371
  threadId: threadId,
6350
- run: run
6372
+ run: run,
6373
+ callback: callback
6351
6374
  }));
6352
6375
  case 12:
6353
6376
  case "end":
@@ -6887,7 +6910,7 @@ var Mastra = /*#__PURE__*/function () {
6887
6910
  this.runBlueprint = /*#__PURE__*/function () {
6888
6911
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
6889
6912
  var _this$availableIntegr;
6890
- var blueprint, _ref2$dataCtx, dataCtx, ctx, systemApis, systemEvents, availableIntegrations, availableIntegrationApis, availableIntegrationEvents, frameworkApis, frameworkEvents;
6913
+ var blueprint, _ref2$dataCtx, dataCtx, ctx, systemApis, systemEvents, availableIntegrations, availableIntegrationApis, availableIntegrationEvents, frameworkApis, frameworkEvents, blueprintResult;
6891
6914
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6892
6915
  while (1) switch (_context.prev = _context.next) {
6893
6916
  case 0:
@@ -6920,6 +6943,9 @@ var Mastra = /*#__PURE__*/function () {
6920
6943
  logger: _this.logger.get('WORKFLOW')
6921
6944
  });
6922
6945
  case 10:
6946
+ blueprintResult = _context.sent;
6947
+ return _context.abrupt("return", blueprintResult);
6948
+ case 12:
6923
6949
  case "end":
6924
6950
  return _context.stop();
6925
6951
  }
@@ -7571,6 +7597,7 @@ var Mastra = /*#__PURE__*/function () {
7571
7597
  case 27:
7572
7598
  return _context8.abrupt("return", {
7573
7599
  status: lastRun.status,
7600
+ output: lastRun.output,
7574
7601
  startedAt: lastRun.run_started_at,
7575
7602
  endedAt: lastRun.ended_at
7576
7603
  });
@@ -7860,11 +7887,15 @@ var Mastra = /*#__PURE__*/function () {
7860
7887
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
7861
7888
  while (1) switch (_context15.prev = _context15.next) {
7862
7889
  case 0:
7863
- _context15.next = 2;
7890
+ if (!(process.env.NODE_ENV === 'development')) {
7891
+ _context15.next = 3;
7892
+ break;
7893
+ }
7894
+ _context15.next = 3;
7864
7895
  return syncAndWriteVectorProviderIndexesToLocal({
7865
7896
  mastra: this
7866
7897
  });
7867
- case 2:
7898
+ case 3:
7868
7899
  case "end":
7869
7900
  return _context15.stop();
7870
7901
  }