@mastra/core 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/file-logger.d.ts +0 -13
- package/dist/agents/file-logger.d.ts.map +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/openai/assistant.d.ts +16 -3
- package/dist/agents/openai/assistant.d.ts.map +1 -1
- package/dist/agents/utils.d.ts +7 -0
- package/dist/agents/utils.d.ts.map +1 -1
- package/dist/agents/vector-sync.d.ts +3 -2
- package/dist/agents/vector-sync.d.ts.map +1 -1
- package/dist/core.cjs.development.js +1673 -1395
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +1671 -1398
- package/dist/core.esm.js.map +1 -1
- package/dist/framework.d.ts +8 -3
- package/dist/framework.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/integration.d.ts.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/logger-utils/logger.d.ts +98 -0
- package/dist/lib/logger-utils/logger.d.ts.map +1 -0
- package/dist/next/cron.d.ts +13 -0
- package/dist/next/cron.d.ts.map +1 -0
- package/dist/next/index.d.ts.map +1 -1
- package/dist/schemas.d.ts +13 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/text.d.ts +2 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/vector-access/index.d.ts +4 -0
- package/dist/vector-access/index.d.ts.map +1 -1
- package/dist/workflows/apis.d.ts +9 -0
- package/dist/workflows/apis.d.ts.map +1 -0
- package/dist/workflows/handler.d.ts +8 -0
- package/dist/workflows/handler.d.ts.map +1 -1
- package/dist/workflows/runner.d.ts +3 -1
- package/dist/workflows/runner.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/prisma/client.ts +0 -31
- package/dist/prisma/gen.js +0 -139
- package/dist/prisma/migrations/20240828034109_initial_migration/migration.sql +0 -111
- package/dist/prisma/migrations/20240829210901_initial_migration/migration.sql +0 -1
- package/dist/prisma/migrations/20240905143158_initial_migration/migration.sql +0 -1
- package/dist/prisma/migrations/20240911212856_initial_migration/migration.sql +0 -1
- package/dist/prisma/migrations/20240915044235_initial_migration/migration.sql +0 -1
- package/dist/prisma/migrations/20241008024219_initial_migration/migration.sql +0 -69
- package/dist/prisma/migrations/migration_lock.toml +0 -3
- package/dist/prisma/schema.prisma +0 -129
package/dist/core.esm.js
CHANGED
|
@@ -9,14 +9,14 @@ import { z } from 'zod';
|
|
|
9
9
|
import { headers } from 'next/headers';
|
|
10
10
|
import qs from 'qs';
|
|
11
11
|
import { serve } from 'inngest/next';
|
|
12
|
-
import path from 'path';
|
|
13
12
|
import * as fs from 'fs';
|
|
14
|
-
import {
|
|
13
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync } from 'fs';
|
|
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(
|
|
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 =
|
|
1949
|
+
directoryPath = _ref2.directoryPath;
|
|
1899
1950
|
return _context6.abrupt("return", new Promise(function (resolve, reject) {
|
|
1900
1951
|
fs.readdir(directoryPath, /*#__PURE__*/function () {
|
|
1901
|
-
var
|
|
1902
|
-
var jsonFiles, result,
|
|
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
|
-
|
|
1969
|
+
_iterator2 = _createForOfIteratorHelperLoose(jsonFiles);
|
|
1919
1970
|
case 7:
|
|
1920
|
-
if ((
|
|
1971
|
+
if ((_step2 = _iterator2()).done) {
|
|
1921
1972
|
_context5.next = 16;
|
|
1922
1973
|
break;
|
|
1923
1974
|
}
|
|
1924
|
-
file =
|
|
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
|
|
2000
|
+
return _ref8.apply(this, arguments);
|
|
1950
2001
|
};
|
|
1951
2002
|
}());
|
|
1952
2003
|
}));
|
|
@@ -1958,40 +2009,46 @@ function _getBlueprints() {
|
|
|
1958
2009
|
}));
|
|
1959
2010
|
return _getBlueprints.apply(this, arguments);
|
|
1960
2011
|
}
|
|
1961
|
-
var createWorkflowHandler = function createWorkflowHandler(
|
|
1962
|
-
var blueprintDirPath =
|
|
1963
|
-
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
|
|
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 =
|
|
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
|
|
1981
|
-
var
|
|
2031
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
2032
|
+
var MASTRA_APP_DIR;
|
|
1982
2033
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1983
2034
|
while (1) switch (_context.prev = _context.next) {
|
|
1984
2035
|
case 0:
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2036
|
+
MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
|
|
2037
|
+
if (blueprintDirPath) {
|
|
2038
|
+
_context.next = 3;
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
2041
|
+
throw new Error('Missing blueprintDirPath in config');
|
|
2042
|
+
case 3:
|
|
2043
|
+
return _context.abrupt("return", path.join(MASTRA_APP_DIR, blueprintDirPath));
|
|
2044
|
+
case 4:
|
|
1988
2045
|
case "end":
|
|
1989
2046
|
return _context.stop();
|
|
1990
2047
|
}
|
|
1991
2048
|
}, _callee);
|
|
1992
2049
|
}));
|
|
1993
2050
|
return function getBlueprintsDirPath() {
|
|
1994
|
-
return
|
|
2051
|
+
return _ref6.apply(this, arguments);
|
|
1995
2052
|
};
|
|
1996
2053
|
}();
|
|
1997
2054
|
_context3.next = 7;
|
|
@@ -2046,7 +2103,7 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
|
|
|
2046
2103
|
}, _callee3, null, [[1, 15]]);
|
|
2047
2104
|
}));
|
|
2048
2105
|
return function (_x3) {
|
|
2049
|
-
return
|
|
2106
|
+
return _ref5.apply(this, arguments);
|
|
2050
2107
|
};
|
|
2051
2108
|
}());
|
|
2052
2109
|
};
|
|
@@ -2143,13 +2200,52 @@ var makeWebhook = function makeWebhook(framework) {
|
|
|
2143
2200
|
};
|
|
2144
2201
|
};
|
|
2145
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
|
+
|
|
2146
2241
|
var registerRoutes = function registerRoutes(_ref) {
|
|
2147
2242
|
var framework = _ref.framework;
|
|
2148
2243
|
var registry = {
|
|
2149
2244
|
connect: makeConnect(framework),
|
|
2150
2245
|
'connect/callback': makeCallback(framework),
|
|
2151
2246
|
inngest: makeInngest(framework),
|
|
2152
|
-
webhook: makeWebhook(framework)
|
|
2247
|
+
webhook: makeWebhook(framework),
|
|
2248
|
+
cron: makeCron(framework)
|
|
2153
2249
|
};
|
|
2154
2250
|
return function (req, _ref2) {
|
|
2155
2251
|
var _Object$keys$at;
|
|
@@ -2335,6 +2431,203 @@ function mergeWithDefinedOnly(base, overrides) {
|
|
|
2335
2431
|
return result;
|
|
2336
2432
|
}
|
|
2337
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
|
+
|
|
2338
2631
|
var _excluded$3 = ["client"],
|
|
2339
2632
|
_excluded2$1 = ["name", "logoUrl"];
|
|
2340
2633
|
/**
|
|
@@ -2421,7 +2714,7 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2421
2714
|
return acc;
|
|
2422
2715
|
}
|
|
2423
2716
|
}, {});
|
|
2424
|
-
_this.apis = apis;
|
|
2717
|
+
_this.apis = _extends({}, _this.apis, apis);
|
|
2425
2718
|
case 5:
|
|
2426
2719
|
case "end":
|
|
2427
2720
|
return _context2.stop();
|
|
@@ -3040,6 +3333,31 @@ var IntegrationAuth = /*#__PURE__*/function () {
|
|
|
3040
3333
|
return IntegrationAuth;
|
|
3041
3334
|
}();
|
|
3042
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
|
+
|
|
3043
3361
|
/**
|
|
3044
3362
|
* Extract schema options for the provided schema - Builds a map of fieldname to field options
|
|
3045
3363
|
* @param schema - schema
|
|
@@ -3116,6 +3434,11 @@ function setFieldOptions(_ref3) {
|
|
|
3116
3434
|
};
|
|
3117
3435
|
}
|
|
3118
3436
|
}
|
|
3437
|
+
var delay$1 = function delay(ms) {
|
|
3438
|
+
return new Promise(function (resolve) {
|
|
3439
|
+
return setTimeout(resolve, ms);
|
|
3440
|
+
});
|
|
3441
|
+
};
|
|
3119
3442
|
|
|
3120
3443
|
function zodToPropertType(zodType) {
|
|
3121
3444
|
if (zodType instanceof z.ZodString) {
|
|
@@ -3860,11 +4183,11 @@ function runActionsRecursively(_x) {
|
|
|
3860
4183
|
}
|
|
3861
4184
|
function _runActionsRecursively() {
|
|
3862
4185
|
_runActionsRecursively = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref7) {
|
|
3863
|
-
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;
|
|
3864
4187
|
return _regeneratorRuntime().wrap(function _callee$(_context3) {
|
|
3865
4188
|
while (1) switch (_context3.prev = _context3.next) {
|
|
3866
4189
|
case 0:
|
|
3867
|
-
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;
|
|
3868
4191
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
3869
4192
|
var _action$subActions;
|
|
3870
4193
|
var action, concreteAction, hasValidBranch, _loop2, _ret2, _iterator3, _step3, defaultCondition, defaultAction, actionExecutor, _ref9, mastraConnectionId, actionPayload, resolvedPayload, resolvedSchema, data, executorResult, _ctx, subActions;
|
|
@@ -3873,9 +4196,15 @@ function _runActionsRecursively() {
|
|
|
3873
4196
|
case 0:
|
|
3874
4197
|
action = _step2.value;
|
|
3875
4198
|
concreteAction = frameworkApis[action.type];
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
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
|
+
});
|
|
3879
4208
|
// check action conditions
|
|
3880
4209
|
if (!(action.type === 'CONDITIONS')) {
|
|
3881
4210
|
_context2.next = 32;
|
|
@@ -3952,7 +4281,8 @@ function _runActionsRecursively() {
|
|
|
3952
4281
|
blueprintId: blueprintId,
|
|
3953
4282
|
runId: runId,
|
|
3954
4283
|
ctx: ctx,
|
|
3955
|
-
blueprintActionKVMap: blueprintActionKVMap
|
|
4284
|
+
blueprintActionKVMap: blueprintActionKVMap,
|
|
4285
|
+
logger: logger
|
|
3956
4286
|
});
|
|
3957
4287
|
case 22:
|
|
3958
4288
|
executorResult = _context.sent;
|
|
@@ -3999,7 +4329,12 @@ function _runActionsRecursively() {
|
|
|
3999
4329
|
_context2.next = 32;
|
|
4000
4330
|
break;
|
|
4001
4331
|
}
|
|
4002
|
-
|
|
4332
|
+
logger.debug({
|
|
4333
|
+
destinationPath: "" + blueprintId,
|
|
4334
|
+
message: JSON.stringify({
|
|
4335
|
+
message: "No valid branch found for action: " + action.type + ":" + action.id
|
|
4336
|
+
})
|
|
4337
|
+
});
|
|
4003
4338
|
// run default branch if available
|
|
4004
4339
|
defaultCondition = action.condition.find(function (c) {
|
|
4005
4340
|
return c.isDefault;
|
|
@@ -4011,7 +4346,12 @@ function _runActionsRecursively() {
|
|
|
4011
4346
|
_context2.next = 30;
|
|
4012
4347
|
break;
|
|
4013
4348
|
}
|
|
4014
|
-
|
|
4349
|
+
logger.debug({
|
|
4350
|
+
destinationPath: "" + blueprintId,
|
|
4351
|
+
message: JSON.stringify({
|
|
4352
|
+
message: "Running default action: " + defaultAction.type + ":" + defaultAction.id
|
|
4353
|
+
})
|
|
4354
|
+
});
|
|
4015
4355
|
_context2.next = 26;
|
|
4016
4356
|
return runActionsRecursively({
|
|
4017
4357
|
blueprintActions: [defaultAction],
|
|
@@ -4021,7 +4361,8 @@ function _runActionsRecursively() {
|
|
|
4021
4361
|
runId: runId,
|
|
4022
4362
|
ctx: ctx,
|
|
4023
4363
|
blueprintId: blueprintId,
|
|
4024
|
-
blueprintActionKVMap: blueprintActionKVMap
|
|
4364
|
+
blueprintActionKVMap: blueprintActionKVMap,
|
|
4365
|
+
logger: logger
|
|
4025
4366
|
});
|
|
4026
4367
|
case 26:
|
|
4027
4368
|
_context2.t1 = _context2.sent;
|
|
@@ -4029,7 +4370,12 @@ function _runActionsRecursively() {
|
|
|
4029
4370
|
v: _context2.t1
|
|
4030
4371
|
});
|
|
4031
4372
|
case 30:
|
|
4032
|
-
|
|
4373
|
+
logger.debug({
|
|
4374
|
+
destinationPath: "" + blueprintId,
|
|
4375
|
+
message: JSON.stringify({
|
|
4376
|
+
message: "No default action found for action: " + action.type + ":" + action.id
|
|
4377
|
+
})
|
|
4378
|
+
});
|
|
4033
4379
|
return _context2.abrupt("return", {
|
|
4034
4380
|
v: false
|
|
4035
4381
|
});
|
|
@@ -4039,7 +4385,12 @@ function _runActionsRecursively() {
|
|
|
4039
4385
|
_context2.next = 36;
|
|
4040
4386
|
break;
|
|
4041
4387
|
}
|
|
4042
|
-
|
|
4388
|
+
logger.debug({
|
|
4389
|
+
destinationPath: "" + blueprintId,
|
|
4390
|
+
message: JSON.stringify({
|
|
4391
|
+
message: "No executor found for " + action.type + ":" + action.id
|
|
4392
|
+
})
|
|
4393
|
+
});
|
|
4043
4394
|
return _context2.abrupt("return", 0);
|
|
4044
4395
|
case 36:
|
|
4045
4396
|
_ref9 = action.payload || {}, mastraConnectionId = _ref9.mastraConnectionId, actionPayload = _objectWithoutPropertiesLoose(_ref9, _excluded);
|
|
@@ -4076,14 +4427,24 @@ function _runActionsRecursively() {
|
|
|
4076
4427
|
});
|
|
4077
4428
|
case 49:
|
|
4078
4429
|
executorResult = _context2.sent;
|
|
4079
|
-
|
|
4430
|
+
logger.info({
|
|
4431
|
+
destinationPath: "" + blueprintId,
|
|
4432
|
+
message: JSON.stringify({
|
|
4433
|
+
message: "Action " + action.type + ":" + action.id + " completed",
|
|
4434
|
+
result: executorResult
|
|
4435
|
+
})
|
|
4436
|
+
});
|
|
4080
4437
|
_context2.next = 57;
|
|
4081
4438
|
break;
|
|
4082
4439
|
case 53:
|
|
4083
4440
|
_context2.prev = 53;
|
|
4084
4441
|
_context2.t2 = _context2["catch"](46);
|
|
4085
|
-
|
|
4086
|
-
|
|
4442
|
+
logger.error({
|
|
4443
|
+
destinationPath: "" + blueprintId,
|
|
4444
|
+
message: JSON.stringify({
|
|
4445
|
+
message: "Action " + action.type + ":" + action.id + " failed",
|
|
4446
|
+
error: _context2.t2
|
|
4447
|
+
})
|
|
4087
4448
|
});
|
|
4088
4449
|
// TODO: Update workflows runs for failed actions
|
|
4089
4450
|
return _context2.abrupt("return", {
|
|
@@ -4109,7 +4470,8 @@ function _runActionsRecursively() {
|
|
|
4109
4470
|
runId: runId,
|
|
4110
4471
|
ctx: ctx,
|
|
4111
4472
|
blueprintId: blueprintId,
|
|
4112
|
-
blueprintActionKVMap: blueprintActionKVMap
|
|
4473
|
+
blueprintActionKVMap: blueprintActionKVMap,
|
|
4474
|
+
logger: logger
|
|
4113
4475
|
});
|
|
4114
4476
|
case 63:
|
|
4115
4477
|
_context2.t3 = _context2.sent;
|
|
@@ -4161,12 +4523,22 @@ function blueprintRunner(_x2) {
|
|
|
4161
4523
|
function _blueprintRunner() {
|
|
4162
4524
|
_blueprintRunner = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
|
|
4163
4525
|
var _fullCtx, _blueprint$trigger;
|
|
4164
|
-
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;
|
|
4165
4527
|
return _regeneratorRuntime().wrap(function _callee2$(_context4) {
|
|
4166
4528
|
while (1) switch (_context4.prev = _context4.next) {
|
|
4167
4529
|
case 0:
|
|
4168
|
-
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;
|
|
4169
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
|
+
});
|
|
4170
4542
|
fullCtx = (_fullCtx = {}, _fullCtx[blueprint.trigger.id] = dataCtx, _fullCtx);
|
|
4171
4543
|
triggerCondition = blueprint.trigger.condition;
|
|
4172
4544
|
concreteTrigger = frameworkEvents[blueprint.trigger.type || ''];
|
|
@@ -4199,10 +4571,16 @@ function _blueprintRunner() {
|
|
|
4199
4571
|
_context4.next = 16;
|
|
4200
4572
|
break;
|
|
4201
4573
|
}
|
|
4574
|
+
logger.info({
|
|
4575
|
+
destinationPath: "" + blueprint.id,
|
|
4576
|
+
message: JSON.stringify({
|
|
4577
|
+
message: 'Workflow run skipped'
|
|
4578
|
+
})
|
|
4579
|
+
});
|
|
4202
4580
|
return _context4.abrupt("return");
|
|
4203
4581
|
case 16:
|
|
4204
4582
|
blueprintActionKVMap = constructWorkflowContextBluePrint(blueprint);
|
|
4205
|
-
_context4.next =
|
|
4583
|
+
_context4.next = 19;
|
|
4206
4584
|
return runActionsRecursively({
|
|
4207
4585
|
blueprintActions: blueprint.actions,
|
|
4208
4586
|
frameworkApis: frameworkApis,
|
|
@@ -4211,21 +4589,27 @@ function _blueprintRunner() {
|
|
|
4211
4589
|
dataContext: fullCtx,
|
|
4212
4590
|
blueprintActionKVMap: blueprintActionKVMap,
|
|
4213
4591
|
blueprintId: blueprint.id,
|
|
4214
|
-
runId: ''
|
|
4592
|
+
runId: '',
|
|
4593
|
+
logger: logger
|
|
4215
4594
|
});
|
|
4216
|
-
case
|
|
4595
|
+
case 19:
|
|
4217
4596
|
ranSuccessfully = _context4.sent;
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
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:
|
|
4229
4613
|
case "end":
|
|
4230
4614
|
return _context4.stop();
|
|
4231
4615
|
}
|
|
@@ -4236,8 +4620,8 @@ function _blueprintRunner() {
|
|
|
4236
4620
|
|
|
4237
4621
|
function getProjectDir(_ref) {
|
|
4238
4622
|
var dir = _ref.dir;
|
|
4239
|
-
var
|
|
4240
|
-
return path.join(
|
|
4623
|
+
var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
|
|
4624
|
+
return path.join(MASTRA_APP_DIR, dir);
|
|
4241
4625
|
}
|
|
4242
4626
|
function listAgentsJson(_ref2) {
|
|
4243
4627
|
var agentDir = _ref2.agentDir;
|
|
@@ -4280,36 +4664,219 @@ function getPineconeConfig(_ref4) {
|
|
|
4280
4664
|
var agentBlueprintPath = path.join(agentDirPath, "pinecone.json");
|
|
4281
4665
|
return getAgentFile(agentBlueprintPath);
|
|
4282
4666
|
}
|
|
4667
|
+
var retryFn = /*#__PURE__*/function () {
|
|
4668
|
+
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(operation, _temp) {
|
|
4669
|
+
var _ref6, _ref6$maxAttempts, maxAttempts, _ref6$initialDelay, initialDelay, _ref6$maxDelay, maxDelay, _ref6$factor, factor, _ref6$jitter, jitter, delay, attempt, jitterFactor;
|
|
4670
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4671
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4672
|
+
case 0:
|
|
4673
|
+
_ref6 = _temp === void 0 ? {} : _temp, _ref6$maxAttempts = _ref6.maxAttempts, maxAttempts = _ref6$maxAttempts === void 0 ? 3 : _ref6$maxAttempts, _ref6$initialDelay = _ref6.initialDelay, initialDelay = _ref6$initialDelay === void 0 ? 1000 : _ref6$initialDelay, _ref6$maxDelay = _ref6.maxDelay, maxDelay = _ref6$maxDelay === void 0 ? 10000 : _ref6$maxDelay, _ref6$factor = _ref6.factor, factor = _ref6$factor === void 0 ? 2 : _ref6$factor, _ref6$jitter = _ref6.jitter, jitter = _ref6$jitter === void 0 ? true : _ref6$jitter;
|
|
4674
|
+
delay = initialDelay;
|
|
4675
|
+
attempt = 1;
|
|
4676
|
+
case 3:
|
|
4677
|
+
if (!(attempt <= maxAttempts)) {
|
|
4678
|
+
_context.next = 22;
|
|
4679
|
+
break;
|
|
4680
|
+
}
|
|
4681
|
+
_context.prev = 4;
|
|
4682
|
+
_context.next = 7;
|
|
4683
|
+
return operation();
|
|
4684
|
+
case 7:
|
|
4685
|
+
return _context.abrupt("return", _context.sent);
|
|
4686
|
+
case 10:
|
|
4687
|
+
_context.prev = 10;
|
|
4688
|
+
_context.t0 = _context["catch"](4);
|
|
4689
|
+
if (!(attempt === maxAttempts)) {
|
|
4690
|
+
_context.next = 14;
|
|
4691
|
+
break;
|
|
4692
|
+
}
|
|
4693
|
+
throw _context.t0;
|
|
4694
|
+
case 14:
|
|
4695
|
+
console.warn("Attempt " + attempt + " failed. Retrying in " + delay + "ms...");
|
|
4696
|
+
_context.next = 17;
|
|
4697
|
+
return new Promise(function (resolve) {
|
|
4698
|
+
return setTimeout(resolve, delay);
|
|
4699
|
+
});
|
|
4700
|
+
case 17:
|
|
4701
|
+
// Calculate next delay with exponential backoff
|
|
4702
|
+
delay = Math.min(delay * factor, maxDelay);
|
|
4703
|
+
// Add jitter if enabled
|
|
4704
|
+
if (jitter) {
|
|
4705
|
+
jitterFactor = 0.5 + Math.random();
|
|
4706
|
+
delay = Math.floor(delay * jitterFactor);
|
|
4707
|
+
}
|
|
4708
|
+
case 19:
|
|
4709
|
+
attempt++;
|
|
4710
|
+
_context.next = 3;
|
|
4711
|
+
break;
|
|
4712
|
+
case 22:
|
|
4713
|
+
case "end":
|
|
4714
|
+
return _context.stop();
|
|
4715
|
+
}
|
|
4716
|
+
}, _callee, null, [[4, 10]]);
|
|
4717
|
+
}));
|
|
4718
|
+
return function retryFn(_x, _x2) {
|
|
4719
|
+
return _ref5.apply(this, arguments);
|
|
4720
|
+
};
|
|
4721
|
+
}();
|
|
4283
4722
|
|
|
4284
4723
|
var VectorLayer = /*#__PURE__*/function () {
|
|
4285
4724
|
function VectorLayer() {
|
|
4286
4725
|
this.supportedProviders = ['PINECONE'];
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4290
|
-
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4291
|
-
var inn;
|
|
4726
|
+
this.fetchPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4727
|
+
var response, _ref2, indexes;
|
|
4292
4728
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4293
4729
|
while (1) switch (_context.prev = _context.next) {
|
|
4294
4730
|
case 0:
|
|
4295
4731
|
_context.prev = 0;
|
|
4296
4732
|
_context.next = 3;
|
|
4733
|
+
return fetch('https://api.pinecone.io/indexes', {
|
|
4734
|
+
method: 'GET',
|
|
4735
|
+
headers: {
|
|
4736
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
4737
|
+
'X-Pinecone-API-Version': 'unstable'
|
|
4738
|
+
},
|
|
4739
|
+
cache: 'no-store'
|
|
4740
|
+
});
|
|
4741
|
+
case 3:
|
|
4742
|
+
response = _context.sent;
|
|
4743
|
+
_context.next = 6;
|
|
4744
|
+
return response.json();
|
|
4745
|
+
case 6:
|
|
4746
|
+
_context.t0 = _context.sent;
|
|
4747
|
+
if (_context.t0) {
|
|
4748
|
+
_context.next = 9;
|
|
4749
|
+
break;
|
|
4750
|
+
}
|
|
4751
|
+
_context.t0 = {};
|
|
4752
|
+
case 9:
|
|
4753
|
+
_ref2 = _context.t0;
|
|
4754
|
+
indexes = _ref2.indexes;
|
|
4755
|
+
return _context.abrupt("return", indexes);
|
|
4756
|
+
case 14:
|
|
4757
|
+
_context.prev = 14;
|
|
4758
|
+
_context.t1 = _context["catch"](0);
|
|
4759
|
+
console.log('Error fetching indexes using JS fetch====', _context.t1);
|
|
4760
|
+
case 17:
|
|
4761
|
+
case "end":
|
|
4762
|
+
return _context.stop();
|
|
4763
|
+
}
|
|
4764
|
+
}, _callee, null, [[0, 14]]);
|
|
4765
|
+
}));
|
|
4766
|
+
this.fetchPineconedIndexByName = /*#__PURE__*/function () {
|
|
4767
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name) {
|
|
4768
|
+
var response, data;
|
|
4769
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4770
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
4771
|
+
case 0:
|
|
4772
|
+
_context2.prev = 0;
|
|
4773
|
+
_context2.next = 3;
|
|
4774
|
+
return fetch("https://api.pinecone.io/indexes/" + name, {
|
|
4775
|
+
method: 'GET',
|
|
4776
|
+
headers: {
|
|
4777
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
4778
|
+
'X-Pinecone-API-Version': 'unstable'
|
|
4779
|
+
},
|
|
4780
|
+
cache: 'no-store'
|
|
4781
|
+
});
|
|
4782
|
+
case 3:
|
|
4783
|
+
response = _context2.sent;
|
|
4784
|
+
_context2.next = 6;
|
|
4785
|
+
return response.json();
|
|
4786
|
+
case 6:
|
|
4787
|
+
_context2.t0 = _context2.sent;
|
|
4788
|
+
if (_context2.t0) {
|
|
4789
|
+
_context2.next = 9;
|
|
4790
|
+
break;
|
|
4791
|
+
}
|
|
4792
|
+
_context2.t0 = {};
|
|
4793
|
+
case 9:
|
|
4794
|
+
data = _context2.t0;
|
|
4795
|
+
return _context2.abrupt("return", data);
|
|
4796
|
+
case 13:
|
|
4797
|
+
_context2.prev = 13;
|
|
4798
|
+
_context2.t1 = _context2["catch"](0);
|
|
4799
|
+
console.log('Error fetching indexes using JS fetch====', _context2.t1);
|
|
4800
|
+
case 16:
|
|
4801
|
+
case "end":
|
|
4802
|
+
return _context2.stop();
|
|
4803
|
+
}
|
|
4804
|
+
}, _callee2, null, [[0, 13]]);
|
|
4805
|
+
}));
|
|
4806
|
+
return function (_x) {
|
|
4807
|
+
return _ref3.apply(this, arguments);
|
|
4808
|
+
};
|
|
4809
|
+
}();
|
|
4810
|
+
this.fetchPineconeIndexStats = /*#__PURE__*/function () {
|
|
4811
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(host) {
|
|
4812
|
+
var response, data;
|
|
4813
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4814
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4815
|
+
case 0:
|
|
4816
|
+
_context3.prev = 0;
|
|
4817
|
+
_context3.next = 3;
|
|
4818
|
+
return fetch("https://" + host + "/describe_index_stats", {
|
|
4819
|
+
method: 'GET',
|
|
4820
|
+
headers: {
|
|
4821
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
4822
|
+
'X-Pinecone-API-Version': '2024-07'
|
|
4823
|
+
},
|
|
4824
|
+
cache: 'no-store'
|
|
4825
|
+
});
|
|
4826
|
+
case 3:
|
|
4827
|
+
response = _context3.sent;
|
|
4828
|
+
_context3.next = 6;
|
|
4829
|
+
return response.json();
|
|
4830
|
+
case 6:
|
|
4831
|
+
_context3.t0 = _context3.sent;
|
|
4832
|
+
if (_context3.t0) {
|
|
4833
|
+
_context3.next = 9;
|
|
4834
|
+
break;
|
|
4835
|
+
}
|
|
4836
|
+
_context3.t0 = {};
|
|
4837
|
+
case 9:
|
|
4838
|
+
data = _context3.t0;
|
|
4839
|
+
return _context3.abrupt("return", data);
|
|
4840
|
+
case 13:
|
|
4841
|
+
_context3.prev = 13;
|
|
4842
|
+
_context3.t1 = _context3["catch"](0);
|
|
4843
|
+
console.log('Error fetching indexes using JS fetch====', _context3.t1);
|
|
4844
|
+
case 16:
|
|
4845
|
+
case "end":
|
|
4846
|
+
return _context3.stop();
|
|
4847
|
+
}
|
|
4848
|
+
}, _callee3, null, [[0, 13]]);
|
|
4849
|
+
}));
|
|
4850
|
+
return function (_x2) {
|
|
4851
|
+
return _ref4.apply(this, arguments);
|
|
4852
|
+
};
|
|
4853
|
+
}();
|
|
4854
|
+
}
|
|
4855
|
+
var _proto = VectorLayer.prototype;
|
|
4856
|
+
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4857
|
+
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
4858
|
+
var inn;
|
|
4859
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4860
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4861
|
+
case 0:
|
|
4862
|
+
_context4.prev = 0;
|
|
4863
|
+
_context4.next = 3;
|
|
4297
4864
|
return this.Pinecone.listIndexes();
|
|
4298
4865
|
case 3:
|
|
4299
|
-
inn =
|
|
4866
|
+
inn = _context4.sent;
|
|
4300
4867
|
console.log('inn====', {
|
|
4301
4868
|
inn: inn
|
|
4302
4869
|
});
|
|
4303
|
-
return
|
|
4870
|
+
return _context4.abrupt("return", inn);
|
|
4304
4871
|
case 8:
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
console.log('error getting indexesss====',
|
|
4872
|
+
_context4.prev = 8;
|
|
4873
|
+
_context4.t0 = _context4["catch"](0);
|
|
4874
|
+
console.log('error getting indexesss====', _context4.t0);
|
|
4308
4875
|
case 11:
|
|
4309
4876
|
case "end":
|
|
4310
|
-
return
|
|
4877
|
+
return _context4.stop();
|
|
4311
4878
|
}
|
|
4312
|
-
},
|
|
4879
|
+
}, _callee4, this, [[0, 8]]);
|
|
4313
4880
|
}));
|
|
4314
4881
|
function getPineconeIndexes() {
|
|
4315
4882
|
return _getPineconeIndexes.apply(this, arguments);
|
|
@@ -4317,13 +4884,13 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4317
4884
|
return getPineconeIndexes;
|
|
4318
4885
|
}();
|
|
4319
4886
|
_proto.createPineconeIndex = /*#__PURE__*/function () {
|
|
4320
|
-
var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4887
|
+
var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
|
|
4321
4888
|
var name;
|
|
4322
|
-
return _regeneratorRuntime().wrap(function
|
|
4323
|
-
while (1) switch (
|
|
4889
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4890
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4324
4891
|
case 0:
|
|
4325
|
-
name =
|
|
4326
|
-
return
|
|
4892
|
+
name = _ref5.name;
|
|
4893
|
+
return _context5.abrupt("return", this.Pinecone.createIndex({
|
|
4327
4894
|
suppressConflicts: true,
|
|
4328
4895
|
name: name,
|
|
4329
4896
|
dimension: 1536,
|
|
@@ -4337,129 +4904,129 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4337
4904
|
}));
|
|
4338
4905
|
case 2:
|
|
4339
4906
|
case "end":
|
|
4340
|
-
return
|
|
4907
|
+
return _context5.stop();
|
|
4341
4908
|
}
|
|
4342
|
-
},
|
|
4909
|
+
}, _callee5, this);
|
|
4343
4910
|
}));
|
|
4344
|
-
function createPineconeIndex(
|
|
4911
|
+
function createPineconeIndex(_x3) {
|
|
4345
4912
|
return _createPineconeIndex.apply(this, arguments);
|
|
4346
4913
|
}
|
|
4347
4914
|
return createPineconeIndex;
|
|
4348
4915
|
}();
|
|
4349
4916
|
_proto.getPineconeIndex = /*#__PURE__*/function () {
|
|
4350
|
-
var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4917
|
+
var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6) {
|
|
4351
4918
|
var name;
|
|
4352
|
-
return _regeneratorRuntime().wrap(function
|
|
4353
|
-
while (1) switch (
|
|
4919
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4920
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4354
4921
|
case 0:
|
|
4355
|
-
name =
|
|
4356
|
-
return
|
|
4922
|
+
name = _ref6.name;
|
|
4923
|
+
return _context6.abrupt("return", this.Pinecone.index(name));
|
|
4357
4924
|
case 2:
|
|
4358
4925
|
case "end":
|
|
4359
|
-
return
|
|
4926
|
+
return _context6.stop();
|
|
4360
4927
|
}
|
|
4361
|
-
},
|
|
4928
|
+
}, _callee6, this);
|
|
4362
4929
|
}));
|
|
4363
|
-
function getPineconeIndex(
|
|
4930
|
+
function getPineconeIndex(_x4) {
|
|
4364
4931
|
return _getPineconeIndex.apply(this, arguments);
|
|
4365
4932
|
}
|
|
4366
4933
|
return getPineconeIndex;
|
|
4367
4934
|
}();
|
|
4368
4935
|
_proto.generateVectorEmbedding = /*#__PURE__*/function () {
|
|
4369
|
-
var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4936
|
+
var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(data) {
|
|
4370
4937
|
var _yield$embed, embedding;
|
|
4371
|
-
return _regeneratorRuntime().wrap(function
|
|
4372
|
-
while (1) switch (
|
|
4938
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4939
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4373
4940
|
case 0:
|
|
4374
|
-
|
|
4941
|
+
_context7.next = 2;
|
|
4375
4942
|
return embed({
|
|
4376
4943
|
model: openai.embedding('text-embedding-3-small'),
|
|
4377
4944
|
value: JSON.stringify(data)
|
|
4378
4945
|
});
|
|
4379
4946
|
case 2:
|
|
4380
|
-
_yield$embed =
|
|
4947
|
+
_yield$embed = _context7.sent;
|
|
4381
4948
|
embedding = _yield$embed.embedding;
|
|
4382
|
-
return
|
|
4949
|
+
return _context7.abrupt("return", embedding);
|
|
4383
4950
|
case 5:
|
|
4384
4951
|
case "end":
|
|
4385
|
-
return
|
|
4952
|
+
return _context7.stop();
|
|
4386
4953
|
}
|
|
4387
|
-
},
|
|
4954
|
+
}, _callee7);
|
|
4388
4955
|
}));
|
|
4389
|
-
function generateVectorEmbedding(
|
|
4956
|
+
function generateVectorEmbedding(_x5) {
|
|
4390
4957
|
return _generateVectorEmbedding.apply(this, arguments);
|
|
4391
4958
|
}
|
|
4392
4959
|
return generateVectorEmbedding;
|
|
4393
4960
|
}();
|
|
4394
4961
|
_proto.getPineconeIndexWithMetadata = /*#__PURE__*/function () {
|
|
4395
|
-
var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4962
|
+
var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
|
|
4396
4963
|
var name, newIndex, indexQuery, namespaces, data, _iterator, _step, _namespaceData$record, namespace, namespaceData, metadata;
|
|
4397
|
-
return _regeneratorRuntime().wrap(function
|
|
4398
|
-
while (1) switch (
|
|
4964
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
4965
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4399
4966
|
case 0:
|
|
4400
|
-
name =
|
|
4401
|
-
|
|
4967
|
+
name = _ref7.name;
|
|
4968
|
+
_context8.prev = 1;
|
|
4402
4969
|
if (name) {
|
|
4403
|
-
|
|
4970
|
+
_context8.next = 5;
|
|
4404
4971
|
break;
|
|
4405
4972
|
}
|
|
4406
4973
|
console.log('Index name not passed');
|
|
4407
|
-
return
|
|
4974
|
+
return _context8.abrupt("return", []);
|
|
4408
4975
|
case 5:
|
|
4409
|
-
|
|
4976
|
+
_context8.next = 7;
|
|
4410
4977
|
return this.getPineconeIndex({
|
|
4411
4978
|
name: name
|
|
4412
4979
|
});
|
|
4413
4980
|
case 7:
|
|
4414
|
-
newIndex =
|
|
4415
|
-
|
|
4981
|
+
newIndex = _context8.sent;
|
|
4982
|
+
_context8.next = 10;
|
|
4416
4983
|
return newIndex == null ? void 0 : newIndex.describeIndexStats();
|
|
4417
4984
|
case 10:
|
|
4418
|
-
indexQuery =
|
|
4985
|
+
indexQuery = _context8.sent;
|
|
4419
4986
|
if (!indexQuery) {
|
|
4420
|
-
|
|
4987
|
+
_context8.next = 27;
|
|
4421
4988
|
break;
|
|
4422
4989
|
}
|
|
4423
4990
|
namespaces = Object.keys((indexQuery == null ? void 0 : indexQuery.namespaces) || {});
|
|
4424
4991
|
data = [];
|
|
4425
4992
|
if (!namespaces.length) {
|
|
4426
|
-
|
|
4993
|
+
_context8.next = 26;
|
|
4427
4994
|
break;
|
|
4428
4995
|
}
|
|
4429
4996
|
_iterator = _createForOfIteratorHelperLoose(namespaces);
|
|
4430
4997
|
case 16:
|
|
4431
4998
|
if ((_step = _iterator()).done) {
|
|
4432
|
-
|
|
4999
|
+
_context8.next = 26;
|
|
4433
5000
|
break;
|
|
4434
5001
|
}
|
|
4435
5002
|
namespace = _step.value;
|
|
4436
|
-
|
|
5003
|
+
_context8.next = 20;
|
|
4437
5004
|
return newIndex == null ? void 0 : newIndex.namespace(namespace).fetch([name]);
|
|
4438
5005
|
case 20:
|
|
4439
|
-
namespaceData =
|
|
5006
|
+
namespaceData = _context8.sent;
|
|
4440
5007
|
metadata = namespaceData == null || (_namespaceData$record = namespaceData.records) == null || (_namespaceData$record = _namespaceData$record[name]) == null ? void 0 : _namespaceData$record.metadata;
|
|
4441
5008
|
console.log("metadata for " + namespace + "===", JSON.stringify(metadata, null, 2));
|
|
4442
5009
|
if (metadata) {
|
|
4443
5010
|
data.push(metadata);
|
|
4444
5011
|
}
|
|
4445
5012
|
case 24:
|
|
4446
|
-
|
|
5013
|
+
_context8.next = 16;
|
|
4447
5014
|
break;
|
|
4448
5015
|
case 26:
|
|
4449
|
-
return
|
|
5016
|
+
return _context8.abrupt("return", data);
|
|
4450
5017
|
case 27:
|
|
4451
|
-
return
|
|
5018
|
+
return _context8.abrupt("return", []);
|
|
4452
5019
|
case 30:
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
console.log("Error getting " + name + " index",
|
|
5020
|
+
_context8.prev = 30;
|
|
5021
|
+
_context8.t0 = _context8["catch"](1);
|
|
5022
|
+
console.log("Error getting " + name + " index", _context8.t0);
|
|
4456
5023
|
case 33:
|
|
4457
5024
|
case "end":
|
|
4458
|
-
return
|
|
5025
|
+
return _context8.stop();
|
|
4459
5026
|
}
|
|
4460
|
-
},
|
|
5027
|
+
}, _callee8, this, [[1, 30]]);
|
|
4461
5028
|
}));
|
|
4462
|
-
function getPineconeIndexWithMetadata(
|
|
5029
|
+
function getPineconeIndexWithMetadata(_x6) {
|
|
4463
5030
|
return _getPineconeIndexWithMetadata.apply(this, arguments);
|
|
4464
5031
|
}
|
|
4465
5032
|
return getPineconeIndexWithMetadata;
|
|
@@ -4478,1075 +5045,608 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4478
5045
|
}();
|
|
4479
5046
|
|
|
4480
5047
|
function getVectorProvider(provider) {
|
|
4481
|
-
if (provider === '
|
|
5048
|
+
if (provider.toUpperCase() === 'PINECONE') {
|
|
4482
5049
|
var _VectorLayer = new VectorLayer(),
|
|
4483
5050
|
Pinecone = _VectorLayer.Pinecone;
|
|
4484
5051
|
return Pinecone;
|
|
4485
5052
|
}
|
|
4486
5053
|
}
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
return _executeIndexSync.apply(this, arguments);
|
|
4494
|
-
}
|
|
4495
|
-
//Generic vector sync from event data
|
|
4496
|
-
function _executeIndexSync() {
|
|
4497
|
-
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref) {
|
|
4498
|
-
var _event$user, _event$data;
|
|
4499
|
-
var event, mastra, connectionId, providedIndexes, systemName, _iterator2, _step2, _step2$value, provider, indexes, vp, _iterator3, _step3, index, indexMetadata, _loop2, _ret, _iterator4, _step4;
|
|
4500
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
|
|
4501
|
-
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) {
|
|
4502
5060
|
case 0:
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
case 5:
|
|
4509
|
-
if ((_step2 = _iterator2()).done) {
|
|
4510
|
-
_context8.next = 36;
|
|
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;
|
|
4511
5066
|
break;
|
|
4512
5067
|
}
|
|
4513
|
-
|
|
5068
|
+
_step$value = _step.value, provider = _step$value.provider, indexes = _step$value.indexes;
|
|
4514
5069
|
vp = getVectorProvider(provider);
|
|
4515
5070
|
if (vp) {
|
|
4516
|
-
|
|
5071
|
+
_context5.next = 8;
|
|
4517
5072
|
break;
|
|
4518
5073
|
}
|
|
4519
5074
|
console.error('UNSUPPORTED VECTOR PROVIDER', provider);
|
|
4520
|
-
return
|
|
4521
|
-
case
|
|
5075
|
+
return _context5.abrupt("return");
|
|
5076
|
+
case 8:
|
|
4522
5077
|
if (process.env.OPENAI_API_KEY) {
|
|
4523
|
-
|
|
5078
|
+
_context5.next = 11;
|
|
4524
5079
|
break;
|
|
4525
5080
|
}
|
|
4526
5081
|
console.error('NO OPENAI_API_KEY');
|
|
4527
|
-
return
|
|
4528
|
-
case
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
break;
|
|
4534
|
-
}
|
|
4535
|
-
index = _step3.value;
|
|
4536
|
-
_context8.next = 19;
|
|
4537
|
-
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
4538
|
-
name: index
|
|
4539
|
-
});
|
|
4540
|
-
case 19:
|
|
4541
|
-
indexMetadata = _context8.sent;
|
|
4542
|
-
if (indexMetadata != null && indexMetadata.length) {
|
|
4543
|
-
_context8.next = 23;
|
|
4544
|
-
break;
|
|
4545
|
-
}
|
|
4546
|
-
console.error('No index metadata found for', index);
|
|
4547
|
-
return _context8.abrupt("return");
|
|
4548
|
-
case 23:
|
|
4549
|
-
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4550
|
-
var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
|
|
4551
|
-
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;
|
|
4552
|
-
return _regeneratorRuntime().wrap(function _loop2$(_context7) {
|
|
4553
|
-
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) {
|
|
4554
5088
|
case 0:
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
5089
|
+
index = _step2.value;
|
|
5090
|
+
getPineconeIndexWithMetadata = /*#__PURE__*/function () {
|
|
5091
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
5092
|
+
var res;
|
|
5093
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5094
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5095
|
+
case 0:
|
|
5096
|
+
_context.prev = 0;
|
|
5097
|
+
_context.next = 3;
|
|
5098
|
+
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
5099
|
+
name: index
|
|
5100
|
+
});
|
|
5101
|
+
case 3:
|
|
5102
|
+
res = _context.sent;
|
|
5103
|
+
if (res != null && res.length) {
|
|
5104
|
+
_context.next = 6;
|
|
5105
|
+
break;
|
|
5106
|
+
}
|
|
5107
|
+
throw new Error('No index metadata found');
|
|
5108
|
+
case 6:
|
|
5109
|
+
return _context.abrupt("return", res);
|
|
5110
|
+
case 9:
|
|
5111
|
+
_context.prev = 9;
|
|
5112
|
+
_context.t0 = _context["catch"](0);
|
|
5113
|
+
throw new Error(_context.t0);
|
|
5114
|
+
case 12:
|
|
5115
|
+
case "end":
|
|
5116
|
+
return _context.stop();
|
|
5117
|
+
}
|
|
5118
|
+
}, _callee, null, [[0, 9]]);
|
|
5119
|
+
}));
|
|
5120
|
+
return function getPineconeIndexWithMetadata() {
|
|
5121
|
+
return _ref3.apply(this, arguments);
|
|
5122
|
+
};
|
|
5123
|
+
}();
|
|
5124
|
+
_context4.next = 4;
|
|
5125
|
+
return retryFn(getPineconeIndexWithMetadata);
|
|
4562
5126
|
case 4:
|
|
4563
|
-
|
|
4564
|
-
if (
|
|
4565
|
-
|
|
4566
|
-
break;
|
|
4567
|
-
}
|
|
4568
|
-
_context7.t2 = void 0;
|
|
4569
|
-
_context7.next = 10;
|
|
4570
|
-
break;
|
|
4571
|
-
case 9:
|
|
4572
|
-
_context7.t2 = _yield$mastra$dataLay.id;
|
|
4573
|
-
case 10:
|
|
4574
|
-
_context7.t0 = _context7.t2;
|
|
4575
|
-
if (_context7.t0) {
|
|
4576
|
-
_context7.next = 13;
|
|
4577
|
-
break;
|
|
4578
|
-
}
|
|
4579
|
-
_context7.t0 = '';
|
|
4580
|
-
case 13:
|
|
4581
|
-
k_id = _context7.t0;
|
|
4582
|
-
if (!(!k_id && integration === systemName)) {
|
|
4583
|
-
_context7.next = 19;
|
|
4584
|
-
break;
|
|
4585
|
-
}
|
|
4586
|
-
_context7.next = 17;
|
|
4587
|
-
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4588
|
-
connection: {
|
|
4589
|
-
connectionId: connectionId,
|
|
4590
|
-
name: integration
|
|
4591
|
-
},
|
|
4592
|
-
credential: {
|
|
4593
|
-
type: 'API_KEY',
|
|
4594
|
-
value: connectionId,
|
|
4595
|
-
scope: []
|
|
4596
|
-
}
|
|
4597
|
-
});
|
|
4598
|
-
case 17:
|
|
4599
|
-
connection = _context7.sent;
|
|
4600
|
-
k_id = connection.id;
|
|
4601
|
-
case 19:
|
|
4602
|
-
if (k_id) {
|
|
4603
|
-
_context7.next = 22;
|
|
5127
|
+
indexMetadata = _context4.sent;
|
|
5128
|
+
if (indexMetadata != null && indexMetadata.length) {
|
|
5129
|
+
_context4.next = 8;
|
|
4604
5130
|
break;
|
|
4605
5131
|
}
|
|
4606
|
-
console.error('
|
|
4607
|
-
return
|
|
5132
|
+
console.error('No index metadata found for', index);
|
|
5133
|
+
return _context4.abrupt("return", {
|
|
4608
5134
|
v: void 0
|
|
4609
5135
|
});
|
|
4610
|
-
case
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
5136
|
+
case 8:
|
|
5137
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
5138
|
+
var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
|
|
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) {
|
|
5142
|
+
case 0:
|
|
5143
|
+
entity = _step3.value;
|
|
5144
|
+
fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent, syncParams = entity.syncParams;
|
|
5145
|
+
_context3.next = 4;
|
|
5146
|
+
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
5147
|
+
connectionId: connectionId,
|
|
5148
|
+
name: integration
|
|
5149
|
+
});
|
|
5150
|
+
case 4:
|
|
5151
|
+
_context3.t1 = _yield$mastra$dataLay = _context3.sent;
|
|
5152
|
+
if (!(_context3.t1 == null)) {
|
|
5153
|
+
_context3.next = 9;
|
|
5154
|
+
break;
|
|
5155
|
+
}
|
|
5156
|
+
_context3.t2 = void 0;
|
|
5157
|
+
_context3.next = 10;
|
|
5158
|
+
break;
|
|
5159
|
+
case 9:
|
|
5160
|
+
_context3.t2 = _yield$mastra$dataLay.id;
|
|
5161
|
+
case 10:
|
|
5162
|
+
_context3.t0 = _context3.t2;
|
|
5163
|
+
if (_context3.t0) {
|
|
5164
|
+
_context3.next = 13;
|
|
5165
|
+
break;
|
|
5166
|
+
}
|
|
5167
|
+
_context3.t0 = '';
|
|
5168
|
+
case 13:
|
|
5169
|
+
k_id = _context3.t0;
|
|
5170
|
+
if (!(!k_id && integration === mastra.config.name)) {
|
|
5171
|
+
_context3.next = 19;
|
|
5172
|
+
break;
|
|
5173
|
+
}
|
|
5174
|
+
_context3.next = 17;
|
|
5175
|
+
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
5176
|
+
connection: {
|
|
5177
|
+
connectionId: connectionId,
|
|
5178
|
+
name: integration
|
|
5179
|
+
},
|
|
5180
|
+
credential: {
|
|
5181
|
+
type: 'API_KEY',
|
|
5182
|
+
value: connectionId,
|
|
5183
|
+
scope: []
|
|
5184
|
+
}
|
|
5185
|
+
});
|
|
5186
|
+
case 17:
|
|
5187
|
+
connection = _context3.sent;
|
|
5188
|
+
k_id = connection.id;
|
|
5189
|
+
case 19:
|
|
5190
|
+
if (k_id) {
|
|
5191
|
+
_context3.next = 22;
|
|
5192
|
+
break;
|
|
5193
|
+
}
|
|
5194
|
+
console.error('Error bootstrapping shit');
|
|
5195
|
+
return _context3.abrupt("return", {
|
|
5196
|
+
v: {
|
|
5197
|
+
v: void 0
|
|
5198
|
+
}
|
|
5199
|
+
});
|
|
5200
|
+
case 22:
|
|
5201
|
+
_context3.next = 24;
|
|
5202
|
+
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
5203
|
+
k_id: k_id,
|
|
5204
|
+
type: name.toUpperCase()
|
|
5205
|
+
});
|
|
5206
|
+
case 24:
|
|
5207
|
+
entityRecords = _context3.sent;
|
|
5208
|
+
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
5209
|
+
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
5210
|
+
_context3.next = 46;
|
|
5211
|
+
break;
|
|
5212
|
+
}
|
|
5213
|
+
console.error('NO RECORDS ATTEMPTING SYNC');
|
|
5214
|
+
data = JSON.parse(Buffer.from(syncParams, 'base64').toString());
|
|
5215
|
+
console.log('sync data====', {
|
|
5216
|
+
data: data
|
|
5217
|
+
});
|
|
5218
|
+
_context3.next = 32;
|
|
5219
|
+
return mastra.triggerEvent({
|
|
5220
|
+
key: syncEvent,
|
|
5221
|
+
data: data,
|
|
5222
|
+
user: {
|
|
5223
|
+
connectionId: connectionId
|
|
5224
|
+
}
|
|
5225
|
+
});
|
|
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;
|
|
5234
|
+
console.log('Subscribe result', res);
|
|
5235
|
+
_context3.next = 41;
|
|
5236
|
+
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
5237
|
+
k_id: k_id,
|
|
5238
|
+
type: entity.name.toUpperCase()
|
|
5239
|
+
});
|
|
5240
|
+
case 41:
|
|
5241
|
+
entityRecords = _context3.sent;
|
|
5242
|
+
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
5243
|
+
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
5244
|
+
_context3.next = 46;
|
|
5245
|
+
break;
|
|
5246
|
+
}
|
|
5247
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
5248
|
+
return _context3.abrupt("return", {
|
|
5249
|
+
v: {
|
|
5250
|
+
v: void 0
|
|
5251
|
+
}
|
|
5252
|
+
});
|
|
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);
|
|
5259
|
+
return _extends({
|
|
5260
|
+
id: String(externalId)
|
|
5261
|
+
}, stringifiedData);
|
|
5262
|
+
});
|
|
5263
|
+
console.log(recordsMapped, 'RECORDS');
|
|
5264
|
+
entityTypeIndex = vp.index(index);
|
|
5265
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
5266
|
+
_context3.prev = 50;
|
|
5267
|
+
_context3.next = 53;
|
|
5268
|
+
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
5269
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(record) {
|
|
5270
|
+
var _yield$embed, embedding;
|
|
5271
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5272
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5273
|
+
case 0:
|
|
5274
|
+
_context2.next = 2;
|
|
5275
|
+
return embed({
|
|
5276
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
5277
|
+
value: JSON.stringify(record)
|
|
5278
|
+
});
|
|
5279
|
+
case 2:
|
|
5280
|
+
_yield$embed = _context2.sent;
|
|
5281
|
+
embedding = _yield$embed.embedding;
|
|
5282
|
+
return _context2.abrupt("return", {
|
|
5283
|
+
id: record.id,
|
|
5284
|
+
values: embedding,
|
|
5285
|
+
metadata: record
|
|
5286
|
+
});
|
|
5287
|
+
case 5:
|
|
5288
|
+
case "end":
|
|
5289
|
+
return _context2.stop();
|
|
5290
|
+
}
|
|
5291
|
+
}, _callee2);
|
|
5292
|
+
}));
|
|
5293
|
+
return function (_x2) {
|
|
5294
|
+
return _ref5.apply(this, arguments);
|
|
5295
|
+
};
|
|
5296
|
+
}())) != null ? _recordsMapped$map : []);
|
|
5297
|
+
case 53:
|
|
5298
|
+
vectors = _context3.sent;
|
|
5299
|
+
console.log('UPSERTING', vectors);
|
|
5300
|
+
if (!(vectors.length > 0)) {
|
|
5301
|
+
_context3.next = 58;
|
|
5302
|
+
break;
|
|
5303
|
+
}
|
|
5304
|
+
_context3.next = 58;
|
|
5305
|
+
return entityTypeIndex.namespace(name).upsert(vectors);
|
|
5306
|
+
case 58:
|
|
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", {
|
|
5315
|
+
v: {
|
|
5316
|
+
v: void 0
|
|
5317
|
+
}
|
|
5318
|
+
});
|
|
5319
|
+
case 64:
|
|
5320
|
+
case "end":
|
|
5321
|
+
return _context3.stop();
|
|
5322
|
+
}
|
|
5323
|
+
}, _loop2, null, [[50, 60]]);
|
|
4645
5324
|
});
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
_context7.next = 44;
|
|
5325
|
+
_iterator3 = _createForOfIteratorHelperLoose(indexMetadata);
|
|
5326
|
+
case 10:
|
|
5327
|
+
if ((_step3 = _iterator3()).done) {
|
|
5328
|
+
_context4.next = 17;
|
|
4651
5329
|
break;
|
|
4652
5330
|
}
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
recordsMapped = records.map(function (_ref12) {
|
|
4659
|
-
var data = _ref12.data,
|
|
4660
|
-
externalId = _ref12.externalId;
|
|
4661
|
-
return _extends({
|
|
4662
|
-
id: externalId
|
|
4663
|
-
}, pick(data, fields));
|
|
4664
|
-
});
|
|
4665
|
-
console.log(recordsMapped, 'RECORDS');
|
|
4666
|
-
entityTypeIndex = vp.index(index);
|
|
4667
|
-
console.log(entityTypeIndex, 'INDEX');
|
|
4668
|
-
_context7.prev = 48;
|
|
4669
|
-
_context7.next = 51;
|
|
4670
|
-
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4671
|
-
var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(record) {
|
|
4672
|
-
var _yield$embed, embedding;
|
|
4673
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4674
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
4675
|
-
case 0:
|
|
4676
|
-
_context6.next = 2;
|
|
4677
|
-
return embed({
|
|
4678
|
-
model: openai.embedding('text-embedding-3-small'),
|
|
4679
|
-
value: JSON.stringify(record)
|
|
4680
|
-
});
|
|
4681
|
-
case 2:
|
|
4682
|
-
_yield$embed = _context6.sent;
|
|
4683
|
-
embedding = _yield$embed.embedding;
|
|
4684
|
-
return _context6.abrupt("return", {
|
|
4685
|
-
id: record.id,
|
|
4686
|
-
values: embedding,
|
|
4687
|
-
metadata: record
|
|
4688
|
-
});
|
|
4689
|
-
case 5:
|
|
4690
|
-
case "end":
|
|
4691
|
-
return _context6.stop();
|
|
4692
|
-
}
|
|
4693
|
-
}, _callee6);
|
|
4694
|
-
}));
|
|
4695
|
-
return function (_x8) {
|
|
4696
|
-
return _ref13.apply(this, arguments);
|
|
4697
|
-
};
|
|
4698
|
-
}())) != null ? _recordsMapped$map : []);
|
|
4699
|
-
case 51:
|
|
4700
|
-
vectors = _context7.sent;
|
|
4701
|
-
console.log('UPSERTING', vectors);
|
|
4702
|
-
if (!(vectors.length > 0)) {
|
|
4703
|
-
_context7.next = 56;
|
|
5331
|
+
return _context4.delegateYield(_loop2(), "t0", 12);
|
|
5332
|
+
case 12:
|
|
5333
|
+
_ret2 = _context4.t0;
|
|
5334
|
+
if (!_ret2) {
|
|
5335
|
+
_context4.next = 15;
|
|
4704
5336
|
break;
|
|
4705
5337
|
}
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
_context7.next = 61;
|
|
5338
|
+
return _context4.abrupt("return", _ret2.v);
|
|
5339
|
+
case 15:
|
|
5340
|
+
_context4.next = 10;
|
|
4710
5341
|
break;
|
|
4711
|
-
case
|
|
4712
|
-
_context7.prev = 58;
|
|
4713
|
-
_context7.t3 = _context7["catch"](48);
|
|
4714
|
-
console.error(_context7.t3);
|
|
4715
|
-
case 61:
|
|
4716
|
-
return _context7.abrupt("return", {
|
|
4717
|
-
v: void 0
|
|
4718
|
-
});
|
|
4719
|
-
case 62:
|
|
5342
|
+
case 17:
|
|
4720
5343
|
case "end":
|
|
4721
|
-
return
|
|
5344
|
+
return _context4.stop();
|
|
4722
5345
|
}
|
|
4723
|
-
},
|
|
5346
|
+
}, _loop);
|
|
4724
5347
|
});
|
|
4725
|
-
|
|
4726
|
-
case
|
|
4727
|
-
if ((
|
|
4728
|
-
|
|
5348
|
+
_iterator2 = _createForOfIteratorHelperLoose(indexes);
|
|
5349
|
+
case 13:
|
|
5350
|
+
if ((_step2 = _iterator2()).done) {
|
|
5351
|
+
_context5.next = 20;
|
|
4729
5352
|
break;
|
|
4730
5353
|
}
|
|
4731
|
-
return
|
|
4732
|
-
case
|
|
4733
|
-
_ret =
|
|
5354
|
+
return _context5.delegateYield(_loop(), "t0", 15);
|
|
5355
|
+
case 15:
|
|
5356
|
+
_ret = _context5.t0;
|
|
4734
5357
|
if (!_ret) {
|
|
4735
|
-
|
|
5358
|
+
_context5.next = 18;
|
|
4736
5359
|
break;
|
|
4737
5360
|
}
|
|
4738
|
-
return
|
|
4739
|
-
case
|
|
4740
|
-
|
|
4741
|
-
break;
|
|
4742
|
-
case 32:
|
|
4743
|
-
_context8.next = 15;
|
|
5361
|
+
return _context5.abrupt("return", _ret.v);
|
|
5362
|
+
case 18:
|
|
5363
|
+
_context5.next = 13;
|
|
4744
5364
|
break;
|
|
4745
|
-
case
|
|
4746
|
-
|
|
5365
|
+
case 20:
|
|
5366
|
+
_context5.next = 2;
|
|
4747
5367
|
break;
|
|
4748
|
-
case
|
|
5368
|
+
case 22:
|
|
5369
|
+
case "end":
|
|
5370
|
+
return _context5.stop();
|
|
5371
|
+
}
|
|
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:
|
|
4749
5402
|
case "end":
|
|
4750
|
-
return
|
|
5403
|
+
return _context9.stop();
|
|
4751
5404
|
}
|
|
4752
5405
|
}, _callee7);
|
|
4753
5406
|
}));
|
|
4754
5407
|
return _executeIndexSync.apply(this, arguments);
|
|
4755
5408
|
}
|
|
4756
|
-
function executeGenericVectorSync(
|
|
5409
|
+
function executeGenericVectorSync(_x4) {
|
|
4757
5410
|
return _executeGenericVectorSync.apply(this, arguments);
|
|
4758
5411
|
}
|
|
4759
5412
|
// Vector Sync from agents Dir
|
|
4760
5413
|
function _executeGenericVectorSync() {
|
|
4761
|
-
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4762
|
-
var _event$user2, _event$data2
|
|
4763
|
-
var event, mastra, connectionId,
|
|
4764
|
-
return _regeneratorRuntime().wrap(function
|
|
4765
|
-
while (1) switch (
|
|
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) {
|
|
4766
5419
|
case 0:
|
|
4767
|
-
event =
|
|
5420
|
+
event = _ref7.event, mastra = _ref7.mastra;
|
|
4768
5421
|
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
if (vector_provider) {
|
|
4773
|
-
_context11.next = 8;
|
|
4774
|
-
break;
|
|
4775
|
-
}
|
|
4776
|
-
console.error("No vector_provider defined for agent");
|
|
4777
|
-
return _context11.abrupt("return");
|
|
4778
|
-
case 8:
|
|
4779
|
-
vp = getVectorProvider(vector_provider);
|
|
4780
|
-
if (vp) {
|
|
4781
|
-
_context11.next = 12;
|
|
4782
|
-
break;
|
|
4783
|
-
}
|
|
4784
|
-
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4785
|
-
return _context11.abrupt("return");
|
|
4786
|
-
case 12:
|
|
4787
|
-
if (process.env.OPENAI_API_KEY) {
|
|
4788
|
-
_context11.next = 15;
|
|
4789
|
-
break;
|
|
4790
|
-
}
|
|
4791
|
-
console.error('NO OPENAI_API_KEY');
|
|
4792
|
-
return _context11.abrupt("return");
|
|
4793
|
-
case 15:
|
|
4794
|
-
_iterator5 = _createForOfIteratorHelperLoose(entities);
|
|
4795
|
-
case 16:
|
|
4796
|
-
if ((_step5 = _iterator5()).done) {
|
|
4797
|
-
_context11.next = 50;
|
|
4798
|
-
break;
|
|
4799
|
-
}
|
|
4800
|
-
vectorE = _step5.value;
|
|
4801
|
-
integrationName = vectorE.integration;
|
|
4802
|
-
_context11.next = 21;
|
|
4803
|
-
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
5422
|
+
entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
|
|
5423
|
+
_context10.next = 5;
|
|
5424
|
+
return indexSync({
|
|
4804
5425
|
connectionId: connectionId,
|
|
4805
|
-
|
|
5426
|
+
knowledgeSource: entities,
|
|
5427
|
+
mastra: mastra
|
|
4806
5428
|
});
|
|
4807
|
-
case
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
_context11.next = 26;
|
|
4811
|
-
break;
|
|
4812
|
-
}
|
|
4813
|
-
_context11.t2 = void 0;
|
|
4814
|
-
_context11.next = 27;
|
|
4815
|
-
break;
|
|
4816
|
-
case 26:
|
|
4817
|
-
_context11.t2 = _yield$mastra$dataLay2.id;
|
|
4818
|
-
case 27:
|
|
4819
|
-
_context11.t0 = _context11.t2;
|
|
4820
|
-
if (_context11.t0) {
|
|
4821
|
-
_context11.next = 30;
|
|
4822
|
-
break;
|
|
4823
|
-
}
|
|
4824
|
-
_context11.t0 = '';
|
|
4825
|
-
case 30:
|
|
4826
|
-
k_id = _context11.t0;
|
|
4827
|
-
if (!(!k_id && integrationName === systemName)) {
|
|
4828
|
-
_context11.next = 36;
|
|
4829
|
-
break;
|
|
4830
|
-
}
|
|
4831
|
-
_context11.next = 34;
|
|
4832
|
-
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4833
|
-
connection: {
|
|
4834
|
-
connectionId: connectionId,
|
|
4835
|
-
name: integrationName
|
|
4836
|
-
},
|
|
4837
|
-
credential: {
|
|
4838
|
-
type: 'API_KEY',
|
|
4839
|
-
value: connectionId,
|
|
4840
|
-
scope: []
|
|
4841
|
-
}
|
|
4842
|
-
});
|
|
4843
|
-
case 34:
|
|
4844
|
-
connection = _context11.sent;
|
|
4845
|
-
k_id = connection.id;
|
|
4846
|
-
case 36:
|
|
4847
|
-
if (k_id) {
|
|
4848
|
-
_context11.next = 39;
|
|
4849
|
-
break;
|
|
4850
|
-
}
|
|
4851
|
-
console.error('Error bootstrapping shit');
|
|
4852
|
-
return _context11.abrupt("return");
|
|
4853
|
-
case 39:
|
|
4854
|
-
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
4855
|
-
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4856
|
-
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4857
|
-
return _regeneratorRuntime().wrap(function _loop3$(_context10) {
|
|
4858
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
4859
|
-
case 0:
|
|
4860
|
-
entity = _step6.value;
|
|
4861
|
-
_context10.next = 3;
|
|
4862
|
-
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4863
|
-
k_id: k_id,
|
|
4864
|
-
type: entity.name
|
|
4865
|
-
});
|
|
4866
|
-
case 3:
|
|
4867
|
-
entityRecords = _context10.sent;
|
|
4868
|
-
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4869
|
-
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4870
|
-
_context10.next = 23;
|
|
4871
|
-
break;
|
|
4872
|
-
}
|
|
4873
|
-
// @TODO: SYNC THEM
|
|
4874
|
-
console.error('NO RECORDS');
|
|
4875
|
-
_context10.next = 9;
|
|
4876
|
-
return mastra.triggerEvent({
|
|
4877
|
-
key: entity.syncEvent,
|
|
4878
|
-
data: {},
|
|
4879
|
-
user: {
|
|
4880
|
-
connectionId: connectionId
|
|
4881
|
-
}
|
|
4882
|
-
});
|
|
4883
|
-
case 9:
|
|
4884
|
-
_yield$mastra$trigger2 = _context10.sent;
|
|
4885
|
-
_event2 = _yield$mastra$trigger2.event;
|
|
4886
|
-
console.log(_event2, '####');
|
|
4887
|
-
_context10.next = 14;
|
|
4888
|
-
return _event2.subscribe();
|
|
4889
|
-
case 14:
|
|
4890
|
-
res = _context10.sent;
|
|
4891
|
-
console.log('Subscribe result', res);
|
|
4892
|
-
_context10.next = 18;
|
|
4893
|
-
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4894
|
-
k_id: k_id,
|
|
4895
|
-
type: entity.name
|
|
4896
|
-
});
|
|
4897
|
-
case 18:
|
|
4898
|
-
entityRecords = _context10.sent;
|
|
4899
|
-
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4900
|
-
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4901
|
-
_context10.next = 23;
|
|
4902
|
-
break;
|
|
4903
|
-
}
|
|
4904
|
-
console.error('NO RECORDS AFTER SYNC');
|
|
4905
|
-
return _context10.abrupt("return", {
|
|
4906
|
-
v: void 0
|
|
4907
|
-
});
|
|
4908
|
-
case 23:
|
|
4909
|
-
recordsMapped = records.map(function (_ref14) {
|
|
4910
|
-
var data = _ref14.data,
|
|
4911
|
-
externalId = _ref14.externalId;
|
|
4912
|
-
return _extends({
|
|
4913
|
-
id: externalId
|
|
4914
|
-
}, pick(data, entity.fields));
|
|
4915
|
-
});
|
|
4916
|
-
console.log(recordsMapped, 'RECORDS');
|
|
4917
|
-
_context10.next = 27;
|
|
4918
|
-
return vp.createIndex({
|
|
4919
|
-
suppressConflicts: true,
|
|
4920
|
-
name: entity.name,
|
|
4921
|
-
dimension: 1536,
|
|
4922
|
-
metric: 'cosine',
|
|
4923
|
-
spec: {
|
|
4924
|
-
serverless: {
|
|
4925
|
-
cloud: 'aws',
|
|
4926
|
-
region: 'us-east-1'
|
|
4927
|
-
}
|
|
4928
|
-
}
|
|
4929
|
-
});
|
|
4930
|
-
case 27:
|
|
4931
|
-
_context10.next = 29;
|
|
4932
|
-
return delay$1(5000);
|
|
4933
|
-
case 29:
|
|
4934
|
-
entityTypeIndex = vp.index(entity.name);
|
|
4935
|
-
console.log(entityTypeIndex, 'INDEX');
|
|
4936
|
-
_context10.prev = 31;
|
|
4937
|
-
_context10.next = 34;
|
|
4938
|
-
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4939
|
-
var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(record) {
|
|
4940
|
-
var _yield$embed2, embedding;
|
|
4941
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context9) {
|
|
4942
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
4943
|
-
case 0:
|
|
4944
|
-
_context9.next = 2;
|
|
4945
|
-
return embed({
|
|
4946
|
-
model: openai.embedding('text-embedding-3-small'),
|
|
4947
|
-
value: JSON.stringify(record)
|
|
4948
|
-
});
|
|
4949
|
-
case 2:
|
|
4950
|
-
_yield$embed2 = _context9.sent;
|
|
4951
|
-
embedding = _yield$embed2.embedding;
|
|
4952
|
-
return _context9.abrupt("return", {
|
|
4953
|
-
id: record.id,
|
|
4954
|
-
values: embedding,
|
|
4955
|
-
metadata: record
|
|
4956
|
-
});
|
|
4957
|
-
case 5:
|
|
4958
|
-
case "end":
|
|
4959
|
-
return _context9.stop();
|
|
4960
|
-
}
|
|
4961
|
-
}, _callee8);
|
|
4962
|
-
}));
|
|
4963
|
-
return function (_x9) {
|
|
4964
|
-
return _ref15.apply(this, arguments);
|
|
4965
|
-
};
|
|
4966
|
-
}())) != null ? _recordsMapped$map2 : []);
|
|
4967
|
-
case 34:
|
|
4968
|
-
vectors = _context10.sent;
|
|
4969
|
-
console.log('UPSERTING', vectors);
|
|
4970
|
-
if (!(vectors.length > 0)) {
|
|
4971
|
-
_context10.next = 39;
|
|
4972
|
-
break;
|
|
4973
|
-
}
|
|
4974
|
-
_context10.next = 39;
|
|
4975
|
-
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4976
|
-
case 39:
|
|
4977
|
-
_context10.next = 44;
|
|
4978
|
-
break;
|
|
4979
|
-
case 41:
|
|
4980
|
-
_context10.prev = 41;
|
|
4981
|
-
_context10.t0 = _context10["catch"](31);
|
|
4982
|
-
console.error(_context10.t0);
|
|
4983
|
-
case 44:
|
|
4984
|
-
return _context10.abrupt("return", {
|
|
4985
|
-
v: void 0
|
|
4986
|
-
});
|
|
4987
|
-
case 45:
|
|
4988
|
-
case "end":
|
|
4989
|
-
return _context10.stop();
|
|
4990
|
-
}
|
|
4991
|
-
}, _loop3, null, [[31, 41]]);
|
|
4992
|
-
});
|
|
4993
|
-
_iterator6 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4994
|
-
case 41:
|
|
4995
|
-
if ((_step6 = _iterator6()).done) {
|
|
4996
|
-
_context11.next = 48;
|
|
4997
|
-
break;
|
|
4998
|
-
}
|
|
4999
|
-
return _context11.delegateYield(_loop3(), "t3", 43);
|
|
5000
|
-
case 43:
|
|
5001
|
-
_ret2 = _context11.t3;
|
|
5002
|
-
if (!_ret2) {
|
|
5003
|
-
_context11.next = 46;
|
|
5004
|
-
break;
|
|
5005
|
-
}
|
|
5006
|
-
return _context11.abrupt("return", _ret2.v);
|
|
5007
|
-
case 46:
|
|
5008
|
-
_context11.next = 41;
|
|
5009
|
-
break;
|
|
5010
|
-
case 48:
|
|
5011
|
-
_context11.next = 16;
|
|
5012
|
-
break;
|
|
5013
|
-
case 50:
|
|
5429
|
+
case 5:
|
|
5430
|
+
return _context10.abrupt("return", _context10.sent);
|
|
5431
|
+
case 6:
|
|
5014
5432
|
case "end":
|
|
5015
|
-
return
|
|
5433
|
+
return _context10.stop();
|
|
5016
5434
|
}
|
|
5017
|
-
},
|
|
5435
|
+
}, _callee8);
|
|
5018
5436
|
}));
|
|
5019
5437
|
return _executeGenericVectorSync.apply(this, arguments);
|
|
5020
5438
|
}
|
|
5021
|
-
function executeVectorSync(
|
|
5439
|
+
function executeVectorSync(_x5) {
|
|
5022
5440
|
return _executeVectorSync.apply(this, arguments);
|
|
5023
5441
|
}
|
|
5024
5442
|
function _executeVectorSync() {
|
|
5025
|
-
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5026
|
-
var _event$user3
|
|
5027
|
-
var event, mastra, agentDir, agent, connectionId
|
|
5028
|
-
return _regeneratorRuntime().wrap(function
|
|
5029
|
-
while (1) switch (
|
|
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) {
|
|
5030
5448
|
case 0:
|
|
5031
|
-
event =
|
|
5449
|
+
event = _ref8.event, mastra = _ref8.mastra;
|
|
5032
5450
|
agentDir = mastra.config.agents.agentDirPath;
|
|
5033
5451
|
agent = getAgentBlueprint({
|
|
5034
5452
|
agentDir: agentDir,
|
|
5035
5453
|
agentId: event.data.agentId
|
|
5036
5454
|
});
|
|
5037
5455
|
connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
_context14.next = 8;
|
|
5041
|
-
break;
|
|
5042
|
-
}
|
|
5043
|
-
console.error("No vector_provider defined for agent");
|
|
5044
|
-
return _context14.abrupt("return");
|
|
5045
|
-
case 8:
|
|
5046
|
-
vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
|
|
5047
|
-
if (vp) {
|
|
5048
|
-
_context14.next = 12;
|
|
5049
|
-
break;
|
|
5050
|
-
}
|
|
5051
|
-
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
|
|
5052
|
-
return _context14.abrupt("return");
|
|
5053
|
-
case 12:
|
|
5054
|
-
if (process.env.OPENAI_API_KEY) {
|
|
5055
|
-
_context14.next = 15;
|
|
5056
|
-
break;
|
|
5057
|
-
}
|
|
5058
|
-
console.error('NO OPENAI_API_KEY');
|
|
5059
|
-
return _context14.abrupt("return");
|
|
5060
|
-
case 15:
|
|
5061
|
-
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
5062
|
-
_context14.next = 18;
|
|
5063
|
-
break;
|
|
5064
|
-
}
|
|
5065
|
-
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
5066
|
-
return _context14.abrupt("return");
|
|
5067
|
-
case 18:
|
|
5068
|
-
_iterator7 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
5069
|
-
case 19:
|
|
5070
|
-
if ((_step7 = _iterator7()).done) {
|
|
5071
|
-
_context14.next = 53;
|
|
5072
|
-
break;
|
|
5073
|
-
}
|
|
5074
|
-
vectorE = _step7.value;
|
|
5075
|
-
integrationName = vectorE.integration;
|
|
5076
|
-
_context14.next = 24;
|
|
5077
|
-
return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
|
|
5456
|
+
_context11.next = 6;
|
|
5457
|
+
return indexSync({
|
|
5078
5458
|
connectionId: connectionId,
|
|
5079
|
-
|
|
5459
|
+
knowledgeSource: agent == null ? void 0 : agent.knowledge_sources,
|
|
5460
|
+
mastra: mastra
|
|
5080
5461
|
});
|
|
5081
|
-
case
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
_context14.next = 29;
|
|
5085
|
-
break;
|
|
5086
|
-
}
|
|
5087
|
-
_context14.t2 = void 0;
|
|
5088
|
-
_context14.next = 30;
|
|
5089
|
-
break;
|
|
5090
|
-
case 29:
|
|
5091
|
-
_context14.t2 = _yield$mastra$dataLay3.id;
|
|
5092
|
-
case 30:
|
|
5093
|
-
_context14.t0 = _context14.t2;
|
|
5094
|
-
if (_context14.t0) {
|
|
5095
|
-
_context14.next = 33;
|
|
5096
|
-
break;
|
|
5097
|
-
}
|
|
5098
|
-
_context14.t0 = '';
|
|
5099
|
-
case 33:
|
|
5100
|
-
k_id = _context14.t0;
|
|
5101
|
-
if (!(!k_id && integrationName === systemName)) {
|
|
5102
|
-
_context14.next = 39;
|
|
5103
|
-
break;
|
|
5104
|
-
}
|
|
5105
|
-
_context14.next = 37;
|
|
5106
|
-
return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
|
|
5107
|
-
connection: {
|
|
5108
|
-
connectionId: connectionId,
|
|
5109
|
-
name: integrationName
|
|
5110
|
-
},
|
|
5111
|
-
credential: {
|
|
5112
|
-
type: 'API_KEY',
|
|
5113
|
-
value: connectionId,
|
|
5114
|
-
scope: []
|
|
5115
|
-
}
|
|
5116
|
-
});
|
|
5117
|
-
case 37:
|
|
5118
|
-
connection = _context14.sent;
|
|
5119
|
-
k_id = connection.id;
|
|
5120
|
-
case 39:
|
|
5121
|
-
if (k_id) {
|
|
5122
|
-
_context14.next = 42;
|
|
5123
|
-
break;
|
|
5124
|
-
}
|
|
5125
|
-
console.error('Error bootstrapping shit');
|
|
5126
|
-
return _context14.abrupt("return");
|
|
5127
|
-
case 42:
|
|
5128
|
-
_loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
|
|
5129
|
-
var _mastra$dataLayer11, _entityRecords5, _records5;
|
|
5130
|
-
var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
|
|
5131
|
-
return _regeneratorRuntime().wrap(function _loop4$(_context13) {
|
|
5132
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
5133
|
-
case 0:
|
|
5134
|
-
entity = _step8.value;
|
|
5135
|
-
_context13.next = 3;
|
|
5136
|
-
return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
|
|
5137
|
-
k_id: k_id,
|
|
5138
|
-
type: entity.name
|
|
5139
|
-
});
|
|
5140
|
-
case 3:
|
|
5141
|
-
entityRecords = _context13.sent;
|
|
5142
|
-
records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
|
|
5143
|
-
if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
|
|
5144
|
-
_context13.next = 23;
|
|
5145
|
-
break;
|
|
5146
|
-
}
|
|
5147
|
-
// @TODO: SYNC THEM
|
|
5148
|
-
console.error('NO RECORDS');
|
|
5149
|
-
_context13.next = 9;
|
|
5150
|
-
return mastra.triggerEvent({
|
|
5151
|
-
key: entity.syncEvent,
|
|
5152
|
-
data: {},
|
|
5153
|
-
user: {
|
|
5154
|
-
connectionId: connectionId
|
|
5155
|
-
}
|
|
5156
|
-
});
|
|
5157
|
-
case 9:
|
|
5158
|
-
_yield$mastra$trigger3 = _context13.sent;
|
|
5159
|
-
_event3 = _yield$mastra$trigger3.event;
|
|
5160
|
-
console.log(_event3, '####');
|
|
5161
|
-
_context13.next = 14;
|
|
5162
|
-
return _event3.subscribe();
|
|
5163
|
-
case 14:
|
|
5164
|
-
res = _context13.sent;
|
|
5165
|
-
console.log('Subscribe result', res);
|
|
5166
|
-
_context13.next = 18;
|
|
5167
|
-
return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
|
|
5168
|
-
k_id: k_id,
|
|
5169
|
-
type: entity.name
|
|
5170
|
-
});
|
|
5171
|
-
case 18:
|
|
5172
|
-
entityRecords = _context13.sent;
|
|
5173
|
-
records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
|
|
5174
|
-
if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
|
|
5175
|
-
_context13.next = 23;
|
|
5176
|
-
break;
|
|
5177
|
-
}
|
|
5178
|
-
console.error('NO RECORDS AFTER SYNC');
|
|
5179
|
-
return _context13.abrupt("return", {
|
|
5180
|
-
v: void 0
|
|
5181
|
-
});
|
|
5182
|
-
case 23:
|
|
5183
|
-
recordsMapped = records.map(function (_ref16) {
|
|
5184
|
-
var data = _ref16.data,
|
|
5185
|
-
externalId = _ref16.externalId;
|
|
5186
|
-
return _extends({
|
|
5187
|
-
id: externalId
|
|
5188
|
-
}, pick(data, entity.fields));
|
|
5189
|
-
});
|
|
5190
|
-
console.log(recordsMapped, 'RECORDS');
|
|
5191
|
-
_context13.next = 27;
|
|
5192
|
-
return vp.createIndex({
|
|
5193
|
-
suppressConflicts: true,
|
|
5194
|
-
name: entity.name,
|
|
5195
|
-
dimension: 1536,
|
|
5196
|
-
metric: 'cosine',
|
|
5197
|
-
spec: {
|
|
5198
|
-
serverless: {
|
|
5199
|
-
cloud: 'aws',
|
|
5200
|
-
region: 'us-east-1'
|
|
5201
|
-
}
|
|
5202
|
-
}
|
|
5203
|
-
});
|
|
5204
|
-
case 27:
|
|
5205
|
-
entityTypeIndex = vp.index(entity.name);
|
|
5206
|
-
console.log(entityTypeIndex, 'INDEX');
|
|
5207
|
-
_context13.prev = 29;
|
|
5208
|
-
_context13.next = 32;
|
|
5209
|
-
return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
|
|
5210
|
-
var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(record) {
|
|
5211
|
-
var _yield$embed3, embedding;
|
|
5212
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context12) {
|
|
5213
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
5214
|
-
case 0:
|
|
5215
|
-
_context12.next = 2;
|
|
5216
|
-
return embed({
|
|
5217
|
-
model: openai.embedding('text-embedding-3-small'),
|
|
5218
|
-
value: JSON.stringify(record)
|
|
5219
|
-
});
|
|
5220
|
-
case 2:
|
|
5221
|
-
_yield$embed3 = _context12.sent;
|
|
5222
|
-
embedding = _yield$embed3.embedding;
|
|
5223
|
-
return _context12.abrupt("return", {
|
|
5224
|
-
id: record.id,
|
|
5225
|
-
values: embedding,
|
|
5226
|
-
metadata: record
|
|
5227
|
-
});
|
|
5228
|
-
case 5:
|
|
5229
|
-
case "end":
|
|
5230
|
-
return _context12.stop();
|
|
5231
|
-
}
|
|
5232
|
-
}, _callee10);
|
|
5233
|
-
}));
|
|
5234
|
-
return function (_x10) {
|
|
5235
|
-
return _ref17.apply(this, arguments);
|
|
5236
|
-
};
|
|
5237
|
-
}())) != null ? _recordsMapped$map3 : []);
|
|
5238
|
-
case 32:
|
|
5239
|
-
vectors = _context13.sent;
|
|
5240
|
-
console.log('UPSERTING', vectors);
|
|
5241
|
-
if (!(vectors.length > 0)) {
|
|
5242
|
-
_context13.next = 37;
|
|
5243
|
-
break;
|
|
5244
|
-
}
|
|
5245
|
-
_context13.next = 37;
|
|
5246
|
-
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
5247
|
-
case 37:
|
|
5248
|
-
_context13.next = 42;
|
|
5249
|
-
break;
|
|
5250
|
-
case 39:
|
|
5251
|
-
_context13.prev = 39;
|
|
5252
|
-
_context13.t0 = _context13["catch"](29);
|
|
5253
|
-
console.error(_context13.t0);
|
|
5254
|
-
case 42:
|
|
5255
|
-
return _context13.abrupt("return", {
|
|
5256
|
-
v: void 0
|
|
5257
|
-
});
|
|
5258
|
-
case 43:
|
|
5259
|
-
case "end":
|
|
5260
|
-
return _context13.stop();
|
|
5261
|
-
}
|
|
5262
|
-
}, _loop4, null, [[29, 39]]);
|
|
5263
|
-
});
|
|
5264
|
-
_iterator8 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5265
|
-
case 44:
|
|
5266
|
-
if ((_step8 = _iterator8()).done) {
|
|
5267
|
-
_context14.next = 51;
|
|
5268
|
-
break;
|
|
5269
|
-
}
|
|
5270
|
-
return _context14.delegateYield(_loop4(), "t3", 46);
|
|
5271
|
-
case 46:
|
|
5272
|
-
_ret3 = _context14.t3;
|
|
5273
|
-
if (!_ret3) {
|
|
5274
|
-
_context14.next = 49;
|
|
5275
|
-
break;
|
|
5276
|
-
}
|
|
5277
|
-
return _context14.abrupt("return", _ret3.v);
|
|
5278
|
-
case 49:
|
|
5279
|
-
_context14.next = 44;
|
|
5280
|
-
break;
|
|
5281
|
-
case 51:
|
|
5282
|
-
_context14.next = 19;
|
|
5283
|
-
break;
|
|
5284
|
-
case 53:
|
|
5462
|
+
case 6:
|
|
5463
|
+
return _context11.abrupt("return", _context11.sent);
|
|
5464
|
+
case 7:
|
|
5285
5465
|
case "end":
|
|
5286
|
-
return
|
|
5466
|
+
return _context11.stop();
|
|
5287
5467
|
}
|
|
5288
|
-
},
|
|
5468
|
+
}, _callee9);
|
|
5289
5469
|
}));
|
|
5290
5470
|
return _executeVectorSync.apply(this, arguments);
|
|
5291
5471
|
}
|
|
5292
|
-
function vectorQueryEngine(
|
|
5472
|
+
function vectorQueryEngine(_x6) {
|
|
5293
5473
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5294
5474
|
}
|
|
5295
5475
|
function _vectorQueryEngine() {
|
|
5296
|
-
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5297
|
-
var vector_provider,
|
|
5298
|
-
return _regeneratorRuntime().wrap(function
|
|
5299
|
-
while (1) switch (
|
|
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) {
|
|
5300
5480
|
case 0:
|
|
5301
|
-
vector_provider =
|
|
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;
|
|
5302
5482
|
vp = getVectorProvider(vector_provider);
|
|
5303
5483
|
if (vp) {
|
|
5304
|
-
|
|
5484
|
+
_context12.next = 5;
|
|
5305
5485
|
break;
|
|
5306
5486
|
}
|
|
5307
5487
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
5308
|
-
return
|
|
5488
|
+
return _context12.abrupt("return");
|
|
5309
5489
|
case 5:
|
|
5310
5490
|
index = vp.index(indexName);
|
|
5311
|
-
|
|
5491
|
+
_context12.next = 8;
|
|
5312
5492
|
return embed({
|
|
5313
5493
|
model: openai.embedding('text-embedding-3-small'),
|
|
5314
5494
|
value: content
|
|
5315
5495
|
});
|
|
5316
5496
|
case 8:
|
|
5317
|
-
_yield$
|
|
5318
|
-
embedding = _yield$
|
|
5497
|
+
_yield$embed2 = _context12.sent;
|
|
5498
|
+
embedding = _yield$embed2.embedding;
|
|
5319
5499
|
console.log(embedding, 'EMBEDDING');
|
|
5320
|
-
|
|
5500
|
+
_context12.next = 13;
|
|
5321
5501
|
return index.namespace(entityType).query({
|
|
5322
5502
|
vector: embedding,
|
|
5323
5503
|
topK: topK,
|
|
5324
5504
|
includeMetadata: true
|
|
5325
5505
|
});
|
|
5326
5506
|
case 13:
|
|
5327
|
-
queryResponse =
|
|
5328
|
-
return
|
|
5507
|
+
queryResponse = _context12.sent;
|
|
5508
|
+
return _context12.abrupt("return", queryResponse);
|
|
5329
5509
|
case 15:
|
|
5330
5510
|
case "end":
|
|
5331
|
-
return
|
|
5511
|
+
return _context12.stop();
|
|
5332
5512
|
}
|
|
5333
|
-
},
|
|
5513
|
+
}, _callee10);
|
|
5334
5514
|
}));
|
|
5335
5515
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5336
5516
|
}
|
|
5337
|
-
var fetchPineconeIndexes = /*#__PURE__*/function () {
|
|
5338
|
-
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
5339
|
-
var response, _ref6, indexes;
|
|
5340
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5341
|
-
while (1) switch (_context.prev = _context.next) {
|
|
5342
|
-
case 0:
|
|
5343
|
-
_context.prev = 0;
|
|
5344
|
-
_context.next = 3;
|
|
5345
|
-
return fetch('https://api.pinecone.io/indexes', {
|
|
5346
|
-
method: 'GET',
|
|
5347
|
-
headers: {
|
|
5348
|
-
'Api-Key': process.env.PINECONE_API_KEY,
|
|
5349
|
-
'X-Pinecone-API-Version': 'unstable'
|
|
5350
|
-
},
|
|
5351
|
-
cache: 'no-store'
|
|
5352
|
-
});
|
|
5353
|
-
case 3:
|
|
5354
|
-
response = _context.sent;
|
|
5355
|
-
_context.next = 6;
|
|
5356
|
-
return response.json();
|
|
5357
|
-
case 6:
|
|
5358
|
-
_context.t0 = _context.sent;
|
|
5359
|
-
if (_context.t0) {
|
|
5360
|
-
_context.next = 9;
|
|
5361
|
-
break;
|
|
5362
|
-
}
|
|
5363
|
-
_context.t0 = {};
|
|
5364
|
-
case 9:
|
|
5365
|
-
_ref6 = _context.t0;
|
|
5366
|
-
indexes = _ref6.indexes;
|
|
5367
|
-
return _context.abrupt("return", indexes);
|
|
5368
|
-
case 14:
|
|
5369
|
-
_context.prev = 14;
|
|
5370
|
-
_context.t1 = _context["catch"](0);
|
|
5371
|
-
console.log('Error fetching indexes using JS fetch====', _context.t1);
|
|
5372
|
-
case 17:
|
|
5373
|
-
case "end":
|
|
5374
|
-
return _context.stop();
|
|
5375
|
-
}
|
|
5376
|
-
}, _callee, null, [[0, 14]]);
|
|
5377
|
-
}));
|
|
5378
|
-
return function fetchPineconeIndexes() {
|
|
5379
|
-
return _ref5.apply(this, arguments);
|
|
5380
|
-
};
|
|
5381
|
-
}();
|
|
5382
|
-
var fetchPineconeIndexStats = /*#__PURE__*/function () {
|
|
5383
|
-
var _ref7 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(host) {
|
|
5384
|
-
var response, data;
|
|
5385
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5386
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
5387
|
-
case 0:
|
|
5388
|
-
_context2.prev = 0;
|
|
5389
|
-
_context2.next = 3;
|
|
5390
|
-
return fetch("https://" + host + "/describe_index_stats", {
|
|
5391
|
-
method: 'GET',
|
|
5392
|
-
headers: {
|
|
5393
|
-
'Api-Key': process.env.PINECONE_API_KEY,
|
|
5394
|
-
'X-Pinecone-API-Version': '2024-07'
|
|
5395
|
-
},
|
|
5396
|
-
cache: 'no-store'
|
|
5397
|
-
});
|
|
5398
|
-
case 3:
|
|
5399
|
-
response = _context2.sent;
|
|
5400
|
-
_context2.next = 6;
|
|
5401
|
-
return response.json();
|
|
5402
|
-
case 6:
|
|
5403
|
-
_context2.t0 = _context2.sent;
|
|
5404
|
-
if (_context2.t0) {
|
|
5405
|
-
_context2.next = 9;
|
|
5406
|
-
break;
|
|
5407
|
-
}
|
|
5408
|
-
_context2.t0 = {};
|
|
5409
|
-
case 9:
|
|
5410
|
-
data = _context2.t0;
|
|
5411
|
-
return _context2.abrupt("return", data);
|
|
5412
|
-
case 13:
|
|
5413
|
-
_context2.prev = 13;
|
|
5414
|
-
_context2.t1 = _context2["catch"](0);
|
|
5415
|
-
console.log('Error fetching indexes using JS fetch====', _context2.t1);
|
|
5416
|
-
case 16:
|
|
5417
|
-
case "end":
|
|
5418
|
-
return _context2.stop();
|
|
5419
|
-
}
|
|
5420
|
-
}, _callee2, null, [[0, 13]]);
|
|
5421
|
-
}));
|
|
5422
|
-
return function fetchPineconeIndexStats(_x5) {
|
|
5423
|
-
return _ref7.apply(this, arguments);
|
|
5424
|
-
};
|
|
5425
|
-
}();
|
|
5426
5517
|
var getPineconeIndices = /*#__PURE__*/function () {
|
|
5427
|
-
var
|
|
5428
|
-
var indexes, indexesWithStats;
|
|
5429
|
-
return _regeneratorRuntime().wrap(function
|
|
5430
|
-
while (1) switch (
|
|
5518
|
+
var _ref10 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
5519
|
+
var vectorLayer, indexes, indexesWithStats;
|
|
5520
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context7) {
|
|
5521
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
5431
5522
|
case 0:
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5523
|
+
vectorLayer = new VectorLayer();
|
|
5524
|
+
_context7.next = 3;
|
|
5525
|
+
return vectorLayer.fetchPineconeIndexes();
|
|
5526
|
+
case 3:
|
|
5527
|
+
indexes = _context7.sent;
|
|
5436
5528
|
if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
|
|
5437
|
-
|
|
5529
|
+
_context7.next = 9;
|
|
5438
5530
|
break;
|
|
5439
5531
|
}
|
|
5440
|
-
|
|
5532
|
+
_context7.next = 7;
|
|
5441
5533
|
return Promise.all(indexes.map(/*#__PURE__*/function () {
|
|
5442
|
-
var
|
|
5534
|
+
var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index) {
|
|
5443
5535
|
var stats, namespaces;
|
|
5444
|
-
return _regeneratorRuntime().wrap(function
|
|
5445
|
-
while (1) switch (
|
|
5536
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context6) {
|
|
5537
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
5446
5538
|
case 0:
|
|
5447
|
-
|
|
5448
|
-
return fetchPineconeIndexStats(index.host);
|
|
5539
|
+
_context6.next = 2;
|
|
5540
|
+
return vectorLayer.fetchPineconeIndexStats(index.host);
|
|
5449
5541
|
case 2:
|
|
5450
|
-
stats =
|
|
5542
|
+
stats = _context6.sent;
|
|
5451
5543
|
namespaces = [];
|
|
5452
5544
|
if (stats != null && stats.namespaces) {
|
|
5453
5545
|
namespaces = Object.keys(stats.namespaces);
|
|
5454
5546
|
}
|
|
5455
|
-
return
|
|
5547
|
+
return _context6.abrupt("return", _extends({}, index, {
|
|
5456
5548
|
namespaces: namespaces
|
|
5457
5549
|
}));
|
|
5458
5550
|
case 6:
|
|
5459
5551
|
case "end":
|
|
5460
|
-
return
|
|
5552
|
+
return _context6.stop();
|
|
5461
5553
|
}
|
|
5462
|
-
},
|
|
5554
|
+
}, _callee4);
|
|
5463
5555
|
}));
|
|
5464
|
-
return function (
|
|
5465
|
-
return
|
|
5556
|
+
return function (_x7) {
|
|
5557
|
+
return _ref11.apply(this, arguments);
|
|
5466
5558
|
};
|
|
5467
5559
|
}()));
|
|
5468
|
-
case
|
|
5469
|
-
indexesWithStats =
|
|
5470
|
-
return
|
|
5471
|
-
case 8:
|
|
5472
|
-
return _context4.abrupt("return", []);
|
|
5560
|
+
case 7:
|
|
5561
|
+
indexesWithStats = _context7.sent;
|
|
5562
|
+
return _context7.abrupt("return", indexesWithStats);
|
|
5473
5563
|
case 9:
|
|
5564
|
+
return _context7.abrupt("return", []);
|
|
5565
|
+
case 10:
|
|
5474
5566
|
case "end":
|
|
5475
|
-
return
|
|
5567
|
+
return _context7.stop();
|
|
5476
5568
|
}
|
|
5477
|
-
},
|
|
5569
|
+
}, _callee5);
|
|
5478
5570
|
}));
|
|
5479
5571
|
return function getPineconeIndices() {
|
|
5480
|
-
return
|
|
5572
|
+
return _ref10.apply(this, arguments);
|
|
5481
5573
|
};
|
|
5482
5574
|
}();
|
|
5483
|
-
function getVectorQueryApis(
|
|
5484
|
-
var mastra =
|
|
5575
|
+
function getVectorQueryApis(_ref12) {
|
|
5576
|
+
var mastra = _ref12.mastra;
|
|
5485
5577
|
var vectorProvider = mastra.config.agents.vectorProvider;
|
|
5486
5578
|
if (!vectorProvider) {
|
|
5487
5579
|
console.error('NO VECTOR PROVIDER');
|
|
5488
5580
|
return [];
|
|
5489
5581
|
}
|
|
5490
5582
|
var vectorApis = [];
|
|
5491
|
-
var
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
integrationName: 'SYSTEM',
|
|
5502
|
-
type: "vector_query_" + index.name + "_" + namespace,
|
|
5503
|
-
label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5504
|
-
description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5505
|
-
schema: z.object({
|
|
5506
|
-
content: z.string(),
|
|
5507
|
-
topResult: z.number()
|
|
5508
|
-
}),
|
|
5509
|
-
executor: function () {
|
|
5510
|
-
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref11) {
|
|
5511
|
-
var data, res;
|
|
5512
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5513
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
5514
|
-
case 0:
|
|
5515
|
-
data = _ref11.data;
|
|
5516
|
-
_context5.next = 3;
|
|
5517
|
-
return vectorQueryEngine({
|
|
5518
|
-
vector_provider: provider.name,
|
|
5519
|
-
indexName: index.name,
|
|
5520
|
-
content: data.content,
|
|
5521
|
-
topK: data.topResult || 1,
|
|
5522
|
-
entityType: namespace
|
|
5523
|
-
});
|
|
5524
|
-
case 3:
|
|
5525
|
-
res = _context5.sent;
|
|
5526
|
-
console.log(JSON.stringify({
|
|
5527
|
-
res: res
|
|
5528
|
-
}, null, 2));
|
|
5529
|
-
// @TODO: make this a proper response
|
|
5530
|
-
return _context5.abrupt("return", res);
|
|
5531
|
-
case 6:
|
|
5532
|
-
case "end":
|
|
5533
|
-
return _context5.stop();
|
|
5534
|
-
}
|
|
5535
|
-
}, _callee5);
|
|
5536
|
-
}));
|
|
5537
|
-
function executor(_x7) {
|
|
5538
|
-
return _executor.apply(this, arguments);
|
|
5539
|
-
}
|
|
5540
|
-
return executor;
|
|
5541
|
-
}()
|
|
5542
|
-
});
|
|
5543
|
-
});
|
|
5583
|
+
var _loop3 = function _loop3() {
|
|
5584
|
+
var provider = _step4.value;
|
|
5585
|
+
if (provider.name.toUpperCase() === 'PINECONE') {
|
|
5586
|
+
var config = getPineconeConfig({
|
|
5587
|
+
dir: provider.dirPath
|
|
5588
|
+
});
|
|
5589
|
+
if (!config || (config == null ? void 0 : config.length) === 0) {
|
|
5590
|
+
return {
|
|
5591
|
+
v: []
|
|
5592
|
+
};
|
|
5544
5593
|
}
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5594
|
+
config == null || config.forEach(function (index) {
|
|
5595
|
+
if (index != null && index.namespaces) {
|
|
5596
|
+
index == null || index.namespaces.forEach(function (namespace) {
|
|
5597
|
+
vectorApis.push({
|
|
5598
|
+
integrationName: mastra.config.name,
|
|
5599
|
+
type: "vq_" + index.name + "_" + namespace,
|
|
5600
|
+
label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5601
|
+
description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5602
|
+
schema: z.object({
|
|
5603
|
+
content: z.string(),
|
|
5604
|
+
topResult: z.number()
|
|
5605
|
+
}),
|
|
5606
|
+
source: provider.name.toUpperCase(),
|
|
5607
|
+
executor: function () {
|
|
5608
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref13) {
|
|
5609
|
+
var data, res;
|
|
5610
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
5611
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
5612
|
+
case 0:
|
|
5613
|
+
data = _ref13.data;
|
|
5614
|
+
_context8.next = 3;
|
|
5615
|
+
return vectorQueryEngine({
|
|
5616
|
+
vector_provider: provider.name,
|
|
5617
|
+
indexName: index.name,
|
|
5618
|
+
content: data.content,
|
|
5619
|
+
topK: data.topResult || 1,
|
|
5620
|
+
entityType: namespace
|
|
5621
|
+
});
|
|
5622
|
+
case 3:
|
|
5623
|
+
res = _context8.sent;
|
|
5624
|
+
console.log(JSON.stringify({
|
|
5625
|
+
res: res
|
|
5626
|
+
}, null, 2));
|
|
5627
|
+
// @TODO: make this a proper response
|
|
5628
|
+
return _context8.abrupt("return", res);
|
|
5629
|
+
case 6:
|
|
5630
|
+
case "end":
|
|
5631
|
+
return _context8.stop();
|
|
5632
|
+
}
|
|
5633
|
+
}, _callee6);
|
|
5634
|
+
}));
|
|
5635
|
+
function executor(_x8) {
|
|
5636
|
+
return _executor.apply(this, arguments);
|
|
5637
|
+
}
|
|
5638
|
+
return executor;
|
|
5639
|
+
}()
|
|
5640
|
+
});
|
|
5641
|
+
});
|
|
5642
|
+
}
|
|
5643
|
+
});
|
|
5644
|
+
}
|
|
5645
|
+
},
|
|
5646
|
+
_ret3;
|
|
5647
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(vectorProvider), _step4; !(_step4 = _iterator4()).done;) {
|
|
5648
|
+
_ret3 = _loop3();
|
|
5649
|
+
if (_ret3) return _ret3.v;
|
|
5550
5650
|
}
|
|
5551
5651
|
return vectorApis;
|
|
5552
5652
|
}
|
|
@@ -5573,6 +5673,74 @@ function vectorIndexSync() {
|
|
|
5573
5673
|
executor: executeIndexSync
|
|
5574
5674
|
};
|
|
5575
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
|
+
}
|
|
5576
5744
|
|
|
5577
5745
|
function getAgentSystemApis(_ref) {
|
|
5578
5746
|
var mastra = _ref.mastra;
|
|
@@ -5690,8 +5858,8 @@ function createAssistantAgentHandler(logger) {
|
|
|
5690
5858
|
});
|
|
5691
5859
|
case 3:
|
|
5692
5860
|
assistant = _context.sent;
|
|
5693
|
-
logger({
|
|
5694
|
-
destinationPath:
|
|
5861
|
+
logger == null || logger.info({
|
|
5862
|
+
destinationPath: "" + assistant.id,
|
|
5695
5863
|
statusCode: 201,
|
|
5696
5864
|
message: JSON.stringify({
|
|
5697
5865
|
message: 'Created assistant',
|
|
@@ -5734,8 +5902,8 @@ function updateAssistantAgentHandler(logger) {
|
|
|
5734
5902
|
});
|
|
5735
5903
|
case 3:
|
|
5736
5904
|
assistant = _context2.sent;
|
|
5737
|
-
logger({
|
|
5738
|
-
destinationPath:
|
|
5905
|
+
logger == null || logger.info({
|
|
5906
|
+
destinationPath: "" + assistant.id,
|
|
5739
5907
|
statusCode: 200,
|
|
5740
5908
|
message: JSON.stringify({
|
|
5741
5909
|
message: 'Updated assistant',
|
|
@@ -5802,8 +5970,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5802
5970
|
return _context3.abrupt("return", _context3.sent);
|
|
5803
5971
|
case 14:
|
|
5804
5972
|
console.error('Run did not complete:', run);
|
|
5805
|
-
logger({
|
|
5806
|
-
destinationPath:
|
|
5973
|
+
logger == null || logger.error({
|
|
5974
|
+
destinationPath: "" + id,
|
|
5807
5975
|
statusCode: 400,
|
|
5808
5976
|
message: JSON.stringify({
|
|
5809
5977
|
message: "Run did not complete",
|
|
@@ -5813,7 +5981,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5813
5981
|
}
|
|
5814
5982
|
}, null, 2)
|
|
5815
5983
|
});
|
|
5816
|
-
|
|
5984
|
+
return _context3.abrupt("return", run == null ? void 0 : run.last_error);
|
|
5985
|
+
case 17:
|
|
5817
5986
|
case "end":
|
|
5818
5987
|
return _context3.stop();
|
|
5819
5988
|
}
|
|
@@ -5849,8 +6018,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5849
6018
|
fn: tool["function"].name,
|
|
5850
6019
|
availableTools: Object.keys(toolMap)
|
|
5851
6020
|
};
|
|
5852
|
-
logger({
|
|
5853
|
-
destinationPath:
|
|
6021
|
+
logger == null || logger.info({
|
|
6022
|
+
destinationPath: "" + id,
|
|
5854
6023
|
statusCode: 100,
|
|
5855
6024
|
message: JSON.stringify({
|
|
5856
6025
|
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
@@ -5864,8 +6033,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5864
6033
|
_context4.next = 8;
|
|
5865
6034
|
break;
|
|
5866
6035
|
}
|
|
5867
|
-
logger({
|
|
5868
|
-
destinationPath:
|
|
6036
|
+
logger == null || logger.error({
|
|
6037
|
+
destinationPath: "" + id,
|
|
5869
6038
|
statusCode: 404,
|
|
5870
6039
|
message: JSON.stringify({
|
|
5871
6040
|
message: "[local] No tool fn found: " + tool["function"].name,
|
|
@@ -5881,8 +6050,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5881
6050
|
try {
|
|
5882
6051
|
if (tool["function"].arguments) {
|
|
5883
6052
|
args = JSON.parse(tool["function"].arguments);
|
|
5884
|
-
logger({
|
|
5885
|
-
destinationPath:
|
|
6053
|
+
logger == null || logger.info({
|
|
6054
|
+
destinationPath: "" + id,
|
|
5886
6055
|
statusCode: 200,
|
|
5887
6056
|
message: JSON.stringify({
|
|
5888
6057
|
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
@@ -5900,8 +6069,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5900
6069
|
return toolFn(args);
|
|
5901
6070
|
case 13:
|
|
5902
6071
|
output = _context4.sent;
|
|
5903
|
-
logger({
|
|
5904
|
-
destinationPath:
|
|
6072
|
+
logger == null || logger.info({
|
|
6073
|
+
destinationPath: "" + id,
|
|
5905
6074
|
statusCode: 200,
|
|
5906
6075
|
message: JSON.stringify({
|
|
5907
6076
|
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
@@ -5933,8 +6102,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5933
6102
|
break;
|
|
5934
6103
|
}
|
|
5935
6104
|
console.error('No tool outputs to submit.');
|
|
5936
|
-
logger({
|
|
5937
|
-
destinationPath:
|
|
6105
|
+
logger == null || logger.error({
|
|
6106
|
+
destinationPath: "" + id,
|
|
5938
6107
|
statusCode: 404,
|
|
5939
6108
|
message: JSON.stringify({
|
|
5940
6109
|
message: "No tool outputs submitted",
|
|
@@ -5957,8 +6126,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5957
6126
|
});
|
|
5958
6127
|
case 15:
|
|
5959
6128
|
run = _context5.sent;
|
|
5960
|
-
logger({
|
|
5961
|
-
destinationPath:
|
|
6129
|
+
logger == null || logger.info({
|
|
6130
|
+
destinationPath: "" + id,
|
|
5962
6131
|
statusCode: 200,
|
|
5963
6132
|
message: JSON.stringify({
|
|
5964
6133
|
message: "Tool outputs submitted",
|
|
@@ -5971,8 +6140,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
5971
6140
|
_context5.next = 22;
|
|
5972
6141
|
break;
|
|
5973
6142
|
case 20:
|
|
5974
|
-
logger({
|
|
5975
|
-
destinationPath:
|
|
6143
|
+
logger == null || logger.info({
|
|
6144
|
+
destinationPath: "" + id,
|
|
5976
6145
|
statusCode: 404,
|
|
5977
6146
|
message: JSON.stringify({
|
|
5978
6147
|
message: "No tool outputs to submit",
|
|
@@ -6121,8 +6290,8 @@ function getAssistantAgentHandler(logger) {
|
|
|
6121
6290
|
});
|
|
6122
6291
|
case 9:
|
|
6123
6292
|
run = _context10.sent;
|
|
6124
|
-
logger({
|
|
6125
|
-
destinationPath:
|
|
6293
|
+
logger == null || logger.info({
|
|
6294
|
+
destinationPath: "" + id,
|
|
6126
6295
|
statusCode: 202,
|
|
6127
6296
|
message: JSON.stringify({
|
|
6128
6297
|
message: "Creating and polling run, tool choice required",
|
|
@@ -6522,87 +6691,136 @@ function _getAgent() {
|
|
|
6522
6691
|
toolChoice: ((_agent$model = agent.model) == null ? void 0 : _agent$model.toolChoice) || 'required'
|
|
6523
6692
|
},
|
|
6524
6693
|
tools: _toolMap,
|
|
6525
|
-
resultTool: resultTool
|
|
6526
|
-
}));
|
|
6527
|
-
case 23:
|
|
6528
|
-
return _context3.abrupt("return", createAgent({
|
|
6529
|
-
agent_instructions: agent.agent_instructions,
|
|
6530
|
-
model: {
|
|
6531
|
-
type: keyToModel[agent.model.provider],
|
|
6532
|
-
name: agent.model.name,
|
|
6533
|
-
toolChoice: ((_agent$model2 = agent.model) == null ? void 0 : _agent$model2.toolChoice) || 'required'
|
|
6534
|
-
},
|
|
6535
|
-
tools: _toolMap,
|
|
6536
|
-
resultTool: resultTool
|
|
6537
|
-
}));
|
|
6538
|
-
case 24:
|
|
6539
|
-
case "end":
|
|
6540
|
-
return _context3.stop();
|
|
6541
|
-
}
|
|
6542
|
-
}, _callee3);
|
|
6543
|
-
}));
|
|
6544
|
-
return _getAgent.apply(this, arguments);
|
|
6545
|
-
}
|
|
6546
|
-
|
|
6547
|
-
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
6548
|
-
function createFileLogger() {
|
|
6549
|
-
return function (log) {
|
|
6550
|
-
var fullPath = path.join(loggerPath, log.destinationPath);
|
|
6551
|
-
if (!existsSync(loggerPath)) {
|
|
6552
|
-
mkdirSync(loggerPath, {
|
|
6553
|
-
recursive: true
|
|
6554
|
-
});
|
|
6555
|
-
return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
6556
|
-
createdAt: new Date()
|
|
6557
|
-
})], null, 2));
|
|
6558
|
-
}
|
|
6559
|
-
if (!existsSync(fullPath)) {
|
|
6560
|
-
return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
6561
|
-
createdAt: new Date()
|
|
6562
|
-
})], null, 2));
|
|
6563
|
-
}
|
|
6564
|
-
var logs = JSON.parse(readFileSync(fullPath, 'utf-8'));
|
|
6565
|
-
logs.push(_extends({}, log, {
|
|
6566
|
-
createdAt: new Date()
|
|
6567
|
-
}));
|
|
6568
|
-
return writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
6569
|
-
};
|
|
6570
|
-
}
|
|
6571
|
-
function getUpstashLogs(_x) {
|
|
6572
|
-
return _getUpstashLogs.apply(this, arguments);
|
|
6573
|
-
}
|
|
6574
|
-
function _getUpstashLogs() {
|
|
6575
|
-
_getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
6576
|
-
var id, url, token, redis;
|
|
6577
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
6578
|
-
while (1) switch (_context.prev = _context.next) {
|
|
6579
|
-
case 0:
|
|
6580
|
-
id = _ref.id, url = _ref.url, token = _ref.token;
|
|
6581
|
-
redis = new Redis({
|
|
6582
|
-
url: url,
|
|
6583
|
-
token: token
|
|
6584
|
-
});
|
|
6585
|
-
return _context.abrupt("return", redis.lrange(id, 0, -1));
|
|
6586
|
-
case 3:
|
|
6694
|
+
resultTool: resultTool
|
|
6695
|
+
}));
|
|
6696
|
+
case 23:
|
|
6697
|
+
return _context3.abrupt("return", createAgent({
|
|
6698
|
+
agent_instructions: agent.agent_instructions,
|
|
6699
|
+
model: {
|
|
6700
|
+
type: keyToModel[agent.model.provider],
|
|
6701
|
+
name: agent.model.name,
|
|
6702
|
+
toolChoice: ((_agent$model2 = agent.model) == null ? void 0 : _agent$model2.toolChoice) || 'required'
|
|
6703
|
+
},
|
|
6704
|
+
tools: _toolMap,
|
|
6705
|
+
resultTool: resultTool
|
|
6706
|
+
}));
|
|
6707
|
+
case 24:
|
|
6587
6708
|
case "end":
|
|
6588
|
-
return
|
|
6709
|
+
return _context3.stop();
|
|
6589
6710
|
}
|
|
6590
|
-
},
|
|
6711
|
+
}, _callee3);
|
|
6591
6712
|
}));
|
|
6592
|
-
return
|
|
6713
|
+
return _getAgent.apply(this, arguments);
|
|
6593
6714
|
}
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
var
|
|
6598
|
-
|
|
6599
|
-
|
|
6715
|
+
|
|
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');
|
|
6723
|
+
}
|
|
6724
|
+
return path.join(MASTRA_APP_DIR, blueprintDirPath);
|
|
6725
|
+
};
|
|
6726
|
+
var blueprints = getBlueprintsSync({
|
|
6727
|
+
directoryPath: getBlueprintsDirPath()
|
|
6600
6728
|
});
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
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
|
+
});
|
|
6764
|
+
}
|
|
6765
|
+
};
|
|
6766
|
+
});
|
|
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
|
+
}()
|
|
6605
6822
|
};
|
|
6823
|
+
return api;
|
|
6606
6824
|
}
|
|
6607
6825
|
|
|
6608
6826
|
var Mastra = /*#__PURE__*/function () {
|
|
@@ -6622,7 +6840,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6622
6840
|
agentDirPath: '',
|
|
6623
6841
|
vectorProvider: []
|
|
6624
6842
|
};
|
|
6625
|
-
this.logger =
|
|
6843
|
+
this.logger = new Map();
|
|
6626
6844
|
this.config = void 0;
|
|
6627
6845
|
this.runBlueprint = /*#__PURE__*/function () {
|
|
6628
6846
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
@@ -6656,7 +6874,8 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6656
6874
|
blueprint: blueprint,
|
|
6657
6875
|
frameworkApis: frameworkApis,
|
|
6658
6876
|
frameworkEvents: frameworkEvents,
|
|
6659
|
-
ctx: ctx
|
|
6877
|
+
ctx: ctx,
|
|
6878
|
+
logger: _this.logger.get('WORKFLOW')
|
|
6660
6879
|
});
|
|
6661
6880
|
case 10:
|
|
6662
6881
|
case "end":
|
|
@@ -6671,9 +6890,10 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6671
6890
|
this.dataLayer = dataLayer;
|
|
6672
6891
|
this.vectorLayer = vectorLayer;
|
|
6673
6892
|
this.config = config;
|
|
6893
|
+
this.__backgroundTasks();
|
|
6674
6894
|
}
|
|
6675
6895
|
Mastra.init = function init(config) {
|
|
6676
|
-
var _config$logs, _config$
|
|
6896
|
+
var _config$logs, _config$logs4, _config$workflows$sys;
|
|
6677
6897
|
if (!config.db.uri) {
|
|
6678
6898
|
throw new Error('No database config/provider found');
|
|
6679
6899
|
}
|
|
@@ -6687,87 +6907,74 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6687
6907
|
dataLayer: dataLayer,
|
|
6688
6908
|
vectorLayer: vectorLayer
|
|
6689
6909
|
});
|
|
6690
|
-
var
|
|
6691
|
-
if (
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
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({
|
|
6698
6932
|
url: (_config$logs$config = config.logs.config) == null ? void 0 : _config$logs$config.url,
|
|
6699
6933
|
token: (_config$logs$config2 = config.logs.config) == null ? void 0 : _config$logs$config2.token
|
|
6700
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
|
+
});
|
|
6701
6965
|
}
|
|
6702
|
-
framework.attachLogger(
|
|
6966
|
+
framework.attachLogger({
|
|
6967
|
+
key: 'AGENT',
|
|
6968
|
+
logger: agentLogger
|
|
6969
|
+
});
|
|
6970
|
+
framework.attachLogger({
|
|
6971
|
+
key: 'WORKFLOW',
|
|
6972
|
+
logger: workflowLogger
|
|
6973
|
+
});
|
|
6703
6974
|
// Register integrations
|
|
6704
6975
|
config.integrations.forEach(function (integration) {
|
|
6705
6976
|
framework.__registerIntgeration(integration);
|
|
6706
6977
|
});
|
|
6707
|
-
// Register system apis
|
|
6708
|
-
framework.__registerApis({
|
|
6709
|
-
apis: [].concat(getVectorQueryApis({
|
|
6710
|
-
mastra: framework
|
|
6711
|
-
}), getAgentSystemApis({
|
|
6712
|
-
mastra: framework
|
|
6713
|
-
}), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
|
|
6714
|
-
return _extends({}, api, {
|
|
6715
|
-
integrationName: config.name
|
|
6716
|
-
});
|
|
6717
|
-
}), [{
|
|
6718
|
-
integrationName: config.name,
|
|
6719
|
-
type: 'trigger_event',
|
|
6720
|
-
label: 'Trigger event',
|
|
6721
|
-
// getSchemaOptions({ ctx }) {
|
|
6722
|
-
// const options = Promise.resolve({
|
|
6723
|
-
// event: {
|
|
6724
|
-
// options: Array.from(framework.globalEvents.values()).flatMap(
|
|
6725
|
-
// (eventRecord) =>
|
|
6726
|
-
// Object.values(eventRecord).map((event) => ({
|
|
6727
|
-
// value: event.key || event.label || '',
|
|
6728
|
-
// label: event.key || event.label || '',
|
|
6729
|
-
// })).filter((event) => event.value !== '')
|
|
6730
|
-
// ),
|
|
6731
|
-
// },
|
|
6732
|
-
// });
|
|
6733
|
-
// return options;
|
|
6734
|
-
// },
|
|
6735
|
-
description: 'Trigger event',
|
|
6736
|
-
schema: z.object({
|
|
6737
|
-
event: z.string(),
|
|
6738
|
-
data: z.record(z.any())
|
|
6739
|
-
}),
|
|
6740
|
-
executor: function () {
|
|
6741
|
-
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
|
|
6742
|
-
var data, ctx, event;
|
|
6743
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
6744
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
6745
|
-
case 0:
|
|
6746
|
-
data = _ref7.data, ctx = _ref7.ctx;
|
|
6747
|
-
event = data.event;
|
|
6748
|
-
_context2.next = 4;
|
|
6749
|
-
return framework.triggerEvent({
|
|
6750
|
-
key: event,
|
|
6751
|
-
data: data.data,
|
|
6752
|
-
user: {
|
|
6753
|
-
connectionId: ctx.connectionId
|
|
6754
|
-
}
|
|
6755
|
-
});
|
|
6756
|
-
case 4:
|
|
6757
|
-
return _context2.abrupt("return", _context2.sent);
|
|
6758
|
-
case 5:
|
|
6759
|
-
case "end":
|
|
6760
|
-
return _context2.stop();
|
|
6761
|
-
}
|
|
6762
|
-
}, _callee2);
|
|
6763
|
-
}));
|
|
6764
|
-
function executor(_x2) {
|
|
6765
|
-
return _executor.apply(this, arguments);
|
|
6766
|
-
}
|
|
6767
|
-
return executor;
|
|
6768
|
-
}()
|
|
6769
|
-
}])
|
|
6770
|
-
});
|
|
6771
6978
|
// Register System events
|
|
6772
6979
|
framework.__registerEvents({
|
|
6773
6980
|
events: config.workflows.systemEvents
|
|
@@ -6785,7 +6992,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6785
6992
|
},
|
|
6786
6993
|
VECTOR_SYNC: {
|
|
6787
6994
|
label: 'Sync vector data',
|
|
6788
|
-
description: '
|
|
6995
|
+
description: 'Generic vector sync',
|
|
6789
6996
|
schema: z.object({
|
|
6790
6997
|
vector_provider: z.string(),
|
|
6791
6998
|
entities: z.array(z.object({
|
|
@@ -6802,11 +7009,14 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6802
7009
|
},
|
|
6803
7010
|
VECTOR_INDEX_SYNC: {
|
|
6804
7011
|
label: 'Sync vector index',
|
|
6805
|
-
description: 'Sync vector index',
|
|
7012
|
+
description: 'Sync data to vector index',
|
|
6806
7013
|
schema: z.object({
|
|
6807
7014
|
data: z.array(z.object({
|
|
6808
7015
|
provider: z.string(),
|
|
6809
|
-
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()
|
|
6810
7020
|
}))
|
|
6811
7021
|
}),
|
|
6812
7022
|
handler: vectorIndexSync
|
|
@@ -6814,55 +7024,73 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6814
7024
|
},
|
|
6815
7025
|
integrationName: config.name
|
|
6816
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
|
+
});
|
|
6817
7043
|
// Register agent config
|
|
6818
7044
|
framework.agentsConfig = config.agents;
|
|
6819
7045
|
return framework;
|
|
6820
7046
|
};
|
|
6821
7047
|
var _proto = Mastra.prototype;
|
|
6822
|
-
_proto.attachLogger = function attachLogger(
|
|
6823
|
-
|
|
7048
|
+
_proto.attachLogger = function attachLogger(_ref7) {
|
|
7049
|
+
var key = _ref7.key,
|
|
7050
|
+
logger = _ref7.logger;
|
|
7051
|
+
this.logger.set(key, logger);
|
|
6824
7052
|
};
|
|
6825
7053
|
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
6826
|
-
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7054
|
+
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
|
|
6827
7055
|
var _this2 = this;
|
|
6828
7056
|
var context, ints, connectionChecks;
|
|
6829
|
-
return _regeneratorRuntime().wrap(function
|
|
6830
|
-
while (1) switch (
|
|
7057
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
7058
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
6831
7059
|
case 0:
|
|
6832
7060
|
context = _ref8.context;
|
|
6833
7061
|
ints = this.availableIntegrations();
|
|
6834
|
-
|
|
7062
|
+
_context3.next = 4;
|
|
6835
7063
|
return Promise.all(ints.map(/*#__PURE__*/function () {
|
|
6836
|
-
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7064
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref9) {
|
|
6837
7065
|
var integration, connection;
|
|
6838
|
-
return _regeneratorRuntime().wrap(function
|
|
6839
|
-
while (1) switch (
|
|
7066
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
7067
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
6840
7068
|
case 0:
|
|
6841
7069
|
integration = _ref9.integration;
|
|
6842
|
-
|
|
7070
|
+
_context2.next = 3;
|
|
6843
7071
|
return _this2.dataLayer.getConnection({
|
|
6844
7072
|
connectionId: context.connectionId,
|
|
6845
7073
|
name: integration.name
|
|
6846
7074
|
});
|
|
6847
7075
|
case 3:
|
|
6848
|
-
connection =
|
|
6849
|
-
return
|
|
7076
|
+
connection = _context2.sent;
|
|
7077
|
+
return _context2.abrupt("return", {
|
|
6850
7078
|
integration: integration,
|
|
6851
7079
|
connected: !!connection
|
|
6852
7080
|
});
|
|
6853
7081
|
case 5:
|
|
6854
7082
|
case "end":
|
|
6855
|
-
return
|
|
7083
|
+
return _context2.stop();
|
|
6856
7084
|
}
|
|
6857
|
-
},
|
|
7085
|
+
}, _callee2);
|
|
6858
7086
|
}));
|
|
6859
|
-
return function (
|
|
7087
|
+
return function (_x3) {
|
|
6860
7088
|
return _ref10.apply(this, arguments);
|
|
6861
7089
|
};
|
|
6862
7090
|
}()));
|
|
6863
7091
|
case 4:
|
|
6864
|
-
connectionChecks =
|
|
6865
|
-
return
|
|
7092
|
+
connectionChecks = _context3.sent;
|
|
7093
|
+
return _context3.abrupt("return", connectionChecks.filter(function (_ref11) {
|
|
6866
7094
|
var connected = _ref11.connected;
|
|
6867
7095
|
return connected;
|
|
6868
7096
|
}).map(function (_ref12) {
|
|
@@ -6871,11 +7099,11 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6871
7099
|
}));
|
|
6872
7100
|
case 6:
|
|
6873
7101
|
case "end":
|
|
6874
|
-
return
|
|
7102
|
+
return _context3.stop();
|
|
6875
7103
|
}
|
|
6876
|
-
},
|
|
7104
|
+
}, _callee3, this);
|
|
6877
7105
|
}));
|
|
6878
|
-
function connectedIntegrations(
|
|
7106
|
+
function connectedIntegrations(_x2) {
|
|
6879
7107
|
return _connectedIntegrations.apply(this, arguments);
|
|
6880
7108
|
}
|
|
6881
7109
|
return connectedIntegrations;
|
|
@@ -6889,14 +7117,14 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6889
7117
|
definition.corePresets = {
|
|
6890
7118
|
redirectURI: router.makeRedirectURI()
|
|
6891
7119
|
};
|
|
6892
|
-
this.integrations.set(name, definition);
|
|
6893
7120
|
definition.registerEvents();
|
|
7121
|
+
definition.registerApis();
|
|
7122
|
+
definition._convertApiClientToSystemApis();
|
|
7123
|
+
this.integrations.set(name, definition);
|
|
6894
7124
|
this.__registerEvents({
|
|
6895
7125
|
events: definition.getEvents(),
|
|
6896
7126
|
integrationName: name
|
|
6897
7127
|
});
|
|
6898
|
-
definition.registerApis();
|
|
6899
|
-
definition._convertApiClientToSystemApis();
|
|
6900
7128
|
this.__registerApis({
|
|
6901
7129
|
apis: Object.values(definition.getApis()),
|
|
6902
7130
|
integrationName: name
|
|
@@ -7025,20 +7253,20 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7025
7253
|
return _int.getAuthenticator();
|
|
7026
7254
|
};
|
|
7027
7255
|
_proto.connectIntegrationByCredential = /*#__PURE__*/function () {
|
|
7028
|
-
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7256
|
+
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref18) {
|
|
7029
7257
|
var name, connectionId, credential, authenticator, integration;
|
|
7030
|
-
return _regeneratorRuntime().wrap(function
|
|
7031
|
-
while (1) switch (
|
|
7258
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
7259
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
7032
7260
|
case 0:
|
|
7033
7261
|
name = _ref18.name, connectionId = _ref18.connectionId, credential = _ref18.credential;
|
|
7034
7262
|
authenticator = this.authenticator(name);
|
|
7035
7263
|
if (authenticator) {
|
|
7036
|
-
|
|
7264
|
+
_context4.next = 4;
|
|
7037
7265
|
break;
|
|
7038
7266
|
}
|
|
7039
7267
|
throw new Error("Authenticator for " + name + " not found");
|
|
7040
7268
|
case 4:
|
|
7041
|
-
|
|
7269
|
+
_context4.next = 6;
|
|
7042
7270
|
return authenticator.dataAccess.createConnection({
|
|
7043
7271
|
connection: {
|
|
7044
7272
|
name: name,
|
|
@@ -7047,112 +7275,112 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7047
7275
|
credential: credential
|
|
7048
7276
|
});
|
|
7049
7277
|
case 6:
|
|
7050
|
-
integration =
|
|
7278
|
+
integration = _context4.sent;
|
|
7051
7279
|
if (!authenticator.onConnectionCreated) {
|
|
7052
|
-
|
|
7280
|
+
_context4.next = 10;
|
|
7053
7281
|
break;
|
|
7054
7282
|
}
|
|
7055
|
-
|
|
7283
|
+
_context4.next = 10;
|
|
7056
7284
|
return authenticator.onConnectionCreated(integration, credential);
|
|
7057
7285
|
case 10:
|
|
7058
7286
|
case "end":
|
|
7059
|
-
return
|
|
7287
|
+
return _context4.stop();
|
|
7060
7288
|
}
|
|
7061
|
-
},
|
|
7289
|
+
}, _callee4, this);
|
|
7062
7290
|
}));
|
|
7063
|
-
function connectIntegrationByCredential(
|
|
7291
|
+
function connectIntegrationByCredential(_x4) {
|
|
7064
7292
|
return _connectIntegrationByCredential.apply(this, arguments);
|
|
7065
7293
|
}
|
|
7066
7294
|
return connectIntegrationByCredential;
|
|
7067
7295
|
}();
|
|
7068
7296
|
_proto.disconnectIntegration = /*#__PURE__*/function () {
|
|
7069
|
-
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7297
|
+
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref19) {
|
|
7070
7298
|
var _yield$this$dataLayer;
|
|
7071
7299
|
var name, connectionId, integration, k_id, authenticator;
|
|
7072
|
-
return _regeneratorRuntime().wrap(function
|
|
7073
|
-
while (1) switch (
|
|
7300
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
7301
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
7074
7302
|
case 0:
|
|
7075
7303
|
name = _ref19.name, connectionId = _ref19.connectionId;
|
|
7076
7304
|
integration = this.getIntegration(name);
|
|
7077
|
-
|
|
7305
|
+
_context5.next = 4;
|
|
7078
7306
|
return this.dataLayer.getConnection({
|
|
7079
7307
|
name: name,
|
|
7080
7308
|
connectionId: connectionId
|
|
7081
7309
|
});
|
|
7082
7310
|
case 4:
|
|
7083
|
-
|
|
7084
|
-
if (!(
|
|
7085
|
-
|
|
7311
|
+
_context5.t0 = _yield$this$dataLayer = _context5.sent;
|
|
7312
|
+
if (!(_context5.t0 == null)) {
|
|
7313
|
+
_context5.next = 9;
|
|
7086
7314
|
break;
|
|
7087
7315
|
}
|
|
7088
|
-
|
|
7089
|
-
|
|
7316
|
+
_context5.t1 = void 0;
|
|
7317
|
+
_context5.next = 10;
|
|
7090
7318
|
break;
|
|
7091
7319
|
case 9:
|
|
7092
|
-
|
|
7320
|
+
_context5.t1 = _yield$this$dataLayer.id;
|
|
7093
7321
|
case 10:
|
|
7094
|
-
k_id =
|
|
7322
|
+
k_id = _context5.t1;
|
|
7095
7323
|
if (k_id) {
|
|
7096
|
-
|
|
7324
|
+
_context5.next = 13;
|
|
7097
7325
|
break;
|
|
7098
7326
|
}
|
|
7099
7327
|
throw new Error("No connection found for " + name);
|
|
7100
7328
|
case 13:
|
|
7101
7329
|
if (!(integration != null && integration.dataLayer)) {
|
|
7102
|
-
|
|
7330
|
+
_context5.next = 16;
|
|
7103
7331
|
break;
|
|
7104
7332
|
}
|
|
7105
|
-
|
|
7333
|
+
_context5.next = 16;
|
|
7106
7334
|
return integration.onDisconnect({
|
|
7107
7335
|
connectionId: connectionId
|
|
7108
7336
|
});
|
|
7109
7337
|
case 16:
|
|
7110
7338
|
if (!((integration == null ? void 0 : integration.config.authType) === IntegrationCredentialType.OAUTH)) {
|
|
7111
|
-
|
|
7339
|
+
_context5.next = 20;
|
|
7112
7340
|
break;
|
|
7113
7341
|
}
|
|
7114
7342
|
authenticator = this.authenticator(name);
|
|
7115
|
-
|
|
7343
|
+
_context5.next = 20;
|
|
7116
7344
|
return authenticator.revokeAuth({
|
|
7117
7345
|
k_id: k_id
|
|
7118
7346
|
});
|
|
7119
7347
|
case 20:
|
|
7120
|
-
|
|
7348
|
+
_context5.next = 22;
|
|
7121
7349
|
return this.dataLayer.deleteConnection({
|
|
7122
7350
|
connectionId: connectionId
|
|
7123
7351
|
});
|
|
7124
7352
|
case 22:
|
|
7125
7353
|
case "end":
|
|
7126
|
-
return
|
|
7354
|
+
return _context5.stop();
|
|
7127
7355
|
}
|
|
7128
|
-
},
|
|
7356
|
+
}, _callee5, this);
|
|
7129
7357
|
}));
|
|
7130
|
-
function disconnectIntegration(
|
|
7358
|
+
function disconnectIntegration(_x5) {
|
|
7131
7359
|
return _disconnectIntegration.apply(this, arguments);
|
|
7132
7360
|
}
|
|
7133
7361
|
return disconnectIntegration;
|
|
7134
7362
|
}();
|
|
7135
7363
|
_proto.createSystemConnection = /*#__PURE__*/function () {
|
|
7136
|
-
var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7364
|
+
var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
7137
7365
|
var systemConnectionId, existingSystemConnection;
|
|
7138
|
-
return _regeneratorRuntime().wrap(function
|
|
7139
|
-
while (1) switch (
|
|
7366
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
7367
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
7140
7368
|
case 0:
|
|
7141
7369
|
systemConnectionId = 'SYSTEM';
|
|
7142
|
-
|
|
7370
|
+
_context6.next = 3;
|
|
7143
7371
|
return this.dataLayer.getConnection({
|
|
7144
7372
|
connectionId: systemConnectionId,
|
|
7145
7373
|
name: this.config.name
|
|
7146
7374
|
});
|
|
7147
7375
|
case 3:
|
|
7148
|
-
existingSystemConnection =
|
|
7376
|
+
existingSystemConnection = _context6.sent;
|
|
7149
7377
|
if (!existingSystemConnection) {
|
|
7150
|
-
|
|
7378
|
+
_context6.next = 6;
|
|
7151
7379
|
break;
|
|
7152
7380
|
}
|
|
7153
|
-
return
|
|
7381
|
+
return _context6.abrupt("return", existingSystemConnection);
|
|
7154
7382
|
case 6:
|
|
7155
|
-
return
|
|
7383
|
+
return _context6.abrupt("return", this.dataLayer.createConnection({
|
|
7156
7384
|
connection: {
|
|
7157
7385
|
connectionId: systemConnectionId,
|
|
7158
7386
|
name: this.config.name
|
|
@@ -7164,9 +7392,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7164
7392
|
}));
|
|
7165
7393
|
case 7:
|
|
7166
7394
|
case "end":
|
|
7167
|
-
return
|
|
7395
|
+
return _context6.stop();
|
|
7168
7396
|
}
|
|
7169
|
-
},
|
|
7397
|
+
}, _callee6, this);
|
|
7170
7398
|
}));
|
|
7171
7399
|
function createSystemConnection() {
|
|
7172
7400
|
return _createSystemConnection.apply(this, arguments);
|
|
@@ -7174,71 +7402,71 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7174
7402
|
return createSystemConnection;
|
|
7175
7403
|
}();
|
|
7176
7404
|
_proto.callApi = /*#__PURE__*/function () {
|
|
7177
|
-
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7405
|
+
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref20) {
|
|
7178
7406
|
var _int2$getApis;
|
|
7179
7407
|
var _ref20$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
|
|
7180
|
-
return _regeneratorRuntime().wrap(function
|
|
7181
|
-
while (1) switch (
|
|
7408
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
7409
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
7182
7410
|
case 0:
|
|
7183
7411
|
_ref20$integrationNam = _ref20.integrationName, integrationName = _ref20$integrationNam === void 0 ? this.config.name : _ref20$integrationNam, api = _ref20.api, payload = _ref20.payload;
|
|
7184
7412
|
if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
|
|
7185
|
-
|
|
7413
|
+
_context7.next = 6;
|
|
7186
7414
|
break;
|
|
7187
7415
|
}
|
|
7188
7416
|
_apiExecutor = (_this$globalApis$get = this.globalApis.get(this.config.name)) == null ? void 0 : _this$globalApis$get[api];
|
|
7189
7417
|
if (_apiExecutor) {
|
|
7190
|
-
|
|
7418
|
+
_context7.next = 5;
|
|
7191
7419
|
break;
|
|
7192
7420
|
}
|
|
7193
7421
|
throw new Error("No global api exists for " + api);
|
|
7194
7422
|
case 5:
|
|
7195
|
-
return
|
|
7423
|
+
return _context7.abrupt("return", _apiExecutor.executor(payload));
|
|
7196
7424
|
case 6:
|
|
7197
7425
|
_int2 = this.getIntegration(integrationName);
|
|
7198
7426
|
if (_int2) {
|
|
7199
|
-
|
|
7427
|
+
_context7.next = 9;
|
|
7200
7428
|
break;
|
|
7201
7429
|
}
|
|
7202
7430
|
throw new Error("No Integration exists for " + integrationName);
|
|
7203
7431
|
case 9:
|
|
7204
7432
|
apiExecutor = (_int2$getApis = _int2.getApis()) == null ? void 0 : _int2$getApis[api];
|
|
7205
7433
|
if (apiExecutor) {
|
|
7206
|
-
|
|
7434
|
+
_context7.next = 12;
|
|
7207
7435
|
break;
|
|
7208
7436
|
}
|
|
7209
7437
|
throw new Error("No api exists for " + api + " in " + integrationName);
|
|
7210
7438
|
case 12:
|
|
7211
|
-
return
|
|
7439
|
+
return _context7.abrupt("return", apiExecutor.executor(payload));
|
|
7212
7440
|
case 13:
|
|
7213
7441
|
case "end":
|
|
7214
|
-
return
|
|
7442
|
+
return _context7.stop();
|
|
7215
7443
|
}
|
|
7216
|
-
},
|
|
7444
|
+
}, _callee7, this);
|
|
7217
7445
|
}));
|
|
7218
|
-
function callApi(
|
|
7446
|
+
function callApi(_x6) {
|
|
7219
7447
|
return _callApi.apply(this, arguments);
|
|
7220
7448
|
}
|
|
7221
7449
|
return callApi;
|
|
7222
7450
|
}();
|
|
7223
7451
|
_proto.subscribeEvent = /*#__PURE__*/function () {
|
|
7224
|
-
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7452
|
+
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
|
|
7225
7453
|
var _this$config$runner$u, _this$config$runner, _ref22, _this$config$runner$s, _this$config$runner2;
|
|
7226
7454
|
var id, _ref21$interval, interval, _ref21$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
|
|
7227
|
-
return _regeneratorRuntime().wrap(function
|
|
7228
|
-
while (1) switch (
|
|
7455
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
7456
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
7229
7457
|
case 0:
|
|
7230
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;
|
|
7231
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;
|
|
7232
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';
|
|
7233
7461
|
startTime = Date.now();
|
|
7234
7462
|
_poll = /*#__PURE__*/function () {
|
|
7235
|
-
var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7463
|
+
var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
7236
7464
|
var response, obj, data, error, lastRun, elapsedTime;
|
|
7237
|
-
return _regeneratorRuntime().wrap(function
|
|
7238
|
-
while (1) switch (
|
|
7465
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
7466
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
7239
7467
|
case 0:
|
|
7240
|
-
|
|
7241
|
-
|
|
7468
|
+
_context8.prev = 0;
|
|
7469
|
+
_context8.next = 3;
|
|
7242
7470
|
return fetch(inngestApiUrl + "/v1/events/" + id + "/runs", {
|
|
7243
7471
|
method: 'GET',
|
|
7244
7472
|
headers: {
|
|
@@ -7247,117 +7475,117 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7247
7475
|
}
|
|
7248
7476
|
});
|
|
7249
7477
|
case 3:
|
|
7250
|
-
response =
|
|
7478
|
+
response = _context8.sent;
|
|
7251
7479
|
console.log("Polling for event " + id + "...", response.ok);
|
|
7252
7480
|
if (!response.ok) {
|
|
7253
|
-
|
|
7481
|
+
_context8.next = 28;
|
|
7254
7482
|
break;
|
|
7255
7483
|
}
|
|
7256
|
-
|
|
7484
|
+
_context8.next = 8;
|
|
7257
7485
|
return response.json();
|
|
7258
7486
|
case 8:
|
|
7259
|
-
obj =
|
|
7487
|
+
obj = _context8.sent;
|
|
7260
7488
|
console.log({
|
|
7261
7489
|
obj: obj
|
|
7262
7490
|
});
|
|
7263
7491
|
data = obj.data, error = obj.error;
|
|
7264
7492
|
console.log("Got data for event " + id + "...", data, error);
|
|
7265
7493
|
if (!error) {
|
|
7266
|
-
|
|
7494
|
+
_context8.next = 15;
|
|
7267
7495
|
break;
|
|
7268
7496
|
}
|
|
7269
7497
|
console.error(error);
|
|
7270
|
-
return
|
|
7498
|
+
return _context8.abrupt("return", null);
|
|
7271
7499
|
case 15:
|
|
7272
7500
|
if (!((data == null ? void 0 : data.length) === 0)) {
|
|
7273
|
-
|
|
7501
|
+
_context8.next = 19;
|
|
7274
7502
|
break;
|
|
7275
7503
|
}
|
|
7276
|
-
|
|
7504
|
+
_context8.next = 18;
|
|
7277
7505
|
return new Promise(function (resolve) {
|
|
7278
7506
|
return setTimeout(resolve, interval);
|
|
7279
7507
|
});
|
|
7280
7508
|
case 18:
|
|
7281
|
-
return
|
|
7509
|
+
return _context8.abrupt("return", _poll());
|
|
7282
7510
|
case 19:
|
|
7283
7511
|
lastRun = data == null ? void 0 : data[0];
|
|
7284
7512
|
console.log(lastRun);
|
|
7285
7513
|
if (lastRun) {
|
|
7286
|
-
|
|
7514
|
+
_context8.next = 23;
|
|
7287
7515
|
break;
|
|
7288
7516
|
}
|
|
7289
|
-
return
|
|
7517
|
+
return _context8.abrupt("return", null);
|
|
7290
7518
|
case 23:
|
|
7291
7519
|
if (!(lastRun.status === 'Running')) {
|
|
7292
|
-
|
|
7520
|
+
_context8.next = 27;
|
|
7293
7521
|
break;
|
|
7294
7522
|
}
|
|
7295
|
-
|
|
7523
|
+
_context8.next = 26;
|
|
7296
7524
|
return new Promise(function (resolve) {
|
|
7297
7525
|
return setTimeout(resolve, interval);
|
|
7298
7526
|
});
|
|
7299
7527
|
case 26:
|
|
7300
|
-
return
|
|
7528
|
+
return _context8.abrupt("return", _poll());
|
|
7301
7529
|
case 27:
|
|
7302
|
-
return
|
|
7530
|
+
return _context8.abrupt("return", {
|
|
7303
7531
|
status: lastRun.status,
|
|
7304
7532
|
startedAt: lastRun.run_started_at,
|
|
7305
7533
|
endedAt: lastRun.ended_at
|
|
7306
7534
|
});
|
|
7307
7535
|
case 28:
|
|
7308
|
-
|
|
7536
|
+
_context8.next = 33;
|
|
7309
7537
|
break;
|
|
7310
7538
|
case 30:
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
console.error("Request failed: " +
|
|
7539
|
+
_context8.prev = 30;
|
|
7540
|
+
_context8.t0 = _context8["catch"](0);
|
|
7541
|
+
console.error("Request failed: " + _context8.t0);
|
|
7314
7542
|
case 33:
|
|
7315
7543
|
// Check if timeout has been reached
|
|
7316
7544
|
elapsedTime = Date.now() - startTime;
|
|
7317
7545
|
if (!(elapsedTime >= timeout)) {
|
|
7318
|
-
|
|
7546
|
+
_context8.next = 37;
|
|
7319
7547
|
break;
|
|
7320
7548
|
}
|
|
7321
7549
|
console.log('Polling timeout reached.');
|
|
7322
|
-
return
|
|
7550
|
+
return _context8.abrupt("return", null);
|
|
7323
7551
|
case 37:
|
|
7324
|
-
|
|
7552
|
+
_context8.next = 39;
|
|
7325
7553
|
return new Promise(function (resolve) {
|
|
7326
7554
|
return setTimeout(resolve, interval);
|
|
7327
7555
|
});
|
|
7328
7556
|
case 39:
|
|
7329
|
-
return
|
|
7557
|
+
return _context8.abrupt("return", _poll());
|
|
7330
7558
|
case 40:
|
|
7331
7559
|
case "end":
|
|
7332
|
-
return
|
|
7560
|
+
return _context8.stop();
|
|
7333
7561
|
}
|
|
7334
|
-
},
|
|
7562
|
+
}, _callee8, null, [[0, 30]]);
|
|
7335
7563
|
}));
|
|
7336
7564
|
return function poll() {
|
|
7337
7565
|
return _ref23.apply(this, arguments);
|
|
7338
7566
|
};
|
|
7339
7567
|
}();
|
|
7340
|
-
return
|
|
7568
|
+
return _context9.abrupt("return", _poll());
|
|
7341
7569
|
case 6:
|
|
7342
7570
|
case "end":
|
|
7343
|
-
return
|
|
7571
|
+
return _context9.stop();
|
|
7344
7572
|
}
|
|
7345
|
-
},
|
|
7573
|
+
}, _callee9, this);
|
|
7346
7574
|
}));
|
|
7347
|
-
function subscribeEvent(
|
|
7575
|
+
function subscribeEvent(_x7) {
|
|
7348
7576
|
return _subscribeEvent.apply(this, arguments);
|
|
7349
7577
|
}
|
|
7350
7578
|
return subscribeEvent;
|
|
7351
7579
|
}();
|
|
7352
7580
|
_proto.triggerEvent = /*#__PURE__*/function () {
|
|
7353
|
-
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7581
|
+
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref24) {
|
|
7354
7582
|
var _this4 = this;
|
|
7355
7583
|
var key, data, user, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
|
|
7356
|
-
return _regeneratorRuntime().wrap(function
|
|
7357
|
-
while (1) switch (
|
|
7584
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
7585
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
7358
7586
|
case 0:
|
|
7359
7587
|
key = _ref24.key, data = _ref24.data, user = _ref24.user, integrationName = _ref24.integrationName;
|
|
7360
|
-
|
|
7588
|
+
_context12.prev = 1;
|
|
7361
7589
|
returnObj = {
|
|
7362
7590
|
event: {}
|
|
7363
7591
|
};
|
|
@@ -7369,53 +7597,53 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7369
7597
|
}, {});
|
|
7370
7598
|
}
|
|
7371
7599
|
if (integrationEvents) {
|
|
7372
|
-
|
|
7600
|
+
_context12.next = 6;
|
|
7373
7601
|
break;
|
|
7374
7602
|
}
|
|
7375
7603
|
throw new Error("No integration events found");
|
|
7376
7604
|
case 6:
|
|
7377
7605
|
integrationEvent = integrationEvents[key];
|
|
7378
7606
|
if (integrationEvent) {
|
|
7379
|
-
|
|
7607
|
+
_context12.next = 9;
|
|
7380
7608
|
break;
|
|
7381
7609
|
}
|
|
7382
7610
|
throw new Error("No event exists for " + key + " in " + (integrationName || 'system'));
|
|
7383
7611
|
case 9:
|
|
7384
|
-
|
|
7612
|
+
_context12.next = 11;
|
|
7385
7613
|
return client$1.send({
|
|
7386
7614
|
name: key,
|
|
7387
7615
|
data: data,
|
|
7388
7616
|
user: user
|
|
7389
7617
|
});
|
|
7390
7618
|
case 11:
|
|
7391
|
-
event =
|
|
7619
|
+
event = _context12.sent;
|
|
7392
7620
|
returnObj['event'] = _extends({}, event, {
|
|
7393
7621
|
subscribe: function () {
|
|
7394
|
-
var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7622
|
+
var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp) {
|
|
7395
7623
|
var _event$ids;
|
|
7396
7624
|
var _ref25, interval, timeout;
|
|
7397
|
-
return _regeneratorRuntime().wrap(function
|
|
7398
|
-
while (1) switch (
|
|
7625
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
7626
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
7399
7627
|
case 0:
|
|
7400
7628
|
_ref25 = _temp === void 0 ? {} : _temp, interval = _ref25.interval, timeout = _ref25.timeout;
|
|
7401
|
-
return
|
|
7629
|
+
return _context10.abrupt("return", _this4.subscribeEvent({
|
|
7402
7630
|
id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
|
|
7403
7631
|
interval: interval,
|
|
7404
7632
|
timeout: timeout
|
|
7405
7633
|
}));
|
|
7406
7634
|
case 2:
|
|
7407
7635
|
case "end":
|
|
7408
|
-
return
|
|
7636
|
+
return _context10.stop();
|
|
7409
7637
|
}
|
|
7410
|
-
},
|
|
7638
|
+
}, _callee10);
|
|
7411
7639
|
}));
|
|
7412
|
-
function subscribe(
|
|
7640
|
+
function subscribe(_x9) {
|
|
7413
7641
|
return _subscribe.apply(this, arguments);
|
|
7414
7642
|
}
|
|
7415
7643
|
return subscribe;
|
|
7416
7644
|
}()
|
|
7417
7645
|
});
|
|
7418
|
-
|
|
7646
|
+
_context12.next = 15;
|
|
7419
7647
|
return client$1.send({
|
|
7420
7648
|
name: 'workflow/run-automations',
|
|
7421
7649
|
data: {
|
|
@@ -7425,45 +7653,45 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7425
7653
|
user: user
|
|
7426
7654
|
});
|
|
7427
7655
|
case 15:
|
|
7428
|
-
workflowEvent =
|
|
7656
|
+
workflowEvent = _context12.sent;
|
|
7429
7657
|
returnObj['workflowEvent'] = _extends({}, workflowEvent, {
|
|
7430
7658
|
subscribe: function () {
|
|
7431
|
-
var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7659
|
+
var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp2) {
|
|
7432
7660
|
var _workflowEvent$ids;
|
|
7433
7661
|
var _ref26, interval, timeout;
|
|
7434
|
-
return _regeneratorRuntime().wrap(function
|
|
7435
|
-
while (1) switch (
|
|
7662
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
7663
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
7436
7664
|
case 0:
|
|
7437
7665
|
_ref26 = _temp2 === void 0 ? {} : _temp2, interval = _ref26.interval, timeout = _ref26.timeout;
|
|
7438
|
-
return
|
|
7666
|
+
return _context11.abrupt("return", _this4.subscribeEvent({
|
|
7439
7667
|
id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
|
|
7440
7668
|
interval: interval,
|
|
7441
7669
|
timeout: timeout
|
|
7442
7670
|
}));
|
|
7443
7671
|
case 2:
|
|
7444
7672
|
case "end":
|
|
7445
|
-
return
|
|
7673
|
+
return _context11.stop();
|
|
7446
7674
|
}
|
|
7447
|
-
},
|
|
7675
|
+
}, _callee11);
|
|
7448
7676
|
}));
|
|
7449
|
-
function subscribe(
|
|
7677
|
+
function subscribe(_x10) {
|
|
7450
7678
|
return _subscribe2.apply(this, arguments);
|
|
7451
7679
|
}
|
|
7452
7680
|
return subscribe;
|
|
7453
7681
|
}()
|
|
7454
7682
|
});
|
|
7455
|
-
return
|
|
7683
|
+
return _context12.abrupt("return", returnObj);
|
|
7456
7684
|
case 20:
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
throw new Error("Error triggering event: " +
|
|
7685
|
+
_context12.prev = 20;
|
|
7686
|
+
_context12.t0 = _context12["catch"](1);
|
|
7687
|
+
throw new Error("Error triggering event: " + _context12.t0);
|
|
7460
7688
|
case 23:
|
|
7461
7689
|
case "end":
|
|
7462
|
-
return
|
|
7690
|
+
return _context12.stop();
|
|
7463
7691
|
}
|
|
7464
|
-
},
|
|
7692
|
+
}, _callee12, this, [[1, 20]]);
|
|
7465
7693
|
}));
|
|
7466
|
-
function triggerEvent(
|
|
7694
|
+
function triggerEvent(_x8) {
|
|
7467
7695
|
return _triggerEvent.apply(this, arguments);
|
|
7468
7696
|
}
|
|
7469
7697
|
return triggerEvent;
|
|
@@ -7472,26 +7700,26 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7472
7700
|
_proto.triggerSystemEvent =
|
|
7473
7701
|
/*#__PURE__*/
|
|
7474
7702
|
function () {
|
|
7475
|
-
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7703
|
+
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref27) {
|
|
7476
7704
|
var key, data, user, event, systemEvent;
|
|
7477
|
-
return _regeneratorRuntime().wrap(function
|
|
7478
|
-
while (1) switch (
|
|
7705
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
7706
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
7479
7707
|
case 0:
|
|
7480
7708
|
key = _ref27.key, data = _ref27.data, user = _ref27.user;
|
|
7481
|
-
|
|
7709
|
+
_context13.next = 3;
|
|
7482
7710
|
return client$1.send({
|
|
7483
7711
|
name: key,
|
|
7484
7712
|
data: data,
|
|
7485
7713
|
user: user
|
|
7486
7714
|
});
|
|
7487
7715
|
case 3:
|
|
7488
|
-
event =
|
|
7716
|
+
event = _context13.sent;
|
|
7489
7717
|
systemEvent = this.getSystemEvents()[key];
|
|
7490
7718
|
if (!systemEvent) {
|
|
7491
|
-
|
|
7719
|
+
_context13.next = 8;
|
|
7492
7720
|
break;
|
|
7493
7721
|
}
|
|
7494
|
-
|
|
7722
|
+
_context13.next = 8;
|
|
7495
7723
|
return client$1.send({
|
|
7496
7724
|
name: 'workflow/run-automations',
|
|
7497
7725
|
data: {
|
|
@@ -7501,14 +7729,14 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7501
7729
|
user: user
|
|
7502
7730
|
});
|
|
7503
7731
|
case 8:
|
|
7504
|
-
return
|
|
7732
|
+
return _context13.abrupt("return", event);
|
|
7505
7733
|
case 9:
|
|
7506
7734
|
case "end":
|
|
7507
|
-
return
|
|
7735
|
+
return _context13.stop();
|
|
7508
7736
|
}
|
|
7509
|
-
},
|
|
7737
|
+
}, _callee13, this);
|
|
7510
7738
|
}));
|
|
7511
|
-
function triggerSystemEvent(
|
|
7739
|
+
function triggerSystemEvent(_x11) {
|
|
7512
7740
|
return _triggerSystemEvent.apply(this, arguments);
|
|
7513
7741
|
}
|
|
7514
7742
|
return triggerSystemEvent;
|
|
@@ -7530,7 +7758,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7530
7758
|
};
|
|
7531
7759
|
var registerRoutes = function registerRoutes() {
|
|
7532
7760
|
var _registry;
|
|
7533
|
-
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);
|
|
7534
7762
|
return function (req) {
|
|
7535
7763
|
var route = req.nextUrl.pathname;
|
|
7536
7764
|
if (req.nextUrl.pathname in registry) {
|
|
@@ -7549,42 +7777,62 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7549
7777
|
};
|
|
7550
7778
|
};
|
|
7551
7779
|
_proto.getAgent = /*#__PURE__*/function () {
|
|
7552
|
-
var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7780
|
+
var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref29) {
|
|
7553
7781
|
var connectionId, agentId, agentBlueprint, arrMap, finalApis;
|
|
7554
|
-
return _regeneratorRuntime().wrap(function
|
|
7555
|
-
while (1) switch (
|
|
7782
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
7783
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
7556
7784
|
case 0:
|
|
7557
7785
|
connectionId = _ref29.connectionId, agentId = _ref29.agentId;
|
|
7558
|
-
|
|
7786
|
+
_context14.next = 3;
|
|
7559
7787
|
return getAgentBlueprint({
|
|
7560
7788
|
agentDir: this.config.agents.agentDirPath,
|
|
7561
7789
|
agentId: agentId
|
|
7562
7790
|
});
|
|
7563
7791
|
case 3:
|
|
7564
|
-
agentBlueprint =
|
|
7792
|
+
agentBlueprint = _context14.sent;
|
|
7565
7793
|
arrMap = Array.from(this.getApis());
|
|
7566
7794
|
finalApis = arrMap.reduce(function (acc, _ref30) {
|
|
7567
7795
|
var v = _ref30[1];
|
|
7568
7796
|
return _extends({}, acc, v);
|
|
7569
7797
|
}, {});
|
|
7570
7798
|
console.log('got finalApis===');
|
|
7571
|
-
return
|
|
7799
|
+
return _context14.abrupt("return", getAgent({
|
|
7572
7800
|
connectionId: connectionId,
|
|
7573
7801
|
agent: agentBlueprint,
|
|
7574
7802
|
apis: finalApis,
|
|
7575
|
-
logger: this.logger
|
|
7803
|
+
logger: this.logger.get('AGENT')
|
|
7576
7804
|
}));
|
|
7577
7805
|
case 8:
|
|
7578
7806
|
case "end":
|
|
7579
|
-
return
|
|
7807
|
+
return _context14.stop();
|
|
7580
7808
|
}
|
|
7581
|
-
},
|
|
7809
|
+
}, _callee14, this);
|
|
7582
7810
|
}));
|
|
7583
|
-
function getAgent$1(
|
|
7811
|
+
function getAgent$1(_x12) {
|
|
7584
7812
|
return _getAgent2.apply(this, arguments);
|
|
7585
7813
|
}
|
|
7586
7814
|
return getAgent$1;
|
|
7587
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
|
+
}();
|
|
7588
7836
|
return _createClass(Mastra, [{
|
|
7589
7837
|
key: "routes",
|
|
7590
7838
|
get: function get() {
|
|
@@ -7593,7 +7841,8 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7593
7841
|
connect: '/connect',
|
|
7594
7842
|
callback: '/connect/callback',
|
|
7595
7843
|
inngest: '/inngest',
|
|
7596
|
-
webhook: '/webhook'
|
|
7844
|
+
webhook: '/webhook',
|
|
7845
|
+
cron: '/cron'
|
|
7597
7846
|
};
|
|
7598
7847
|
return Object.entries(registry).reduce(function (acc, _ref31) {
|
|
7599
7848
|
var _extends5;
|
|
@@ -7606,13 +7855,37 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7606
7855
|
key: "openAIAssistant",
|
|
7607
7856
|
get: function get() {
|
|
7608
7857
|
return {
|
|
7609
|
-
createAssistantAgent: createAssistantAgentHandler(this.logger),
|
|
7610
|
-
getAssistantAgent: getAssistantAgentHandler(this.logger),
|
|
7611
|
-
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'))
|
|
7612
7861
|
};
|
|
7613
7862
|
}
|
|
7614
7863
|
}]);
|
|
7615
7864
|
}();
|
|
7616
7865
|
|
|
7617
|
-
|
|
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 };
|
|
7618
7891
|
//# sourceMappingURL=core.esm.js.map
|