@mastra/core 0.1.12 → 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 (43) 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/vector-sync.d.ts +3 -0
  7. package/dist/agents/vector-sync.d.ts.map +1 -1
  8. package/dist/core.cjs.development.js +1243 -1132
  9. package/dist/core.cjs.development.js.map +1 -1
  10. package/dist/core.cjs.production.min.js +1 -1
  11. package/dist/core.cjs.production.min.js.map +1 -1
  12. package/dist/core.esm.js +1241 -1135
  13. package/dist/core.esm.js.map +1 -1
  14. package/dist/framework.d.ts +8 -3
  15. package/dist/framework.d.ts.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/integration.d.ts.map +1 -1
  19. package/dist/lib/index.d.ts +1 -0
  20. package/dist/lib/index.d.ts.map +1 -1
  21. package/dist/lib/logger-utils/logger.d.ts +98 -0
  22. package/dist/lib/logger-utils/logger.d.ts.map +1 -0
  23. package/dist/next/cron.d.ts +13 -0
  24. package/dist/next/cron.d.ts.map +1 -0
  25. package/dist/next/index.d.ts.map +1 -1
  26. package/dist/schemas.d.ts +13 -0
  27. package/dist/schemas.d.ts.map +1 -1
  28. package/dist/types.d.ts +5 -2
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/utils/index.d.ts +2 -0
  31. package/dist/utils/index.d.ts.map +1 -1
  32. package/dist/utils/text.d.ts +2 -0
  33. package/dist/utils/text.d.ts.map +1 -0
  34. package/dist/workflows/apis.d.ts +9 -0
  35. package/dist/workflows/apis.d.ts.map +1 -0
  36. package/dist/workflows/handler.d.ts +8 -0
  37. package/dist/workflows/handler.d.ts.map +1 -1
  38. package/dist/workflows/runner.d.ts +3 -1
  39. package/dist/workflows/runner.d.ts.map +1 -1
  40. package/package.json +4 -4
  41. package/dist/prisma/client.ts +0 -31
  42. package/dist/prisma/gen.js +0 -139
  43. package/dist/prisma/schema.prisma +0 -129
@@ -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,26 +2030,26 @@ 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() {
2052
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2002
2053
  var MASTRA_APP_DIR;
2003
2054
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2004
2055
  while (1) switch (_context.prev = _context.next) {
@@ -2018,7 +2069,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
2018
2069
  }, _callee);
2019
2070
  }));
2020
2071
  return function getBlueprintsDirPath() {
2021
- return _ref5.apply(this, arguments);
2072
+ return _ref6.apply(this, arguments);
2022
2073
  };
2023
2074
  }();
2024
2075
  _context3.next = 7;
@@ -2073,7 +2124,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
2073
2124
  }, _callee3, null, [[1, 15]]);
2074
2125
  }));
2075
2126
  return function (_x3) {
2076
- return _ref4.apply(this, arguments);
2127
+ return _ref5.apply(this, arguments);
2077
2128
  };
2078
2129
  }());
2079
2130
  };
@@ -2170,13 +2221,52 @@ var makeWebhook = function makeWebhook(framework) {
2170
2221
  };
2171
2222
  };
2172
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
+
2173
2262
  var registerRoutes = function registerRoutes(_ref) {
2174
2263
  var framework = _ref.framework;
2175
2264
  var registry = {
2176
2265
  connect: makeConnect(framework),
2177
2266
  'connect/callback': makeCallback(framework),
2178
2267
  inngest: makeInngest(framework),
2179
- webhook: makeWebhook(framework)
2268
+ webhook: makeWebhook(framework),
2269
+ cron: makeCron(framework)
2180
2270
  };
2181
2271
  return function (req, _ref2) {
2182
2272
  var _Object$keys$at;
@@ -2362,6 +2452,203 @@ function mergeWithDefinedOnly(base, overrides) {
2362
2452
  return result;
2363
2453
  }
2364
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
+
2365
2652
  var _excluded$3 = ["client"],
2366
2653
  _excluded2$1 = ["name", "logoUrl"];
2367
2654
  /**
@@ -2448,7 +2735,7 @@ var Integration = /*#__PURE__*/function () {
2448
2735
  return acc;
2449
2736
  }
2450
2737
  }, {});
2451
- _this.apis = apis;
2738
+ _this.apis = _extends({}, _this.apis, apis);
2452
2739
  case 5:
2453
2740
  case "end":
2454
2741
  return _context2.stop();
@@ -3067,6 +3354,31 @@ var IntegrationAuth = /*#__PURE__*/function () {
3067
3354
  return IntegrationAuth;
3068
3355
  }();
3069
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
+
3070
3382
  /**
3071
3383
  * Extract schema options for the provided schema - Builds a map of fieldname to field options
3072
3384
  * @param schema - schema
@@ -3143,6 +3455,11 @@ function setFieldOptions(_ref3) {
3143
3455
  };
3144
3456
  }
3145
3457
  }
3458
+ var delay$1 = function delay(ms) {
3459
+ return new Promise(function (resolve) {
3460
+ return setTimeout(resolve, ms);
3461
+ });
3462
+ };
3146
3463
 
3147
3464
  function zodToPropertType(zodType) {
3148
3465
  if (zodType instanceof zod.z.ZodString) {
@@ -3887,11 +4204,11 @@ function runActionsRecursively(_x) {
3887
4204
  }
3888
4205
  function _runActionsRecursively() {
3889
4206
  _runActionsRecursively = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref7) {
3890
- 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;
3891
4208
  return _regeneratorRuntime().wrap(function _callee$(_context3) {
3892
4209
  while (1) switch (_context3.prev = _context3.next) {
3893
4210
  case 0:
3894
- 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;
3895
4212
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
3896
4213
  var _action$subActions;
3897
4214
  var action, concreteAction, hasValidBranch, _loop2, _ret2, _iterator3, _step3, defaultCondition, defaultAction, actionExecutor, _ref9, mastraConnectionId, actionPayload, resolvedPayload, resolvedSchema, data, executorResult, _ctx, subActions;
@@ -3900,9 +4217,15 @@ function _runActionsRecursively() {
3900
4217
  case 0:
3901
4218
  action = _step2.value;
3902
4219
  concreteAction = frameworkApis[action.type];
3903
- console.log('==========', "Running action " + action.type, {
3904
- dataContext: JSON.stringify(dataContext, null, 2)
3905
- }, '=======');
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
+ });
3906
4229
  // check action conditions
3907
4230
  if (!(action.type === 'CONDITIONS')) {
3908
4231
  _context2.next = 32;
@@ -3979,7 +4302,8 @@ function _runActionsRecursively() {
3979
4302
  blueprintId: blueprintId,
3980
4303
  runId: runId,
3981
4304
  ctx: ctx,
3982
- blueprintActionKVMap: blueprintActionKVMap
4305
+ blueprintActionKVMap: blueprintActionKVMap,
4306
+ logger: logger
3983
4307
  });
3984
4308
  case 22:
3985
4309
  executorResult = _context.sent;
@@ -4026,7 +4350,12 @@ function _runActionsRecursively() {
4026
4350
  _context2.next = 32;
4027
4351
  break;
4028
4352
  }
4029
- 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
+ });
4030
4359
  // run default branch if available
4031
4360
  defaultCondition = action.condition.find(function (c) {
4032
4361
  return c.isDefault;
@@ -4038,7 +4367,12 @@ function _runActionsRecursively() {
4038
4367
  _context2.next = 30;
4039
4368
  break;
4040
4369
  }
4041
- 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
+ });
4042
4376
  _context2.next = 26;
4043
4377
  return runActionsRecursively({
4044
4378
  blueprintActions: [defaultAction],
@@ -4048,7 +4382,8 @@ function _runActionsRecursively() {
4048
4382
  runId: runId,
4049
4383
  ctx: ctx,
4050
4384
  blueprintId: blueprintId,
4051
- blueprintActionKVMap: blueprintActionKVMap
4385
+ blueprintActionKVMap: blueprintActionKVMap,
4386
+ logger: logger
4052
4387
  });
4053
4388
  case 26:
4054
4389
  _context2.t1 = _context2.sent;
@@ -4056,7 +4391,12 @@ function _runActionsRecursively() {
4056
4391
  v: _context2.t1
4057
4392
  });
4058
4393
  case 30:
4059
- 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
+ });
4060
4400
  return _context2.abrupt("return", {
4061
4401
  v: false
4062
4402
  });
@@ -4066,7 +4406,12 @@ function _runActionsRecursively() {
4066
4406
  _context2.next = 36;
4067
4407
  break;
4068
4408
  }
4069
- 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
+ });
4070
4415
  return _context2.abrupt("return", 0);
4071
4416
  case 36:
4072
4417
  _ref9 = action.payload || {}, mastraConnectionId = _ref9.mastraConnectionId, actionPayload = _objectWithoutPropertiesLoose(_ref9, _excluded);
@@ -4103,14 +4448,24 @@ function _runActionsRecursively() {
4103
4448
  });
4104
4449
  case 49:
4105
4450
  executorResult = _context2.sent;
4106
- 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
+ });
4107
4458
  _context2.next = 57;
4108
4459
  break;
4109
4460
  case 53:
4110
4461
  _context2.prev = 53;
4111
4462
  _context2.t2 = _context2["catch"](46);
4112
- console.log('===Error executing action===', {
4113
- 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
+ })
4114
4469
  });
4115
4470
  // TODO: Update workflows runs for failed actions
4116
4471
  return _context2.abrupt("return", {
@@ -4136,7 +4491,8 @@ function _runActionsRecursively() {
4136
4491
  runId: runId,
4137
4492
  ctx: ctx,
4138
4493
  blueprintId: blueprintId,
4139
- blueprintActionKVMap: blueprintActionKVMap
4494
+ blueprintActionKVMap: blueprintActionKVMap,
4495
+ logger: logger
4140
4496
  });
4141
4497
  case 63:
4142
4498
  _context2.t3 = _context2.sent;
@@ -4188,12 +4544,22 @@ function blueprintRunner(_x2) {
4188
4544
  function _blueprintRunner() {
4189
4545
  _blueprintRunner = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
4190
4546
  var _fullCtx, _blueprint$trigger;
4191
- 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;
4192
4548
  return _regeneratorRuntime().wrap(function _callee2$(_context4) {
4193
4549
  while (1) switch (_context4.prev = _context4.next) {
4194
4550
  case 0:
4195
- 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;
4196
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
+ });
4197
4563
  fullCtx = (_fullCtx = {}, _fullCtx[blueprint.trigger.id] = dataCtx, _fullCtx);
4198
4564
  triggerCondition = blueprint.trigger.condition;
4199
4565
  concreteTrigger = frameworkEvents[blueprint.trigger.type || ''];
@@ -4226,10 +4592,16 @@ function _blueprintRunner() {
4226
4592
  _context4.next = 16;
4227
4593
  break;
4228
4594
  }
4595
+ logger.info({
4596
+ destinationPath: "" + blueprint.id,
4597
+ message: JSON.stringify({
4598
+ message: 'Workflow run skipped'
4599
+ })
4600
+ });
4229
4601
  return _context4.abrupt("return");
4230
4602
  case 16:
4231
4603
  blueprintActionKVMap = constructWorkflowContextBluePrint(blueprint);
4232
- _context4.next = 20;
4604
+ _context4.next = 19;
4233
4605
  return runActionsRecursively({
4234
4606
  blueprintActions: blueprint.actions,
4235
4607
  frameworkApis: frameworkApis,
@@ -4238,21 +4610,27 @@ function _blueprintRunner() {
4238
4610
  dataContext: fullCtx,
4239
4611
  blueprintActionKVMap: blueprintActionKVMap,
4240
4612
  blueprintId: blueprint.id,
4241
- runId: ''
4613
+ runId: '',
4614
+ logger: logger
4242
4615
  });
4243
- case 20:
4616
+ case 19:
4244
4617
  ranSuccessfully = _context4.sent;
4245
- try {
4246
- if (ranSuccessfully) {
4247
- // await automationRunService.updateAutomationRun({
4248
- // runId: blueprintRun?.id || '',
4249
- // blueprintId: blueprint.id,
4250
- // completedAt: new Date(),
4251
- // status: AutomationRunStatus.COMPLETED,
4252
- // });
4253
- }
4254
- } catch (e) {}
4255
- 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:
4256
4634
  case "end":
4257
4635
  return _context4.stop();
4258
4636
  }
@@ -4694,139 +5072,127 @@ function getVectorProvider(provider) {
4694
5072
  return Pinecone;
4695
5073
  }
4696
5074
  }
4697
- var delay$1 = function delay(ms) {
4698
- return new Promise(function (resolve) {
4699
- return setTimeout(resolve, ms);
4700
- });
4701
- };
4702
- function executeIndexSync(_x) {
4703
- return _executeIndexSync.apply(this, arguments);
4704
- }
4705
- //Generic vector sync from event data
4706
- function _executeIndexSync() {
4707
- _executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref) {
4708
- var _event$user, _event$data;
4709
- var event, mastra, connectionId, providedIndexes, systemName, _iterator2, _step2, _step2$value, provider, indexes, vp, _loop2, _ret2, _iterator3, _step3;
4710
- return _regeneratorRuntime().wrap(function _callee6$(_context8) {
4711
- 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) {
4712
5081
  case 0:
4713
- event = _ref.event, mastra = _ref.mastra;
4714
- connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
4715
- providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
4716
- systemName = mastra.config.name;
4717
- _iterator2 = _createForOfIteratorHelperLoose(providedIndexes);
4718
- case 5:
4719
- if ((_step2 = _iterator2()).done) {
4720
- _context8.next = 25;
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;
4721
5087
  break;
4722
5088
  }
4723
- _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;
4724
5090
  vp = getVectorProvider(provider);
4725
5091
  if (vp) {
4726
- _context8.next = 11;
5092
+ _context5.next = 8;
4727
5093
  break;
4728
5094
  }
4729
5095
  console.error('UNSUPPORTED VECTOR PROVIDER', provider);
4730
- return _context8.abrupt("return");
4731
- case 11:
5096
+ return _context5.abrupt("return");
5097
+ case 8:
4732
5098
  if (process.env.OPENAI_API_KEY) {
4733
- _context8.next = 14;
5099
+ _context5.next = 11;
4734
5100
  break;
4735
5101
  }
4736
5102
  console.error('NO OPENAI_API_KEY');
4737
- return _context8.abrupt("return");
4738
- case 14:
4739
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
4740
- var index, getPineconeIndexWithMetadata, indexMetadata, _loop3, _ret3, _iterator4, _step4;
4741
- return _regeneratorRuntime().wrap(function _loop2$(_context7) {
4742
- 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) {
4743
5109
  case 0:
4744
- index = _step3.value;
5110
+ index = _step2.value;
4745
5111
  getPineconeIndexWithMetadata = /*#__PURE__*/function () {
4746
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
5112
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4747
5113
  var res;
4748
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4749
- while (1) switch (_context4.prev = _context4.next) {
5114
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
5115
+ while (1) switch (_context.prev = _context.next) {
4750
5116
  case 0:
4751
- _context4.prev = 0;
4752
- _context4.next = 3;
5117
+ _context.prev = 0;
5118
+ _context.next = 3;
4753
5119
  return mastra.vectorLayer.getPineconeIndexWithMetadata({
4754
5120
  name: index
4755
5121
  });
4756
5122
  case 3:
4757
- res = _context4.sent;
4758
- if (res.length) {
4759
- _context4.next = 6;
5123
+ res = _context.sent;
5124
+ if (res != null && res.length) {
5125
+ _context.next = 6;
4760
5126
  break;
4761
5127
  }
4762
5128
  throw new Error('No index metadata found');
4763
5129
  case 6:
4764
- return _context4.abrupt("return", res);
5130
+ return _context.abrupt("return", res);
4765
5131
  case 9:
4766
- _context4.prev = 9;
4767
- _context4.t0 = _context4["catch"](0);
4768
- throw new Error(_context4.t0);
5132
+ _context.prev = 9;
5133
+ _context.t0 = _context["catch"](0);
5134
+ throw new Error(_context.t0);
4769
5135
  case 12:
4770
5136
  case "end":
4771
- return _context4.stop();
5137
+ return _context.stop();
4772
5138
  }
4773
- }, _callee4, null, [[0, 9]]);
5139
+ }, _callee, null, [[0, 9]]);
4774
5140
  }));
4775
5141
  return function getPineconeIndexWithMetadata() {
4776
- return _ref9.apply(this, arguments);
5142
+ return _ref3.apply(this, arguments);
4777
5143
  };
4778
5144
  }();
4779
- _context7.next = 4;
5145
+ _context4.next = 4;
4780
5146
  return retryFn(getPineconeIndexWithMetadata);
4781
5147
  case 4:
4782
- indexMetadata = _context7.sent;
5148
+ indexMetadata = _context4.sent;
4783
5149
  if (indexMetadata != null && indexMetadata.length) {
4784
- _context7.next = 8;
5150
+ _context4.next = 8;
4785
5151
  break;
4786
5152
  }
4787
5153
  console.error('No index metadata found for', index);
4788
- return _context7.abrupt("return", {
5154
+ return _context4.abrupt("return", {
4789
5155
  v: void 0
4790
5156
  });
4791
5157
  case 8:
4792
- _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
5158
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
4793
5159
  var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
4794
- 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;
4795
- return _regeneratorRuntime().wrap(function _loop3$(_context6) {
4796
- while (1) switch (_context6.prev = _context6.next) {
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) {
4797
5163
  case 0:
4798
- entity = _step4.value;
4799
- fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
4800
- _context6.next = 4;
5164
+ entity = _step3.value;
5165
+ fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent, syncParams = entity.syncParams;
5166
+ _context3.next = 4;
4801
5167
  return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
4802
5168
  connectionId: connectionId,
4803
5169
  name: integration
4804
5170
  });
4805
5171
  case 4:
4806
- _context6.t1 = _yield$mastra$dataLay = _context6.sent;
4807
- if (!(_context6.t1 == null)) {
4808
- _context6.next = 9;
5172
+ _context3.t1 = _yield$mastra$dataLay = _context3.sent;
5173
+ if (!(_context3.t1 == null)) {
5174
+ _context3.next = 9;
4809
5175
  break;
4810
5176
  }
4811
- _context6.t2 = void 0;
4812
- _context6.next = 10;
5177
+ _context3.t2 = void 0;
5178
+ _context3.next = 10;
4813
5179
  break;
4814
5180
  case 9:
4815
- _context6.t2 = _yield$mastra$dataLay.id;
5181
+ _context3.t2 = _yield$mastra$dataLay.id;
4816
5182
  case 10:
4817
- _context6.t0 = _context6.t2;
4818
- if (_context6.t0) {
4819
- _context6.next = 13;
5183
+ _context3.t0 = _context3.t2;
5184
+ if (_context3.t0) {
5185
+ _context3.next = 13;
4820
5186
  break;
4821
5187
  }
4822
- _context6.t0 = '';
5188
+ _context3.t0 = '';
4823
5189
  case 13:
4824
- k_id = _context6.t0;
4825
- if (!(!k_id && integration === systemName)) {
4826
- _context6.next = 19;
5190
+ k_id = _context3.t0;
5191
+ if (!(!k_id && integration === mastra.config.name)) {
5192
+ _context3.next = 19;
4827
5193
  break;
4828
5194
  }
4829
- _context6.next = 17;
5195
+ _context3.next = 17;
4830
5196
  return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
4831
5197
  connection: {
4832
5198
  connectionId: connectionId,
@@ -4839,843 +5205,409 @@ function _executeIndexSync() {
4839
5205
  }
4840
5206
  });
4841
5207
  case 17:
4842
- connection = _context6.sent;
5208
+ connection = _context3.sent;
4843
5209
  k_id = connection.id;
4844
5210
  case 19:
4845
5211
  if (k_id) {
4846
- _context6.next = 22;
5212
+ _context3.next = 22;
4847
5213
  break;
4848
5214
  }
4849
5215
  console.error('Error bootstrapping shit');
4850
- return _context6.abrupt("return", {
5216
+ return _context3.abrupt("return", {
4851
5217
  v: {
4852
5218
  v: void 0
4853
5219
  }
4854
5220
  });
4855
5221
  case 22:
4856
- _context6.next = 24;
5222
+ _context3.next = 24;
4857
5223
  return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
4858
5224
  k_id: k_id,
4859
- type: name
5225
+ type: name.toUpperCase()
4860
5226
  });
4861
5227
  case 24:
4862
- entityRecords = _context6.sent;
5228
+ entityRecords = _context3.sent;
4863
5229
  records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
4864
5230
  if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
4865
- _context6.next = 44;
5231
+ _context3.next = 46;
4866
5232
  break;
4867
5233
  }
4868
5234
  console.error('NO RECORDS ATTEMPTING SYNC');
4869
- _context6.next = 30;
5235
+ data = JSON.parse(Buffer.from(syncParams, 'base64').toString());
5236
+ console.log('sync data====', {
5237
+ data: data
5238
+ });
5239
+ _context3.next = 32;
4870
5240
  return mastra.triggerEvent({
4871
5241
  key: syncEvent,
4872
- data: {},
5242
+ data: data,
4873
5243
  user: {
4874
5244
  connectionId: connectionId
4875
5245
  }
4876
5246
  });
4877
- case 30:
4878
- _yield$mastra$trigger = _context6.sent;
4879
- _event = _yield$mastra$trigger.event;
4880
- console.log(_event, '####');
4881
- _context6.next = 35;
4882
- return _event.subscribe();
4883
- case 35:
4884
- res = _context6.sent;
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;
4885
5255
  console.log('Subscribe result', res);
4886
- _context6.next = 39;
5256
+ _context3.next = 41;
4887
5257
  return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
4888
5258
  k_id: k_id,
4889
- type: entity.name
5259
+ type: entity.name.toUpperCase()
4890
5260
  });
4891
- case 39:
4892
- entityRecords = _context6.sent;
5261
+ case 41:
5262
+ entityRecords = _context3.sent;
4893
5263
  records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
4894
5264
  if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
4895
- _context6.next = 44;
5265
+ _context3.next = 46;
4896
5266
  break;
4897
5267
  }
4898
5268
  console.error('NO RECORDS AFTER SYNC');
4899
- return _context6.abrupt("return", {
5269
+ return _context3.abrupt("return", {
4900
5270
  v: {
4901
5271
  v: void 0
4902
5272
  }
4903
5273
  });
4904
- case 44:
4905
- recordsMapped = records.map(function (_ref10) {
4906
- var data = _ref10.data,
4907
- externalId = _ref10.externalId;
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);
4908
5280
  return _extends({
4909
- id: externalId
4910
- }, _.pick(data, fields));
5281
+ id: String(externalId)
5282
+ }, stringifiedData);
4911
5283
  });
4912
5284
  console.log(recordsMapped, 'RECORDS');
4913
5285
  entityTypeIndex = vp.index(index);
4914
5286
  console.log(entityTypeIndex, 'INDEX');
4915
- _context6.prev = 48;
4916
- _context6.next = 51;
5287
+ _context3.prev = 50;
5288
+ _context3.next = 53;
4917
5289
  return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
4918
- var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record) {
5290
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(record) {
4919
5291
  var _yield$embed, embedding;
4920
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4921
- while (1) switch (_context5.prev = _context5.next) {
5292
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
5293
+ while (1) switch (_context2.prev = _context2.next) {
4922
5294
  case 0:
4923
- _context5.next = 2;
5295
+ _context2.next = 2;
4924
5296
  return ai.embed({
4925
5297
  model: openai.openai.embedding('text-embedding-3-small'),
4926
5298
  value: JSON.stringify(record)
4927
5299
  });
4928
5300
  case 2:
4929
- _yield$embed = _context5.sent;
5301
+ _yield$embed = _context2.sent;
4930
5302
  embedding = _yield$embed.embedding;
4931
- return _context5.abrupt("return", {
5303
+ return _context2.abrupt("return", {
4932
5304
  id: record.id,
4933
5305
  values: embedding,
4934
5306
  metadata: record
4935
5307
  });
4936
5308
  case 5:
4937
5309
  case "end":
4938
- return _context5.stop();
5310
+ return _context2.stop();
4939
5311
  }
4940
- }, _callee5);
5312
+ }, _callee2);
4941
5313
  }));
4942
- return function (_x7) {
4943
- return _ref11.apply(this, arguments);
5314
+ return function (_x2) {
5315
+ return _ref5.apply(this, arguments);
4944
5316
  };
4945
5317
  }())) != null ? _recordsMapped$map : []);
4946
- case 51:
4947
- vectors = _context6.sent;
5318
+ case 53:
5319
+ vectors = _context3.sent;
4948
5320
  console.log('UPSERTING', vectors);
4949
5321
  if (!(vectors.length > 0)) {
4950
- _context6.next = 56;
5322
+ _context3.next = 58;
4951
5323
  break;
4952
5324
  }
4953
- _context6.next = 56;
5325
+ _context3.next = 58;
4954
5326
  return entityTypeIndex.namespace(name).upsert(vectors);
4955
- case 56:
4956
- _context6.next = 61;
4957
- break;
4958
5327
  case 58:
4959
- _context6.prev = 58;
4960
- _context6.t3 = _context6["catch"](48);
4961
- console.error(_context6.t3);
4962
- case 61:
4963
- return _context6.abrupt("return", {
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", {
4964
5336
  v: {
4965
5337
  v: void 0
4966
5338
  }
4967
5339
  });
4968
- case 62:
5340
+ case 64:
4969
5341
  case "end":
4970
- return _context6.stop();
5342
+ return _context3.stop();
4971
5343
  }
4972
- }, _loop3, null, [[48, 58]]);
5344
+ }, _loop2, null, [[50, 60]]);
4973
5345
  });
4974
- _iterator4 = _createForOfIteratorHelperLoose(indexMetadata);
5346
+ _iterator3 = _createForOfIteratorHelperLoose(indexMetadata);
4975
5347
  case 10:
4976
- if ((_step4 = _iterator4()).done) {
4977
- _context7.next = 17;
5348
+ if ((_step3 = _iterator3()).done) {
5349
+ _context4.next = 17;
4978
5350
  break;
4979
5351
  }
4980
- return _context7.delegateYield(_loop3(), "t0", 12);
5352
+ return _context4.delegateYield(_loop2(), "t0", 12);
4981
5353
  case 12:
4982
- _ret3 = _context7.t0;
4983
- if (!_ret3) {
4984
- _context7.next = 15;
5354
+ _ret2 = _context4.t0;
5355
+ if (!_ret2) {
5356
+ _context4.next = 15;
4985
5357
  break;
4986
5358
  }
4987
- return _context7.abrupt("return", _ret3.v);
5359
+ return _context4.abrupt("return", _ret2.v);
4988
5360
  case 15:
4989
- _context7.next = 10;
5361
+ _context4.next = 10;
4990
5362
  break;
4991
5363
  case 17:
4992
5364
  case "end":
4993
- return _context7.stop();
5365
+ return _context4.stop();
4994
5366
  }
4995
- }, _loop2);
5367
+ }, _loop);
4996
5368
  });
4997
- _iterator3 = _createForOfIteratorHelperLoose(indexes);
4998
- case 16:
4999
- if ((_step3 = _iterator3()).done) {
5000
- _context8.next = 23;
5369
+ _iterator2 = _createForOfIteratorHelperLoose(indexes);
5370
+ case 13:
5371
+ if ((_step2 = _iterator2()).done) {
5372
+ _context5.next = 20;
5001
5373
  break;
5002
5374
  }
5003
- return _context8.delegateYield(_loop2(), "t0", 18);
5004
- case 18:
5005
- _ret2 = _context8.t0;
5006
- if (!_ret2) {
5007
- _context8.next = 21;
5375
+ return _context5.delegateYield(_loop(), "t0", 15);
5376
+ case 15:
5377
+ _ret = _context5.t0;
5378
+ if (!_ret) {
5379
+ _context5.next = 18;
5008
5380
  break;
5009
5381
  }
5010
- return _context8.abrupt("return", _ret2.v);
5011
- case 21:
5012
- _context8.next = 16;
5382
+ return _context5.abrupt("return", _ret.v);
5383
+ case 18:
5384
+ _context5.next = 13;
5013
5385
  break;
5014
- case 23:
5015
- _context8.next = 5;
5386
+ case 20:
5387
+ _context5.next = 2;
5016
5388
  break;
5017
- case 25:
5389
+ case 22:
5018
5390
  case "end":
5019
- return _context8.stop();
5391
+ return _context5.stop();
5020
5392
  }
5021
- }, _callee6);
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:
5423
+ case "end":
5424
+ return _context9.stop();
5425
+ }
5426
+ }, _callee7);
5022
5427
  }));
5023
5428
  return _executeIndexSync.apply(this, arguments);
5024
5429
  }
5025
- function executeGenericVectorSync(_x2) {
5430
+ function executeGenericVectorSync(_x4) {
5026
5431
  return _executeGenericVectorSync.apply(this, arguments);
5027
5432
  }
5028
5433
  // Vector Sync from agents Dir
5029
5434
  function _executeGenericVectorSync() {
5030
- _executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref2) {
5031
- var _event$user2, _event$data2, _event$data3;
5032
- var event, mastra, connectionId, vector_provider, entities, systemName, vp, _iterator5, _step5, _yield$mastra$dataLay2, _mastra$dataLayer5, vectorE, integrationName, k_id, _mastra$dataLayer6, connection, _loop4, _ret4, _iterator6, _step6;
5033
- return _regeneratorRuntime().wrap(function _callee8$(_context11) {
5034
- 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) {
5035
5440
  case 0:
5036
- event = _ref2.event, mastra = _ref2.mastra;
5441
+ event = _ref7.event, mastra = _ref7.mastra;
5037
5442
  connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
5038
- vector_provider = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.vector_provider;
5039
- entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
5040
- systemName = mastra.config.name;
5041
- if (vector_provider) {
5042
- _context11.next = 8;
5043
- break;
5044
- }
5045
- console.error("No vector_provider defined for agent");
5046
- return _context11.abrupt("return");
5047
- case 8:
5443
+ entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
5444
+ _context10.next = 5;
5445
+ return indexSync({
5446
+ connectionId: connectionId,
5447
+ knowledgeSource: entities,
5448
+ mastra: mastra
5449
+ });
5450
+ case 5:
5451
+ return _context10.abrupt("return", _context10.sent);
5452
+ case 6:
5453
+ case "end":
5454
+ return _context10.stop();
5455
+ }
5456
+ }, _callee8);
5457
+ }));
5458
+ return _executeGenericVectorSync.apply(this, arguments);
5459
+ }
5460
+ function executeVectorSync(_x5) {
5461
+ return _executeVectorSync.apply(this, arguments);
5462
+ }
5463
+ function _executeVectorSync() {
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) {
5469
+ case 0:
5470
+ event = _ref8.event, mastra = _ref8.mastra;
5471
+ agentDir = mastra.config.agents.agentDirPath;
5472
+ agent = getAgentBlueprint({
5473
+ agentDir: agentDir,
5474
+ agentId: event.data.agentId
5475
+ });
5476
+ connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
5477
+ _context11.next = 6;
5478
+ return indexSync({
5479
+ connectionId: connectionId,
5480
+ knowledgeSource: agent == null ? void 0 : agent.knowledge_sources,
5481
+ mastra: mastra
5482
+ });
5483
+ case 6:
5484
+ return _context11.abrupt("return", _context11.sent);
5485
+ case 7:
5486
+ case "end":
5487
+ return _context11.stop();
5488
+ }
5489
+ }, _callee9);
5490
+ }));
5491
+ return _executeVectorSync.apply(this, arguments);
5492
+ }
5493
+ function vectorQueryEngine(_x6) {
5494
+ return _vectorQueryEngine.apply(this, arguments);
5495
+ }
5496
+ function _vectorQueryEngine() {
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) {
5501
+ case 0:
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;
5048
5503
  vp = getVectorProvider(vector_provider);
5049
5504
  if (vp) {
5050
- _context11.next = 12;
5505
+ _context12.next = 5;
5051
5506
  break;
5052
5507
  }
5053
5508
  console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
5054
- return _context11.abrupt("return");
5055
- case 12:
5056
- if (process.env.OPENAI_API_KEY) {
5057
- _context11.next = 15;
5058
- break;
5059
- }
5060
- console.error('NO OPENAI_API_KEY');
5061
- return _context11.abrupt("return");
5062
- case 15:
5063
- _iterator5 = _createForOfIteratorHelperLoose(entities);
5064
- case 16:
5065
- if ((_step5 = _iterator5()).done) {
5066
- _context11.next = 50;
5067
- break;
5068
- }
5069
- vectorE = _step5.value;
5070
- integrationName = vectorE.integration;
5071
- _context11.next = 21;
5072
- return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
5073
- connectionId: connectionId,
5074
- name: integrationName
5509
+ return _context12.abrupt("return");
5510
+ case 5:
5511
+ index = vp.index(indexName);
5512
+ _context12.next = 8;
5513
+ return ai.embed({
5514
+ model: openai.openai.embedding('text-embedding-3-small'),
5515
+ value: content
5075
5516
  });
5076
- case 21:
5077
- _context11.t1 = _yield$mastra$dataLay2 = _context11.sent;
5078
- if (!(_context11.t1 == null)) {
5079
- _context11.next = 26;
5080
- break;
5081
- }
5082
- _context11.t2 = void 0;
5083
- _context11.next = 27;
5084
- break;
5085
- case 26:
5086
- _context11.t2 = _yield$mastra$dataLay2.id;
5087
- case 27:
5088
- _context11.t0 = _context11.t2;
5089
- if (_context11.t0) {
5090
- _context11.next = 30;
5091
- break;
5092
- }
5093
- _context11.t0 = '';
5094
- case 30:
5095
- k_id = _context11.t0;
5096
- if (!(!k_id && integrationName === systemName)) {
5097
- _context11.next = 36;
5098
- break;
5099
- }
5100
- _context11.next = 34;
5101
- return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
5102
- connection: {
5103
- connectionId: connectionId,
5104
- name: integrationName
5105
- },
5106
- credential: {
5107
- type: 'API_KEY',
5108
- value: connectionId,
5109
- scope: []
5110
- }
5111
- });
5112
- case 34:
5113
- connection = _context11.sent;
5114
- k_id = connection.id;
5115
- case 36:
5116
- if (k_id) {
5117
- _context11.next = 39;
5118
- break;
5119
- }
5120
- console.error('Error bootstrapping shit');
5121
- return _context11.abrupt("return");
5122
- case 39:
5123
- _loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
5124
- var _mastra$dataLayer7, _entityRecords3, _records3;
5125
- var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
5126
- return _regeneratorRuntime().wrap(function _loop4$(_context10) {
5127
- while (1) switch (_context10.prev = _context10.next) {
5128
- case 0:
5129
- entity = _step6.value;
5130
- _context10.next = 3;
5131
- return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
5132
- k_id: k_id,
5133
- type: entity.name
5134
- });
5135
- case 3:
5136
- entityRecords = _context10.sent;
5137
- records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
5138
- if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
5139
- _context10.next = 23;
5140
- break;
5141
- }
5142
- // @TODO: SYNC THEM
5143
- console.error('NO RECORDS');
5144
- _context10.next = 9;
5145
- return mastra.triggerEvent({
5146
- key: entity.syncEvent,
5147
- data: {},
5148
- user: {
5149
- connectionId: connectionId
5150
- }
5151
- });
5152
- case 9:
5153
- _yield$mastra$trigger2 = _context10.sent;
5154
- _event2 = _yield$mastra$trigger2.event;
5155
- console.log(_event2, '####');
5156
- _context10.next = 14;
5157
- return _event2.subscribe();
5158
- case 14:
5159
- res = _context10.sent;
5160
- console.log('Subscribe result', res);
5161
- _context10.next = 18;
5162
- return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
5163
- k_id: k_id,
5164
- type: entity.name
5165
- });
5166
- case 18:
5167
- entityRecords = _context10.sent;
5168
- records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
5169
- if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
5170
- _context10.next = 23;
5171
- break;
5172
- }
5173
- console.error('NO RECORDS AFTER SYNC');
5174
- return _context10.abrupt("return", {
5175
- v: void 0
5176
- });
5177
- case 23:
5178
- recordsMapped = records.map(function (_ref12) {
5179
- var data = _ref12.data,
5180
- externalId = _ref12.externalId;
5181
- return _extends({
5182
- id: externalId
5183
- }, _.pick(data, entity.fields));
5184
- });
5185
- console.log(recordsMapped, 'RECORDS');
5186
- _context10.next = 27;
5187
- return vp.createIndex({
5188
- suppressConflicts: true,
5189
- name: entity.name,
5190
- dimension: 1536,
5191
- metric: 'cosine',
5192
- spec: {
5193
- serverless: {
5194
- cloud: 'aws',
5195
- region: 'us-east-1'
5196
- }
5197
- }
5198
- });
5199
- case 27:
5200
- _context10.next = 29;
5201
- return delay$1(5000);
5202
- case 29:
5203
- entityTypeIndex = vp.index(entity.name);
5204
- console.log(entityTypeIndex, 'INDEX');
5205
- _context10.prev = 31;
5206
- _context10.next = 34;
5207
- return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
5208
- var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(record) {
5209
- var _yield$embed2, embedding;
5210
- return _regeneratorRuntime().wrap(function _callee7$(_context9) {
5211
- while (1) switch (_context9.prev = _context9.next) {
5212
- case 0:
5213
- _context9.next = 2;
5214
- return ai.embed({
5215
- model: openai.openai.embedding('text-embedding-3-small'),
5216
- value: JSON.stringify(record)
5217
- });
5218
- case 2:
5219
- _yield$embed2 = _context9.sent;
5220
- embedding = _yield$embed2.embedding;
5221
- return _context9.abrupt("return", {
5222
- id: record.id,
5223
- values: embedding,
5224
- metadata: record
5225
- });
5226
- case 5:
5227
- case "end":
5228
- return _context9.stop();
5229
- }
5230
- }, _callee7);
5231
- }));
5232
- return function (_x8) {
5233
- return _ref13.apply(this, arguments);
5234
- };
5235
- }())) != null ? _recordsMapped$map2 : []);
5236
- case 34:
5237
- vectors = _context10.sent;
5238
- console.log('UPSERTING', vectors);
5239
- if (!(vectors.length > 0)) {
5240
- _context10.next = 39;
5241
- break;
5242
- }
5243
- _context10.next = 39;
5244
- return entityTypeIndex.namespace(entity.name).upsert(vectors);
5245
- case 39:
5246
- _context10.next = 44;
5247
- break;
5248
- case 41:
5249
- _context10.prev = 41;
5250
- _context10.t0 = _context10["catch"](31);
5251
- console.error(_context10.t0);
5252
- case 44:
5253
- return _context10.abrupt("return", {
5254
- v: void 0
5255
- });
5256
- case 45:
5257
- case "end":
5258
- return _context10.stop();
5259
- }
5260
- }, _loop4, null, [[31, 41]]);
5261
- });
5262
- _iterator6 = _createForOfIteratorHelperLoose(vectorE.data);
5263
- case 41:
5264
- if ((_step6 = _iterator6()).done) {
5265
- _context11.next = 48;
5266
- break;
5267
- }
5268
- return _context11.delegateYield(_loop4(), "t3", 43);
5269
- case 43:
5270
- _ret4 = _context11.t3;
5271
- if (!_ret4) {
5272
- _context11.next = 46;
5273
- break;
5274
- }
5275
- return _context11.abrupt("return", _ret4.v);
5276
- case 46:
5277
- _context11.next = 41;
5278
- break;
5279
- case 48:
5280
- _context11.next = 16;
5281
- break;
5282
- case 50:
5283
- case "end":
5284
- return _context11.stop();
5285
- }
5286
- }, _callee8);
5287
- }));
5288
- return _executeGenericVectorSync.apply(this, arguments);
5289
- }
5290
- function executeVectorSync(_x3) {
5291
- return _executeVectorSync.apply(this, arguments);
5292
- }
5293
- function _executeVectorSync() {
5294
- _executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref3) {
5295
- var _event$user3, _agent$knowledge_sour;
5296
- 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, _loop5, _ret5, _iterator8, _step8;
5297
- return _regeneratorRuntime().wrap(function _callee10$(_context14) {
5298
- while (1) switch (_context14.prev = _context14.next) {
5299
- case 0:
5300
- event = _ref3.event, mastra = _ref3.mastra;
5301
- agentDir = mastra.config.agents.agentDirPath;
5302
- agent = getAgentBlueprint({
5303
- agentDir: agentDir,
5304
- agentId: event.data.agentId
5305
- });
5306
- connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
5307
- systemName = mastra.config.name;
5308
- if (agent.knowledge_sources.vector_provider) {
5309
- _context14.next = 8;
5310
- break;
5311
- }
5312
- console.error("No vector_provider defined for agent");
5313
- return _context14.abrupt("return");
5314
5517
  case 8:
5315
- vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
5316
- if (vp) {
5317
- _context14.next = 12;
5318
- break;
5319
- }
5320
- console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
5321
- return _context14.abrupt("return");
5322
- case 12:
5323
- if (process.env.OPENAI_API_KEY) {
5324
- _context14.next = 15;
5325
- break;
5326
- }
5327
- console.error('NO OPENAI_API_KEY');
5328
- return _context14.abrupt("return");
5329
- case 15:
5330
- if (!(!agent || !(agent != null && agent.knowledge_sources))) {
5331
- _context14.next = 18;
5332
- break;
5333
- }
5334
- console.error('NO AGENT OR KNOWLEDGE SOURCES');
5335
- return _context14.abrupt("return");
5336
- case 18:
5337
- _iterator7 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
5338
- case 19:
5339
- if ((_step7 = _iterator7()).done) {
5340
- _context14.next = 53;
5341
- break;
5342
- }
5343
- vectorE = _step7.value;
5344
- integrationName = vectorE.integration;
5345
- _context14.next = 24;
5346
- return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
5347
- connectionId: connectionId,
5348
- name: integrationName
5349
- });
5350
- case 24:
5351
- _context14.t1 = _yield$mastra$dataLay3 = _context14.sent;
5352
- if (!(_context14.t1 == null)) {
5353
- _context14.next = 29;
5354
- break;
5355
- }
5356
- _context14.t2 = void 0;
5357
- _context14.next = 30;
5358
- break;
5359
- case 29:
5360
- _context14.t2 = _yield$mastra$dataLay3.id;
5361
- case 30:
5362
- _context14.t0 = _context14.t2;
5363
- if (_context14.t0) {
5364
- _context14.next = 33;
5365
- break;
5366
- }
5367
- _context14.t0 = '';
5368
- case 33:
5369
- k_id = _context14.t0;
5370
- if (!(!k_id && integrationName === systemName)) {
5371
- _context14.next = 39;
5372
- break;
5373
- }
5374
- _context14.next = 37;
5375
- return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
5376
- connection: {
5377
- connectionId: connectionId,
5378
- name: integrationName
5379
- },
5380
- credential: {
5381
- type: 'API_KEY',
5382
- value: connectionId,
5383
- scope: []
5384
- }
5385
- });
5386
- case 37:
5387
- connection = _context14.sent;
5388
- k_id = connection.id;
5389
- case 39:
5390
- if (k_id) {
5391
- _context14.next = 42;
5392
- break;
5393
- }
5394
- console.error('Error bootstrapping shit');
5395
- return _context14.abrupt("return");
5396
- case 42:
5397
- _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
5398
- var _mastra$dataLayer11, _entityRecords5, _records5;
5399
- var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
5400
- return _regeneratorRuntime().wrap(function _loop5$(_context13) {
5401
- while (1) switch (_context13.prev = _context13.next) {
5402
- case 0:
5403
- entity = _step8.value;
5404
- _context13.next = 3;
5405
- return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
5406
- k_id: k_id,
5407
- type: entity.name
5408
- });
5409
- case 3:
5410
- entityRecords = _context13.sent;
5411
- records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
5412
- if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
5413
- _context13.next = 23;
5414
- break;
5415
- }
5416
- // @TODO: SYNC THEM
5417
- console.error('NO RECORDS');
5418
- _context13.next = 9;
5419
- return mastra.triggerEvent({
5420
- key: entity.syncEvent,
5421
- data: {},
5422
- user: {
5423
- connectionId: connectionId
5424
- }
5425
- });
5426
- case 9:
5427
- _yield$mastra$trigger3 = _context13.sent;
5428
- _event3 = _yield$mastra$trigger3.event;
5429
- console.log(_event3, '####');
5430
- _context13.next = 14;
5431
- return _event3.subscribe();
5432
- case 14:
5433
- res = _context13.sent;
5434
- console.log('Subscribe result', res);
5435
- _context13.next = 18;
5436
- return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
5437
- k_id: k_id,
5438
- type: entity.name
5439
- });
5440
- case 18:
5441
- entityRecords = _context13.sent;
5442
- records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
5443
- if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
5444
- _context13.next = 23;
5445
- break;
5446
- }
5447
- console.error('NO RECORDS AFTER SYNC');
5448
- return _context13.abrupt("return", {
5449
- v: void 0
5450
- });
5451
- case 23:
5452
- recordsMapped = records.map(function (_ref14) {
5453
- var data = _ref14.data,
5454
- externalId = _ref14.externalId;
5455
- return _extends({
5456
- id: externalId
5457
- }, _.pick(data, entity.fields));
5458
- });
5459
- console.log(recordsMapped, 'RECORDS');
5460
- _context13.next = 27;
5461
- return vp.createIndex({
5462
- suppressConflicts: true,
5463
- name: entity.name,
5464
- dimension: 1536,
5465
- metric: 'cosine',
5466
- spec: {
5467
- serverless: {
5468
- cloud: 'aws',
5469
- region: 'us-east-1'
5470
- }
5471
- }
5472
- });
5473
- case 27:
5474
- entityTypeIndex = vp.index(entity.name);
5475
- console.log(entityTypeIndex, 'INDEX');
5476
- _context13.prev = 29;
5477
- _context13.next = 32;
5478
- return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
5479
- var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
5480
- var _yield$embed3, embedding;
5481
- return _regeneratorRuntime().wrap(function _callee9$(_context12) {
5482
- while (1) switch (_context12.prev = _context12.next) {
5483
- case 0:
5484
- _context12.next = 2;
5485
- return ai.embed({
5486
- model: openai.openai.embedding('text-embedding-3-small'),
5487
- value: JSON.stringify(record)
5488
- });
5489
- case 2:
5490
- _yield$embed3 = _context12.sent;
5491
- embedding = _yield$embed3.embedding;
5492
- return _context12.abrupt("return", {
5493
- id: record.id,
5494
- values: embedding,
5495
- metadata: record
5496
- });
5497
- case 5:
5498
- case "end":
5499
- return _context12.stop();
5500
- }
5501
- }, _callee9);
5502
- }));
5503
- return function (_x9) {
5504
- return _ref15.apply(this, arguments);
5505
- };
5506
- }())) != null ? _recordsMapped$map3 : []);
5507
- case 32:
5508
- vectors = _context13.sent;
5509
- console.log('UPSERTING', vectors);
5510
- if (!(vectors.length > 0)) {
5511
- _context13.next = 37;
5512
- break;
5513
- }
5514
- _context13.next = 37;
5515
- return entityTypeIndex.namespace(entity.name).upsert(vectors);
5516
- case 37:
5517
- _context13.next = 42;
5518
- break;
5519
- case 39:
5520
- _context13.prev = 39;
5521
- _context13.t0 = _context13["catch"](29);
5522
- console.error(_context13.t0);
5523
- case 42:
5524
- return _context13.abrupt("return", {
5525
- v: void 0
5526
- });
5527
- case 43:
5528
- case "end":
5529
- return _context13.stop();
5530
- }
5531
- }, _loop5, null, [[29, 39]]);
5532
- });
5533
- _iterator8 = _createForOfIteratorHelperLoose(vectorE.data);
5534
- case 44:
5535
- if ((_step8 = _iterator8()).done) {
5536
- _context14.next = 51;
5537
- break;
5538
- }
5539
- return _context14.delegateYield(_loop5(), "t3", 46);
5540
- case 46:
5541
- _ret5 = _context14.t3;
5542
- if (!_ret5) {
5543
- _context14.next = 49;
5544
- break;
5545
- }
5546
- return _context14.abrupt("return", _ret5.v);
5547
- case 49:
5548
- _context14.next = 44;
5549
- break;
5550
- case 51:
5551
- _context14.next = 19;
5552
- break;
5553
- case 53:
5554
- case "end":
5555
- return _context14.stop();
5556
- }
5557
- }, _callee10);
5558
- }));
5559
- return _executeVectorSync.apply(this, arguments);
5560
- }
5561
- function vectorQueryEngine(_x4) {
5562
- return _vectorQueryEngine.apply(this, arguments);
5563
- }
5564
- function _vectorQueryEngine() {
5565
- _vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref4) {
5566
- var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
5567
- return _regeneratorRuntime().wrap(function _callee11$(_context15) {
5568
- while (1) switch (_context15.prev = _context15.next) {
5569
- case 0:
5570
- 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;
5571
- vp = getVectorProvider(vector_provider);
5572
- if (vp) {
5573
- _context15.next = 5;
5574
- break;
5575
- }
5576
- console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
5577
- return _context15.abrupt("return");
5578
- case 5:
5579
- index = vp.index(indexName);
5580
- _context15.next = 8;
5581
- return ai.embed({
5582
- model: openai.openai.embedding('text-embedding-3-small'),
5583
- value: content
5584
- });
5585
- case 8:
5586
- _yield$embed4 = _context15.sent;
5587
- embedding = _yield$embed4.embedding;
5518
+ _yield$embed2 = _context12.sent;
5519
+ embedding = _yield$embed2.embedding;
5588
5520
  console.log(embedding, 'EMBEDDING');
5589
- _context15.next = 13;
5521
+ _context12.next = 13;
5590
5522
  return index.namespace(entityType).query({
5591
5523
  vector: embedding,
5592
5524
  topK: topK,
5593
5525
  includeMetadata: true
5594
5526
  });
5595
5527
  case 13:
5596
- queryResponse = _context15.sent;
5597
- return _context15.abrupt("return", queryResponse);
5528
+ queryResponse = _context12.sent;
5529
+ return _context12.abrupt("return", queryResponse);
5598
5530
  case 15:
5599
5531
  case "end":
5600
- return _context15.stop();
5532
+ return _context12.stop();
5601
5533
  }
5602
- }, _callee11);
5534
+ }, _callee10);
5603
5535
  }));
5604
5536
  return _vectorQueryEngine.apply(this, arguments);
5605
5537
  }
5606
5538
  var getPineconeIndices = /*#__PURE__*/function () {
5607
- var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
5539
+ var _ref10 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
5608
5540
  var vectorLayer, indexes, indexesWithStats;
5609
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
5610
- while (1) switch (_context2.prev = _context2.next) {
5541
+ return _regeneratorRuntime().wrap(function _callee5$(_context7) {
5542
+ while (1) switch (_context7.prev = _context7.next) {
5611
5543
  case 0:
5612
5544
  vectorLayer = new VectorLayer();
5613
- _context2.next = 3;
5545
+ _context7.next = 3;
5614
5546
  return vectorLayer.fetchPineconeIndexes();
5615
5547
  case 3:
5616
- indexes = _context2.sent;
5548
+ indexes = _context7.sent;
5617
5549
  if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
5618
- _context2.next = 9;
5550
+ _context7.next = 9;
5619
5551
  break;
5620
5552
  }
5621
- _context2.next = 7;
5553
+ _context7.next = 7;
5622
5554
  return Promise.all(indexes.map(/*#__PURE__*/function () {
5623
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(index) {
5555
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index) {
5624
5556
  var stats, namespaces;
5625
- return _regeneratorRuntime().wrap(function _callee$(_context) {
5626
- while (1) switch (_context.prev = _context.next) {
5557
+ return _regeneratorRuntime().wrap(function _callee4$(_context6) {
5558
+ while (1) switch (_context6.prev = _context6.next) {
5627
5559
  case 0:
5628
- _context.next = 2;
5560
+ _context6.next = 2;
5629
5561
  return vectorLayer.fetchPineconeIndexStats(index.host);
5630
5562
  case 2:
5631
- stats = _context.sent;
5563
+ stats = _context6.sent;
5632
5564
  namespaces = [];
5633
5565
  if (stats != null && stats.namespaces) {
5634
5566
  namespaces = Object.keys(stats.namespaces);
5635
5567
  }
5636
- return _context.abrupt("return", _extends({}, index, {
5568
+ return _context6.abrupt("return", _extends({}, index, {
5637
5569
  namespaces: namespaces
5638
5570
  }));
5639
5571
  case 6:
5640
5572
  case "end":
5641
- return _context.stop();
5573
+ return _context6.stop();
5642
5574
  }
5643
- }, _callee);
5575
+ }, _callee4);
5644
5576
  }));
5645
- return function (_x5) {
5646
- return _ref6.apply(this, arguments);
5577
+ return function (_x7) {
5578
+ return _ref11.apply(this, arguments);
5647
5579
  };
5648
5580
  }()));
5649
5581
  case 7:
5650
- indexesWithStats = _context2.sent;
5651
- return _context2.abrupt("return", indexesWithStats);
5582
+ indexesWithStats = _context7.sent;
5583
+ return _context7.abrupt("return", indexesWithStats);
5652
5584
  case 9:
5653
- return _context2.abrupt("return", []);
5585
+ return _context7.abrupt("return", []);
5654
5586
  case 10:
5655
5587
  case "end":
5656
- return _context2.stop();
5588
+ return _context7.stop();
5657
5589
  }
5658
- }, _callee2);
5590
+ }, _callee5);
5659
5591
  }));
5660
5592
  return function getPineconeIndices() {
5661
- return _ref5.apply(this, arguments);
5593
+ return _ref10.apply(this, arguments);
5662
5594
  };
5663
5595
  }();
5664
- function getVectorQueryApis(_ref7) {
5665
- var mastra = _ref7.mastra;
5596
+ function getVectorQueryApis(_ref12) {
5597
+ var mastra = _ref12.mastra;
5666
5598
  var vectorProvider = mastra.config.agents.vectorProvider;
5667
5599
  if (!vectorProvider) {
5668
5600
  console.error('NO VECTOR PROVIDER');
5669
5601
  return [];
5670
5602
  }
5671
5603
  var vectorApis = [];
5672
- var _loop = function _loop() {
5673
- var provider = _step.value;
5604
+ var _loop3 = function _loop3() {
5605
+ var provider = _step4.value;
5674
5606
  if (provider.name.toUpperCase() === 'PINECONE') {
5675
5607
  var config = getPineconeConfig({
5676
5608
  dir: provider.dirPath
5677
5609
  });
5678
- if (!config) {
5610
+ if (!config || (config == null ? void 0 : config.length) === 0) {
5679
5611
  return {
5680
5612
  v: []
5681
5613
  };
@@ -5685,21 +5617,22 @@ function getVectorQueryApis(_ref7) {
5685
5617
  index == null || index.namespaces.forEach(function (namespace) {
5686
5618
  vectorApis.push({
5687
5619
  integrationName: mastra.config.name,
5688
- type: "vector_query_" + index.name + "_" + namespace,
5620
+ type: "vq_" + index.name + "_" + namespace,
5689
5621
  label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5690
5622
  description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5691
5623
  schema: zod.z.object({
5692
5624
  content: zod.z.string(),
5693
5625
  topResult: zod.z.number()
5694
5626
  }),
5627
+ source: provider.name.toUpperCase(),
5695
5628
  executor: function () {
5696
- var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
5629
+ var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref13) {
5697
5630
  var data, res;
5698
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
5699
- while (1) switch (_context3.prev = _context3.next) {
5631
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
5632
+ while (1) switch (_context8.prev = _context8.next) {
5700
5633
  case 0:
5701
- data = _ref8.data;
5702
- _context3.next = 3;
5634
+ data = _ref13.data;
5635
+ _context8.next = 3;
5703
5636
  return vectorQueryEngine({
5704
5637
  vector_provider: provider.name,
5705
5638
  indexName: index.name,
@@ -5708,19 +5641,19 @@ function getVectorQueryApis(_ref7) {
5708
5641
  entityType: namespace
5709
5642
  });
5710
5643
  case 3:
5711
- res = _context3.sent;
5644
+ res = _context8.sent;
5712
5645
  console.log(JSON.stringify({
5713
5646
  res: res
5714
5647
  }, null, 2));
5715
5648
  // @TODO: make this a proper response
5716
- return _context3.abrupt("return", res);
5649
+ return _context8.abrupt("return", res);
5717
5650
  case 6:
5718
5651
  case "end":
5719
- return _context3.stop();
5652
+ return _context8.stop();
5720
5653
  }
5721
- }, _callee3);
5654
+ }, _callee6);
5722
5655
  }));
5723
- function executor(_x6) {
5656
+ function executor(_x8) {
5724
5657
  return _executor.apply(this, arguments);
5725
5658
  }
5726
5659
  return executor;
@@ -5731,10 +5664,10 @@ function getVectorQueryApis(_ref7) {
5731
5664
  });
5732
5665
  }
5733
5666
  },
5734
- _ret;
5735
- for (var _iterator = _createForOfIteratorHelperLoose(vectorProvider), _step; !(_step = _iterator()).done;) {
5736
- _ret = _loop();
5737
- if (_ret) return _ret.v;
5667
+ _ret3;
5668
+ for (var _iterator4 = _createForOfIteratorHelperLoose(vectorProvider), _step4; !(_step4 = _iterator4()).done;) {
5669
+ _ret3 = _loop3();
5670
+ if (_ret3) return _ret3.v;
5738
5671
  }
5739
5672
  return vectorApis;
5740
5673
  }
@@ -5761,6 +5694,74 @@ function vectorIndexSync() {
5761
5694
  executor: executeIndexSync
5762
5695
  };
5763
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
+ }
5764
5765
 
5765
5766
  function getAgentSystemApis(_ref) {
5766
5767
  var mastra = _ref.mastra;
@@ -5878,8 +5879,8 @@ function createAssistantAgentHandler(logger) {
5878
5879
  });
5879
5880
  case 3:
5880
5881
  assistant = _context.sent;
5881
- logger({
5882
- destinationPath: assistant.id + ".json",
5882
+ logger == null || logger.info({
5883
+ destinationPath: "" + assistant.id,
5883
5884
  statusCode: 201,
5884
5885
  message: JSON.stringify({
5885
5886
  message: 'Created assistant',
@@ -5922,8 +5923,8 @@ function updateAssistantAgentHandler(logger) {
5922
5923
  });
5923
5924
  case 3:
5924
5925
  assistant = _context2.sent;
5925
- logger({
5926
- destinationPath: assistant.id + ".json",
5926
+ logger == null || logger.info({
5927
+ destinationPath: "" + assistant.id,
5927
5928
  statusCode: 200,
5928
5929
  message: JSON.stringify({
5929
5930
  message: 'Updated assistant',
@@ -5990,8 +5991,8 @@ function getAssistantAgentHandler(logger) {
5990
5991
  return _context3.abrupt("return", _context3.sent);
5991
5992
  case 14:
5992
5993
  console.error('Run did not complete:', run);
5993
- logger({
5994
- destinationPath: id + ".json",
5994
+ logger == null || logger.error({
5995
+ destinationPath: "" + id,
5995
5996
  statusCode: 400,
5996
5997
  message: JSON.stringify({
5997
5998
  message: "Run did not complete",
@@ -6001,7 +6002,8 @@ function getAssistantAgentHandler(logger) {
6001
6002
  }
6002
6003
  }, null, 2)
6003
6004
  });
6004
- case 16:
6005
+ return _context3.abrupt("return", run == null ? void 0 : run.last_error);
6006
+ case 17:
6005
6007
  case "end":
6006
6008
  return _context3.stop();
6007
6009
  }
@@ -6037,8 +6039,8 @@ function getAssistantAgentHandler(logger) {
6037
6039
  fn: tool["function"].name,
6038
6040
  availableTools: Object.keys(toolMap)
6039
6041
  };
6040
- logger({
6041
- destinationPath: id + ".json",
6042
+ logger == null || logger.info({
6043
+ destinationPath: "" + id,
6042
6044
  statusCode: 100,
6043
6045
  message: JSON.stringify({
6044
6046
  message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
@@ -6052,8 +6054,8 @@ function getAssistantAgentHandler(logger) {
6052
6054
  _context4.next = 8;
6053
6055
  break;
6054
6056
  }
6055
- logger({
6056
- destinationPath: id + ".json",
6057
+ logger == null || logger.error({
6058
+ destinationPath: "" + id,
6057
6059
  statusCode: 404,
6058
6060
  message: JSON.stringify({
6059
6061
  message: "[local] No tool fn found: " + tool["function"].name,
@@ -6069,8 +6071,8 @@ function getAssistantAgentHandler(logger) {
6069
6071
  try {
6070
6072
  if (tool["function"].arguments) {
6071
6073
  args = JSON.parse(tool["function"].arguments);
6072
- logger({
6073
- destinationPath: id + ".json",
6074
+ logger == null || logger.info({
6075
+ destinationPath: "" + id,
6074
6076
  statusCode: 200,
6075
6077
  message: JSON.stringify({
6076
6078
  message: "[local] Passing args to tool call: " + tool["function"].name,
@@ -6088,8 +6090,8 @@ function getAssistantAgentHandler(logger) {
6088
6090
  return toolFn(args);
6089
6091
  case 13:
6090
6092
  output = _context4.sent;
6091
- logger({
6092
- destinationPath: id + ".json",
6093
+ logger == null || logger.info({
6094
+ destinationPath: "" + id,
6093
6095
  statusCode: 200,
6094
6096
  message: JSON.stringify({
6095
6097
  message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
@@ -6121,8 +6123,8 @@ function getAssistantAgentHandler(logger) {
6121
6123
  break;
6122
6124
  }
6123
6125
  console.error('No tool outputs to submit.');
6124
- logger({
6125
- destinationPath: id + ".json",
6126
+ logger == null || logger.error({
6127
+ destinationPath: "" + id,
6126
6128
  statusCode: 404,
6127
6129
  message: JSON.stringify({
6128
6130
  message: "No tool outputs submitted",
@@ -6145,8 +6147,8 @@ function getAssistantAgentHandler(logger) {
6145
6147
  });
6146
6148
  case 15:
6147
6149
  run = _context5.sent;
6148
- logger({
6149
- destinationPath: id + ".json",
6150
+ logger == null || logger.info({
6151
+ destinationPath: "" + id,
6150
6152
  statusCode: 200,
6151
6153
  message: JSON.stringify({
6152
6154
  message: "Tool outputs submitted",
@@ -6159,8 +6161,8 @@ function getAssistantAgentHandler(logger) {
6159
6161
  _context5.next = 22;
6160
6162
  break;
6161
6163
  case 20:
6162
- logger({
6163
- destinationPath: id + ".json",
6164
+ logger == null || logger.info({
6165
+ destinationPath: "" + id,
6164
6166
  statusCode: 404,
6165
6167
  message: JSON.stringify({
6166
6168
  message: "No tool outputs to submit",
@@ -6309,8 +6311,8 @@ function getAssistantAgentHandler(logger) {
6309
6311
  });
6310
6312
  case 9:
6311
6313
  run = _context10.sent;
6312
- logger({
6313
- destinationPath: id + ".json",
6314
+ logger == null || logger.info({
6315
+ destinationPath: "" + id,
6314
6316
  statusCode: 202,
6315
6317
  message: JSON.stringify({
6316
6318
  message: "Creating and polling run, tool choice required",
@@ -6732,65 +6734,114 @@ function _getAgent() {
6732
6734
  return _getAgent.apply(this, arguments);
6733
6735
  }
6734
6736
 
6735
- var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
6736
- function createFileLogger() {
6737
- return function (log) {
6738
- var fullPath = path.join(loggerPath, log.destinationPath);
6739
- if (!fs.existsSync(loggerPath)) {
6740
- fs.mkdirSync(loggerPath, {
6741
- recursive: true
6742
- });
6743
- return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
6744
- createdAt: new Date()
6745
- })], null, 2));
6746
- }
6747
- if (!fs.existsSync(fullPath)) {
6748
- return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
6749
- createdAt: new Date()
6750
- })], null, 2));
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');
6751
6744
  }
6752
- var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
6753
- logs.push(_extends({}, log, {
6754
- createdAt: new Date()
6755
- }));
6756
- return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
6745
+ return path.join(MASTRA_APP_DIR, blueprintDirPath);
6757
6746
  };
6758
- }
6759
- function getUpstashLogs(_x) {
6760
- return _getUpstashLogs.apply(this, arguments);
6761
- }
6762
- function _getUpstashLogs() {
6763
- _getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
6764
- var id, url, token, redis$1;
6765
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6766
- while (1) switch (_context.prev = _context.next) {
6767
- case 0:
6768
- id = _ref.id, url = _ref.url, token = _ref.token;
6769
- redis$1 = new redis.Redis({
6770
- url: url,
6771
- token: token
6772
- });
6773
- return _context.abrupt("return", redis$1.lrange(id, 0, -1));
6774
- case 3:
6775
- case "end":
6776
- return _context.stop();
6747
+ var blueprints = getBlueprintsSync({
6748
+ directoryPath: getBlueprintsDirPath()
6749
+ });
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
+ });
6777
6785
  }
6778
- }, _callee);
6779
- }));
6780
- return _getUpstashLogs.apply(this, arguments);
6781
- }
6782
- function createUpstashLogger(_ref2) {
6783
- var url = _ref2.url,
6784
- token = _ref2.token;
6785
- var redis$1 = new redis.Redis({
6786
- url: url,
6787
- token: token
6786
+ };
6788
6787
  });
6789
- return function (log) {
6790
- redis$1.lpush(log.destinationPath, JSON.stringify(_extends({}, log, {
6791
- createdAt: new Date()
6792
- })));
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
+ }()
6793
6843
  };
6844
+ return api;
6794
6845
  }
6795
6846
 
6796
6847
  var Mastra = /*#__PURE__*/function () {
@@ -6810,7 +6861,7 @@ var Mastra = /*#__PURE__*/function () {
6810
6861
  agentDirPath: '',
6811
6862
  vectorProvider: []
6812
6863
  };
6813
- this.logger = void 0;
6864
+ this.logger = new Map();
6814
6865
  this.config = void 0;
6815
6866
  this.runBlueprint = /*#__PURE__*/function () {
6816
6867
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
@@ -6844,7 +6895,8 @@ var Mastra = /*#__PURE__*/function () {
6844
6895
  blueprint: blueprint,
6845
6896
  frameworkApis: frameworkApis,
6846
6897
  frameworkEvents: frameworkEvents,
6847
- ctx: ctx
6898
+ ctx: ctx,
6899
+ logger: _this.logger.get('WORKFLOW')
6848
6900
  });
6849
6901
  case 10:
6850
6902
  case "end":
@@ -6859,9 +6911,10 @@ var Mastra = /*#__PURE__*/function () {
6859
6911
  this.dataLayer = dataLayer;
6860
6912
  this.vectorLayer = vectorLayer;
6861
6913
  this.config = config;
6914
+ this.__backgroundTasks();
6862
6915
  }
6863
6916
  Mastra.init = function init(config) {
6864
- var _config$logs, _config$logs2, _config$workflows$sys;
6917
+ var _config$logs, _config$logs4, _config$workflows$sys;
6865
6918
  if (!config.db.uri) {
6866
6919
  throw new Error('No database config/provider found');
6867
6920
  }
@@ -6875,87 +6928,74 @@ var Mastra = /*#__PURE__*/function () {
6875
6928
  dataLayer: dataLayer,
6876
6929
  vectorLayer: vectorLayer
6877
6930
  });
6878
- var logger;
6879
- if (!(config != null && config.logs)) {
6880
- logger = console.log;
6881
- } else if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
6882
- logger = createFileLogger();
6883
- } else if (((_config$logs2 = config.logs) == null ? void 0 : _config$logs2.provider) === 'UPSTASH') {
6884
- var _config$logs$config, _config$logs$config2;
6885
- 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({
6886
6953
  url: (_config$logs$config = config.logs.config) == null ? void 0 : _config$logs$config.url,
6887
6954
  token: (_config$logs$config2 = config.logs.config) == null ? void 0 : _config$logs$config2.token
6888
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
+ });
6889
6986
  }
6890
- framework.attachLogger(logger);
6987
+ framework.attachLogger({
6988
+ key: 'AGENT',
6989
+ logger: agentLogger
6990
+ });
6991
+ framework.attachLogger({
6992
+ key: 'WORKFLOW',
6993
+ logger: workflowLogger
6994
+ });
6891
6995
  // Register integrations
6892
6996
  config.integrations.forEach(function (integration) {
6893
6997
  framework.__registerIntgeration(integration);
6894
6998
  });
6895
- // Register system apis
6896
- framework.__registerApis({
6897
- apis: [].concat(getVectorQueryApis({
6898
- mastra: framework
6899
- }), getAgentSystemApis({
6900
- mastra: framework
6901
- }), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
6902
- return _extends({}, api, {
6903
- integrationName: config.name
6904
- });
6905
- }), [{
6906
- integrationName: config.name,
6907
- type: 'trigger_event',
6908
- label: 'Trigger event',
6909
- // getSchemaOptions({ ctx }) {
6910
- // const options = Promise.resolve({
6911
- // event: {
6912
- // options: Array.from(framework.globalEvents.values()).flatMap(
6913
- // (eventRecord) =>
6914
- // Object.values(eventRecord).map((event) => ({
6915
- // value: event.key || event.label || '',
6916
- // label: event.key || event.label || '',
6917
- // })).filter((event) => event.value !== '')
6918
- // ),
6919
- // },
6920
- // });
6921
- // return options;
6922
- // },
6923
- description: 'Trigger event',
6924
- schema: zod.z.object({
6925
- event: zod.z.string(),
6926
- data: zod.z.record(zod.z.any())
6927
- }),
6928
- executor: function () {
6929
- var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
6930
- var data, ctx, event;
6931
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6932
- while (1) switch (_context2.prev = _context2.next) {
6933
- case 0:
6934
- data = _ref7.data, ctx = _ref7.ctx;
6935
- event = data.event;
6936
- _context2.next = 4;
6937
- return framework.triggerEvent({
6938
- key: event,
6939
- data: data.data,
6940
- user: {
6941
- connectionId: ctx.connectionId
6942
- }
6943
- });
6944
- case 4:
6945
- return _context2.abrupt("return", _context2.sent);
6946
- case 5:
6947
- case "end":
6948
- return _context2.stop();
6949
- }
6950
- }, _callee2);
6951
- }));
6952
- function executor(_x2) {
6953
- return _executor.apply(this, arguments);
6954
- }
6955
- return executor;
6956
- }()
6957
- }])
6958
- });
6959
6999
  // Register System events
6960
7000
  framework.__registerEvents({
6961
7001
  events: config.workflows.systemEvents
@@ -6973,7 +7013,7 @@ var Mastra = /*#__PURE__*/function () {
6973
7013
  },
6974
7014
  VECTOR_SYNC: {
6975
7015
  label: 'Sync vector data',
6976
- description: 'Sync vector data',
7016
+ description: 'Generic vector sync',
6977
7017
  schema: zod.z.object({
6978
7018
  vector_provider: zod.z.string(),
6979
7019
  entities: zod.z.array(zod.z.object({
@@ -6990,11 +7030,14 @@ var Mastra = /*#__PURE__*/function () {
6990
7030
  },
6991
7031
  VECTOR_INDEX_SYNC: {
6992
7032
  label: 'Sync vector index',
6993
- description: 'Sync vector index',
7033
+ description: 'Sync data to vector index',
6994
7034
  schema: zod.z.object({
6995
7035
  data: zod.z.array(zod.z.object({
6996
7036
  provider: zod.z.string(),
6997
- 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()
6998
7041
  }))
6999
7042
  }),
7000
7043
  handler: vectorIndexSync
@@ -7002,55 +7045,73 @@ var Mastra = /*#__PURE__*/function () {
7002
7045
  },
7003
7046
  integrationName: config.name
7004
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
+ });
7005
7064
  // Register agent config
7006
7065
  framework.agentsConfig = config.agents;
7007
7066
  return framework;
7008
7067
  };
7009
7068
  var _proto = Mastra.prototype;
7010
- _proto.attachLogger = function attachLogger(logger) {
7011
- this.logger = logger;
7069
+ _proto.attachLogger = function attachLogger(_ref7) {
7070
+ var key = _ref7.key,
7071
+ logger = _ref7.logger;
7072
+ this.logger.set(key, logger);
7012
7073
  };
7013
7074
  _proto.connectedIntegrations = /*#__PURE__*/function () {
7014
- var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref8) {
7075
+ var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
7015
7076
  var _this2 = this;
7016
7077
  var context, ints, connectionChecks;
7017
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
7018
- while (1) switch (_context4.prev = _context4.next) {
7078
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7079
+ while (1) switch (_context3.prev = _context3.next) {
7019
7080
  case 0:
7020
7081
  context = _ref8.context;
7021
7082
  ints = this.availableIntegrations();
7022
- _context4.next = 4;
7083
+ _context3.next = 4;
7023
7084
  return Promise.all(ints.map(/*#__PURE__*/function () {
7024
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref9) {
7085
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref9) {
7025
7086
  var integration, connection;
7026
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7027
- while (1) switch (_context3.prev = _context3.next) {
7087
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7088
+ while (1) switch (_context2.prev = _context2.next) {
7028
7089
  case 0:
7029
7090
  integration = _ref9.integration;
7030
- _context3.next = 3;
7091
+ _context2.next = 3;
7031
7092
  return _this2.dataLayer.getConnection({
7032
7093
  connectionId: context.connectionId,
7033
7094
  name: integration.name
7034
7095
  });
7035
7096
  case 3:
7036
- connection = _context3.sent;
7037
- return _context3.abrupt("return", {
7097
+ connection = _context2.sent;
7098
+ return _context2.abrupt("return", {
7038
7099
  integration: integration,
7039
7100
  connected: !!connection
7040
7101
  });
7041
7102
  case 5:
7042
7103
  case "end":
7043
- return _context3.stop();
7104
+ return _context2.stop();
7044
7105
  }
7045
- }, _callee3);
7106
+ }, _callee2);
7046
7107
  }));
7047
- return function (_x4) {
7108
+ return function (_x3) {
7048
7109
  return _ref10.apply(this, arguments);
7049
7110
  };
7050
7111
  }()));
7051
7112
  case 4:
7052
- connectionChecks = _context4.sent;
7053
- return _context4.abrupt("return", connectionChecks.filter(function (_ref11) {
7113
+ connectionChecks = _context3.sent;
7114
+ return _context3.abrupt("return", connectionChecks.filter(function (_ref11) {
7054
7115
  var connected = _ref11.connected;
7055
7116
  return connected;
7056
7117
  }).map(function (_ref12) {
@@ -7059,11 +7120,11 @@ var Mastra = /*#__PURE__*/function () {
7059
7120
  }));
7060
7121
  case 6:
7061
7122
  case "end":
7062
- return _context4.stop();
7123
+ return _context3.stop();
7063
7124
  }
7064
- }, _callee4, this);
7125
+ }, _callee3, this);
7065
7126
  }));
7066
- function connectedIntegrations(_x3) {
7127
+ function connectedIntegrations(_x2) {
7067
7128
  return _connectedIntegrations.apply(this, arguments);
7068
7129
  }
7069
7130
  return connectedIntegrations;
@@ -7077,14 +7138,14 @@ var Mastra = /*#__PURE__*/function () {
7077
7138
  definition.corePresets = {
7078
7139
  redirectURI: router.makeRedirectURI()
7079
7140
  };
7080
- this.integrations.set(name, definition);
7081
7141
  definition.registerEvents();
7142
+ definition.registerApis();
7143
+ definition._convertApiClientToSystemApis();
7144
+ this.integrations.set(name, definition);
7082
7145
  this.__registerEvents({
7083
7146
  events: definition.getEvents(),
7084
7147
  integrationName: name
7085
7148
  });
7086
- definition.registerApis();
7087
- definition._convertApiClientToSystemApis();
7088
7149
  this.__registerApis({
7089
7150
  apis: Object.values(definition.getApis()),
7090
7151
  integrationName: name
@@ -7213,20 +7274,20 @@ var Mastra = /*#__PURE__*/function () {
7213
7274
  return _int.getAuthenticator();
7214
7275
  };
7215
7276
  _proto.connectIntegrationByCredential = /*#__PURE__*/function () {
7216
- var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref18) {
7277
+ var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref18) {
7217
7278
  var name, connectionId, credential, authenticator, integration;
7218
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7219
- while (1) switch (_context5.prev = _context5.next) {
7279
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
7280
+ while (1) switch (_context4.prev = _context4.next) {
7220
7281
  case 0:
7221
7282
  name = _ref18.name, connectionId = _ref18.connectionId, credential = _ref18.credential;
7222
7283
  authenticator = this.authenticator(name);
7223
7284
  if (authenticator) {
7224
- _context5.next = 4;
7285
+ _context4.next = 4;
7225
7286
  break;
7226
7287
  }
7227
7288
  throw new Error("Authenticator for " + name + " not found");
7228
7289
  case 4:
7229
- _context5.next = 6;
7290
+ _context4.next = 6;
7230
7291
  return authenticator.dataAccess.createConnection({
7231
7292
  connection: {
7232
7293
  name: name,
@@ -7235,112 +7296,112 @@ var Mastra = /*#__PURE__*/function () {
7235
7296
  credential: credential
7236
7297
  });
7237
7298
  case 6:
7238
- integration = _context5.sent;
7299
+ integration = _context4.sent;
7239
7300
  if (!authenticator.onConnectionCreated) {
7240
- _context5.next = 10;
7301
+ _context4.next = 10;
7241
7302
  break;
7242
7303
  }
7243
- _context5.next = 10;
7304
+ _context4.next = 10;
7244
7305
  return authenticator.onConnectionCreated(integration, credential);
7245
7306
  case 10:
7246
7307
  case "end":
7247
- return _context5.stop();
7308
+ return _context4.stop();
7248
7309
  }
7249
- }, _callee5, this);
7310
+ }, _callee4, this);
7250
7311
  }));
7251
- function connectIntegrationByCredential(_x5) {
7312
+ function connectIntegrationByCredential(_x4) {
7252
7313
  return _connectIntegrationByCredential.apply(this, arguments);
7253
7314
  }
7254
7315
  return connectIntegrationByCredential;
7255
7316
  }();
7256
7317
  _proto.disconnectIntegration = /*#__PURE__*/function () {
7257
- var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref19) {
7318
+ var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref19) {
7258
7319
  var _yield$this$dataLayer;
7259
7320
  var name, connectionId, integration, k_id, authenticator;
7260
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7261
- while (1) switch (_context6.prev = _context6.next) {
7321
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7322
+ while (1) switch (_context5.prev = _context5.next) {
7262
7323
  case 0:
7263
7324
  name = _ref19.name, connectionId = _ref19.connectionId;
7264
7325
  integration = this.getIntegration(name);
7265
- _context6.next = 4;
7326
+ _context5.next = 4;
7266
7327
  return this.dataLayer.getConnection({
7267
7328
  name: name,
7268
7329
  connectionId: connectionId
7269
7330
  });
7270
7331
  case 4:
7271
- _context6.t0 = _yield$this$dataLayer = _context6.sent;
7272
- if (!(_context6.t0 == null)) {
7273
- _context6.next = 9;
7332
+ _context5.t0 = _yield$this$dataLayer = _context5.sent;
7333
+ if (!(_context5.t0 == null)) {
7334
+ _context5.next = 9;
7274
7335
  break;
7275
7336
  }
7276
- _context6.t1 = void 0;
7277
- _context6.next = 10;
7337
+ _context5.t1 = void 0;
7338
+ _context5.next = 10;
7278
7339
  break;
7279
7340
  case 9:
7280
- _context6.t1 = _yield$this$dataLayer.id;
7341
+ _context5.t1 = _yield$this$dataLayer.id;
7281
7342
  case 10:
7282
- k_id = _context6.t1;
7343
+ k_id = _context5.t1;
7283
7344
  if (k_id) {
7284
- _context6.next = 13;
7345
+ _context5.next = 13;
7285
7346
  break;
7286
7347
  }
7287
7348
  throw new Error("No connection found for " + name);
7288
7349
  case 13:
7289
7350
  if (!(integration != null && integration.dataLayer)) {
7290
- _context6.next = 16;
7351
+ _context5.next = 16;
7291
7352
  break;
7292
7353
  }
7293
- _context6.next = 16;
7354
+ _context5.next = 16;
7294
7355
  return integration.onDisconnect({
7295
7356
  connectionId: connectionId
7296
7357
  });
7297
7358
  case 16:
7298
7359
  if (!((integration == null ? void 0 : integration.config.authType) === exports.IntegrationCredentialType.OAUTH)) {
7299
- _context6.next = 20;
7360
+ _context5.next = 20;
7300
7361
  break;
7301
7362
  }
7302
7363
  authenticator = this.authenticator(name);
7303
- _context6.next = 20;
7364
+ _context5.next = 20;
7304
7365
  return authenticator.revokeAuth({
7305
7366
  k_id: k_id
7306
7367
  });
7307
7368
  case 20:
7308
- _context6.next = 22;
7369
+ _context5.next = 22;
7309
7370
  return this.dataLayer.deleteConnection({
7310
7371
  connectionId: connectionId
7311
7372
  });
7312
7373
  case 22:
7313
7374
  case "end":
7314
- return _context6.stop();
7375
+ return _context5.stop();
7315
7376
  }
7316
- }, _callee6, this);
7377
+ }, _callee5, this);
7317
7378
  }));
7318
- function disconnectIntegration(_x6) {
7379
+ function disconnectIntegration(_x5) {
7319
7380
  return _disconnectIntegration.apply(this, arguments);
7320
7381
  }
7321
7382
  return disconnectIntegration;
7322
7383
  }();
7323
7384
  _proto.createSystemConnection = /*#__PURE__*/function () {
7324
- var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
7385
+ var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
7325
7386
  var systemConnectionId, existingSystemConnection;
7326
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7327
- while (1) switch (_context7.prev = _context7.next) {
7387
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7388
+ while (1) switch (_context6.prev = _context6.next) {
7328
7389
  case 0:
7329
7390
  systemConnectionId = 'SYSTEM';
7330
- _context7.next = 3;
7391
+ _context6.next = 3;
7331
7392
  return this.dataLayer.getConnection({
7332
7393
  connectionId: systemConnectionId,
7333
7394
  name: this.config.name
7334
7395
  });
7335
7396
  case 3:
7336
- existingSystemConnection = _context7.sent;
7397
+ existingSystemConnection = _context6.sent;
7337
7398
  if (!existingSystemConnection) {
7338
- _context7.next = 6;
7399
+ _context6.next = 6;
7339
7400
  break;
7340
7401
  }
7341
- return _context7.abrupt("return", existingSystemConnection);
7402
+ return _context6.abrupt("return", existingSystemConnection);
7342
7403
  case 6:
7343
- return _context7.abrupt("return", this.dataLayer.createConnection({
7404
+ return _context6.abrupt("return", this.dataLayer.createConnection({
7344
7405
  connection: {
7345
7406
  connectionId: systemConnectionId,
7346
7407
  name: this.config.name
@@ -7352,9 +7413,9 @@ var Mastra = /*#__PURE__*/function () {
7352
7413
  }));
7353
7414
  case 7:
7354
7415
  case "end":
7355
- return _context7.stop();
7416
+ return _context6.stop();
7356
7417
  }
7357
- }, _callee7, this);
7418
+ }, _callee6, this);
7358
7419
  }));
7359
7420
  function createSystemConnection() {
7360
7421
  return _createSystemConnection.apply(this, arguments);
@@ -7362,71 +7423,71 @@ var Mastra = /*#__PURE__*/function () {
7362
7423
  return createSystemConnection;
7363
7424
  }();
7364
7425
  _proto.callApi = /*#__PURE__*/function () {
7365
- var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
7426
+ var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref20) {
7366
7427
  var _int2$getApis;
7367
7428
  var _ref20$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
7368
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7369
- while (1) switch (_context8.prev = _context8.next) {
7429
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7430
+ while (1) switch (_context7.prev = _context7.next) {
7370
7431
  case 0:
7371
7432
  _ref20$integrationNam = _ref20.integrationName, integrationName = _ref20$integrationNam === void 0 ? this.config.name : _ref20$integrationNam, api = _ref20.api, payload = _ref20.payload;
7372
7433
  if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
7373
- _context8.next = 6;
7434
+ _context7.next = 6;
7374
7435
  break;
7375
7436
  }
7376
7437
  _apiExecutor = (_this$globalApis$get = this.globalApis.get(this.config.name)) == null ? void 0 : _this$globalApis$get[api];
7377
7438
  if (_apiExecutor) {
7378
- _context8.next = 5;
7439
+ _context7.next = 5;
7379
7440
  break;
7380
7441
  }
7381
7442
  throw new Error("No global api exists for " + api);
7382
7443
  case 5:
7383
- return _context8.abrupt("return", _apiExecutor.executor(payload));
7444
+ return _context7.abrupt("return", _apiExecutor.executor(payload));
7384
7445
  case 6:
7385
7446
  _int2 = this.getIntegration(integrationName);
7386
7447
  if (_int2) {
7387
- _context8.next = 9;
7448
+ _context7.next = 9;
7388
7449
  break;
7389
7450
  }
7390
7451
  throw new Error("No Integration exists for " + integrationName);
7391
7452
  case 9:
7392
7453
  apiExecutor = (_int2$getApis = _int2.getApis()) == null ? void 0 : _int2$getApis[api];
7393
7454
  if (apiExecutor) {
7394
- _context8.next = 12;
7455
+ _context7.next = 12;
7395
7456
  break;
7396
7457
  }
7397
7458
  throw new Error("No api exists for " + api + " in " + integrationName);
7398
7459
  case 12:
7399
- return _context8.abrupt("return", apiExecutor.executor(payload));
7460
+ return _context7.abrupt("return", apiExecutor.executor(payload));
7400
7461
  case 13:
7401
7462
  case "end":
7402
- return _context8.stop();
7463
+ return _context7.stop();
7403
7464
  }
7404
- }, _callee8, this);
7465
+ }, _callee7, this);
7405
7466
  }));
7406
- function callApi(_x7) {
7467
+ function callApi(_x6) {
7407
7468
  return _callApi.apply(this, arguments);
7408
7469
  }
7409
7470
  return callApi;
7410
7471
  }();
7411
7472
  _proto.subscribeEvent = /*#__PURE__*/function () {
7412
- var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref21) {
7473
+ var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
7413
7474
  var _this$config$runner$u, _this$config$runner, _ref22, _this$config$runner$s, _this$config$runner2;
7414
7475
  var id, _ref21$interval, interval, _ref21$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
7415
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
7416
- while (1) switch (_context10.prev = _context10.next) {
7476
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7477
+ while (1) switch (_context9.prev = _context9.next) {
7417
7478
  case 0:
7418
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;
7419
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;
7420
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';
7421
7482
  startTime = Date.now();
7422
7483
  _poll = /*#__PURE__*/function () {
7423
- var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
7484
+ var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
7424
7485
  var response, obj, data, error, lastRun, elapsedTime;
7425
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7426
- while (1) switch (_context9.prev = _context9.next) {
7486
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7487
+ while (1) switch (_context8.prev = _context8.next) {
7427
7488
  case 0:
7428
- _context9.prev = 0;
7429
- _context9.next = 3;
7489
+ _context8.prev = 0;
7490
+ _context8.next = 3;
7430
7491
  return fetch(inngestApiUrl + "/v1/events/" + id + "/runs", {
7431
7492
  method: 'GET',
7432
7493
  headers: {
@@ -7435,117 +7496,117 @@ var Mastra = /*#__PURE__*/function () {
7435
7496
  }
7436
7497
  });
7437
7498
  case 3:
7438
- response = _context9.sent;
7499
+ response = _context8.sent;
7439
7500
  console.log("Polling for event " + id + "...", response.ok);
7440
7501
  if (!response.ok) {
7441
- _context9.next = 28;
7502
+ _context8.next = 28;
7442
7503
  break;
7443
7504
  }
7444
- _context9.next = 8;
7505
+ _context8.next = 8;
7445
7506
  return response.json();
7446
7507
  case 8:
7447
- obj = _context9.sent;
7508
+ obj = _context8.sent;
7448
7509
  console.log({
7449
7510
  obj: obj
7450
7511
  });
7451
7512
  data = obj.data, error = obj.error;
7452
7513
  console.log("Got data for event " + id + "...", data, error);
7453
7514
  if (!error) {
7454
- _context9.next = 15;
7515
+ _context8.next = 15;
7455
7516
  break;
7456
7517
  }
7457
7518
  console.error(error);
7458
- return _context9.abrupt("return", null);
7519
+ return _context8.abrupt("return", null);
7459
7520
  case 15:
7460
7521
  if (!((data == null ? void 0 : data.length) === 0)) {
7461
- _context9.next = 19;
7522
+ _context8.next = 19;
7462
7523
  break;
7463
7524
  }
7464
- _context9.next = 18;
7525
+ _context8.next = 18;
7465
7526
  return new Promise(function (resolve) {
7466
7527
  return setTimeout(resolve, interval);
7467
7528
  });
7468
7529
  case 18:
7469
- return _context9.abrupt("return", _poll());
7530
+ return _context8.abrupt("return", _poll());
7470
7531
  case 19:
7471
7532
  lastRun = data == null ? void 0 : data[0];
7472
7533
  console.log(lastRun);
7473
7534
  if (lastRun) {
7474
- _context9.next = 23;
7535
+ _context8.next = 23;
7475
7536
  break;
7476
7537
  }
7477
- return _context9.abrupt("return", null);
7538
+ return _context8.abrupt("return", null);
7478
7539
  case 23:
7479
7540
  if (!(lastRun.status === 'Running')) {
7480
- _context9.next = 27;
7541
+ _context8.next = 27;
7481
7542
  break;
7482
7543
  }
7483
- _context9.next = 26;
7544
+ _context8.next = 26;
7484
7545
  return new Promise(function (resolve) {
7485
7546
  return setTimeout(resolve, interval);
7486
7547
  });
7487
7548
  case 26:
7488
- return _context9.abrupt("return", _poll());
7549
+ return _context8.abrupt("return", _poll());
7489
7550
  case 27:
7490
- return _context9.abrupt("return", {
7551
+ return _context8.abrupt("return", {
7491
7552
  status: lastRun.status,
7492
7553
  startedAt: lastRun.run_started_at,
7493
7554
  endedAt: lastRun.ended_at
7494
7555
  });
7495
7556
  case 28:
7496
- _context9.next = 33;
7557
+ _context8.next = 33;
7497
7558
  break;
7498
7559
  case 30:
7499
- _context9.prev = 30;
7500
- _context9.t0 = _context9["catch"](0);
7501
- console.error("Request failed: " + _context9.t0);
7560
+ _context8.prev = 30;
7561
+ _context8.t0 = _context8["catch"](0);
7562
+ console.error("Request failed: " + _context8.t0);
7502
7563
  case 33:
7503
7564
  // Check if timeout has been reached
7504
7565
  elapsedTime = Date.now() - startTime;
7505
7566
  if (!(elapsedTime >= timeout)) {
7506
- _context9.next = 37;
7567
+ _context8.next = 37;
7507
7568
  break;
7508
7569
  }
7509
7570
  console.log('Polling timeout reached.');
7510
- return _context9.abrupt("return", null);
7571
+ return _context8.abrupt("return", null);
7511
7572
  case 37:
7512
- _context9.next = 39;
7573
+ _context8.next = 39;
7513
7574
  return new Promise(function (resolve) {
7514
7575
  return setTimeout(resolve, interval);
7515
7576
  });
7516
7577
  case 39:
7517
- return _context9.abrupt("return", _poll());
7578
+ return _context8.abrupt("return", _poll());
7518
7579
  case 40:
7519
7580
  case "end":
7520
- return _context9.stop();
7581
+ return _context8.stop();
7521
7582
  }
7522
- }, _callee9, null, [[0, 30]]);
7583
+ }, _callee8, null, [[0, 30]]);
7523
7584
  }));
7524
7585
  return function poll() {
7525
7586
  return _ref23.apply(this, arguments);
7526
7587
  };
7527
7588
  }();
7528
- return _context10.abrupt("return", _poll());
7589
+ return _context9.abrupt("return", _poll());
7529
7590
  case 6:
7530
7591
  case "end":
7531
- return _context10.stop();
7592
+ return _context9.stop();
7532
7593
  }
7533
- }, _callee10, this);
7594
+ }, _callee9, this);
7534
7595
  }));
7535
- function subscribeEvent(_x8) {
7596
+ function subscribeEvent(_x7) {
7536
7597
  return _subscribeEvent.apply(this, arguments);
7537
7598
  }
7538
7599
  return subscribeEvent;
7539
7600
  }();
7540
7601
  _proto.triggerEvent = /*#__PURE__*/function () {
7541
- var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref24) {
7602
+ var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref24) {
7542
7603
  var _this4 = this;
7543
7604
  var key, data, user, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
7544
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
7545
- while (1) switch (_context13.prev = _context13.next) {
7605
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
7606
+ while (1) switch (_context12.prev = _context12.next) {
7546
7607
  case 0:
7547
7608
  key = _ref24.key, data = _ref24.data, user = _ref24.user, integrationName = _ref24.integrationName;
7548
- _context13.prev = 1;
7609
+ _context12.prev = 1;
7549
7610
  returnObj = {
7550
7611
  event: {}
7551
7612
  };
@@ -7557,53 +7618,53 @@ var Mastra = /*#__PURE__*/function () {
7557
7618
  }, {});
7558
7619
  }
7559
7620
  if (integrationEvents) {
7560
- _context13.next = 6;
7621
+ _context12.next = 6;
7561
7622
  break;
7562
7623
  }
7563
7624
  throw new Error("No integration events found");
7564
7625
  case 6:
7565
7626
  integrationEvent = integrationEvents[key];
7566
7627
  if (integrationEvent) {
7567
- _context13.next = 9;
7628
+ _context12.next = 9;
7568
7629
  break;
7569
7630
  }
7570
7631
  throw new Error("No event exists for " + key + " in " + (integrationName || 'system'));
7571
7632
  case 9:
7572
- _context13.next = 11;
7633
+ _context12.next = 11;
7573
7634
  return client$1.send({
7574
7635
  name: key,
7575
7636
  data: data,
7576
7637
  user: user
7577
7638
  });
7578
7639
  case 11:
7579
- event = _context13.sent;
7640
+ event = _context12.sent;
7580
7641
  returnObj['event'] = _extends({}, event, {
7581
7642
  subscribe: function () {
7582
- var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp) {
7643
+ var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp) {
7583
7644
  var _event$ids;
7584
7645
  var _ref25, interval, timeout;
7585
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
7586
- while (1) switch (_context11.prev = _context11.next) {
7646
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
7647
+ while (1) switch (_context10.prev = _context10.next) {
7587
7648
  case 0:
7588
7649
  _ref25 = _temp === void 0 ? {} : _temp, interval = _ref25.interval, timeout = _ref25.timeout;
7589
- return _context11.abrupt("return", _this4.subscribeEvent({
7650
+ return _context10.abrupt("return", _this4.subscribeEvent({
7590
7651
  id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
7591
7652
  interval: interval,
7592
7653
  timeout: timeout
7593
7654
  }));
7594
7655
  case 2:
7595
7656
  case "end":
7596
- return _context11.stop();
7657
+ return _context10.stop();
7597
7658
  }
7598
- }, _callee11);
7659
+ }, _callee10);
7599
7660
  }));
7600
- function subscribe(_x10) {
7661
+ function subscribe(_x9) {
7601
7662
  return _subscribe.apply(this, arguments);
7602
7663
  }
7603
7664
  return subscribe;
7604
7665
  }()
7605
7666
  });
7606
- _context13.next = 15;
7667
+ _context12.next = 15;
7607
7668
  return client$1.send({
7608
7669
  name: 'workflow/run-automations',
7609
7670
  data: {
@@ -7613,45 +7674,45 @@ var Mastra = /*#__PURE__*/function () {
7613
7674
  user: user
7614
7675
  });
7615
7676
  case 15:
7616
- workflowEvent = _context13.sent;
7677
+ workflowEvent = _context12.sent;
7617
7678
  returnObj['workflowEvent'] = _extends({}, workflowEvent, {
7618
7679
  subscribe: function () {
7619
- var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_temp2) {
7680
+ var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp2) {
7620
7681
  var _workflowEvent$ids;
7621
7682
  var _ref26, interval, timeout;
7622
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
7623
- while (1) switch (_context12.prev = _context12.next) {
7683
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
7684
+ while (1) switch (_context11.prev = _context11.next) {
7624
7685
  case 0:
7625
7686
  _ref26 = _temp2 === void 0 ? {} : _temp2, interval = _ref26.interval, timeout = _ref26.timeout;
7626
- return _context12.abrupt("return", _this4.subscribeEvent({
7687
+ return _context11.abrupt("return", _this4.subscribeEvent({
7627
7688
  id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
7628
7689
  interval: interval,
7629
7690
  timeout: timeout
7630
7691
  }));
7631
7692
  case 2:
7632
7693
  case "end":
7633
- return _context12.stop();
7694
+ return _context11.stop();
7634
7695
  }
7635
- }, _callee12);
7696
+ }, _callee11);
7636
7697
  }));
7637
- function subscribe(_x11) {
7698
+ function subscribe(_x10) {
7638
7699
  return _subscribe2.apply(this, arguments);
7639
7700
  }
7640
7701
  return subscribe;
7641
7702
  }()
7642
7703
  });
7643
- return _context13.abrupt("return", returnObj);
7704
+ return _context12.abrupt("return", returnObj);
7644
7705
  case 20:
7645
- _context13.prev = 20;
7646
- _context13.t0 = _context13["catch"](1);
7647
- 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);
7648
7709
  case 23:
7649
7710
  case "end":
7650
- return _context13.stop();
7711
+ return _context12.stop();
7651
7712
  }
7652
- }, _callee13, this, [[1, 20]]);
7713
+ }, _callee12, this, [[1, 20]]);
7653
7714
  }));
7654
- function triggerEvent(_x9) {
7715
+ function triggerEvent(_x8) {
7655
7716
  return _triggerEvent.apply(this, arguments);
7656
7717
  }
7657
7718
  return triggerEvent;
@@ -7660,26 +7721,26 @@ var Mastra = /*#__PURE__*/function () {
7660
7721
  _proto.triggerSystemEvent =
7661
7722
  /*#__PURE__*/
7662
7723
  function () {
7663
- var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref27) {
7724
+ var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref27) {
7664
7725
  var key, data, user, event, systemEvent;
7665
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
7666
- while (1) switch (_context14.prev = _context14.next) {
7726
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
7727
+ while (1) switch (_context13.prev = _context13.next) {
7667
7728
  case 0:
7668
7729
  key = _ref27.key, data = _ref27.data, user = _ref27.user;
7669
- _context14.next = 3;
7730
+ _context13.next = 3;
7670
7731
  return client$1.send({
7671
7732
  name: key,
7672
7733
  data: data,
7673
7734
  user: user
7674
7735
  });
7675
7736
  case 3:
7676
- event = _context14.sent;
7737
+ event = _context13.sent;
7677
7738
  systemEvent = this.getSystemEvents()[key];
7678
7739
  if (!systemEvent) {
7679
- _context14.next = 8;
7740
+ _context13.next = 8;
7680
7741
  break;
7681
7742
  }
7682
- _context14.next = 8;
7743
+ _context13.next = 8;
7683
7744
  return client$1.send({
7684
7745
  name: 'workflow/run-automations',
7685
7746
  data: {
@@ -7689,14 +7750,14 @@ var Mastra = /*#__PURE__*/function () {
7689
7750
  user: user
7690
7751
  });
7691
7752
  case 8:
7692
- return _context14.abrupt("return", event);
7753
+ return _context13.abrupt("return", event);
7693
7754
  case 9:
7694
7755
  case "end":
7695
- return _context14.stop();
7756
+ return _context13.stop();
7696
7757
  }
7697
- }, _callee14, this);
7758
+ }, _callee13, this);
7698
7759
  }));
7699
- function triggerSystemEvent(_x12) {
7760
+ function triggerSystemEvent(_x11) {
7700
7761
  return _triggerSystemEvent.apply(this, arguments);
7701
7762
  }
7702
7763
  return triggerSystemEvent;
@@ -7718,7 +7779,7 @@ var Mastra = /*#__PURE__*/function () {
7718
7779
  };
7719
7780
  var registerRoutes = function registerRoutes() {
7720
7781
  var _registry;
7721
- 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);
7722
7783
  return function (req) {
7723
7784
  var route = req.nextUrl.pathname;
7724
7785
  if (req.nextUrl.pathname in registry) {
@@ -7737,42 +7798,62 @@ var Mastra = /*#__PURE__*/function () {
7737
7798
  };
7738
7799
  };
7739
7800
  _proto.getAgent = /*#__PURE__*/function () {
7740
- var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref29) {
7801
+ var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref29) {
7741
7802
  var connectionId, agentId, agentBlueprint, arrMap, finalApis;
7742
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
7743
- while (1) switch (_context15.prev = _context15.next) {
7803
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
7804
+ while (1) switch (_context14.prev = _context14.next) {
7744
7805
  case 0:
7745
7806
  connectionId = _ref29.connectionId, agentId = _ref29.agentId;
7746
- _context15.next = 3;
7807
+ _context14.next = 3;
7747
7808
  return getAgentBlueprint({
7748
7809
  agentDir: this.config.agents.agentDirPath,
7749
7810
  agentId: agentId
7750
7811
  });
7751
7812
  case 3:
7752
- agentBlueprint = _context15.sent;
7813
+ agentBlueprint = _context14.sent;
7753
7814
  arrMap = Array.from(this.getApis());
7754
7815
  finalApis = arrMap.reduce(function (acc, _ref30) {
7755
7816
  var v = _ref30[1];
7756
7817
  return _extends({}, acc, v);
7757
7818
  }, {});
7758
7819
  console.log('got finalApis===');
7759
- return _context15.abrupt("return", getAgent({
7820
+ return _context14.abrupt("return", getAgent({
7760
7821
  connectionId: connectionId,
7761
7822
  agent: agentBlueprint,
7762
7823
  apis: finalApis,
7763
- logger: this.logger
7824
+ logger: this.logger.get('AGENT')
7764
7825
  }));
7765
7826
  case 8:
7766
7827
  case "end":
7767
- return _context15.stop();
7828
+ return _context14.stop();
7768
7829
  }
7769
- }, _callee15, this);
7830
+ }, _callee14, this);
7770
7831
  }));
7771
- function getAgent$1(_x13) {
7832
+ function getAgent$1(_x12) {
7772
7833
  return _getAgent2.apply(this, arguments);
7773
7834
  }
7774
7835
  return getAgent$1;
7775
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
+ }();
7776
7857
  return _createClass(Mastra, [{
7777
7858
  key: "routes",
7778
7859
  get: function get() {
@@ -7781,7 +7862,8 @@ var Mastra = /*#__PURE__*/function () {
7781
7862
  connect: '/connect',
7782
7863
  callback: '/connect/callback',
7783
7864
  inngest: '/inngest',
7784
- webhook: '/webhook'
7865
+ webhook: '/webhook',
7866
+ cron: '/cron'
7785
7867
  };
7786
7868
  return Object.entries(registry).reduce(function (acc, _ref31) {
7787
7869
  var _extends5;
@@ -7794,14 +7876,38 @@ var Mastra = /*#__PURE__*/function () {
7794
7876
  key: "openAIAssistant",
7795
7877
  get: function get() {
7796
7878
  return {
7797
- createAssistantAgent: createAssistantAgentHandler(this.logger),
7798
- getAssistantAgent: getAssistantAgentHandler(this.logger),
7799
- 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'))
7800
7882
  };
7801
7883
  }
7802
7884
  }]);
7803
7885
  }();
7804
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
+
7805
7911
  Object.defineProperty(exports, 'PropertyType', {
7806
7912
  enumerable: true,
7807
7913
  get: function () { return client$2.PropertyType; }
@@ -7813,6 +7919,7 @@ exports.Integration = Integration;
7813
7919
  exports.IntegrationAuth = IntegrationAuth;
7814
7920
  exports.IntegrationError = IntegrationError;
7815
7921
  exports.IntegrationFieldTypeEnum = IntegrationFieldTypeEnum;
7922
+ exports.LogProvider = LogProvider;
7816
7923
  exports.Mastra = Mastra;
7817
7924
  exports.RunStatus = RunStatus;
7818
7925
  exports.SORT_MODE_TO_ABBR = SORT_MODE_TO_ABBR;
@@ -7823,6 +7930,9 @@ exports.buildQueryString = buildQueryString;
7823
7930
  exports.callbackParams = callbackParams;
7824
7931
  exports.connectParams = connectParams;
7825
7932
  exports.constructObjFromStringPath = constructObjFromStringPath;
7933
+ exports.createLogger = createLogger;
7934
+ exports.cronQueryParams = cronQueryParams;
7935
+ exports.delay = delay$1;
7826
7936
  exports.extractSchemaOptions = extractSchemaOptions;
7827
7937
  exports.fieldsWithCommaSeparatedValues = fieldsWithCommaSeparatedValues;
7828
7938
  exports.filterQuerySchema = filterQuerySchema;
@@ -7844,6 +7954,7 @@ exports.recordHasData = recordHasData;
7844
7954
  exports.registerRoutes = registerRoutes;
7845
7955
  exports.sortQuerySchema = sortQuerySchema;
7846
7956
  exports.splitAndStripQuotes = splitAndStripQuotes;
7957
+ exports.splitMarkdownIntoChunks = splitMarkdownIntoChunks;
7847
7958
  exports.transformFilterValueArray = transformFilterValueArray;
7848
7959
  exports.transformFilterValueBoolean = transformFilterValueBoolean;
7849
7960
  exports.webhookQueryParams = webhookQueryParams;