@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
package/dist/core.esm.js CHANGED
@@ -10,13 +10,13 @@ import { headers } from 'next/headers';
10
10
  import qs from 'qs';
11
11
  import { serve } from 'inngest/next';
12
12
  import * as fs from 'fs';
13
- import { readdirSync, readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
13
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync } from 'fs';
14
14
  import path from 'path';
15
15
  import first from 'lodash-es/first';
16
16
  import last from 'lodash-es/last';
17
17
  import { Inngest } from 'inngest';
18
18
  import { OAuth2Client } from '@badgateway/oauth2-client';
19
- import _, { isEmpty, omit, pick, compact, omitBy } from 'lodash-es';
19
+ import _, { isEmpty, omit, pick, mapValues, compact, omitBy } from 'lodash-es';
20
20
  import { openai, createOpenAI } from '@ai-sdk/openai';
21
21
  import { embed, tool, generateText, streamText } from 'ai';
22
22
  import { Pinecone } from '@pinecone-database/pinecone';
@@ -66,6 +66,14 @@ function _asyncToGenerator(n) {
66
66
  });
67
67
  };
68
68
  }
69
+ function _classPrivateFieldLooseBase(e, t) {
70
+ if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance");
71
+ return e;
72
+ }
73
+ var id = 0;
74
+ function _classPrivateFieldLooseKey(e) {
75
+ return "__private_" + id++ + "_" + e;
76
+ }
69
77
  function _construct(t, e, r) {
70
78
  if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
71
79
  var o = [null];
@@ -1753,6 +1761,11 @@ var webhookQueryParams = /*#__PURE__*/z.object({
1753
1761
  var apiKeyConnectionOptions = /*#__PURE__*/z.object({
1754
1762
  apiKey: /*#__PURE__*/z.string()
1755
1763
  });
1764
+ var cronQueryParams = /*#__PURE__*/z.object({
1765
+ event: /*#__PURE__*/z.string(),
1766
+ data: /*#__PURE__*/z.string().optional(),
1767
+ integrationName: /*#__PURE__*/z.string()
1768
+ });
1756
1769
 
1757
1770
  var parseQueryParams = function parseQueryParams(req, schema) {
1758
1771
  var search = req.nextUrl.search.slice(1);
@@ -1858,6 +1871,44 @@ var client$1 = /*#__PURE__*/new Inngest({
1858
1871
  id: APP_ID
1859
1872
  });
1860
1873
 
1874
+ function readBlueprintSync(filePath) {
1875
+ try {
1876
+ var data = fs.readFileSync(filePath, 'utf8');
1877
+ var jsonData = JSON.parse(data);
1878
+ var blueprintFile = last(filePath == null ? void 0 : filePath.split('/'));
1879
+ var blueprintId = first(blueprintFile == null ? void 0 : blueprintFile.split('.json'));
1880
+ return _extends({}, jsonData, {
1881
+ id: blueprintId
1882
+ });
1883
+ } catch (err) {
1884
+ throw new Error("Failed to read blueprint: " + err);
1885
+ }
1886
+ }
1887
+ function getBlueprintsSync(_ref) {
1888
+ var directoryPath = _ref.directoryPath;
1889
+ try {
1890
+ var files = fs.readdirSync(directoryPath);
1891
+ var jsonFiles = files.filter(function (file) {
1892
+ return file.endsWith('.json');
1893
+ });
1894
+ var result = [];
1895
+ for (var _iterator = _createForOfIteratorHelperLoose(jsonFiles), _step; !(_step = _iterator()).done;) {
1896
+ var file = _step.value;
1897
+ var filePath = path.join(directoryPath, file);
1898
+ var jsonData = readBlueprintSync(filePath);
1899
+ if (jsonData.title) {
1900
+ var blueprintFile = last(filePath == null ? void 0 : filePath.split('/'));
1901
+ var blueprintId = first(blueprintFile == null ? void 0 : blueprintFile.split('.json'));
1902
+ result.push(_extends({}, jsonData, {
1903
+ id: blueprintId
1904
+ }));
1905
+ }
1906
+ }
1907
+ return result;
1908
+ } catch (err) {
1909
+ throw new Error("Failed to get blueprints: " + err);
1910
+ }
1911
+ }
1861
1912
  function readBlueprint(_x) {
1862
1913
  return _readBlueprint.apply(this, arguments);
1863
1914
  }
@@ -1890,16 +1941,16 @@ function getBlueprints(_x2) {
1890
1941
  return _getBlueprints.apply(this, arguments);
1891
1942
  }
1892
1943
  function _getBlueprints() {
1893
- _getBlueprints = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref) {
1944
+ _getBlueprints = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref2) {
1894
1945
  var directoryPath;
1895
1946
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1896
1947
  while (1) switch (_context6.prev = _context6.next) {
1897
1948
  case 0:
1898
- directoryPath = _ref.directoryPath;
1949
+ directoryPath = _ref2.directoryPath;
1899
1950
  return _context6.abrupt("return", new Promise(function (resolve, reject) {
1900
1951
  fs.readdir(directoryPath, /*#__PURE__*/function () {
1901
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(err, files) {
1902
- var jsonFiles, result, _iterator, _step, file, filePath, jsonData, blueprintFile, blueprintId;
1952
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(err, files) {
1953
+ var jsonFiles, result, _iterator2, _step2, file, filePath, jsonData, blueprintFile, blueprintId;
1903
1954
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1904
1955
  while (1) switch (_context5.prev = _context5.next) {
1905
1956
  case 0:
@@ -1915,13 +1966,13 @@ function _getBlueprints() {
1915
1966
  return file.endsWith('.json');
1916
1967
  });
1917
1968
  result = [];
1918
- _iterator = _createForOfIteratorHelperLoose(jsonFiles);
1969
+ _iterator2 = _createForOfIteratorHelperLoose(jsonFiles);
1919
1970
  case 7:
1920
- if ((_step = _iterator()).done) {
1971
+ if ((_step2 = _iterator2()).done) {
1921
1972
  _context5.next = 16;
1922
1973
  break;
1923
1974
  }
1924
- file = _step.value;
1975
+ file = _step2.value;
1925
1976
  filePath = path.join(directoryPath, file);
1926
1977
  _context5.next = 12;
1927
1978
  return readBlueprint(filePath);
@@ -1946,7 +1997,7 @@ function _getBlueprints() {
1946
1997
  }, _callee5);
1947
1998
  }));
1948
1999
  return function (_x4, _x5) {
1949
- return _ref7.apply(this, arguments);
2000
+ return _ref8.apply(this, arguments);
1950
2001
  };
1951
2002
  }());
1952
2003
  }));
@@ -1958,26 +2009,26 @@ function _getBlueprints() {
1958
2009
  }));
1959
2010
  return _getBlueprints.apply(this, arguments);
1960
2011
  }
1961
- var createWorkflowHandler = function createWorkflowHandler(_ref2) {
1962
- var blueprintDirPath = _ref2.blueprintDirPath,
1963
- runBlueprint = _ref2.runBlueprint;
2012
+ var createWorkflowHandler = function createWorkflowHandler(_ref3) {
2013
+ var blueprintDirPath = _ref3.blueprintDirPath,
2014
+ runBlueprint = _ref3.runBlueprint;
1964
2015
  return client$1.createFunction({
1965
2016
  id: 'workflow-executor',
1966
2017
  retries: 0
1967
2018
  }, {
1968
2019
  event: 'workflow/run-automations'
1969
2020
  }, /*#__PURE__*/function () {
1970
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
2021
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
1971
2022
  var event, step, _event$data, trigger, payload, connectionId, getBlueprintsDirPath, blueprints, triggeredAndPublishedBlueprints, runs;
1972
2023
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1973
2024
  while (1) switch (_context3.prev = _context3.next) {
1974
2025
  case 0:
1975
- event = _ref3.event, step = _ref3.step;
2026
+ event = _ref4.event, step = _ref4.step;
1976
2027
  _context3.prev = 1;
1977
2028
  _event$data = event.data, trigger = _event$data.trigger, payload = _event$data.payload;
1978
2029
  connectionId = event.user.connectionId;
1979
2030
  getBlueprintsDirPath = /*#__PURE__*/function () {
1980
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2031
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1981
2032
  var MASTRA_APP_DIR;
1982
2033
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1983
2034
  while (1) switch (_context.prev = _context.next) {
@@ -1997,7 +2048,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
1997
2048
  }, _callee);
1998
2049
  }));
1999
2050
  return function getBlueprintsDirPath() {
2000
- return _ref5.apply(this, arguments);
2051
+ return _ref6.apply(this, arguments);
2001
2052
  };
2002
2053
  }();
2003
2054
  _context3.next = 7;
@@ -2052,7 +2103,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
2052
2103
  }, _callee3, null, [[1, 15]]);
2053
2104
  }));
2054
2105
  return function (_x3) {
2055
- return _ref4.apply(this, arguments);
2106
+ return _ref5.apply(this, arguments);
2056
2107
  };
2057
2108
  }());
2058
2109
  };
@@ -2149,13 +2200,52 @@ var makeWebhook = function makeWebhook(framework) {
2149
2200
  };
2150
2201
  };
2151
2202
 
2203
+ var makeCron = function makeCron(framework) {
2204
+ return function (req) {
2205
+ var params = parseQueryParams(req, cronQueryParams);
2206
+ var data = params.data,
2207
+ error = params.error;
2208
+ if (error) {
2209
+ return NextResponse.json({
2210
+ error: error,
2211
+ status: 400
2212
+ });
2213
+ }
2214
+ var event = data.event,
2215
+ integrationName = data.integrationName;
2216
+ if (!event) {
2217
+ return NextResponse.json({
2218
+ error: 'Event is required for mastra cron',
2219
+ status: 400
2220
+ });
2221
+ }
2222
+ var decodedEvent = decodeURI(event);
2223
+ var decodedData = {};
2224
+ if (data != null && data.data) {
2225
+ decodedData = JSON.parse(Buffer.from(data.data, 'base64').toString());
2226
+ }
2227
+ void framework.triggerEvent({
2228
+ key: decodedEvent,
2229
+ data: decodedData,
2230
+ integrationName: integrationName,
2231
+ user: {
2232
+ connectionId: 'SYSTEM'
2233
+ }
2234
+ });
2235
+ return NextResponse.json({
2236
+ message: "Cron Triggered event " + event
2237
+ });
2238
+ };
2239
+ };
2240
+
2152
2241
  var registerRoutes = function registerRoutes(_ref) {
2153
2242
  var framework = _ref.framework;
2154
2243
  var registry = {
2155
2244
  connect: makeConnect(framework),
2156
2245
  'connect/callback': makeCallback(framework),
2157
2246
  inngest: makeInngest(framework),
2158
- webhook: makeWebhook(framework)
2247
+ webhook: makeWebhook(framework),
2248
+ cron: makeCron(framework)
2159
2249
  };
2160
2250
  return function (req, _ref2) {
2161
2251
  var _Object$keys$at;
@@ -2341,6 +2431,203 @@ function mergeWithDefinedOnly(base, overrides) {
2341
2431
  return result;
2342
2432
  }
2343
2433
 
2434
+ var LogProvider = {
2435
+ CONSOLE: 'CONSOLE',
2436
+ FILE: 'FILE',
2437
+ UPSTASH: 'UPSTASH'
2438
+ };
2439
+ var LogLevel;
2440
+ (function (LogLevel) {
2441
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
2442
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
2443
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
2444
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
2445
+ })(LogLevel || (LogLevel = {}));
2446
+ // Abstract base class for loggers
2447
+ var BaseLogger = /*#__PURE__*/function () {
2448
+ function BaseLogger(level) {
2449
+ if (level === void 0) {
2450
+ level = LogLevel.INFO;
2451
+ }
2452
+ this.level = void 0;
2453
+ this.level = level;
2454
+ }
2455
+ var _proto = BaseLogger.prototype;
2456
+ _proto.debug = function debug(message) {
2457
+ if (this.level <= LogLevel.DEBUG) {
2458
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2459
+ args[_key - 1] = arguments[_key];
2460
+ }
2461
+ this.log.apply(this, [LogLevel.DEBUG, message].concat(args));
2462
+ }
2463
+ };
2464
+ _proto.info = function info(message) {
2465
+ if (this.level <= LogLevel.INFO) {
2466
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2467
+ args[_key2 - 1] = arguments[_key2];
2468
+ }
2469
+ this.log.apply(this, [LogLevel.INFO, message].concat(args));
2470
+ }
2471
+ };
2472
+ _proto.warn = function warn(message) {
2473
+ if (this.level <= LogLevel.WARN) {
2474
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2475
+ args[_key3 - 1] = arguments[_key3];
2476
+ }
2477
+ this.log.apply(this, [LogLevel.WARN, message].concat(args));
2478
+ }
2479
+ };
2480
+ _proto.error = function error(message) {
2481
+ if (this.level <= LogLevel.ERROR) {
2482
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
2483
+ args[_key4 - 1] = arguments[_key4];
2484
+ }
2485
+ this.log.apply(this, [LogLevel.ERROR, message].concat(args));
2486
+ }
2487
+ };
2488
+ _proto.formatMessage = function formatMessage(message) {
2489
+ if (typeof message === 'string') {
2490
+ return message;
2491
+ }
2492
+ return JSON.stringify(message);
2493
+ };
2494
+ return BaseLogger;
2495
+ }();
2496
+ /**
2497
+ * Logs to the console
2498
+ */
2499
+ var ConsoleLogger = /*#__PURE__*/function (_BaseLogger2) {
2500
+ function ConsoleLogger(_ref) {
2501
+ var level = _ref.level;
2502
+ return _BaseLogger2.call(this, level != null ? level : LogLevel.INFO) || this;
2503
+ }
2504
+ _inheritsLoose(ConsoleLogger, _BaseLogger2);
2505
+ var _proto2 = ConsoleLogger.prototype;
2506
+ _proto2.log = function log(level, message) {
2507
+ var _console;
2508
+ var timestamp = new Date().toISOString();
2509
+ for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
2510
+ args[_key5 - 2] = arguments[_key5];
2511
+ }
2512
+ (_console = console).log.apply(_console, ["[" + timestamp + "] [" + level + "] " + this.formatMessage(message)].concat(args));
2513
+ };
2514
+ return ConsoleLogger;
2515
+ }(BaseLogger);
2516
+ /**
2517
+ * Logs to a file
2518
+ */
2519
+ var _dirPath = /*#__PURE__*/_classPrivateFieldLooseKey("dirPath");
2520
+ var FileLogger = /*#__PURE__*/function (_BaseLogger3) {
2521
+ function FileLogger(_ref2) {
2522
+ var _this;
2523
+ var dirPath = _ref2.dirPath,
2524
+ level = _ref2.level;
2525
+ _this = _BaseLogger3.call(this, level != null ? level : LogLevel.INFO) || this;
2526
+ Object.defineProperty(_this, _dirPath, {
2527
+ writable: true,
2528
+ value: void 0
2529
+ });
2530
+ if (!dirPath) {
2531
+ throw new Error('File path is required');
2532
+ }
2533
+ _classPrivateFieldLooseBase(_this, _dirPath)[_dirPath] = dirPath;
2534
+ return _this;
2535
+ }
2536
+ _inheritsLoose(FileLogger, _BaseLogger3);
2537
+ var _proto3 = FileLogger.prototype;
2538
+ _proto3.log = function log(level, message) {
2539
+ var fullPath = path.join(_classPrivateFieldLooseBase(this, _dirPath)[_dirPath], message.destinationPath + ".json");
2540
+ console.log("Logging to file: " + fullPath);
2541
+ if (!existsSync(_classPrivateFieldLooseBase(this, _dirPath)[_dirPath])) {
2542
+ mkdirSync(_classPrivateFieldLooseBase(this, _dirPath)[_dirPath], {
2543
+ recursive: true
2544
+ });
2545
+ return writeFileSync(fullPath, JSON.stringify([_extends({}, message, {
2546
+ level: level,
2547
+ createdAt: new Date()
2548
+ })], null, 2));
2549
+ }
2550
+ if (!existsSync(fullPath)) {
2551
+ return writeFileSync(fullPath, JSON.stringify([_extends({}, message, {
2552
+ createdAt: new Date()
2553
+ })], null, 2));
2554
+ }
2555
+ var logs = JSON.parse(readFileSync(fullPath, 'utf-8'));
2556
+ logs.push(_extends({}, message, {
2557
+ createdAt: new Date()
2558
+ }));
2559
+ return writeFileSync(fullPath, JSON.stringify(logs, null, 2));
2560
+ };
2561
+ return FileLogger;
2562
+ }(BaseLogger);
2563
+ /**
2564
+ * Logs to Upstash Redis
2565
+ */
2566
+ var _redisClient = /*#__PURE__*/_classPrivateFieldLooseKey("redisClient");
2567
+ var _key6 = /*#__PURE__*/_classPrivateFieldLooseKey("key");
2568
+ var UpstashRedisLogger = /*#__PURE__*/function (_BaseLogger4) {
2569
+ function UpstashRedisLogger(_ref3) {
2570
+ var _this2;
2571
+ var redisClient = _ref3.redisClient,
2572
+ level = _ref3.level,
2573
+ key = _ref3.key;
2574
+ _this2 = _BaseLogger4.call(this, level != null ? level : LogLevel.INFO) || this;
2575
+ Object.defineProperty(_this2, _redisClient, {
2576
+ writable: true,
2577
+ value: void 0
2578
+ });
2579
+ Object.defineProperty(_this2, _key6, {
2580
+ writable: true,
2581
+ value: void 0
2582
+ });
2583
+ if (!redisClient) {
2584
+ throw new Error('redisClient is required');
2585
+ }
2586
+ if (!key) {
2587
+ throw new Error('Redis storage key is required');
2588
+ }
2589
+ _classPrivateFieldLooseBase(_this2, _redisClient)[_redisClient] = redisClient;
2590
+ _classPrivateFieldLooseBase(_this2, _key6)[_key6] = key;
2591
+ return _this2;
2592
+ }
2593
+ _inheritsLoose(UpstashRedisLogger, _BaseLogger4);
2594
+ var _proto4 = UpstashRedisLogger.prototype;
2595
+ _proto4.log = function log(level, message) {
2596
+ var fullKey = path.join(_classPrivateFieldLooseBase(this, _key6)[_key6], "" + message.destinationPath);
2597
+ _classPrivateFieldLooseBase(this, _redisClient)[_redisClient].lpush(fullKey, JSON.stringify(_extends({}, message, {
2598
+ level: level,
2599
+ createdAt: new Date()
2600
+ })));
2601
+ };
2602
+ _proto4.getLogs = function getLogs(key) {
2603
+ return _classPrivateFieldLooseBase(this, _redisClient)[_redisClient].lrange(key, 0, -1);
2604
+ };
2605
+ return UpstashRedisLogger;
2606
+ }(BaseLogger);
2607
+ function createLogger(_ref4) {
2608
+ var type = _ref4.type,
2609
+ options = _ref4.options;
2610
+ switch (type) {
2611
+ case 'CONSOLE':
2612
+ return new ConsoleLogger({
2613
+ level: options == null ? void 0 : options.level
2614
+ });
2615
+ case 'FILE':
2616
+ return new FileLogger({
2617
+ dirPath: options.dirPath,
2618
+ level: options.level
2619
+ });
2620
+ case 'UPSTASH':
2621
+ return new UpstashRedisLogger({
2622
+ redisClient: options.redisClient,
2623
+ key: options.key,
2624
+ level: options.level
2625
+ });
2626
+ default:
2627
+ throw new Error("Unsupported logger type: " + type);
2628
+ }
2629
+ }
2630
+
2344
2631
  var _excluded$3 = ["client"],
2345
2632
  _excluded2$1 = ["name", "logoUrl"];
2346
2633
  /**
@@ -2427,7 +2714,7 @@ var Integration = /*#__PURE__*/function () {
2427
2714
  return acc;
2428
2715
  }
2429
2716
  }, {});
2430
- _this.apis = apis;
2717
+ _this.apis = _extends({}, _this.apis, apis);
2431
2718
  case 5:
2432
2719
  case "end":
2433
2720
  return _context2.stop();
@@ -3046,6 +3333,31 @@ var IntegrationAuth = /*#__PURE__*/function () {
3046
3333
  return IntegrationAuth;
3047
3334
  }();
3048
3335
 
3336
+ function splitMarkdownIntoChunks(markdown, maxTokens) {
3337
+ if (maxTokens === void 0) {
3338
+ maxTokens = 8190;
3339
+ }
3340
+ var tokens = markdown.split(/\s+/); // Split by whitespace to tokenize
3341
+ var chunks = [];
3342
+ var currentChunk = [];
3343
+ for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
3344
+ var token = _step.value;
3345
+ if (currentChunk.join(' ').length + token.length + 1 > maxTokens) {
3346
+ // If adding the next token exceeds the limit, push the current chunk and reset
3347
+ chunks.push(currentChunk.join(' '));
3348
+ currentChunk = [token]; // Start a new chunk with the current token
3349
+ } else {
3350
+ // Otherwise, add the token to the current chunk
3351
+ currentChunk.push(token);
3352
+ }
3353
+ }
3354
+ // Add any remaining tokens as the last chunk
3355
+ if (currentChunk.length > 0) {
3356
+ chunks.push(currentChunk.join(' '));
3357
+ }
3358
+ return chunks;
3359
+ }
3360
+
3049
3361
  /**
3050
3362
  * Extract schema options for the provided schema - Builds a map of fieldname to field options
3051
3363
  * @param schema - schema
@@ -3122,6 +3434,11 @@ function setFieldOptions(_ref3) {
3122
3434
  };
3123
3435
  }
3124
3436
  }
3437
+ var delay$1 = function delay(ms) {
3438
+ return new Promise(function (resolve) {
3439
+ return setTimeout(resolve, ms);
3440
+ });
3441
+ };
3125
3442
 
3126
3443
  function zodToPropertType(zodType) {
3127
3444
  if (zodType instanceof z.ZodString) {
@@ -3866,11 +4183,11 @@ function runActionsRecursively(_x) {
3866
4183
  }
3867
4184
  function _runActionsRecursively() {
3868
4185
  _runActionsRecursively = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref7) {
3869
- var blueprintActions, frameworkApis, frameworkEvents, dataContext, blueprintId, runId, ctx, blueprintActionKVMap, _loop, _ret, _iterator2, _step2;
4186
+ var blueprintActions, frameworkApis, frameworkEvents, dataContext, blueprintId, runId, ctx, blueprintActionKVMap, logger, _loop, _ret, _iterator2, _step2;
3870
4187
  return _regeneratorRuntime().wrap(function _callee$(_context3) {
3871
4188
  while (1) switch (_context3.prev = _context3.next) {
3872
4189
  case 0:
3873
- blueprintActions = _ref7.blueprintActions, frameworkApis = _ref7.frameworkApis, frameworkEvents = _ref7.frameworkEvents, dataContext = _ref7.dataContext, blueprintId = _ref7.blueprintId, runId = _ref7.runId, ctx = _ref7.ctx, blueprintActionKVMap = _ref7.blueprintActionKVMap;
4190
+ 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;
3874
4191
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
3875
4192
  var _action$subActions;
3876
4193
  var action, concreteAction, hasValidBranch, _loop2, _ret2, _iterator3, _step3, defaultCondition, defaultAction, actionExecutor, _ref9, mastraConnectionId, actionPayload, resolvedPayload, resolvedSchema, data, executorResult, _ctx, subActions;
@@ -3879,9 +4196,15 @@ function _runActionsRecursively() {
3879
4196
  case 0:
3880
4197
  action = _step2.value;
3881
4198
  concreteAction = frameworkApis[action.type];
3882
- console.log('==========', "Running action " + action.type, {
3883
- dataContext: JSON.stringify(dataContext, null, 2)
3884
- }, '=======');
4199
+ logger.info({
4200
+ destinationPath: "" + blueprintId,
4201
+ message: JSON.stringify({
4202
+ message: "Running action " + action.type,
4203
+ metadata: {
4204
+ dataContext: JSON.stringify(dataContext, null, 2)
4205
+ }
4206
+ })
4207
+ });
3885
4208
  // check action conditions
3886
4209
  if (!(action.type === 'CONDITIONS')) {
3887
4210
  _context2.next = 32;
@@ -3958,7 +4281,8 @@ function _runActionsRecursively() {
3958
4281
  blueprintId: blueprintId,
3959
4282
  runId: runId,
3960
4283
  ctx: ctx,
3961
- blueprintActionKVMap: blueprintActionKVMap
4284
+ blueprintActionKVMap: blueprintActionKVMap,
4285
+ logger: logger
3962
4286
  });
3963
4287
  case 22:
3964
4288
  executorResult = _context.sent;
@@ -4005,7 +4329,12 @@ function _runActionsRecursively() {
4005
4329
  _context2.next = 32;
4006
4330
  break;
4007
4331
  }
4008
- console.log('======== No valid branch found for action ============');
4332
+ logger.debug({
4333
+ destinationPath: "" + blueprintId,
4334
+ message: JSON.stringify({
4335
+ message: "No valid branch found for action: " + action.type + ":" + action.id
4336
+ })
4337
+ });
4009
4338
  // run default branch if available
4010
4339
  defaultCondition = action.condition.find(function (c) {
4011
4340
  return c.isDefault;
@@ -4017,7 +4346,12 @@ function _runActionsRecursively() {
4017
4346
  _context2.next = 30;
4018
4347
  break;
4019
4348
  }
4020
- console.log('========= running default action =============');
4349
+ logger.debug({
4350
+ destinationPath: "" + blueprintId,
4351
+ message: JSON.stringify({
4352
+ message: "Running default action: " + defaultAction.type + ":" + defaultAction.id
4353
+ })
4354
+ });
4021
4355
  _context2.next = 26;
4022
4356
  return runActionsRecursively({
4023
4357
  blueprintActions: [defaultAction],
@@ -4027,7 +4361,8 @@ function _runActionsRecursively() {
4027
4361
  runId: runId,
4028
4362
  ctx: ctx,
4029
4363
  blueprintId: blueprintId,
4030
- blueprintActionKVMap: blueprintActionKVMap
4364
+ blueprintActionKVMap: blueprintActionKVMap,
4365
+ logger: logger
4031
4366
  });
4032
4367
  case 26:
4033
4368
  _context2.t1 = _context2.sent;
@@ -4035,7 +4370,12 @@ function _runActionsRecursively() {
4035
4370
  v: _context2.t1
4036
4371
  });
4037
4372
  case 30:
4038
- console.log('========= No default branch found =============');
4373
+ logger.debug({
4374
+ destinationPath: "" + blueprintId,
4375
+ message: JSON.stringify({
4376
+ message: "No default action found for action: " + action.type + ":" + action.id
4377
+ })
4378
+ });
4039
4379
  return _context2.abrupt("return", {
4040
4380
  v: false
4041
4381
  });
@@ -4045,7 +4385,12 @@ function _runActionsRecursively() {
4045
4385
  _context2.next = 36;
4046
4386
  break;
4047
4387
  }
4048
- console.log("No executor found for " + action.type);
4388
+ logger.debug({
4389
+ destinationPath: "" + blueprintId,
4390
+ message: JSON.stringify({
4391
+ message: "No executor found for " + action.type + ":" + action.id
4392
+ })
4393
+ });
4049
4394
  return _context2.abrupt("return", 0);
4050
4395
  case 36:
4051
4396
  _ref9 = action.payload || {}, mastraConnectionId = _ref9.mastraConnectionId, actionPayload = _objectWithoutPropertiesLoose(_ref9, _excluded);
@@ -4082,14 +4427,24 @@ function _runActionsRecursively() {
4082
4427
  });
4083
4428
  case 49:
4084
4429
  executorResult = _context2.sent;
4085
- console.log('executed successfully');
4430
+ logger.info({
4431
+ destinationPath: "" + blueprintId,
4432
+ message: JSON.stringify({
4433
+ message: "Action " + action.type + ":" + action.id + " completed",
4434
+ result: executorResult
4435
+ })
4436
+ });
4086
4437
  _context2.next = 57;
4087
4438
  break;
4088
4439
  case 53:
4089
4440
  _context2.prev = 53;
4090
4441
  _context2.t2 = _context2["catch"](46);
4091
- console.log('===Error executing action===', {
4092
- e: _context2.t2
4442
+ logger.error({
4443
+ destinationPath: "" + blueprintId,
4444
+ message: JSON.stringify({
4445
+ message: "Action " + action.type + ":" + action.id + " failed",
4446
+ error: _context2.t2
4447
+ })
4093
4448
  });
4094
4449
  // TODO: Update workflows runs for failed actions
4095
4450
  return _context2.abrupt("return", {
@@ -4115,7 +4470,8 @@ function _runActionsRecursively() {
4115
4470
  runId: runId,
4116
4471
  ctx: ctx,
4117
4472
  blueprintId: blueprintId,
4118
- blueprintActionKVMap: blueprintActionKVMap
4473
+ blueprintActionKVMap: blueprintActionKVMap,
4474
+ logger: logger
4119
4475
  });
4120
4476
  case 63:
4121
4477
  _context2.t3 = _context2.sent;
@@ -4167,12 +4523,22 @@ function blueprintRunner(_x2) {
4167
4523
  function _blueprintRunner() {
4168
4524
  _blueprintRunner = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
4169
4525
  var _fullCtx, _blueprint$trigger;
4170
- var ctx, dataCtx, blueprint, frameworkEvents, frameworkApis, fullCtx, triggerCondition, concreteTrigger, resolvedSchema, shouldRunWorkflow, blueprintActionKVMap, ranSuccessfully;
4526
+ var ctx, dataCtx, blueprint, frameworkEvents, frameworkApis, logger, fullCtx, triggerCondition, concreteTrigger, resolvedSchema, shouldRunWorkflow, blueprintActionKVMap, ranSuccessfully;
4171
4527
  return _regeneratorRuntime().wrap(function _callee2$(_context4) {
4172
4528
  while (1) switch (_context4.prev = _context4.next) {
4173
4529
  case 0:
4174
- ctx = _ref8.ctx, dataCtx = _ref8.dataCtx, blueprint = _ref8.blueprint, frameworkEvents = _ref8.frameworkEvents, frameworkApis = _ref8.frameworkApis;
4530
+ ctx = _ref8.ctx, dataCtx = _ref8.dataCtx, blueprint = _ref8.blueprint, frameworkEvents = _ref8.frameworkEvents, frameworkApis = _ref8.frameworkApis, logger = _ref8.logger;
4175
4531
  console.log("Running blueprint " + blueprint.id);
4532
+ logger.info({
4533
+ destinationPath: "" + blueprint.id,
4534
+ message: JSON.stringify({
4535
+ message: 'Started workflow run',
4536
+ metadata: {
4537
+ blueprintId: blueprint.id,
4538
+ trigger: blueprint.trigger
4539
+ }
4540
+ })
4541
+ });
4176
4542
  fullCtx = (_fullCtx = {}, _fullCtx[blueprint.trigger.id] = dataCtx, _fullCtx);
4177
4543
  triggerCondition = blueprint.trigger.condition;
4178
4544
  concreteTrigger = frameworkEvents[blueprint.trigger.type || ''];
@@ -4205,10 +4571,16 @@ function _blueprintRunner() {
4205
4571
  _context4.next = 16;
4206
4572
  break;
4207
4573
  }
4574
+ logger.info({
4575
+ destinationPath: "" + blueprint.id,
4576
+ message: JSON.stringify({
4577
+ message: 'Workflow run skipped'
4578
+ })
4579
+ });
4208
4580
  return _context4.abrupt("return");
4209
4581
  case 16:
4210
4582
  blueprintActionKVMap = constructWorkflowContextBluePrint(blueprint);
4211
- _context4.next = 20;
4583
+ _context4.next = 19;
4212
4584
  return runActionsRecursively({
4213
4585
  blueprintActions: blueprint.actions,
4214
4586
  frameworkApis: frameworkApis,
@@ -4217,21 +4589,27 @@ function _blueprintRunner() {
4217
4589
  dataContext: fullCtx,
4218
4590
  blueprintActionKVMap: blueprintActionKVMap,
4219
4591
  blueprintId: blueprint.id,
4220
- runId: ''
4592
+ runId: '',
4593
+ logger: logger
4221
4594
  });
4222
- case 20:
4595
+ case 19:
4223
4596
  ranSuccessfully = _context4.sent;
4224
- try {
4225
- if (ranSuccessfully) {
4226
- // await automationRunService.updateAutomationRun({
4227
- // runId: blueprintRun?.id || '',
4228
- // blueprintId: blueprint.id,
4229
- // completedAt: new Date(),
4230
- // status: AutomationRunStatus.COMPLETED,
4231
- // });
4232
- }
4233
- } catch (e) {}
4234
- case 22:
4597
+ if (ranSuccessfully) {
4598
+ logger.info({
4599
+ destinationPath: "" + blueprint.id,
4600
+ message: JSON.stringify({
4601
+ message: 'Workflow run completed'
4602
+ })
4603
+ });
4604
+ } else {
4605
+ logger.error({
4606
+ destinationPath: "" + blueprint.id,
4607
+ message: JSON.stringify({
4608
+ message: 'Workflow run failed'
4609
+ })
4610
+ });
4611
+ }
4612
+ case 21:
4235
4613
  case "end":
4236
4614
  return _context4.stop();
4237
4615
  }
@@ -4673,139 +5051,127 @@ function getVectorProvider(provider) {
4673
5051
  return Pinecone;
4674
5052
  }
4675
5053
  }
4676
- var delay$1 = function delay(ms) {
4677
- return new Promise(function (resolve) {
4678
- return setTimeout(resolve, ms);
4679
- });
4680
- };
4681
- function executeIndexSync(_x) {
4682
- return _executeIndexSync.apply(this, arguments);
4683
- }
4684
- //Generic vector sync from event data
4685
- function _executeIndexSync() {
4686
- _executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref) {
4687
- var _event$user, _event$data;
4688
- var event, mastra, connectionId, providedIndexes, systemName, _iterator2, _step2, _step2$value, provider, indexes, vp, _loop2, _ret2, _iterator3, _step3;
4689
- return _regeneratorRuntime().wrap(function _callee6$(_context8) {
4690
- while (1) switch (_context8.prev = _context8.next) {
5054
+ // base index sync from knowledge source
5055
+ var indexSync = /*#__PURE__*/function () {
5056
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
5057
+ var knowledgeSource, mastra, connectionId, _iterator, _step, _step$value, provider, indexes, vp, _loop, _ret, _iterator2, _step2;
5058
+ return _regeneratorRuntime().wrap(function _callee3$(_context5) {
5059
+ while (1) switch (_context5.prev = _context5.next) {
4691
5060
  case 0:
4692
- event = _ref.event, mastra = _ref.mastra;
4693
- connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
4694
- providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
4695
- systemName = mastra.config.name;
4696
- _iterator2 = _createForOfIteratorHelperLoose(providedIndexes);
4697
- case 5:
4698
- if ((_step2 = _iterator2()).done) {
4699
- _context8.next = 25;
5061
+ knowledgeSource = _ref.knowledgeSource, mastra = _ref.mastra, connectionId = _ref.connectionId;
5062
+ _iterator = _createForOfIteratorHelperLoose(knowledgeSource);
5063
+ case 2:
5064
+ if ((_step = _iterator()).done) {
5065
+ _context5.next = 22;
4700
5066
  break;
4701
5067
  }
4702
- _step2$value = _step2.value, provider = _step2$value.provider, indexes = _step2$value.indexes;
5068
+ _step$value = _step.value, provider = _step$value.provider, indexes = _step$value.indexes;
4703
5069
  vp = getVectorProvider(provider);
4704
5070
  if (vp) {
4705
- _context8.next = 11;
5071
+ _context5.next = 8;
4706
5072
  break;
4707
5073
  }
4708
5074
  console.error('UNSUPPORTED VECTOR PROVIDER', provider);
4709
- return _context8.abrupt("return");
4710
- case 11:
5075
+ return _context5.abrupt("return");
5076
+ case 8:
4711
5077
  if (process.env.OPENAI_API_KEY) {
4712
- _context8.next = 14;
5078
+ _context5.next = 11;
4713
5079
  break;
4714
5080
  }
4715
5081
  console.error('NO OPENAI_API_KEY');
4716
- return _context8.abrupt("return");
4717
- case 14:
4718
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
4719
- var index, getPineconeIndexWithMetadata, indexMetadata, _loop3, _ret3, _iterator4, _step4;
4720
- return _regeneratorRuntime().wrap(function _loop2$(_context7) {
4721
- while (1) switch (_context7.prev = _context7.next) {
5082
+ return _context5.abrupt("return");
5083
+ case 11:
5084
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
5085
+ var index, getPineconeIndexWithMetadata, indexMetadata, _loop2, _ret2, _iterator3, _step3;
5086
+ return _regeneratorRuntime().wrap(function _loop$(_context4) {
5087
+ while (1) switch (_context4.prev = _context4.next) {
4722
5088
  case 0:
4723
- index = _step3.value;
5089
+ index = _step2.value;
4724
5090
  getPineconeIndexWithMetadata = /*#__PURE__*/function () {
4725
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
5091
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4726
5092
  var res;
4727
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4728
- while (1) switch (_context4.prev = _context4.next) {
5093
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
5094
+ while (1) switch (_context.prev = _context.next) {
4729
5095
  case 0:
4730
- _context4.prev = 0;
4731
- _context4.next = 3;
5096
+ _context.prev = 0;
5097
+ _context.next = 3;
4732
5098
  return mastra.vectorLayer.getPineconeIndexWithMetadata({
4733
5099
  name: index
4734
5100
  });
4735
5101
  case 3:
4736
- res = _context4.sent;
4737
- if (res.length) {
4738
- _context4.next = 6;
5102
+ res = _context.sent;
5103
+ if (res != null && res.length) {
5104
+ _context.next = 6;
4739
5105
  break;
4740
5106
  }
4741
5107
  throw new Error('No index metadata found');
4742
5108
  case 6:
4743
- return _context4.abrupt("return", res);
5109
+ return _context.abrupt("return", res);
4744
5110
  case 9:
4745
- _context4.prev = 9;
4746
- _context4.t0 = _context4["catch"](0);
4747
- throw new Error(_context4.t0);
5111
+ _context.prev = 9;
5112
+ _context.t0 = _context["catch"](0);
5113
+ throw new Error(_context.t0);
4748
5114
  case 12:
4749
5115
  case "end":
4750
- return _context4.stop();
5116
+ return _context.stop();
4751
5117
  }
4752
- }, _callee4, null, [[0, 9]]);
5118
+ }, _callee, null, [[0, 9]]);
4753
5119
  }));
4754
5120
  return function getPineconeIndexWithMetadata() {
4755
- return _ref9.apply(this, arguments);
5121
+ return _ref3.apply(this, arguments);
4756
5122
  };
4757
5123
  }();
4758
- _context7.next = 4;
5124
+ _context4.next = 4;
4759
5125
  return retryFn(getPineconeIndexWithMetadata);
4760
5126
  case 4:
4761
- indexMetadata = _context7.sent;
5127
+ indexMetadata = _context4.sent;
4762
5128
  if (indexMetadata != null && indexMetadata.length) {
4763
- _context7.next = 8;
5129
+ _context4.next = 8;
4764
5130
  break;
4765
5131
  }
4766
5132
  console.error('No index metadata found for', index);
4767
- return _context7.abrupt("return", {
5133
+ return _context4.abrupt("return", {
4768
5134
  v: void 0
4769
5135
  });
4770
5136
  case 8:
4771
- _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
5137
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
4772
5138
  var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
4773
- 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;
4774
- return _regeneratorRuntime().wrap(function _loop3$(_context6) {
4775
- while (1) switch (_context6.prev = _context6.next) {
5139
+ 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;
5140
+ return _regeneratorRuntime().wrap(function _loop2$(_context3) {
5141
+ while (1) switch (_context3.prev = _context3.next) {
4776
5142
  case 0:
4777
- entity = _step4.value;
4778
- fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
4779
- _context6.next = 4;
5143
+ entity = _step3.value;
5144
+ fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent, syncParams = entity.syncParams;
5145
+ _context3.next = 4;
4780
5146
  return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
4781
5147
  connectionId: connectionId,
4782
5148
  name: integration
4783
5149
  });
4784
5150
  case 4:
4785
- _context6.t1 = _yield$mastra$dataLay = _context6.sent;
4786
- if (!(_context6.t1 == null)) {
4787
- _context6.next = 9;
5151
+ _context3.t1 = _yield$mastra$dataLay = _context3.sent;
5152
+ if (!(_context3.t1 == null)) {
5153
+ _context3.next = 9;
4788
5154
  break;
4789
5155
  }
4790
- _context6.t2 = void 0;
4791
- _context6.next = 10;
5156
+ _context3.t2 = void 0;
5157
+ _context3.next = 10;
4792
5158
  break;
4793
5159
  case 9:
4794
- _context6.t2 = _yield$mastra$dataLay.id;
5160
+ _context3.t2 = _yield$mastra$dataLay.id;
4795
5161
  case 10:
4796
- _context6.t0 = _context6.t2;
4797
- if (_context6.t0) {
4798
- _context6.next = 13;
5162
+ _context3.t0 = _context3.t2;
5163
+ if (_context3.t0) {
5164
+ _context3.next = 13;
4799
5165
  break;
4800
5166
  }
4801
- _context6.t0 = '';
5167
+ _context3.t0 = '';
4802
5168
  case 13:
4803
- k_id = _context6.t0;
4804
- if (!(!k_id && integration === systemName)) {
4805
- _context6.next = 19;
5169
+ k_id = _context3.t0;
5170
+ if (!(!k_id && integration === mastra.config.name)) {
5171
+ _context3.next = 19;
4806
5172
  break;
4807
5173
  }
4808
- _context6.next = 17;
5174
+ _context3.next = 17;
4809
5175
  return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
4810
5176
  connection: {
4811
5177
  connectionId: connectionId,
@@ -4818,843 +5184,409 @@ function _executeIndexSync() {
4818
5184
  }
4819
5185
  });
4820
5186
  case 17:
4821
- connection = _context6.sent;
5187
+ connection = _context3.sent;
4822
5188
  k_id = connection.id;
4823
5189
  case 19:
4824
5190
  if (k_id) {
4825
- _context6.next = 22;
5191
+ _context3.next = 22;
4826
5192
  break;
4827
5193
  }
4828
5194
  console.error('Error bootstrapping shit');
4829
- return _context6.abrupt("return", {
5195
+ return _context3.abrupt("return", {
4830
5196
  v: {
4831
5197
  v: void 0
4832
5198
  }
4833
5199
  });
4834
5200
  case 22:
4835
- _context6.next = 24;
5201
+ _context3.next = 24;
4836
5202
  return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
4837
5203
  k_id: k_id,
4838
- type: name
5204
+ type: name.toUpperCase()
4839
5205
  });
4840
5206
  case 24:
4841
- entityRecords = _context6.sent;
5207
+ entityRecords = _context3.sent;
4842
5208
  records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
4843
5209
  if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
4844
- _context6.next = 44;
5210
+ _context3.next = 46;
4845
5211
  break;
4846
5212
  }
4847
5213
  console.error('NO RECORDS ATTEMPTING SYNC');
4848
- _context6.next = 30;
5214
+ data = JSON.parse(Buffer.from(syncParams, 'base64').toString());
5215
+ console.log('sync data====', {
5216
+ data: data
5217
+ });
5218
+ _context3.next = 32;
4849
5219
  return mastra.triggerEvent({
4850
5220
  key: syncEvent,
4851
- data: {},
5221
+ data: data,
4852
5222
  user: {
4853
5223
  connectionId: connectionId
4854
5224
  }
4855
5225
  });
4856
- case 30:
4857
- _yield$mastra$trigger = _context6.sent;
4858
- _event = _yield$mastra$trigger.event;
4859
- console.log(_event, '####');
4860
- _context6.next = 35;
4861
- return _event.subscribe();
4862
- case 35:
4863
- res = _context6.sent;
5226
+ case 32:
5227
+ _yield$mastra$trigger = _context3.sent;
5228
+ event = _yield$mastra$trigger.event;
5229
+ console.log(event, '####');
5230
+ _context3.next = 37;
5231
+ return event.subscribe();
5232
+ case 37:
5233
+ res = _context3.sent;
4864
5234
  console.log('Subscribe result', res);
4865
- _context6.next = 39;
5235
+ _context3.next = 41;
4866
5236
  return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
4867
5237
  k_id: k_id,
4868
- type: entity.name
5238
+ type: entity.name.toUpperCase()
4869
5239
  });
4870
- case 39:
4871
- entityRecords = _context6.sent;
5240
+ case 41:
5241
+ entityRecords = _context3.sent;
4872
5242
  records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
4873
5243
  if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
4874
- _context6.next = 44;
5244
+ _context3.next = 46;
4875
5245
  break;
4876
5246
  }
4877
5247
  console.error('NO RECORDS AFTER SYNC');
4878
- return _context6.abrupt("return", {
5248
+ return _context3.abrupt("return", {
4879
5249
  v: {
4880
5250
  v: void 0
4881
5251
  }
4882
5252
  });
4883
- case 44:
4884
- recordsMapped = records.map(function (_ref10) {
4885
- var data = _ref10.data,
4886
- externalId = _ref10.externalId;
5253
+ case 46:
5254
+ recordsMapped = records.map(function (_ref4) {
5255
+ var data = _ref4.data,
5256
+ externalId = _ref4.externalId;
5257
+ var pickedData = pick(data, fields);
5258
+ var stringifiedData = mapValues(pickedData, String);
4887
5259
  return _extends({
4888
- id: externalId
4889
- }, pick(data, fields));
5260
+ id: String(externalId)
5261
+ }, stringifiedData);
4890
5262
  });
4891
5263
  console.log(recordsMapped, 'RECORDS');
4892
5264
  entityTypeIndex = vp.index(index);
4893
5265
  console.log(entityTypeIndex, 'INDEX');
4894
- _context6.prev = 48;
4895
- _context6.next = 51;
5266
+ _context3.prev = 50;
5267
+ _context3.next = 53;
4896
5268
  return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
4897
- var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record) {
5269
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(record) {
4898
5270
  var _yield$embed, embedding;
4899
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4900
- while (1) switch (_context5.prev = _context5.next) {
5271
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
5272
+ while (1) switch (_context2.prev = _context2.next) {
4901
5273
  case 0:
4902
- _context5.next = 2;
5274
+ _context2.next = 2;
4903
5275
  return embed({
4904
5276
  model: openai.embedding('text-embedding-3-small'),
4905
5277
  value: JSON.stringify(record)
4906
5278
  });
4907
5279
  case 2:
4908
- _yield$embed = _context5.sent;
5280
+ _yield$embed = _context2.sent;
4909
5281
  embedding = _yield$embed.embedding;
4910
- return _context5.abrupt("return", {
5282
+ return _context2.abrupt("return", {
4911
5283
  id: record.id,
4912
5284
  values: embedding,
4913
5285
  metadata: record
4914
5286
  });
4915
5287
  case 5:
4916
5288
  case "end":
4917
- return _context5.stop();
5289
+ return _context2.stop();
4918
5290
  }
4919
- }, _callee5);
5291
+ }, _callee2);
4920
5292
  }));
4921
- return function (_x7) {
4922
- return _ref11.apply(this, arguments);
5293
+ return function (_x2) {
5294
+ return _ref5.apply(this, arguments);
4923
5295
  };
4924
5296
  }())) != null ? _recordsMapped$map : []);
4925
- case 51:
4926
- vectors = _context6.sent;
5297
+ case 53:
5298
+ vectors = _context3.sent;
4927
5299
  console.log('UPSERTING', vectors);
4928
5300
  if (!(vectors.length > 0)) {
4929
- _context6.next = 56;
5301
+ _context3.next = 58;
4930
5302
  break;
4931
5303
  }
4932
- _context6.next = 56;
5304
+ _context3.next = 58;
4933
5305
  return entityTypeIndex.namespace(name).upsert(vectors);
4934
- case 56:
4935
- _context6.next = 61;
4936
- break;
4937
5306
  case 58:
4938
- _context6.prev = 58;
4939
- _context6.t3 = _context6["catch"](48);
4940
- console.error(_context6.t3);
4941
- case 61:
4942
- return _context6.abrupt("return", {
5307
+ _context3.next = 63;
5308
+ break;
5309
+ case 60:
5310
+ _context3.prev = 60;
5311
+ _context3.t3 = _context3["catch"](50);
5312
+ console.error(_context3.t3);
5313
+ case 63:
5314
+ return _context3.abrupt("return", {
4943
5315
  v: {
4944
5316
  v: void 0
4945
5317
  }
4946
5318
  });
4947
- case 62:
5319
+ case 64:
4948
5320
  case "end":
4949
- return _context6.stop();
5321
+ return _context3.stop();
4950
5322
  }
4951
- }, _loop3, null, [[48, 58]]);
5323
+ }, _loop2, null, [[50, 60]]);
4952
5324
  });
4953
- _iterator4 = _createForOfIteratorHelperLoose(indexMetadata);
5325
+ _iterator3 = _createForOfIteratorHelperLoose(indexMetadata);
4954
5326
  case 10:
4955
- if ((_step4 = _iterator4()).done) {
4956
- _context7.next = 17;
5327
+ if ((_step3 = _iterator3()).done) {
5328
+ _context4.next = 17;
4957
5329
  break;
4958
5330
  }
4959
- return _context7.delegateYield(_loop3(), "t0", 12);
5331
+ return _context4.delegateYield(_loop2(), "t0", 12);
4960
5332
  case 12:
4961
- _ret3 = _context7.t0;
4962
- if (!_ret3) {
4963
- _context7.next = 15;
5333
+ _ret2 = _context4.t0;
5334
+ if (!_ret2) {
5335
+ _context4.next = 15;
4964
5336
  break;
4965
5337
  }
4966
- return _context7.abrupt("return", _ret3.v);
5338
+ return _context4.abrupt("return", _ret2.v);
4967
5339
  case 15:
4968
- _context7.next = 10;
5340
+ _context4.next = 10;
4969
5341
  break;
4970
5342
  case 17:
4971
5343
  case "end":
4972
- return _context7.stop();
5344
+ return _context4.stop();
4973
5345
  }
4974
- }, _loop2);
5346
+ }, _loop);
4975
5347
  });
4976
- _iterator3 = _createForOfIteratorHelperLoose(indexes);
4977
- case 16:
4978
- if ((_step3 = _iterator3()).done) {
4979
- _context8.next = 23;
5348
+ _iterator2 = _createForOfIteratorHelperLoose(indexes);
5349
+ case 13:
5350
+ if ((_step2 = _iterator2()).done) {
5351
+ _context5.next = 20;
4980
5352
  break;
4981
5353
  }
4982
- return _context8.delegateYield(_loop2(), "t0", 18);
4983
- case 18:
4984
- _ret2 = _context8.t0;
4985
- if (!_ret2) {
4986
- _context8.next = 21;
5354
+ return _context5.delegateYield(_loop(), "t0", 15);
5355
+ case 15:
5356
+ _ret = _context5.t0;
5357
+ if (!_ret) {
5358
+ _context5.next = 18;
4987
5359
  break;
4988
5360
  }
4989
- return _context8.abrupt("return", _ret2.v);
4990
- case 21:
4991
- _context8.next = 16;
5361
+ return _context5.abrupt("return", _ret.v);
5362
+ case 18:
5363
+ _context5.next = 13;
4992
5364
  break;
4993
- case 23:
4994
- _context8.next = 5;
5365
+ case 20:
5366
+ _context5.next = 2;
4995
5367
  break;
4996
- case 25:
5368
+ case 22:
4997
5369
  case "end":
4998
- return _context8.stop();
5370
+ return _context5.stop();
4999
5371
  }
5000
- }, _callee6);
5372
+ }, _callee3);
5373
+ }));
5374
+ return function indexSync(_x) {
5375
+ return _ref2.apply(this, arguments);
5376
+ };
5377
+ }();
5378
+ // vector index sync
5379
+ function executeIndexSync(_x3) {
5380
+ return _executeIndexSync.apply(this, arguments);
5381
+ }
5382
+ //Generic vector sync from event data
5383
+ function _executeIndexSync() {
5384
+ _executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref6) {
5385
+ var _event$user, _event$data;
5386
+ var event, mastra, connectionId, providedIndexes;
5387
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
5388
+ while (1) switch (_context9.prev = _context9.next) {
5389
+ case 0:
5390
+ event = _ref6.event, mastra = _ref6.mastra;
5391
+ connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
5392
+ providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
5393
+ _context9.next = 5;
5394
+ return indexSync({
5395
+ connectionId: connectionId,
5396
+ knowledgeSource: providedIndexes,
5397
+ mastra: mastra
5398
+ });
5399
+ case 5:
5400
+ return _context9.abrupt("return", _context9.sent);
5401
+ case 6:
5402
+ case "end":
5403
+ return _context9.stop();
5404
+ }
5405
+ }, _callee7);
5001
5406
  }));
5002
5407
  return _executeIndexSync.apply(this, arguments);
5003
5408
  }
5004
- function executeGenericVectorSync(_x2) {
5409
+ function executeGenericVectorSync(_x4) {
5005
5410
  return _executeGenericVectorSync.apply(this, arguments);
5006
5411
  }
5007
5412
  // Vector Sync from agents Dir
5008
5413
  function _executeGenericVectorSync() {
5009
- _executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref2) {
5010
- var _event$user2, _event$data2, _event$data3;
5011
- 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;
5012
- return _regeneratorRuntime().wrap(function _callee8$(_context11) {
5013
- while (1) switch (_context11.prev = _context11.next) {
5414
+ _executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
5415
+ var _event$user2, _event$data2;
5416
+ var event, mastra, connectionId, entities;
5417
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
5418
+ while (1) switch (_context10.prev = _context10.next) {
5014
5419
  case 0:
5015
- event = _ref2.event, mastra = _ref2.mastra;
5420
+ event = _ref7.event, mastra = _ref7.mastra;
5016
5421
  connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
5017
- vector_provider = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.vector_provider;
5018
- entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
5019
- systemName = mastra.config.name;
5020
- if (vector_provider) {
5021
- _context11.next = 8;
5022
- break;
5023
- }
5024
- console.error("No vector_provider defined for agent");
5025
- return _context11.abrupt("return");
5026
- case 8:
5422
+ entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
5423
+ _context10.next = 5;
5424
+ return indexSync({
5425
+ connectionId: connectionId,
5426
+ knowledgeSource: entities,
5427
+ mastra: mastra
5428
+ });
5429
+ case 5:
5430
+ return _context10.abrupt("return", _context10.sent);
5431
+ case 6:
5432
+ case "end":
5433
+ return _context10.stop();
5434
+ }
5435
+ }, _callee8);
5436
+ }));
5437
+ return _executeGenericVectorSync.apply(this, arguments);
5438
+ }
5439
+ function executeVectorSync(_x5) {
5440
+ return _executeVectorSync.apply(this, arguments);
5441
+ }
5442
+ function _executeVectorSync() {
5443
+ _executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref8) {
5444
+ var _event$user3;
5445
+ var event, mastra, agentDir, agent, connectionId;
5446
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
5447
+ while (1) switch (_context11.prev = _context11.next) {
5448
+ case 0:
5449
+ event = _ref8.event, mastra = _ref8.mastra;
5450
+ agentDir = mastra.config.agents.agentDirPath;
5451
+ agent = getAgentBlueprint({
5452
+ agentDir: agentDir,
5453
+ agentId: event.data.agentId
5454
+ });
5455
+ connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
5456
+ _context11.next = 6;
5457
+ return indexSync({
5458
+ connectionId: connectionId,
5459
+ knowledgeSource: agent == null ? void 0 : agent.knowledge_sources,
5460
+ mastra: mastra
5461
+ });
5462
+ case 6:
5463
+ return _context11.abrupt("return", _context11.sent);
5464
+ case 7:
5465
+ case "end":
5466
+ return _context11.stop();
5467
+ }
5468
+ }, _callee9);
5469
+ }));
5470
+ return _executeVectorSync.apply(this, arguments);
5471
+ }
5472
+ function vectorQueryEngine(_x6) {
5473
+ return _vectorQueryEngine.apply(this, arguments);
5474
+ }
5475
+ function _vectorQueryEngine() {
5476
+ _vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref9) {
5477
+ var vector_provider, _ref9$topK, topK, indexName, content, entityType, vp, index, _yield$embed2, embedding, queryResponse;
5478
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
5479
+ while (1) switch (_context12.prev = _context12.next) {
5480
+ case 0:
5481
+ 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;
5027
5482
  vp = getVectorProvider(vector_provider);
5028
5483
  if (vp) {
5029
- _context11.next = 12;
5484
+ _context12.next = 5;
5030
5485
  break;
5031
5486
  }
5032
5487
  console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
5033
- return _context11.abrupt("return");
5034
- case 12:
5035
- if (process.env.OPENAI_API_KEY) {
5036
- _context11.next = 15;
5037
- break;
5038
- }
5039
- console.error('NO OPENAI_API_KEY');
5040
- return _context11.abrupt("return");
5041
- case 15:
5042
- _iterator5 = _createForOfIteratorHelperLoose(entities);
5043
- case 16:
5044
- if ((_step5 = _iterator5()).done) {
5045
- _context11.next = 50;
5046
- break;
5047
- }
5048
- vectorE = _step5.value;
5049
- integrationName = vectorE.integration;
5050
- _context11.next = 21;
5051
- return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
5052
- connectionId: connectionId,
5053
- name: integrationName
5488
+ return _context12.abrupt("return");
5489
+ case 5:
5490
+ index = vp.index(indexName);
5491
+ _context12.next = 8;
5492
+ return embed({
5493
+ model: openai.embedding('text-embedding-3-small'),
5494
+ value: content
5054
5495
  });
5055
- case 21:
5056
- _context11.t1 = _yield$mastra$dataLay2 = _context11.sent;
5057
- if (!(_context11.t1 == null)) {
5058
- _context11.next = 26;
5059
- break;
5060
- }
5061
- _context11.t2 = void 0;
5062
- _context11.next = 27;
5063
- break;
5064
- case 26:
5065
- _context11.t2 = _yield$mastra$dataLay2.id;
5066
- case 27:
5067
- _context11.t0 = _context11.t2;
5068
- if (_context11.t0) {
5069
- _context11.next = 30;
5070
- break;
5071
- }
5072
- _context11.t0 = '';
5073
- case 30:
5074
- k_id = _context11.t0;
5075
- if (!(!k_id && integrationName === systemName)) {
5076
- _context11.next = 36;
5077
- break;
5078
- }
5079
- _context11.next = 34;
5080
- return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
5081
- connection: {
5082
- connectionId: connectionId,
5083
- name: integrationName
5084
- },
5085
- credential: {
5086
- type: 'API_KEY',
5087
- value: connectionId,
5088
- scope: []
5089
- }
5090
- });
5091
- case 34:
5092
- connection = _context11.sent;
5093
- k_id = connection.id;
5094
- case 36:
5095
- if (k_id) {
5096
- _context11.next = 39;
5097
- break;
5098
- }
5099
- console.error('Error bootstrapping shit');
5100
- return _context11.abrupt("return");
5101
- case 39:
5102
- _loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
5103
- var _mastra$dataLayer7, _entityRecords3, _records3;
5104
- var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
5105
- return _regeneratorRuntime().wrap(function _loop4$(_context10) {
5106
- while (1) switch (_context10.prev = _context10.next) {
5107
- case 0:
5108
- entity = _step6.value;
5109
- _context10.next = 3;
5110
- return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
5111
- k_id: k_id,
5112
- type: entity.name
5113
- });
5114
- case 3:
5115
- entityRecords = _context10.sent;
5116
- records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
5117
- if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
5118
- _context10.next = 23;
5119
- break;
5120
- }
5121
- // @TODO: SYNC THEM
5122
- console.error('NO RECORDS');
5123
- _context10.next = 9;
5124
- return mastra.triggerEvent({
5125
- key: entity.syncEvent,
5126
- data: {},
5127
- user: {
5128
- connectionId: connectionId
5129
- }
5130
- });
5131
- case 9:
5132
- _yield$mastra$trigger2 = _context10.sent;
5133
- _event2 = _yield$mastra$trigger2.event;
5134
- console.log(_event2, '####');
5135
- _context10.next = 14;
5136
- return _event2.subscribe();
5137
- case 14:
5138
- res = _context10.sent;
5139
- console.log('Subscribe result', res);
5140
- _context10.next = 18;
5141
- return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
5142
- k_id: k_id,
5143
- type: entity.name
5144
- });
5145
- case 18:
5146
- entityRecords = _context10.sent;
5147
- records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
5148
- if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
5149
- _context10.next = 23;
5150
- break;
5151
- }
5152
- console.error('NO RECORDS AFTER SYNC');
5153
- return _context10.abrupt("return", {
5154
- v: void 0
5155
- });
5156
- case 23:
5157
- recordsMapped = records.map(function (_ref12) {
5158
- var data = _ref12.data,
5159
- externalId = _ref12.externalId;
5160
- return _extends({
5161
- id: externalId
5162
- }, pick(data, entity.fields));
5163
- });
5164
- console.log(recordsMapped, 'RECORDS');
5165
- _context10.next = 27;
5166
- return vp.createIndex({
5167
- suppressConflicts: true,
5168
- name: entity.name,
5169
- dimension: 1536,
5170
- metric: 'cosine',
5171
- spec: {
5172
- serverless: {
5173
- cloud: 'aws',
5174
- region: 'us-east-1'
5175
- }
5176
- }
5177
- });
5178
- case 27:
5179
- _context10.next = 29;
5180
- return delay$1(5000);
5181
- case 29:
5182
- entityTypeIndex = vp.index(entity.name);
5183
- console.log(entityTypeIndex, 'INDEX');
5184
- _context10.prev = 31;
5185
- _context10.next = 34;
5186
- return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
5187
- var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(record) {
5188
- var _yield$embed2, embedding;
5189
- return _regeneratorRuntime().wrap(function _callee7$(_context9) {
5190
- while (1) switch (_context9.prev = _context9.next) {
5191
- case 0:
5192
- _context9.next = 2;
5193
- return embed({
5194
- model: openai.embedding('text-embedding-3-small'),
5195
- value: JSON.stringify(record)
5196
- });
5197
- case 2:
5198
- _yield$embed2 = _context9.sent;
5199
- embedding = _yield$embed2.embedding;
5200
- return _context9.abrupt("return", {
5201
- id: record.id,
5202
- values: embedding,
5203
- metadata: record
5204
- });
5205
- case 5:
5206
- case "end":
5207
- return _context9.stop();
5208
- }
5209
- }, _callee7);
5210
- }));
5211
- return function (_x8) {
5212
- return _ref13.apply(this, arguments);
5213
- };
5214
- }())) != null ? _recordsMapped$map2 : []);
5215
- case 34:
5216
- vectors = _context10.sent;
5217
- console.log('UPSERTING', vectors);
5218
- if (!(vectors.length > 0)) {
5219
- _context10.next = 39;
5220
- break;
5221
- }
5222
- _context10.next = 39;
5223
- return entityTypeIndex.namespace(entity.name).upsert(vectors);
5224
- case 39:
5225
- _context10.next = 44;
5226
- break;
5227
- case 41:
5228
- _context10.prev = 41;
5229
- _context10.t0 = _context10["catch"](31);
5230
- console.error(_context10.t0);
5231
- case 44:
5232
- return _context10.abrupt("return", {
5233
- v: void 0
5234
- });
5235
- case 45:
5236
- case "end":
5237
- return _context10.stop();
5238
- }
5239
- }, _loop4, null, [[31, 41]]);
5240
- });
5241
- _iterator6 = _createForOfIteratorHelperLoose(vectorE.data);
5242
- case 41:
5243
- if ((_step6 = _iterator6()).done) {
5244
- _context11.next = 48;
5245
- break;
5246
- }
5247
- return _context11.delegateYield(_loop4(), "t3", 43);
5248
- case 43:
5249
- _ret4 = _context11.t3;
5250
- if (!_ret4) {
5251
- _context11.next = 46;
5252
- break;
5253
- }
5254
- return _context11.abrupt("return", _ret4.v);
5255
- case 46:
5256
- _context11.next = 41;
5257
- break;
5258
- case 48:
5259
- _context11.next = 16;
5260
- break;
5261
- case 50:
5262
- case "end":
5263
- return _context11.stop();
5264
- }
5265
- }, _callee8);
5266
- }));
5267
- return _executeGenericVectorSync.apply(this, arguments);
5268
- }
5269
- function executeVectorSync(_x3) {
5270
- return _executeVectorSync.apply(this, arguments);
5271
- }
5272
- function _executeVectorSync() {
5273
- _executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref3) {
5274
- var _event$user3, _agent$knowledge_sour;
5275
- 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;
5276
- return _regeneratorRuntime().wrap(function _callee10$(_context14) {
5277
- while (1) switch (_context14.prev = _context14.next) {
5278
- case 0:
5279
- event = _ref3.event, mastra = _ref3.mastra;
5280
- agentDir = mastra.config.agents.agentDirPath;
5281
- agent = getAgentBlueprint({
5282
- agentDir: agentDir,
5283
- agentId: event.data.agentId
5284
- });
5285
- connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
5286
- systemName = mastra.config.name;
5287
- if (agent.knowledge_sources.vector_provider) {
5288
- _context14.next = 8;
5289
- break;
5290
- }
5291
- console.error("No vector_provider defined for agent");
5292
- return _context14.abrupt("return");
5293
5496
  case 8:
5294
- vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
5295
- if (vp) {
5296
- _context14.next = 12;
5297
- break;
5298
- }
5299
- console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
5300
- return _context14.abrupt("return");
5301
- case 12:
5302
- if (process.env.OPENAI_API_KEY) {
5303
- _context14.next = 15;
5304
- break;
5305
- }
5306
- console.error('NO OPENAI_API_KEY');
5307
- return _context14.abrupt("return");
5308
- case 15:
5309
- if (!(!agent || !(agent != null && agent.knowledge_sources))) {
5310
- _context14.next = 18;
5311
- break;
5312
- }
5313
- console.error('NO AGENT OR KNOWLEDGE SOURCES');
5314
- return _context14.abrupt("return");
5315
- case 18:
5316
- _iterator7 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
5317
- case 19:
5318
- if ((_step7 = _iterator7()).done) {
5319
- _context14.next = 53;
5320
- break;
5321
- }
5322
- vectorE = _step7.value;
5323
- integrationName = vectorE.integration;
5324
- _context14.next = 24;
5325
- return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
5326
- connectionId: connectionId,
5327
- name: integrationName
5328
- });
5329
- case 24:
5330
- _context14.t1 = _yield$mastra$dataLay3 = _context14.sent;
5331
- if (!(_context14.t1 == null)) {
5332
- _context14.next = 29;
5333
- break;
5334
- }
5335
- _context14.t2 = void 0;
5336
- _context14.next = 30;
5337
- break;
5338
- case 29:
5339
- _context14.t2 = _yield$mastra$dataLay3.id;
5340
- case 30:
5341
- _context14.t0 = _context14.t2;
5342
- if (_context14.t0) {
5343
- _context14.next = 33;
5344
- break;
5345
- }
5346
- _context14.t0 = '';
5347
- case 33:
5348
- k_id = _context14.t0;
5349
- if (!(!k_id && integrationName === systemName)) {
5350
- _context14.next = 39;
5351
- break;
5352
- }
5353
- _context14.next = 37;
5354
- return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
5355
- connection: {
5356
- connectionId: connectionId,
5357
- name: integrationName
5358
- },
5359
- credential: {
5360
- type: 'API_KEY',
5361
- value: connectionId,
5362
- scope: []
5363
- }
5364
- });
5365
- case 37:
5366
- connection = _context14.sent;
5367
- k_id = connection.id;
5368
- case 39:
5369
- if (k_id) {
5370
- _context14.next = 42;
5371
- break;
5372
- }
5373
- console.error('Error bootstrapping shit');
5374
- return _context14.abrupt("return");
5375
- case 42:
5376
- _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
5377
- var _mastra$dataLayer11, _entityRecords5, _records5;
5378
- var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
5379
- return _regeneratorRuntime().wrap(function _loop5$(_context13) {
5380
- while (1) switch (_context13.prev = _context13.next) {
5381
- case 0:
5382
- entity = _step8.value;
5383
- _context13.next = 3;
5384
- return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
5385
- k_id: k_id,
5386
- type: entity.name
5387
- });
5388
- case 3:
5389
- entityRecords = _context13.sent;
5390
- records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
5391
- if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
5392
- _context13.next = 23;
5393
- break;
5394
- }
5395
- // @TODO: SYNC THEM
5396
- console.error('NO RECORDS');
5397
- _context13.next = 9;
5398
- return mastra.triggerEvent({
5399
- key: entity.syncEvent,
5400
- data: {},
5401
- user: {
5402
- connectionId: connectionId
5403
- }
5404
- });
5405
- case 9:
5406
- _yield$mastra$trigger3 = _context13.sent;
5407
- _event3 = _yield$mastra$trigger3.event;
5408
- console.log(_event3, '####');
5409
- _context13.next = 14;
5410
- return _event3.subscribe();
5411
- case 14:
5412
- res = _context13.sent;
5413
- console.log('Subscribe result', res);
5414
- _context13.next = 18;
5415
- return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
5416
- k_id: k_id,
5417
- type: entity.name
5418
- });
5419
- case 18:
5420
- entityRecords = _context13.sent;
5421
- records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
5422
- if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
5423
- _context13.next = 23;
5424
- break;
5425
- }
5426
- console.error('NO RECORDS AFTER SYNC');
5427
- return _context13.abrupt("return", {
5428
- v: void 0
5429
- });
5430
- case 23:
5431
- recordsMapped = records.map(function (_ref14) {
5432
- var data = _ref14.data,
5433
- externalId = _ref14.externalId;
5434
- return _extends({
5435
- id: externalId
5436
- }, pick(data, entity.fields));
5437
- });
5438
- console.log(recordsMapped, 'RECORDS');
5439
- _context13.next = 27;
5440
- return vp.createIndex({
5441
- suppressConflicts: true,
5442
- name: entity.name,
5443
- dimension: 1536,
5444
- metric: 'cosine',
5445
- spec: {
5446
- serverless: {
5447
- cloud: 'aws',
5448
- region: 'us-east-1'
5449
- }
5450
- }
5451
- });
5452
- case 27:
5453
- entityTypeIndex = vp.index(entity.name);
5454
- console.log(entityTypeIndex, 'INDEX');
5455
- _context13.prev = 29;
5456
- _context13.next = 32;
5457
- return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
5458
- var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
5459
- var _yield$embed3, embedding;
5460
- return _regeneratorRuntime().wrap(function _callee9$(_context12) {
5461
- while (1) switch (_context12.prev = _context12.next) {
5462
- case 0:
5463
- _context12.next = 2;
5464
- return embed({
5465
- model: openai.embedding('text-embedding-3-small'),
5466
- value: JSON.stringify(record)
5467
- });
5468
- case 2:
5469
- _yield$embed3 = _context12.sent;
5470
- embedding = _yield$embed3.embedding;
5471
- return _context12.abrupt("return", {
5472
- id: record.id,
5473
- values: embedding,
5474
- metadata: record
5475
- });
5476
- case 5:
5477
- case "end":
5478
- return _context12.stop();
5479
- }
5480
- }, _callee9);
5481
- }));
5482
- return function (_x9) {
5483
- return _ref15.apply(this, arguments);
5484
- };
5485
- }())) != null ? _recordsMapped$map3 : []);
5486
- case 32:
5487
- vectors = _context13.sent;
5488
- console.log('UPSERTING', vectors);
5489
- if (!(vectors.length > 0)) {
5490
- _context13.next = 37;
5491
- break;
5492
- }
5493
- _context13.next = 37;
5494
- return entityTypeIndex.namespace(entity.name).upsert(vectors);
5495
- case 37:
5496
- _context13.next = 42;
5497
- break;
5498
- case 39:
5499
- _context13.prev = 39;
5500
- _context13.t0 = _context13["catch"](29);
5501
- console.error(_context13.t0);
5502
- case 42:
5503
- return _context13.abrupt("return", {
5504
- v: void 0
5505
- });
5506
- case 43:
5507
- case "end":
5508
- return _context13.stop();
5509
- }
5510
- }, _loop5, null, [[29, 39]]);
5511
- });
5512
- _iterator8 = _createForOfIteratorHelperLoose(vectorE.data);
5513
- case 44:
5514
- if ((_step8 = _iterator8()).done) {
5515
- _context14.next = 51;
5516
- break;
5517
- }
5518
- return _context14.delegateYield(_loop5(), "t3", 46);
5519
- case 46:
5520
- _ret5 = _context14.t3;
5521
- if (!_ret5) {
5522
- _context14.next = 49;
5523
- break;
5524
- }
5525
- return _context14.abrupt("return", _ret5.v);
5526
- case 49:
5527
- _context14.next = 44;
5528
- break;
5529
- case 51:
5530
- _context14.next = 19;
5531
- break;
5532
- case 53:
5533
- case "end":
5534
- return _context14.stop();
5535
- }
5536
- }, _callee10);
5537
- }));
5538
- return _executeVectorSync.apply(this, arguments);
5539
- }
5540
- function vectorQueryEngine(_x4) {
5541
- return _vectorQueryEngine.apply(this, arguments);
5542
- }
5543
- function _vectorQueryEngine() {
5544
- _vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref4) {
5545
- var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
5546
- return _regeneratorRuntime().wrap(function _callee11$(_context15) {
5547
- while (1) switch (_context15.prev = _context15.next) {
5548
- case 0:
5549
- 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;
5550
- vp = getVectorProvider(vector_provider);
5551
- if (vp) {
5552
- _context15.next = 5;
5553
- break;
5554
- }
5555
- console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
5556
- return _context15.abrupt("return");
5557
- case 5:
5558
- index = vp.index(indexName);
5559
- _context15.next = 8;
5560
- return embed({
5561
- model: openai.embedding('text-embedding-3-small'),
5562
- value: content
5563
- });
5564
- case 8:
5565
- _yield$embed4 = _context15.sent;
5566
- embedding = _yield$embed4.embedding;
5497
+ _yield$embed2 = _context12.sent;
5498
+ embedding = _yield$embed2.embedding;
5567
5499
  console.log(embedding, 'EMBEDDING');
5568
- _context15.next = 13;
5500
+ _context12.next = 13;
5569
5501
  return index.namespace(entityType).query({
5570
5502
  vector: embedding,
5571
5503
  topK: topK,
5572
5504
  includeMetadata: true
5573
5505
  });
5574
5506
  case 13:
5575
- queryResponse = _context15.sent;
5576
- return _context15.abrupt("return", queryResponse);
5507
+ queryResponse = _context12.sent;
5508
+ return _context12.abrupt("return", queryResponse);
5577
5509
  case 15:
5578
5510
  case "end":
5579
- return _context15.stop();
5511
+ return _context12.stop();
5580
5512
  }
5581
- }, _callee11);
5513
+ }, _callee10);
5582
5514
  }));
5583
5515
  return _vectorQueryEngine.apply(this, arguments);
5584
5516
  }
5585
5517
  var getPineconeIndices = /*#__PURE__*/function () {
5586
- var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
5518
+ var _ref10 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
5587
5519
  var vectorLayer, indexes, indexesWithStats;
5588
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
5589
- while (1) switch (_context2.prev = _context2.next) {
5520
+ return _regeneratorRuntime().wrap(function _callee5$(_context7) {
5521
+ while (1) switch (_context7.prev = _context7.next) {
5590
5522
  case 0:
5591
5523
  vectorLayer = new VectorLayer();
5592
- _context2.next = 3;
5524
+ _context7.next = 3;
5593
5525
  return vectorLayer.fetchPineconeIndexes();
5594
5526
  case 3:
5595
- indexes = _context2.sent;
5527
+ indexes = _context7.sent;
5596
5528
  if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
5597
- _context2.next = 9;
5529
+ _context7.next = 9;
5598
5530
  break;
5599
5531
  }
5600
- _context2.next = 7;
5532
+ _context7.next = 7;
5601
5533
  return Promise.all(indexes.map(/*#__PURE__*/function () {
5602
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(index) {
5534
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index) {
5603
5535
  var stats, namespaces;
5604
- return _regeneratorRuntime().wrap(function _callee$(_context) {
5605
- while (1) switch (_context.prev = _context.next) {
5536
+ return _regeneratorRuntime().wrap(function _callee4$(_context6) {
5537
+ while (1) switch (_context6.prev = _context6.next) {
5606
5538
  case 0:
5607
- _context.next = 2;
5539
+ _context6.next = 2;
5608
5540
  return vectorLayer.fetchPineconeIndexStats(index.host);
5609
5541
  case 2:
5610
- stats = _context.sent;
5542
+ stats = _context6.sent;
5611
5543
  namespaces = [];
5612
5544
  if (stats != null && stats.namespaces) {
5613
5545
  namespaces = Object.keys(stats.namespaces);
5614
5546
  }
5615
- return _context.abrupt("return", _extends({}, index, {
5547
+ return _context6.abrupt("return", _extends({}, index, {
5616
5548
  namespaces: namespaces
5617
5549
  }));
5618
5550
  case 6:
5619
5551
  case "end":
5620
- return _context.stop();
5552
+ return _context6.stop();
5621
5553
  }
5622
- }, _callee);
5554
+ }, _callee4);
5623
5555
  }));
5624
- return function (_x5) {
5625
- return _ref6.apply(this, arguments);
5556
+ return function (_x7) {
5557
+ return _ref11.apply(this, arguments);
5626
5558
  };
5627
5559
  }()));
5628
5560
  case 7:
5629
- indexesWithStats = _context2.sent;
5630
- return _context2.abrupt("return", indexesWithStats);
5561
+ indexesWithStats = _context7.sent;
5562
+ return _context7.abrupt("return", indexesWithStats);
5631
5563
  case 9:
5632
- return _context2.abrupt("return", []);
5564
+ return _context7.abrupt("return", []);
5633
5565
  case 10:
5634
5566
  case "end":
5635
- return _context2.stop();
5567
+ return _context7.stop();
5636
5568
  }
5637
- }, _callee2);
5569
+ }, _callee5);
5638
5570
  }));
5639
5571
  return function getPineconeIndices() {
5640
- return _ref5.apply(this, arguments);
5572
+ return _ref10.apply(this, arguments);
5641
5573
  };
5642
5574
  }();
5643
- function getVectorQueryApis(_ref7) {
5644
- var mastra = _ref7.mastra;
5575
+ function getVectorQueryApis(_ref12) {
5576
+ var mastra = _ref12.mastra;
5645
5577
  var vectorProvider = mastra.config.agents.vectorProvider;
5646
5578
  if (!vectorProvider) {
5647
5579
  console.error('NO VECTOR PROVIDER');
5648
5580
  return [];
5649
5581
  }
5650
5582
  var vectorApis = [];
5651
- var _loop = function _loop() {
5652
- var provider = _step.value;
5583
+ var _loop3 = function _loop3() {
5584
+ var provider = _step4.value;
5653
5585
  if (provider.name.toUpperCase() === 'PINECONE') {
5654
5586
  var config = getPineconeConfig({
5655
5587
  dir: provider.dirPath
5656
5588
  });
5657
- if (!config) {
5589
+ if (!config || (config == null ? void 0 : config.length) === 0) {
5658
5590
  return {
5659
5591
  v: []
5660
5592
  };
@@ -5664,21 +5596,22 @@ function getVectorQueryApis(_ref7) {
5664
5596
  index == null || index.namespaces.forEach(function (namespace) {
5665
5597
  vectorApis.push({
5666
5598
  integrationName: mastra.config.name,
5667
- type: "vector_query_" + index.name + "_" + namespace,
5599
+ type: "vq_" + index.name + "_" + namespace,
5668
5600
  label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5669
5601
  description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
5670
5602
  schema: z.object({
5671
5603
  content: z.string(),
5672
5604
  topResult: z.number()
5673
5605
  }),
5606
+ source: provider.name.toUpperCase(),
5674
5607
  executor: function () {
5675
- var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
5608
+ var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref13) {
5676
5609
  var data, res;
5677
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
5678
- while (1) switch (_context3.prev = _context3.next) {
5610
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
5611
+ while (1) switch (_context8.prev = _context8.next) {
5679
5612
  case 0:
5680
- data = _ref8.data;
5681
- _context3.next = 3;
5613
+ data = _ref13.data;
5614
+ _context8.next = 3;
5682
5615
  return vectorQueryEngine({
5683
5616
  vector_provider: provider.name,
5684
5617
  indexName: index.name,
@@ -5687,19 +5620,19 @@ function getVectorQueryApis(_ref7) {
5687
5620
  entityType: namespace
5688
5621
  });
5689
5622
  case 3:
5690
- res = _context3.sent;
5623
+ res = _context8.sent;
5691
5624
  console.log(JSON.stringify({
5692
5625
  res: res
5693
5626
  }, null, 2));
5694
5627
  // @TODO: make this a proper response
5695
- return _context3.abrupt("return", res);
5628
+ return _context8.abrupt("return", res);
5696
5629
  case 6:
5697
5630
  case "end":
5698
- return _context3.stop();
5631
+ return _context8.stop();
5699
5632
  }
5700
- }, _callee3);
5633
+ }, _callee6);
5701
5634
  }));
5702
- function executor(_x6) {
5635
+ function executor(_x8) {
5703
5636
  return _executor.apply(this, arguments);
5704
5637
  }
5705
5638
  return executor;
@@ -5710,10 +5643,10 @@ function getVectorQueryApis(_ref7) {
5710
5643
  });
5711
5644
  }
5712
5645
  },
5713
- _ret;
5714
- for (var _iterator = _createForOfIteratorHelperLoose(vectorProvider), _step; !(_step = _iterator()).done;) {
5715
- _ret = _loop();
5716
- if (_ret) return _ret.v;
5646
+ _ret3;
5647
+ for (var _iterator4 = _createForOfIteratorHelperLoose(vectorProvider), _step4; !(_step4 = _iterator4()).done;) {
5648
+ _ret3 = _loop3();
5649
+ if (_ret3) return _ret3.v;
5717
5650
  }
5718
5651
  return vectorApis;
5719
5652
  }
@@ -5740,6 +5673,74 @@ function vectorIndexSync() {
5740
5673
  executor: executeIndexSync
5741
5674
  };
5742
5675
  }
5676
+ function syncAndWriteVectorProviderIndexesToLocal(_x9) {
5677
+ return _syncAndWriteVectorProviderIndexesToLocal.apply(this, arguments);
5678
+ }
5679
+ function _syncAndWriteVectorProviderIndexesToLocal() {
5680
+ _syncAndWriteVectorProviderIndexesToLocal = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref14) {
5681
+ var mastra, vectorProviders, pullVectorProviderIndexes;
5682
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
5683
+ while (1) switch (_context15.prev = _context15.next) {
5684
+ case 0:
5685
+ mastra = _ref14.mastra;
5686
+ // TODO: Return in prod ? or do somethif different
5687
+ vectorProviders = mastra.config.agents.vectorProvider;
5688
+ pullVectorProviderIndexes = /*#__PURE__*/function () {
5689
+ var _ref16 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref15) {
5690
+ var provider, dirPath, name, indexes, MASTRA_APP_DIR, providerIndexPath;
5691
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
5692
+ while (1) switch (_context13.prev = _context13.next) {
5693
+ case 0:
5694
+ provider = _ref15.provider;
5695
+ dirPath = provider.dirPath, name = provider.name;
5696
+ if (!(name === 'PINECONE')) {
5697
+ _context13.next = 9;
5698
+ break;
5699
+ }
5700
+ _context13.next = 5;
5701
+ return getPineconeIndices();
5702
+ case 5:
5703
+ indexes = _context13.sent;
5704
+ MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
5705
+ providerIndexPath = path.join(MASTRA_APP_DIR, dirPath, name.toLowerCase() + ".json");
5706
+ writeFileSync(providerIndexPath, JSON.stringify(indexes, null, 2));
5707
+ case 9:
5708
+ case "end":
5709
+ return _context13.stop();
5710
+ }
5711
+ }, _callee11);
5712
+ }));
5713
+ return function pullVectorProviderIndexes(_x10) {
5714
+ return _ref16.apply(this, arguments);
5715
+ };
5716
+ }();
5717
+ _context15.next = 5;
5718
+ return Promise.all(vectorProviders.map(/*#__PURE__*/function () {
5719
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(provider) {
5720
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
5721
+ while (1) switch (_context14.prev = _context14.next) {
5722
+ case 0:
5723
+ return _context14.abrupt("return", pullVectorProviderIndexes({
5724
+ provider: provider
5725
+ }));
5726
+ case 1:
5727
+ case "end":
5728
+ return _context14.stop();
5729
+ }
5730
+ }, _callee12);
5731
+ }));
5732
+ return function (_x11) {
5733
+ return _ref17.apply(this, arguments);
5734
+ };
5735
+ }()));
5736
+ case 5:
5737
+ case "end":
5738
+ return _context15.stop();
5739
+ }
5740
+ }, _callee13);
5741
+ }));
5742
+ return _syncAndWriteVectorProviderIndexesToLocal.apply(this, arguments);
5743
+ }
5743
5744
 
5744
5745
  function getAgentSystemApis(_ref) {
5745
5746
  var mastra = _ref.mastra;
@@ -5857,8 +5858,8 @@ function createAssistantAgentHandler(logger) {
5857
5858
  });
5858
5859
  case 3:
5859
5860
  assistant = _context.sent;
5860
- logger({
5861
- destinationPath: assistant.id + ".json",
5861
+ logger == null || logger.info({
5862
+ destinationPath: "" + assistant.id,
5862
5863
  statusCode: 201,
5863
5864
  message: JSON.stringify({
5864
5865
  message: 'Created assistant',
@@ -5901,8 +5902,8 @@ function updateAssistantAgentHandler(logger) {
5901
5902
  });
5902
5903
  case 3:
5903
5904
  assistant = _context2.sent;
5904
- logger({
5905
- destinationPath: assistant.id + ".json",
5905
+ logger == null || logger.info({
5906
+ destinationPath: "" + assistant.id,
5906
5907
  statusCode: 200,
5907
5908
  message: JSON.stringify({
5908
5909
  message: 'Updated assistant',
@@ -5969,8 +5970,8 @@ function getAssistantAgentHandler(logger) {
5969
5970
  return _context3.abrupt("return", _context3.sent);
5970
5971
  case 14:
5971
5972
  console.error('Run did not complete:', run);
5972
- logger({
5973
- destinationPath: id + ".json",
5973
+ logger == null || logger.error({
5974
+ destinationPath: "" + id,
5974
5975
  statusCode: 400,
5975
5976
  message: JSON.stringify({
5976
5977
  message: "Run did not complete",
@@ -5980,7 +5981,8 @@ function getAssistantAgentHandler(logger) {
5980
5981
  }
5981
5982
  }, null, 2)
5982
5983
  });
5983
- case 16:
5984
+ return _context3.abrupt("return", run == null ? void 0 : run.last_error);
5985
+ case 17:
5984
5986
  case "end":
5985
5987
  return _context3.stop();
5986
5988
  }
@@ -6016,8 +6018,8 @@ function getAssistantAgentHandler(logger) {
6016
6018
  fn: tool["function"].name,
6017
6019
  availableTools: Object.keys(toolMap)
6018
6020
  };
6019
- logger({
6020
- destinationPath: id + ".json",
6021
+ logger == null || logger.info({
6022
+ destinationPath: "" + id,
6021
6023
  statusCode: 100,
6022
6024
  message: JSON.stringify({
6023
6025
  message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
@@ -6031,8 +6033,8 @@ function getAssistantAgentHandler(logger) {
6031
6033
  _context4.next = 8;
6032
6034
  break;
6033
6035
  }
6034
- logger({
6035
- destinationPath: id + ".json",
6036
+ logger == null || logger.error({
6037
+ destinationPath: "" + id,
6036
6038
  statusCode: 404,
6037
6039
  message: JSON.stringify({
6038
6040
  message: "[local] No tool fn found: " + tool["function"].name,
@@ -6048,8 +6050,8 @@ function getAssistantAgentHandler(logger) {
6048
6050
  try {
6049
6051
  if (tool["function"].arguments) {
6050
6052
  args = JSON.parse(tool["function"].arguments);
6051
- logger({
6052
- destinationPath: id + ".json",
6053
+ logger == null || logger.info({
6054
+ destinationPath: "" + id,
6053
6055
  statusCode: 200,
6054
6056
  message: JSON.stringify({
6055
6057
  message: "[local] Passing args to tool call: " + tool["function"].name,
@@ -6067,8 +6069,8 @@ function getAssistantAgentHandler(logger) {
6067
6069
  return toolFn(args);
6068
6070
  case 13:
6069
6071
  output = _context4.sent;
6070
- logger({
6071
- destinationPath: id + ".json",
6072
+ logger == null || logger.info({
6073
+ destinationPath: "" + id,
6072
6074
  statusCode: 200,
6073
6075
  message: JSON.stringify({
6074
6076
  message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
@@ -6100,8 +6102,8 @@ function getAssistantAgentHandler(logger) {
6100
6102
  break;
6101
6103
  }
6102
6104
  console.error('No tool outputs to submit.');
6103
- logger({
6104
- destinationPath: id + ".json",
6105
+ logger == null || logger.error({
6106
+ destinationPath: "" + id,
6105
6107
  statusCode: 404,
6106
6108
  message: JSON.stringify({
6107
6109
  message: "No tool outputs submitted",
@@ -6124,8 +6126,8 @@ function getAssistantAgentHandler(logger) {
6124
6126
  });
6125
6127
  case 15:
6126
6128
  run = _context5.sent;
6127
- logger({
6128
- destinationPath: id + ".json",
6129
+ logger == null || logger.info({
6130
+ destinationPath: "" + id,
6129
6131
  statusCode: 200,
6130
6132
  message: JSON.stringify({
6131
6133
  message: "Tool outputs submitted",
@@ -6138,8 +6140,8 @@ function getAssistantAgentHandler(logger) {
6138
6140
  _context5.next = 22;
6139
6141
  break;
6140
6142
  case 20:
6141
- logger({
6142
- destinationPath: id + ".json",
6143
+ logger == null || logger.info({
6144
+ destinationPath: "" + id,
6143
6145
  statusCode: 404,
6144
6146
  message: JSON.stringify({
6145
6147
  message: "No tool outputs to submit",
@@ -6288,8 +6290,8 @@ function getAssistantAgentHandler(logger) {
6288
6290
  });
6289
6291
  case 9:
6290
6292
  run = _context10.sent;
6291
- logger({
6292
- destinationPath: id + ".json",
6293
+ logger == null || logger.info({
6294
+ destinationPath: "" + id,
6293
6295
  statusCode: 202,
6294
6296
  message: JSON.stringify({
6295
6297
  message: "Creating and polling run, tool choice required",
@@ -6711,65 +6713,114 @@ function _getAgent() {
6711
6713
  return _getAgent.apply(this, arguments);
6712
6714
  }
6713
6715
 
6714
- var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
6715
- function createFileLogger() {
6716
- return function (log) {
6717
- var fullPath = path.join(loggerPath, log.destinationPath);
6718
- if (!existsSync(loggerPath)) {
6719
- mkdirSync(loggerPath, {
6720
- recursive: true
6721
- });
6722
- return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
6723
- createdAt: new Date()
6724
- })], null, 2));
6725
- }
6726
- if (!existsSync(fullPath)) {
6727
- return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
6728
- createdAt: new Date()
6729
- })], null, 2));
6716
+ function getWorkflowApis(_ref) {
6717
+ var mastra = _ref.mastra;
6718
+ var blueprintDirPath = mastra.config.workflows.blueprintDirPath;
6719
+ var getBlueprintsDirPath = function getBlueprintsDirPath() {
6720
+ var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
6721
+ if (!blueprintDirPath) {
6722
+ throw new Error('Missing blueprintDirPath in config');
6730
6723
  }
6731
- var logs = JSON.parse(readFileSync(fullPath, 'utf-8'));
6732
- logs.push(_extends({}, log, {
6733
- createdAt: new Date()
6734
- }));
6735
- return writeFileSync(fullPath, JSON.stringify(logs, null, 2));
6724
+ return path.join(MASTRA_APP_DIR, blueprintDirPath);
6736
6725
  };
6737
- }
6738
- function getUpstashLogs(_x) {
6739
- return _getUpstashLogs.apply(this, arguments);
6740
- }
6741
- function _getUpstashLogs() {
6742
- _getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
6743
- var id, url, token, redis;
6744
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6745
- while (1) switch (_context.prev = _context.next) {
6746
- case 0:
6747
- id = _ref.id, url = _ref.url, token = _ref.token;
6748
- redis = new Redis({
6749
- url: url,
6750
- token: token
6751
- });
6752
- return _context.abrupt("return", redis.lrange(id, 0, -1));
6753
- case 3:
6754
- case "end":
6755
- return _context.stop();
6726
+ var blueprints = getBlueprintsSync({
6727
+ directoryPath: getBlueprintsDirPath()
6728
+ });
6729
+ var publishedBlueprints = blueprints.filter(function (blueprint) {
6730
+ return blueprint.status === WorkflowStatusEnum.PUBLISHED;
6731
+ });
6732
+ var events = mastra.getGlobalEvents();
6733
+ var allEvents = Array.from(events.values()).reduce(function (acc, val) {
6734
+ return _extends({}, acc, val);
6735
+ }, {});
6736
+ var getEvent = function getEvent(type) {
6737
+ var _Object$entries$find;
6738
+ return (_Object$entries$find = Object.entries(allEvents).find(function (_ref2) {
6739
+ var key = _ref2[0];
6740
+ return key === type;
6741
+ })) == null ? void 0 : _Object$entries$find[1];
6742
+ };
6743
+ return publishedBlueprints.map(function (blueprint) {
6744
+ var _getEvent, _blueprint$trigger;
6745
+ return {
6746
+ integrationName: mastra.config.name,
6747
+ source: 'WORKFLOW',
6748
+ description: "Workflow Trigger API for " + blueprint.title + " ",
6749
+ label: blueprint.title + " Trigger",
6750
+ schema: (_getEvent = getEvent((_blueprint$trigger = blueprint.trigger) == null ? void 0 : _blueprint$trigger.type)) == null ? void 0 : _getEvent.schema,
6751
+ type: blueprint == null ? void 0 : blueprint.title.replaceAll(' ', '_').toLowerCase(),
6752
+ executor: function executor(params) {
6753
+ var _blueprint$trigger2;
6754
+ var data = params.data,
6755
+ ctx = params.ctx;
6756
+ return mastra.triggerEvent({
6757
+ data: data,
6758
+ key: (_blueprint$trigger2 = blueprint.trigger) == null ? void 0 : _blueprint$trigger2.type,
6759
+ integrationName: mastra.config.name,
6760
+ user: {
6761
+ connectionId: ctx.connectionId
6762
+ }
6763
+ });
6756
6764
  }
6757
- }, _callee);
6758
- }));
6759
- return _getUpstashLogs.apply(this, arguments);
6760
- }
6761
- function createUpstashLogger(_ref2) {
6762
- var url = _ref2.url,
6763
- token = _ref2.token;
6764
- var redis = new Redis({
6765
- url: url,
6766
- token: token
6765
+ };
6767
6766
  });
6768
- return function (log) {
6769
- redis.lpush(log.destinationPath, JSON.stringify(_extends({}, log, {
6770
- createdAt: new Date()
6771
- })));
6767
+ }
6768
+ function eventTriggerApi(_ref3) {
6769
+ var mastra = _ref3.mastra;
6770
+ var api = {
6771
+ integrationName: mastra.config.name,
6772
+ type: 'trigger_event',
6773
+ label: 'Trigger event',
6774
+ // getSchemaOptions({ ctx }) {
6775
+ // const options = Promise.resolve({
6776
+ // event: {
6777
+ // options: Array.from(framework.globalEvents.values()).flatMap(
6778
+ // (eventRecord) =>
6779
+ // Object.values(eventRecord).map((event) => ({
6780
+ // value: event.key || event.label || '',
6781
+ // label: event.key || event.label || '',
6782
+ // })).filter((event) => event.value !== '')
6783
+ // ),
6784
+ // },
6785
+ // });
6786
+ // return options;
6787
+ // },
6788
+ description: 'Trigger event',
6789
+ schema: z.object({
6790
+ event: z.string(),
6791
+ data: z.record(z.any())
6792
+ }),
6793
+ executor: function () {
6794
+ var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref4) {
6795
+ var data, ctx, event;
6796
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6797
+ while (1) switch (_context.prev = _context.next) {
6798
+ case 0:
6799
+ data = _ref4.data, ctx = _ref4.ctx;
6800
+ event = data.event;
6801
+ _context.next = 4;
6802
+ return mastra.triggerEvent({
6803
+ key: event,
6804
+ data: data.data,
6805
+ user: {
6806
+ connectionId: ctx.connectionId
6807
+ }
6808
+ });
6809
+ case 4:
6810
+ return _context.abrupt("return", _context.sent);
6811
+ case 5:
6812
+ case "end":
6813
+ return _context.stop();
6814
+ }
6815
+ }, _callee);
6816
+ }));
6817
+ function executor(_x) {
6818
+ return _executor.apply(this, arguments);
6819
+ }
6820
+ return executor;
6821
+ }()
6772
6822
  };
6823
+ return api;
6773
6824
  }
6774
6825
 
6775
6826
  var Mastra = /*#__PURE__*/function () {
@@ -6789,7 +6840,7 @@ var Mastra = /*#__PURE__*/function () {
6789
6840
  agentDirPath: '',
6790
6841
  vectorProvider: []
6791
6842
  };
6792
- this.logger = void 0;
6843
+ this.logger = new Map();
6793
6844
  this.config = void 0;
6794
6845
  this.runBlueprint = /*#__PURE__*/function () {
6795
6846
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
@@ -6823,7 +6874,8 @@ var Mastra = /*#__PURE__*/function () {
6823
6874
  blueprint: blueprint,
6824
6875
  frameworkApis: frameworkApis,
6825
6876
  frameworkEvents: frameworkEvents,
6826
- ctx: ctx
6877
+ ctx: ctx,
6878
+ logger: _this.logger.get('WORKFLOW')
6827
6879
  });
6828
6880
  case 10:
6829
6881
  case "end":
@@ -6838,9 +6890,10 @@ var Mastra = /*#__PURE__*/function () {
6838
6890
  this.dataLayer = dataLayer;
6839
6891
  this.vectorLayer = vectorLayer;
6840
6892
  this.config = config;
6893
+ this.__backgroundTasks();
6841
6894
  }
6842
6895
  Mastra.init = function init(config) {
6843
- var _config$logs, _config$logs2, _config$workflows$sys;
6896
+ var _config$logs, _config$logs4, _config$workflows$sys;
6844
6897
  if (!config.db.uri) {
6845
6898
  throw new Error('No database config/provider found');
6846
6899
  }
@@ -6854,87 +6907,74 @@ var Mastra = /*#__PURE__*/function () {
6854
6907
  dataLayer: dataLayer,
6855
6908
  vectorLayer: vectorLayer
6856
6909
  });
6857
- var logger;
6858
- if (!(config != null && config.logs)) {
6859
- logger = console.log;
6860
- } else if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
6861
- logger = createFileLogger();
6862
- } else if (((_config$logs2 = config.logs) == null ? void 0 : _config$logs2.provider) === 'UPSTASH') {
6863
- var _config$logs$config, _config$logs$config2;
6864
- logger = createUpstashLogger({
6910
+ var agentLogger, workflowLogger;
6911
+ if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
6912
+ var _config$logs2, _config$logs3;
6913
+ var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
6914
+ var basePath = path.join(MASTRA_APP_DIR, '/mastra-logs/');
6915
+ agentLogger = createLogger({
6916
+ type: 'FILE',
6917
+ options: {
6918
+ dirPath: path.join(basePath, 'agent'),
6919
+ level: (_config$logs2 = config.logs) == null ? void 0 : _config$logs2.level
6920
+ }
6921
+ });
6922
+ workflowLogger = createLogger({
6923
+ type: 'FILE',
6924
+ options: {
6925
+ dirPath: path.join(basePath, 'workflow'),
6926
+ level: (_config$logs3 = config.logs) == null ? void 0 : _config$logs3.level
6927
+ }
6928
+ });
6929
+ } else if (((_config$logs4 = config.logs) == null ? void 0 : _config$logs4.provider) === 'UPSTASH') {
6930
+ var _config$logs$config, _config$logs$config2, _config$logs5, _config$logs6;
6931
+ var redisClient = new Redis({
6865
6932
  url: (_config$logs$config = config.logs.config) == null ? void 0 : _config$logs$config.url,
6866
6933
  token: (_config$logs$config2 = config.logs.config) == null ? void 0 : _config$logs$config2.token
6867
6934
  });
6935
+ agentLogger = createLogger({
6936
+ type: 'UPSTASH',
6937
+ options: {
6938
+ redisClient: redisClient,
6939
+ key: "mastra-logs/agent",
6940
+ level: (_config$logs5 = config.logs) == null ? void 0 : _config$logs5.level
6941
+ }
6942
+ });
6943
+ workflowLogger = createLogger({
6944
+ type: 'UPSTASH',
6945
+ options: {
6946
+ redisClient: redisClient,
6947
+ key: "mastra-logs/workflow",
6948
+ level: (_config$logs6 = config.logs) == null ? void 0 : _config$logs6.level
6949
+ }
6950
+ });
6951
+ } else {
6952
+ var _config$logs7, _config$logs8;
6953
+ agentLogger = createLogger({
6954
+ type: 'CONSOLE',
6955
+ options: {
6956
+ level: (_config$logs7 = config.logs) == null ? void 0 : _config$logs7.level
6957
+ }
6958
+ });
6959
+ workflowLogger = createLogger({
6960
+ type: 'CONSOLE',
6961
+ options: {
6962
+ level: (_config$logs8 = config.logs) == null ? void 0 : _config$logs8.level
6963
+ }
6964
+ });
6868
6965
  }
6869
- framework.attachLogger(logger);
6966
+ framework.attachLogger({
6967
+ key: 'AGENT',
6968
+ logger: agentLogger
6969
+ });
6970
+ framework.attachLogger({
6971
+ key: 'WORKFLOW',
6972
+ logger: workflowLogger
6973
+ });
6870
6974
  // Register integrations
6871
6975
  config.integrations.forEach(function (integration) {
6872
6976
  framework.__registerIntgeration(integration);
6873
6977
  });
6874
- // Register system apis
6875
- framework.__registerApis({
6876
- apis: [].concat(getVectorQueryApis({
6877
- mastra: framework
6878
- }), getAgentSystemApis({
6879
- mastra: framework
6880
- }), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
6881
- return _extends({}, api, {
6882
- integrationName: config.name
6883
- });
6884
- }), [{
6885
- integrationName: config.name,
6886
- type: 'trigger_event',
6887
- label: 'Trigger event',
6888
- // getSchemaOptions({ ctx }) {
6889
- // const options = Promise.resolve({
6890
- // event: {
6891
- // options: Array.from(framework.globalEvents.values()).flatMap(
6892
- // (eventRecord) =>
6893
- // Object.values(eventRecord).map((event) => ({
6894
- // value: event.key || event.label || '',
6895
- // label: event.key || event.label || '',
6896
- // })).filter((event) => event.value !== '')
6897
- // ),
6898
- // },
6899
- // });
6900
- // return options;
6901
- // },
6902
- description: 'Trigger event',
6903
- schema: z.object({
6904
- event: z.string(),
6905
- data: z.record(z.any())
6906
- }),
6907
- executor: function () {
6908
- var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
6909
- var data, ctx, event;
6910
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6911
- while (1) switch (_context2.prev = _context2.next) {
6912
- case 0:
6913
- data = _ref7.data, ctx = _ref7.ctx;
6914
- event = data.event;
6915
- _context2.next = 4;
6916
- return framework.triggerEvent({
6917
- key: event,
6918
- data: data.data,
6919
- user: {
6920
- connectionId: ctx.connectionId
6921
- }
6922
- });
6923
- case 4:
6924
- return _context2.abrupt("return", _context2.sent);
6925
- case 5:
6926
- case "end":
6927
- return _context2.stop();
6928
- }
6929
- }, _callee2);
6930
- }));
6931
- function executor(_x2) {
6932
- return _executor.apply(this, arguments);
6933
- }
6934
- return executor;
6935
- }()
6936
- }])
6937
- });
6938
6978
  // Register System events
6939
6979
  framework.__registerEvents({
6940
6980
  events: config.workflows.systemEvents
@@ -6952,7 +6992,7 @@ var Mastra = /*#__PURE__*/function () {
6952
6992
  },
6953
6993
  VECTOR_SYNC: {
6954
6994
  label: 'Sync vector data',
6955
- description: 'Sync vector data',
6995
+ description: 'Generic vector sync',
6956
6996
  schema: z.object({
6957
6997
  vector_provider: z.string(),
6958
6998
  entities: z.array(z.object({
@@ -6969,11 +7009,14 @@ var Mastra = /*#__PURE__*/function () {
6969
7009
  },
6970
7010
  VECTOR_INDEX_SYNC: {
6971
7011
  label: 'Sync vector index',
6972
- description: 'Sync vector index',
7012
+ description: 'Sync data to vector index',
6973
7013
  schema: z.object({
6974
7014
  data: z.array(z.object({
6975
7015
  provider: z.string(),
6976
- indexes: z.array(z.string())
7016
+ indexes: z.array(z.string()),
7017
+ mastraSyncInterval: z.number({
7018
+ 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"'
7019
+ }).optional()
6977
7020
  }))
6978
7021
  }),
6979
7022
  handler: vectorIndexSync
@@ -6981,55 +7024,73 @@ var Mastra = /*#__PURE__*/function () {
6981
7024
  },
6982
7025
  integrationName: config.name
6983
7026
  });
7027
+ // Register system apis
7028
+ framework.__registerApis({
7029
+ apis: [].concat(getVectorQueryApis({
7030
+ mastra: framework
7031
+ }), getAgentSystemApis({
7032
+ mastra: framework
7033
+ }), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
7034
+ return _extends({}, api, {
7035
+ integrationName: config.name
7036
+ });
7037
+ }), [eventTriggerApi({
7038
+ mastra: framework
7039
+ })], getWorkflowApis({
7040
+ mastra: framework
7041
+ }))
7042
+ });
6984
7043
  // Register agent config
6985
7044
  framework.agentsConfig = config.agents;
6986
7045
  return framework;
6987
7046
  };
6988
7047
  var _proto = Mastra.prototype;
6989
- _proto.attachLogger = function attachLogger(logger) {
6990
- this.logger = logger;
7048
+ _proto.attachLogger = function attachLogger(_ref7) {
7049
+ var key = _ref7.key,
7050
+ logger = _ref7.logger;
7051
+ this.logger.set(key, logger);
6991
7052
  };
6992
7053
  _proto.connectedIntegrations = /*#__PURE__*/function () {
6993
- var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref8) {
7054
+ var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
6994
7055
  var _this2 = this;
6995
7056
  var context, ints, connectionChecks;
6996
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
6997
- while (1) switch (_context4.prev = _context4.next) {
7057
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7058
+ while (1) switch (_context3.prev = _context3.next) {
6998
7059
  case 0:
6999
7060
  context = _ref8.context;
7000
7061
  ints = this.availableIntegrations();
7001
- _context4.next = 4;
7062
+ _context3.next = 4;
7002
7063
  return Promise.all(ints.map(/*#__PURE__*/function () {
7003
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref9) {
7064
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref9) {
7004
7065
  var integration, connection;
7005
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7006
- while (1) switch (_context3.prev = _context3.next) {
7066
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7067
+ while (1) switch (_context2.prev = _context2.next) {
7007
7068
  case 0:
7008
7069
  integration = _ref9.integration;
7009
- _context3.next = 3;
7070
+ _context2.next = 3;
7010
7071
  return _this2.dataLayer.getConnection({
7011
7072
  connectionId: context.connectionId,
7012
7073
  name: integration.name
7013
7074
  });
7014
7075
  case 3:
7015
- connection = _context3.sent;
7016
- return _context3.abrupt("return", {
7076
+ connection = _context2.sent;
7077
+ return _context2.abrupt("return", {
7017
7078
  integration: integration,
7018
7079
  connected: !!connection
7019
7080
  });
7020
7081
  case 5:
7021
7082
  case "end":
7022
- return _context3.stop();
7083
+ return _context2.stop();
7023
7084
  }
7024
- }, _callee3);
7085
+ }, _callee2);
7025
7086
  }));
7026
- return function (_x4) {
7087
+ return function (_x3) {
7027
7088
  return _ref10.apply(this, arguments);
7028
7089
  };
7029
7090
  }()));
7030
7091
  case 4:
7031
- connectionChecks = _context4.sent;
7032
- return _context4.abrupt("return", connectionChecks.filter(function (_ref11) {
7092
+ connectionChecks = _context3.sent;
7093
+ return _context3.abrupt("return", connectionChecks.filter(function (_ref11) {
7033
7094
  var connected = _ref11.connected;
7034
7095
  return connected;
7035
7096
  }).map(function (_ref12) {
@@ -7038,11 +7099,11 @@ var Mastra = /*#__PURE__*/function () {
7038
7099
  }));
7039
7100
  case 6:
7040
7101
  case "end":
7041
- return _context4.stop();
7102
+ return _context3.stop();
7042
7103
  }
7043
- }, _callee4, this);
7104
+ }, _callee3, this);
7044
7105
  }));
7045
- function connectedIntegrations(_x3) {
7106
+ function connectedIntegrations(_x2) {
7046
7107
  return _connectedIntegrations.apply(this, arguments);
7047
7108
  }
7048
7109
  return connectedIntegrations;
@@ -7056,14 +7117,14 @@ var Mastra = /*#__PURE__*/function () {
7056
7117
  definition.corePresets = {
7057
7118
  redirectURI: router.makeRedirectURI()
7058
7119
  };
7059
- this.integrations.set(name, definition);
7060
7120
  definition.registerEvents();
7121
+ definition.registerApis();
7122
+ definition._convertApiClientToSystemApis();
7123
+ this.integrations.set(name, definition);
7061
7124
  this.__registerEvents({
7062
7125
  events: definition.getEvents(),
7063
7126
  integrationName: name
7064
7127
  });
7065
- definition.registerApis();
7066
- definition._convertApiClientToSystemApis();
7067
7128
  this.__registerApis({
7068
7129
  apis: Object.values(definition.getApis()),
7069
7130
  integrationName: name
@@ -7192,20 +7253,20 @@ var Mastra = /*#__PURE__*/function () {
7192
7253
  return _int.getAuthenticator();
7193
7254
  };
7194
7255
  _proto.connectIntegrationByCredential = /*#__PURE__*/function () {
7195
- var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref18) {
7256
+ var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref18) {
7196
7257
  var name, connectionId, credential, authenticator, integration;
7197
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7198
- while (1) switch (_context5.prev = _context5.next) {
7258
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
7259
+ while (1) switch (_context4.prev = _context4.next) {
7199
7260
  case 0:
7200
7261
  name = _ref18.name, connectionId = _ref18.connectionId, credential = _ref18.credential;
7201
7262
  authenticator = this.authenticator(name);
7202
7263
  if (authenticator) {
7203
- _context5.next = 4;
7264
+ _context4.next = 4;
7204
7265
  break;
7205
7266
  }
7206
7267
  throw new Error("Authenticator for " + name + " not found");
7207
7268
  case 4:
7208
- _context5.next = 6;
7269
+ _context4.next = 6;
7209
7270
  return authenticator.dataAccess.createConnection({
7210
7271
  connection: {
7211
7272
  name: name,
@@ -7214,112 +7275,112 @@ var Mastra = /*#__PURE__*/function () {
7214
7275
  credential: credential
7215
7276
  });
7216
7277
  case 6:
7217
- integration = _context5.sent;
7278
+ integration = _context4.sent;
7218
7279
  if (!authenticator.onConnectionCreated) {
7219
- _context5.next = 10;
7280
+ _context4.next = 10;
7220
7281
  break;
7221
7282
  }
7222
- _context5.next = 10;
7283
+ _context4.next = 10;
7223
7284
  return authenticator.onConnectionCreated(integration, credential);
7224
7285
  case 10:
7225
7286
  case "end":
7226
- return _context5.stop();
7287
+ return _context4.stop();
7227
7288
  }
7228
- }, _callee5, this);
7289
+ }, _callee4, this);
7229
7290
  }));
7230
- function connectIntegrationByCredential(_x5) {
7291
+ function connectIntegrationByCredential(_x4) {
7231
7292
  return _connectIntegrationByCredential.apply(this, arguments);
7232
7293
  }
7233
7294
  return connectIntegrationByCredential;
7234
7295
  }();
7235
7296
  _proto.disconnectIntegration = /*#__PURE__*/function () {
7236
- var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref19) {
7297
+ var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref19) {
7237
7298
  var _yield$this$dataLayer;
7238
7299
  var name, connectionId, integration, k_id, authenticator;
7239
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7240
- while (1) switch (_context6.prev = _context6.next) {
7300
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7301
+ while (1) switch (_context5.prev = _context5.next) {
7241
7302
  case 0:
7242
7303
  name = _ref19.name, connectionId = _ref19.connectionId;
7243
7304
  integration = this.getIntegration(name);
7244
- _context6.next = 4;
7305
+ _context5.next = 4;
7245
7306
  return this.dataLayer.getConnection({
7246
7307
  name: name,
7247
7308
  connectionId: connectionId
7248
7309
  });
7249
7310
  case 4:
7250
- _context6.t0 = _yield$this$dataLayer = _context6.sent;
7251
- if (!(_context6.t0 == null)) {
7252
- _context6.next = 9;
7311
+ _context5.t0 = _yield$this$dataLayer = _context5.sent;
7312
+ if (!(_context5.t0 == null)) {
7313
+ _context5.next = 9;
7253
7314
  break;
7254
7315
  }
7255
- _context6.t1 = void 0;
7256
- _context6.next = 10;
7316
+ _context5.t1 = void 0;
7317
+ _context5.next = 10;
7257
7318
  break;
7258
7319
  case 9:
7259
- _context6.t1 = _yield$this$dataLayer.id;
7320
+ _context5.t1 = _yield$this$dataLayer.id;
7260
7321
  case 10:
7261
- k_id = _context6.t1;
7322
+ k_id = _context5.t1;
7262
7323
  if (k_id) {
7263
- _context6.next = 13;
7324
+ _context5.next = 13;
7264
7325
  break;
7265
7326
  }
7266
7327
  throw new Error("No connection found for " + name);
7267
7328
  case 13:
7268
7329
  if (!(integration != null && integration.dataLayer)) {
7269
- _context6.next = 16;
7330
+ _context5.next = 16;
7270
7331
  break;
7271
7332
  }
7272
- _context6.next = 16;
7333
+ _context5.next = 16;
7273
7334
  return integration.onDisconnect({
7274
7335
  connectionId: connectionId
7275
7336
  });
7276
7337
  case 16:
7277
7338
  if (!((integration == null ? void 0 : integration.config.authType) === IntegrationCredentialType.OAUTH)) {
7278
- _context6.next = 20;
7339
+ _context5.next = 20;
7279
7340
  break;
7280
7341
  }
7281
7342
  authenticator = this.authenticator(name);
7282
- _context6.next = 20;
7343
+ _context5.next = 20;
7283
7344
  return authenticator.revokeAuth({
7284
7345
  k_id: k_id
7285
7346
  });
7286
7347
  case 20:
7287
- _context6.next = 22;
7348
+ _context5.next = 22;
7288
7349
  return this.dataLayer.deleteConnection({
7289
7350
  connectionId: connectionId
7290
7351
  });
7291
7352
  case 22:
7292
7353
  case "end":
7293
- return _context6.stop();
7354
+ return _context5.stop();
7294
7355
  }
7295
- }, _callee6, this);
7356
+ }, _callee5, this);
7296
7357
  }));
7297
- function disconnectIntegration(_x6) {
7358
+ function disconnectIntegration(_x5) {
7298
7359
  return _disconnectIntegration.apply(this, arguments);
7299
7360
  }
7300
7361
  return disconnectIntegration;
7301
7362
  }();
7302
7363
  _proto.createSystemConnection = /*#__PURE__*/function () {
7303
- var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
7364
+ var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
7304
7365
  var systemConnectionId, existingSystemConnection;
7305
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7306
- while (1) switch (_context7.prev = _context7.next) {
7366
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7367
+ while (1) switch (_context6.prev = _context6.next) {
7307
7368
  case 0:
7308
7369
  systemConnectionId = 'SYSTEM';
7309
- _context7.next = 3;
7370
+ _context6.next = 3;
7310
7371
  return this.dataLayer.getConnection({
7311
7372
  connectionId: systemConnectionId,
7312
7373
  name: this.config.name
7313
7374
  });
7314
7375
  case 3:
7315
- existingSystemConnection = _context7.sent;
7376
+ existingSystemConnection = _context6.sent;
7316
7377
  if (!existingSystemConnection) {
7317
- _context7.next = 6;
7378
+ _context6.next = 6;
7318
7379
  break;
7319
7380
  }
7320
- return _context7.abrupt("return", existingSystemConnection);
7381
+ return _context6.abrupt("return", existingSystemConnection);
7321
7382
  case 6:
7322
- return _context7.abrupt("return", this.dataLayer.createConnection({
7383
+ return _context6.abrupt("return", this.dataLayer.createConnection({
7323
7384
  connection: {
7324
7385
  connectionId: systemConnectionId,
7325
7386
  name: this.config.name
@@ -7331,9 +7392,9 @@ var Mastra = /*#__PURE__*/function () {
7331
7392
  }));
7332
7393
  case 7:
7333
7394
  case "end":
7334
- return _context7.stop();
7395
+ return _context6.stop();
7335
7396
  }
7336
- }, _callee7, this);
7397
+ }, _callee6, this);
7337
7398
  }));
7338
7399
  function createSystemConnection() {
7339
7400
  return _createSystemConnection.apply(this, arguments);
@@ -7341,71 +7402,71 @@ var Mastra = /*#__PURE__*/function () {
7341
7402
  return createSystemConnection;
7342
7403
  }();
7343
7404
  _proto.callApi = /*#__PURE__*/function () {
7344
- var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
7405
+ var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref20) {
7345
7406
  var _int2$getApis;
7346
7407
  var _ref20$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
7347
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7348
- while (1) switch (_context8.prev = _context8.next) {
7408
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7409
+ while (1) switch (_context7.prev = _context7.next) {
7349
7410
  case 0:
7350
7411
  _ref20$integrationNam = _ref20.integrationName, integrationName = _ref20$integrationNam === void 0 ? this.config.name : _ref20$integrationNam, api = _ref20.api, payload = _ref20.payload;
7351
7412
  if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
7352
- _context8.next = 6;
7413
+ _context7.next = 6;
7353
7414
  break;
7354
7415
  }
7355
7416
  _apiExecutor = (_this$globalApis$get = this.globalApis.get(this.config.name)) == null ? void 0 : _this$globalApis$get[api];
7356
7417
  if (_apiExecutor) {
7357
- _context8.next = 5;
7418
+ _context7.next = 5;
7358
7419
  break;
7359
7420
  }
7360
7421
  throw new Error("No global api exists for " + api);
7361
7422
  case 5:
7362
- return _context8.abrupt("return", _apiExecutor.executor(payload));
7423
+ return _context7.abrupt("return", _apiExecutor.executor(payload));
7363
7424
  case 6:
7364
7425
  _int2 = this.getIntegration(integrationName);
7365
7426
  if (_int2) {
7366
- _context8.next = 9;
7427
+ _context7.next = 9;
7367
7428
  break;
7368
7429
  }
7369
7430
  throw new Error("No Integration exists for " + integrationName);
7370
7431
  case 9:
7371
7432
  apiExecutor = (_int2$getApis = _int2.getApis()) == null ? void 0 : _int2$getApis[api];
7372
7433
  if (apiExecutor) {
7373
- _context8.next = 12;
7434
+ _context7.next = 12;
7374
7435
  break;
7375
7436
  }
7376
7437
  throw new Error("No api exists for " + api + " in " + integrationName);
7377
7438
  case 12:
7378
- return _context8.abrupt("return", apiExecutor.executor(payload));
7439
+ return _context7.abrupt("return", apiExecutor.executor(payload));
7379
7440
  case 13:
7380
7441
  case "end":
7381
- return _context8.stop();
7442
+ return _context7.stop();
7382
7443
  }
7383
- }, _callee8, this);
7444
+ }, _callee7, this);
7384
7445
  }));
7385
- function callApi(_x7) {
7446
+ function callApi(_x6) {
7386
7447
  return _callApi.apply(this, arguments);
7387
7448
  }
7388
7449
  return callApi;
7389
7450
  }();
7390
7451
  _proto.subscribeEvent = /*#__PURE__*/function () {
7391
- var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref21) {
7452
+ var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
7392
7453
  var _this$config$runner$u, _this$config$runner, _ref22, _this$config$runner$s, _this$config$runner2;
7393
7454
  var id, _ref21$interval, interval, _ref21$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
7394
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
7395
- while (1) switch (_context10.prev = _context10.next) {
7455
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7456
+ while (1) switch (_context9.prev = _context9.next) {
7396
7457
  case 0:
7397
7458
  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;
7398
7459
  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;
7399
7460
  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';
7400
7461
  startTime = Date.now();
7401
7462
  _poll = /*#__PURE__*/function () {
7402
- var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
7463
+ var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
7403
7464
  var response, obj, data, error, lastRun, elapsedTime;
7404
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7405
- while (1) switch (_context9.prev = _context9.next) {
7465
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7466
+ while (1) switch (_context8.prev = _context8.next) {
7406
7467
  case 0:
7407
- _context9.prev = 0;
7408
- _context9.next = 3;
7468
+ _context8.prev = 0;
7469
+ _context8.next = 3;
7409
7470
  return fetch(inngestApiUrl + "/v1/events/" + id + "/runs", {
7410
7471
  method: 'GET',
7411
7472
  headers: {
@@ -7414,117 +7475,117 @@ var Mastra = /*#__PURE__*/function () {
7414
7475
  }
7415
7476
  });
7416
7477
  case 3:
7417
- response = _context9.sent;
7478
+ response = _context8.sent;
7418
7479
  console.log("Polling for event " + id + "...", response.ok);
7419
7480
  if (!response.ok) {
7420
- _context9.next = 28;
7481
+ _context8.next = 28;
7421
7482
  break;
7422
7483
  }
7423
- _context9.next = 8;
7484
+ _context8.next = 8;
7424
7485
  return response.json();
7425
7486
  case 8:
7426
- obj = _context9.sent;
7487
+ obj = _context8.sent;
7427
7488
  console.log({
7428
7489
  obj: obj
7429
7490
  });
7430
7491
  data = obj.data, error = obj.error;
7431
7492
  console.log("Got data for event " + id + "...", data, error);
7432
7493
  if (!error) {
7433
- _context9.next = 15;
7494
+ _context8.next = 15;
7434
7495
  break;
7435
7496
  }
7436
7497
  console.error(error);
7437
- return _context9.abrupt("return", null);
7498
+ return _context8.abrupt("return", null);
7438
7499
  case 15:
7439
7500
  if (!((data == null ? void 0 : data.length) === 0)) {
7440
- _context9.next = 19;
7501
+ _context8.next = 19;
7441
7502
  break;
7442
7503
  }
7443
- _context9.next = 18;
7504
+ _context8.next = 18;
7444
7505
  return new Promise(function (resolve) {
7445
7506
  return setTimeout(resolve, interval);
7446
7507
  });
7447
7508
  case 18:
7448
- return _context9.abrupt("return", _poll());
7509
+ return _context8.abrupt("return", _poll());
7449
7510
  case 19:
7450
7511
  lastRun = data == null ? void 0 : data[0];
7451
7512
  console.log(lastRun);
7452
7513
  if (lastRun) {
7453
- _context9.next = 23;
7514
+ _context8.next = 23;
7454
7515
  break;
7455
7516
  }
7456
- return _context9.abrupt("return", null);
7517
+ return _context8.abrupt("return", null);
7457
7518
  case 23:
7458
7519
  if (!(lastRun.status === 'Running')) {
7459
- _context9.next = 27;
7520
+ _context8.next = 27;
7460
7521
  break;
7461
7522
  }
7462
- _context9.next = 26;
7523
+ _context8.next = 26;
7463
7524
  return new Promise(function (resolve) {
7464
7525
  return setTimeout(resolve, interval);
7465
7526
  });
7466
7527
  case 26:
7467
- return _context9.abrupt("return", _poll());
7528
+ return _context8.abrupt("return", _poll());
7468
7529
  case 27:
7469
- return _context9.abrupt("return", {
7530
+ return _context8.abrupt("return", {
7470
7531
  status: lastRun.status,
7471
7532
  startedAt: lastRun.run_started_at,
7472
7533
  endedAt: lastRun.ended_at
7473
7534
  });
7474
7535
  case 28:
7475
- _context9.next = 33;
7536
+ _context8.next = 33;
7476
7537
  break;
7477
7538
  case 30:
7478
- _context9.prev = 30;
7479
- _context9.t0 = _context9["catch"](0);
7480
- console.error("Request failed: " + _context9.t0);
7539
+ _context8.prev = 30;
7540
+ _context8.t0 = _context8["catch"](0);
7541
+ console.error("Request failed: " + _context8.t0);
7481
7542
  case 33:
7482
7543
  // Check if timeout has been reached
7483
7544
  elapsedTime = Date.now() - startTime;
7484
7545
  if (!(elapsedTime >= timeout)) {
7485
- _context9.next = 37;
7546
+ _context8.next = 37;
7486
7547
  break;
7487
7548
  }
7488
7549
  console.log('Polling timeout reached.');
7489
- return _context9.abrupt("return", null);
7550
+ return _context8.abrupt("return", null);
7490
7551
  case 37:
7491
- _context9.next = 39;
7552
+ _context8.next = 39;
7492
7553
  return new Promise(function (resolve) {
7493
7554
  return setTimeout(resolve, interval);
7494
7555
  });
7495
7556
  case 39:
7496
- return _context9.abrupt("return", _poll());
7557
+ return _context8.abrupt("return", _poll());
7497
7558
  case 40:
7498
7559
  case "end":
7499
- return _context9.stop();
7560
+ return _context8.stop();
7500
7561
  }
7501
- }, _callee9, null, [[0, 30]]);
7562
+ }, _callee8, null, [[0, 30]]);
7502
7563
  }));
7503
7564
  return function poll() {
7504
7565
  return _ref23.apply(this, arguments);
7505
7566
  };
7506
7567
  }();
7507
- return _context10.abrupt("return", _poll());
7568
+ return _context9.abrupt("return", _poll());
7508
7569
  case 6:
7509
7570
  case "end":
7510
- return _context10.stop();
7571
+ return _context9.stop();
7511
7572
  }
7512
- }, _callee10, this);
7573
+ }, _callee9, this);
7513
7574
  }));
7514
- function subscribeEvent(_x8) {
7575
+ function subscribeEvent(_x7) {
7515
7576
  return _subscribeEvent.apply(this, arguments);
7516
7577
  }
7517
7578
  return subscribeEvent;
7518
7579
  }();
7519
7580
  _proto.triggerEvent = /*#__PURE__*/function () {
7520
- var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref24) {
7581
+ var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref24) {
7521
7582
  var _this4 = this;
7522
7583
  var key, data, user, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
7523
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
7524
- while (1) switch (_context13.prev = _context13.next) {
7584
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
7585
+ while (1) switch (_context12.prev = _context12.next) {
7525
7586
  case 0:
7526
7587
  key = _ref24.key, data = _ref24.data, user = _ref24.user, integrationName = _ref24.integrationName;
7527
- _context13.prev = 1;
7588
+ _context12.prev = 1;
7528
7589
  returnObj = {
7529
7590
  event: {}
7530
7591
  };
@@ -7536,53 +7597,53 @@ var Mastra = /*#__PURE__*/function () {
7536
7597
  }, {});
7537
7598
  }
7538
7599
  if (integrationEvents) {
7539
- _context13.next = 6;
7600
+ _context12.next = 6;
7540
7601
  break;
7541
7602
  }
7542
7603
  throw new Error("No integration events found");
7543
7604
  case 6:
7544
7605
  integrationEvent = integrationEvents[key];
7545
7606
  if (integrationEvent) {
7546
- _context13.next = 9;
7607
+ _context12.next = 9;
7547
7608
  break;
7548
7609
  }
7549
7610
  throw new Error("No event exists for " + key + " in " + (integrationName || 'system'));
7550
7611
  case 9:
7551
- _context13.next = 11;
7612
+ _context12.next = 11;
7552
7613
  return client$1.send({
7553
7614
  name: key,
7554
7615
  data: data,
7555
7616
  user: user
7556
7617
  });
7557
7618
  case 11:
7558
- event = _context13.sent;
7619
+ event = _context12.sent;
7559
7620
  returnObj['event'] = _extends({}, event, {
7560
7621
  subscribe: function () {
7561
- var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp) {
7622
+ var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp) {
7562
7623
  var _event$ids;
7563
7624
  var _ref25, interval, timeout;
7564
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
7565
- while (1) switch (_context11.prev = _context11.next) {
7625
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
7626
+ while (1) switch (_context10.prev = _context10.next) {
7566
7627
  case 0:
7567
7628
  _ref25 = _temp === void 0 ? {} : _temp, interval = _ref25.interval, timeout = _ref25.timeout;
7568
- return _context11.abrupt("return", _this4.subscribeEvent({
7629
+ return _context10.abrupt("return", _this4.subscribeEvent({
7569
7630
  id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
7570
7631
  interval: interval,
7571
7632
  timeout: timeout
7572
7633
  }));
7573
7634
  case 2:
7574
7635
  case "end":
7575
- return _context11.stop();
7636
+ return _context10.stop();
7576
7637
  }
7577
- }, _callee11);
7638
+ }, _callee10);
7578
7639
  }));
7579
- function subscribe(_x10) {
7640
+ function subscribe(_x9) {
7580
7641
  return _subscribe.apply(this, arguments);
7581
7642
  }
7582
7643
  return subscribe;
7583
7644
  }()
7584
7645
  });
7585
- _context13.next = 15;
7646
+ _context12.next = 15;
7586
7647
  return client$1.send({
7587
7648
  name: 'workflow/run-automations',
7588
7649
  data: {
@@ -7592,45 +7653,45 @@ var Mastra = /*#__PURE__*/function () {
7592
7653
  user: user
7593
7654
  });
7594
7655
  case 15:
7595
- workflowEvent = _context13.sent;
7656
+ workflowEvent = _context12.sent;
7596
7657
  returnObj['workflowEvent'] = _extends({}, workflowEvent, {
7597
7658
  subscribe: function () {
7598
- var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_temp2) {
7659
+ var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp2) {
7599
7660
  var _workflowEvent$ids;
7600
7661
  var _ref26, interval, timeout;
7601
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
7602
- while (1) switch (_context12.prev = _context12.next) {
7662
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
7663
+ while (1) switch (_context11.prev = _context11.next) {
7603
7664
  case 0:
7604
7665
  _ref26 = _temp2 === void 0 ? {} : _temp2, interval = _ref26.interval, timeout = _ref26.timeout;
7605
- return _context12.abrupt("return", _this4.subscribeEvent({
7666
+ return _context11.abrupt("return", _this4.subscribeEvent({
7606
7667
  id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
7607
7668
  interval: interval,
7608
7669
  timeout: timeout
7609
7670
  }));
7610
7671
  case 2:
7611
7672
  case "end":
7612
- return _context12.stop();
7673
+ return _context11.stop();
7613
7674
  }
7614
- }, _callee12);
7675
+ }, _callee11);
7615
7676
  }));
7616
- function subscribe(_x11) {
7677
+ function subscribe(_x10) {
7617
7678
  return _subscribe2.apply(this, arguments);
7618
7679
  }
7619
7680
  return subscribe;
7620
7681
  }()
7621
7682
  });
7622
- return _context13.abrupt("return", returnObj);
7683
+ return _context12.abrupt("return", returnObj);
7623
7684
  case 20:
7624
- _context13.prev = 20;
7625
- _context13.t0 = _context13["catch"](1);
7626
- throw new Error("Error triggering event: " + _context13.t0);
7685
+ _context12.prev = 20;
7686
+ _context12.t0 = _context12["catch"](1);
7687
+ throw new Error("Error triggering event: " + _context12.t0);
7627
7688
  case 23:
7628
7689
  case "end":
7629
- return _context13.stop();
7690
+ return _context12.stop();
7630
7691
  }
7631
- }, _callee13, this, [[1, 20]]);
7692
+ }, _callee12, this, [[1, 20]]);
7632
7693
  }));
7633
- function triggerEvent(_x9) {
7694
+ function triggerEvent(_x8) {
7634
7695
  return _triggerEvent.apply(this, arguments);
7635
7696
  }
7636
7697
  return triggerEvent;
@@ -7639,26 +7700,26 @@ var Mastra = /*#__PURE__*/function () {
7639
7700
  _proto.triggerSystemEvent =
7640
7701
  /*#__PURE__*/
7641
7702
  function () {
7642
- var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref27) {
7703
+ var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref27) {
7643
7704
  var key, data, user, event, systemEvent;
7644
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
7645
- while (1) switch (_context14.prev = _context14.next) {
7705
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
7706
+ while (1) switch (_context13.prev = _context13.next) {
7646
7707
  case 0:
7647
7708
  key = _ref27.key, data = _ref27.data, user = _ref27.user;
7648
- _context14.next = 3;
7709
+ _context13.next = 3;
7649
7710
  return client$1.send({
7650
7711
  name: key,
7651
7712
  data: data,
7652
7713
  user: user
7653
7714
  });
7654
7715
  case 3:
7655
- event = _context14.sent;
7716
+ event = _context13.sent;
7656
7717
  systemEvent = this.getSystemEvents()[key];
7657
7718
  if (!systemEvent) {
7658
- _context14.next = 8;
7719
+ _context13.next = 8;
7659
7720
  break;
7660
7721
  }
7661
- _context14.next = 8;
7722
+ _context13.next = 8;
7662
7723
  return client$1.send({
7663
7724
  name: 'workflow/run-automations',
7664
7725
  data: {
@@ -7668,14 +7729,14 @@ var Mastra = /*#__PURE__*/function () {
7668
7729
  user: user
7669
7730
  });
7670
7731
  case 8:
7671
- return _context14.abrupt("return", event);
7732
+ return _context13.abrupt("return", event);
7672
7733
  case 9:
7673
7734
  case "end":
7674
- return _context14.stop();
7735
+ return _context13.stop();
7675
7736
  }
7676
- }, _callee14, this);
7737
+ }, _callee13, this);
7677
7738
  }));
7678
- function triggerSystemEvent(_x12) {
7739
+ function triggerSystemEvent(_x11) {
7679
7740
  return _triggerSystemEvent.apply(this, arguments);
7680
7741
  }
7681
7742
  return triggerSystemEvent;
@@ -7697,7 +7758,7 @@ var Mastra = /*#__PURE__*/function () {
7697
7758
  };
7698
7759
  var registerRoutes = function registerRoutes() {
7699
7760
  var _registry;
7700
- 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);
7761
+ 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);
7701
7762
  return function (req) {
7702
7763
  var route = req.nextUrl.pathname;
7703
7764
  if (req.nextUrl.pathname in registry) {
@@ -7716,42 +7777,62 @@ var Mastra = /*#__PURE__*/function () {
7716
7777
  };
7717
7778
  };
7718
7779
  _proto.getAgent = /*#__PURE__*/function () {
7719
- var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref29) {
7780
+ var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref29) {
7720
7781
  var connectionId, agentId, agentBlueprint, arrMap, finalApis;
7721
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
7722
- while (1) switch (_context15.prev = _context15.next) {
7782
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
7783
+ while (1) switch (_context14.prev = _context14.next) {
7723
7784
  case 0:
7724
7785
  connectionId = _ref29.connectionId, agentId = _ref29.agentId;
7725
- _context15.next = 3;
7786
+ _context14.next = 3;
7726
7787
  return getAgentBlueprint({
7727
7788
  agentDir: this.config.agents.agentDirPath,
7728
7789
  agentId: agentId
7729
7790
  });
7730
7791
  case 3:
7731
- agentBlueprint = _context15.sent;
7792
+ agentBlueprint = _context14.sent;
7732
7793
  arrMap = Array.from(this.getApis());
7733
7794
  finalApis = arrMap.reduce(function (acc, _ref30) {
7734
7795
  var v = _ref30[1];
7735
7796
  return _extends({}, acc, v);
7736
7797
  }, {});
7737
7798
  console.log('got finalApis===');
7738
- return _context15.abrupt("return", getAgent({
7799
+ return _context14.abrupt("return", getAgent({
7739
7800
  connectionId: connectionId,
7740
7801
  agent: agentBlueprint,
7741
7802
  apis: finalApis,
7742
- logger: this.logger
7803
+ logger: this.logger.get('AGENT')
7743
7804
  }));
7744
7805
  case 8:
7745
7806
  case "end":
7746
- return _context15.stop();
7807
+ return _context14.stop();
7747
7808
  }
7748
- }, _callee15, this);
7809
+ }, _callee14, this);
7749
7810
  }));
7750
- function getAgent$1(_x13) {
7811
+ function getAgent$1(_x12) {
7751
7812
  return _getAgent2.apply(this, arguments);
7752
7813
  }
7753
7814
  return getAgent$1;
7754
7815
  }();
7816
+ _proto.__backgroundTasks = /*#__PURE__*/function () {
7817
+ var _backgroundTasks = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
7818
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
7819
+ while (1) switch (_context15.prev = _context15.next) {
7820
+ case 0:
7821
+ _context15.next = 2;
7822
+ return syncAndWriteVectorProviderIndexesToLocal({
7823
+ mastra: this
7824
+ });
7825
+ case 2:
7826
+ case "end":
7827
+ return _context15.stop();
7828
+ }
7829
+ }, _callee15, this);
7830
+ }));
7831
+ function __backgroundTasks() {
7832
+ return _backgroundTasks.apply(this, arguments);
7833
+ }
7834
+ return __backgroundTasks;
7835
+ }();
7755
7836
  return _createClass(Mastra, [{
7756
7837
  key: "routes",
7757
7838
  get: function get() {
@@ -7760,7 +7841,8 @@ var Mastra = /*#__PURE__*/function () {
7760
7841
  connect: '/connect',
7761
7842
  callback: '/connect/callback',
7762
7843
  inngest: '/inngest',
7763
- webhook: '/webhook'
7844
+ webhook: '/webhook',
7845
+ cron: '/cron'
7764
7846
  };
7765
7847
  return Object.entries(registry).reduce(function (acc, _ref31) {
7766
7848
  var _extends5;
@@ -7773,13 +7855,37 @@ var Mastra = /*#__PURE__*/function () {
7773
7855
  key: "openAIAssistant",
7774
7856
  get: function get() {
7775
7857
  return {
7776
- createAssistantAgent: createAssistantAgentHandler(this.logger),
7777
- getAssistantAgent: getAssistantAgentHandler(this.logger),
7778
- updateAssistantAgent: updateAssistantAgentHandler(this.logger)
7858
+ createAssistantAgent: createAssistantAgentHandler(this.logger.get('AGENT')),
7859
+ getAssistantAgent: getAssistantAgentHandler(this.logger.get('AGENT')),
7860
+ updateAssistantAgent: updateAssistantAgentHandler(this.logger.get('AGENT'))
7779
7861
  };
7780
7862
  }
7781
7863
  }]);
7782
7864
  }();
7783
7865
 
7784
- export { DataLayer, FieldTypePrimitiveMap, FilterOperatorToSQL, FilterOperators, Integration, IntegrationAuth, IntegrationCredentialType, IntegrationError, IntegrationErrors, IntegrationFieldTypeEnum, Mastra, RunStatus, SORT_MODE_TO_ABBR, WorkflowStatusEnum, allowedKey, apiKeyConnectionOptions, buildQueryString, callbackParams, connectParams, constructObjFromStringPath, extractSchemaOptions, fieldsWithCommaSeparatedValues, filterQuerySchema, flattenObject, generateSyncs, getEntityKey, getJSONField, getPath, getPineconeIndices, getResponseDataKey, getUpstashLogs, isLiteralObject, isObjectEmpty, mergeWithDefinedOnly, nextHeaders, oauthState, parseQueryParams, recordHasData, registerRoutes, sortQuerySchema, splitAndStripQuotes, transformFilterValueArray, transformFilterValueBoolean, webhookQueryParams };
7866
+ function getUpstashLogs(_x) {
7867
+ return _getUpstashLogs.apply(this, arguments);
7868
+ }
7869
+ function _getUpstashLogs() {
7870
+ _getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
7871
+ var id, url, token, redis;
7872
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7873
+ while (1) switch (_context.prev = _context.next) {
7874
+ case 0:
7875
+ id = _ref.id, url = _ref.url, token = _ref.token;
7876
+ redis = new Redis({
7877
+ url: url,
7878
+ token: token
7879
+ });
7880
+ return _context.abrupt("return", redis.lrange(id, 0, -1));
7881
+ case 3:
7882
+ case "end":
7883
+ return _context.stop();
7884
+ }
7885
+ }, _callee);
7886
+ }));
7887
+ return _getUpstashLogs.apply(this, arguments);
7888
+ }
7889
+
7890
+ export { DataLayer, FieldTypePrimitiveMap, FilterOperatorToSQL, FilterOperators, Integration, IntegrationAuth, IntegrationCredentialType, IntegrationError, IntegrationErrors, IntegrationFieldTypeEnum, LogLevel, LogProvider, Mastra, RunStatus, SORT_MODE_TO_ABBR, WorkflowStatusEnum, allowedKey, apiKeyConnectionOptions, buildQueryString, callbackParams, connectParams, constructObjFromStringPath, createLogger, cronQueryParams, delay$1 as delay, extractSchemaOptions, fieldsWithCommaSeparatedValues, filterQuerySchema, flattenObject, generateSyncs, getEntityKey, getJSONField, getPath, getPineconeIndices, getResponseDataKey, getUpstashLogs, isLiteralObject, isObjectEmpty, mergeWithDefinedOnly, nextHeaders, oauthState, parseQueryParams, recordHasData, registerRoutes, sortQuerySchema, splitAndStripQuotes, splitMarkdownIntoChunks, transformFilterValueArray, transformFilterValueBoolean, webhookQueryParams };
7785
7891
  //# sourceMappingURL=core.esm.js.map