@mastra/core 0.1.10 → 0.1.12
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/utils.d.ts +12 -2
- package/dist/agents/utils.d.ts.map +1 -1
- package/dist/agents/vector-sync.d.ts +2 -3
- package/dist/agents/vector-sync.d.ts.map +1 -1
- package/dist/core.cjs.development.js +845 -699
- 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 +845 -700
- package/dist/core.esm.js.map +1 -1
- package/dist/framework.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-access/index.d.ts +4 -0
- package/dist/vector-access/index.d.ts.map +1 -1
- package/dist/workflows/handler.d.ts.map +1 -1
- package/package.json +2 -2
- 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
|
@@ -11,8 +11,8 @@ var zod = require('zod');
|
|
|
11
11
|
var headers = require('next/headers');
|
|
12
12
|
var qs = require('qs');
|
|
13
13
|
var next = require('inngest/next');
|
|
14
|
-
var path = require('path');
|
|
15
14
|
var fs = require('fs');
|
|
15
|
+
var path = require('path');
|
|
16
16
|
var first = require('lodash/first');
|
|
17
17
|
var last = require('lodash/last');
|
|
18
18
|
var inngest = require('inngest');
|
|
@@ -1999,13 +1999,19 @@ var createWorkflowHandler = function createWorkflowHandler(_ref2) {
|
|
|
1999
1999
|
connectionId = event.user.connectionId;
|
|
2000
2000
|
getBlueprintsDirPath = /*#__PURE__*/function () {
|
|
2001
2001
|
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
2002
|
-
var
|
|
2002
|
+
var MASTRA_APP_DIR;
|
|
2003
2003
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2004
2004
|
while (1) switch (_context.prev = _context.next) {
|
|
2005
2005
|
case 0:
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2006
|
+
MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
|
|
2007
|
+
if (blueprintDirPath) {
|
|
2008
|
+
_context.next = 3;
|
|
2009
|
+
break;
|
|
2010
|
+
}
|
|
2011
|
+
throw new Error('Missing blueprintDirPath in config');
|
|
2012
|
+
case 3:
|
|
2013
|
+
return _context.abrupt("return", path.join(MASTRA_APP_DIR, blueprintDirPath));
|
|
2014
|
+
case 4:
|
|
2009
2015
|
case "end":
|
|
2010
2016
|
return _context.stop();
|
|
2011
2017
|
}
|
|
@@ -4255,16 +4261,16 @@ function _blueprintRunner() {
|
|
|
4255
4261
|
return _blueprintRunner.apply(this, arguments);
|
|
4256
4262
|
}
|
|
4257
4263
|
|
|
4258
|
-
function
|
|
4259
|
-
var
|
|
4260
|
-
var
|
|
4261
|
-
return path.join(
|
|
4264
|
+
function getProjectDir(_ref) {
|
|
4265
|
+
var dir = _ref.dir;
|
|
4266
|
+
var MASTRA_APP_DIR = process.env.MASTRA_APP_DIR || process.cwd();
|
|
4267
|
+
return path.join(MASTRA_APP_DIR, dir);
|
|
4262
4268
|
}
|
|
4263
4269
|
function listAgentsJson(_ref2) {
|
|
4264
4270
|
var agentDir = _ref2.agentDir;
|
|
4265
4271
|
try {
|
|
4266
|
-
var agentDirPath =
|
|
4267
|
-
|
|
4272
|
+
var agentDirPath = getProjectDir({
|
|
4273
|
+
dir: agentDir
|
|
4268
4274
|
});
|
|
4269
4275
|
var agents = fs.readdirSync(agentDirPath);
|
|
4270
4276
|
return agents;
|
|
@@ -4287,42 +4293,233 @@ function getAgentFile(agentFilePath) {
|
|
|
4287
4293
|
function getAgentBlueprint(_ref3) {
|
|
4288
4294
|
var agentId = _ref3.agentId,
|
|
4289
4295
|
agentDir = _ref3.agentDir;
|
|
4290
|
-
var agentDirPath =
|
|
4291
|
-
|
|
4296
|
+
var agentDirPath = getProjectDir({
|
|
4297
|
+
dir: agentDir
|
|
4292
4298
|
});
|
|
4293
4299
|
var agentBlueprintPath = path.join(agentDirPath, agentId + ".json");
|
|
4294
4300
|
return getAgentFile(agentBlueprintPath);
|
|
4295
4301
|
}
|
|
4302
|
+
function getPineconeConfig(_ref4) {
|
|
4303
|
+
var dir = _ref4.dir;
|
|
4304
|
+
var agentDirPath = getProjectDir({
|
|
4305
|
+
dir: dir
|
|
4306
|
+
});
|
|
4307
|
+
var agentBlueprintPath = path.join(agentDirPath, "pinecone.json");
|
|
4308
|
+
return getAgentFile(agentBlueprintPath);
|
|
4309
|
+
}
|
|
4310
|
+
var retryFn = /*#__PURE__*/function () {
|
|
4311
|
+
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(operation, _temp) {
|
|
4312
|
+
var _ref6, _ref6$maxAttempts, maxAttempts, _ref6$initialDelay, initialDelay, _ref6$maxDelay, maxDelay, _ref6$factor, factor, _ref6$jitter, jitter, delay, attempt, jitterFactor;
|
|
4313
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4314
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4315
|
+
case 0:
|
|
4316
|
+
_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;
|
|
4317
|
+
delay = initialDelay;
|
|
4318
|
+
attempt = 1;
|
|
4319
|
+
case 3:
|
|
4320
|
+
if (!(attempt <= maxAttempts)) {
|
|
4321
|
+
_context.next = 22;
|
|
4322
|
+
break;
|
|
4323
|
+
}
|
|
4324
|
+
_context.prev = 4;
|
|
4325
|
+
_context.next = 7;
|
|
4326
|
+
return operation();
|
|
4327
|
+
case 7:
|
|
4328
|
+
return _context.abrupt("return", _context.sent);
|
|
4329
|
+
case 10:
|
|
4330
|
+
_context.prev = 10;
|
|
4331
|
+
_context.t0 = _context["catch"](4);
|
|
4332
|
+
if (!(attempt === maxAttempts)) {
|
|
4333
|
+
_context.next = 14;
|
|
4334
|
+
break;
|
|
4335
|
+
}
|
|
4336
|
+
throw _context.t0;
|
|
4337
|
+
case 14:
|
|
4338
|
+
console.warn("Attempt " + attempt + " failed. Retrying in " + delay + "ms...");
|
|
4339
|
+
_context.next = 17;
|
|
4340
|
+
return new Promise(function (resolve) {
|
|
4341
|
+
return setTimeout(resolve, delay);
|
|
4342
|
+
});
|
|
4343
|
+
case 17:
|
|
4344
|
+
// Calculate next delay with exponential backoff
|
|
4345
|
+
delay = Math.min(delay * factor, maxDelay);
|
|
4346
|
+
// Add jitter if enabled
|
|
4347
|
+
if (jitter) {
|
|
4348
|
+
jitterFactor = 0.5 + Math.random();
|
|
4349
|
+
delay = Math.floor(delay * jitterFactor);
|
|
4350
|
+
}
|
|
4351
|
+
case 19:
|
|
4352
|
+
attempt++;
|
|
4353
|
+
_context.next = 3;
|
|
4354
|
+
break;
|
|
4355
|
+
case 22:
|
|
4356
|
+
case "end":
|
|
4357
|
+
return _context.stop();
|
|
4358
|
+
}
|
|
4359
|
+
}, _callee, null, [[4, 10]]);
|
|
4360
|
+
}));
|
|
4361
|
+
return function retryFn(_x, _x2) {
|
|
4362
|
+
return _ref5.apply(this, arguments);
|
|
4363
|
+
};
|
|
4364
|
+
}();
|
|
4296
4365
|
|
|
4297
4366
|
var VectorLayer = /*#__PURE__*/function () {
|
|
4298
4367
|
function VectorLayer() {
|
|
4299
4368
|
this.supportedProviders = ['PINECONE'];
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4303
|
-
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4304
|
-
var inn;
|
|
4369
|
+
this.fetchPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4370
|
+
var response, _ref2, indexes;
|
|
4305
4371
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4306
4372
|
while (1) switch (_context.prev = _context.next) {
|
|
4307
4373
|
case 0:
|
|
4308
4374
|
_context.prev = 0;
|
|
4309
4375
|
_context.next = 3;
|
|
4376
|
+
return fetch('https://api.pinecone.io/indexes', {
|
|
4377
|
+
method: 'GET',
|
|
4378
|
+
headers: {
|
|
4379
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
4380
|
+
'X-Pinecone-API-Version': 'unstable'
|
|
4381
|
+
},
|
|
4382
|
+
cache: 'no-store'
|
|
4383
|
+
});
|
|
4384
|
+
case 3:
|
|
4385
|
+
response = _context.sent;
|
|
4386
|
+
_context.next = 6;
|
|
4387
|
+
return response.json();
|
|
4388
|
+
case 6:
|
|
4389
|
+
_context.t0 = _context.sent;
|
|
4390
|
+
if (_context.t0) {
|
|
4391
|
+
_context.next = 9;
|
|
4392
|
+
break;
|
|
4393
|
+
}
|
|
4394
|
+
_context.t0 = {};
|
|
4395
|
+
case 9:
|
|
4396
|
+
_ref2 = _context.t0;
|
|
4397
|
+
indexes = _ref2.indexes;
|
|
4398
|
+
return _context.abrupt("return", indexes);
|
|
4399
|
+
case 14:
|
|
4400
|
+
_context.prev = 14;
|
|
4401
|
+
_context.t1 = _context["catch"](0);
|
|
4402
|
+
console.log('Error fetching indexes using JS fetch====', _context.t1);
|
|
4403
|
+
case 17:
|
|
4404
|
+
case "end":
|
|
4405
|
+
return _context.stop();
|
|
4406
|
+
}
|
|
4407
|
+
}, _callee, null, [[0, 14]]);
|
|
4408
|
+
}));
|
|
4409
|
+
this.fetchPineconedIndexByName = /*#__PURE__*/function () {
|
|
4410
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name) {
|
|
4411
|
+
var response, data;
|
|
4412
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4413
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
4414
|
+
case 0:
|
|
4415
|
+
_context2.prev = 0;
|
|
4416
|
+
_context2.next = 3;
|
|
4417
|
+
return fetch("https://api.pinecone.io/indexes/" + name, {
|
|
4418
|
+
method: 'GET',
|
|
4419
|
+
headers: {
|
|
4420
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
4421
|
+
'X-Pinecone-API-Version': 'unstable'
|
|
4422
|
+
},
|
|
4423
|
+
cache: 'no-store'
|
|
4424
|
+
});
|
|
4425
|
+
case 3:
|
|
4426
|
+
response = _context2.sent;
|
|
4427
|
+
_context2.next = 6;
|
|
4428
|
+
return response.json();
|
|
4429
|
+
case 6:
|
|
4430
|
+
_context2.t0 = _context2.sent;
|
|
4431
|
+
if (_context2.t0) {
|
|
4432
|
+
_context2.next = 9;
|
|
4433
|
+
break;
|
|
4434
|
+
}
|
|
4435
|
+
_context2.t0 = {};
|
|
4436
|
+
case 9:
|
|
4437
|
+
data = _context2.t0;
|
|
4438
|
+
return _context2.abrupt("return", data);
|
|
4439
|
+
case 13:
|
|
4440
|
+
_context2.prev = 13;
|
|
4441
|
+
_context2.t1 = _context2["catch"](0);
|
|
4442
|
+
console.log('Error fetching indexes using JS fetch====', _context2.t1);
|
|
4443
|
+
case 16:
|
|
4444
|
+
case "end":
|
|
4445
|
+
return _context2.stop();
|
|
4446
|
+
}
|
|
4447
|
+
}, _callee2, null, [[0, 13]]);
|
|
4448
|
+
}));
|
|
4449
|
+
return function (_x) {
|
|
4450
|
+
return _ref3.apply(this, arguments);
|
|
4451
|
+
};
|
|
4452
|
+
}();
|
|
4453
|
+
this.fetchPineconeIndexStats = /*#__PURE__*/function () {
|
|
4454
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(host) {
|
|
4455
|
+
var response, data;
|
|
4456
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4457
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4458
|
+
case 0:
|
|
4459
|
+
_context3.prev = 0;
|
|
4460
|
+
_context3.next = 3;
|
|
4461
|
+
return fetch("https://" + host + "/describe_index_stats", {
|
|
4462
|
+
method: 'GET',
|
|
4463
|
+
headers: {
|
|
4464
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
4465
|
+
'X-Pinecone-API-Version': '2024-07'
|
|
4466
|
+
},
|
|
4467
|
+
cache: 'no-store'
|
|
4468
|
+
});
|
|
4469
|
+
case 3:
|
|
4470
|
+
response = _context3.sent;
|
|
4471
|
+
_context3.next = 6;
|
|
4472
|
+
return response.json();
|
|
4473
|
+
case 6:
|
|
4474
|
+
_context3.t0 = _context3.sent;
|
|
4475
|
+
if (_context3.t0) {
|
|
4476
|
+
_context3.next = 9;
|
|
4477
|
+
break;
|
|
4478
|
+
}
|
|
4479
|
+
_context3.t0 = {};
|
|
4480
|
+
case 9:
|
|
4481
|
+
data = _context3.t0;
|
|
4482
|
+
return _context3.abrupt("return", data);
|
|
4483
|
+
case 13:
|
|
4484
|
+
_context3.prev = 13;
|
|
4485
|
+
_context3.t1 = _context3["catch"](0);
|
|
4486
|
+
console.log('Error fetching indexes using JS fetch====', _context3.t1);
|
|
4487
|
+
case 16:
|
|
4488
|
+
case "end":
|
|
4489
|
+
return _context3.stop();
|
|
4490
|
+
}
|
|
4491
|
+
}, _callee3, null, [[0, 13]]);
|
|
4492
|
+
}));
|
|
4493
|
+
return function (_x2) {
|
|
4494
|
+
return _ref4.apply(this, arguments);
|
|
4495
|
+
};
|
|
4496
|
+
}();
|
|
4497
|
+
}
|
|
4498
|
+
var _proto = VectorLayer.prototype;
|
|
4499
|
+
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4500
|
+
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
4501
|
+
var inn;
|
|
4502
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4503
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4504
|
+
case 0:
|
|
4505
|
+
_context4.prev = 0;
|
|
4506
|
+
_context4.next = 3;
|
|
4310
4507
|
return this.Pinecone.listIndexes();
|
|
4311
4508
|
case 3:
|
|
4312
|
-
inn =
|
|
4509
|
+
inn = _context4.sent;
|
|
4313
4510
|
console.log('inn====', {
|
|
4314
4511
|
inn: inn
|
|
4315
4512
|
});
|
|
4316
|
-
return
|
|
4513
|
+
return _context4.abrupt("return", inn);
|
|
4317
4514
|
case 8:
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
console.log('error getting indexesss====',
|
|
4515
|
+
_context4.prev = 8;
|
|
4516
|
+
_context4.t0 = _context4["catch"](0);
|
|
4517
|
+
console.log('error getting indexesss====', _context4.t0);
|
|
4321
4518
|
case 11:
|
|
4322
4519
|
case "end":
|
|
4323
|
-
return
|
|
4520
|
+
return _context4.stop();
|
|
4324
4521
|
}
|
|
4325
|
-
},
|
|
4522
|
+
}, _callee4, this, [[0, 8]]);
|
|
4326
4523
|
}));
|
|
4327
4524
|
function getPineconeIndexes() {
|
|
4328
4525
|
return _getPineconeIndexes.apply(this, arguments);
|
|
@@ -4330,13 +4527,13 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4330
4527
|
return getPineconeIndexes;
|
|
4331
4528
|
}();
|
|
4332
4529
|
_proto.createPineconeIndex = /*#__PURE__*/function () {
|
|
4333
|
-
var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4530
|
+
var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
|
|
4334
4531
|
var name;
|
|
4335
|
-
return _regeneratorRuntime().wrap(function
|
|
4336
|
-
while (1) switch (
|
|
4532
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4533
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4337
4534
|
case 0:
|
|
4338
|
-
name =
|
|
4339
|
-
return
|
|
4535
|
+
name = _ref5.name;
|
|
4536
|
+
return _context5.abrupt("return", this.Pinecone.createIndex({
|
|
4340
4537
|
suppressConflicts: true,
|
|
4341
4538
|
name: name,
|
|
4342
4539
|
dimension: 1536,
|
|
@@ -4350,129 +4547,129 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4350
4547
|
}));
|
|
4351
4548
|
case 2:
|
|
4352
4549
|
case "end":
|
|
4353
|
-
return
|
|
4550
|
+
return _context5.stop();
|
|
4354
4551
|
}
|
|
4355
|
-
},
|
|
4552
|
+
}, _callee5, this);
|
|
4356
4553
|
}));
|
|
4357
|
-
function createPineconeIndex(
|
|
4554
|
+
function createPineconeIndex(_x3) {
|
|
4358
4555
|
return _createPineconeIndex.apply(this, arguments);
|
|
4359
4556
|
}
|
|
4360
4557
|
return createPineconeIndex;
|
|
4361
4558
|
}();
|
|
4362
4559
|
_proto.getPineconeIndex = /*#__PURE__*/function () {
|
|
4363
|
-
var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4560
|
+
var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6) {
|
|
4364
4561
|
var name;
|
|
4365
|
-
return _regeneratorRuntime().wrap(function
|
|
4366
|
-
while (1) switch (
|
|
4562
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4563
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4367
4564
|
case 0:
|
|
4368
|
-
name =
|
|
4369
|
-
return
|
|
4565
|
+
name = _ref6.name;
|
|
4566
|
+
return _context6.abrupt("return", this.Pinecone.index(name));
|
|
4370
4567
|
case 2:
|
|
4371
4568
|
case "end":
|
|
4372
|
-
return
|
|
4569
|
+
return _context6.stop();
|
|
4373
4570
|
}
|
|
4374
|
-
},
|
|
4571
|
+
}, _callee6, this);
|
|
4375
4572
|
}));
|
|
4376
|
-
function getPineconeIndex(
|
|
4573
|
+
function getPineconeIndex(_x4) {
|
|
4377
4574
|
return _getPineconeIndex.apply(this, arguments);
|
|
4378
4575
|
}
|
|
4379
4576
|
return getPineconeIndex;
|
|
4380
4577
|
}();
|
|
4381
4578
|
_proto.generateVectorEmbedding = /*#__PURE__*/function () {
|
|
4382
|
-
var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4579
|
+
var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(data) {
|
|
4383
4580
|
var _yield$embed, embedding;
|
|
4384
|
-
return _regeneratorRuntime().wrap(function
|
|
4385
|
-
while (1) switch (
|
|
4581
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4582
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4386
4583
|
case 0:
|
|
4387
|
-
|
|
4584
|
+
_context7.next = 2;
|
|
4388
4585
|
return ai.embed({
|
|
4389
4586
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4390
4587
|
value: JSON.stringify(data)
|
|
4391
4588
|
});
|
|
4392
4589
|
case 2:
|
|
4393
|
-
_yield$embed =
|
|
4590
|
+
_yield$embed = _context7.sent;
|
|
4394
4591
|
embedding = _yield$embed.embedding;
|
|
4395
|
-
return
|
|
4592
|
+
return _context7.abrupt("return", embedding);
|
|
4396
4593
|
case 5:
|
|
4397
4594
|
case "end":
|
|
4398
|
-
return
|
|
4595
|
+
return _context7.stop();
|
|
4399
4596
|
}
|
|
4400
|
-
},
|
|
4597
|
+
}, _callee7);
|
|
4401
4598
|
}));
|
|
4402
|
-
function generateVectorEmbedding(
|
|
4599
|
+
function generateVectorEmbedding(_x5) {
|
|
4403
4600
|
return _generateVectorEmbedding.apply(this, arguments);
|
|
4404
4601
|
}
|
|
4405
4602
|
return generateVectorEmbedding;
|
|
4406
4603
|
}();
|
|
4407
4604
|
_proto.getPineconeIndexWithMetadata = /*#__PURE__*/function () {
|
|
4408
|
-
var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4605
|
+
var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
|
|
4409
4606
|
var name, newIndex, indexQuery, namespaces, data, _iterator, _step, _namespaceData$record, namespace, namespaceData, metadata;
|
|
4410
|
-
return _regeneratorRuntime().wrap(function
|
|
4411
|
-
while (1) switch (
|
|
4607
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
4608
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4412
4609
|
case 0:
|
|
4413
|
-
name =
|
|
4414
|
-
|
|
4610
|
+
name = _ref7.name;
|
|
4611
|
+
_context8.prev = 1;
|
|
4415
4612
|
if (name) {
|
|
4416
|
-
|
|
4613
|
+
_context8.next = 5;
|
|
4417
4614
|
break;
|
|
4418
4615
|
}
|
|
4419
4616
|
console.log('Index name not passed');
|
|
4420
|
-
return
|
|
4617
|
+
return _context8.abrupt("return", []);
|
|
4421
4618
|
case 5:
|
|
4422
|
-
|
|
4619
|
+
_context8.next = 7;
|
|
4423
4620
|
return this.getPineconeIndex({
|
|
4424
4621
|
name: name
|
|
4425
4622
|
});
|
|
4426
4623
|
case 7:
|
|
4427
|
-
newIndex =
|
|
4428
|
-
|
|
4624
|
+
newIndex = _context8.sent;
|
|
4625
|
+
_context8.next = 10;
|
|
4429
4626
|
return newIndex == null ? void 0 : newIndex.describeIndexStats();
|
|
4430
4627
|
case 10:
|
|
4431
|
-
indexQuery =
|
|
4628
|
+
indexQuery = _context8.sent;
|
|
4432
4629
|
if (!indexQuery) {
|
|
4433
|
-
|
|
4630
|
+
_context8.next = 27;
|
|
4434
4631
|
break;
|
|
4435
4632
|
}
|
|
4436
4633
|
namespaces = Object.keys((indexQuery == null ? void 0 : indexQuery.namespaces) || {});
|
|
4437
4634
|
data = [];
|
|
4438
4635
|
if (!namespaces.length) {
|
|
4439
|
-
|
|
4636
|
+
_context8.next = 26;
|
|
4440
4637
|
break;
|
|
4441
4638
|
}
|
|
4442
4639
|
_iterator = _createForOfIteratorHelperLoose(namespaces);
|
|
4443
4640
|
case 16:
|
|
4444
4641
|
if ((_step = _iterator()).done) {
|
|
4445
|
-
|
|
4642
|
+
_context8.next = 26;
|
|
4446
4643
|
break;
|
|
4447
4644
|
}
|
|
4448
4645
|
namespace = _step.value;
|
|
4449
|
-
|
|
4646
|
+
_context8.next = 20;
|
|
4450
4647
|
return newIndex == null ? void 0 : newIndex.namespace(namespace).fetch([name]);
|
|
4451
4648
|
case 20:
|
|
4452
|
-
namespaceData =
|
|
4649
|
+
namespaceData = _context8.sent;
|
|
4453
4650
|
metadata = namespaceData == null || (_namespaceData$record = namespaceData.records) == null || (_namespaceData$record = _namespaceData$record[name]) == null ? void 0 : _namespaceData$record.metadata;
|
|
4454
4651
|
console.log("metadata for " + namespace + "===", JSON.stringify(metadata, null, 2));
|
|
4455
4652
|
if (metadata) {
|
|
4456
4653
|
data.push(metadata);
|
|
4457
4654
|
}
|
|
4458
4655
|
case 24:
|
|
4459
|
-
|
|
4656
|
+
_context8.next = 16;
|
|
4460
4657
|
break;
|
|
4461
4658
|
case 26:
|
|
4462
|
-
return
|
|
4659
|
+
return _context8.abrupt("return", data);
|
|
4463
4660
|
case 27:
|
|
4464
|
-
return
|
|
4661
|
+
return _context8.abrupt("return", []);
|
|
4465
4662
|
case 30:
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
console.log("Error getting " + name + " index",
|
|
4663
|
+
_context8.prev = 30;
|
|
4664
|
+
_context8.t0 = _context8["catch"](1);
|
|
4665
|
+
console.log("Error getting " + name + " index", _context8.t0);
|
|
4469
4666
|
case 33:
|
|
4470
4667
|
case "end":
|
|
4471
|
-
return
|
|
4668
|
+
return _context8.stop();
|
|
4472
4669
|
}
|
|
4473
|
-
},
|
|
4670
|
+
}, _callee8, this, [[1, 30]]);
|
|
4474
4671
|
}));
|
|
4475
|
-
function getPineconeIndexWithMetadata(
|
|
4672
|
+
function getPineconeIndexWithMetadata(_x6) {
|
|
4476
4673
|
return _getPineconeIndexWithMetadata.apply(this, arguments);
|
|
4477
4674
|
}
|
|
4478
4675
|
return getPineconeIndexWithMetadata;
|
|
@@ -4491,7 +4688,7 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4491
4688
|
}();
|
|
4492
4689
|
|
|
4493
4690
|
function getVectorProvider(provider) {
|
|
4494
|
-
if (provider === '
|
|
4691
|
+
if (provider.toUpperCase() === 'PINECONE') {
|
|
4495
4692
|
var _VectorLayer = new VectorLayer(),
|
|
4496
4693
|
Pinecone = _VectorLayer.Pinecone;
|
|
4497
4694
|
return Pinecone;
|
|
@@ -4507,262 +4704,321 @@ function executeIndexSync(_x) {
|
|
|
4507
4704
|
}
|
|
4508
4705
|
//Generic vector sync from event data
|
|
4509
4706
|
function _executeIndexSync() {
|
|
4510
|
-
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4707
|
+
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref) {
|
|
4511
4708
|
var _event$user, _event$data;
|
|
4512
|
-
var event, mastra, connectionId, providedIndexes, systemName,
|
|
4513
|
-
return _regeneratorRuntime().wrap(function
|
|
4514
|
-
while (1) switch (
|
|
4709
|
+
var event, mastra, connectionId, providedIndexes, systemName, _iterator2, _step2, _step2$value, provider, indexes, vp, _loop2, _ret2, _iterator3, _step3;
|
|
4710
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
4711
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4515
4712
|
case 0:
|
|
4516
4713
|
event = _ref.event, mastra = _ref.mastra;
|
|
4517
4714
|
connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
|
|
4518
4715
|
providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
|
|
4519
4716
|
systemName = mastra.config.name;
|
|
4520
|
-
|
|
4717
|
+
_iterator2 = _createForOfIteratorHelperLoose(providedIndexes);
|
|
4521
4718
|
case 5:
|
|
4522
|
-
if ((
|
|
4523
|
-
|
|
4719
|
+
if ((_step2 = _iterator2()).done) {
|
|
4720
|
+
_context8.next = 25;
|
|
4524
4721
|
break;
|
|
4525
4722
|
}
|
|
4526
|
-
|
|
4723
|
+
_step2$value = _step2.value, provider = _step2$value.provider, indexes = _step2$value.indexes;
|
|
4527
4724
|
vp = getVectorProvider(provider);
|
|
4528
4725
|
if (vp) {
|
|
4529
|
-
|
|
4726
|
+
_context8.next = 11;
|
|
4530
4727
|
break;
|
|
4531
4728
|
}
|
|
4532
4729
|
console.error('UNSUPPORTED VECTOR PROVIDER', provider);
|
|
4533
|
-
return
|
|
4730
|
+
return _context8.abrupt("return");
|
|
4534
4731
|
case 11:
|
|
4535
4732
|
if (process.env.OPENAI_API_KEY) {
|
|
4536
|
-
|
|
4733
|
+
_context8.next = 14;
|
|
4537
4734
|
break;
|
|
4538
4735
|
}
|
|
4539
4736
|
console.error('NO OPENAI_API_KEY');
|
|
4540
|
-
return
|
|
4737
|
+
return _context8.abrupt("return");
|
|
4541
4738
|
case 14:
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
break;
|
|
4547
|
-
}
|
|
4548
|
-
index = _step2.value;
|
|
4549
|
-
_context5.next = 19;
|
|
4550
|
-
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
4551
|
-
name: index
|
|
4552
|
-
});
|
|
4553
|
-
case 19:
|
|
4554
|
-
indexMetadata = _context5.sent;
|
|
4555
|
-
if (indexMetadata != null && indexMetadata.length) {
|
|
4556
|
-
_context5.next = 23;
|
|
4557
|
-
break;
|
|
4558
|
-
}
|
|
4559
|
-
console.error('No index metadata found for', index);
|
|
4560
|
-
return _context5.abrupt("return");
|
|
4561
|
-
case 23:
|
|
4562
|
-
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
4563
|
-
var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
|
|
4564
|
-
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;
|
|
4565
|
-
return _regeneratorRuntime().wrap(function _loop$(_context4) {
|
|
4566
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
4739
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4740
|
+
var index, getPineconeIndexWithMetadata, indexMetadata, _loop3, _ret3, _iterator4, _step4;
|
|
4741
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context7) {
|
|
4742
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4567
4743
|
case 0:
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4744
|
+
index = _step3.value;
|
|
4745
|
+
getPineconeIndexWithMetadata = /*#__PURE__*/function () {
|
|
4746
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
4747
|
+
var res;
|
|
4748
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4749
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4750
|
+
case 0:
|
|
4751
|
+
_context4.prev = 0;
|
|
4752
|
+
_context4.next = 3;
|
|
4753
|
+
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
4754
|
+
name: index
|
|
4755
|
+
});
|
|
4756
|
+
case 3:
|
|
4757
|
+
res = _context4.sent;
|
|
4758
|
+
if (res.length) {
|
|
4759
|
+
_context4.next = 6;
|
|
4760
|
+
break;
|
|
4761
|
+
}
|
|
4762
|
+
throw new Error('No index metadata found');
|
|
4763
|
+
case 6:
|
|
4764
|
+
return _context4.abrupt("return", res);
|
|
4765
|
+
case 9:
|
|
4766
|
+
_context4.prev = 9;
|
|
4767
|
+
_context4.t0 = _context4["catch"](0);
|
|
4768
|
+
throw new Error(_context4.t0);
|
|
4769
|
+
case 12:
|
|
4770
|
+
case "end":
|
|
4771
|
+
return _context4.stop();
|
|
4772
|
+
}
|
|
4773
|
+
}, _callee4, null, [[0, 9]]);
|
|
4774
|
+
}));
|
|
4775
|
+
return function getPineconeIndexWithMetadata() {
|
|
4776
|
+
return _ref9.apply(this, arguments);
|
|
4777
|
+
};
|
|
4778
|
+
}();
|
|
4779
|
+
_context7.next = 4;
|
|
4780
|
+
return retryFn(getPineconeIndexWithMetadata);
|
|
4575
4781
|
case 4:
|
|
4576
|
-
|
|
4577
|
-
if (
|
|
4578
|
-
|
|
4782
|
+
indexMetadata = _context7.sent;
|
|
4783
|
+
if (indexMetadata != null && indexMetadata.length) {
|
|
4784
|
+
_context7.next = 8;
|
|
4579
4785
|
break;
|
|
4580
4786
|
}
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
break;
|
|
4584
|
-
case 9:
|
|
4585
|
-
_context4.t2 = _yield$mastra$dataLay.id;
|
|
4586
|
-
case 10:
|
|
4587
|
-
_context4.t0 = _context4.t2;
|
|
4588
|
-
if (_context4.t0) {
|
|
4589
|
-
_context4.next = 13;
|
|
4590
|
-
break;
|
|
4591
|
-
}
|
|
4592
|
-
_context4.t0 = '';
|
|
4593
|
-
case 13:
|
|
4594
|
-
k_id = _context4.t0;
|
|
4595
|
-
if (!(!k_id && integration === systemName)) {
|
|
4596
|
-
_context4.next = 19;
|
|
4597
|
-
break;
|
|
4598
|
-
}
|
|
4599
|
-
_context4.next = 17;
|
|
4600
|
-
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4601
|
-
connection: {
|
|
4602
|
-
connectionId: connectionId,
|
|
4603
|
-
name: integration
|
|
4604
|
-
},
|
|
4605
|
-
credential: {
|
|
4606
|
-
type: 'API_KEY',
|
|
4607
|
-
value: connectionId,
|
|
4608
|
-
scope: []
|
|
4609
|
-
}
|
|
4610
|
-
});
|
|
4611
|
-
case 17:
|
|
4612
|
-
connection = _context4.sent;
|
|
4613
|
-
k_id = connection.id;
|
|
4614
|
-
case 19:
|
|
4615
|
-
if (k_id) {
|
|
4616
|
-
_context4.next = 22;
|
|
4617
|
-
break;
|
|
4618
|
-
}
|
|
4619
|
-
console.error('Error bootstrapping shit');
|
|
4620
|
-
return _context4.abrupt("return", {
|
|
4787
|
+
console.error('No index metadata found for', index);
|
|
4788
|
+
return _context7.abrupt("return", {
|
|
4621
4789
|
v: void 0
|
|
4622
4790
|
});
|
|
4623
|
-
case
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4791
|
+
case 8:
|
|
4792
|
+
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
4793
|
+
var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
|
|
4794
|
+
var entity, fields, integration, name, syncEvent, k_id, _mastra$dataLayer2, connection, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, _yield$mastra$trigger, _event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
|
|
4795
|
+
return _regeneratorRuntime().wrap(function _loop3$(_context6) {
|
|
4796
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4797
|
+
case 0:
|
|
4798
|
+
entity = _step4.value;
|
|
4799
|
+
fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
|
|
4800
|
+
_context6.next = 4;
|
|
4801
|
+
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4802
|
+
connectionId: connectionId,
|
|
4803
|
+
name: integration
|
|
4804
|
+
});
|
|
4805
|
+
case 4:
|
|
4806
|
+
_context6.t1 = _yield$mastra$dataLay = _context6.sent;
|
|
4807
|
+
if (!(_context6.t1 == null)) {
|
|
4808
|
+
_context6.next = 9;
|
|
4809
|
+
break;
|
|
4810
|
+
}
|
|
4811
|
+
_context6.t2 = void 0;
|
|
4812
|
+
_context6.next = 10;
|
|
4813
|
+
break;
|
|
4814
|
+
case 9:
|
|
4815
|
+
_context6.t2 = _yield$mastra$dataLay.id;
|
|
4816
|
+
case 10:
|
|
4817
|
+
_context6.t0 = _context6.t2;
|
|
4818
|
+
if (_context6.t0) {
|
|
4819
|
+
_context6.next = 13;
|
|
4820
|
+
break;
|
|
4821
|
+
}
|
|
4822
|
+
_context6.t0 = '';
|
|
4823
|
+
case 13:
|
|
4824
|
+
k_id = _context6.t0;
|
|
4825
|
+
if (!(!k_id && integration === systemName)) {
|
|
4826
|
+
_context6.next = 19;
|
|
4827
|
+
break;
|
|
4828
|
+
}
|
|
4829
|
+
_context6.next = 17;
|
|
4830
|
+
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4831
|
+
connection: {
|
|
4832
|
+
connectionId: connectionId,
|
|
4833
|
+
name: integration
|
|
4834
|
+
},
|
|
4835
|
+
credential: {
|
|
4836
|
+
type: 'API_KEY',
|
|
4837
|
+
value: connectionId,
|
|
4838
|
+
scope: []
|
|
4839
|
+
}
|
|
4840
|
+
});
|
|
4841
|
+
case 17:
|
|
4842
|
+
connection = _context6.sent;
|
|
4843
|
+
k_id = connection.id;
|
|
4844
|
+
case 19:
|
|
4845
|
+
if (k_id) {
|
|
4846
|
+
_context6.next = 22;
|
|
4847
|
+
break;
|
|
4848
|
+
}
|
|
4849
|
+
console.error('Error bootstrapping shit');
|
|
4850
|
+
return _context6.abrupt("return", {
|
|
4851
|
+
v: {
|
|
4852
|
+
v: void 0
|
|
4853
|
+
}
|
|
4854
|
+
});
|
|
4855
|
+
case 22:
|
|
4856
|
+
_context6.next = 24;
|
|
4857
|
+
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
4858
|
+
k_id: k_id,
|
|
4859
|
+
type: name
|
|
4860
|
+
});
|
|
4861
|
+
case 24:
|
|
4862
|
+
entityRecords = _context6.sent;
|
|
4863
|
+
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
4864
|
+
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
4865
|
+
_context6.next = 44;
|
|
4866
|
+
break;
|
|
4867
|
+
}
|
|
4868
|
+
console.error('NO RECORDS ATTEMPTING SYNC');
|
|
4869
|
+
_context6.next = 30;
|
|
4870
|
+
return mastra.triggerEvent({
|
|
4871
|
+
key: syncEvent,
|
|
4872
|
+
data: {},
|
|
4873
|
+
user: {
|
|
4874
|
+
connectionId: connectionId
|
|
4875
|
+
}
|
|
4876
|
+
});
|
|
4877
|
+
case 30:
|
|
4878
|
+
_yield$mastra$trigger = _context6.sent;
|
|
4879
|
+
_event = _yield$mastra$trigger.event;
|
|
4880
|
+
console.log(_event, '####');
|
|
4881
|
+
_context6.next = 35;
|
|
4882
|
+
return _event.subscribe();
|
|
4883
|
+
case 35:
|
|
4884
|
+
res = _context6.sent;
|
|
4885
|
+
console.log('Subscribe result', res);
|
|
4886
|
+
_context6.next = 39;
|
|
4887
|
+
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
4888
|
+
k_id: k_id,
|
|
4889
|
+
type: entity.name
|
|
4890
|
+
});
|
|
4891
|
+
case 39:
|
|
4892
|
+
entityRecords = _context6.sent;
|
|
4893
|
+
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
4894
|
+
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
4895
|
+
_context6.next = 44;
|
|
4896
|
+
break;
|
|
4897
|
+
}
|
|
4898
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
4899
|
+
return _context6.abrupt("return", {
|
|
4900
|
+
v: {
|
|
4901
|
+
v: void 0
|
|
4902
|
+
}
|
|
4903
|
+
});
|
|
4904
|
+
case 44:
|
|
4905
|
+
recordsMapped = records.map(function (_ref10) {
|
|
4906
|
+
var data = _ref10.data,
|
|
4907
|
+
externalId = _ref10.externalId;
|
|
4908
|
+
return _extends({
|
|
4909
|
+
id: externalId
|
|
4910
|
+
}, _.pick(data, fields));
|
|
4911
|
+
});
|
|
4912
|
+
console.log(recordsMapped, 'RECORDS');
|
|
4913
|
+
entityTypeIndex = vp.index(index);
|
|
4914
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
4915
|
+
_context6.prev = 48;
|
|
4916
|
+
_context6.next = 51;
|
|
4917
|
+
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4918
|
+
var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record) {
|
|
4919
|
+
var _yield$embed, embedding;
|
|
4920
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4921
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4922
|
+
case 0:
|
|
4923
|
+
_context5.next = 2;
|
|
4924
|
+
return ai.embed({
|
|
4925
|
+
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4926
|
+
value: JSON.stringify(record)
|
|
4927
|
+
});
|
|
4928
|
+
case 2:
|
|
4929
|
+
_yield$embed = _context5.sent;
|
|
4930
|
+
embedding = _yield$embed.embedding;
|
|
4931
|
+
return _context5.abrupt("return", {
|
|
4932
|
+
id: record.id,
|
|
4933
|
+
values: embedding,
|
|
4934
|
+
metadata: record
|
|
4935
|
+
});
|
|
4936
|
+
case 5:
|
|
4937
|
+
case "end":
|
|
4938
|
+
return _context5.stop();
|
|
4939
|
+
}
|
|
4940
|
+
}, _callee5);
|
|
4941
|
+
}));
|
|
4942
|
+
return function (_x7) {
|
|
4943
|
+
return _ref11.apply(this, arguments);
|
|
4944
|
+
};
|
|
4945
|
+
}())) != null ? _recordsMapped$map : []);
|
|
4946
|
+
case 51:
|
|
4947
|
+
vectors = _context6.sent;
|
|
4948
|
+
console.log('UPSERTING', vectors);
|
|
4949
|
+
if (!(vectors.length > 0)) {
|
|
4950
|
+
_context6.next = 56;
|
|
4951
|
+
break;
|
|
4952
|
+
}
|
|
4953
|
+
_context6.next = 56;
|
|
4954
|
+
return entityTypeIndex.namespace(name).upsert(vectors);
|
|
4955
|
+
case 56:
|
|
4956
|
+
_context6.next = 61;
|
|
4957
|
+
break;
|
|
4958
|
+
case 58:
|
|
4959
|
+
_context6.prev = 58;
|
|
4960
|
+
_context6.t3 = _context6["catch"](48);
|
|
4961
|
+
console.error(_context6.t3);
|
|
4962
|
+
case 61:
|
|
4963
|
+
return _context6.abrupt("return", {
|
|
4964
|
+
v: {
|
|
4965
|
+
v: void 0
|
|
4966
|
+
}
|
|
4967
|
+
});
|
|
4968
|
+
case 62:
|
|
4969
|
+
case "end":
|
|
4970
|
+
return _context6.stop();
|
|
4971
|
+
}
|
|
4972
|
+
}, _loop3, null, [[48, 58]]);
|
|
4658
4973
|
});
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
_context4.next = 44;
|
|
4974
|
+
_iterator4 = _createForOfIteratorHelperLoose(indexMetadata);
|
|
4975
|
+
case 10:
|
|
4976
|
+
if ((_step4 = _iterator4()).done) {
|
|
4977
|
+
_context7.next = 17;
|
|
4664
4978
|
break;
|
|
4665
4979
|
}
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
recordsMapped = records.map(function (_ref9) {
|
|
4672
|
-
var data = _ref9.data,
|
|
4673
|
-
externalId = _ref9.externalId;
|
|
4674
|
-
return _extends({
|
|
4675
|
-
id: externalId
|
|
4676
|
-
}, _.pick(data, fields));
|
|
4677
|
-
});
|
|
4678
|
-
console.log(recordsMapped, 'RECORDS');
|
|
4679
|
-
entityTypeIndex = vp.index(index);
|
|
4680
|
-
console.log(entityTypeIndex, 'INDEX');
|
|
4681
|
-
_context4.prev = 48;
|
|
4682
|
-
_context4.next = 51;
|
|
4683
|
-
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4684
|
-
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(record) {
|
|
4685
|
-
var _yield$embed, embedding;
|
|
4686
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4687
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
4688
|
-
case 0:
|
|
4689
|
-
_context3.next = 2;
|
|
4690
|
-
return ai.embed({
|
|
4691
|
-
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4692
|
-
value: JSON.stringify(record)
|
|
4693
|
-
});
|
|
4694
|
-
case 2:
|
|
4695
|
-
_yield$embed = _context3.sent;
|
|
4696
|
-
embedding = _yield$embed.embedding;
|
|
4697
|
-
return _context3.abrupt("return", {
|
|
4698
|
-
id: record.id,
|
|
4699
|
-
values: embedding,
|
|
4700
|
-
metadata: record
|
|
4701
|
-
});
|
|
4702
|
-
case 5:
|
|
4703
|
-
case "end":
|
|
4704
|
-
return _context3.stop();
|
|
4705
|
-
}
|
|
4706
|
-
}, _callee3);
|
|
4707
|
-
}));
|
|
4708
|
-
return function (_x7) {
|
|
4709
|
-
return _ref10.apply(this, arguments);
|
|
4710
|
-
};
|
|
4711
|
-
}())) != null ? _recordsMapped$map : []);
|
|
4712
|
-
case 51:
|
|
4713
|
-
vectors = _context4.sent;
|
|
4714
|
-
console.log('UPSERTING', vectors);
|
|
4715
|
-
if (!(vectors.length > 0)) {
|
|
4716
|
-
_context4.next = 56;
|
|
4980
|
+
return _context7.delegateYield(_loop3(), "t0", 12);
|
|
4981
|
+
case 12:
|
|
4982
|
+
_ret3 = _context7.t0;
|
|
4983
|
+
if (!_ret3) {
|
|
4984
|
+
_context7.next = 15;
|
|
4717
4985
|
break;
|
|
4718
4986
|
}
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
_context4.next = 61;
|
|
4987
|
+
return _context7.abrupt("return", _ret3.v);
|
|
4988
|
+
case 15:
|
|
4989
|
+
_context7.next = 10;
|
|
4723
4990
|
break;
|
|
4724
|
-
case
|
|
4725
|
-
_context4.prev = 58;
|
|
4726
|
-
_context4.t3 = _context4["catch"](48);
|
|
4727
|
-
console.error(_context4.t3);
|
|
4728
|
-
case 61:
|
|
4729
|
-
return _context4.abrupt("return", {
|
|
4730
|
-
v: void 0
|
|
4731
|
-
});
|
|
4732
|
-
case 62:
|
|
4991
|
+
case 17:
|
|
4733
4992
|
case "end":
|
|
4734
|
-
return
|
|
4993
|
+
return _context7.stop();
|
|
4735
4994
|
}
|
|
4736
|
-
},
|
|
4995
|
+
}, _loop2);
|
|
4737
4996
|
});
|
|
4738
|
-
_iterator3 = _createForOfIteratorHelperLoose(
|
|
4739
|
-
case
|
|
4997
|
+
_iterator3 = _createForOfIteratorHelperLoose(indexes);
|
|
4998
|
+
case 16:
|
|
4740
4999
|
if ((_step3 = _iterator3()).done) {
|
|
4741
|
-
|
|
5000
|
+
_context8.next = 23;
|
|
4742
5001
|
break;
|
|
4743
5002
|
}
|
|
4744
|
-
return
|
|
4745
|
-
case
|
|
4746
|
-
|
|
4747
|
-
if (!
|
|
4748
|
-
|
|
5003
|
+
return _context8.delegateYield(_loop2(), "t0", 18);
|
|
5004
|
+
case 18:
|
|
5005
|
+
_ret2 = _context8.t0;
|
|
5006
|
+
if (!_ret2) {
|
|
5007
|
+
_context8.next = 21;
|
|
4749
5008
|
break;
|
|
4750
5009
|
}
|
|
4751
|
-
return
|
|
4752
|
-
case
|
|
4753
|
-
|
|
4754
|
-
break;
|
|
4755
|
-
case 32:
|
|
4756
|
-
_context5.next = 15;
|
|
5010
|
+
return _context8.abrupt("return", _ret2.v);
|
|
5011
|
+
case 21:
|
|
5012
|
+
_context8.next = 16;
|
|
4757
5013
|
break;
|
|
4758
|
-
case
|
|
4759
|
-
|
|
5014
|
+
case 23:
|
|
5015
|
+
_context8.next = 5;
|
|
4760
5016
|
break;
|
|
4761
|
-
case
|
|
5017
|
+
case 25:
|
|
4762
5018
|
case "end":
|
|
4763
|
-
return
|
|
5019
|
+
return _context8.stop();
|
|
4764
5020
|
}
|
|
4765
|
-
},
|
|
5021
|
+
}, _callee6);
|
|
4766
5022
|
}));
|
|
4767
5023
|
return _executeIndexSync.apply(this, arguments);
|
|
4768
5024
|
}
|
|
@@ -4771,11 +5027,11 @@ function executeGenericVectorSync(_x2) {
|
|
|
4771
5027
|
}
|
|
4772
5028
|
// Vector Sync from agents Dir
|
|
4773
5029
|
function _executeGenericVectorSync() {
|
|
4774
|
-
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5030
|
+
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref2) {
|
|
4775
5031
|
var _event$user2, _event$data2, _event$data3;
|
|
4776
|
-
var event, mastra, connectionId, vector_provider, entities, systemName, vp,
|
|
4777
|
-
return _regeneratorRuntime().wrap(function
|
|
4778
|
-
while (1) switch (
|
|
5032
|
+
var event, mastra, connectionId, vector_provider, entities, systemName, vp, _iterator5, _step5, _yield$mastra$dataLay2, _mastra$dataLayer5, vectorE, integrationName, k_id, _mastra$dataLayer6, connection, _loop4, _ret4, _iterator6, _step6;
|
|
5033
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context11) {
|
|
5034
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
4779
5035
|
case 0:
|
|
4780
5036
|
event = _ref2.event, mastra = _ref2.mastra;
|
|
4781
5037
|
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
@@ -4783,65 +5039,65 @@ function _executeGenericVectorSync() {
|
|
|
4783
5039
|
entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
|
|
4784
5040
|
systemName = mastra.config.name;
|
|
4785
5041
|
if (vector_provider) {
|
|
4786
|
-
|
|
5042
|
+
_context11.next = 8;
|
|
4787
5043
|
break;
|
|
4788
5044
|
}
|
|
4789
5045
|
console.error("No vector_provider defined for agent");
|
|
4790
|
-
return
|
|
5046
|
+
return _context11.abrupt("return");
|
|
4791
5047
|
case 8:
|
|
4792
5048
|
vp = getVectorProvider(vector_provider);
|
|
4793
5049
|
if (vp) {
|
|
4794
|
-
|
|
5050
|
+
_context11.next = 12;
|
|
4795
5051
|
break;
|
|
4796
5052
|
}
|
|
4797
5053
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4798
|
-
return
|
|
5054
|
+
return _context11.abrupt("return");
|
|
4799
5055
|
case 12:
|
|
4800
5056
|
if (process.env.OPENAI_API_KEY) {
|
|
4801
|
-
|
|
5057
|
+
_context11.next = 15;
|
|
4802
5058
|
break;
|
|
4803
5059
|
}
|
|
4804
5060
|
console.error('NO OPENAI_API_KEY');
|
|
4805
|
-
return
|
|
5061
|
+
return _context11.abrupt("return");
|
|
4806
5062
|
case 15:
|
|
4807
|
-
|
|
5063
|
+
_iterator5 = _createForOfIteratorHelperLoose(entities);
|
|
4808
5064
|
case 16:
|
|
4809
|
-
if ((
|
|
4810
|
-
|
|
5065
|
+
if ((_step5 = _iterator5()).done) {
|
|
5066
|
+
_context11.next = 50;
|
|
4811
5067
|
break;
|
|
4812
5068
|
}
|
|
4813
|
-
vectorE =
|
|
5069
|
+
vectorE = _step5.value;
|
|
4814
5070
|
integrationName = vectorE.integration;
|
|
4815
|
-
|
|
5071
|
+
_context11.next = 21;
|
|
4816
5072
|
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
4817
5073
|
connectionId: connectionId,
|
|
4818
5074
|
name: integrationName
|
|
4819
5075
|
});
|
|
4820
5076
|
case 21:
|
|
4821
|
-
|
|
4822
|
-
if (!(
|
|
4823
|
-
|
|
5077
|
+
_context11.t1 = _yield$mastra$dataLay2 = _context11.sent;
|
|
5078
|
+
if (!(_context11.t1 == null)) {
|
|
5079
|
+
_context11.next = 26;
|
|
4824
5080
|
break;
|
|
4825
5081
|
}
|
|
4826
|
-
|
|
4827
|
-
|
|
5082
|
+
_context11.t2 = void 0;
|
|
5083
|
+
_context11.next = 27;
|
|
4828
5084
|
break;
|
|
4829
5085
|
case 26:
|
|
4830
|
-
|
|
5086
|
+
_context11.t2 = _yield$mastra$dataLay2.id;
|
|
4831
5087
|
case 27:
|
|
4832
|
-
|
|
4833
|
-
if (
|
|
4834
|
-
|
|
5088
|
+
_context11.t0 = _context11.t2;
|
|
5089
|
+
if (_context11.t0) {
|
|
5090
|
+
_context11.next = 30;
|
|
4835
5091
|
break;
|
|
4836
5092
|
}
|
|
4837
|
-
|
|
5093
|
+
_context11.t0 = '';
|
|
4838
5094
|
case 30:
|
|
4839
|
-
k_id =
|
|
5095
|
+
k_id = _context11.t0;
|
|
4840
5096
|
if (!(!k_id && integrationName === systemName)) {
|
|
4841
|
-
|
|
5097
|
+
_context11.next = 36;
|
|
4842
5098
|
break;
|
|
4843
5099
|
}
|
|
4844
|
-
|
|
5100
|
+
_context11.next = 34;
|
|
4845
5101
|
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4846
5102
|
connection: {
|
|
4847
5103
|
connectionId: connectionId,
|
|
@@ -4854,38 +5110,38 @@ function _executeGenericVectorSync() {
|
|
|
4854
5110
|
}
|
|
4855
5111
|
});
|
|
4856
5112
|
case 34:
|
|
4857
|
-
connection =
|
|
5113
|
+
connection = _context11.sent;
|
|
4858
5114
|
k_id = connection.id;
|
|
4859
5115
|
case 36:
|
|
4860
5116
|
if (k_id) {
|
|
4861
|
-
|
|
5117
|
+
_context11.next = 39;
|
|
4862
5118
|
break;
|
|
4863
5119
|
}
|
|
4864
5120
|
console.error('Error bootstrapping shit');
|
|
4865
|
-
return
|
|
5121
|
+
return _context11.abrupt("return");
|
|
4866
5122
|
case 39:
|
|
4867
|
-
|
|
5123
|
+
_loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
|
|
4868
5124
|
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4869
5125
|
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4870
|
-
return _regeneratorRuntime().wrap(function
|
|
4871
|
-
while (1) switch (
|
|
5126
|
+
return _regeneratorRuntime().wrap(function _loop4$(_context10) {
|
|
5127
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
4872
5128
|
case 0:
|
|
4873
|
-
entity =
|
|
4874
|
-
|
|
5129
|
+
entity = _step6.value;
|
|
5130
|
+
_context10.next = 3;
|
|
4875
5131
|
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4876
5132
|
k_id: k_id,
|
|
4877
5133
|
type: entity.name
|
|
4878
5134
|
});
|
|
4879
5135
|
case 3:
|
|
4880
|
-
entityRecords =
|
|
5136
|
+
entityRecords = _context10.sent;
|
|
4881
5137
|
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4882
5138
|
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4883
|
-
|
|
5139
|
+
_context10.next = 23;
|
|
4884
5140
|
break;
|
|
4885
5141
|
}
|
|
4886
5142
|
// @TODO: SYNC THEM
|
|
4887
5143
|
console.error('NO RECORDS');
|
|
4888
|
-
|
|
5144
|
+
_context10.next = 9;
|
|
4889
5145
|
return mastra.triggerEvent({
|
|
4890
5146
|
key: entity.syncEvent,
|
|
4891
5147
|
data: {},
|
|
@@ -4894,40 +5150,40 @@ function _executeGenericVectorSync() {
|
|
|
4894
5150
|
}
|
|
4895
5151
|
});
|
|
4896
5152
|
case 9:
|
|
4897
|
-
_yield$mastra$trigger2 =
|
|
5153
|
+
_yield$mastra$trigger2 = _context10.sent;
|
|
4898
5154
|
_event2 = _yield$mastra$trigger2.event;
|
|
4899
5155
|
console.log(_event2, '####');
|
|
4900
|
-
|
|
5156
|
+
_context10.next = 14;
|
|
4901
5157
|
return _event2.subscribe();
|
|
4902
5158
|
case 14:
|
|
4903
|
-
res =
|
|
5159
|
+
res = _context10.sent;
|
|
4904
5160
|
console.log('Subscribe result', res);
|
|
4905
|
-
|
|
5161
|
+
_context10.next = 18;
|
|
4906
5162
|
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4907
5163
|
k_id: k_id,
|
|
4908
5164
|
type: entity.name
|
|
4909
5165
|
});
|
|
4910
5166
|
case 18:
|
|
4911
|
-
entityRecords =
|
|
5167
|
+
entityRecords = _context10.sent;
|
|
4912
5168
|
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4913
5169
|
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4914
|
-
|
|
5170
|
+
_context10.next = 23;
|
|
4915
5171
|
break;
|
|
4916
5172
|
}
|
|
4917
5173
|
console.error('NO RECORDS AFTER SYNC');
|
|
4918
|
-
return
|
|
5174
|
+
return _context10.abrupt("return", {
|
|
4919
5175
|
v: void 0
|
|
4920
5176
|
});
|
|
4921
5177
|
case 23:
|
|
4922
|
-
recordsMapped = records.map(function (
|
|
4923
|
-
var data =
|
|
4924
|
-
externalId =
|
|
5178
|
+
recordsMapped = records.map(function (_ref12) {
|
|
5179
|
+
var data = _ref12.data,
|
|
5180
|
+
externalId = _ref12.externalId;
|
|
4925
5181
|
return _extends({
|
|
4926
5182
|
id: externalId
|
|
4927
5183
|
}, _.pick(data, entity.fields));
|
|
4928
5184
|
});
|
|
4929
5185
|
console.log(recordsMapped, 'RECORDS');
|
|
4930
|
-
|
|
5186
|
+
_context10.next = 27;
|
|
4931
5187
|
return vp.createIndex({
|
|
4932
5188
|
suppressConflicts: true,
|
|
4933
5189
|
name: entity.name,
|
|
@@ -4941,93 +5197,93 @@ function _executeGenericVectorSync() {
|
|
|
4941
5197
|
}
|
|
4942
5198
|
});
|
|
4943
5199
|
case 27:
|
|
4944
|
-
|
|
5200
|
+
_context10.next = 29;
|
|
4945
5201
|
return delay$1(5000);
|
|
4946
5202
|
case 29:
|
|
4947
5203
|
entityTypeIndex = vp.index(entity.name);
|
|
4948
5204
|
console.log(entityTypeIndex, 'INDEX');
|
|
4949
|
-
|
|
4950
|
-
|
|
5205
|
+
_context10.prev = 31;
|
|
5206
|
+
_context10.next = 34;
|
|
4951
5207
|
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4952
|
-
var
|
|
5208
|
+
var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(record) {
|
|
4953
5209
|
var _yield$embed2, embedding;
|
|
4954
|
-
return _regeneratorRuntime().wrap(function
|
|
4955
|
-
while (1) switch (
|
|
5210
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context9) {
|
|
5211
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
4956
5212
|
case 0:
|
|
4957
|
-
|
|
5213
|
+
_context9.next = 2;
|
|
4958
5214
|
return ai.embed({
|
|
4959
5215
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4960
5216
|
value: JSON.stringify(record)
|
|
4961
5217
|
});
|
|
4962
5218
|
case 2:
|
|
4963
|
-
_yield$embed2 =
|
|
5219
|
+
_yield$embed2 = _context9.sent;
|
|
4964
5220
|
embedding = _yield$embed2.embedding;
|
|
4965
|
-
return
|
|
5221
|
+
return _context9.abrupt("return", {
|
|
4966
5222
|
id: record.id,
|
|
4967
5223
|
values: embedding,
|
|
4968
5224
|
metadata: record
|
|
4969
5225
|
});
|
|
4970
5226
|
case 5:
|
|
4971
5227
|
case "end":
|
|
4972
|
-
return
|
|
5228
|
+
return _context9.stop();
|
|
4973
5229
|
}
|
|
4974
|
-
},
|
|
5230
|
+
}, _callee7);
|
|
4975
5231
|
}));
|
|
4976
5232
|
return function (_x8) {
|
|
4977
|
-
return
|
|
5233
|
+
return _ref13.apply(this, arguments);
|
|
4978
5234
|
};
|
|
4979
5235
|
}())) != null ? _recordsMapped$map2 : []);
|
|
4980
5236
|
case 34:
|
|
4981
|
-
vectors =
|
|
5237
|
+
vectors = _context10.sent;
|
|
4982
5238
|
console.log('UPSERTING', vectors);
|
|
4983
5239
|
if (!(vectors.length > 0)) {
|
|
4984
|
-
|
|
5240
|
+
_context10.next = 39;
|
|
4985
5241
|
break;
|
|
4986
5242
|
}
|
|
4987
|
-
|
|
5243
|
+
_context10.next = 39;
|
|
4988
5244
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4989
5245
|
case 39:
|
|
4990
|
-
|
|
5246
|
+
_context10.next = 44;
|
|
4991
5247
|
break;
|
|
4992
5248
|
case 41:
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
console.error(
|
|
5249
|
+
_context10.prev = 41;
|
|
5250
|
+
_context10.t0 = _context10["catch"](31);
|
|
5251
|
+
console.error(_context10.t0);
|
|
4996
5252
|
case 44:
|
|
4997
|
-
return
|
|
5253
|
+
return _context10.abrupt("return", {
|
|
4998
5254
|
v: void 0
|
|
4999
5255
|
});
|
|
5000
5256
|
case 45:
|
|
5001
5257
|
case "end":
|
|
5002
|
-
return
|
|
5258
|
+
return _context10.stop();
|
|
5003
5259
|
}
|
|
5004
|
-
},
|
|
5260
|
+
}, _loop4, null, [[31, 41]]);
|
|
5005
5261
|
});
|
|
5006
|
-
|
|
5262
|
+
_iterator6 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5007
5263
|
case 41:
|
|
5008
|
-
if ((
|
|
5009
|
-
|
|
5264
|
+
if ((_step6 = _iterator6()).done) {
|
|
5265
|
+
_context11.next = 48;
|
|
5010
5266
|
break;
|
|
5011
5267
|
}
|
|
5012
|
-
return
|
|
5268
|
+
return _context11.delegateYield(_loop4(), "t3", 43);
|
|
5013
5269
|
case 43:
|
|
5014
|
-
|
|
5015
|
-
if (!
|
|
5016
|
-
|
|
5270
|
+
_ret4 = _context11.t3;
|
|
5271
|
+
if (!_ret4) {
|
|
5272
|
+
_context11.next = 46;
|
|
5017
5273
|
break;
|
|
5018
5274
|
}
|
|
5019
|
-
return
|
|
5275
|
+
return _context11.abrupt("return", _ret4.v);
|
|
5020
5276
|
case 46:
|
|
5021
|
-
|
|
5277
|
+
_context11.next = 41;
|
|
5022
5278
|
break;
|
|
5023
5279
|
case 48:
|
|
5024
|
-
|
|
5280
|
+
_context11.next = 16;
|
|
5025
5281
|
break;
|
|
5026
5282
|
case 50:
|
|
5027
5283
|
case "end":
|
|
5028
|
-
return
|
|
5284
|
+
return _context11.stop();
|
|
5029
5285
|
}
|
|
5030
|
-
},
|
|
5286
|
+
}, _callee8);
|
|
5031
5287
|
}));
|
|
5032
5288
|
return _executeGenericVectorSync.apply(this, arguments);
|
|
5033
5289
|
}
|
|
@@ -5035,11 +5291,11 @@ function executeVectorSync(_x3) {
|
|
|
5035
5291
|
return _executeVectorSync.apply(this, arguments);
|
|
5036
5292
|
}
|
|
5037
5293
|
function _executeVectorSync() {
|
|
5038
|
-
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5294
|
+
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref3) {
|
|
5039
5295
|
var _event$user3, _agent$knowledge_sour;
|
|
5040
|
-
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$knowledge_sour2,
|
|
5041
|
-
return _regeneratorRuntime().wrap(function
|
|
5042
|
-
while (1) switch (
|
|
5296
|
+
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$knowledge_sour2, _iterator7, _step7, _yield$mastra$dataLay3, _mastra$dataLayer9, vectorE, integrationName, k_id, _mastra$dataLayer10, connection, _loop5, _ret5, _iterator8, _step8;
|
|
5297
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context14) {
|
|
5298
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
5043
5299
|
case 0:
|
|
5044
5300
|
event = _ref3.event, mastra = _ref3.mastra;
|
|
5045
5301
|
agentDir = mastra.config.agents.agentDirPath;
|
|
@@ -5050,72 +5306,72 @@ function _executeVectorSync() {
|
|
|
5050
5306
|
connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
|
|
5051
5307
|
systemName = mastra.config.name;
|
|
5052
5308
|
if (agent.knowledge_sources.vector_provider) {
|
|
5053
|
-
|
|
5309
|
+
_context14.next = 8;
|
|
5054
5310
|
break;
|
|
5055
5311
|
}
|
|
5056
5312
|
console.error("No vector_provider defined for agent");
|
|
5057
|
-
return
|
|
5313
|
+
return _context14.abrupt("return");
|
|
5058
5314
|
case 8:
|
|
5059
5315
|
vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
|
|
5060
5316
|
if (vp) {
|
|
5061
|
-
|
|
5317
|
+
_context14.next = 12;
|
|
5062
5318
|
break;
|
|
5063
5319
|
}
|
|
5064
5320
|
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
|
|
5065
|
-
return
|
|
5321
|
+
return _context14.abrupt("return");
|
|
5066
5322
|
case 12:
|
|
5067
5323
|
if (process.env.OPENAI_API_KEY) {
|
|
5068
|
-
|
|
5324
|
+
_context14.next = 15;
|
|
5069
5325
|
break;
|
|
5070
5326
|
}
|
|
5071
5327
|
console.error('NO OPENAI_API_KEY');
|
|
5072
|
-
return
|
|
5328
|
+
return _context14.abrupt("return");
|
|
5073
5329
|
case 15:
|
|
5074
5330
|
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
5075
|
-
|
|
5331
|
+
_context14.next = 18;
|
|
5076
5332
|
break;
|
|
5077
5333
|
}
|
|
5078
5334
|
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
5079
|
-
return
|
|
5335
|
+
return _context14.abrupt("return");
|
|
5080
5336
|
case 18:
|
|
5081
|
-
|
|
5337
|
+
_iterator7 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
5082
5338
|
case 19:
|
|
5083
|
-
if ((
|
|
5084
|
-
|
|
5339
|
+
if ((_step7 = _iterator7()).done) {
|
|
5340
|
+
_context14.next = 53;
|
|
5085
5341
|
break;
|
|
5086
5342
|
}
|
|
5087
|
-
vectorE =
|
|
5343
|
+
vectorE = _step7.value;
|
|
5088
5344
|
integrationName = vectorE.integration;
|
|
5089
|
-
|
|
5345
|
+
_context14.next = 24;
|
|
5090
5346
|
return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
|
|
5091
5347
|
connectionId: connectionId,
|
|
5092
5348
|
name: integrationName
|
|
5093
5349
|
});
|
|
5094
5350
|
case 24:
|
|
5095
|
-
|
|
5096
|
-
if (!(
|
|
5097
|
-
|
|
5351
|
+
_context14.t1 = _yield$mastra$dataLay3 = _context14.sent;
|
|
5352
|
+
if (!(_context14.t1 == null)) {
|
|
5353
|
+
_context14.next = 29;
|
|
5098
5354
|
break;
|
|
5099
5355
|
}
|
|
5100
|
-
|
|
5101
|
-
|
|
5356
|
+
_context14.t2 = void 0;
|
|
5357
|
+
_context14.next = 30;
|
|
5102
5358
|
break;
|
|
5103
5359
|
case 29:
|
|
5104
|
-
|
|
5360
|
+
_context14.t2 = _yield$mastra$dataLay3.id;
|
|
5105
5361
|
case 30:
|
|
5106
|
-
|
|
5107
|
-
if (
|
|
5108
|
-
|
|
5362
|
+
_context14.t0 = _context14.t2;
|
|
5363
|
+
if (_context14.t0) {
|
|
5364
|
+
_context14.next = 33;
|
|
5109
5365
|
break;
|
|
5110
5366
|
}
|
|
5111
|
-
|
|
5367
|
+
_context14.t0 = '';
|
|
5112
5368
|
case 33:
|
|
5113
|
-
k_id =
|
|
5369
|
+
k_id = _context14.t0;
|
|
5114
5370
|
if (!(!k_id && integrationName === systemName)) {
|
|
5115
|
-
|
|
5371
|
+
_context14.next = 39;
|
|
5116
5372
|
break;
|
|
5117
5373
|
}
|
|
5118
|
-
|
|
5374
|
+
_context14.next = 37;
|
|
5119
5375
|
return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
|
|
5120
5376
|
connection: {
|
|
5121
5377
|
connectionId: connectionId,
|
|
@@ -5128,38 +5384,38 @@ function _executeVectorSync() {
|
|
|
5128
5384
|
}
|
|
5129
5385
|
});
|
|
5130
5386
|
case 37:
|
|
5131
|
-
connection =
|
|
5387
|
+
connection = _context14.sent;
|
|
5132
5388
|
k_id = connection.id;
|
|
5133
5389
|
case 39:
|
|
5134
5390
|
if (k_id) {
|
|
5135
|
-
|
|
5391
|
+
_context14.next = 42;
|
|
5136
5392
|
break;
|
|
5137
5393
|
}
|
|
5138
5394
|
console.error('Error bootstrapping shit');
|
|
5139
|
-
return
|
|
5395
|
+
return _context14.abrupt("return");
|
|
5140
5396
|
case 42:
|
|
5141
|
-
|
|
5397
|
+
_loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
|
|
5142
5398
|
var _mastra$dataLayer11, _entityRecords5, _records5;
|
|
5143
5399
|
var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
|
|
5144
|
-
return _regeneratorRuntime().wrap(function
|
|
5145
|
-
while (1) switch (
|
|
5400
|
+
return _regeneratorRuntime().wrap(function _loop5$(_context13) {
|
|
5401
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
5146
5402
|
case 0:
|
|
5147
|
-
entity =
|
|
5148
|
-
|
|
5403
|
+
entity = _step8.value;
|
|
5404
|
+
_context13.next = 3;
|
|
5149
5405
|
return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
|
|
5150
5406
|
k_id: k_id,
|
|
5151
5407
|
type: entity.name
|
|
5152
5408
|
});
|
|
5153
5409
|
case 3:
|
|
5154
|
-
entityRecords =
|
|
5410
|
+
entityRecords = _context13.sent;
|
|
5155
5411
|
records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
|
|
5156
5412
|
if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
|
|
5157
|
-
|
|
5413
|
+
_context13.next = 23;
|
|
5158
5414
|
break;
|
|
5159
5415
|
}
|
|
5160
5416
|
// @TODO: SYNC THEM
|
|
5161
5417
|
console.error('NO RECORDS');
|
|
5162
|
-
|
|
5418
|
+
_context13.next = 9;
|
|
5163
5419
|
return mastra.triggerEvent({
|
|
5164
5420
|
key: entity.syncEvent,
|
|
5165
5421
|
data: {},
|
|
@@ -5168,40 +5424,40 @@ function _executeVectorSync() {
|
|
|
5168
5424
|
}
|
|
5169
5425
|
});
|
|
5170
5426
|
case 9:
|
|
5171
|
-
_yield$mastra$trigger3 =
|
|
5427
|
+
_yield$mastra$trigger3 = _context13.sent;
|
|
5172
5428
|
_event3 = _yield$mastra$trigger3.event;
|
|
5173
5429
|
console.log(_event3, '####');
|
|
5174
|
-
|
|
5430
|
+
_context13.next = 14;
|
|
5175
5431
|
return _event3.subscribe();
|
|
5176
5432
|
case 14:
|
|
5177
|
-
res =
|
|
5433
|
+
res = _context13.sent;
|
|
5178
5434
|
console.log('Subscribe result', res);
|
|
5179
|
-
|
|
5435
|
+
_context13.next = 18;
|
|
5180
5436
|
return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
|
|
5181
5437
|
k_id: k_id,
|
|
5182
5438
|
type: entity.name
|
|
5183
5439
|
});
|
|
5184
5440
|
case 18:
|
|
5185
|
-
entityRecords =
|
|
5441
|
+
entityRecords = _context13.sent;
|
|
5186
5442
|
records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
|
|
5187
5443
|
if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
|
|
5188
|
-
|
|
5444
|
+
_context13.next = 23;
|
|
5189
5445
|
break;
|
|
5190
5446
|
}
|
|
5191
5447
|
console.error('NO RECORDS AFTER SYNC');
|
|
5192
|
-
return
|
|
5448
|
+
return _context13.abrupt("return", {
|
|
5193
5449
|
v: void 0
|
|
5194
5450
|
});
|
|
5195
5451
|
case 23:
|
|
5196
|
-
recordsMapped = records.map(function (
|
|
5197
|
-
var data =
|
|
5198
|
-
externalId =
|
|
5452
|
+
recordsMapped = records.map(function (_ref14) {
|
|
5453
|
+
var data = _ref14.data,
|
|
5454
|
+
externalId = _ref14.externalId;
|
|
5199
5455
|
return _extends({
|
|
5200
5456
|
id: externalId
|
|
5201
5457
|
}, _.pick(data, entity.fields));
|
|
5202
5458
|
});
|
|
5203
5459
|
console.log(recordsMapped, 'RECORDS');
|
|
5204
|
-
|
|
5460
|
+
_context13.next = 27;
|
|
5205
5461
|
return vp.createIndex({
|
|
5206
5462
|
suppressConflicts: true,
|
|
5207
5463
|
name: entity.name,
|
|
@@ -5217,88 +5473,88 @@ function _executeVectorSync() {
|
|
|
5217
5473
|
case 27:
|
|
5218
5474
|
entityTypeIndex = vp.index(entity.name);
|
|
5219
5475
|
console.log(entityTypeIndex, 'INDEX');
|
|
5220
|
-
|
|
5221
|
-
|
|
5476
|
+
_context13.prev = 29;
|
|
5477
|
+
_context13.next = 32;
|
|
5222
5478
|
return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
|
|
5223
|
-
var
|
|
5479
|
+
var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
|
|
5224
5480
|
var _yield$embed3, embedding;
|
|
5225
|
-
return _regeneratorRuntime().wrap(function
|
|
5226
|
-
while (1) switch (
|
|
5481
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context12) {
|
|
5482
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
5227
5483
|
case 0:
|
|
5228
|
-
|
|
5484
|
+
_context12.next = 2;
|
|
5229
5485
|
return ai.embed({
|
|
5230
5486
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
5231
5487
|
value: JSON.stringify(record)
|
|
5232
5488
|
});
|
|
5233
5489
|
case 2:
|
|
5234
|
-
_yield$embed3 =
|
|
5490
|
+
_yield$embed3 = _context12.sent;
|
|
5235
5491
|
embedding = _yield$embed3.embedding;
|
|
5236
|
-
return
|
|
5492
|
+
return _context12.abrupt("return", {
|
|
5237
5493
|
id: record.id,
|
|
5238
5494
|
values: embedding,
|
|
5239
5495
|
metadata: record
|
|
5240
5496
|
});
|
|
5241
5497
|
case 5:
|
|
5242
5498
|
case "end":
|
|
5243
|
-
return
|
|
5499
|
+
return _context12.stop();
|
|
5244
5500
|
}
|
|
5245
|
-
},
|
|
5501
|
+
}, _callee9);
|
|
5246
5502
|
}));
|
|
5247
5503
|
return function (_x9) {
|
|
5248
|
-
return
|
|
5504
|
+
return _ref15.apply(this, arguments);
|
|
5249
5505
|
};
|
|
5250
5506
|
}())) != null ? _recordsMapped$map3 : []);
|
|
5251
5507
|
case 32:
|
|
5252
|
-
vectors =
|
|
5508
|
+
vectors = _context13.sent;
|
|
5253
5509
|
console.log('UPSERTING', vectors);
|
|
5254
5510
|
if (!(vectors.length > 0)) {
|
|
5255
|
-
|
|
5511
|
+
_context13.next = 37;
|
|
5256
5512
|
break;
|
|
5257
5513
|
}
|
|
5258
|
-
|
|
5514
|
+
_context13.next = 37;
|
|
5259
5515
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
5260
5516
|
case 37:
|
|
5261
|
-
|
|
5517
|
+
_context13.next = 42;
|
|
5262
5518
|
break;
|
|
5263
5519
|
case 39:
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
console.error(
|
|
5520
|
+
_context13.prev = 39;
|
|
5521
|
+
_context13.t0 = _context13["catch"](29);
|
|
5522
|
+
console.error(_context13.t0);
|
|
5267
5523
|
case 42:
|
|
5268
|
-
return
|
|
5524
|
+
return _context13.abrupt("return", {
|
|
5269
5525
|
v: void 0
|
|
5270
5526
|
});
|
|
5271
5527
|
case 43:
|
|
5272
5528
|
case "end":
|
|
5273
|
-
return
|
|
5529
|
+
return _context13.stop();
|
|
5274
5530
|
}
|
|
5275
|
-
},
|
|
5531
|
+
}, _loop5, null, [[29, 39]]);
|
|
5276
5532
|
});
|
|
5277
|
-
|
|
5533
|
+
_iterator8 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5278
5534
|
case 44:
|
|
5279
|
-
if ((
|
|
5280
|
-
|
|
5535
|
+
if ((_step8 = _iterator8()).done) {
|
|
5536
|
+
_context14.next = 51;
|
|
5281
5537
|
break;
|
|
5282
5538
|
}
|
|
5283
|
-
return
|
|
5539
|
+
return _context14.delegateYield(_loop5(), "t3", 46);
|
|
5284
5540
|
case 46:
|
|
5285
|
-
|
|
5286
|
-
if (!
|
|
5287
|
-
|
|
5541
|
+
_ret5 = _context14.t3;
|
|
5542
|
+
if (!_ret5) {
|
|
5543
|
+
_context14.next = 49;
|
|
5288
5544
|
break;
|
|
5289
5545
|
}
|
|
5290
|
-
return
|
|
5546
|
+
return _context14.abrupt("return", _ret5.v);
|
|
5291
5547
|
case 49:
|
|
5292
|
-
|
|
5548
|
+
_context14.next = 44;
|
|
5293
5549
|
break;
|
|
5294
5550
|
case 51:
|
|
5295
|
-
|
|
5551
|
+
_context14.next = 19;
|
|
5296
5552
|
break;
|
|
5297
5553
|
case 53:
|
|
5298
5554
|
case "end":
|
|
5299
|
-
return
|
|
5555
|
+
return _context14.stop();
|
|
5300
5556
|
}
|
|
5301
|
-
},
|
|
5557
|
+
}, _callee10);
|
|
5302
5558
|
}));
|
|
5303
5559
|
return _executeVectorSync.apply(this, arguments);
|
|
5304
5560
|
}
|
|
@@ -5306,285 +5562,181 @@ function vectorQueryEngine(_x4) {
|
|
|
5306
5562
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5307
5563
|
}
|
|
5308
5564
|
function _vectorQueryEngine() {
|
|
5309
|
-
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5565
|
+
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref4) {
|
|
5310
5566
|
var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
|
|
5311
|
-
return _regeneratorRuntime().wrap(function
|
|
5312
|
-
while (1) switch (
|
|
5567
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context15) {
|
|
5568
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
5313
5569
|
case 0:
|
|
5314
5570
|
vector_provider = _ref4.vector_provider, _ref4$topK = _ref4.topK, topK = _ref4$topK === void 0 ? 1 : _ref4$topK, indexName = _ref4.indexName, content = _ref4.content, entityType = _ref4.entityType;
|
|
5315
5571
|
vp = getVectorProvider(vector_provider);
|
|
5316
5572
|
if (vp) {
|
|
5317
|
-
|
|
5573
|
+
_context15.next = 5;
|
|
5318
5574
|
break;
|
|
5319
5575
|
}
|
|
5320
5576
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
5321
|
-
return
|
|
5577
|
+
return _context15.abrupt("return");
|
|
5322
5578
|
case 5:
|
|
5323
5579
|
index = vp.index(indexName);
|
|
5324
|
-
|
|
5580
|
+
_context15.next = 8;
|
|
5325
5581
|
return ai.embed({
|
|
5326
5582
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
5327
5583
|
value: content
|
|
5328
5584
|
});
|
|
5329
5585
|
case 8:
|
|
5330
|
-
_yield$embed4 =
|
|
5586
|
+
_yield$embed4 = _context15.sent;
|
|
5331
5587
|
embedding = _yield$embed4.embedding;
|
|
5332
5588
|
console.log(embedding, 'EMBEDDING');
|
|
5333
|
-
|
|
5589
|
+
_context15.next = 13;
|
|
5334
5590
|
return index.namespace(entityType).query({
|
|
5335
5591
|
vector: embedding,
|
|
5336
5592
|
topK: topK,
|
|
5337
5593
|
includeMetadata: true
|
|
5338
5594
|
});
|
|
5339
5595
|
case 13:
|
|
5340
|
-
queryResponse =
|
|
5341
|
-
return
|
|
5596
|
+
queryResponse = _context15.sent;
|
|
5597
|
+
return _context15.abrupt("return", queryResponse);
|
|
5342
5598
|
case 15:
|
|
5343
5599
|
case "end":
|
|
5344
|
-
return
|
|
5600
|
+
return _context15.stop();
|
|
5345
5601
|
}
|
|
5346
|
-
},
|
|
5602
|
+
}, _callee11);
|
|
5347
5603
|
}));
|
|
5348
5604
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5349
5605
|
}
|
|
5350
|
-
var
|
|
5351
|
-
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5352
|
-
var
|
|
5353
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5354
|
-
while (1) switch (_context.prev = _context.next) {
|
|
5355
|
-
case 0:
|
|
5356
|
-
_context.prev = 0;
|
|
5357
|
-
_context.next = 3;
|
|
5358
|
-
return fetch('https://api.pinecone.io/indexes', {
|
|
5359
|
-
method: 'GET',
|
|
5360
|
-
headers: {
|
|
5361
|
-
'Api-Key': process.env.PINECONE_API_KEY,
|
|
5362
|
-
'X-Pinecone-API-Version': 'unstable'
|
|
5363
|
-
},
|
|
5364
|
-
cache: 'no-store'
|
|
5365
|
-
});
|
|
5366
|
-
case 3:
|
|
5367
|
-
response = _context.sent;
|
|
5368
|
-
_context.next = 6;
|
|
5369
|
-
return response.json();
|
|
5370
|
-
case 6:
|
|
5371
|
-
_context.t0 = _context.sent;
|
|
5372
|
-
if (_context.t0) {
|
|
5373
|
-
_context.next = 9;
|
|
5374
|
-
break;
|
|
5375
|
-
}
|
|
5376
|
-
_context.t0 = {};
|
|
5377
|
-
case 9:
|
|
5378
|
-
_ref6 = _context.t0;
|
|
5379
|
-
indexes = _ref6.indexes;
|
|
5380
|
-
return _context.abrupt("return", indexes);
|
|
5381
|
-
case 14:
|
|
5382
|
-
_context.prev = 14;
|
|
5383
|
-
_context.t1 = _context["catch"](0);
|
|
5384
|
-
console.log('Error fetching indexes using JS fetch====', _context.t1);
|
|
5385
|
-
case 17:
|
|
5386
|
-
case "end":
|
|
5387
|
-
return _context.stop();
|
|
5388
|
-
}
|
|
5389
|
-
}, _callee, null, [[0, 14]]);
|
|
5390
|
-
}));
|
|
5391
|
-
return function fetchPineconeIndexes() {
|
|
5392
|
-
return _ref5.apply(this, arguments);
|
|
5393
|
-
};
|
|
5394
|
-
}();
|
|
5395
|
-
var fetchPineconeIndexStats = /*#__PURE__*/function () {
|
|
5396
|
-
var _ref7 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(host) {
|
|
5397
|
-
var response, data;
|
|
5606
|
+
var getPineconeIndices = /*#__PURE__*/function () {
|
|
5607
|
+
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
5608
|
+
var vectorLayer, indexes, indexesWithStats;
|
|
5398
5609
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5399
5610
|
while (1) switch (_context2.prev = _context2.next) {
|
|
5400
5611
|
case 0:
|
|
5401
|
-
|
|
5612
|
+
vectorLayer = new VectorLayer();
|
|
5402
5613
|
_context2.next = 3;
|
|
5403
|
-
return
|
|
5404
|
-
method: 'GET',
|
|
5405
|
-
headers: {
|
|
5406
|
-
'Api-Key': process.env.PINECONE_API_KEY,
|
|
5407
|
-
'X-Pinecone-API-Version': '2024-07'
|
|
5408
|
-
},
|
|
5409
|
-
cache: 'no-store'
|
|
5410
|
-
});
|
|
5614
|
+
return vectorLayer.fetchPineconeIndexes();
|
|
5411
5615
|
case 3:
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
return response.json();
|
|
5415
|
-
case 6:
|
|
5416
|
-
_context2.t0 = _context2.sent;
|
|
5417
|
-
if (_context2.t0) {
|
|
5616
|
+
indexes = _context2.sent;
|
|
5617
|
+
if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
|
|
5418
5618
|
_context2.next = 9;
|
|
5419
5619
|
break;
|
|
5420
5620
|
}
|
|
5421
|
-
_context2.
|
|
5621
|
+
_context2.next = 7;
|
|
5622
|
+
return Promise.all(indexes.map(/*#__PURE__*/function () {
|
|
5623
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(index) {
|
|
5624
|
+
var stats, namespaces;
|
|
5625
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5626
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5627
|
+
case 0:
|
|
5628
|
+
_context.next = 2;
|
|
5629
|
+
return vectorLayer.fetchPineconeIndexStats(index.host);
|
|
5630
|
+
case 2:
|
|
5631
|
+
stats = _context.sent;
|
|
5632
|
+
namespaces = [];
|
|
5633
|
+
if (stats != null && stats.namespaces) {
|
|
5634
|
+
namespaces = Object.keys(stats.namespaces);
|
|
5635
|
+
}
|
|
5636
|
+
return _context.abrupt("return", _extends({}, index, {
|
|
5637
|
+
namespaces: namespaces
|
|
5638
|
+
}));
|
|
5639
|
+
case 6:
|
|
5640
|
+
case "end":
|
|
5641
|
+
return _context.stop();
|
|
5642
|
+
}
|
|
5643
|
+
}, _callee);
|
|
5644
|
+
}));
|
|
5645
|
+
return function (_x5) {
|
|
5646
|
+
return _ref6.apply(this, arguments);
|
|
5647
|
+
};
|
|
5648
|
+
}()));
|
|
5649
|
+
case 7:
|
|
5650
|
+
indexesWithStats = _context2.sent;
|
|
5651
|
+
return _context2.abrupt("return", indexesWithStats);
|
|
5422
5652
|
case 9:
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
case 13:
|
|
5426
|
-
_context2.prev = 13;
|
|
5427
|
-
_context2.t1 = _context2["catch"](0);
|
|
5428
|
-
console.log('Error fetching indexes using JS fetch====', _context2.t1);
|
|
5429
|
-
case 16:
|
|
5653
|
+
return _context2.abrupt("return", []);
|
|
5654
|
+
case 10:
|
|
5430
5655
|
case "end":
|
|
5431
5656
|
return _context2.stop();
|
|
5432
5657
|
}
|
|
5433
|
-
}, _callee2
|
|
5658
|
+
}, _callee2);
|
|
5434
5659
|
}));
|
|
5435
|
-
return function
|
|
5436
|
-
return
|
|
5660
|
+
return function getPineconeIndices() {
|
|
5661
|
+
return _ref5.apply(this, arguments);
|
|
5437
5662
|
};
|
|
5438
5663
|
}();
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5664
|
+
function getVectorQueryApis(_ref7) {
|
|
5665
|
+
var mastra = _ref7.mastra;
|
|
5666
|
+
var vectorProvider = mastra.config.agents.vectorProvider;
|
|
5667
|
+
if (!vectorProvider) {
|
|
5668
|
+
console.error('NO VECTOR PROVIDER');
|
|
5669
|
+
return [];
|
|
5670
|
+
}
|
|
5671
|
+
var vectorApis = [];
|
|
5672
|
+
var _loop = function _loop() {
|
|
5673
|
+
var provider = _step.value;
|
|
5674
|
+
if (provider.name.toUpperCase() === 'PINECONE') {
|
|
5675
|
+
var config = getPineconeConfig({
|
|
5676
|
+
dir: provider.dirPath
|
|
5677
|
+
});
|
|
5678
|
+
if (!config) {
|
|
5679
|
+
return {
|
|
5680
|
+
v: []
|
|
5681
|
+
};
|
|
5682
|
+
}
|
|
5683
|
+
config == null || config.forEach(function (index) {
|
|
5684
|
+
if (index != null && index.namespaces) {
|
|
5685
|
+
index == null || index.namespaces.forEach(function (namespace) {
|
|
5686
|
+
vectorApis.push({
|
|
5687
|
+
integrationName: mastra.config.name,
|
|
5688
|
+
type: "vector_query_" + index.name + "_" + namespace,
|
|
5689
|
+
label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5690
|
+
description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5691
|
+
schema: zod.z.object({
|
|
5692
|
+
content: zod.z.string(),
|
|
5693
|
+
topResult: zod.z.number()
|
|
5694
|
+
}),
|
|
5695
|
+
executor: function () {
|
|
5696
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref8) {
|
|
5697
|
+
var data, res;
|
|
5698
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5699
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5700
|
+
case 0:
|
|
5701
|
+
data = _ref8.data;
|
|
5702
|
+
_context3.next = 3;
|
|
5703
|
+
return vectorQueryEngine({
|
|
5704
|
+
vector_provider: provider.name,
|
|
5705
|
+
indexName: index.name,
|
|
5706
|
+
content: data.content,
|
|
5707
|
+
topK: data.topResult || 1,
|
|
5708
|
+
entityType: namespace
|
|
5709
|
+
});
|
|
5710
|
+
case 3:
|
|
5711
|
+
res = _context3.sent;
|
|
5712
|
+
console.log(JSON.stringify({
|
|
5713
|
+
res: res
|
|
5714
|
+
}, null, 2));
|
|
5715
|
+
// @TODO: make this a proper response
|
|
5716
|
+
return _context3.abrupt("return", res);
|
|
5717
|
+
case 6:
|
|
5718
|
+
case "end":
|
|
5719
|
+
return _context3.stop();
|
|
5720
|
+
}
|
|
5721
|
+
}, _callee3);
|
|
5722
|
+
}));
|
|
5723
|
+
function executor(_x6) {
|
|
5724
|
+
return _executor.apply(this, arguments);
|
|
5481
5725
|
}
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context13) {
|
|
5487
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
5488
|
-
case 0:
|
|
5489
|
-
_context13.next = 2;
|
|
5490
|
-
return fetchPineconeIndexStats(index.host);
|
|
5491
|
-
case 2:
|
|
5492
|
-
stats = _context13.sent;
|
|
5493
|
-
namespaces = [];
|
|
5494
|
-
if (stats != null && stats.namespaces) {
|
|
5495
|
-
namespaces = Object.keys(stats.namespaces);
|
|
5496
|
-
}
|
|
5497
|
-
return _context13.abrupt("return", _extends({}, index, {
|
|
5498
|
-
namespaces: namespaces
|
|
5499
|
-
}));
|
|
5500
|
-
case 6:
|
|
5501
|
-
case "end":
|
|
5502
|
-
return _context13.stop();
|
|
5503
|
-
}
|
|
5504
|
-
}, _callee10);
|
|
5505
|
-
}));
|
|
5506
|
-
return function (_x10) {
|
|
5507
|
-
return _ref15.apply(this, arguments);
|
|
5508
|
-
};
|
|
5509
|
-
}()));
|
|
5510
|
-
case 10:
|
|
5511
|
-
indexesWithStats = _context15.sent;
|
|
5512
|
-
pineconeIndexes = indexesWithStats;
|
|
5513
|
-
case 12:
|
|
5514
|
-
pineconeIndexes.forEach(function (index) {
|
|
5515
|
-
if (index != null && index.namespaces) {
|
|
5516
|
-
index == null || index.namespaces.forEach(function (namespace) {
|
|
5517
|
-
vectorApis.push({
|
|
5518
|
-
integrationName: 'SYSTEM',
|
|
5519
|
-
type: "vector_query_" + index.name + "_" + namespace,
|
|
5520
|
-
label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5521
|
-
description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5522
|
-
schema: zod.z.object({
|
|
5523
|
-
content: zod.z.string(),
|
|
5524
|
-
topResult: zod.z.number()
|
|
5525
|
-
}),
|
|
5526
|
-
executor: function () {
|
|
5527
|
-
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref16) {
|
|
5528
|
-
var data, res;
|
|
5529
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context14) {
|
|
5530
|
-
while (1) switch (_context14.prev = _context14.next) {
|
|
5531
|
-
case 0:
|
|
5532
|
-
data = _ref16.data;
|
|
5533
|
-
_context14.next = 3;
|
|
5534
|
-
return vectorQueryEngine({
|
|
5535
|
-
vector_provider: provider.name,
|
|
5536
|
-
indexName: index.name,
|
|
5537
|
-
content: data.content,
|
|
5538
|
-
topK: data.topResult || 1,
|
|
5539
|
-
entityType: namespace
|
|
5540
|
-
});
|
|
5541
|
-
case 3:
|
|
5542
|
-
res = _context14.sent;
|
|
5543
|
-
console.log(JSON.stringify({
|
|
5544
|
-
res: res
|
|
5545
|
-
}, null, 2));
|
|
5546
|
-
// @TODO: make this a proper response
|
|
5547
|
-
return _context14.abrupt("return", res);
|
|
5548
|
-
case 6:
|
|
5549
|
-
case "end":
|
|
5550
|
-
return _context14.stop();
|
|
5551
|
-
}
|
|
5552
|
-
}, _callee11);
|
|
5553
|
-
}));
|
|
5554
|
-
function executor(_x11) {
|
|
5555
|
-
return _executor.apply(this, arguments);
|
|
5556
|
-
}
|
|
5557
|
-
return executor;
|
|
5558
|
-
}()
|
|
5559
|
-
});
|
|
5560
|
-
});
|
|
5561
|
-
}
|
|
5562
|
-
});
|
|
5563
|
-
case 13:
|
|
5564
|
-
case "end":
|
|
5565
|
-
return _context15.stop();
|
|
5566
|
-
}
|
|
5567
|
-
}, _loop4);
|
|
5568
|
-
});
|
|
5569
|
-
_iterator8 = _createForOfIteratorHelperLoose(vectorProvider);
|
|
5570
|
-
case 8:
|
|
5571
|
-
if ((_step8 = _iterator8()).done) {
|
|
5572
|
-
_context16.next = 12;
|
|
5573
|
-
break;
|
|
5726
|
+
return executor;
|
|
5727
|
+
}()
|
|
5728
|
+
});
|
|
5729
|
+
});
|
|
5574
5730
|
}
|
|
5575
|
-
|
|
5576
|
-
case 10:
|
|
5577
|
-
_context16.next = 8;
|
|
5578
|
-
break;
|
|
5579
|
-
case 12:
|
|
5580
|
-
return _context16.abrupt("return", vectorApis);
|
|
5581
|
-
case 13:
|
|
5582
|
-
case "end":
|
|
5583
|
-
return _context16.stop();
|
|
5731
|
+
});
|
|
5584
5732
|
}
|
|
5585
|
-
},
|
|
5586
|
-
|
|
5587
|
-
|
|
5733
|
+
},
|
|
5734
|
+
_ret;
|
|
5735
|
+
for (var _iterator = _createForOfIteratorHelperLoose(vectorProvider), _step; !(_step = _iterator()).done;) {
|
|
5736
|
+
_ret = _loop();
|
|
5737
|
+
if (_ret) return _ret.v;
|
|
5738
|
+
}
|
|
5739
|
+
return vectorApis;
|
|
5588
5740
|
}
|
|
5589
5741
|
function agentVectorSyncEvent() {
|
|
5590
5742
|
return {
|
|
@@ -6742,7 +6894,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6742
6894
|
});
|
|
6743
6895
|
// Register system apis
|
|
6744
6896
|
framework.__registerApis({
|
|
6745
|
-
apis: [].concat(
|
|
6897
|
+
apis: [].concat(getVectorQueryApis({
|
|
6898
|
+
mastra: framework
|
|
6899
|
+
}), getAgentSystemApis({
|
|
6746
6900
|
mastra: framework
|
|
6747
6901
|
}), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
|
|
6748
6902
|
return _extends({}, api, {
|
|
@@ -6802,15 +6956,6 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6802
6956
|
}()
|
|
6803
6957
|
}])
|
|
6804
6958
|
});
|
|
6805
|
-
getVectorQueryApis({
|
|
6806
|
-
mastra: framework
|
|
6807
|
-
}).then(function (d) {
|
|
6808
|
-
framework.__registerApis({
|
|
6809
|
-
apis: d
|
|
6810
|
-
});
|
|
6811
|
-
})["catch"](function (e) {
|
|
6812
|
-
console.error(e);
|
|
6813
|
-
});
|
|
6814
6959
|
// Register System events
|
|
6815
6960
|
framework.__registerEvents({
|
|
6816
6961
|
events: config.workflows.systemEvents
|
|
@@ -7686,6 +7831,7 @@ exports.generateSyncs = generateSyncs;
|
|
|
7686
7831
|
exports.getEntityKey = getEntityKey;
|
|
7687
7832
|
exports.getJSONField = getJSONField;
|
|
7688
7833
|
exports.getPath = getPath;
|
|
7834
|
+
exports.getPineconeIndices = getPineconeIndices;
|
|
7689
7835
|
exports.getResponseDataKey = getResponseDataKey;
|
|
7690
7836
|
exports.getUpstashLogs = getUpstashLogs;
|
|
7691
7837
|
exports.isLiteralObject = isLiteralObject;
|