@mastra/core 0.1.11 → 0.1.13

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 (54) hide show
  1. package/dist/agents/file-logger.d.ts +0 -13
  2. package/dist/agents/file-logger.d.ts.map +1 -1
  3. package/dist/agents/index.d.ts.map +1 -1
  4. package/dist/agents/openai/assistant.d.ts +16 -3
  5. package/dist/agents/openai/assistant.d.ts.map +1 -1
  6. package/dist/agents/utils.d.ts +7 -0
  7. package/dist/agents/utils.d.ts.map +1 -1
  8. package/dist/agents/vector-sync.d.ts +3 -2
  9. package/dist/agents/vector-sync.d.ts.map +1 -1
  10. package/dist/core.cjs.development.js +1673 -1395
  11. package/dist/core.cjs.development.js.map +1 -1
  12. package/dist/core.cjs.production.min.js +1 -1
  13. package/dist/core.cjs.production.min.js.map +1 -1
  14. package/dist/core.esm.js +1671 -1398
  15. package/dist/core.esm.js.map +1 -1
  16. package/dist/framework.d.ts +8 -3
  17. package/dist/framework.d.ts.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/integration.d.ts.map +1 -1
  21. package/dist/lib/index.d.ts +1 -0
  22. package/dist/lib/index.d.ts.map +1 -1
  23. package/dist/lib/logger-utils/logger.d.ts +98 -0
  24. package/dist/lib/logger-utils/logger.d.ts.map +1 -0
  25. package/dist/next/cron.d.ts +13 -0
  26. package/dist/next/cron.d.ts.map +1 -0
  27. package/dist/next/index.d.ts.map +1 -1
  28. package/dist/schemas.d.ts +13 -0
  29. package/dist/schemas.d.ts.map +1 -1
  30. package/dist/types.d.ts +6 -2
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/utils/index.d.ts +2 -0
  33. package/dist/utils/index.d.ts.map +1 -1
  34. package/dist/utils/text.d.ts +2 -0
  35. package/dist/utils/text.d.ts.map +1 -0
  36. package/dist/vector-access/index.d.ts +4 -0
  37. package/dist/vector-access/index.d.ts.map +1 -1
  38. package/dist/workflows/apis.d.ts +9 -0
  39. package/dist/workflows/apis.d.ts.map +1 -0
  40. package/dist/workflows/handler.d.ts +8 -0
  41. package/dist/workflows/handler.d.ts.map +1 -1
  42. package/dist/workflows/runner.d.ts +3 -1
  43. package/dist/workflows/runner.d.ts.map +1 -1
  44. package/package.json +4 -4
  45. package/dist/prisma/client.ts +0 -31
  46. package/dist/prisma/gen.js +0 -139
  47. package/dist/prisma/migrations/20240828034109_initial_migration/migration.sql +0 -111
  48. package/dist/prisma/migrations/20240829210901_initial_migration/migration.sql +0 -1
  49. package/dist/prisma/migrations/20240905143158_initial_migration/migration.sql +0 -1
  50. package/dist/prisma/migrations/20240911212856_initial_migration/migration.sql +0 -1
  51. package/dist/prisma/migrations/20240915044235_initial_migration/migration.sql +0 -1
  52. package/dist/prisma/migrations/20241008024219_initial_migration/migration.sql +0 -69
  53. package/dist/prisma/migrations/migration_lock.toml +0 -3
  54. package/dist/prisma/schema.prisma +0 -129
@@ -11,8 +11,8 @@ var zod = require('zod');
11
11
  var headers = require('next/headers');
12
12
  var qs = require('qs');
13
13
  var next = require('inngest/next');
14
- var path = require('path');
15
14
  var fs = require('fs');
15
+ var path = require('path');
16
16
  var first = require('lodash/first');
17
17
  var last = require('lodash/last');
18
18
  var inngest = require('inngest');
@@ -87,6 +87,14 @@ function _asyncToGenerator(n) {
87
87
  });
88
88
  };
89
89
  }
90
+ function _classPrivateFieldLooseBase(e, t) {
91
+ if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance");
92
+ return e;
93
+ }
94
+ var id = 0;
95
+ function _classPrivateFieldLooseKey(e) {
96
+ return "__private_" + id++ + "_" + e;
97
+ }
90
98
  function _construct(t, e, r) {
91
99
  if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
92
100
  var o = [null];
@@ -1774,6 +1782,11 @@ var webhookQueryParams = /*#__PURE__*/zod.z.object({
1774
1782
  var apiKeyConnectionOptions = /*#__PURE__*/zod.z.object({
1775
1783
  apiKey: /*#__PURE__*/zod.z.string()
1776
1784
  });
1785
+ var cronQueryParams = /*#__PURE__*/zod.z.object({
1786
+ event: /*#__PURE__*/zod.z.string(),
1787
+ data: /*#__PURE__*/zod.z.string().optional(),
1788
+ integrationName: /*#__PURE__*/zod.z.string()
1789
+ });
1777
1790
 
1778
1791
  var parseQueryParams = function parseQueryParams(req, schema) {
1779
1792
  var search = req.nextUrl.search.slice(1);
@@ -1879,6 +1892,44 @@ var client$1 = /*#__PURE__*/new inngest.Inngest({
1879
1892
  id: APP_ID
1880
1893
  });
1881
1894
 
1895
+ function readBlueprintSync(filePath) {
1896
+ try {
1897
+ var data = fs__namespace.readFileSync(filePath, 'utf8');
1898
+ var jsonData = JSON.parse(data);
1899
+ var blueprintFile = last(filePath == null ? void 0 : filePath.split('/'));
1900
+ var blueprintId = first(blueprintFile == null ? void 0 : blueprintFile.split('.json'));
1901
+ return _extends({}, jsonData, {
1902
+ id: blueprintId
1903
+ });
1904
+ } catch (err) {
1905
+ throw new Error("Failed to read blueprint: " + err);
1906
+ }
1907
+ }
1908
+ function getBlueprintsSync(_ref) {
1909
+ var directoryPath = _ref.directoryPath;
1910
+ try {
1911
+ var files = fs__namespace.readdirSync(directoryPath);
1912
+ var jsonFiles = files.filter(function (file) {
1913
+ return file.endsWith('.json');
1914
+ });
1915
+ var result = [];
1916
+ for (var _iterator = _createForOfIteratorHelperLoose(jsonFiles), _step; !(_step = _iterator()).done;) {
1917
+ var file = _step.value;
1918
+ var filePath = path.join(directoryPath, file);
1919
+ var jsonData = readBlueprintSync(filePath);
1920
+ if (jsonData.title) {
1921
+ var blueprintFile = last(filePath == null ? void 0 : filePath.split('/'));
1922
+ var blueprintId = first(blueprintFile == null ? void 0 : blueprintFile.split('.json'));
1923
+ result.push(_extends({}, jsonData, {
1924
+ id: blueprintId
1925
+ }));
1926
+ }
1927
+ }
1928
+ return result;
1929
+ } catch (err) {
1930
+ throw new Error("Failed to get blueprints: " + err);
1931
+ }
1932
+ }
1882
1933
  function readBlueprint(_x) {
1883
1934
  return _readBlueprint.apply(this, arguments);
1884
1935
  }
@@ -1911,16 +1962,16 @@ function getBlueprints(_x2) {
1911
1962
  return _getBlueprints.apply(this, arguments);
1912
1963
  }
1913
1964
  function _getBlueprints() {
1914
- _getBlueprints = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref) {
1965
+ _getBlueprints = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref2) {
1915
1966
  var directoryPath;
1916
1967
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1917
1968
  while (1) switch (_context6.prev = _context6.next) {
1918
1969
  case 0:
1919
- directoryPath = _ref.directoryPath;
1970
+ directoryPath = _ref2.directoryPath;
1920
1971
  return _context6.abrupt("return", new Promise(function (resolve, reject) {
1921
1972
  fs__namespace.readdir(directoryPath, /*#__PURE__*/function () {
1922
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(err, files) {
1923
- var jsonFiles, result, _iterator, _step, file, filePath, jsonData, blueprintFile, blueprintId;
1973
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(err, files) {
1974
+ var jsonFiles, result, _iterator2, _step2, file, filePath, jsonData, blueprintFile, blueprintId;
1924
1975
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1925
1976
  while (1) switch (_context5.prev = _context5.next) {
1926
1977
  case 0:
@@ -1936,13 +1987,13 @@ function _getBlueprints() {
1936
1987
  return file.endsWith('.json');
1937
1988
  });
1938
1989
  result = [];
1939
- _iterator = _createForOfIteratorHelperLoose(jsonFiles);
1990
+ _iterator2 = _createForOfIteratorHelperLoose(jsonFiles);
1940
1991
  case 7:
1941
- if ((_step = _iterator()).done) {
1992
+ if ((_step2 = _iterator2()).done) {
1942
1993
  _context5.next = 16;
1943
1994
  break;
1944
1995
  }
1945
- file = _step.value;
1996
+ file = _step2.value;
1946
1997
  filePath = path.join(directoryPath, file);
1947
1998
  _context5.next = 12;
1948
1999
  return readBlueprint(filePath);
@@ -1967,7 +2018,7 @@ function _getBlueprints() {
1967
2018
  }, _callee5);
1968
2019
  }));
1969
2020
  return function (_x4, _x5) {
1970
- return _ref7.apply(this, arguments);
2021
+ return _ref8.apply(this, arguments);
1971
2022
  };
1972
2023
  }());
1973
2024
  }));
@@ -1979,40 +2030,46 @@ function _getBlueprints() {
1979
2030
  }));
1980
2031
  return _getBlueprints.apply(this, arguments);
1981
2032
  }
1982
- var createWorkflowHandler = function createWorkflowHandler(_ref2) {
1983
- var blueprintDirPath = _ref2.blueprintDirPath,
1984
- runBlueprint = _ref2.runBlueprint;
2033
+ var createWorkflowHandler = function createWorkflowHandler(_ref3) {
2034
+ var blueprintDirPath = _ref3.blueprintDirPath,
2035
+ runBlueprint = _ref3.runBlueprint;
1985
2036
  return client$1.createFunction({
1986
2037
  id: 'workflow-executor',
1987
2038
  retries: 0
1988
2039
  }, {
1989
2040
  event: 'workflow/run-automations'
1990
2041
  }, /*#__PURE__*/function () {
1991
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
2042
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
1992
2043
  var event, step, _event$data, trigger, payload, connectionId, getBlueprintsDirPath, blueprints, triggeredAndPublishedBlueprints, runs;
1993
2044
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1994
2045
  while (1) switch (_context3.prev = _context3.next) {
1995
2046
  case 0:
1996
- event = _ref3.event, step = _ref3.step;
2047
+ event = _ref4.event, step = _ref4.step;
1997
2048
  _context3.prev = 1;
1998
2049
  _event$data = event.data, trigger = _event$data.trigger, payload = _event$data.payload;
1999
2050
  connectionId = event.user.connectionId;
2000
2051
  getBlueprintsDirPath = /*#__PURE__*/function () {
2001
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2002
- var ARK_APP_DIR;
2052
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2053
+ var MASTRA_APP_DIR;
2003
2054
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2004
2055
  while (1) switch (_context.prev = _context.next) {
2005
2056
  case 0:
2006
- ARK_APP_DIR = process.env.ARK_APP_DIR || process.cwd();
2007
- return _context.abrupt("return", path.join(ARK_APP_DIR, blueprintDirPath || '/blueprints'));
2008
- case 2:
2057
+ MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
2058
+ if (blueprintDirPath) {
2059
+ _context.next = 3;
2060
+ break;
2061
+ }
2062
+ throw new Error('Missing blueprintDirPath in config');
2063
+ case 3:
2064
+ return _context.abrupt("return", path.join(MASTRA_APP_DIR, blueprintDirPath));
2065
+ case 4:
2009
2066
  case "end":
2010
2067
  return _context.stop();
2011
2068
  }
2012
2069
  }, _callee);
2013
2070
  }));
2014
2071
  return function getBlueprintsDirPath() {
2015
- return _ref5.apply(this, arguments);
2072
+ return _ref6.apply(this, arguments);
2016
2073
  };
2017
2074
  }();
2018
2075
  _context3.next = 7;
@@ -2067,7 +2124,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
2067
2124
  }, _callee3, null, [[1, 15]]);
2068
2125
  }));
2069
2126
  return function (_x3) {
2070
- return _ref4.apply(this, arguments);
2127
+ return _ref5.apply(this, arguments);
2071
2128
  };
2072
2129
  }());
2073
2130
  };
@@ -2164,13 +2221,52 @@ var makeWebhook = function makeWebhook(framework) {
2164
2221
  };
2165
2222
  };
2166
2223
 
2224
+ var makeCron = function makeCron(framework) {
2225
+ return function (req) {
2226
+ var params = parseQueryParams(req, cronQueryParams);
2227
+ var data = params.data,
2228
+ error = params.error;
2229
+ if (error) {
2230
+ return server.NextResponse.json({
2231
+ error: error,
2232
+ status: 400
2233
+ });
2234
+ }
2235
+ var event = data.event,
2236
+ integrationName = data.integrationName;
2237
+ if (!event) {
2238
+ return server.NextResponse.json({
2239
+ error: 'Event is required for mastra cron',
2240
+ status: 400
2241
+ });
2242
+ }
2243
+ var decodedEvent = decodeURI(event);
2244
+ var decodedData = {};
2245
+ if (data != null && data.data) {
2246
+ decodedData = JSON.parse(Buffer.from(data.data, 'base64').toString());
2247
+ }
2248
+ void framework.triggerEvent({
2249
+ key: decodedEvent,
2250
+ data: decodedData,
2251
+ integrationName: integrationName,
2252
+ user: {
2253
+ connectionId: 'SYSTEM'
2254
+ }
2255
+ });
2256
+ return server.NextResponse.json({
2257
+ message: "Cron Triggered event " + event
2258
+ });
2259
+ };
2260
+ };
2261
+
2167
2262
  var registerRoutes = function registerRoutes(_ref) {
2168
2263
  var framework = _ref.framework;
2169
2264
  var registry = {
2170
2265
  connect: makeConnect(framework),
2171
2266
  'connect/callback': makeCallback(framework),
2172
2267
  inngest: makeInngest(framework),
2173
- webhook: makeWebhook(framework)
2268
+ webhook: makeWebhook(framework),
2269
+ cron: makeCron(framework)
2174
2270
  };
2175
2271
  return function (req, _ref2) {
2176
2272
  var _Object$keys$at;
@@ -2356,6 +2452,203 @@ function mergeWithDefinedOnly(base, overrides) {
2356
2452
  return result;
2357
2453
  }
2358
2454
 
2455
+ var LogProvider = {
2456
+ CONSOLE: 'CONSOLE',
2457
+ FILE: 'FILE',
2458
+ UPSTASH: 'UPSTASH'
2459
+ };
2460
+ exports.LogLevel = void 0;
2461
+ (function (LogLevel) {
2462
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
2463
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
2464
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
2465
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
2466
+ })(exports.LogLevel || (exports.LogLevel = {}));
2467
+ // Abstract base class for loggers
2468
+ var BaseLogger = /*#__PURE__*/function () {
2469
+ function BaseLogger(level) {
2470
+ if (level === void 0) {
2471
+ level = exports.LogLevel.INFO;
2472
+ }
2473
+ this.level = void 0;
2474
+ this.level = level;
2475
+ }
2476
+ var _proto = BaseLogger.prototype;
2477
+ _proto.debug = function debug(message) {
2478
+ if (this.level <= exports.LogLevel.DEBUG) {
2479
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2480
+ args[_key - 1] = arguments[_key];
2481
+ }
2482
+ this.log.apply(this, [exports.LogLevel.DEBUG, message].concat(args));
2483
+ }
2484
+ };
2485
+ _proto.info = function info(message) {
2486
+ if (this.level <= exports.LogLevel.INFO) {
2487
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2488
+ args[_key2 - 1] = arguments[_key2];
2489
+ }
2490
+ this.log.apply(this, [exports.LogLevel.INFO, message].concat(args));
2491
+ }
2492
+ };
2493
+ _proto.warn = function warn(message) {
2494
+ if (this.level <= exports.LogLevel.WARN) {
2495
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2496
+ args[_key3 - 1] = arguments[_key3];
2497
+ }
2498
+ this.log.apply(this, [exports.LogLevel.WARN, message].concat(args));
2499
+ }
2500
+ };
2501
+ _proto.error = function error(message) {
2502
+ if (this.level <= exports.LogLevel.ERROR) {
2503
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
2504
+ args[_key4 - 1] = arguments[_key4];
2505
+ }
2506
+ this.log.apply(this, [exports.LogLevel.ERROR, message].concat(args));
2507
+ }
2508
+ };
2509
+ _proto.formatMessage = function formatMessage(message) {
2510
+ if (typeof message === 'string') {
2511
+ return message;
2512
+ }
2513
+ return JSON.stringify(message);
2514
+ };
2515
+ return BaseLogger;
2516
+ }();
2517
+ /**
2518
+ * Logs to the console
2519
+ */
2520
+ var ConsoleLogger = /*#__PURE__*/function (_BaseLogger2) {
2521
+ function ConsoleLogger(_ref) {
2522
+ var level = _ref.level;
2523
+ return _BaseLogger2.call(this, level != null ? level : exports.LogLevel.INFO) || this;
2524
+ }
2525
+ _inheritsLoose(ConsoleLogger, _BaseLogger2);
2526
+ var _proto2 = ConsoleLogger.prototype;
2527
+ _proto2.log = function log(level, message) {
2528
+ var _console;
2529
+ var timestamp = new Date().toISOString();
2530
+ for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
2531
+ args[_key5 - 2] = arguments[_key5];
2532
+ }
2533
+ (_console = console).log.apply(_console, ["[" + timestamp + "] [" + level + "] " + this.formatMessage(message)].concat(args));
2534
+ };
2535
+ return ConsoleLogger;
2536
+ }(BaseLogger);
2537
+ /**
2538
+ * Logs to a file
2539
+ */
2540
+ var _dirPath = /*#__PURE__*/_classPrivateFieldLooseKey("dirPath");
2541
+ var FileLogger = /*#__PURE__*/function (_BaseLogger3) {
2542
+ function FileLogger(_ref2) {
2543
+ var _this;
2544
+ var dirPath = _ref2.dirPath,
2545
+ level = _ref2.level;
2546
+ _this = _BaseLogger3.call(this, level != null ? level : exports.LogLevel.INFO) || this;
2547
+ Object.defineProperty(_this, _dirPath, {
2548
+ writable: true,
2549
+ value: void 0
2550
+ });
2551
+ if (!dirPath) {
2552
+ throw new Error('File path is required');
2553
+ }
2554
+ _classPrivateFieldLooseBase(_this, _dirPath)[_dirPath] = dirPath;
2555
+ return _this;
2556
+ }
2557
+ _inheritsLoose(FileLogger, _BaseLogger3);
2558
+ var _proto3 = FileLogger.prototype;
2559
+ _proto3.log = function log(level, message) {
2560
+ var fullPath = path.join(_classPrivateFieldLooseBase(this, _dirPath)[_dirPath], message.destinationPath + ".json");
2561
+ console.log("Logging to file: " + fullPath);
2562
+ if (!fs.existsSync(_classPrivateFieldLooseBase(this, _dirPath)[_dirPath])) {
2563
+ fs.mkdirSync(_classPrivateFieldLooseBase(this, _dirPath)[_dirPath], {
2564
+ recursive: true
2565
+ });
2566
+ return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, message, {
2567
+ level: level,
2568
+ createdAt: new Date()
2569
+ })], null, 2));
2570
+ }
2571
+ if (!fs.existsSync(fullPath)) {
2572
+ return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, message, {
2573
+ createdAt: new Date()
2574
+ })], null, 2));
2575
+ }
2576
+ var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
2577
+ logs.push(_extends({}, message, {
2578
+ createdAt: new Date()
2579
+ }));
2580
+ return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
2581
+ };
2582
+ return FileLogger;
2583
+ }(BaseLogger);
2584
+ /**
2585
+ * Logs to Upstash Redis
2586
+ */
2587
+ var _redisClient = /*#__PURE__*/_classPrivateFieldLooseKey("redisClient");
2588
+ var _key6 = /*#__PURE__*/_classPrivateFieldLooseKey("key");
2589
+ var UpstashRedisLogger = /*#__PURE__*/function (_BaseLogger4) {
2590
+ function UpstashRedisLogger(_ref3) {
2591
+ var _this2;
2592
+ var redisClient = _ref3.redisClient,
2593
+ level = _ref3.level,
2594
+ key = _ref3.key;
2595
+ _this2 = _BaseLogger4.call(this, level != null ? level : exports.LogLevel.INFO) || this;
2596
+ Object.defineProperty(_this2, _redisClient, {
2597
+ writable: true,
2598
+ value: void 0
2599
+ });
2600
+ Object.defineProperty(_this2, _key6, {
2601
+ writable: true,
2602
+ value: void 0
2603
+ });
2604
+ if (!redisClient) {
2605
+ throw new Error('redisClient is required');
2606
+ }
2607
+ if (!key) {
2608
+ throw new Error('Redis storage key is required');
2609
+ }
2610
+ _classPrivateFieldLooseBase(_this2, _redisClient)[_redisClient] = redisClient;
2611
+ _classPrivateFieldLooseBase(_this2, _key6)[_key6] = key;
2612
+ return _this2;
2613
+ }
2614
+ _inheritsLoose(UpstashRedisLogger, _BaseLogger4);
2615
+ var _proto4 = UpstashRedisLogger.prototype;
2616
+ _proto4.log = function log(level, message) {
2617
+ var fullKey = path.join(_classPrivateFieldLooseBase(this, _key6)[_key6], "" + message.destinationPath);
2618
+ _classPrivateFieldLooseBase(this, _redisClient)[_redisClient].lpush(fullKey, JSON.stringify(_extends({}, message, {
2619
+ level: level,
2620
+ createdAt: new Date()
2621
+ })));
2622
+ };
2623
+ _proto4.getLogs = function getLogs(key) {
2624
+ return _classPrivateFieldLooseBase(this, _redisClient)[_redisClient].lrange(key, 0, -1);
2625
+ };
2626
+ return UpstashRedisLogger;
2627
+ }(BaseLogger);
2628
+ function createLogger(_ref4) {
2629
+ var type = _ref4.type,
2630
+ options = _ref4.options;
2631
+ switch (type) {
2632
+ case 'CONSOLE':
2633
+ return new ConsoleLogger({
2634
+ level: options == null ? void 0 : options.level
2635
+ });
2636
+ case 'FILE':
2637
+ return new FileLogger({
2638
+ dirPath: options.dirPath,
2639
+ level: options.level
2640
+ });
2641
+ case 'UPSTASH':
2642
+ return new UpstashRedisLogger({
2643
+ redisClient: options.redisClient,
2644
+ key: options.key,
2645
+ level: options.level
2646
+ });
2647
+ default:
2648
+ throw new Error("Unsupported logger type: " + type);
2649
+ }
2650
+ }
2651
+
2359
2652
  var _excluded$3 = ["client"],
2360
2653
  _excluded2$1 = ["name", "logoUrl"];
2361
2654
  /**
@@ -2442,7 +2735,7 @@ var Integration = /*#__PURE__*/function () {
2442
2735
  return acc;
2443
2736
  }
2444
2737
  }, {});
2445
- _this.apis = apis;
2738
+ _this.apis = _extends({}, _this.apis, apis);
2446
2739
  case 5:
2447
2740
  case "end":
2448
2741
  return _context2.stop();
@@ -3061,6 +3354,31 @@ var IntegrationAuth = /*#__PURE__*/function () {
3061
3354
  return IntegrationAuth;
3062
3355
  }();
3063
3356
 
3357
+ function splitMarkdownIntoChunks(markdown, maxTokens) {
3358
+ if (maxTokens === void 0) {
3359
+ maxTokens = 8190;
3360
+ }
3361
+ var tokens = markdown.split(/\s+/); // Split by whitespace to tokenize
3362
+ var chunks = [];
3363
+ var currentChunk = [];
3364
+ for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
3365
+ var token = _step.value;
3366
+ if (currentChunk.join(' ').length + token.length + 1 > maxTokens) {
3367
+ // If adding the next token exceeds the limit, push the current chunk and reset
3368
+ chunks.push(currentChunk.join(' '));
3369
+ currentChunk = [token]; // Start a new chunk with the current token
3370
+ } else {
3371
+ // Otherwise, add the token to the current chunk
3372
+ currentChunk.push(token);
3373
+ }
3374
+ }
3375
+ // Add any remaining tokens as the last chunk
3376
+ if (currentChunk.length > 0) {
3377
+ chunks.push(currentChunk.join(' '));
3378
+ }
3379
+ return chunks;
3380
+ }
3381
+
3064
3382
  /**
3065
3383
  * Extract schema options for the provided schema - Builds a map of fieldname to field options
3066
3384
  * @param schema - schema
@@ -3137,6 +3455,11 @@ function setFieldOptions(_ref3) {
3137
3455
  };
3138
3456
  }
3139
3457
  }
3458
+ var delay$1 = function delay(ms) {
3459
+ return new Promise(function (resolve) {
3460
+ return setTimeout(resolve, ms);
3461
+ });
3462
+ };
3140
3463
 
3141
3464
  function zodToPropertType(zodType) {
3142
3465
  if (zodType instanceof zod.z.ZodString) {
@@ -3881,11 +4204,11 @@ function runActionsRecursively(_x) {
3881
4204
  }
3882
4205
  function _runActionsRecursively() {
3883
4206
  _runActionsRecursively = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref7) {
3884
- var blueprintActions, frameworkApis, frameworkEvents, dataContext, blueprintId, runId, ctx, blueprintActionKVMap, _loop, _ret, _iterator2, _step2;
4207
+ var blueprintActions, frameworkApis, frameworkEvents, dataContext, blueprintId, runId, ctx, blueprintActionKVMap, logger, _loop, _ret, _iterator2, _step2;
3885
4208
  return _regeneratorRuntime().wrap(function _callee$(_context3) {
3886
4209
  while (1) switch (_context3.prev = _context3.next) {
3887
4210
  case 0:
3888
- blueprintActions = _ref7.blueprintActions, frameworkApis = _ref7.frameworkApis, frameworkEvents = _ref7.frameworkEvents, dataContext = _ref7.dataContext, blueprintId = _ref7.blueprintId, runId = _ref7.runId, ctx = _ref7.ctx, blueprintActionKVMap = _ref7.blueprintActionKVMap;
4211
+ 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;
3889
4212
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
3890
4213
  var _action$subActions;
3891
4214
  var action, concreteAction, hasValidBranch, _loop2, _ret2, _iterator3, _step3, defaultCondition, defaultAction, actionExecutor, _ref9, mastraConnectionId, actionPayload, resolvedPayload, resolvedSchema, data, executorResult, _ctx, subActions;
@@ -3894,9 +4217,15 @@ function _runActionsRecursively() {
3894
4217
  case 0:
3895
4218
  action = _step2.value;
3896
4219
  concreteAction = frameworkApis[action.type];
3897
- console.log('==========', "Running action " + action.type, {
3898
- dataContext: JSON.stringify(dataContext, null, 2)
3899
- }, '=======');
4220
+ logger.info({
4221
+ destinationPath: "" + blueprintId,
4222
+ message: JSON.stringify({
4223
+ message: "Running action " + action.type,
4224
+ metadata: {
4225
+ dataContext: JSON.stringify(dataContext, null, 2)
4226
+ }
4227
+ })
4228
+ });
3900
4229
  // check action conditions
3901
4230
  if (!(action.type === 'CONDITIONS')) {
3902
4231
  _context2.next = 32;
@@ -3973,7 +4302,8 @@ function _runActionsRecursively() {
3973
4302
  blueprintId: blueprintId,
3974
4303
  runId: runId,
3975
4304
  ctx: ctx,
3976
- blueprintActionKVMap: blueprintActionKVMap
4305
+ blueprintActionKVMap: blueprintActionKVMap,
4306
+ logger: logger
3977
4307
  });
3978
4308
  case 22:
3979
4309
  executorResult = _context.sent;
@@ -4020,7 +4350,12 @@ function _runActionsRecursively() {
4020
4350
  _context2.next = 32;
4021
4351
  break;
4022
4352
  }
4023
- console.log('======== No valid branch found for action ============');
4353
+ logger.debug({
4354
+ destinationPath: "" + blueprintId,
4355
+ message: JSON.stringify({
4356
+ message: "No valid branch found for action: " + action.type + ":" + action.id
4357
+ })
4358
+ });
4024
4359
  // run default branch if available
4025
4360
  defaultCondition = action.condition.find(function (c) {
4026
4361
  return c.isDefault;
@@ -4032,7 +4367,12 @@ function _runActionsRecursively() {
4032
4367
  _context2.next = 30;
4033
4368
  break;
4034
4369
  }
4035
- console.log('========= running default action =============');
4370
+ logger.debug({
4371
+ destinationPath: "" + blueprintId,
4372
+ message: JSON.stringify({
4373
+ message: "Running default action: " + defaultAction.type + ":" + defaultAction.id
4374
+ })
4375
+ });
4036
4376
  _context2.next = 26;
4037
4377
  return runActionsRecursively({
4038
4378
  blueprintActions: [defaultAction],
@@ -4042,7 +4382,8 @@ function _runActionsRecursively() {
4042
4382
  runId: runId,
4043
4383
  ctx: ctx,
4044
4384
  blueprintId: blueprintId,
4045
- blueprintActionKVMap: blueprintActionKVMap
4385
+ blueprintActionKVMap: blueprintActionKVMap,
4386
+ logger: logger
4046
4387
  });
4047
4388
  case 26:
4048
4389
  _context2.t1 = _context2.sent;
@@ -4050,7 +4391,12 @@ function _runActionsRecursively() {
4050
4391
  v: _context2.t1
4051
4392
  });
4052
4393
  case 30:
4053
- console.log('========= No default branch found =============');
4394
+ logger.debug({
4395
+ destinationPath: "" + blueprintId,
4396
+ message: JSON.stringify({
4397
+ message: "No default action found for action: " + action.type + ":" + action.id
4398
+ })
4399
+ });
4054
4400
  return _context2.abrupt("return", {
4055
4401
  v: false
4056
4402
  });
@@ -4060,7 +4406,12 @@ function _runActionsRecursively() {
4060
4406
  _context2.next = 36;
4061
4407
  break;
4062
4408
  }
4063
- console.log("No executor found for " + action.type);
4409
+ logger.debug({
4410
+ destinationPath: "" + blueprintId,
4411
+ message: JSON.stringify({
4412
+ message: "No executor found for " + action.type + ":" + action.id
4413
+ })
4414
+ });
4064
4415
  return _context2.abrupt("return", 0);
4065
4416
  case 36:
4066
4417
  _ref9 = action.payload || {}, mastraConnectionId = _ref9.mastraConnectionId, actionPayload = _objectWithoutPropertiesLoose(_ref9, _excluded);
@@ -4097,14 +4448,24 @@ function _runActionsRecursively() {
4097
4448
  });
4098
4449
  case 49:
4099
4450
  executorResult = _context2.sent;
4100
- console.log('executed successfully');
4451
+ logger.info({
4452
+ destinationPath: "" + blueprintId,
4453
+ message: JSON.stringify({
4454
+ message: "Action " + action.type + ":" + action.id + " completed",
4455
+ result: executorResult
4456
+ })
4457
+ });
4101
4458
  _context2.next = 57;
4102
4459
  break;
4103
4460
  case 53:
4104
4461
  _context2.prev = 53;
4105
4462
  _context2.t2 = _context2["catch"](46);
4106
- console.log('===Error executing action===', {
4107
- e: _context2.t2
4463
+ logger.error({
4464
+ destinationPath: "" + blueprintId,
4465
+ message: JSON.stringify({
4466
+ message: "Action " + action.type + ":" + action.id + " failed",
4467
+ error: _context2.t2
4468
+ })
4108
4469
  });
4109
4470
  // TODO: Update workflows runs for failed actions
4110
4471
  return _context2.abrupt("return", {
@@ -4130,7 +4491,8 @@ function _runActionsRecursively() {
4130
4491
  runId: runId,
4131
4492
  ctx: ctx,
4132
4493
  blueprintId: blueprintId,
4133
- blueprintActionKVMap: blueprintActionKVMap
4494
+ blueprintActionKVMap: blueprintActionKVMap,
4495
+ logger: logger
4134
4496
  });
4135
4497
  case 63:
4136
4498
  _context2.t3 = _context2.sent;
@@ -4182,12 +4544,22 @@ function blueprintRunner(_x2) {
4182
4544
  function _blueprintRunner() {
4183
4545
  _blueprintRunner = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
4184
4546
  var _fullCtx, _blueprint$trigger;
4185
- var ctx, dataCtx, blueprint, frameworkEvents, frameworkApis, fullCtx, triggerCondition, concreteTrigger, resolvedSchema, shouldRunWorkflow, blueprintActionKVMap, ranSuccessfully;
4547
+ var ctx, dataCtx, blueprint, frameworkEvents, frameworkApis, logger, fullCtx, triggerCondition, concreteTrigger, resolvedSchema, shouldRunWorkflow, blueprintActionKVMap, ranSuccessfully;
4186
4548
  return _regeneratorRuntime().wrap(function _callee2$(_context4) {
4187
4549
  while (1) switch (_context4.prev = _context4.next) {
4188
4550
  case 0:
4189
- ctx = _ref8.ctx, dataCtx = _ref8.dataCtx, blueprint = _ref8.blueprint, frameworkEvents = _ref8.frameworkEvents, frameworkApis = _ref8.frameworkApis;
4551
+ ctx = _ref8.ctx, dataCtx = _ref8.dataCtx, blueprint = _ref8.blueprint, frameworkEvents = _ref8.frameworkEvents, frameworkApis = _ref8.frameworkApis, logger = _ref8.logger;
4190
4552
  console.log("Running blueprint " + blueprint.id);
4553
+ logger.info({
4554
+ destinationPath: "" + blueprint.id,
4555
+ message: JSON.stringify({
4556
+ message: 'Started workflow run',
4557
+ metadata: {
4558
+ blueprintId: blueprint.id,
4559
+ trigger: blueprint.trigger
4560
+ }
4561
+ })
4562
+ });
4191
4563
  fullCtx = (_fullCtx = {}, _fullCtx[blueprint.trigger.id] = dataCtx, _fullCtx);
4192
4564
  triggerCondition = blueprint.trigger.condition;
4193
4565
  concreteTrigger = frameworkEvents[blueprint.trigger.type || ''];
@@ -4220,10 +4592,16 @@ function _blueprintRunner() {
4220
4592
  _context4.next = 16;
4221
4593
  break;
4222
4594
  }
4595
+ logger.info({
4596
+ destinationPath: "" + blueprint.id,
4597
+ message: JSON.stringify({
4598
+ message: 'Workflow run skipped'
4599
+ })
4600
+ });
4223
4601
  return _context4.abrupt("return");
4224
4602
  case 16:
4225
4603
  blueprintActionKVMap = constructWorkflowContextBluePrint(blueprint);
4226
- _context4.next = 20;
4604
+ _context4.next = 19;
4227
4605
  return runActionsRecursively({
4228
4606
  blueprintActions: blueprint.actions,
4229
4607
  frameworkApis: frameworkApis,
@@ -4232,21 +4610,27 @@ function _blueprintRunner() {
4232
4610
  dataContext: fullCtx,
4233
4611
  blueprintActionKVMap: blueprintActionKVMap,
4234
4612
  blueprintId: blueprint.id,
4235
- runId: ''
4613
+ runId: '',
4614
+ logger: logger
4236
4615
  });
4237
- case 20:
4616
+ case 19:
4238
4617
  ranSuccessfully = _context4.sent;
4239
- try {
4240
- if (ranSuccessfully) {
4241
- // await automationRunService.updateAutomationRun({
4242
- // runId: blueprintRun?.id || '',
4243
- // blueprintId: blueprint.id,
4244
- // completedAt: new Date(),
4245
- // status: AutomationRunStatus.COMPLETED,
4246
- // });
4247
- }
4248
- } catch (e) {}
4249
- case 22:
4618
+ if (ranSuccessfully) {
4619
+ logger.info({
4620
+ destinationPath: "" + blueprint.id,
4621
+ message: JSON.stringify({
4622
+ message: 'Workflow run completed'
4623
+ })
4624
+ });
4625
+ } else {
4626
+ logger.error({
4627
+ destinationPath: "" + blueprint.id,
4628
+ message: JSON.stringify({
4629
+ message: 'Workflow run failed'
4630
+ })
4631
+ });
4632
+ }
4633
+ case 21:
4250
4634
  case "end":
4251
4635
  return _context4.stop();
4252
4636
  }
@@ -4257,8 +4641,8 @@ function _blueprintRunner() {
4257
4641
 
4258
4642
  function getProjectDir(_ref) {
4259
4643
  var dir = _ref.dir;
4260
- var ARK_APP_DIR = process.env.ARK_APP_DIR || process.cwd();
4261
- return path.join(ARK_APP_DIR, dir);
4644
+ var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
4645
+ return path.join(MASTRA_APP_DIR, dir);
4262
4646
  }
4263
4647
  function listAgentsJson(_ref2) {
4264
4648
  var agentDir = _ref2.agentDir;
@@ -4301,36 +4685,219 @@ function getPineconeConfig(_ref4) {
4301
4685
  var agentBlueprintPath = path.join(agentDirPath, "pinecone.json");
4302
4686
  return getAgentFile(agentBlueprintPath);
4303
4687
  }
4688
+ var retryFn = /*#__PURE__*/function () {
4689
+ var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(operation, _temp) {
4690
+ var _ref6, _ref6$maxAttempts, maxAttempts, _ref6$initialDelay, initialDelay, _ref6$maxDelay, maxDelay, _ref6$factor, factor, _ref6$jitter, jitter, delay, attempt, jitterFactor;
4691
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4692
+ while (1) switch (_context.prev = _context.next) {
4693
+ case 0:
4694
+ _ref6 = _temp === void 0 ? {} : _temp, _ref6$maxAttempts = _ref6.maxAttempts, maxAttempts = _ref6$maxAttempts === void 0 ? 3 : _ref6$maxAttempts, _ref6$initialDelay = _ref6.initialDelay, initialDelay = _ref6$initialDelay === void 0 ? 1000 : _ref6$initialDelay, _ref6$maxDelay = _ref6.maxDelay, maxDelay = _ref6$maxDelay === void 0 ? 10000 : _ref6$maxDelay, _ref6$factor = _ref6.factor, factor = _ref6$factor === void 0 ? 2 : _ref6$factor, _ref6$jitter = _ref6.jitter, jitter = _ref6$jitter === void 0 ? true : _ref6$jitter;
4695
+ delay = initialDelay;
4696
+ attempt = 1;
4697
+ case 3:
4698
+ if (!(attempt <= maxAttempts)) {
4699
+ _context.next = 22;
4700
+ break;
4701
+ }
4702
+ _context.prev = 4;
4703
+ _context.next = 7;
4704
+ return operation();
4705
+ case 7:
4706
+ return _context.abrupt("return", _context.sent);
4707
+ case 10:
4708
+ _context.prev = 10;
4709
+ _context.t0 = _context["catch"](4);
4710
+ if (!(attempt === maxAttempts)) {
4711
+ _context.next = 14;
4712
+ break;
4713
+ }
4714
+ throw _context.t0;
4715
+ case 14:
4716
+ console.warn("Attempt " + attempt + " failed. Retrying in " + delay + "ms...");
4717
+ _context.next = 17;
4718
+ return new Promise(function (resolve) {
4719
+ return setTimeout(resolve, delay);
4720
+ });
4721
+ case 17:
4722
+ // Calculate next delay with exponential backoff
4723
+ delay = Math.min(delay * factor, maxDelay);
4724
+ // Add jitter if enabled
4725
+ if (jitter) {
4726
+ jitterFactor = 0.5 + Math.random();
4727
+ delay = Math.floor(delay * jitterFactor);
4728
+ }
4729
+ case 19:
4730
+ attempt++;
4731
+ _context.next = 3;
4732
+ break;
4733
+ case 22:
4734
+ case "end":
4735
+ return _context.stop();
4736
+ }
4737
+ }, _callee, null, [[4, 10]]);
4738
+ }));
4739
+ return function retryFn(_x, _x2) {
4740
+ return _ref5.apply(this, arguments);
4741
+ };
4742
+ }();
4304
4743
 
4305
4744
  var VectorLayer = /*#__PURE__*/function () {
4306
4745
  function VectorLayer() {
4307
4746
  this.supportedProviders = ['PINECONE'];
4308
- }
4309
- var _proto = VectorLayer.prototype;
4310
- _proto.getPineconeIndexes = /*#__PURE__*/function () {
4311
- var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4312
- var inn;
4747
+ this.fetchPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4748
+ var response, _ref2, indexes;
4313
4749
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4314
4750
  while (1) switch (_context.prev = _context.next) {
4315
4751
  case 0:
4316
4752
  _context.prev = 0;
4317
4753
  _context.next = 3;
4754
+ return fetch('https://api.pinecone.io/indexes', {
4755
+ method: 'GET',
4756
+ headers: {
4757
+ 'Api-Key': process.env.PINECONE_API_KEY,
4758
+ 'X-Pinecone-API-Version': 'unstable'
4759
+ },
4760
+ cache: 'no-store'
4761
+ });
4762
+ case 3:
4763
+ response = _context.sent;
4764
+ _context.next = 6;
4765
+ return response.json();
4766
+ case 6:
4767
+ _context.t0 = _context.sent;
4768
+ if (_context.t0) {
4769
+ _context.next = 9;
4770
+ break;
4771
+ }
4772
+ _context.t0 = {};
4773
+ case 9:
4774
+ _ref2 = _context.t0;
4775
+ indexes = _ref2.indexes;
4776
+ return _context.abrupt("return", indexes);
4777
+ case 14:
4778
+ _context.prev = 14;
4779
+ _context.t1 = _context["catch"](0);
4780
+ console.log('Error fetching indexes using JS fetch====', _context.t1);
4781
+ case 17:
4782
+ case "end":
4783
+ return _context.stop();
4784
+ }
4785
+ }, _callee, null, [[0, 14]]);
4786
+ }));
4787
+ this.fetchPineconedIndexByName = /*#__PURE__*/function () {
4788
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name) {
4789
+ var response, data;
4790
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4791
+ while (1) switch (_context2.prev = _context2.next) {
4792
+ case 0:
4793
+ _context2.prev = 0;
4794
+ _context2.next = 3;
4795
+ return fetch("https://api.pinecone.io/indexes/" + name, {
4796
+ method: 'GET',
4797
+ headers: {
4798
+ 'Api-Key': process.env.PINECONE_API_KEY,
4799
+ 'X-Pinecone-API-Version': 'unstable'
4800
+ },
4801
+ cache: 'no-store'
4802
+ });
4803
+ case 3:
4804
+ response = _context2.sent;
4805
+ _context2.next = 6;
4806
+ return response.json();
4807
+ case 6:
4808
+ _context2.t0 = _context2.sent;
4809
+ if (_context2.t0) {
4810
+ _context2.next = 9;
4811
+ break;
4812
+ }
4813
+ _context2.t0 = {};
4814
+ case 9:
4815
+ data = _context2.t0;
4816
+ return _context2.abrupt("return", data);
4817
+ case 13:
4818
+ _context2.prev = 13;
4819
+ _context2.t1 = _context2["catch"](0);
4820
+ console.log('Error fetching indexes using JS fetch====', _context2.t1);
4821
+ case 16:
4822
+ case "end":
4823
+ return _context2.stop();
4824
+ }
4825
+ }, _callee2, null, [[0, 13]]);
4826
+ }));
4827
+ return function (_x) {
4828
+ return _ref3.apply(this, arguments);
4829
+ };
4830
+ }();
4831
+ this.fetchPineconeIndexStats = /*#__PURE__*/function () {
4832
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(host) {
4833
+ var response, data;
4834
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4835
+ while (1) switch (_context3.prev = _context3.next) {
4836
+ case 0:
4837
+ _context3.prev = 0;
4838
+ _context3.next = 3;
4839
+ return fetch("https://" + host + "/describe_index_stats", {
4840
+ method: 'GET',
4841
+ headers: {
4842
+ 'Api-Key': process.env.PINECONE_API_KEY,
4843
+ 'X-Pinecone-API-Version': '2024-07'
4844
+ },
4845
+ cache: 'no-store'
4846
+ });
4847
+ case 3:
4848
+ response = _context3.sent;
4849
+ _context3.next = 6;
4850
+ return response.json();
4851
+ case 6:
4852
+ _context3.t0 = _context3.sent;
4853
+ if (_context3.t0) {
4854
+ _context3.next = 9;
4855
+ break;
4856
+ }
4857
+ _context3.t0 = {};
4858
+ case 9:
4859
+ data = _context3.t0;
4860
+ return _context3.abrupt("return", data);
4861
+ case 13:
4862
+ _context3.prev = 13;
4863
+ _context3.t1 = _context3["catch"](0);
4864
+ console.log('Error fetching indexes using JS fetch====', _context3.t1);
4865
+ case 16:
4866
+ case "end":
4867
+ return _context3.stop();
4868
+ }
4869
+ }, _callee3, null, [[0, 13]]);
4870
+ }));
4871
+ return function (_x2) {
4872
+ return _ref4.apply(this, arguments);
4873
+ };
4874
+ }();
4875
+ }
4876
+ var _proto = VectorLayer.prototype;
4877
+ _proto.getPineconeIndexes = /*#__PURE__*/function () {
4878
+ var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
4879
+ var inn;
4880
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4881
+ while (1) switch (_context4.prev = _context4.next) {
4882
+ case 0:
4883
+ _context4.prev = 0;
4884
+ _context4.next = 3;
4318
4885
  return this.Pinecone.listIndexes();
4319
4886
  case 3:
4320
- inn = _context.sent;
4887
+ inn = _context4.sent;
4321
4888
  console.log('inn====', {
4322
4889
  inn: inn
4323
4890
  });
4324
- return _context.abrupt("return", inn);
4891
+ return _context4.abrupt("return", inn);
4325
4892
  case 8:
4326
- _context.prev = 8;
4327
- _context.t0 = _context["catch"](0);
4328
- console.log('error getting indexesss====', _context.t0);
4893
+ _context4.prev = 8;
4894
+ _context4.t0 = _context4["catch"](0);
4895
+ console.log('error getting indexesss====', _context4.t0);
4329
4896
  case 11:
4330
4897
  case "end":
4331
- return _context.stop();
4898
+ return _context4.stop();
4332
4899
  }
4333
- }, _callee, this, [[0, 8]]);
4900
+ }, _callee4, this, [[0, 8]]);
4334
4901
  }));
4335
4902
  function getPineconeIndexes() {
4336
4903
  return _getPineconeIndexes.apply(this, arguments);
@@ -4338,13 +4905,13 @@ var VectorLayer = /*#__PURE__*/function () {
4338
4905
  return getPineconeIndexes;
4339
4906
  }();
4340
4907
  _proto.createPineconeIndex = /*#__PURE__*/function () {
4341
- var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
4908
+ var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
4342
4909
  var name;
4343
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4344
- while (1) switch (_context2.prev = _context2.next) {
4910
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4911
+ while (1) switch (_context5.prev = _context5.next) {
4345
4912
  case 0:
4346
- name = _ref.name;
4347
- return _context2.abrupt("return", this.Pinecone.createIndex({
4913
+ name = _ref5.name;
4914
+ return _context5.abrupt("return", this.Pinecone.createIndex({
4348
4915
  suppressConflicts: true,
4349
4916
  name: name,
4350
4917
  dimension: 1536,
@@ -4358,129 +4925,129 @@ var VectorLayer = /*#__PURE__*/function () {
4358
4925
  }));
4359
4926
  case 2:
4360
4927
  case "end":
4361
- return _context2.stop();
4928
+ return _context5.stop();
4362
4929
  }
4363
- }, _callee2, this);
4930
+ }, _callee5, this);
4364
4931
  }));
4365
- function createPineconeIndex(_x) {
4932
+ function createPineconeIndex(_x3) {
4366
4933
  return _createPineconeIndex.apply(this, arguments);
4367
4934
  }
4368
4935
  return createPineconeIndex;
4369
4936
  }();
4370
4937
  _proto.getPineconeIndex = /*#__PURE__*/function () {
4371
- var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
4938
+ var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6) {
4372
4939
  var name;
4373
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4374
- while (1) switch (_context3.prev = _context3.next) {
4940
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4941
+ while (1) switch (_context6.prev = _context6.next) {
4375
4942
  case 0:
4376
- name = _ref2.name;
4377
- return _context3.abrupt("return", this.Pinecone.index(name));
4943
+ name = _ref6.name;
4944
+ return _context6.abrupt("return", this.Pinecone.index(name));
4378
4945
  case 2:
4379
4946
  case "end":
4380
- return _context3.stop();
4947
+ return _context6.stop();
4381
4948
  }
4382
- }, _callee3, this);
4949
+ }, _callee6, this);
4383
4950
  }));
4384
- function getPineconeIndex(_x2) {
4951
+ function getPineconeIndex(_x4) {
4385
4952
  return _getPineconeIndex.apply(this, arguments);
4386
4953
  }
4387
4954
  return getPineconeIndex;
4388
4955
  }();
4389
4956
  _proto.generateVectorEmbedding = /*#__PURE__*/function () {
4390
- var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(data) {
4957
+ var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(data) {
4391
4958
  var _yield$embed, embedding;
4392
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4393
- while (1) switch (_context4.prev = _context4.next) {
4959
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4960
+ while (1) switch (_context7.prev = _context7.next) {
4394
4961
  case 0:
4395
- _context4.next = 2;
4962
+ _context7.next = 2;
4396
4963
  return ai.embed({
4397
4964
  model: openai.openai.embedding('text-embedding-3-small'),
4398
4965
  value: JSON.stringify(data)
4399
4966
  });
4400
4967
  case 2:
4401
- _yield$embed = _context4.sent;
4968
+ _yield$embed = _context7.sent;
4402
4969
  embedding = _yield$embed.embedding;
4403
- return _context4.abrupt("return", embedding);
4970
+ return _context7.abrupt("return", embedding);
4404
4971
  case 5:
4405
4972
  case "end":
4406
- return _context4.stop();
4973
+ return _context7.stop();
4407
4974
  }
4408
- }, _callee4);
4975
+ }, _callee7);
4409
4976
  }));
4410
- function generateVectorEmbedding(_x3) {
4977
+ function generateVectorEmbedding(_x5) {
4411
4978
  return _generateVectorEmbedding.apply(this, arguments);
4412
4979
  }
4413
4980
  return generateVectorEmbedding;
4414
4981
  }();
4415
4982
  _proto.getPineconeIndexWithMetadata = /*#__PURE__*/function () {
4416
- var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref3) {
4983
+ var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
4417
4984
  var name, newIndex, indexQuery, namespaces, data, _iterator, _step, _namespaceData$record, namespace, namespaceData, metadata;
4418
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4419
- while (1) switch (_context5.prev = _context5.next) {
4985
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
4986
+ while (1) switch (_context8.prev = _context8.next) {
4420
4987
  case 0:
4421
- name = _ref3.name;
4422
- _context5.prev = 1;
4988
+ name = _ref7.name;
4989
+ _context8.prev = 1;
4423
4990
  if (name) {
4424
- _context5.next = 5;
4991
+ _context8.next = 5;
4425
4992
  break;
4426
4993
  }
4427
4994
  console.log('Index name not passed');
4428
- return _context5.abrupt("return", []);
4995
+ return _context8.abrupt("return", []);
4429
4996
  case 5:
4430
- _context5.next = 7;
4997
+ _context8.next = 7;
4431
4998
  return this.getPineconeIndex({
4432
4999
  name: name
4433
5000
  });
4434
5001
  case 7:
4435
- newIndex = _context5.sent;
4436
- _context5.next = 10;
5002
+ newIndex = _context8.sent;
5003
+ _context8.next = 10;
4437
5004
  return newIndex == null ? void 0 : newIndex.describeIndexStats();
4438
5005
  case 10:
4439
- indexQuery = _context5.sent;
5006
+ indexQuery = _context8.sent;
4440
5007
  if (!indexQuery) {
4441
- _context5.next = 27;
5008
+ _context8.next = 27;
4442
5009
  break;
4443
5010
  }
4444
5011
  namespaces = Object.keys((indexQuery == null ? void 0 : indexQuery.namespaces) || {});
4445
5012
  data = [];
4446
5013
  if (!namespaces.length) {
4447
- _context5.next = 26;
5014
+ _context8.next = 26;
4448
5015
  break;
4449
5016
  }
4450
5017
  _iterator = _createForOfIteratorHelperLoose(namespaces);
4451
5018
  case 16:
4452
5019
  if ((_step = _iterator()).done) {
4453
- _context5.next = 26;
5020
+ _context8.next = 26;
4454
5021
  break;
4455
5022
  }
4456
5023
  namespace = _step.value;
4457
- _context5.next = 20;
5024
+ _context8.next = 20;
4458
5025
  return newIndex == null ? void 0 : newIndex.namespace(namespace).fetch([name]);
4459
5026
  case 20:
4460
- namespaceData = _context5.sent;
5027
+ namespaceData = _context8.sent;
4461
5028
  metadata = namespaceData == null || (_namespaceData$record = namespaceData.records) == null || (_namespaceData$record = _namespaceData$record[name]) == null ? void 0 : _namespaceData$record.metadata;
4462
5029
  console.log("metadata for " + namespace + "===", JSON.stringify(metadata, null, 2));
4463
5030
  if (metadata) {
4464
5031
  data.push(metadata);
4465
5032
  }
4466
5033
  case 24:
4467
- _context5.next = 16;
5034
+ _context8.next = 16;
4468
5035
  break;
4469
5036
  case 26:
4470
- return _context5.abrupt("return", data);
5037
+ return _context8.abrupt("return", data);
4471
5038
  case 27:
4472
- return _context5.abrupt("return", []);
5039
+ return _context8.abrupt("return", []);
4473
5040
  case 30:
4474
- _context5.prev = 30;
4475
- _context5.t0 = _context5["catch"](1);
4476
- console.log("Error getting " + name + " index", _context5.t0);
5041
+ _context8.prev = 30;
5042
+ _context8.t0 = _context8["catch"](1);
5043
+ console.log("Error getting " + name + " index", _context8.t0);
4477
5044
  case 33:
4478
5045
  case "end":
4479
- return _context5.stop();
5046
+ return _context8.stop();
4480
5047
  }
4481
- }, _callee5, this, [[1, 30]]);
5048
+ }, _callee8, this, [[1, 30]]);
4482
5049
  }));
4483
- function getPineconeIndexWithMetadata(_x4) {
5050
+ function getPineconeIndexWithMetadata(_x6) {
4484
5051
  return _getPineconeIndexWithMetadata.apply(this, arguments);
4485
5052
  }
4486
5053
  return getPineconeIndexWithMetadata;
@@ -4499,1075 +5066,608 @@ var VectorLayer = /*#__PURE__*/function () {
4499
5066
  }();
4500
5067
 
4501
5068
  function getVectorProvider(provider) {
4502
- if (provider === 'pinecone') {
5069
+ if (provider.toUpperCase() === 'PINECONE') {
4503
5070
  var _VectorLayer = new VectorLayer(),
4504
5071
  Pinecone = _VectorLayer.Pinecone;
4505
5072
  return Pinecone;
4506
5073
  }
4507
5074
  }
4508
- var delay$1 = function delay(ms) {
4509
- return new Promise(function (resolve) {
4510
- return setTimeout(resolve, ms);
4511
- });
4512
- };
4513
- function executeIndexSync(_x) {
4514
- return _executeIndexSync.apply(this, arguments);
4515
- }
4516
- //Generic vector sync from event data
4517
- function _executeIndexSync() {
4518
- _executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref) {
4519
- var _event$user, _event$data;
4520
- var event, mastra, connectionId, providedIndexes, systemName, _iterator2, _step2, _step2$value, provider, indexes, vp, _iterator3, _step3, index, indexMetadata, _loop2, _ret, _iterator4, _step4;
4521
- return _regeneratorRuntime().wrap(function _callee7$(_context8) {
4522
- while (1) switch (_context8.prev = _context8.next) {
5075
+ // base index sync from knowledge source
5076
+ var indexSync = /*#__PURE__*/function () {
5077
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
5078
+ var knowledgeSource, mastra, connectionId, _iterator, _step, _step$value, provider, indexes, vp, _loop, _ret, _iterator2, _step2;
5079
+ return _regeneratorRuntime().wrap(function _callee3$(_context5) {
5080
+ while (1) switch (_context5.prev = _context5.next) {
4523
5081
  case 0:
4524
- event = _ref.event, mastra = _ref.mastra;
4525
- connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
4526
- providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
4527
- systemName = mastra.config.name;
4528
- _iterator2 = _createForOfIteratorHelperLoose(providedIndexes);
4529
- case 5:
4530
- if ((_step2 = _iterator2()).done) {
4531
- _context8.next = 36;
5082
+ knowledgeSource = _ref.knowledgeSource, mastra = _ref.mastra, connectionId = _ref.connectionId;
5083
+ _iterator = _createForOfIteratorHelperLoose(knowledgeSource);
5084
+ case 2:
5085
+ if ((_step = _iterator()).done) {
5086
+ _context5.next = 22;
4532
5087
  break;
4533
5088
  }
4534
- _step2$value = _step2.value, provider = _step2$value.provider, indexes = _step2$value.indexes;
5089
+ _step$value = _step.value, provider = _step$value.provider, indexes = _step$value.indexes;
4535
5090
  vp = getVectorProvider(provider);
4536
5091
  if (vp) {
4537
- _context8.next = 11;
5092
+ _context5.next = 8;
4538
5093
  break;
4539
5094
  }
4540
5095
  console.error('UNSUPPORTED VECTOR PROVIDER', provider);
4541
- return _context8.abrupt("return");
4542
- case 11:
5096
+ return _context5.abrupt("return");
5097
+ case 8:
4543
5098
  if (process.env.OPENAI_API_KEY) {
4544
- _context8.next = 14;
5099
+ _context5.next = 11;
4545
5100
  break;
4546
5101
  }
4547
5102
  console.error('NO OPENAI_API_KEY');
4548
- return _context8.abrupt("return");
4549
- case 14:
4550
- _iterator3 = _createForOfIteratorHelperLoose(indexes);
4551
- case 15:
4552
- if ((_step3 = _iterator3()).done) {
4553
- _context8.next = 34;
4554
- break;
4555
- }
4556
- index = _step3.value;
4557
- _context8.next = 19;
4558
- return mastra.vectorLayer.getPineconeIndexWithMetadata({
4559
- name: index
4560
- });
4561
- case 19:
4562
- indexMetadata = _context8.sent;
4563
- if (indexMetadata != null && indexMetadata.length) {
4564
- _context8.next = 23;
4565
- break;
4566
- }
4567
- console.error('No index metadata found for', index);
4568
- return _context8.abrupt("return");
4569
- case 23:
4570
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
4571
- var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
4572
- var entity, fields, integration, name, syncEvent, k_id, _mastra$dataLayer2, connection, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, _yield$mastra$trigger, _event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
4573
- return _regeneratorRuntime().wrap(function _loop2$(_context7) {
4574
- while (1) switch (_context7.prev = _context7.next) {
5103
+ return _context5.abrupt("return");
5104
+ case 11:
5105
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
5106
+ var index, getPineconeIndexWithMetadata, indexMetadata, _loop2, _ret2, _iterator3, _step3;
5107
+ return _regeneratorRuntime().wrap(function _loop$(_context4) {
5108
+ while (1) switch (_context4.prev = _context4.next) {
4575
5109
  case 0:
4576
- entity = _step4.value;
4577
- fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
4578
- _context7.next = 4;
4579
- return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
4580
- connectionId: connectionId,
4581
- name: integration
4582
- });
5110
+ index = _step2.value;
5111
+ getPineconeIndexWithMetadata = /*#__PURE__*/function () {
5112
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
5113
+ var res;
5114
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
5115
+ while (1) switch (_context.prev = _context.next) {
5116
+ case 0:
5117
+ _context.prev = 0;
5118
+ _context.next = 3;
5119
+ return mastra.vectorLayer.getPineconeIndexWithMetadata({
5120
+ name: index
5121
+ });
5122
+ case 3:
5123
+ res = _context.sent;
5124
+ if (res != null && res.length) {
5125
+ _context.next = 6;
5126
+ break;
5127
+ }
5128
+ throw new Error('No index metadata found');
5129
+ case 6:
5130
+ return _context.abrupt("return", res);
5131
+ case 9:
5132
+ _context.prev = 9;
5133
+ _context.t0 = _context["catch"](0);
5134
+ throw new Error(_context.t0);
5135
+ case 12:
5136
+ case "end":
5137
+ return _context.stop();
5138
+ }
5139
+ }, _callee, null, [[0, 9]]);
5140
+ }));
5141
+ return function getPineconeIndexWithMetadata() {
5142
+ return _ref3.apply(this, arguments);
5143
+ };
5144
+ }();
5145
+ _context4.next = 4;
5146
+ return retryFn(getPineconeIndexWithMetadata);
4583
5147
  case 4:
4584
- _context7.t1 = _yield$mastra$dataLay = _context7.sent;
4585
- if (!(_context7.t1 == null)) {
4586
- _context7.next = 9;
4587
- break;
4588
- }
4589
- _context7.t2 = void 0;
4590
- _context7.next = 10;
4591
- break;
4592
- case 9:
4593
- _context7.t2 = _yield$mastra$dataLay.id;
4594
- case 10:
4595
- _context7.t0 = _context7.t2;
4596
- if (_context7.t0) {
4597
- _context7.next = 13;
4598
- break;
4599
- }
4600
- _context7.t0 = '';
4601
- case 13:
4602
- k_id = _context7.t0;
4603
- if (!(!k_id && integration === systemName)) {
4604
- _context7.next = 19;
4605
- break;
4606
- }
4607
- _context7.next = 17;
4608
- return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
4609
- connection: {
4610
- connectionId: connectionId,
4611
- name: integration
4612
- },
4613
- credential: {
4614
- type: 'API_KEY',
4615
- value: connectionId,
4616
- scope: []
4617
- }
4618
- });
4619
- case 17:
4620
- connection = _context7.sent;
4621
- k_id = connection.id;
4622
- case 19:
4623
- if (k_id) {
4624
- _context7.next = 22;
5148
+ indexMetadata = _context4.sent;
5149
+ if (indexMetadata != null && indexMetadata.length) {
5150
+ _context4.next = 8;
4625
5151
  break;
4626
5152
  }
4627
- console.error('Error bootstrapping shit');
4628
- return _context7.abrupt("return", {
5153
+ console.error('No index metadata found for', index);
5154
+ return _context4.abrupt("return", {
4629
5155
  v: void 0
4630
5156
  });
4631
- case 22:
4632
- _context7.next = 24;
4633
- return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
4634
- k_id: k_id,
4635
- type: name
4636
- });
4637
- case 24:
4638
- entityRecords = _context7.sent;
4639
- records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
4640
- if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
4641
- _context7.next = 44;
4642
- break;
4643
- }
4644
- console.error('NO RECORDS ATTEMPTING SYNC');
4645
- _context7.next = 30;
4646
- return mastra.triggerEvent({
4647
- key: syncEvent,
4648
- data: {},
4649
- user: {
4650
- connectionId: connectionId
4651
- }
4652
- });
4653
- case 30:
4654
- _yield$mastra$trigger = _context7.sent;
4655
- _event = _yield$mastra$trigger.event;
4656
- console.log(_event, '####');
4657
- _context7.next = 35;
4658
- return _event.subscribe();
4659
- case 35:
4660
- res = _context7.sent;
4661
- console.log('Subscribe result', res);
4662
- _context7.next = 39;
4663
- return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
4664
- k_id: k_id,
4665
- type: entity.name
5157
+ case 8:
5158
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
5159
+ var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
5160
+ var entity, fields, integration, name, syncEvent, syncParams, k_id, _mastra$dataLayer2, connection, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, data, _yield$mastra$trigger, event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
5161
+ return _regeneratorRuntime().wrap(function _loop2$(_context3) {
5162
+ while (1) switch (_context3.prev = _context3.next) {
5163
+ case 0:
5164
+ entity = _step3.value;
5165
+ fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent, syncParams = entity.syncParams;
5166
+ _context3.next = 4;
5167
+ return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
5168
+ connectionId: connectionId,
5169
+ name: integration
5170
+ });
5171
+ case 4:
5172
+ _context3.t1 = _yield$mastra$dataLay = _context3.sent;
5173
+ if (!(_context3.t1 == null)) {
5174
+ _context3.next = 9;
5175
+ break;
5176
+ }
5177
+ _context3.t2 = void 0;
5178
+ _context3.next = 10;
5179
+ break;
5180
+ case 9:
5181
+ _context3.t2 = _yield$mastra$dataLay.id;
5182
+ case 10:
5183
+ _context3.t0 = _context3.t2;
5184
+ if (_context3.t0) {
5185
+ _context3.next = 13;
5186
+ break;
5187
+ }
5188
+ _context3.t0 = '';
5189
+ case 13:
5190
+ k_id = _context3.t0;
5191
+ if (!(!k_id && integration === mastra.config.name)) {
5192
+ _context3.next = 19;
5193
+ break;
5194
+ }
5195
+ _context3.next = 17;
5196
+ return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
5197
+ connection: {
5198
+ connectionId: connectionId,
5199
+ name: integration
5200
+ },
5201
+ credential: {
5202
+ type: 'API_KEY',
5203
+ value: connectionId,
5204
+ scope: []
5205
+ }
5206
+ });
5207
+ case 17:
5208
+ connection = _context3.sent;
5209
+ k_id = connection.id;
5210
+ case 19:
5211
+ if (k_id) {
5212
+ _context3.next = 22;
5213
+ break;
5214
+ }
5215
+ console.error('Error bootstrapping shit');
5216
+ return _context3.abrupt("return", {
5217
+ v: {
5218
+ v: void 0
5219
+ }
5220
+ });
5221
+ case 22:
5222
+ _context3.next = 24;
5223
+ return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
5224
+ k_id: k_id,
5225
+ type: name.toUpperCase()
5226
+ });
5227
+ case 24:
5228
+ entityRecords = _context3.sent;
5229
+ records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
5230
+ if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
5231
+ _context3.next = 46;
5232
+ break;
5233
+ }
5234
+ console.error('NO RECORDS ATTEMPTING SYNC');
5235
+ data = JSON.parse(Buffer.from(syncParams, 'base64').toString());
5236
+ console.log('sync data====', {
5237
+ data: data
5238
+ });
5239
+ _context3.next = 32;
5240
+ return mastra.triggerEvent({
5241
+ key: syncEvent,
5242
+ data: data,
5243
+ user: {
5244
+ connectionId: connectionId
5245
+ }
5246
+ });
5247
+ case 32:
5248
+ _yield$mastra$trigger = _context3.sent;
5249
+ event = _yield$mastra$trigger.event;
5250
+ console.log(event, '####');
5251
+ _context3.next = 37;
5252
+ return event.subscribe();
5253
+ case 37:
5254
+ res = _context3.sent;
5255
+ console.log('Subscribe result', res);
5256
+ _context3.next = 41;
5257
+ return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
5258
+ k_id: k_id,
5259
+ type: entity.name.toUpperCase()
5260
+ });
5261
+ case 41:
5262
+ entityRecords = _context3.sent;
5263
+ records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
5264
+ if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
5265
+ _context3.next = 46;
5266
+ break;
5267
+ }
5268
+ console.error('NO RECORDS AFTER SYNC');
5269
+ return _context3.abrupt("return", {
5270
+ v: {
5271
+ v: void 0
5272
+ }
5273
+ });
5274
+ case 46:
5275
+ recordsMapped = records.map(function (_ref4) {
5276
+ var data = _ref4.data,
5277
+ externalId = _ref4.externalId;
5278
+ var pickedData = _.pick(data, fields);
5279
+ var stringifiedData = _.mapValues(pickedData, String);
5280
+ return _extends({
5281
+ id: String(externalId)
5282
+ }, stringifiedData);
5283
+ });
5284
+ console.log(recordsMapped, 'RECORDS');
5285
+ entityTypeIndex = vp.index(index);
5286
+ console.log(entityTypeIndex, 'INDEX');
5287
+ _context3.prev = 50;
5288
+ _context3.next = 53;
5289
+ return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
5290
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(record) {
5291
+ var _yield$embed, embedding;
5292
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
5293
+ while (1) switch (_context2.prev = _context2.next) {
5294
+ case 0:
5295
+ _context2.next = 2;
5296
+ return ai.embed({
5297
+ model: openai.openai.embedding('text-embedding-3-small'),
5298
+ value: JSON.stringify(record)
5299
+ });
5300
+ case 2:
5301
+ _yield$embed = _context2.sent;
5302
+ embedding = _yield$embed.embedding;
5303
+ return _context2.abrupt("return", {
5304
+ id: record.id,
5305
+ values: embedding,
5306
+ metadata: record
5307
+ });
5308
+ case 5:
5309
+ case "end":
5310
+ return _context2.stop();
5311
+ }
5312
+ }, _callee2);
5313
+ }));
5314
+ return function (_x2) {
5315
+ return _ref5.apply(this, arguments);
5316
+ };
5317
+ }())) != null ? _recordsMapped$map : []);
5318
+ case 53:
5319
+ vectors = _context3.sent;
5320
+ console.log('UPSERTING', vectors);
5321
+ if (!(vectors.length > 0)) {
5322
+ _context3.next = 58;
5323
+ break;
5324
+ }
5325
+ _context3.next = 58;
5326
+ return entityTypeIndex.namespace(name).upsert(vectors);
5327
+ case 58:
5328
+ _context3.next = 63;
5329
+ break;
5330
+ case 60:
5331
+ _context3.prev = 60;
5332
+ _context3.t3 = _context3["catch"](50);
5333
+ console.error(_context3.t3);
5334
+ case 63:
5335
+ return _context3.abrupt("return", {
5336
+ v: {
5337
+ v: void 0
5338
+ }
5339
+ });
5340
+ case 64:
5341
+ case "end":
5342
+ return _context3.stop();
5343
+ }
5344
+ }, _loop2, null, [[50, 60]]);
4666
5345
  });
4667
- case 39:
4668
- entityRecords = _context7.sent;
4669
- records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
4670
- if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
4671
- _context7.next = 44;
5346
+ _iterator3 = _createForOfIteratorHelperLoose(indexMetadata);
5347
+ case 10:
5348
+ if ((_step3 = _iterator3()).done) {
5349
+ _context4.next = 17;
4672
5350
  break;
4673
5351
  }
4674
- console.error('NO RECORDS AFTER SYNC');
4675
- return _context7.abrupt("return", {
4676
- v: void 0
4677
- });
4678
- case 44:
4679
- recordsMapped = records.map(function (_ref12) {
4680
- var data = _ref12.data,
4681
- externalId = _ref12.externalId;
4682
- return _extends({
4683
- id: externalId
4684
- }, _.pick(data, fields));
4685
- });
4686
- console.log(recordsMapped, 'RECORDS');
4687
- entityTypeIndex = vp.index(index);
4688
- console.log(entityTypeIndex, 'INDEX');
4689
- _context7.prev = 48;
4690
- _context7.next = 51;
4691
- return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
4692
- var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(record) {
4693
- var _yield$embed, embedding;
4694
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4695
- while (1) switch (_context6.prev = _context6.next) {
4696
- case 0:
4697
- _context6.next = 2;
4698
- return ai.embed({
4699
- model: openai.openai.embedding('text-embedding-3-small'),
4700
- value: JSON.stringify(record)
4701
- });
4702
- case 2:
4703
- _yield$embed = _context6.sent;
4704
- embedding = _yield$embed.embedding;
4705
- return _context6.abrupt("return", {
4706
- id: record.id,
4707
- values: embedding,
4708
- metadata: record
4709
- });
4710
- case 5:
4711
- case "end":
4712
- return _context6.stop();
4713
- }
4714
- }, _callee6);
4715
- }));
4716
- return function (_x8) {
4717
- return _ref13.apply(this, arguments);
4718
- };
4719
- }())) != null ? _recordsMapped$map : []);
4720
- case 51:
4721
- vectors = _context7.sent;
4722
- console.log('UPSERTING', vectors);
4723
- if (!(vectors.length > 0)) {
4724
- _context7.next = 56;
5352
+ return _context4.delegateYield(_loop2(), "t0", 12);
5353
+ case 12:
5354
+ _ret2 = _context4.t0;
5355
+ if (!_ret2) {
5356
+ _context4.next = 15;
4725
5357
  break;
4726
5358
  }
4727
- _context7.next = 56;
4728
- return entityTypeIndex.namespace(name).upsert(vectors);
4729
- case 56:
4730
- _context7.next = 61;
5359
+ return _context4.abrupt("return", _ret2.v);
5360
+ case 15:
5361
+ _context4.next = 10;
4731
5362
  break;
4732
- case 58:
4733
- _context7.prev = 58;
4734
- _context7.t3 = _context7["catch"](48);
4735
- console.error(_context7.t3);
4736
- case 61:
4737
- return _context7.abrupt("return", {
4738
- v: void 0
4739
- });
4740
- case 62:
5363
+ case 17:
4741
5364
  case "end":
4742
- return _context7.stop();
5365
+ return _context4.stop();
4743
5366
  }
4744
- }, _loop2, null, [[48, 58]]);
5367
+ }, _loop);
4745
5368
  });
4746
- _iterator4 = _createForOfIteratorHelperLoose(indexMetadata);
4747
- case 25:
4748
- if ((_step4 = _iterator4()).done) {
4749
- _context8.next = 32;
5369
+ _iterator2 = _createForOfIteratorHelperLoose(indexes);
5370
+ case 13:
5371
+ if ((_step2 = _iterator2()).done) {
5372
+ _context5.next = 20;
4750
5373
  break;
4751
5374
  }
4752
- return _context8.delegateYield(_loop2(), "t0", 27);
4753
- case 27:
4754
- _ret = _context8.t0;
5375
+ return _context5.delegateYield(_loop(), "t0", 15);
5376
+ case 15:
5377
+ _ret = _context5.t0;
4755
5378
  if (!_ret) {
4756
- _context8.next = 30;
5379
+ _context5.next = 18;
4757
5380
  break;
4758
5381
  }
4759
- return _context8.abrupt("return", _ret.v);
4760
- case 30:
4761
- _context8.next = 25;
4762
- break;
4763
- case 32:
4764
- _context8.next = 15;
5382
+ return _context5.abrupt("return", _ret.v);
5383
+ case 18:
5384
+ _context5.next = 13;
4765
5385
  break;
4766
- case 34:
4767
- _context8.next = 5;
5386
+ case 20:
5387
+ _context5.next = 2;
4768
5388
  break;
4769
- case 36:
5389
+ case 22:
5390
+ case "end":
5391
+ return _context5.stop();
5392
+ }
5393
+ }, _callee3);
5394
+ }));
5395
+ return function indexSync(_x) {
5396
+ return _ref2.apply(this, arguments);
5397
+ };
5398
+ }();
5399
+ // vector index sync
5400
+ function executeIndexSync(_x3) {
5401
+ return _executeIndexSync.apply(this, arguments);
5402
+ }
5403
+ //Generic vector sync from event data
5404
+ function _executeIndexSync() {
5405
+ _executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref6) {
5406
+ var _event$user, _event$data;
5407
+ var event, mastra, connectionId, providedIndexes;
5408
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
5409
+ while (1) switch (_context9.prev = _context9.next) {
5410
+ case 0:
5411
+ event = _ref6.event, mastra = _ref6.mastra;
5412
+ connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
5413
+ providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
5414
+ _context9.next = 5;
5415
+ return indexSync({
5416
+ connectionId: connectionId,
5417
+ knowledgeSource: providedIndexes,
5418
+ mastra: mastra
5419
+ });
5420
+ case 5:
5421
+ return _context9.abrupt("return", _context9.sent);
5422
+ case 6:
4770
5423
  case "end":
4771
- return _context8.stop();
5424
+ return _context9.stop();
4772
5425
  }
4773
5426
  }, _callee7);
4774
5427
  }));
4775
5428
  return _executeIndexSync.apply(this, arguments);
4776
5429
  }
4777
- function executeGenericVectorSync(_x2) {
5430
+ function executeGenericVectorSync(_x4) {
4778
5431
  return _executeGenericVectorSync.apply(this, arguments);
4779
5432
  }
4780
5433
  // Vector Sync from agents Dir
4781
5434
  function _executeGenericVectorSync() {
4782
- _executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref2) {
4783
- var _event$user2, _event$data2, _event$data3;
4784
- var event, mastra, connectionId, vector_provider, entities, systemName, vp, _iterator5, _step5, _yield$mastra$dataLay2, _mastra$dataLayer5, vectorE, integrationName, k_id, _mastra$dataLayer6, connection, _loop3, _ret2, _iterator6, _step6;
4785
- return _regeneratorRuntime().wrap(function _callee9$(_context11) {
4786
- while (1) switch (_context11.prev = _context11.next) {
5435
+ _executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
5436
+ var _event$user2, _event$data2;
5437
+ var event, mastra, connectionId, entities;
5438
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
5439
+ while (1) switch (_context10.prev = _context10.next) {
4787
5440
  case 0:
4788
- event = _ref2.event, mastra = _ref2.mastra;
5441
+ event = _ref7.event, mastra = _ref7.mastra;
4789
5442
  connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
4790
- vector_provider = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.vector_provider;
4791
- entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
4792
- systemName = mastra.config.name;
4793
- if (vector_provider) {
4794
- _context11.next = 8;
4795
- break;
4796
- }
4797
- console.error("No vector_provider defined for agent");
4798
- return _context11.abrupt("return");
4799
- case 8:
4800
- vp = getVectorProvider(vector_provider);
4801
- if (vp) {
4802
- _context11.next = 12;
4803
- break;
4804
- }
4805
- console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
4806
- return _context11.abrupt("return");
4807
- case 12:
4808
- if (process.env.OPENAI_API_KEY) {
4809
- _context11.next = 15;
4810
- break;
4811
- }
4812
- console.error('NO OPENAI_API_KEY');
4813
- return _context11.abrupt("return");
4814
- case 15:
4815
- _iterator5 = _createForOfIteratorHelperLoose(entities);
4816
- case 16:
4817
- if ((_step5 = _iterator5()).done) {
4818
- _context11.next = 50;
4819
- break;
4820
- }
4821
- vectorE = _step5.value;
4822
- integrationName = vectorE.integration;
4823
- _context11.next = 21;
4824
- return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
5443
+ entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
5444
+ _context10.next = 5;
5445
+ return indexSync({
4825
5446
  connectionId: connectionId,
4826
- name: integrationName
5447
+ knowledgeSource: entities,
5448
+ mastra: mastra
4827
5449
  });
4828
- case 21:
4829
- _context11.t1 = _yield$mastra$dataLay2 = _context11.sent;
4830
- if (!(_context11.t1 == null)) {
4831
- _context11.next = 26;
4832
- break;
4833
- }
4834
- _context11.t2 = void 0;
4835
- _context11.next = 27;
4836
- break;
4837
- case 26:
4838
- _context11.t2 = _yield$mastra$dataLay2.id;
4839
- case 27:
4840
- _context11.t0 = _context11.t2;
4841
- if (_context11.t0) {
4842
- _context11.next = 30;
4843
- break;
4844
- }
4845
- _context11.t0 = '';
4846
- case 30:
4847
- k_id = _context11.t0;
4848
- if (!(!k_id && integrationName === systemName)) {
4849
- _context11.next = 36;
4850
- break;
4851
- }
4852
- _context11.next = 34;
4853
- return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
4854
- connection: {
4855
- connectionId: connectionId,
4856
- name: integrationName
4857
- },
4858
- credential: {
4859
- type: 'API_KEY',
4860
- value: connectionId,
4861
- scope: []
4862
- }
4863
- });
4864
- case 34:
4865
- connection = _context11.sent;
4866
- k_id = connection.id;
4867
- case 36:
4868
- if (k_id) {
4869
- _context11.next = 39;
4870
- break;
4871
- }
4872
- console.error('Error bootstrapping shit');
4873
- return _context11.abrupt("return");
4874
- case 39:
4875
- _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4876
- var _mastra$dataLayer7, _entityRecords3, _records3;
4877
- var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
4878
- return _regeneratorRuntime().wrap(function _loop3$(_context10) {
4879
- while (1) switch (_context10.prev = _context10.next) {
4880
- case 0:
4881
- entity = _step6.value;
4882
- _context10.next = 3;
4883
- return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
4884
- k_id: k_id,
4885
- type: entity.name
4886
- });
4887
- case 3:
4888
- entityRecords = _context10.sent;
4889
- records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
4890
- if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
4891
- _context10.next = 23;
4892
- break;
4893
- }
4894
- // @TODO: SYNC THEM
4895
- console.error('NO RECORDS');
4896
- _context10.next = 9;
4897
- return mastra.triggerEvent({
4898
- key: entity.syncEvent,
4899
- data: {},
4900
- user: {
4901
- connectionId: connectionId
4902
- }
4903
- });
4904
- case 9:
4905
- _yield$mastra$trigger2 = _context10.sent;
4906
- _event2 = _yield$mastra$trigger2.event;
4907
- console.log(_event2, '####');
4908
- _context10.next = 14;
4909
- return _event2.subscribe();
4910
- case 14:
4911
- res = _context10.sent;
4912
- console.log('Subscribe result', res);
4913
- _context10.next = 18;
4914
- return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
4915
- k_id: k_id,
4916
- type: entity.name
4917
- });
4918
- case 18:
4919
- entityRecords = _context10.sent;
4920
- records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
4921
- if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
4922
- _context10.next = 23;
4923
- break;
4924
- }
4925
- console.error('NO RECORDS AFTER SYNC');
4926
- return _context10.abrupt("return", {
4927
- v: void 0
4928
- });
4929
- case 23:
4930
- recordsMapped = records.map(function (_ref14) {
4931
- var data = _ref14.data,
4932
- externalId = _ref14.externalId;
4933
- return _extends({
4934
- id: externalId
4935
- }, _.pick(data, entity.fields));
4936
- });
4937
- console.log(recordsMapped, 'RECORDS');
4938
- _context10.next = 27;
4939
- return vp.createIndex({
4940
- suppressConflicts: true,
4941
- name: entity.name,
4942
- dimension: 1536,
4943
- metric: 'cosine',
4944
- spec: {
4945
- serverless: {
4946
- cloud: 'aws',
4947
- region: 'us-east-1'
4948
- }
4949
- }
4950
- });
4951
- case 27:
4952
- _context10.next = 29;
4953
- return delay$1(5000);
4954
- case 29:
4955
- entityTypeIndex = vp.index(entity.name);
4956
- console.log(entityTypeIndex, 'INDEX');
4957
- _context10.prev = 31;
4958
- _context10.next = 34;
4959
- return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
4960
- var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(record) {
4961
- var _yield$embed2, embedding;
4962
- return _regeneratorRuntime().wrap(function _callee8$(_context9) {
4963
- while (1) switch (_context9.prev = _context9.next) {
4964
- case 0:
4965
- _context9.next = 2;
4966
- return ai.embed({
4967
- model: openai.openai.embedding('text-embedding-3-small'),
4968
- value: JSON.stringify(record)
4969
- });
4970
- case 2:
4971
- _yield$embed2 = _context9.sent;
4972
- embedding = _yield$embed2.embedding;
4973
- return _context9.abrupt("return", {
4974
- id: record.id,
4975
- values: embedding,
4976
- metadata: record
4977
- });
4978
- case 5:
4979
- case "end":
4980
- return _context9.stop();
4981
- }
4982
- }, _callee8);
4983
- }));
4984
- return function (_x9) {
4985
- return _ref15.apply(this, arguments);
4986
- };
4987
- }())) != null ? _recordsMapped$map2 : []);
4988
- case 34:
4989
- vectors = _context10.sent;
4990
- console.log('UPSERTING', vectors);
4991
- if (!(vectors.length > 0)) {
4992
- _context10.next = 39;
4993
- break;
4994
- }
4995
- _context10.next = 39;
4996
- return entityTypeIndex.namespace(entity.name).upsert(vectors);
4997
- case 39:
4998
- _context10.next = 44;
4999
- break;
5000
- case 41:
5001
- _context10.prev = 41;
5002
- _context10.t0 = _context10["catch"](31);
5003
- console.error(_context10.t0);
5004
- case 44:
5005
- return _context10.abrupt("return", {
5006
- v: void 0
5007
- });
5008
- case 45:
5009
- case "end":
5010
- return _context10.stop();
5011
- }
5012
- }, _loop3, null, [[31, 41]]);
5013
- });
5014
- _iterator6 = _createForOfIteratorHelperLoose(vectorE.data);
5015
- case 41:
5016
- if ((_step6 = _iterator6()).done) {
5017
- _context11.next = 48;
5018
- break;
5019
- }
5020
- return _context11.delegateYield(_loop3(), "t3", 43);
5021
- case 43:
5022
- _ret2 = _context11.t3;
5023
- if (!_ret2) {
5024
- _context11.next = 46;
5025
- break;
5026
- }
5027
- return _context11.abrupt("return", _ret2.v);
5028
- case 46:
5029
- _context11.next = 41;
5030
- break;
5031
- case 48:
5032
- _context11.next = 16;
5033
- break;
5034
- case 50:
5450
+ case 5:
5451
+ return _context10.abrupt("return", _context10.sent);
5452
+ case 6:
5035
5453
  case "end":
5036
- return _context11.stop();
5454
+ return _context10.stop();
5037
5455
  }
5038
- }, _callee9);
5456
+ }, _callee8);
5039
5457
  }));
5040
5458
  return _executeGenericVectorSync.apply(this, arguments);
5041
5459
  }
5042
- function executeVectorSync(_x3) {
5460
+ function executeVectorSync(_x5) {
5043
5461
  return _executeVectorSync.apply(this, arguments);
5044
5462
  }
5045
5463
  function _executeVectorSync() {
5046
- _executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref3) {
5047
- var _event$user3, _agent$knowledge_sour;
5048
- var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$knowledge_sour2, _iterator7, _step7, _yield$mastra$dataLay3, _mastra$dataLayer9, vectorE, integrationName, k_id, _mastra$dataLayer10, connection, _loop4, _ret3, _iterator8, _step8;
5049
- return _regeneratorRuntime().wrap(function _callee11$(_context14) {
5050
- while (1) switch (_context14.prev = _context14.next) {
5464
+ _executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref8) {
5465
+ var _event$user3;
5466
+ var event, mastra, agentDir, agent, connectionId;
5467
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
5468
+ while (1) switch (_context11.prev = _context11.next) {
5051
5469
  case 0:
5052
- event = _ref3.event, mastra = _ref3.mastra;
5470
+ event = _ref8.event, mastra = _ref8.mastra;
5053
5471
  agentDir = mastra.config.agents.agentDirPath;
5054
5472
  agent = getAgentBlueprint({
5055
5473
  agentDir: agentDir,
5056
5474
  agentId: event.data.agentId
5057
5475
  });
5058
5476
  connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
5059
- systemName = mastra.config.name;
5060
- if (agent.knowledge_sources.vector_provider) {
5061
- _context14.next = 8;
5062
- break;
5063
- }
5064
- console.error("No vector_provider defined for agent");
5065
- return _context14.abrupt("return");
5066
- case 8:
5067
- vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
5068
- if (vp) {
5069
- _context14.next = 12;
5070
- break;
5071
- }
5072
- console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
5073
- return _context14.abrupt("return");
5074
- case 12:
5075
- if (process.env.OPENAI_API_KEY) {
5076
- _context14.next = 15;
5077
- break;
5078
- }
5079
- console.error('NO OPENAI_API_KEY');
5080
- return _context14.abrupt("return");
5081
- case 15:
5082
- if (!(!agent || !(agent != null && agent.knowledge_sources))) {
5083
- _context14.next = 18;
5084
- break;
5085
- }
5086
- console.error('NO AGENT OR KNOWLEDGE SOURCES');
5087
- return _context14.abrupt("return");
5088
- case 18:
5089
- _iterator7 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
5090
- case 19:
5091
- if ((_step7 = _iterator7()).done) {
5092
- _context14.next = 53;
5093
- break;
5094
- }
5095
- vectorE = _step7.value;
5096
- integrationName = vectorE.integration;
5097
- _context14.next = 24;
5098
- return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
5477
+ _context11.next = 6;
5478
+ return indexSync({
5099
5479
  connectionId: connectionId,
5100
- name: integrationName
5480
+ knowledgeSource: agent == null ? void 0 : agent.knowledge_sources,
5481
+ mastra: mastra
5101
5482
  });
5102
- case 24:
5103
- _context14.t1 = _yield$mastra$dataLay3 = _context14.sent;
5104
- if (!(_context14.t1 == null)) {
5105
- _context14.next = 29;
5106
- break;
5107
- }
5108
- _context14.t2 = void 0;
5109
- _context14.next = 30;
5110
- break;
5111
- case 29:
5112
- _context14.t2 = _yield$mastra$dataLay3.id;
5113
- case 30:
5114
- _context14.t0 = _context14.t2;
5115
- if (_context14.t0) {
5116
- _context14.next = 33;
5117
- break;
5118
- }
5119
- _context14.t0 = '';
5120
- case 33:
5121
- k_id = _context14.t0;
5122
- if (!(!k_id && integrationName === systemName)) {
5123
- _context14.next = 39;
5124
- break;
5125
- }
5126
- _context14.next = 37;
5127
- return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
5128
- connection: {
5129
- connectionId: connectionId,
5130
- name: integrationName
5131
- },
5132
- credential: {
5133
- type: 'API_KEY',
5134
- value: connectionId,
5135
- scope: []
5136
- }
5137
- });
5138
- case 37:
5139
- connection = _context14.sent;
5140
- k_id = connection.id;
5141
- case 39:
5142
- if (k_id) {
5143
- _context14.next = 42;
5144
- break;
5145
- }
5146
- console.error('Error bootstrapping shit');
5147
- return _context14.abrupt("return");
5148
- case 42:
5149
- _loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
5150
- var _mastra$dataLayer11, _entityRecords5, _records5;
5151
- var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
5152
- return _regeneratorRuntime().wrap(function _loop4$(_context13) {
5153
- while (1) switch (_context13.prev = _context13.next) {
5154
- case 0:
5155
- entity = _step8.value;
5156
- _context13.next = 3;
5157
- return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
5158
- k_id: k_id,
5159
- type: entity.name
5160
- });
5161
- case 3:
5162
- entityRecords = _context13.sent;
5163
- records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
5164
- if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
5165
- _context13.next = 23;
5166
- break;
5167
- }
5168
- // @TODO: SYNC THEM
5169
- console.error('NO RECORDS');
5170
- _context13.next = 9;
5171
- return mastra.triggerEvent({
5172
- key: entity.syncEvent,
5173
- data: {},
5174
- user: {
5175
- connectionId: connectionId
5176
- }
5177
- });
5178
- case 9:
5179
- _yield$mastra$trigger3 = _context13.sent;
5180
- _event3 = _yield$mastra$trigger3.event;
5181
- console.log(_event3, '####');
5182
- _context13.next = 14;
5183
- return _event3.subscribe();
5184
- case 14:
5185
- res = _context13.sent;
5186
- console.log('Subscribe result', res);
5187
- _context13.next = 18;
5188
- return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
5189
- k_id: k_id,
5190
- type: entity.name
5191
- });
5192
- case 18:
5193
- entityRecords = _context13.sent;
5194
- records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
5195
- if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
5196
- _context13.next = 23;
5197
- break;
5198
- }
5199
- console.error('NO RECORDS AFTER SYNC');
5200
- return _context13.abrupt("return", {
5201
- v: void 0
5202
- });
5203
- case 23:
5204
- recordsMapped = records.map(function (_ref16) {
5205
- var data = _ref16.data,
5206
- externalId = _ref16.externalId;
5207
- return _extends({
5208
- id: externalId
5209
- }, _.pick(data, entity.fields));
5210
- });
5211
- console.log(recordsMapped, 'RECORDS');
5212
- _context13.next = 27;
5213
- return vp.createIndex({
5214
- suppressConflicts: true,
5215
- name: entity.name,
5216
- dimension: 1536,
5217
- metric: 'cosine',
5218
- spec: {
5219
- serverless: {
5220
- cloud: 'aws',
5221
- region: 'us-east-1'
5222
- }
5223
- }
5224
- });
5225
- case 27:
5226
- entityTypeIndex = vp.index(entity.name);
5227
- console.log(entityTypeIndex, 'INDEX');
5228
- _context13.prev = 29;
5229
- _context13.next = 32;
5230
- return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
5231
- var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(record) {
5232
- var _yield$embed3, embedding;
5233
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
5234
- while (1) switch (_context12.prev = _context12.next) {
5235
- case 0:
5236
- _context12.next = 2;
5237
- return ai.embed({
5238
- model: openai.openai.embedding('text-embedding-3-small'),
5239
- value: JSON.stringify(record)
5240
- });
5241
- case 2:
5242
- _yield$embed3 = _context12.sent;
5243
- embedding = _yield$embed3.embedding;
5244
- return _context12.abrupt("return", {
5245
- id: record.id,
5246
- values: embedding,
5247
- metadata: record
5248
- });
5249
- case 5:
5250
- case "end":
5251
- return _context12.stop();
5252
- }
5253
- }, _callee10);
5254
- }));
5255
- return function (_x10) {
5256
- return _ref17.apply(this, arguments);
5257
- };
5258
- }())) != null ? _recordsMapped$map3 : []);
5259
- case 32:
5260
- vectors = _context13.sent;
5261
- console.log('UPSERTING', vectors);
5262
- if (!(vectors.length > 0)) {
5263
- _context13.next = 37;
5264
- break;
5265
- }
5266
- _context13.next = 37;
5267
- return entityTypeIndex.namespace(entity.name).upsert(vectors);
5268
- case 37:
5269
- _context13.next = 42;
5270
- break;
5271
- case 39:
5272
- _context13.prev = 39;
5273
- _context13.t0 = _context13["catch"](29);
5274
- console.error(_context13.t0);
5275
- case 42:
5276
- return _context13.abrupt("return", {
5277
- v: void 0
5278
- });
5279
- case 43:
5280
- case "end":
5281
- return _context13.stop();
5282
- }
5283
- }, _loop4, null, [[29, 39]]);
5284
- });
5285
- _iterator8 = _createForOfIteratorHelperLoose(vectorE.data);
5286
- case 44:
5287
- if ((_step8 = _iterator8()).done) {
5288
- _context14.next = 51;
5289
- break;
5290
- }
5291
- return _context14.delegateYield(_loop4(), "t3", 46);
5292
- case 46:
5293
- _ret3 = _context14.t3;
5294
- if (!_ret3) {
5295
- _context14.next = 49;
5296
- break;
5297
- }
5298
- return _context14.abrupt("return", _ret3.v);
5299
- case 49:
5300
- _context14.next = 44;
5301
- break;
5302
- case 51:
5303
- _context14.next = 19;
5304
- break;
5305
- case 53:
5483
+ case 6:
5484
+ return _context11.abrupt("return", _context11.sent);
5485
+ case 7:
5306
5486
  case "end":
5307
- return _context14.stop();
5487
+ return _context11.stop();
5308
5488
  }
5309
- }, _callee11);
5489
+ }, _callee9);
5310
5490
  }));
5311
5491
  return _executeVectorSync.apply(this, arguments);
5312
5492
  }
5313
- function vectorQueryEngine(_x4) {
5493
+ function vectorQueryEngine(_x6) {
5314
5494
  return _vectorQueryEngine.apply(this, arguments);
5315
5495
  }
5316
5496
  function _vectorQueryEngine() {
5317
- _vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref4) {
5318
- var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
5319
- return _regeneratorRuntime().wrap(function _callee12$(_context15) {
5320
- while (1) switch (_context15.prev = _context15.next) {
5497
+ _vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref9) {
5498
+ var vector_provider, _ref9$topK, topK, indexName, content, entityType, vp, index, _yield$embed2, embedding, queryResponse;
5499
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
5500
+ while (1) switch (_context12.prev = _context12.next) {
5321
5501
  case 0:
5322
- vector_provider = _ref4.vector_provider, _ref4$topK = _ref4.topK, topK = _ref4$topK === void 0 ? 1 : _ref4$topK, indexName = _ref4.indexName, content = _ref4.content, entityType = _ref4.entityType;
5502
+ vector_provider = _ref9.vector_provider, _ref9$topK = _ref9.topK, topK = _ref9$topK === void 0 ? 1 : _ref9$topK, indexName = _ref9.indexName, content = _ref9.content, entityType = _ref9.entityType;
5323
5503
  vp = getVectorProvider(vector_provider);
5324
5504
  if (vp) {
5325
- _context15.next = 5;
5505
+ _context12.next = 5;
5326
5506
  break;
5327
5507
  }
5328
5508
  console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
5329
- return _context15.abrupt("return");
5509
+ return _context12.abrupt("return");
5330
5510
  case 5:
5331
5511
  index = vp.index(indexName);
5332
- _context15.next = 8;
5512
+ _context12.next = 8;
5333
5513
  return ai.embed({
5334
5514
  model: openai.openai.embedding('text-embedding-3-small'),
5335
5515
  value: content
5336
5516
  });
5337
5517
  case 8:
5338
- _yield$embed4 = _context15.sent;
5339
- embedding = _yield$embed4.embedding;
5518
+ _yield$embed2 = _context12.sent;
5519
+ embedding = _yield$embed2.embedding;
5340
5520
  console.log(embedding, 'EMBEDDING');
5341
- _context15.next = 13;
5521
+ _context12.next = 13;
5342
5522
  return index.namespace(entityType).query({
5343
5523
  vector: embedding,
5344
5524
  topK: topK,
5345
5525
  includeMetadata: true
5346
5526
  });
5347
5527
  case 13:
5348
- queryResponse = _context15.sent;
5349
- return _context15.abrupt("return", queryResponse);
5528
+ queryResponse = _context12.sent;
5529
+ return _context12.abrupt("return", queryResponse);
5350
5530
  case 15:
5351
5531
  case "end":
5352
- return _context15.stop();
5532
+ return _context12.stop();
5353
5533
  }
5354
- }, _callee12);
5534
+ }, _callee10);
5355
5535
  }));
5356
5536
  return _vectorQueryEngine.apply(this, arguments);
5357
5537
  }
5358
- var fetchPineconeIndexes = /*#__PURE__*/function () {
5359
- var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
5360
- var response, _ref6, indexes;
5361
- return _regeneratorRuntime().wrap(function _callee$(_context) {
5362
- while (1) switch (_context.prev = _context.next) {
5363
- case 0:
5364
- _context.prev = 0;
5365
- _context.next = 3;
5366
- return fetch('https://api.pinecone.io/indexes', {
5367
- method: 'GET',
5368
- headers: {
5369
- 'Api-Key': process.env.PINECONE_API_KEY,
5370
- 'X-Pinecone-API-Version': 'unstable'
5371
- },
5372
- cache: 'no-store'
5373
- });
5374
- case 3:
5375
- response = _context.sent;
5376
- _context.next = 6;
5377
- return response.json();
5378
- case 6:
5379
- _context.t0 = _context.sent;
5380
- if (_context.t0) {
5381
- _context.next = 9;
5382
- break;
5383
- }
5384
- _context.t0 = {};
5385
- case 9:
5386
- _ref6 = _context.t0;
5387
- indexes = _ref6.indexes;
5388
- return _context.abrupt("return", indexes);
5389
- case 14:
5390
- _context.prev = 14;
5391
- _context.t1 = _context["catch"](0);
5392
- console.log('Error fetching indexes using JS fetch====', _context.t1);
5393
- case 17:
5394
- case "end":
5395
- return _context.stop();
5396
- }
5397
- }, _callee, null, [[0, 14]]);
5398
- }));
5399
- return function fetchPineconeIndexes() {
5400
- return _ref5.apply(this, arguments);
5401
- };
5402
- }();
5403
- var fetchPineconeIndexStats = /*#__PURE__*/function () {
5404
- var _ref7 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(host) {
5405
- var response, data;
5406
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
5407
- while (1) switch (_context2.prev = _context2.next) {
5408
- case 0:
5409
- _context2.prev = 0;
5410
- _context2.next = 3;
5411
- return fetch("https://" + host + "/describe_index_stats", {
5412
- method: 'GET',
5413
- headers: {
5414
- 'Api-Key': process.env.PINECONE_API_KEY,
5415
- 'X-Pinecone-API-Version': '2024-07'
5416
- },
5417
- cache: 'no-store'
5418
- });
5419
- case 3:
5420
- response = _context2.sent;
5421
- _context2.next = 6;
5422
- return response.json();
5423
- case 6:
5424
- _context2.t0 = _context2.sent;
5425
- if (_context2.t0) {
5426
- _context2.next = 9;
5427
- break;
5428
- }
5429
- _context2.t0 = {};
5430
- case 9:
5431
- data = _context2.t0;
5432
- return _context2.abrupt("return", data);
5433
- case 13:
5434
- _context2.prev = 13;
5435
- _context2.t1 = _context2["catch"](0);
5436
- console.log('Error fetching indexes using JS fetch====', _context2.t1);
5437
- case 16:
5438
- case "end":
5439
- return _context2.stop();
5440
- }
5441
- }, _callee2, null, [[0, 13]]);
5442
- }));
5443
- return function fetchPineconeIndexStats(_x5) {
5444
- return _ref7.apply(this, arguments);
5445
- };
5446
- }();
5447
5538
  var getPineconeIndices = /*#__PURE__*/function () {
5448
- var _ref8 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
5449
- var indexes, indexesWithStats;
5450
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
5451
- while (1) switch (_context4.prev = _context4.next) {
5539
+ var _ref10 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
5540
+ var vectorLayer, indexes, indexesWithStats;
5541
+ return _regeneratorRuntime().wrap(function _callee5$(_context7) {
5542
+ while (1) switch (_context7.prev = _context7.next) {
5452
5543
  case 0:
5453
- _context4.next = 2;
5454
- return fetchPineconeIndexes();
5455
- case 2:
5456
- indexes = _context4.sent;
5544
+ vectorLayer = new VectorLayer();
5545
+ _context7.next = 3;
5546
+ return vectorLayer.fetchPineconeIndexes();
5547
+ case 3:
5548
+ indexes = _context7.sent;
5457
5549
  if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
5458
- _context4.next = 8;
5550
+ _context7.next = 9;
5459
5551
  break;
5460
5552
  }
5461
- _context4.next = 6;
5553
+ _context7.next = 7;
5462
5554
  return Promise.all(indexes.map(/*#__PURE__*/function () {
5463
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(index) {
5555
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index) {
5464
5556
  var stats, namespaces;
5465
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
5466
- while (1) switch (_context3.prev = _context3.next) {
5557
+ return _regeneratorRuntime().wrap(function _callee4$(_context6) {
5558
+ while (1) switch (_context6.prev = _context6.next) {
5467
5559
  case 0:
5468
- _context3.next = 2;
5469
- return fetchPineconeIndexStats(index.host);
5560
+ _context6.next = 2;
5561
+ return vectorLayer.fetchPineconeIndexStats(index.host);
5470
5562
  case 2:
5471
- stats = _context3.sent;
5563
+ stats = _context6.sent;
5472
5564
  namespaces = [];
5473
5565
  if (stats != null && stats.namespaces) {
5474
5566
  namespaces = Object.keys(stats.namespaces);
5475
5567
  }
5476
- return _context3.abrupt("return", _extends({}, index, {
5568
+ return _context6.abrupt("return", _extends({}, index, {
5477
5569
  namespaces: namespaces
5478
5570
  }));
5479
5571
  case 6:
5480
5572
  case "end":
5481
- return _context3.stop();
5573
+ return _context6.stop();
5482
5574
  }
5483
- }, _callee3);
5575
+ }, _callee4);
5484
5576
  }));
5485
- return function (_x6) {
5486
- return _ref9.apply(this, arguments);
5577
+ return function (_x7) {
5578
+ return _ref11.apply(this, arguments);
5487
5579
  };
5488
5580
  }()));
5489
- case 6:
5490
- indexesWithStats = _context4.sent;
5491
- return _context4.abrupt("return", indexesWithStats);
5492
- case 8:
5493
- return _context4.abrupt("return", []);
5581
+ case 7:
5582
+ indexesWithStats = _context7.sent;
5583
+ return _context7.abrupt("return", indexesWithStats);
5494
5584
  case 9:
5585
+ return _context7.abrupt("return", []);
5586
+ case 10:
5495
5587
  case "end":
5496
- return _context4.stop();
5588
+ return _context7.stop();
5497
5589
  }
5498
- }, _callee4);
5590
+ }, _callee5);
5499
5591
  }));
5500
5592
  return function getPineconeIndices() {
5501
- return _ref8.apply(this, arguments);
5593
+ return _ref10.apply(this, arguments);
5502
5594
  };
5503
5595
  }();
5504
- function getVectorQueryApis(_ref10) {
5505
- var mastra = _ref10.mastra;
5596
+ function getVectorQueryApis(_ref12) {
5597
+ var mastra = _ref12.mastra;
5506
5598
  var vectorProvider = mastra.config.agents.vectorProvider;
5507
5599
  if (!vectorProvider) {
5508
5600
  console.error('NO VECTOR PROVIDER');
5509
5601
  return [];
5510
5602
  }
5511
5603
  var vectorApis = [];
5512
- var _loop = function _loop() {
5513
- var provider = _step.value;
5514
- if (provider.name === 'pinecone') {
5515
- var config = getPineconeConfig({
5516
- dir: provider.dirPath
5517
- });
5518
- config.forEach(function (index) {
5519
- if (index != null && index.namespaces) {
5520
- index == null || index.namespaces.forEach(function (namespace) {
5521
- vectorApis.push({
5522
- integrationName: 'SYSTEM',
5523
- type: "vector_query_" + index.name + "_" + namespace,
5524
- label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5525
- description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5526
- schema: zod.z.object({
5527
- content: zod.z.string(),
5528
- topResult: zod.z.number()
5529
- }),
5530
- executor: function () {
5531
- var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref11) {
5532
- var data, res;
5533
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
5534
- while (1) switch (_context5.prev = _context5.next) {
5535
- case 0:
5536
- data = _ref11.data;
5537
- _context5.next = 3;
5538
- return vectorQueryEngine({
5539
- vector_provider: provider.name,
5540
- indexName: index.name,
5541
- content: data.content,
5542
- topK: data.topResult || 1,
5543
- entityType: namespace
5544
- });
5545
- case 3:
5546
- res = _context5.sent;
5547
- console.log(JSON.stringify({
5548
- res: res
5549
- }, null, 2));
5550
- // @TODO: make this a proper response
5551
- return _context5.abrupt("return", res);
5552
- case 6:
5553
- case "end":
5554
- return _context5.stop();
5555
- }
5556
- }, _callee5);
5557
- }));
5558
- function executor(_x7) {
5559
- return _executor.apply(this, arguments);
5560
- }
5561
- return executor;
5562
- }()
5563
- });
5564
- });
5604
+ var _loop3 = function _loop3() {
5605
+ var provider = _step4.value;
5606
+ if (provider.name.toUpperCase() === 'PINECONE') {
5607
+ var config = getPineconeConfig({
5608
+ dir: provider.dirPath
5609
+ });
5610
+ if (!config || (config == null ? void 0 : config.length) === 0) {
5611
+ return {
5612
+ v: []
5613
+ };
5565
5614
  }
5566
- });
5567
- }
5568
- };
5569
- for (var _iterator = _createForOfIteratorHelperLoose(vectorProvider), _step; !(_step = _iterator()).done;) {
5570
- _loop();
5615
+ config == null || config.forEach(function (index) {
5616
+ if (index != null && index.namespaces) {
5617
+ index == null || index.namespaces.forEach(function (namespace) {
5618
+ vectorApis.push({
5619
+ integrationName: mastra.config.name,
5620
+ type: "vq_" + index.name + "_" + namespace,
5621
+ label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5622
+ description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5623
+ schema: zod.z.object({
5624
+ content: zod.z.string(),
5625
+ topResult: zod.z.number()
5626
+ }),
5627
+ source: provider.name.toUpperCase(),
5628
+ executor: function () {
5629
+ var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref13) {
5630
+ var data, res;
5631
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
5632
+ while (1) switch (_context8.prev = _context8.next) {
5633
+ case 0:
5634
+ data = _ref13.data;
5635
+ _context8.next = 3;
5636
+ return vectorQueryEngine({
5637
+ vector_provider: provider.name,
5638
+ indexName: index.name,
5639
+ content: data.content,
5640
+ topK: data.topResult || 1,
5641
+ entityType: namespace
5642
+ });
5643
+ case 3:
5644
+ res = _context8.sent;
5645
+ console.log(JSON.stringify({
5646
+ res: res
5647
+ }, null, 2));
5648
+ // @TODO: make this a proper response
5649
+ return _context8.abrupt("return", res);
5650
+ case 6:
5651
+ case "end":
5652
+ return _context8.stop();
5653
+ }
5654
+ }, _callee6);
5655
+ }));
5656
+ function executor(_x8) {
5657
+ return _executor.apply(this, arguments);
5658
+ }
5659
+ return executor;
5660
+ }()
5661
+ });
5662
+ });
5663
+ }
5664
+ });
5665
+ }
5666
+ },
5667
+ _ret3;
5668
+ for (var _iterator4 = _createForOfIteratorHelperLoose(vectorProvider), _step4; !(_step4 = _iterator4()).done;) {
5669
+ _ret3 = _loop3();
5670
+ if (_ret3) return _ret3.v;
5571
5671
  }
5572
5672
  return vectorApis;
5573
5673
  }
@@ -5594,6 +5694,74 @@ function vectorIndexSync() {
5594
5694
  executor: executeIndexSync
5595
5695
  };
5596
5696
  }
5697
+ function syncAndWriteVectorProviderIndexesToLocal(_x9) {
5698
+ return _syncAndWriteVectorProviderIndexesToLocal.apply(this, arguments);
5699
+ }
5700
+ function _syncAndWriteVectorProviderIndexesToLocal() {
5701
+ _syncAndWriteVectorProviderIndexesToLocal = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref14) {
5702
+ var mastra, vectorProviders, pullVectorProviderIndexes;
5703
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
5704
+ while (1) switch (_context15.prev = _context15.next) {
5705
+ case 0:
5706
+ mastra = _ref14.mastra;
5707
+ // TODO: Return in prod ? or do somethif different
5708
+ vectorProviders = mastra.config.agents.vectorProvider;
5709
+ pullVectorProviderIndexes = /*#__PURE__*/function () {
5710
+ var _ref16 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref15) {
5711
+ var provider, dirPath, name, indexes, MASTRA_APP_DIR, providerIndexPath;
5712
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
5713
+ while (1) switch (_context13.prev = _context13.next) {
5714
+ case 0:
5715
+ provider = _ref15.provider;
5716
+ dirPath = provider.dirPath, name = provider.name;
5717
+ if (!(name === 'PINECONE')) {
5718
+ _context13.next = 9;
5719
+ break;
5720
+ }
5721
+ _context13.next = 5;
5722
+ return getPineconeIndices();
5723
+ case 5:
5724
+ indexes = _context13.sent;
5725
+ MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
5726
+ providerIndexPath = path.join(MASTRA_APP_DIR, dirPath, name.toLowerCase() + ".json");
5727
+ fs.writeFileSync(providerIndexPath, JSON.stringify(indexes, null, 2));
5728
+ case 9:
5729
+ case "end":
5730
+ return _context13.stop();
5731
+ }
5732
+ }, _callee11);
5733
+ }));
5734
+ return function pullVectorProviderIndexes(_x10) {
5735
+ return _ref16.apply(this, arguments);
5736
+ };
5737
+ }();
5738
+ _context15.next = 5;
5739
+ return Promise.all(vectorProviders.map(/*#__PURE__*/function () {
5740
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(provider) {
5741
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
5742
+ while (1) switch (_context14.prev = _context14.next) {
5743
+ case 0:
5744
+ return _context14.abrupt("return", pullVectorProviderIndexes({
5745
+ provider: provider
5746
+ }));
5747
+ case 1:
5748
+ case "end":
5749
+ return _context14.stop();
5750
+ }
5751
+ }, _callee12);
5752
+ }));
5753
+ return function (_x11) {
5754
+ return _ref17.apply(this, arguments);
5755
+ };
5756
+ }()));
5757
+ case 5:
5758
+ case "end":
5759
+ return _context15.stop();
5760
+ }
5761
+ }, _callee13);
5762
+ }));
5763
+ return _syncAndWriteVectorProviderIndexesToLocal.apply(this, arguments);
5764
+ }
5597
5765
 
5598
5766
  function getAgentSystemApis(_ref) {
5599
5767
  var mastra = _ref.mastra;
@@ -5711,8 +5879,8 @@ function createAssistantAgentHandler(logger) {
5711
5879
  });
5712
5880
  case 3:
5713
5881
  assistant = _context.sent;
5714
- logger({
5715
- destinationPath: assistant.id + ".json",
5882
+ logger == null || logger.info({
5883
+ destinationPath: "" + assistant.id,
5716
5884
  statusCode: 201,
5717
5885
  message: JSON.stringify({
5718
5886
  message: 'Created assistant',
@@ -5755,8 +5923,8 @@ function updateAssistantAgentHandler(logger) {
5755
5923
  });
5756
5924
  case 3:
5757
5925
  assistant = _context2.sent;
5758
- logger({
5759
- destinationPath: assistant.id + ".json",
5926
+ logger == null || logger.info({
5927
+ destinationPath: "" + assistant.id,
5760
5928
  statusCode: 200,
5761
5929
  message: JSON.stringify({
5762
5930
  message: 'Updated assistant',
@@ -5823,8 +5991,8 @@ function getAssistantAgentHandler(logger) {
5823
5991
  return _context3.abrupt("return", _context3.sent);
5824
5992
  case 14:
5825
5993
  console.error('Run did not complete:', run);
5826
- logger({
5827
- destinationPath: id + ".json",
5994
+ logger == null || logger.error({
5995
+ destinationPath: "" + id,
5828
5996
  statusCode: 400,
5829
5997
  message: JSON.stringify({
5830
5998
  message: "Run did not complete",
@@ -5834,7 +6002,8 @@ function getAssistantAgentHandler(logger) {
5834
6002
  }
5835
6003
  }, null, 2)
5836
6004
  });
5837
- case 16:
6005
+ return _context3.abrupt("return", run == null ? void 0 : run.last_error);
6006
+ case 17:
5838
6007
  case "end":
5839
6008
  return _context3.stop();
5840
6009
  }
@@ -5870,8 +6039,8 @@ function getAssistantAgentHandler(logger) {
5870
6039
  fn: tool["function"].name,
5871
6040
  availableTools: Object.keys(toolMap)
5872
6041
  };
5873
- logger({
5874
- destinationPath: id + ".json",
6042
+ logger == null || logger.info({
6043
+ destinationPath: "" + id,
5875
6044
  statusCode: 100,
5876
6045
  message: JSON.stringify({
5877
6046
  message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
@@ -5885,8 +6054,8 @@ function getAssistantAgentHandler(logger) {
5885
6054
  _context4.next = 8;
5886
6055
  break;
5887
6056
  }
5888
- logger({
5889
- destinationPath: id + ".json",
6057
+ logger == null || logger.error({
6058
+ destinationPath: "" + id,
5890
6059
  statusCode: 404,
5891
6060
  message: JSON.stringify({
5892
6061
  message: "[local] No tool fn found: " + tool["function"].name,
@@ -5902,8 +6071,8 @@ function getAssistantAgentHandler(logger) {
5902
6071
  try {
5903
6072
  if (tool["function"].arguments) {
5904
6073
  args = JSON.parse(tool["function"].arguments);
5905
- logger({
5906
- destinationPath: id + ".json",
6074
+ logger == null || logger.info({
6075
+ destinationPath: "" + id,
5907
6076
  statusCode: 200,
5908
6077
  message: JSON.stringify({
5909
6078
  message: "[local] Passing args to tool call: " + tool["function"].name,
@@ -5921,8 +6090,8 @@ function getAssistantAgentHandler(logger) {
5921
6090
  return toolFn(args);
5922
6091
  case 13:
5923
6092
  output = _context4.sent;
5924
- logger({
5925
- destinationPath: id + ".json",
6093
+ logger == null || logger.info({
6094
+ destinationPath: "" + id,
5926
6095
  statusCode: 200,
5927
6096
  message: JSON.stringify({
5928
6097
  message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
@@ -5954,8 +6123,8 @@ function getAssistantAgentHandler(logger) {
5954
6123
  break;
5955
6124
  }
5956
6125
  console.error('No tool outputs to submit.');
5957
- logger({
5958
- destinationPath: id + ".json",
6126
+ logger == null || logger.error({
6127
+ destinationPath: "" + id,
5959
6128
  statusCode: 404,
5960
6129
  message: JSON.stringify({
5961
6130
  message: "No tool outputs submitted",
@@ -5978,8 +6147,8 @@ function getAssistantAgentHandler(logger) {
5978
6147
  });
5979
6148
  case 15:
5980
6149
  run = _context5.sent;
5981
- logger({
5982
- destinationPath: id + ".json",
6150
+ logger == null || logger.info({
6151
+ destinationPath: "" + id,
5983
6152
  statusCode: 200,
5984
6153
  message: JSON.stringify({
5985
6154
  message: "Tool outputs submitted",
@@ -5992,8 +6161,8 @@ function getAssistantAgentHandler(logger) {
5992
6161
  _context5.next = 22;
5993
6162
  break;
5994
6163
  case 20:
5995
- logger({
5996
- destinationPath: id + ".json",
6164
+ logger == null || logger.info({
6165
+ destinationPath: "" + id,
5997
6166
  statusCode: 404,
5998
6167
  message: JSON.stringify({
5999
6168
  message: "No tool outputs to submit",
@@ -6142,8 +6311,8 @@ function getAssistantAgentHandler(logger) {
6142
6311
  });
6143
6312
  case 9:
6144
6313
  run = _context10.sent;
6145
- logger({
6146
- destinationPath: id + ".json",
6314
+ logger == null || logger.info({
6315
+ destinationPath: "" + id,
6147
6316
  statusCode: 202,
6148
6317
  message: JSON.stringify({
6149
6318
  message: "Creating and polling run, tool choice required",
@@ -6543,87 +6712,136 @@ function _getAgent() {
6543
6712
  toolChoice: ((_agent$model = agent.model) == null ? void 0 : _agent$model.toolChoice) || 'required'
6544
6713
  },
6545
6714
  tools: _toolMap,
6546
- resultTool: resultTool
6547
- }));
6548
- case 23:
6549
- return _context3.abrupt("return", createAgent({
6550
- agent_instructions: agent.agent_instructions,
6551
- model: {
6552
- type: keyToModel[agent.model.provider],
6553
- name: agent.model.name,
6554
- toolChoice: ((_agent$model2 = agent.model) == null ? void 0 : _agent$model2.toolChoice) || 'required'
6555
- },
6556
- tools: _toolMap,
6557
- resultTool: resultTool
6558
- }));
6559
- case 24:
6560
- case "end":
6561
- return _context3.stop();
6562
- }
6563
- }, _callee3);
6564
- }));
6565
- return _getAgent.apply(this, arguments);
6566
- }
6567
-
6568
- var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
6569
- function createFileLogger() {
6570
- return function (log) {
6571
- var fullPath = path.join(loggerPath, log.destinationPath);
6572
- if (!fs.existsSync(loggerPath)) {
6573
- fs.mkdirSync(loggerPath, {
6574
- recursive: true
6575
- });
6576
- return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
6577
- createdAt: new Date()
6578
- })], null, 2));
6579
- }
6580
- if (!fs.existsSync(fullPath)) {
6581
- return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
6582
- createdAt: new Date()
6583
- })], null, 2));
6584
- }
6585
- var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
6586
- logs.push(_extends({}, log, {
6587
- createdAt: new Date()
6588
- }));
6589
- return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
6590
- };
6591
- }
6592
- function getUpstashLogs(_x) {
6593
- return _getUpstashLogs.apply(this, arguments);
6594
- }
6595
- function _getUpstashLogs() {
6596
- _getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
6597
- var id, url, token, redis$1;
6598
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6599
- while (1) switch (_context.prev = _context.next) {
6600
- case 0:
6601
- id = _ref.id, url = _ref.url, token = _ref.token;
6602
- redis$1 = new redis.Redis({
6603
- url: url,
6604
- token: token
6605
- });
6606
- return _context.abrupt("return", redis$1.lrange(id, 0, -1));
6607
- case 3:
6715
+ resultTool: resultTool
6716
+ }));
6717
+ case 23:
6718
+ return _context3.abrupt("return", createAgent({
6719
+ agent_instructions: agent.agent_instructions,
6720
+ model: {
6721
+ type: keyToModel[agent.model.provider],
6722
+ name: agent.model.name,
6723
+ toolChoice: ((_agent$model2 = agent.model) == null ? void 0 : _agent$model2.toolChoice) || 'required'
6724
+ },
6725
+ tools: _toolMap,
6726
+ resultTool: resultTool
6727
+ }));
6728
+ case 24:
6608
6729
  case "end":
6609
- return _context.stop();
6730
+ return _context3.stop();
6610
6731
  }
6611
- }, _callee);
6732
+ }, _callee3);
6612
6733
  }));
6613
- return _getUpstashLogs.apply(this, arguments);
6734
+ return _getAgent.apply(this, arguments);
6614
6735
  }
6615
- function createUpstashLogger(_ref2) {
6616
- var url = _ref2.url,
6617
- token = _ref2.token;
6618
- var redis$1 = new redis.Redis({
6619
- url: url,
6620
- token: token
6736
+
6737
+ function getWorkflowApis(_ref) {
6738
+ var mastra = _ref.mastra;
6739
+ var blueprintDirPath = mastra.config.workflows.blueprintDirPath;
6740
+ var getBlueprintsDirPath = function getBlueprintsDirPath() {
6741
+ var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
6742
+ if (!blueprintDirPath) {
6743
+ throw new Error('Missing blueprintDirPath in config');
6744
+ }
6745
+ return path.join(MASTRA_APP_DIR, blueprintDirPath);
6746
+ };
6747
+ var blueprints = getBlueprintsSync({
6748
+ directoryPath: getBlueprintsDirPath()
6621
6749
  });
6622
- return function (log) {
6623
- redis$1.lpush(log.destinationPath, JSON.stringify(_extends({}, log, {
6624
- createdAt: new Date()
6625
- })));
6750
+ var publishedBlueprints = blueprints.filter(function (blueprint) {
6751
+ return blueprint.status === WorkflowStatusEnum.PUBLISHED;
6752
+ });
6753
+ var events = mastra.getGlobalEvents();
6754
+ var allEvents = Array.from(events.values()).reduce(function (acc, val) {
6755
+ return _extends({}, acc, val);
6756
+ }, {});
6757
+ var getEvent = function getEvent(type) {
6758
+ var _Object$entries$find;
6759
+ return (_Object$entries$find = Object.entries(allEvents).find(function (_ref2) {
6760
+ var key = _ref2[0];
6761
+ return key === type;
6762
+ })) == null ? void 0 : _Object$entries$find[1];
6763
+ };
6764
+ return publishedBlueprints.map(function (blueprint) {
6765
+ var _getEvent, _blueprint$trigger;
6766
+ return {
6767
+ integrationName: mastra.config.name,
6768
+ source: 'WORKFLOW',
6769
+ description: "Workflow Trigger API for " + blueprint.title + " ",
6770
+ label: blueprint.title + " Trigger",
6771
+ schema: (_getEvent = getEvent((_blueprint$trigger = blueprint.trigger) == null ? void 0 : _blueprint$trigger.type)) == null ? void 0 : _getEvent.schema,
6772
+ type: blueprint == null ? void 0 : blueprint.title.replaceAll(' ', '_').toLowerCase(),
6773
+ executor: function executor(params) {
6774
+ var _blueprint$trigger2;
6775
+ var data = params.data,
6776
+ ctx = params.ctx;
6777
+ return mastra.triggerEvent({
6778
+ data: data,
6779
+ key: (_blueprint$trigger2 = blueprint.trigger) == null ? void 0 : _blueprint$trigger2.type,
6780
+ integrationName: mastra.config.name,
6781
+ user: {
6782
+ connectionId: ctx.connectionId
6783
+ }
6784
+ });
6785
+ }
6786
+ };
6787
+ });
6788
+ }
6789
+ function eventTriggerApi(_ref3) {
6790
+ var mastra = _ref3.mastra;
6791
+ var api = {
6792
+ integrationName: mastra.config.name,
6793
+ type: 'trigger_event',
6794
+ label: 'Trigger event',
6795
+ // getSchemaOptions({ ctx }) {
6796
+ // const options = Promise.resolve({
6797
+ // event: {
6798
+ // options: Array.from(framework.globalEvents.values()).flatMap(
6799
+ // (eventRecord) =>
6800
+ // Object.values(eventRecord).map((event) => ({
6801
+ // value: event.key || event.label || '',
6802
+ // label: event.key || event.label || '',
6803
+ // })).filter((event) => event.value !== '')
6804
+ // ),
6805
+ // },
6806
+ // });
6807
+ // return options;
6808
+ // },
6809
+ description: 'Trigger event',
6810
+ schema: zod.z.object({
6811
+ event: zod.z.string(),
6812
+ data: zod.z.record(zod.z.any())
6813
+ }),
6814
+ executor: function () {
6815
+ var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref4) {
6816
+ var data, ctx, event;
6817
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6818
+ while (1) switch (_context.prev = _context.next) {
6819
+ case 0:
6820
+ data = _ref4.data, ctx = _ref4.ctx;
6821
+ event = data.event;
6822
+ _context.next = 4;
6823
+ return mastra.triggerEvent({
6824
+ key: event,
6825
+ data: data.data,
6826
+ user: {
6827
+ connectionId: ctx.connectionId
6828
+ }
6829
+ });
6830
+ case 4:
6831
+ return _context.abrupt("return", _context.sent);
6832
+ case 5:
6833
+ case "end":
6834
+ return _context.stop();
6835
+ }
6836
+ }, _callee);
6837
+ }));
6838
+ function executor(_x) {
6839
+ return _executor.apply(this, arguments);
6840
+ }
6841
+ return executor;
6842
+ }()
6626
6843
  };
6844
+ return api;
6627
6845
  }
6628
6846
 
6629
6847
  var Mastra = /*#__PURE__*/function () {
@@ -6643,7 +6861,7 @@ var Mastra = /*#__PURE__*/function () {
6643
6861
  agentDirPath: '',
6644
6862
  vectorProvider: []
6645
6863
  };
6646
- this.logger = void 0;
6864
+ this.logger = new Map();
6647
6865
  this.config = void 0;
6648
6866
  this.runBlueprint = /*#__PURE__*/function () {
6649
6867
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
@@ -6677,7 +6895,8 @@ var Mastra = /*#__PURE__*/function () {
6677
6895
  blueprint: blueprint,
6678
6896
  frameworkApis: frameworkApis,
6679
6897
  frameworkEvents: frameworkEvents,
6680
- ctx: ctx
6898
+ ctx: ctx,
6899
+ logger: _this.logger.get('WORKFLOW')
6681
6900
  });
6682
6901
  case 10:
6683
6902
  case "end":
@@ -6692,9 +6911,10 @@ var Mastra = /*#__PURE__*/function () {
6692
6911
  this.dataLayer = dataLayer;
6693
6912
  this.vectorLayer = vectorLayer;
6694
6913
  this.config = config;
6914
+ this.__backgroundTasks();
6695
6915
  }
6696
6916
  Mastra.init = function init(config) {
6697
- var _config$logs, _config$logs2, _config$workflows$sys;
6917
+ var _config$logs, _config$logs4, _config$workflows$sys;
6698
6918
  if (!config.db.uri) {
6699
6919
  throw new Error('No database config/provider found');
6700
6920
  }
@@ -6708,87 +6928,74 @@ var Mastra = /*#__PURE__*/function () {
6708
6928
  dataLayer: dataLayer,
6709
6929
  vectorLayer: vectorLayer
6710
6930
  });
6711
- var logger;
6712
- if (!(config != null && config.logs)) {
6713
- logger = console.log;
6714
- } else if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
6715
- logger = createFileLogger();
6716
- } else if (((_config$logs2 = config.logs) == null ? void 0 : _config$logs2.provider) === 'UPSTASH') {
6717
- var _config$logs$config, _config$logs$config2;
6718
- logger = createUpstashLogger({
6931
+ var agentLogger, workflowLogger;
6932
+ if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
6933
+ var _config$logs2, _config$logs3;
6934
+ var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
6935
+ var basePath = path.join(MASTRA_APP_DIR, '/mastra-logs/');
6936
+ agentLogger = createLogger({
6937
+ type: 'FILE',
6938
+ options: {
6939
+ dirPath: path.join(basePath, 'agent'),
6940
+ level: (_config$logs2 = config.logs) == null ? void 0 : _config$logs2.level
6941
+ }
6942
+ });
6943
+ workflowLogger = createLogger({
6944
+ type: 'FILE',
6945
+ options: {
6946
+ dirPath: path.join(basePath, 'workflow'),
6947
+ level: (_config$logs3 = config.logs) == null ? void 0 : _config$logs3.level
6948
+ }
6949
+ });
6950
+ } else if (((_config$logs4 = config.logs) == null ? void 0 : _config$logs4.provider) === 'UPSTASH') {
6951
+ var _config$logs$config, _config$logs$config2, _config$logs5, _config$logs6;
6952
+ var redisClient = new redis.Redis({
6719
6953
  url: (_config$logs$config = config.logs.config) == null ? void 0 : _config$logs$config.url,
6720
6954
  token: (_config$logs$config2 = config.logs.config) == null ? void 0 : _config$logs$config2.token
6721
6955
  });
6956
+ agentLogger = createLogger({
6957
+ type: 'UPSTASH',
6958
+ options: {
6959
+ redisClient: redisClient,
6960
+ key: "mastra-logs/agent",
6961
+ level: (_config$logs5 = config.logs) == null ? void 0 : _config$logs5.level
6962
+ }
6963
+ });
6964
+ workflowLogger = createLogger({
6965
+ type: 'UPSTASH',
6966
+ options: {
6967
+ redisClient: redisClient,
6968
+ key: "mastra-logs/workflow",
6969
+ level: (_config$logs6 = config.logs) == null ? void 0 : _config$logs6.level
6970
+ }
6971
+ });
6972
+ } else {
6973
+ var _config$logs7, _config$logs8;
6974
+ agentLogger = createLogger({
6975
+ type: 'CONSOLE',
6976
+ options: {
6977
+ level: (_config$logs7 = config.logs) == null ? void 0 : _config$logs7.level
6978
+ }
6979
+ });
6980
+ workflowLogger = createLogger({
6981
+ type: 'CONSOLE',
6982
+ options: {
6983
+ level: (_config$logs8 = config.logs) == null ? void 0 : _config$logs8.level
6984
+ }
6985
+ });
6722
6986
  }
6723
- framework.attachLogger(logger);
6987
+ framework.attachLogger({
6988
+ key: 'AGENT',
6989
+ logger: agentLogger
6990
+ });
6991
+ framework.attachLogger({
6992
+ key: 'WORKFLOW',
6993
+ logger: workflowLogger
6994
+ });
6724
6995
  // Register integrations
6725
6996
  config.integrations.forEach(function (integration) {
6726
6997
  framework.__registerIntgeration(integration);
6727
6998
  });
6728
- // Register system apis
6729
- framework.__registerApis({
6730
- apis: [].concat(getVectorQueryApis({
6731
- mastra: framework
6732
- }), getAgentSystemApis({
6733
- mastra: framework
6734
- }), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
6735
- return _extends({}, api, {
6736
- integrationName: config.name
6737
- });
6738
- }), [{
6739
- integrationName: config.name,
6740
- type: 'trigger_event',
6741
- label: 'Trigger event',
6742
- // getSchemaOptions({ ctx }) {
6743
- // const options = Promise.resolve({
6744
- // event: {
6745
- // options: Array.from(framework.globalEvents.values()).flatMap(
6746
- // (eventRecord) =>
6747
- // Object.values(eventRecord).map((event) => ({
6748
- // value: event.key || event.label || '',
6749
- // label: event.key || event.label || '',
6750
- // })).filter((event) => event.value !== '')
6751
- // ),
6752
- // },
6753
- // });
6754
- // return options;
6755
- // },
6756
- description: 'Trigger event',
6757
- schema: zod.z.object({
6758
- event: zod.z.string(),
6759
- data: zod.z.record(zod.z.any())
6760
- }),
6761
- executor: function () {
6762
- var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
6763
- var data, ctx, event;
6764
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6765
- while (1) switch (_context2.prev = _context2.next) {
6766
- case 0:
6767
- data = _ref7.data, ctx = _ref7.ctx;
6768
- event = data.event;
6769
- _context2.next = 4;
6770
- return framework.triggerEvent({
6771
- key: event,
6772
- data: data.data,
6773
- user: {
6774
- connectionId: ctx.connectionId
6775
- }
6776
- });
6777
- case 4:
6778
- return _context2.abrupt("return", _context2.sent);
6779
- case 5:
6780
- case "end":
6781
- return _context2.stop();
6782
- }
6783
- }, _callee2);
6784
- }));
6785
- function executor(_x2) {
6786
- return _executor.apply(this, arguments);
6787
- }
6788
- return executor;
6789
- }()
6790
- }])
6791
- });
6792
6999
  // Register System events
6793
7000
  framework.__registerEvents({
6794
7001
  events: config.workflows.systemEvents
@@ -6806,7 +7013,7 @@ var Mastra = /*#__PURE__*/function () {
6806
7013
  },
6807
7014
  VECTOR_SYNC: {
6808
7015
  label: 'Sync vector data',
6809
- description: 'Sync vector data',
7016
+ description: 'Generic vector sync',
6810
7017
  schema: zod.z.object({
6811
7018
  vector_provider: zod.z.string(),
6812
7019
  entities: zod.z.array(zod.z.object({
@@ -6823,11 +7030,14 @@ var Mastra = /*#__PURE__*/function () {
6823
7030
  },
6824
7031
  VECTOR_INDEX_SYNC: {
6825
7032
  label: 'Sync vector index',
6826
- description: 'Sync vector index',
7033
+ description: 'Sync data to vector index',
6827
7034
  schema: zod.z.object({
6828
7035
  data: zod.z.array(zod.z.object({
6829
7036
  provider: zod.z.string(),
6830
- indexes: zod.z.array(zod.z.string())
7037
+ indexes: zod.z.array(zod.z.string()),
7038
+ mastraSyncInterval: zod.z.number({
7039
+ description: 'The time to wait can be specified using a number of milliseconds or an ms-compatible time string like "1 hour", "30 mins", or "2.5d"'
7040
+ }).optional()
6831
7041
  }))
6832
7042
  }),
6833
7043
  handler: vectorIndexSync
@@ -6835,55 +7045,73 @@ var Mastra = /*#__PURE__*/function () {
6835
7045
  },
6836
7046
  integrationName: config.name
6837
7047
  });
7048
+ // Register system apis
7049
+ framework.__registerApis({
7050
+ apis: [].concat(getVectorQueryApis({
7051
+ mastra: framework
7052
+ }), getAgentSystemApis({
7053
+ mastra: framework
7054
+ }), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
7055
+ return _extends({}, api, {
7056
+ integrationName: config.name
7057
+ });
7058
+ }), [eventTriggerApi({
7059
+ mastra: framework
7060
+ })], getWorkflowApis({
7061
+ mastra: framework
7062
+ }))
7063
+ });
6838
7064
  // Register agent config
6839
7065
  framework.agentsConfig = config.agents;
6840
7066
  return framework;
6841
7067
  };
6842
7068
  var _proto = Mastra.prototype;
6843
- _proto.attachLogger = function attachLogger(logger) {
6844
- this.logger = logger;
7069
+ _proto.attachLogger = function attachLogger(_ref7) {
7070
+ var key = _ref7.key,
7071
+ logger = _ref7.logger;
7072
+ this.logger.set(key, logger);
6845
7073
  };
6846
7074
  _proto.connectedIntegrations = /*#__PURE__*/function () {
6847
- var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref8) {
7075
+ var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
6848
7076
  var _this2 = this;
6849
7077
  var context, ints, connectionChecks;
6850
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
6851
- while (1) switch (_context4.prev = _context4.next) {
7078
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7079
+ while (1) switch (_context3.prev = _context3.next) {
6852
7080
  case 0:
6853
7081
  context = _ref8.context;
6854
7082
  ints = this.availableIntegrations();
6855
- _context4.next = 4;
7083
+ _context3.next = 4;
6856
7084
  return Promise.all(ints.map(/*#__PURE__*/function () {
6857
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref9) {
7085
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref9) {
6858
7086
  var integration, connection;
6859
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
6860
- while (1) switch (_context3.prev = _context3.next) {
7087
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7088
+ while (1) switch (_context2.prev = _context2.next) {
6861
7089
  case 0:
6862
7090
  integration = _ref9.integration;
6863
- _context3.next = 3;
7091
+ _context2.next = 3;
6864
7092
  return _this2.dataLayer.getConnection({
6865
7093
  connectionId: context.connectionId,
6866
7094
  name: integration.name
6867
7095
  });
6868
7096
  case 3:
6869
- connection = _context3.sent;
6870
- return _context3.abrupt("return", {
7097
+ connection = _context2.sent;
7098
+ return _context2.abrupt("return", {
6871
7099
  integration: integration,
6872
7100
  connected: !!connection
6873
7101
  });
6874
7102
  case 5:
6875
7103
  case "end":
6876
- return _context3.stop();
7104
+ return _context2.stop();
6877
7105
  }
6878
- }, _callee3);
7106
+ }, _callee2);
6879
7107
  }));
6880
- return function (_x4) {
7108
+ return function (_x3) {
6881
7109
  return _ref10.apply(this, arguments);
6882
7110
  };
6883
7111
  }()));
6884
7112
  case 4:
6885
- connectionChecks = _context4.sent;
6886
- return _context4.abrupt("return", connectionChecks.filter(function (_ref11) {
7113
+ connectionChecks = _context3.sent;
7114
+ return _context3.abrupt("return", connectionChecks.filter(function (_ref11) {
6887
7115
  var connected = _ref11.connected;
6888
7116
  return connected;
6889
7117
  }).map(function (_ref12) {
@@ -6892,11 +7120,11 @@ var Mastra = /*#__PURE__*/function () {
6892
7120
  }));
6893
7121
  case 6:
6894
7122
  case "end":
6895
- return _context4.stop();
7123
+ return _context3.stop();
6896
7124
  }
6897
- }, _callee4, this);
7125
+ }, _callee3, this);
6898
7126
  }));
6899
- function connectedIntegrations(_x3) {
7127
+ function connectedIntegrations(_x2) {
6900
7128
  return _connectedIntegrations.apply(this, arguments);
6901
7129
  }
6902
7130
  return connectedIntegrations;
@@ -6910,14 +7138,14 @@ var Mastra = /*#__PURE__*/function () {
6910
7138
  definition.corePresets = {
6911
7139
  redirectURI: router.makeRedirectURI()
6912
7140
  };
6913
- this.integrations.set(name, definition);
6914
7141
  definition.registerEvents();
7142
+ definition.registerApis();
7143
+ definition._convertApiClientToSystemApis();
7144
+ this.integrations.set(name, definition);
6915
7145
  this.__registerEvents({
6916
7146
  events: definition.getEvents(),
6917
7147
  integrationName: name
6918
7148
  });
6919
- definition.registerApis();
6920
- definition._convertApiClientToSystemApis();
6921
7149
  this.__registerApis({
6922
7150
  apis: Object.values(definition.getApis()),
6923
7151
  integrationName: name
@@ -7046,20 +7274,20 @@ var Mastra = /*#__PURE__*/function () {
7046
7274
  return _int.getAuthenticator();
7047
7275
  };
7048
7276
  _proto.connectIntegrationByCredential = /*#__PURE__*/function () {
7049
- var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref18) {
7277
+ var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref18) {
7050
7278
  var name, connectionId, credential, authenticator, integration;
7051
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7052
- while (1) switch (_context5.prev = _context5.next) {
7279
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
7280
+ while (1) switch (_context4.prev = _context4.next) {
7053
7281
  case 0:
7054
7282
  name = _ref18.name, connectionId = _ref18.connectionId, credential = _ref18.credential;
7055
7283
  authenticator = this.authenticator(name);
7056
7284
  if (authenticator) {
7057
- _context5.next = 4;
7285
+ _context4.next = 4;
7058
7286
  break;
7059
7287
  }
7060
7288
  throw new Error("Authenticator for " + name + " not found");
7061
7289
  case 4:
7062
- _context5.next = 6;
7290
+ _context4.next = 6;
7063
7291
  return authenticator.dataAccess.createConnection({
7064
7292
  connection: {
7065
7293
  name: name,
@@ -7068,112 +7296,112 @@ var Mastra = /*#__PURE__*/function () {
7068
7296
  credential: credential
7069
7297
  });
7070
7298
  case 6:
7071
- integration = _context5.sent;
7299
+ integration = _context4.sent;
7072
7300
  if (!authenticator.onConnectionCreated) {
7073
- _context5.next = 10;
7301
+ _context4.next = 10;
7074
7302
  break;
7075
7303
  }
7076
- _context5.next = 10;
7304
+ _context4.next = 10;
7077
7305
  return authenticator.onConnectionCreated(integration, credential);
7078
7306
  case 10:
7079
7307
  case "end":
7080
- return _context5.stop();
7308
+ return _context4.stop();
7081
7309
  }
7082
- }, _callee5, this);
7310
+ }, _callee4, this);
7083
7311
  }));
7084
- function connectIntegrationByCredential(_x5) {
7312
+ function connectIntegrationByCredential(_x4) {
7085
7313
  return _connectIntegrationByCredential.apply(this, arguments);
7086
7314
  }
7087
7315
  return connectIntegrationByCredential;
7088
7316
  }();
7089
7317
  _proto.disconnectIntegration = /*#__PURE__*/function () {
7090
- var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref19) {
7318
+ var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref19) {
7091
7319
  var _yield$this$dataLayer;
7092
7320
  var name, connectionId, integration, k_id, authenticator;
7093
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7094
- while (1) switch (_context6.prev = _context6.next) {
7321
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7322
+ while (1) switch (_context5.prev = _context5.next) {
7095
7323
  case 0:
7096
7324
  name = _ref19.name, connectionId = _ref19.connectionId;
7097
7325
  integration = this.getIntegration(name);
7098
- _context6.next = 4;
7326
+ _context5.next = 4;
7099
7327
  return this.dataLayer.getConnection({
7100
7328
  name: name,
7101
7329
  connectionId: connectionId
7102
7330
  });
7103
7331
  case 4:
7104
- _context6.t0 = _yield$this$dataLayer = _context6.sent;
7105
- if (!(_context6.t0 == null)) {
7106
- _context6.next = 9;
7332
+ _context5.t0 = _yield$this$dataLayer = _context5.sent;
7333
+ if (!(_context5.t0 == null)) {
7334
+ _context5.next = 9;
7107
7335
  break;
7108
7336
  }
7109
- _context6.t1 = void 0;
7110
- _context6.next = 10;
7337
+ _context5.t1 = void 0;
7338
+ _context5.next = 10;
7111
7339
  break;
7112
7340
  case 9:
7113
- _context6.t1 = _yield$this$dataLayer.id;
7341
+ _context5.t1 = _yield$this$dataLayer.id;
7114
7342
  case 10:
7115
- k_id = _context6.t1;
7343
+ k_id = _context5.t1;
7116
7344
  if (k_id) {
7117
- _context6.next = 13;
7345
+ _context5.next = 13;
7118
7346
  break;
7119
7347
  }
7120
7348
  throw new Error("No connection found for " + name);
7121
7349
  case 13:
7122
7350
  if (!(integration != null && integration.dataLayer)) {
7123
- _context6.next = 16;
7351
+ _context5.next = 16;
7124
7352
  break;
7125
7353
  }
7126
- _context6.next = 16;
7354
+ _context5.next = 16;
7127
7355
  return integration.onDisconnect({
7128
7356
  connectionId: connectionId
7129
7357
  });
7130
7358
  case 16:
7131
7359
  if (!((integration == null ? void 0 : integration.config.authType) === exports.IntegrationCredentialType.OAUTH)) {
7132
- _context6.next = 20;
7360
+ _context5.next = 20;
7133
7361
  break;
7134
7362
  }
7135
7363
  authenticator = this.authenticator(name);
7136
- _context6.next = 20;
7364
+ _context5.next = 20;
7137
7365
  return authenticator.revokeAuth({
7138
7366
  k_id: k_id
7139
7367
  });
7140
7368
  case 20:
7141
- _context6.next = 22;
7369
+ _context5.next = 22;
7142
7370
  return this.dataLayer.deleteConnection({
7143
7371
  connectionId: connectionId
7144
7372
  });
7145
7373
  case 22:
7146
7374
  case "end":
7147
- return _context6.stop();
7375
+ return _context5.stop();
7148
7376
  }
7149
- }, _callee6, this);
7377
+ }, _callee5, this);
7150
7378
  }));
7151
- function disconnectIntegration(_x6) {
7379
+ function disconnectIntegration(_x5) {
7152
7380
  return _disconnectIntegration.apply(this, arguments);
7153
7381
  }
7154
7382
  return disconnectIntegration;
7155
7383
  }();
7156
7384
  _proto.createSystemConnection = /*#__PURE__*/function () {
7157
- var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
7385
+ var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
7158
7386
  var systemConnectionId, existingSystemConnection;
7159
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7160
- while (1) switch (_context7.prev = _context7.next) {
7387
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7388
+ while (1) switch (_context6.prev = _context6.next) {
7161
7389
  case 0:
7162
7390
  systemConnectionId = 'SYSTEM';
7163
- _context7.next = 3;
7391
+ _context6.next = 3;
7164
7392
  return this.dataLayer.getConnection({
7165
7393
  connectionId: systemConnectionId,
7166
7394
  name: this.config.name
7167
7395
  });
7168
7396
  case 3:
7169
- existingSystemConnection = _context7.sent;
7397
+ existingSystemConnection = _context6.sent;
7170
7398
  if (!existingSystemConnection) {
7171
- _context7.next = 6;
7399
+ _context6.next = 6;
7172
7400
  break;
7173
7401
  }
7174
- return _context7.abrupt("return", existingSystemConnection);
7402
+ return _context6.abrupt("return", existingSystemConnection);
7175
7403
  case 6:
7176
- return _context7.abrupt("return", this.dataLayer.createConnection({
7404
+ return _context6.abrupt("return", this.dataLayer.createConnection({
7177
7405
  connection: {
7178
7406
  connectionId: systemConnectionId,
7179
7407
  name: this.config.name
@@ -7185,9 +7413,9 @@ var Mastra = /*#__PURE__*/function () {
7185
7413
  }));
7186
7414
  case 7:
7187
7415
  case "end":
7188
- return _context7.stop();
7416
+ return _context6.stop();
7189
7417
  }
7190
- }, _callee7, this);
7418
+ }, _callee6, this);
7191
7419
  }));
7192
7420
  function createSystemConnection() {
7193
7421
  return _createSystemConnection.apply(this, arguments);
@@ -7195,71 +7423,71 @@ var Mastra = /*#__PURE__*/function () {
7195
7423
  return createSystemConnection;
7196
7424
  }();
7197
7425
  _proto.callApi = /*#__PURE__*/function () {
7198
- var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
7426
+ var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref20) {
7199
7427
  var _int2$getApis;
7200
7428
  var _ref20$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
7201
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7202
- while (1) switch (_context8.prev = _context8.next) {
7429
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7430
+ while (1) switch (_context7.prev = _context7.next) {
7203
7431
  case 0:
7204
7432
  _ref20$integrationNam = _ref20.integrationName, integrationName = _ref20$integrationNam === void 0 ? this.config.name : _ref20$integrationNam, api = _ref20.api, payload = _ref20.payload;
7205
7433
  if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
7206
- _context8.next = 6;
7434
+ _context7.next = 6;
7207
7435
  break;
7208
7436
  }
7209
7437
  _apiExecutor = (_this$globalApis$get = this.globalApis.get(this.config.name)) == null ? void 0 : _this$globalApis$get[api];
7210
7438
  if (_apiExecutor) {
7211
- _context8.next = 5;
7439
+ _context7.next = 5;
7212
7440
  break;
7213
7441
  }
7214
7442
  throw new Error("No global api exists for " + api);
7215
7443
  case 5:
7216
- return _context8.abrupt("return", _apiExecutor.executor(payload));
7444
+ return _context7.abrupt("return", _apiExecutor.executor(payload));
7217
7445
  case 6:
7218
7446
  _int2 = this.getIntegration(integrationName);
7219
7447
  if (_int2) {
7220
- _context8.next = 9;
7448
+ _context7.next = 9;
7221
7449
  break;
7222
7450
  }
7223
7451
  throw new Error("No Integration exists for " + integrationName);
7224
7452
  case 9:
7225
7453
  apiExecutor = (_int2$getApis = _int2.getApis()) == null ? void 0 : _int2$getApis[api];
7226
7454
  if (apiExecutor) {
7227
- _context8.next = 12;
7455
+ _context7.next = 12;
7228
7456
  break;
7229
7457
  }
7230
7458
  throw new Error("No api exists for " + api + " in " + integrationName);
7231
7459
  case 12:
7232
- return _context8.abrupt("return", apiExecutor.executor(payload));
7460
+ return _context7.abrupt("return", apiExecutor.executor(payload));
7233
7461
  case 13:
7234
7462
  case "end":
7235
- return _context8.stop();
7463
+ return _context7.stop();
7236
7464
  }
7237
- }, _callee8, this);
7465
+ }, _callee7, this);
7238
7466
  }));
7239
- function callApi(_x7) {
7467
+ function callApi(_x6) {
7240
7468
  return _callApi.apply(this, arguments);
7241
7469
  }
7242
7470
  return callApi;
7243
7471
  }();
7244
7472
  _proto.subscribeEvent = /*#__PURE__*/function () {
7245
- var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref21) {
7473
+ var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
7246
7474
  var _this$config$runner$u, _this$config$runner, _ref22, _this$config$runner$s, _this$config$runner2;
7247
7475
  var id, _ref21$interval, interval, _ref21$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
7248
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
7249
- while (1) switch (_context10.prev = _context10.next) {
7476
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7477
+ while (1) switch (_context9.prev = _context9.next) {
7250
7478
  case 0:
7251
7479
  id = _ref21.id, _ref21$interval = _ref21.interval, interval = _ref21$interval === void 0 ? 5000 : _ref21$interval, _ref21$timeout = _ref21.timeout, timeout = _ref21$timeout === void 0 ? 60000 : _ref21$timeout;
7252
7480
  inngestApiUrl = (_this$config$runner$u = (_this$config$runner = this.config.runner) == null ? void 0 : _this$config$runner.uri) != null ? _this$config$runner$u : process.env.INNGEST_URL;
7253
7481
  inngestApiToken = (_ref22 = (_this$config$runner$s = (_this$config$runner2 = this.config.runner) == null ? void 0 : _this$config$runner2.signingKey) != null ? _this$config$runner$s : process.env.INNGEST_SIGNING_KEY) != null ? _ref22 : '123';
7254
7482
  startTime = Date.now();
7255
7483
  _poll = /*#__PURE__*/function () {
7256
- var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
7484
+ var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
7257
7485
  var response, obj, data, error, lastRun, elapsedTime;
7258
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7259
- while (1) switch (_context9.prev = _context9.next) {
7486
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7487
+ while (1) switch (_context8.prev = _context8.next) {
7260
7488
  case 0:
7261
- _context9.prev = 0;
7262
- _context9.next = 3;
7489
+ _context8.prev = 0;
7490
+ _context8.next = 3;
7263
7491
  return fetch(inngestApiUrl + "/v1/events/" + id + "/runs", {
7264
7492
  method: 'GET',
7265
7493
  headers: {
@@ -7268,117 +7496,117 @@ var Mastra = /*#__PURE__*/function () {
7268
7496
  }
7269
7497
  });
7270
7498
  case 3:
7271
- response = _context9.sent;
7499
+ response = _context8.sent;
7272
7500
  console.log("Polling for event " + id + "...", response.ok);
7273
7501
  if (!response.ok) {
7274
- _context9.next = 28;
7502
+ _context8.next = 28;
7275
7503
  break;
7276
7504
  }
7277
- _context9.next = 8;
7505
+ _context8.next = 8;
7278
7506
  return response.json();
7279
7507
  case 8:
7280
- obj = _context9.sent;
7508
+ obj = _context8.sent;
7281
7509
  console.log({
7282
7510
  obj: obj
7283
7511
  });
7284
7512
  data = obj.data, error = obj.error;
7285
7513
  console.log("Got data for event " + id + "...", data, error);
7286
7514
  if (!error) {
7287
- _context9.next = 15;
7515
+ _context8.next = 15;
7288
7516
  break;
7289
7517
  }
7290
7518
  console.error(error);
7291
- return _context9.abrupt("return", null);
7519
+ return _context8.abrupt("return", null);
7292
7520
  case 15:
7293
7521
  if (!((data == null ? void 0 : data.length) === 0)) {
7294
- _context9.next = 19;
7522
+ _context8.next = 19;
7295
7523
  break;
7296
7524
  }
7297
- _context9.next = 18;
7525
+ _context8.next = 18;
7298
7526
  return new Promise(function (resolve) {
7299
7527
  return setTimeout(resolve, interval);
7300
7528
  });
7301
7529
  case 18:
7302
- return _context9.abrupt("return", _poll());
7530
+ return _context8.abrupt("return", _poll());
7303
7531
  case 19:
7304
7532
  lastRun = data == null ? void 0 : data[0];
7305
7533
  console.log(lastRun);
7306
7534
  if (lastRun) {
7307
- _context9.next = 23;
7535
+ _context8.next = 23;
7308
7536
  break;
7309
7537
  }
7310
- return _context9.abrupt("return", null);
7538
+ return _context8.abrupt("return", null);
7311
7539
  case 23:
7312
7540
  if (!(lastRun.status === 'Running')) {
7313
- _context9.next = 27;
7541
+ _context8.next = 27;
7314
7542
  break;
7315
7543
  }
7316
- _context9.next = 26;
7544
+ _context8.next = 26;
7317
7545
  return new Promise(function (resolve) {
7318
7546
  return setTimeout(resolve, interval);
7319
7547
  });
7320
7548
  case 26:
7321
- return _context9.abrupt("return", _poll());
7549
+ return _context8.abrupt("return", _poll());
7322
7550
  case 27:
7323
- return _context9.abrupt("return", {
7551
+ return _context8.abrupt("return", {
7324
7552
  status: lastRun.status,
7325
7553
  startedAt: lastRun.run_started_at,
7326
7554
  endedAt: lastRun.ended_at
7327
7555
  });
7328
7556
  case 28:
7329
- _context9.next = 33;
7557
+ _context8.next = 33;
7330
7558
  break;
7331
7559
  case 30:
7332
- _context9.prev = 30;
7333
- _context9.t0 = _context9["catch"](0);
7334
- console.error("Request failed: " + _context9.t0);
7560
+ _context8.prev = 30;
7561
+ _context8.t0 = _context8["catch"](0);
7562
+ console.error("Request failed: " + _context8.t0);
7335
7563
  case 33:
7336
7564
  // Check if timeout has been reached
7337
7565
  elapsedTime = Date.now() - startTime;
7338
7566
  if (!(elapsedTime >= timeout)) {
7339
- _context9.next = 37;
7567
+ _context8.next = 37;
7340
7568
  break;
7341
7569
  }
7342
7570
  console.log('Polling timeout reached.');
7343
- return _context9.abrupt("return", null);
7571
+ return _context8.abrupt("return", null);
7344
7572
  case 37:
7345
- _context9.next = 39;
7573
+ _context8.next = 39;
7346
7574
  return new Promise(function (resolve) {
7347
7575
  return setTimeout(resolve, interval);
7348
7576
  });
7349
7577
  case 39:
7350
- return _context9.abrupt("return", _poll());
7578
+ return _context8.abrupt("return", _poll());
7351
7579
  case 40:
7352
7580
  case "end":
7353
- return _context9.stop();
7581
+ return _context8.stop();
7354
7582
  }
7355
- }, _callee9, null, [[0, 30]]);
7583
+ }, _callee8, null, [[0, 30]]);
7356
7584
  }));
7357
7585
  return function poll() {
7358
7586
  return _ref23.apply(this, arguments);
7359
7587
  };
7360
7588
  }();
7361
- return _context10.abrupt("return", _poll());
7589
+ return _context9.abrupt("return", _poll());
7362
7590
  case 6:
7363
7591
  case "end":
7364
- return _context10.stop();
7592
+ return _context9.stop();
7365
7593
  }
7366
- }, _callee10, this);
7594
+ }, _callee9, this);
7367
7595
  }));
7368
- function subscribeEvent(_x8) {
7596
+ function subscribeEvent(_x7) {
7369
7597
  return _subscribeEvent.apply(this, arguments);
7370
7598
  }
7371
7599
  return subscribeEvent;
7372
7600
  }();
7373
7601
  _proto.triggerEvent = /*#__PURE__*/function () {
7374
- var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref24) {
7602
+ var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref24) {
7375
7603
  var _this4 = this;
7376
7604
  var key, data, user, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
7377
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
7378
- while (1) switch (_context13.prev = _context13.next) {
7605
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
7606
+ while (1) switch (_context12.prev = _context12.next) {
7379
7607
  case 0:
7380
7608
  key = _ref24.key, data = _ref24.data, user = _ref24.user, integrationName = _ref24.integrationName;
7381
- _context13.prev = 1;
7609
+ _context12.prev = 1;
7382
7610
  returnObj = {
7383
7611
  event: {}
7384
7612
  };
@@ -7390,53 +7618,53 @@ var Mastra = /*#__PURE__*/function () {
7390
7618
  }, {});
7391
7619
  }
7392
7620
  if (integrationEvents) {
7393
- _context13.next = 6;
7621
+ _context12.next = 6;
7394
7622
  break;
7395
7623
  }
7396
7624
  throw new Error("No integration events found");
7397
7625
  case 6:
7398
7626
  integrationEvent = integrationEvents[key];
7399
7627
  if (integrationEvent) {
7400
- _context13.next = 9;
7628
+ _context12.next = 9;
7401
7629
  break;
7402
7630
  }
7403
7631
  throw new Error("No event exists for " + key + " in " + (integrationName || 'system'));
7404
7632
  case 9:
7405
- _context13.next = 11;
7633
+ _context12.next = 11;
7406
7634
  return client$1.send({
7407
7635
  name: key,
7408
7636
  data: data,
7409
7637
  user: user
7410
7638
  });
7411
7639
  case 11:
7412
- event = _context13.sent;
7640
+ event = _context12.sent;
7413
7641
  returnObj['event'] = _extends({}, event, {
7414
7642
  subscribe: function () {
7415
- var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp) {
7643
+ var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp) {
7416
7644
  var _event$ids;
7417
7645
  var _ref25, interval, timeout;
7418
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
7419
- while (1) switch (_context11.prev = _context11.next) {
7646
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
7647
+ while (1) switch (_context10.prev = _context10.next) {
7420
7648
  case 0:
7421
7649
  _ref25 = _temp === void 0 ? {} : _temp, interval = _ref25.interval, timeout = _ref25.timeout;
7422
- return _context11.abrupt("return", _this4.subscribeEvent({
7650
+ return _context10.abrupt("return", _this4.subscribeEvent({
7423
7651
  id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
7424
7652
  interval: interval,
7425
7653
  timeout: timeout
7426
7654
  }));
7427
7655
  case 2:
7428
7656
  case "end":
7429
- return _context11.stop();
7657
+ return _context10.stop();
7430
7658
  }
7431
- }, _callee11);
7659
+ }, _callee10);
7432
7660
  }));
7433
- function subscribe(_x10) {
7661
+ function subscribe(_x9) {
7434
7662
  return _subscribe.apply(this, arguments);
7435
7663
  }
7436
7664
  return subscribe;
7437
7665
  }()
7438
7666
  });
7439
- _context13.next = 15;
7667
+ _context12.next = 15;
7440
7668
  return client$1.send({
7441
7669
  name: 'workflow/run-automations',
7442
7670
  data: {
@@ -7446,45 +7674,45 @@ var Mastra = /*#__PURE__*/function () {
7446
7674
  user: user
7447
7675
  });
7448
7676
  case 15:
7449
- workflowEvent = _context13.sent;
7677
+ workflowEvent = _context12.sent;
7450
7678
  returnObj['workflowEvent'] = _extends({}, workflowEvent, {
7451
7679
  subscribe: function () {
7452
- var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_temp2) {
7680
+ var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp2) {
7453
7681
  var _workflowEvent$ids;
7454
7682
  var _ref26, interval, timeout;
7455
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
7456
- while (1) switch (_context12.prev = _context12.next) {
7683
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
7684
+ while (1) switch (_context11.prev = _context11.next) {
7457
7685
  case 0:
7458
7686
  _ref26 = _temp2 === void 0 ? {} : _temp2, interval = _ref26.interval, timeout = _ref26.timeout;
7459
- return _context12.abrupt("return", _this4.subscribeEvent({
7687
+ return _context11.abrupt("return", _this4.subscribeEvent({
7460
7688
  id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
7461
7689
  interval: interval,
7462
7690
  timeout: timeout
7463
7691
  }));
7464
7692
  case 2:
7465
7693
  case "end":
7466
- return _context12.stop();
7694
+ return _context11.stop();
7467
7695
  }
7468
- }, _callee12);
7696
+ }, _callee11);
7469
7697
  }));
7470
- function subscribe(_x11) {
7698
+ function subscribe(_x10) {
7471
7699
  return _subscribe2.apply(this, arguments);
7472
7700
  }
7473
7701
  return subscribe;
7474
7702
  }()
7475
7703
  });
7476
- return _context13.abrupt("return", returnObj);
7704
+ return _context12.abrupt("return", returnObj);
7477
7705
  case 20:
7478
- _context13.prev = 20;
7479
- _context13.t0 = _context13["catch"](1);
7480
- throw new Error("Error triggering event: " + _context13.t0);
7706
+ _context12.prev = 20;
7707
+ _context12.t0 = _context12["catch"](1);
7708
+ throw new Error("Error triggering event: " + _context12.t0);
7481
7709
  case 23:
7482
7710
  case "end":
7483
- return _context13.stop();
7711
+ return _context12.stop();
7484
7712
  }
7485
- }, _callee13, this, [[1, 20]]);
7713
+ }, _callee12, this, [[1, 20]]);
7486
7714
  }));
7487
- function triggerEvent(_x9) {
7715
+ function triggerEvent(_x8) {
7488
7716
  return _triggerEvent.apply(this, arguments);
7489
7717
  }
7490
7718
  return triggerEvent;
@@ -7493,26 +7721,26 @@ var Mastra = /*#__PURE__*/function () {
7493
7721
  _proto.triggerSystemEvent =
7494
7722
  /*#__PURE__*/
7495
7723
  function () {
7496
- var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref27) {
7724
+ var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref27) {
7497
7725
  var key, data, user, event, systemEvent;
7498
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
7499
- while (1) switch (_context14.prev = _context14.next) {
7726
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
7727
+ while (1) switch (_context13.prev = _context13.next) {
7500
7728
  case 0:
7501
7729
  key = _ref27.key, data = _ref27.data, user = _ref27.user;
7502
- _context14.next = 3;
7730
+ _context13.next = 3;
7503
7731
  return client$1.send({
7504
7732
  name: key,
7505
7733
  data: data,
7506
7734
  user: user
7507
7735
  });
7508
7736
  case 3:
7509
- event = _context14.sent;
7737
+ event = _context13.sent;
7510
7738
  systemEvent = this.getSystemEvents()[key];
7511
7739
  if (!systemEvent) {
7512
- _context14.next = 8;
7740
+ _context13.next = 8;
7513
7741
  break;
7514
7742
  }
7515
- _context14.next = 8;
7743
+ _context13.next = 8;
7516
7744
  return client$1.send({
7517
7745
  name: 'workflow/run-automations',
7518
7746
  data: {
@@ -7522,14 +7750,14 @@ var Mastra = /*#__PURE__*/function () {
7522
7750
  user: user
7523
7751
  });
7524
7752
  case 8:
7525
- return _context14.abrupt("return", event);
7753
+ return _context13.abrupt("return", event);
7526
7754
  case 9:
7527
7755
  case "end":
7528
- return _context14.stop();
7756
+ return _context13.stop();
7529
7757
  }
7530
- }, _callee14, this);
7758
+ }, _callee13, this);
7531
7759
  }));
7532
- function triggerSystemEvent(_x12) {
7760
+ function triggerSystemEvent(_x11) {
7533
7761
  return _triggerSystemEvent.apply(this, arguments);
7534
7762
  }
7535
7763
  return triggerSystemEvent;
@@ -7551,7 +7779,7 @@ var Mastra = /*#__PURE__*/function () {
7551
7779
  };
7552
7780
  var registerRoutes = function registerRoutes() {
7553
7781
  var _registry;
7554
- var registry = (_registry = {}, _registry[self.routes.connect] = makeConnect(self), _registry[self.routes.callback] = makeCallback(self), _registry[self.routes.inngest] = makeInngest(self), _registry[self.routes.webhook] = makeWebhook(self), _registry);
7782
+ var registry = (_registry = {}, _registry[self.routes.connect] = makeConnect(self), _registry[self.routes.callback] = makeCallback(self), _registry[self.routes.inngest] = makeInngest(self), _registry[self.routes.webhook] = makeWebhook(self), _registry[self.routes.cron] = makeCron(self), _registry);
7555
7783
  return function (req) {
7556
7784
  var route = req.nextUrl.pathname;
7557
7785
  if (req.nextUrl.pathname in registry) {
@@ -7570,42 +7798,62 @@ var Mastra = /*#__PURE__*/function () {
7570
7798
  };
7571
7799
  };
7572
7800
  _proto.getAgent = /*#__PURE__*/function () {
7573
- var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref29) {
7801
+ var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref29) {
7574
7802
  var connectionId, agentId, agentBlueprint, arrMap, finalApis;
7575
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
7576
- while (1) switch (_context15.prev = _context15.next) {
7803
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
7804
+ while (1) switch (_context14.prev = _context14.next) {
7577
7805
  case 0:
7578
7806
  connectionId = _ref29.connectionId, agentId = _ref29.agentId;
7579
- _context15.next = 3;
7807
+ _context14.next = 3;
7580
7808
  return getAgentBlueprint({
7581
7809
  agentDir: this.config.agents.agentDirPath,
7582
7810
  agentId: agentId
7583
7811
  });
7584
7812
  case 3:
7585
- agentBlueprint = _context15.sent;
7813
+ agentBlueprint = _context14.sent;
7586
7814
  arrMap = Array.from(this.getApis());
7587
7815
  finalApis = arrMap.reduce(function (acc, _ref30) {
7588
7816
  var v = _ref30[1];
7589
7817
  return _extends({}, acc, v);
7590
7818
  }, {});
7591
7819
  console.log('got finalApis===');
7592
- return _context15.abrupt("return", getAgent({
7820
+ return _context14.abrupt("return", getAgent({
7593
7821
  connectionId: connectionId,
7594
7822
  agent: agentBlueprint,
7595
7823
  apis: finalApis,
7596
- logger: this.logger
7824
+ logger: this.logger.get('AGENT')
7597
7825
  }));
7598
7826
  case 8:
7599
7827
  case "end":
7600
- return _context15.stop();
7828
+ return _context14.stop();
7601
7829
  }
7602
- }, _callee15, this);
7830
+ }, _callee14, this);
7603
7831
  }));
7604
- function getAgent$1(_x13) {
7832
+ function getAgent$1(_x12) {
7605
7833
  return _getAgent2.apply(this, arguments);
7606
7834
  }
7607
7835
  return getAgent$1;
7608
7836
  }();
7837
+ _proto.__backgroundTasks = /*#__PURE__*/function () {
7838
+ var _backgroundTasks = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
7839
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
7840
+ while (1) switch (_context15.prev = _context15.next) {
7841
+ case 0:
7842
+ _context15.next = 2;
7843
+ return syncAndWriteVectorProviderIndexesToLocal({
7844
+ mastra: this
7845
+ });
7846
+ case 2:
7847
+ case "end":
7848
+ return _context15.stop();
7849
+ }
7850
+ }, _callee15, this);
7851
+ }));
7852
+ function __backgroundTasks() {
7853
+ return _backgroundTasks.apply(this, arguments);
7854
+ }
7855
+ return __backgroundTasks;
7856
+ }();
7609
7857
  return _createClass(Mastra, [{
7610
7858
  key: "routes",
7611
7859
  get: function get() {
@@ -7614,7 +7862,8 @@ var Mastra = /*#__PURE__*/function () {
7614
7862
  connect: '/connect',
7615
7863
  callback: '/connect/callback',
7616
7864
  inngest: '/inngest',
7617
- webhook: '/webhook'
7865
+ webhook: '/webhook',
7866
+ cron: '/cron'
7618
7867
  };
7619
7868
  return Object.entries(registry).reduce(function (acc, _ref31) {
7620
7869
  var _extends5;
@@ -7627,14 +7876,38 @@ var Mastra = /*#__PURE__*/function () {
7627
7876
  key: "openAIAssistant",
7628
7877
  get: function get() {
7629
7878
  return {
7630
- createAssistantAgent: createAssistantAgentHandler(this.logger),
7631
- getAssistantAgent: getAssistantAgentHandler(this.logger),
7632
- updateAssistantAgent: updateAssistantAgentHandler(this.logger)
7879
+ createAssistantAgent: createAssistantAgentHandler(this.logger.get('AGENT')),
7880
+ getAssistantAgent: getAssistantAgentHandler(this.logger.get('AGENT')),
7881
+ updateAssistantAgent: updateAssistantAgentHandler(this.logger.get('AGENT'))
7633
7882
  };
7634
7883
  }
7635
7884
  }]);
7636
7885
  }();
7637
7886
 
7887
+ function getUpstashLogs(_x) {
7888
+ return _getUpstashLogs.apply(this, arguments);
7889
+ }
7890
+ function _getUpstashLogs() {
7891
+ _getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
7892
+ var id, url, token, redis$1;
7893
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7894
+ while (1) switch (_context.prev = _context.next) {
7895
+ case 0:
7896
+ id = _ref.id, url = _ref.url, token = _ref.token;
7897
+ redis$1 = new redis.Redis({
7898
+ url: url,
7899
+ token: token
7900
+ });
7901
+ return _context.abrupt("return", redis$1.lrange(id, 0, -1));
7902
+ case 3:
7903
+ case "end":
7904
+ return _context.stop();
7905
+ }
7906
+ }, _callee);
7907
+ }));
7908
+ return _getUpstashLogs.apply(this, arguments);
7909
+ }
7910
+
7638
7911
  Object.defineProperty(exports, 'PropertyType', {
7639
7912
  enumerable: true,
7640
7913
  get: function () { return client$2.PropertyType; }
@@ -7646,6 +7919,7 @@ exports.Integration = Integration;
7646
7919
  exports.IntegrationAuth = IntegrationAuth;
7647
7920
  exports.IntegrationError = IntegrationError;
7648
7921
  exports.IntegrationFieldTypeEnum = IntegrationFieldTypeEnum;
7922
+ exports.LogProvider = LogProvider;
7649
7923
  exports.Mastra = Mastra;
7650
7924
  exports.RunStatus = RunStatus;
7651
7925
  exports.SORT_MODE_TO_ABBR = SORT_MODE_TO_ABBR;
@@ -7656,6 +7930,9 @@ exports.buildQueryString = buildQueryString;
7656
7930
  exports.callbackParams = callbackParams;
7657
7931
  exports.connectParams = connectParams;
7658
7932
  exports.constructObjFromStringPath = constructObjFromStringPath;
7933
+ exports.createLogger = createLogger;
7934
+ exports.cronQueryParams = cronQueryParams;
7935
+ exports.delay = delay$1;
7659
7936
  exports.extractSchemaOptions = extractSchemaOptions;
7660
7937
  exports.fieldsWithCommaSeparatedValues = fieldsWithCommaSeparatedValues;
7661
7938
  exports.filterQuerySchema = filterQuerySchema;
@@ -7677,6 +7954,7 @@ exports.recordHasData = recordHasData;
7677
7954
  exports.registerRoutes = registerRoutes;
7678
7955
  exports.sortQuerySchema = sortQuerySchema;
7679
7956
  exports.splitAndStripQuotes = splitAndStripQuotes;
7957
+ exports.splitMarkdownIntoChunks = splitMarkdownIntoChunks;
7680
7958
  exports.transformFilterValueArray = transformFilterValueArray;
7681
7959
  exports.transformFilterValueBoolean = transformFilterValueBoolean;
7682
7960
  exports.webhookQueryParams = webhookQueryParams;