@mastra/core 0.1.8 → 0.1.10
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/agent-apis.d.ts +1 -1
- package/dist/agents/agent-apis.d.ts.map +1 -1
- package/dist/agents/file-logger.d.ts +13 -1
- package/dist/agents/file-logger.d.ts.map +1 -1
- package/dist/agents/index.d.ts +2 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/openai/assistant.d.ts +9 -6
- package/dist/agents/openai/assistant.d.ts.map +1 -1
- package/dist/agents/utils.d.ts +1 -1
- package/dist/agents/utils.d.ts.map +1 -1
- package/dist/agents/vector-sync.d.ts +23 -24
- package/dist/agents/vector-sync.d.ts.map +1 -1
- package/dist/core.cjs.development.js +1920 -1011
- 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 +1920 -1012
- package/dist/core.esm.js.map +1 -1
- package/dist/data-access/index.d.ts.map +1 -1
- package/dist/framework.d.ts +71 -0
- 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 +10 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-access/index.d.ts +12 -1
- package/dist/vector-access/index.d.ts.map +1 -1
- package/dist/vector-access/types.d.ts +7 -0
- package/dist/vector-access/types.d.ts.map +1 -0
- package/package.json +3 -2
|
@@ -23,6 +23,7 @@ var ai = require('ai');
|
|
|
23
23
|
var pinecone = require('@pinecone-database/pinecone');
|
|
24
24
|
var OpenAI = require('openai');
|
|
25
25
|
var anthropic = require('@ai-sdk/anthropic');
|
|
26
|
+
var redis = require('@upstash/redis');
|
|
26
27
|
|
|
27
28
|
function _interopNamespaceDefault(e) {
|
|
28
29
|
var n = Object.create(null);
|
|
@@ -1666,47 +1667,53 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1666
1667
|
});
|
|
1667
1668
|
case 3:
|
|
1668
1669
|
dataInt = _context24.sent;
|
|
1669
|
-
|
|
1670
|
+
if (dataInt) {
|
|
1671
|
+
_context24.next = 6;
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
throw new Error("No connection found for " + name);
|
|
1675
|
+
case 6:
|
|
1676
|
+
_context24.next = 8;
|
|
1670
1677
|
return this.getEntityByConnectionAndType({
|
|
1671
1678
|
k_id: dataInt == null ? void 0 : dataInt.id,
|
|
1672
1679
|
type: type
|
|
1673
1680
|
});
|
|
1674
|
-
case
|
|
1681
|
+
case 8:
|
|
1675
1682
|
existingEntity = _context24.sent;
|
|
1676
1683
|
if (existingEntity) {
|
|
1677
|
-
_context24.next =
|
|
1684
|
+
_context24.next = 15;
|
|
1678
1685
|
break;
|
|
1679
1686
|
}
|
|
1680
|
-
_context24.next =
|
|
1687
|
+
_context24.next = 12;
|
|
1681
1688
|
return this.createEntity({
|
|
1682
1689
|
k_id: dataInt == null ? void 0 : dataInt.id,
|
|
1683
1690
|
type: type,
|
|
1684
1691
|
connectionId: connectionId
|
|
1685
1692
|
});
|
|
1686
|
-
case
|
|
1693
|
+
case 12:
|
|
1687
1694
|
existingEntity = _context24.sent;
|
|
1688
|
-
_context24.next =
|
|
1695
|
+
_context24.next = 15;
|
|
1689
1696
|
return this.addPropertiesToEntity({
|
|
1690
1697
|
entityId: (_existingEntity = existingEntity) == null ? void 0 : _existingEntity.id,
|
|
1691
1698
|
properties: properties
|
|
1692
1699
|
});
|
|
1693
|
-
case
|
|
1694
|
-
_context24.next =
|
|
1700
|
+
case 15:
|
|
1701
|
+
_context24.next = 17;
|
|
1695
1702
|
return this.mergeExternalRecordsForEntity({
|
|
1696
1703
|
entityId: (_existingEntity2 = existingEntity) == null ? void 0 : _existingEntity2.id,
|
|
1697
1704
|
records: data
|
|
1698
1705
|
});
|
|
1699
|
-
case
|
|
1706
|
+
case 17:
|
|
1700
1707
|
if (!lastSyncId) {
|
|
1701
|
-
_context24.next =
|
|
1708
|
+
_context24.next = 20;
|
|
1702
1709
|
break;
|
|
1703
1710
|
}
|
|
1704
|
-
_context24.next =
|
|
1711
|
+
_context24.next = 20;
|
|
1705
1712
|
return this.updateEntityLastSyncId({
|
|
1706
1713
|
entityId: (_existingEntity3 = existingEntity) == null ? void 0 : _existingEntity3.id,
|
|
1707
1714
|
syncId: lastSyncId
|
|
1708
1715
|
});
|
|
1709
|
-
case
|
|
1716
|
+
case 20:
|
|
1710
1717
|
case "end":
|
|
1711
1718
|
return _context24.stop();
|
|
1712
1719
|
}
|
|
@@ -2188,6 +2195,7 @@ exports.IntegrationCredentialType = void 0;
|
|
|
2188
2195
|
(function (IntegrationCredentialType) {
|
|
2189
2196
|
IntegrationCredentialType["OAUTH"] = "OAUTH";
|
|
2190
2197
|
IntegrationCredentialType["API_KEY"] = "API_KEY";
|
|
2198
|
+
IntegrationCredentialType["SYSTEM"] = "SYSTEM";
|
|
2191
2199
|
})(exports.IntegrationCredentialType || (exports.IntegrationCredentialType = {}));
|
|
2192
2200
|
var IntegrationFieldTypeEnum = {
|
|
2193
2201
|
SINGLE_LINE_TEXT: 'SINGLE_LINE_TEXT',
|
|
@@ -4254,11 +4262,16 @@ function getAgentDir(_ref) {
|
|
|
4254
4262
|
}
|
|
4255
4263
|
function listAgentsJson(_ref2) {
|
|
4256
4264
|
var agentDir = _ref2.agentDir;
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4265
|
+
try {
|
|
4266
|
+
var agentDirPath = getAgentDir({
|
|
4267
|
+
agentDir: agentDir
|
|
4268
|
+
});
|
|
4269
|
+
var agents = fs.readdirSync(agentDirPath);
|
|
4270
|
+
return agents;
|
|
4271
|
+
} catch (e) {
|
|
4272
|
+
console.error('No agent directory found:', agentDir);
|
|
4273
|
+
return;
|
|
4274
|
+
}
|
|
4262
4275
|
}
|
|
4263
4276
|
function getAgentFile(agentFilePath) {
|
|
4264
4277
|
try {
|
|
@@ -4288,21 +4301,182 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4288
4301
|
var _proto = VectorLayer.prototype;
|
|
4289
4302
|
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4290
4303
|
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4304
|
+
var inn;
|
|
4291
4305
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4292
4306
|
while (1) switch (_context.prev = _context.next) {
|
|
4293
4307
|
case 0:
|
|
4294
|
-
|
|
4295
|
-
|
|
4308
|
+
_context.prev = 0;
|
|
4309
|
+
_context.next = 3;
|
|
4310
|
+
return this.Pinecone.listIndexes();
|
|
4311
|
+
case 3:
|
|
4312
|
+
inn = _context.sent;
|
|
4313
|
+
console.log('inn====', {
|
|
4314
|
+
inn: inn
|
|
4315
|
+
});
|
|
4316
|
+
return _context.abrupt("return", inn);
|
|
4317
|
+
case 8:
|
|
4318
|
+
_context.prev = 8;
|
|
4319
|
+
_context.t0 = _context["catch"](0);
|
|
4320
|
+
console.log('error getting indexesss====', _context.t0);
|
|
4321
|
+
case 11:
|
|
4296
4322
|
case "end":
|
|
4297
4323
|
return _context.stop();
|
|
4298
4324
|
}
|
|
4299
|
-
}, _callee, this);
|
|
4325
|
+
}, _callee, this, [[0, 8]]);
|
|
4300
4326
|
}));
|
|
4301
4327
|
function getPineconeIndexes() {
|
|
4302
4328
|
return _getPineconeIndexes.apply(this, arguments);
|
|
4303
4329
|
}
|
|
4304
4330
|
return getPineconeIndexes;
|
|
4305
4331
|
}();
|
|
4332
|
+
_proto.createPineconeIndex = /*#__PURE__*/function () {
|
|
4333
|
+
var _createPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
4334
|
+
var name;
|
|
4335
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4336
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
4337
|
+
case 0:
|
|
4338
|
+
name = _ref.name;
|
|
4339
|
+
return _context2.abrupt("return", this.Pinecone.createIndex({
|
|
4340
|
+
suppressConflicts: true,
|
|
4341
|
+
name: name,
|
|
4342
|
+
dimension: 1536,
|
|
4343
|
+
metric: 'cosine',
|
|
4344
|
+
spec: {
|
|
4345
|
+
serverless: {
|
|
4346
|
+
cloud: 'aws',
|
|
4347
|
+
region: 'us-east-1'
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
}));
|
|
4351
|
+
case 2:
|
|
4352
|
+
case "end":
|
|
4353
|
+
return _context2.stop();
|
|
4354
|
+
}
|
|
4355
|
+
}, _callee2, this);
|
|
4356
|
+
}));
|
|
4357
|
+
function createPineconeIndex(_x) {
|
|
4358
|
+
return _createPineconeIndex.apply(this, arguments);
|
|
4359
|
+
}
|
|
4360
|
+
return createPineconeIndex;
|
|
4361
|
+
}();
|
|
4362
|
+
_proto.getPineconeIndex = /*#__PURE__*/function () {
|
|
4363
|
+
var _getPineconeIndex = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
|
|
4364
|
+
var name;
|
|
4365
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4366
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4367
|
+
case 0:
|
|
4368
|
+
name = _ref2.name;
|
|
4369
|
+
return _context3.abrupt("return", this.Pinecone.index(name));
|
|
4370
|
+
case 2:
|
|
4371
|
+
case "end":
|
|
4372
|
+
return _context3.stop();
|
|
4373
|
+
}
|
|
4374
|
+
}, _callee3, this);
|
|
4375
|
+
}));
|
|
4376
|
+
function getPineconeIndex(_x2) {
|
|
4377
|
+
return _getPineconeIndex.apply(this, arguments);
|
|
4378
|
+
}
|
|
4379
|
+
return getPineconeIndex;
|
|
4380
|
+
}();
|
|
4381
|
+
_proto.generateVectorEmbedding = /*#__PURE__*/function () {
|
|
4382
|
+
var _generateVectorEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(data) {
|
|
4383
|
+
var _yield$embed, embedding;
|
|
4384
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4385
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4386
|
+
case 0:
|
|
4387
|
+
_context4.next = 2;
|
|
4388
|
+
return ai.embed({
|
|
4389
|
+
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4390
|
+
value: JSON.stringify(data)
|
|
4391
|
+
});
|
|
4392
|
+
case 2:
|
|
4393
|
+
_yield$embed = _context4.sent;
|
|
4394
|
+
embedding = _yield$embed.embedding;
|
|
4395
|
+
return _context4.abrupt("return", embedding);
|
|
4396
|
+
case 5:
|
|
4397
|
+
case "end":
|
|
4398
|
+
return _context4.stop();
|
|
4399
|
+
}
|
|
4400
|
+
}, _callee4);
|
|
4401
|
+
}));
|
|
4402
|
+
function generateVectorEmbedding(_x3) {
|
|
4403
|
+
return _generateVectorEmbedding.apply(this, arguments);
|
|
4404
|
+
}
|
|
4405
|
+
return generateVectorEmbedding;
|
|
4406
|
+
}();
|
|
4407
|
+
_proto.getPineconeIndexWithMetadata = /*#__PURE__*/function () {
|
|
4408
|
+
var _getPineconeIndexWithMetadata = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref3) {
|
|
4409
|
+
var name, newIndex, indexQuery, namespaces, data, _iterator, _step, _namespaceData$record, namespace, namespaceData, metadata;
|
|
4410
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4411
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4412
|
+
case 0:
|
|
4413
|
+
name = _ref3.name;
|
|
4414
|
+
_context5.prev = 1;
|
|
4415
|
+
if (name) {
|
|
4416
|
+
_context5.next = 5;
|
|
4417
|
+
break;
|
|
4418
|
+
}
|
|
4419
|
+
console.log('Index name not passed');
|
|
4420
|
+
return _context5.abrupt("return", []);
|
|
4421
|
+
case 5:
|
|
4422
|
+
_context5.next = 7;
|
|
4423
|
+
return this.getPineconeIndex({
|
|
4424
|
+
name: name
|
|
4425
|
+
});
|
|
4426
|
+
case 7:
|
|
4427
|
+
newIndex = _context5.sent;
|
|
4428
|
+
_context5.next = 10;
|
|
4429
|
+
return newIndex == null ? void 0 : newIndex.describeIndexStats();
|
|
4430
|
+
case 10:
|
|
4431
|
+
indexQuery = _context5.sent;
|
|
4432
|
+
if (!indexQuery) {
|
|
4433
|
+
_context5.next = 27;
|
|
4434
|
+
break;
|
|
4435
|
+
}
|
|
4436
|
+
namespaces = Object.keys((indexQuery == null ? void 0 : indexQuery.namespaces) || {});
|
|
4437
|
+
data = [];
|
|
4438
|
+
if (!namespaces.length) {
|
|
4439
|
+
_context5.next = 26;
|
|
4440
|
+
break;
|
|
4441
|
+
}
|
|
4442
|
+
_iterator = _createForOfIteratorHelperLoose(namespaces);
|
|
4443
|
+
case 16:
|
|
4444
|
+
if ((_step = _iterator()).done) {
|
|
4445
|
+
_context5.next = 26;
|
|
4446
|
+
break;
|
|
4447
|
+
}
|
|
4448
|
+
namespace = _step.value;
|
|
4449
|
+
_context5.next = 20;
|
|
4450
|
+
return newIndex == null ? void 0 : newIndex.namespace(namespace).fetch([name]);
|
|
4451
|
+
case 20:
|
|
4452
|
+
namespaceData = _context5.sent;
|
|
4453
|
+
metadata = namespaceData == null || (_namespaceData$record = namespaceData.records) == null || (_namespaceData$record = _namespaceData$record[name]) == null ? void 0 : _namespaceData$record.metadata;
|
|
4454
|
+
console.log("metadata for " + namespace + "===", JSON.stringify(metadata, null, 2));
|
|
4455
|
+
if (metadata) {
|
|
4456
|
+
data.push(metadata);
|
|
4457
|
+
}
|
|
4458
|
+
case 24:
|
|
4459
|
+
_context5.next = 16;
|
|
4460
|
+
break;
|
|
4461
|
+
case 26:
|
|
4462
|
+
return _context5.abrupt("return", data);
|
|
4463
|
+
case 27:
|
|
4464
|
+
return _context5.abrupt("return", []);
|
|
4465
|
+
case 30:
|
|
4466
|
+
_context5.prev = 30;
|
|
4467
|
+
_context5.t0 = _context5["catch"](1);
|
|
4468
|
+
console.log("Error getting " + name + " index", _context5.t0);
|
|
4469
|
+
case 33:
|
|
4470
|
+
case "end":
|
|
4471
|
+
return _context5.stop();
|
|
4472
|
+
}
|
|
4473
|
+
}, _callee5, this, [[1, 30]]);
|
|
4474
|
+
}));
|
|
4475
|
+
function getPineconeIndexWithMetadata(_x4) {
|
|
4476
|
+
return _getPineconeIndexWithMetadata.apply(this, arguments);
|
|
4477
|
+
}
|
|
4478
|
+
return getPineconeIndexWithMetadata;
|
|
4479
|
+
}();
|
|
4306
4480
|
return _createClass(VectorLayer, [{
|
|
4307
4481
|
key: "Pinecone",
|
|
4308
4482
|
get: function get() {
|
|
@@ -4317,7 +4491,7 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4317
4491
|
}();
|
|
4318
4492
|
|
|
4319
4493
|
function getVectorProvider(provider) {
|
|
4320
|
-
if (provider === '
|
|
4494
|
+
if (provider === 'pinecone') {
|
|
4321
4495
|
var _VectorLayer = new VectorLayer(),
|
|
4322
4496
|
Pinecone = _VectorLayer.Pinecone;
|
|
4323
4497
|
return Pinecone;
|
|
@@ -4328,355 +4502,346 @@ var delay$1 = function delay(ms) {
|
|
|
4328
4502
|
return setTimeout(resolve, ms);
|
|
4329
4503
|
});
|
|
4330
4504
|
};
|
|
4331
|
-
function
|
|
4332
|
-
return
|
|
4505
|
+
function executeIndexSync(_x) {
|
|
4506
|
+
return _executeIndexSync.apply(this, arguments);
|
|
4333
4507
|
}
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
var
|
|
4338
|
-
|
|
4339
|
-
|
|
4508
|
+
//Generic vector sync from event data
|
|
4509
|
+
function _executeIndexSync() {
|
|
4510
|
+
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
|
|
4511
|
+
var _event$user, _event$data;
|
|
4512
|
+
var event, mastra, connectionId, providedIndexes, systemName, _iterator, _step, _step$value, provider, indexes, vp, _iterator2, _step2, index, indexMetadata, _loop, _ret, _iterator3, _step3;
|
|
4513
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
4514
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4340
4515
|
case 0:
|
|
4341
4516
|
event = _ref.event, mastra = _ref.mastra;
|
|
4342
4517
|
connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
|
|
4343
|
-
|
|
4344
|
-
entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
|
|
4518
|
+
providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
|
|
4345
4519
|
systemName = mastra.config.name;
|
|
4346
|
-
|
|
4347
|
-
|
|
4520
|
+
_iterator = _createForOfIteratorHelperLoose(providedIndexes);
|
|
4521
|
+
case 5:
|
|
4522
|
+
if ((_step = _iterator()).done) {
|
|
4523
|
+
_context5.next = 36;
|
|
4348
4524
|
break;
|
|
4349
4525
|
}
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
case 8:
|
|
4353
|
-
vp = getVectorProvider(vector_provider);
|
|
4526
|
+
_step$value = _step.value, provider = _step$value.provider, indexes = _step$value.indexes;
|
|
4527
|
+
vp = getVectorProvider(provider);
|
|
4354
4528
|
if (vp) {
|
|
4355
|
-
|
|
4529
|
+
_context5.next = 11;
|
|
4356
4530
|
break;
|
|
4357
4531
|
}
|
|
4358
|
-
console.error('UNSUPPORTED VECTOR PROVIDER',
|
|
4359
|
-
return
|
|
4360
|
-
case
|
|
4532
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', provider);
|
|
4533
|
+
return _context5.abrupt("return");
|
|
4534
|
+
case 11:
|
|
4361
4535
|
if (process.env.OPENAI_API_KEY) {
|
|
4362
|
-
|
|
4536
|
+
_context5.next = 14;
|
|
4363
4537
|
break;
|
|
4364
4538
|
}
|
|
4365
4539
|
console.error('NO OPENAI_API_KEY');
|
|
4366
|
-
return
|
|
4540
|
+
return _context5.abrupt("return");
|
|
4541
|
+
case 14:
|
|
4542
|
+
_iterator2 = _createForOfIteratorHelperLoose(indexes);
|
|
4367
4543
|
case 15:
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
if ((_step = _iterator()).done) {
|
|
4371
|
-
_context4.next = 50;
|
|
4372
|
-
break;
|
|
4373
|
-
}
|
|
4374
|
-
vectorE = _step.value;
|
|
4375
|
-
integrationName = vectorE.integration;
|
|
4376
|
-
_context4.next = 21;
|
|
4377
|
-
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4378
|
-
connectionId: connectionId,
|
|
4379
|
-
name: integrationName
|
|
4380
|
-
});
|
|
4381
|
-
case 21:
|
|
4382
|
-
_context4.t1 = _yield$mastra$dataLay = _context4.sent;
|
|
4383
|
-
if (!(_context4.t1 == null)) {
|
|
4384
|
-
_context4.next = 26;
|
|
4385
|
-
break;
|
|
4386
|
-
}
|
|
4387
|
-
_context4.t2 = void 0;
|
|
4388
|
-
_context4.next = 27;
|
|
4389
|
-
break;
|
|
4390
|
-
case 26:
|
|
4391
|
-
_context4.t2 = _yield$mastra$dataLay.id;
|
|
4392
|
-
case 27:
|
|
4393
|
-
_context4.t0 = _context4.t2;
|
|
4394
|
-
if (_context4.t0) {
|
|
4395
|
-
_context4.next = 30;
|
|
4396
|
-
break;
|
|
4397
|
-
}
|
|
4398
|
-
_context4.t0 = '';
|
|
4399
|
-
case 30:
|
|
4400
|
-
k_id = _context4.t0;
|
|
4401
|
-
if (!(!k_id && integrationName === systemName)) {
|
|
4402
|
-
_context4.next = 36;
|
|
4544
|
+
if ((_step2 = _iterator2()).done) {
|
|
4545
|
+
_context5.next = 34;
|
|
4403
4546
|
break;
|
|
4404
4547
|
}
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
name: integrationName
|
|
4410
|
-
},
|
|
4411
|
-
credential: {
|
|
4412
|
-
type: 'API_KEY',
|
|
4413
|
-
value: connectionId,
|
|
4414
|
-
scope: []
|
|
4415
|
-
}
|
|
4548
|
+
index = _step2.value;
|
|
4549
|
+
_context5.next = 19;
|
|
4550
|
+
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
4551
|
+
name: index
|
|
4416
4552
|
});
|
|
4417
|
-
case
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
if (k_id) {
|
|
4422
|
-
_context4.next = 39;
|
|
4553
|
+
case 19:
|
|
4554
|
+
indexMetadata = _context5.sent;
|
|
4555
|
+
if (indexMetadata != null && indexMetadata.length) {
|
|
4556
|
+
_context5.next = 23;
|
|
4423
4557
|
break;
|
|
4424
4558
|
}
|
|
4425
|
-
console.error('
|
|
4426
|
-
return
|
|
4427
|
-
case
|
|
4559
|
+
console.error('No index metadata found for', index);
|
|
4560
|
+
return _context5.abrupt("return");
|
|
4561
|
+
case 23:
|
|
4428
4562
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
4429
|
-
var _mastra$dataLayer3, _entityRecords, _records;
|
|
4430
|
-
var entity, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, _yield$mastra$trigger, _event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
|
|
4431
|
-
return _regeneratorRuntime().wrap(function _loop$(
|
|
4432
|
-
while (1) switch (
|
|
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) {
|
|
4433
4567
|
case 0:
|
|
4434
|
-
entity =
|
|
4435
|
-
|
|
4568
|
+
entity = _step3.value;
|
|
4569
|
+
fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
|
|
4570
|
+
_context4.next = 4;
|
|
4571
|
+
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4572
|
+
connectionId: connectionId,
|
|
4573
|
+
name: integration
|
|
4574
|
+
});
|
|
4575
|
+
case 4:
|
|
4576
|
+
_context4.t1 = _yield$mastra$dataLay = _context4.sent;
|
|
4577
|
+
if (!(_context4.t1 == null)) {
|
|
4578
|
+
_context4.next = 9;
|
|
4579
|
+
break;
|
|
4580
|
+
}
|
|
4581
|
+
_context4.t2 = void 0;
|
|
4582
|
+
_context4.next = 10;
|
|
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", {
|
|
4621
|
+
v: void 0
|
|
4622
|
+
});
|
|
4623
|
+
case 22:
|
|
4624
|
+
_context4.next = 24;
|
|
4436
4625
|
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
4437
4626
|
k_id: k_id,
|
|
4438
|
-
type:
|
|
4627
|
+
type: name
|
|
4439
4628
|
});
|
|
4440
|
-
case
|
|
4441
|
-
entityRecords =
|
|
4629
|
+
case 24:
|
|
4630
|
+
entityRecords = _context4.sent;
|
|
4442
4631
|
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
4443
4632
|
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
4444
|
-
|
|
4633
|
+
_context4.next = 44;
|
|
4445
4634
|
break;
|
|
4446
4635
|
}
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
_context3.next = 9;
|
|
4636
|
+
console.error('NO RECORDS ATTEMPTING SYNC');
|
|
4637
|
+
_context4.next = 30;
|
|
4450
4638
|
return mastra.triggerEvent({
|
|
4451
|
-
key:
|
|
4639
|
+
key: syncEvent,
|
|
4452
4640
|
data: {},
|
|
4453
4641
|
user: {
|
|
4454
4642
|
connectionId: connectionId
|
|
4455
4643
|
}
|
|
4456
4644
|
});
|
|
4457
|
-
case
|
|
4458
|
-
_yield$mastra$trigger =
|
|
4645
|
+
case 30:
|
|
4646
|
+
_yield$mastra$trigger = _context4.sent;
|
|
4459
4647
|
_event = _yield$mastra$trigger.event;
|
|
4460
4648
|
console.log(_event, '####');
|
|
4461
|
-
|
|
4649
|
+
_context4.next = 35;
|
|
4462
4650
|
return _event.subscribe();
|
|
4463
|
-
case
|
|
4464
|
-
res =
|
|
4651
|
+
case 35:
|
|
4652
|
+
res = _context4.sent;
|
|
4465
4653
|
console.log('Subscribe result', res);
|
|
4466
|
-
|
|
4654
|
+
_context4.next = 39;
|
|
4467
4655
|
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
4468
4656
|
k_id: k_id,
|
|
4469
4657
|
type: entity.name
|
|
4470
4658
|
});
|
|
4471
|
-
case
|
|
4472
|
-
entityRecords =
|
|
4659
|
+
case 39:
|
|
4660
|
+
entityRecords = _context4.sent;
|
|
4473
4661
|
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
4474
4662
|
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
4475
|
-
|
|
4663
|
+
_context4.next = 44;
|
|
4476
4664
|
break;
|
|
4477
4665
|
}
|
|
4478
4666
|
console.error('NO RECORDS AFTER SYNC');
|
|
4479
|
-
return
|
|
4667
|
+
return _context4.abrupt("return", {
|
|
4480
4668
|
v: void 0
|
|
4481
4669
|
});
|
|
4482
|
-
case
|
|
4483
|
-
recordsMapped = records.map(function (
|
|
4484
|
-
var data =
|
|
4485
|
-
externalId =
|
|
4670
|
+
case 44:
|
|
4671
|
+
recordsMapped = records.map(function (_ref9) {
|
|
4672
|
+
var data = _ref9.data,
|
|
4673
|
+
externalId = _ref9.externalId;
|
|
4486
4674
|
return _extends({
|
|
4487
4675
|
id: externalId
|
|
4488
|
-
}, _.pick(data,
|
|
4676
|
+
}, _.pick(data, fields));
|
|
4489
4677
|
});
|
|
4490
4678
|
console.log(recordsMapped, 'RECORDS');
|
|
4491
|
-
|
|
4492
|
-
return vp.createIndex({
|
|
4493
|
-
suppressConflicts: true,
|
|
4494
|
-
name: entity.name,
|
|
4495
|
-
dimension: 1536,
|
|
4496
|
-
metric: 'cosine',
|
|
4497
|
-
spec: {
|
|
4498
|
-
serverless: {
|
|
4499
|
-
cloud: 'aws',
|
|
4500
|
-
region: 'us-east-1'
|
|
4501
|
-
}
|
|
4502
|
-
}
|
|
4503
|
-
});
|
|
4504
|
-
case 27:
|
|
4505
|
-
_context3.next = 29;
|
|
4506
|
-
return delay$1(5000);
|
|
4507
|
-
case 29:
|
|
4508
|
-
entityTypeIndex = vp.index(entity.name);
|
|
4679
|
+
entityTypeIndex = vp.index(index);
|
|
4509
4680
|
console.log(entityTypeIndex, 'INDEX');
|
|
4510
|
-
|
|
4511
|
-
|
|
4681
|
+
_context4.prev = 48;
|
|
4682
|
+
_context4.next = 51;
|
|
4512
4683
|
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4513
|
-
var
|
|
4684
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(record) {
|
|
4514
4685
|
var _yield$embed, embedding;
|
|
4515
|
-
return _regeneratorRuntime().wrap(function
|
|
4516
|
-
while (1) switch (
|
|
4686
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4687
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4517
4688
|
case 0:
|
|
4518
|
-
|
|
4689
|
+
_context3.next = 2;
|
|
4519
4690
|
return ai.embed({
|
|
4520
4691
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4521
4692
|
value: JSON.stringify(record)
|
|
4522
4693
|
});
|
|
4523
4694
|
case 2:
|
|
4524
|
-
_yield$embed =
|
|
4695
|
+
_yield$embed = _context3.sent;
|
|
4525
4696
|
embedding = _yield$embed.embedding;
|
|
4526
|
-
return
|
|
4697
|
+
return _context3.abrupt("return", {
|
|
4527
4698
|
id: record.id,
|
|
4528
4699
|
values: embedding,
|
|
4529
4700
|
metadata: record
|
|
4530
4701
|
});
|
|
4531
4702
|
case 5:
|
|
4532
4703
|
case "end":
|
|
4533
|
-
return
|
|
4704
|
+
return _context3.stop();
|
|
4534
4705
|
}
|
|
4535
|
-
},
|
|
4706
|
+
}, _callee3);
|
|
4536
4707
|
}));
|
|
4537
|
-
return function (
|
|
4538
|
-
return
|
|
4708
|
+
return function (_x7) {
|
|
4709
|
+
return _ref10.apply(this, arguments);
|
|
4539
4710
|
};
|
|
4540
4711
|
}())) != null ? _recordsMapped$map : []);
|
|
4541
|
-
case
|
|
4542
|
-
vectors =
|
|
4712
|
+
case 51:
|
|
4713
|
+
vectors = _context4.sent;
|
|
4543
4714
|
console.log('UPSERTING', vectors);
|
|
4544
4715
|
if (!(vectors.length > 0)) {
|
|
4545
|
-
|
|
4716
|
+
_context4.next = 56;
|
|
4546
4717
|
break;
|
|
4547
4718
|
}
|
|
4548
|
-
|
|
4549
|
-
return entityTypeIndex.namespace(
|
|
4550
|
-
case
|
|
4551
|
-
|
|
4719
|
+
_context4.next = 56;
|
|
4720
|
+
return entityTypeIndex.namespace(name).upsert(vectors);
|
|
4721
|
+
case 56:
|
|
4722
|
+
_context4.next = 61;
|
|
4552
4723
|
break;
|
|
4553
|
-
case
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
console.error(
|
|
4557
|
-
case
|
|
4558
|
-
return
|
|
4724
|
+
case 58:
|
|
4725
|
+
_context4.prev = 58;
|
|
4726
|
+
_context4.t3 = _context4["catch"](48);
|
|
4727
|
+
console.error(_context4.t3);
|
|
4728
|
+
case 61:
|
|
4729
|
+
return _context4.abrupt("return", {
|
|
4559
4730
|
v: void 0
|
|
4560
4731
|
});
|
|
4561
|
-
case
|
|
4732
|
+
case 62:
|
|
4562
4733
|
case "end":
|
|
4563
|
-
return
|
|
4734
|
+
return _context4.stop();
|
|
4564
4735
|
}
|
|
4565
|
-
}, _loop, null, [[
|
|
4736
|
+
}, _loop, null, [[48, 58]]);
|
|
4566
4737
|
});
|
|
4567
|
-
|
|
4568
|
-
case
|
|
4569
|
-
if ((
|
|
4570
|
-
|
|
4738
|
+
_iterator3 = _createForOfIteratorHelperLoose(indexMetadata);
|
|
4739
|
+
case 25:
|
|
4740
|
+
if ((_step3 = _iterator3()).done) {
|
|
4741
|
+
_context5.next = 32;
|
|
4571
4742
|
break;
|
|
4572
4743
|
}
|
|
4573
|
-
return
|
|
4574
|
-
case
|
|
4575
|
-
_ret =
|
|
4744
|
+
return _context5.delegateYield(_loop(), "t0", 27);
|
|
4745
|
+
case 27:
|
|
4746
|
+
_ret = _context5.t0;
|
|
4576
4747
|
if (!_ret) {
|
|
4577
|
-
|
|
4748
|
+
_context5.next = 30;
|
|
4578
4749
|
break;
|
|
4579
4750
|
}
|
|
4580
|
-
return
|
|
4581
|
-
case
|
|
4582
|
-
|
|
4751
|
+
return _context5.abrupt("return", _ret.v);
|
|
4752
|
+
case 30:
|
|
4753
|
+
_context5.next = 25;
|
|
4583
4754
|
break;
|
|
4584
|
-
case
|
|
4585
|
-
|
|
4755
|
+
case 32:
|
|
4756
|
+
_context5.next = 15;
|
|
4586
4757
|
break;
|
|
4587
|
-
case
|
|
4758
|
+
case 34:
|
|
4759
|
+
_context5.next = 5;
|
|
4760
|
+
break;
|
|
4761
|
+
case 36:
|
|
4588
4762
|
case "end":
|
|
4589
|
-
return
|
|
4763
|
+
return _context5.stop();
|
|
4590
4764
|
}
|
|
4591
|
-
},
|
|
4765
|
+
}, _callee4);
|
|
4592
4766
|
}));
|
|
4593
|
-
return
|
|
4767
|
+
return _executeIndexSync.apply(this, arguments);
|
|
4594
4768
|
}
|
|
4595
|
-
function
|
|
4596
|
-
return
|
|
4769
|
+
function executeGenericVectorSync(_x2) {
|
|
4770
|
+
return _executeGenericVectorSync.apply(this, arguments);
|
|
4597
4771
|
}
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
var
|
|
4602
|
-
|
|
4603
|
-
|
|
4772
|
+
// Vector Sync from agents Dir
|
|
4773
|
+
function _executeGenericVectorSync() {
|
|
4774
|
+
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref2) {
|
|
4775
|
+
var _event$user2, _event$data2, _event$data3;
|
|
4776
|
+
var event, mastra, connectionId, vector_provider, entities, systemName, vp, _iterator4, _step4, _yield$mastra$dataLay2, _mastra$dataLayer5, vectorE, integrationName, k_id, _mastra$dataLayer6, connection, _loop2, _ret2, _iterator5, _step5;
|
|
4777
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
4778
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4604
4779
|
case 0:
|
|
4605
4780
|
event = _ref2.event, mastra = _ref2.mastra;
|
|
4606
|
-
agentDir = mastra.config.agents.agentDirPath;
|
|
4607
|
-
agent = getAgentBlueprint({
|
|
4608
|
-
agentDir: agentDir,
|
|
4609
|
-
agentId: event.data.agentId
|
|
4610
|
-
});
|
|
4611
4781
|
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
4782
|
+
vector_provider = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.vector_provider;
|
|
4783
|
+
entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
|
|
4612
4784
|
systemName = mastra.config.name;
|
|
4613
|
-
if (
|
|
4614
|
-
|
|
4785
|
+
if (vector_provider) {
|
|
4786
|
+
_context8.next = 8;
|
|
4615
4787
|
break;
|
|
4616
4788
|
}
|
|
4617
4789
|
console.error("No vector_provider defined for agent");
|
|
4618
|
-
return
|
|
4790
|
+
return _context8.abrupt("return");
|
|
4619
4791
|
case 8:
|
|
4620
|
-
vp = getVectorProvider(
|
|
4792
|
+
vp = getVectorProvider(vector_provider);
|
|
4621
4793
|
if (vp) {
|
|
4622
|
-
|
|
4794
|
+
_context8.next = 12;
|
|
4623
4795
|
break;
|
|
4624
4796
|
}
|
|
4625
|
-
console.error('UNSUPPORTED VECTOR PROVIDER',
|
|
4626
|
-
return
|
|
4797
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4798
|
+
return _context8.abrupt("return");
|
|
4627
4799
|
case 12:
|
|
4628
4800
|
if (process.env.OPENAI_API_KEY) {
|
|
4629
|
-
|
|
4801
|
+
_context8.next = 15;
|
|
4630
4802
|
break;
|
|
4631
4803
|
}
|
|
4632
4804
|
console.error('NO OPENAI_API_KEY');
|
|
4633
|
-
return
|
|
4805
|
+
return _context8.abrupt("return");
|
|
4634
4806
|
case 15:
|
|
4635
|
-
|
|
4636
|
-
|
|
4807
|
+
_iterator4 = _createForOfIteratorHelperLoose(entities);
|
|
4808
|
+
case 16:
|
|
4809
|
+
if ((_step4 = _iterator4()).done) {
|
|
4810
|
+
_context8.next = 50;
|
|
4637
4811
|
break;
|
|
4638
4812
|
}
|
|
4639
|
-
|
|
4640
|
-
return _context7.abrupt("return");
|
|
4641
|
-
case 18:
|
|
4642
|
-
_iterator3 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
4643
|
-
case 19:
|
|
4644
|
-
if ((_step3 = _iterator3()).done) {
|
|
4645
|
-
_context7.next = 53;
|
|
4646
|
-
break;
|
|
4647
|
-
}
|
|
4648
|
-
vectorE = _step3.value;
|
|
4813
|
+
vectorE = _step4.value;
|
|
4649
4814
|
integrationName = vectorE.integration;
|
|
4650
|
-
|
|
4815
|
+
_context8.next = 21;
|
|
4651
4816
|
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
4652
4817
|
connectionId: connectionId,
|
|
4653
4818
|
name: integrationName
|
|
4654
4819
|
});
|
|
4655
|
-
case
|
|
4656
|
-
|
|
4657
|
-
if (!(
|
|
4658
|
-
|
|
4820
|
+
case 21:
|
|
4821
|
+
_context8.t1 = _yield$mastra$dataLay2 = _context8.sent;
|
|
4822
|
+
if (!(_context8.t1 == null)) {
|
|
4823
|
+
_context8.next = 26;
|
|
4659
4824
|
break;
|
|
4660
4825
|
}
|
|
4661
|
-
|
|
4662
|
-
|
|
4826
|
+
_context8.t2 = void 0;
|
|
4827
|
+
_context8.next = 27;
|
|
4663
4828
|
break;
|
|
4664
|
-
case
|
|
4665
|
-
|
|
4666
|
-
case
|
|
4667
|
-
|
|
4668
|
-
if (
|
|
4669
|
-
|
|
4829
|
+
case 26:
|
|
4830
|
+
_context8.t2 = _yield$mastra$dataLay2.id;
|
|
4831
|
+
case 27:
|
|
4832
|
+
_context8.t0 = _context8.t2;
|
|
4833
|
+
if (_context8.t0) {
|
|
4834
|
+
_context8.next = 30;
|
|
4670
4835
|
break;
|
|
4671
4836
|
}
|
|
4672
|
-
|
|
4673
|
-
case
|
|
4674
|
-
k_id =
|
|
4837
|
+
_context8.t0 = '';
|
|
4838
|
+
case 30:
|
|
4839
|
+
k_id = _context8.t0;
|
|
4675
4840
|
if (!(!k_id && integrationName === systemName)) {
|
|
4676
|
-
|
|
4841
|
+
_context8.next = 36;
|
|
4677
4842
|
break;
|
|
4678
4843
|
}
|
|
4679
|
-
|
|
4844
|
+
_context8.next = 34;
|
|
4680
4845
|
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4681
4846
|
connection: {
|
|
4682
4847
|
connectionId: connectionId,
|
|
@@ -4688,39 +4853,39 @@ function _executeVectorSync() {
|
|
|
4688
4853
|
scope: []
|
|
4689
4854
|
}
|
|
4690
4855
|
});
|
|
4691
|
-
case
|
|
4692
|
-
connection =
|
|
4856
|
+
case 34:
|
|
4857
|
+
connection = _context8.sent;
|
|
4693
4858
|
k_id = connection.id;
|
|
4694
|
-
case
|
|
4859
|
+
case 36:
|
|
4695
4860
|
if (k_id) {
|
|
4696
|
-
|
|
4861
|
+
_context8.next = 39;
|
|
4697
4862
|
break;
|
|
4698
4863
|
}
|
|
4699
4864
|
console.error('Error bootstrapping shit');
|
|
4700
|
-
return
|
|
4701
|
-
case
|
|
4865
|
+
return _context8.abrupt("return");
|
|
4866
|
+
case 39:
|
|
4702
4867
|
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4703
4868
|
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4704
4869
|
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4705
|
-
return _regeneratorRuntime().wrap(function _loop2$(
|
|
4706
|
-
while (1) switch (
|
|
4870
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context7) {
|
|
4871
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4707
4872
|
case 0:
|
|
4708
|
-
entity =
|
|
4709
|
-
|
|
4873
|
+
entity = _step5.value;
|
|
4874
|
+
_context7.next = 3;
|
|
4710
4875
|
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4711
4876
|
k_id: k_id,
|
|
4712
4877
|
type: entity.name
|
|
4713
4878
|
});
|
|
4714
4879
|
case 3:
|
|
4715
|
-
entityRecords =
|
|
4880
|
+
entityRecords = _context7.sent;
|
|
4716
4881
|
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4717
4882
|
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4718
|
-
|
|
4883
|
+
_context7.next = 23;
|
|
4719
4884
|
break;
|
|
4720
4885
|
}
|
|
4721
4886
|
// @TODO: SYNC THEM
|
|
4722
4887
|
console.error('NO RECORDS');
|
|
4723
|
-
|
|
4888
|
+
_context7.next = 9;
|
|
4724
4889
|
return mastra.triggerEvent({
|
|
4725
4890
|
key: entity.syncEvent,
|
|
4726
4891
|
data: {},
|
|
@@ -4729,40 +4894,40 @@ function _executeVectorSync() {
|
|
|
4729
4894
|
}
|
|
4730
4895
|
});
|
|
4731
4896
|
case 9:
|
|
4732
|
-
_yield$mastra$trigger2 =
|
|
4897
|
+
_yield$mastra$trigger2 = _context7.sent;
|
|
4733
4898
|
_event2 = _yield$mastra$trigger2.event;
|
|
4734
4899
|
console.log(_event2, '####');
|
|
4735
|
-
|
|
4900
|
+
_context7.next = 14;
|
|
4736
4901
|
return _event2.subscribe();
|
|
4737
4902
|
case 14:
|
|
4738
|
-
res =
|
|
4903
|
+
res = _context7.sent;
|
|
4739
4904
|
console.log('Subscribe result', res);
|
|
4740
|
-
|
|
4905
|
+
_context7.next = 18;
|
|
4741
4906
|
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4742
4907
|
k_id: k_id,
|
|
4743
4908
|
type: entity.name
|
|
4744
4909
|
});
|
|
4745
4910
|
case 18:
|
|
4746
|
-
entityRecords =
|
|
4911
|
+
entityRecords = _context7.sent;
|
|
4747
4912
|
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4748
4913
|
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4749
|
-
|
|
4914
|
+
_context7.next = 23;
|
|
4750
4915
|
break;
|
|
4751
4916
|
}
|
|
4752
4917
|
console.error('NO RECORDS AFTER SYNC');
|
|
4753
|
-
return
|
|
4918
|
+
return _context7.abrupt("return", {
|
|
4754
4919
|
v: void 0
|
|
4755
4920
|
});
|
|
4756
4921
|
case 23:
|
|
4757
|
-
recordsMapped = records.map(function (
|
|
4758
|
-
var data =
|
|
4759
|
-
externalId =
|
|
4922
|
+
recordsMapped = records.map(function (_ref11) {
|
|
4923
|
+
var data = _ref11.data,
|
|
4924
|
+
externalId = _ref11.externalId;
|
|
4760
4925
|
return _extends({
|
|
4761
4926
|
id: externalId
|
|
4762
4927
|
}, _.pick(data, entity.fields));
|
|
4763
4928
|
});
|
|
4764
4929
|
console.log(recordsMapped, 'RECORDS');
|
|
4765
|
-
|
|
4930
|
+
_context7.next = 27;
|
|
4766
4931
|
return vp.createIndex({
|
|
4767
4932
|
suppressConflicts: true,
|
|
4768
4933
|
name: entity.name,
|
|
@@ -4776,209 +4941,650 @@ function _executeVectorSync() {
|
|
|
4776
4941
|
}
|
|
4777
4942
|
});
|
|
4778
4943
|
case 27:
|
|
4944
|
+
_context7.next = 29;
|
|
4945
|
+
return delay$1(5000);
|
|
4946
|
+
case 29:
|
|
4779
4947
|
entityTypeIndex = vp.index(entity.name);
|
|
4780
4948
|
console.log(entityTypeIndex, 'INDEX');
|
|
4781
|
-
|
|
4782
|
-
|
|
4949
|
+
_context7.prev = 31;
|
|
4950
|
+
_context7.next = 34;
|
|
4783
4951
|
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4784
|
-
var
|
|
4952
|
+
var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record) {
|
|
4785
4953
|
var _yield$embed2, embedding;
|
|
4786
|
-
return _regeneratorRuntime().wrap(function
|
|
4787
|
-
while (1) switch (
|
|
4954
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
|
|
4955
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4788
4956
|
case 0:
|
|
4789
|
-
|
|
4957
|
+
_context6.next = 2;
|
|
4790
4958
|
return ai.embed({
|
|
4791
4959
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4792
4960
|
value: JSON.stringify(record)
|
|
4793
4961
|
});
|
|
4794
4962
|
case 2:
|
|
4795
|
-
_yield$embed2 =
|
|
4963
|
+
_yield$embed2 = _context6.sent;
|
|
4796
4964
|
embedding = _yield$embed2.embedding;
|
|
4797
|
-
return
|
|
4965
|
+
return _context6.abrupt("return", {
|
|
4798
4966
|
id: record.id,
|
|
4799
4967
|
values: embedding,
|
|
4800
4968
|
metadata: record
|
|
4801
4969
|
});
|
|
4802
4970
|
case 5:
|
|
4803
4971
|
case "end":
|
|
4804
|
-
return
|
|
4972
|
+
return _context6.stop();
|
|
4805
4973
|
}
|
|
4806
|
-
},
|
|
4974
|
+
}, _callee5);
|
|
4807
4975
|
}));
|
|
4808
|
-
return function (
|
|
4809
|
-
return
|
|
4976
|
+
return function (_x8) {
|
|
4977
|
+
return _ref12.apply(this, arguments);
|
|
4810
4978
|
};
|
|
4811
4979
|
}())) != null ? _recordsMapped$map2 : []);
|
|
4980
|
+
case 34:
|
|
4981
|
+
vectors = _context7.sent;
|
|
4982
|
+
console.log('UPSERTING', vectors);
|
|
4983
|
+
if (!(vectors.length > 0)) {
|
|
4984
|
+
_context7.next = 39;
|
|
4985
|
+
break;
|
|
4986
|
+
}
|
|
4987
|
+
_context7.next = 39;
|
|
4988
|
+
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4989
|
+
case 39:
|
|
4990
|
+
_context7.next = 44;
|
|
4991
|
+
break;
|
|
4992
|
+
case 41:
|
|
4993
|
+
_context7.prev = 41;
|
|
4994
|
+
_context7.t0 = _context7["catch"](31);
|
|
4995
|
+
console.error(_context7.t0);
|
|
4996
|
+
case 44:
|
|
4997
|
+
return _context7.abrupt("return", {
|
|
4998
|
+
v: void 0
|
|
4999
|
+
});
|
|
5000
|
+
case 45:
|
|
5001
|
+
case "end":
|
|
5002
|
+
return _context7.stop();
|
|
5003
|
+
}
|
|
5004
|
+
}, _loop2, null, [[31, 41]]);
|
|
5005
|
+
});
|
|
5006
|
+
_iterator5 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5007
|
+
case 41:
|
|
5008
|
+
if ((_step5 = _iterator5()).done) {
|
|
5009
|
+
_context8.next = 48;
|
|
5010
|
+
break;
|
|
5011
|
+
}
|
|
5012
|
+
return _context8.delegateYield(_loop2(), "t3", 43);
|
|
5013
|
+
case 43:
|
|
5014
|
+
_ret2 = _context8.t3;
|
|
5015
|
+
if (!_ret2) {
|
|
5016
|
+
_context8.next = 46;
|
|
5017
|
+
break;
|
|
5018
|
+
}
|
|
5019
|
+
return _context8.abrupt("return", _ret2.v);
|
|
5020
|
+
case 46:
|
|
5021
|
+
_context8.next = 41;
|
|
5022
|
+
break;
|
|
5023
|
+
case 48:
|
|
5024
|
+
_context8.next = 16;
|
|
5025
|
+
break;
|
|
5026
|
+
case 50:
|
|
5027
|
+
case "end":
|
|
5028
|
+
return _context8.stop();
|
|
5029
|
+
}
|
|
5030
|
+
}, _callee6);
|
|
5031
|
+
}));
|
|
5032
|
+
return _executeGenericVectorSync.apply(this, arguments);
|
|
5033
|
+
}
|
|
5034
|
+
function executeVectorSync(_x3) {
|
|
5035
|
+
return _executeVectorSync.apply(this, arguments);
|
|
5036
|
+
}
|
|
5037
|
+
function _executeVectorSync() {
|
|
5038
|
+
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref3) {
|
|
5039
|
+
var _event$user3, _agent$knowledge_sour;
|
|
5040
|
+
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$knowledge_sour2, _iterator6, _step6, _yield$mastra$dataLay3, _mastra$dataLayer9, vectorE, integrationName, k_id, _mastra$dataLayer10, connection, _loop3, _ret3, _iterator7, _step7;
|
|
5041
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context11) {
|
|
5042
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
5043
|
+
case 0:
|
|
5044
|
+
event = _ref3.event, mastra = _ref3.mastra;
|
|
5045
|
+
agentDir = mastra.config.agents.agentDirPath;
|
|
5046
|
+
agent = getAgentBlueprint({
|
|
5047
|
+
agentDir: agentDir,
|
|
5048
|
+
agentId: event.data.agentId
|
|
5049
|
+
});
|
|
5050
|
+
connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
|
|
5051
|
+
systemName = mastra.config.name;
|
|
5052
|
+
if (agent.knowledge_sources.vector_provider) {
|
|
5053
|
+
_context11.next = 8;
|
|
5054
|
+
break;
|
|
5055
|
+
}
|
|
5056
|
+
console.error("No vector_provider defined for agent");
|
|
5057
|
+
return _context11.abrupt("return");
|
|
5058
|
+
case 8:
|
|
5059
|
+
vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
|
|
5060
|
+
if (vp) {
|
|
5061
|
+
_context11.next = 12;
|
|
5062
|
+
break;
|
|
5063
|
+
}
|
|
5064
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
|
|
5065
|
+
return _context11.abrupt("return");
|
|
5066
|
+
case 12:
|
|
5067
|
+
if (process.env.OPENAI_API_KEY) {
|
|
5068
|
+
_context11.next = 15;
|
|
5069
|
+
break;
|
|
5070
|
+
}
|
|
5071
|
+
console.error('NO OPENAI_API_KEY');
|
|
5072
|
+
return _context11.abrupt("return");
|
|
5073
|
+
case 15:
|
|
5074
|
+
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
5075
|
+
_context11.next = 18;
|
|
5076
|
+
break;
|
|
5077
|
+
}
|
|
5078
|
+
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
5079
|
+
return _context11.abrupt("return");
|
|
5080
|
+
case 18:
|
|
5081
|
+
_iterator6 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
5082
|
+
case 19:
|
|
5083
|
+
if ((_step6 = _iterator6()).done) {
|
|
5084
|
+
_context11.next = 53;
|
|
5085
|
+
break;
|
|
5086
|
+
}
|
|
5087
|
+
vectorE = _step6.value;
|
|
5088
|
+
integrationName = vectorE.integration;
|
|
5089
|
+
_context11.next = 24;
|
|
5090
|
+
return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
|
|
5091
|
+
connectionId: connectionId,
|
|
5092
|
+
name: integrationName
|
|
5093
|
+
});
|
|
5094
|
+
case 24:
|
|
5095
|
+
_context11.t1 = _yield$mastra$dataLay3 = _context11.sent;
|
|
5096
|
+
if (!(_context11.t1 == null)) {
|
|
5097
|
+
_context11.next = 29;
|
|
5098
|
+
break;
|
|
5099
|
+
}
|
|
5100
|
+
_context11.t2 = void 0;
|
|
5101
|
+
_context11.next = 30;
|
|
5102
|
+
break;
|
|
5103
|
+
case 29:
|
|
5104
|
+
_context11.t2 = _yield$mastra$dataLay3.id;
|
|
5105
|
+
case 30:
|
|
5106
|
+
_context11.t0 = _context11.t2;
|
|
5107
|
+
if (_context11.t0) {
|
|
5108
|
+
_context11.next = 33;
|
|
5109
|
+
break;
|
|
5110
|
+
}
|
|
5111
|
+
_context11.t0 = '';
|
|
5112
|
+
case 33:
|
|
5113
|
+
k_id = _context11.t0;
|
|
5114
|
+
if (!(!k_id && integrationName === systemName)) {
|
|
5115
|
+
_context11.next = 39;
|
|
5116
|
+
break;
|
|
5117
|
+
}
|
|
5118
|
+
_context11.next = 37;
|
|
5119
|
+
return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
|
|
5120
|
+
connection: {
|
|
5121
|
+
connectionId: connectionId,
|
|
5122
|
+
name: integrationName
|
|
5123
|
+
},
|
|
5124
|
+
credential: {
|
|
5125
|
+
type: 'API_KEY',
|
|
5126
|
+
value: connectionId,
|
|
5127
|
+
scope: []
|
|
5128
|
+
}
|
|
5129
|
+
});
|
|
5130
|
+
case 37:
|
|
5131
|
+
connection = _context11.sent;
|
|
5132
|
+
k_id = connection.id;
|
|
5133
|
+
case 39:
|
|
5134
|
+
if (k_id) {
|
|
5135
|
+
_context11.next = 42;
|
|
5136
|
+
break;
|
|
5137
|
+
}
|
|
5138
|
+
console.error('Error bootstrapping shit');
|
|
5139
|
+
return _context11.abrupt("return");
|
|
5140
|
+
case 42:
|
|
5141
|
+
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
5142
|
+
var _mastra$dataLayer11, _entityRecords5, _records5;
|
|
5143
|
+
var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
|
|
5144
|
+
return _regeneratorRuntime().wrap(function _loop3$(_context10) {
|
|
5145
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
5146
|
+
case 0:
|
|
5147
|
+
entity = _step7.value;
|
|
5148
|
+
_context10.next = 3;
|
|
5149
|
+
return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
|
|
5150
|
+
k_id: k_id,
|
|
5151
|
+
type: entity.name
|
|
5152
|
+
});
|
|
5153
|
+
case 3:
|
|
5154
|
+
entityRecords = _context10.sent;
|
|
5155
|
+
records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
|
|
5156
|
+
if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
|
|
5157
|
+
_context10.next = 23;
|
|
5158
|
+
break;
|
|
5159
|
+
}
|
|
5160
|
+
// @TODO: SYNC THEM
|
|
5161
|
+
console.error('NO RECORDS');
|
|
5162
|
+
_context10.next = 9;
|
|
5163
|
+
return mastra.triggerEvent({
|
|
5164
|
+
key: entity.syncEvent,
|
|
5165
|
+
data: {},
|
|
5166
|
+
user: {
|
|
5167
|
+
connectionId: connectionId
|
|
5168
|
+
}
|
|
5169
|
+
});
|
|
5170
|
+
case 9:
|
|
5171
|
+
_yield$mastra$trigger3 = _context10.sent;
|
|
5172
|
+
_event3 = _yield$mastra$trigger3.event;
|
|
5173
|
+
console.log(_event3, '####');
|
|
5174
|
+
_context10.next = 14;
|
|
5175
|
+
return _event3.subscribe();
|
|
5176
|
+
case 14:
|
|
5177
|
+
res = _context10.sent;
|
|
5178
|
+
console.log('Subscribe result', res);
|
|
5179
|
+
_context10.next = 18;
|
|
5180
|
+
return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
|
|
5181
|
+
k_id: k_id,
|
|
5182
|
+
type: entity.name
|
|
5183
|
+
});
|
|
5184
|
+
case 18:
|
|
5185
|
+
entityRecords = _context10.sent;
|
|
5186
|
+
records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
|
|
5187
|
+
if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
|
|
5188
|
+
_context10.next = 23;
|
|
5189
|
+
break;
|
|
5190
|
+
}
|
|
5191
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
5192
|
+
return _context10.abrupt("return", {
|
|
5193
|
+
v: void 0
|
|
5194
|
+
});
|
|
5195
|
+
case 23:
|
|
5196
|
+
recordsMapped = records.map(function (_ref13) {
|
|
5197
|
+
var data = _ref13.data,
|
|
5198
|
+
externalId = _ref13.externalId;
|
|
5199
|
+
return _extends({
|
|
5200
|
+
id: externalId
|
|
5201
|
+
}, _.pick(data, entity.fields));
|
|
5202
|
+
});
|
|
5203
|
+
console.log(recordsMapped, 'RECORDS');
|
|
5204
|
+
_context10.next = 27;
|
|
5205
|
+
return vp.createIndex({
|
|
5206
|
+
suppressConflicts: true,
|
|
5207
|
+
name: entity.name,
|
|
5208
|
+
dimension: 1536,
|
|
5209
|
+
metric: 'cosine',
|
|
5210
|
+
spec: {
|
|
5211
|
+
serverless: {
|
|
5212
|
+
cloud: 'aws',
|
|
5213
|
+
region: 'us-east-1'
|
|
5214
|
+
}
|
|
5215
|
+
}
|
|
5216
|
+
});
|
|
5217
|
+
case 27:
|
|
5218
|
+
entityTypeIndex = vp.index(entity.name);
|
|
5219
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
5220
|
+
_context10.prev = 29;
|
|
5221
|
+
_context10.next = 32;
|
|
5222
|
+
return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
|
|
5223
|
+
var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(record) {
|
|
5224
|
+
var _yield$embed3, embedding;
|
|
5225
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context9) {
|
|
5226
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
5227
|
+
case 0:
|
|
5228
|
+
_context9.next = 2;
|
|
5229
|
+
return ai.embed({
|
|
5230
|
+
model: openai.openai.embedding('text-embedding-3-small'),
|
|
5231
|
+
value: JSON.stringify(record)
|
|
5232
|
+
});
|
|
5233
|
+
case 2:
|
|
5234
|
+
_yield$embed3 = _context9.sent;
|
|
5235
|
+
embedding = _yield$embed3.embedding;
|
|
5236
|
+
return _context9.abrupt("return", {
|
|
5237
|
+
id: record.id,
|
|
5238
|
+
values: embedding,
|
|
5239
|
+
metadata: record
|
|
5240
|
+
});
|
|
5241
|
+
case 5:
|
|
5242
|
+
case "end":
|
|
5243
|
+
return _context9.stop();
|
|
5244
|
+
}
|
|
5245
|
+
}, _callee7);
|
|
5246
|
+
}));
|
|
5247
|
+
return function (_x9) {
|
|
5248
|
+
return _ref14.apply(this, arguments);
|
|
5249
|
+
};
|
|
5250
|
+
}())) != null ? _recordsMapped$map3 : []);
|
|
4812
5251
|
case 32:
|
|
4813
|
-
vectors =
|
|
5252
|
+
vectors = _context10.sent;
|
|
4814
5253
|
console.log('UPSERTING', vectors);
|
|
4815
5254
|
if (!(vectors.length > 0)) {
|
|
4816
|
-
|
|
5255
|
+
_context10.next = 37;
|
|
4817
5256
|
break;
|
|
4818
5257
|
}
|
|
4819
|
-
|
|
5258
|
+
_context10.next = 37;
|
|
4820
5259
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4821
5260
|
case 37:
|
|
4822
|
-
|
|
5261
|
+
_context10.next = 42;
|
|
4823
5262
|
break;
|
|
4824
5263
|
case 39:
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
console.error(
|
|
5264
|
+
_context10.prev = 39;
|
|
5265
|
+
_context10.t0 = _context10["catch"](29);
|
|
5266
|
+
console.error(_context10.t0);
|
|
4828
5267
|
case 42:
|
|
4829
|
-
return
|
|
5268
|
+
return _context10.abrupt("return", {
|
|
4830
5269
|
v: void 0
|
|
4831
5270
|
});
|
|
4832
5271
|
case 43:
|
|
4833
5272
|
case "end":
|
|
4834
|
-
return
|
|
5273
|
+
return _context10.stop();
|
|
4835
5274
|
}
|
|
4836
|
-
},
|
|
5275
|
+
}, _loop3, null, [[29, 39]]);
|
|
4837
5276
|
});
|
|
4838
|
-
|
|
5277
|
+
_iterator7 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4839
5278
|
case 44:
|
|
4840
|
-
if ((
|
|
4841
|
-
|
|
5279
|
+
if ((_step7 = _iterator7()).done) {
|
|
5280
|
+
_context11.next = 51;
|
|
4842
5281
|
break;
|
|
4843
5282
|
}
|
|
4844
|
-
return
|
|
5283
|
+
return _context11.delegateYield(_loop3(), "t3", 46);
|
|
4845
5284
|
case 46:
|
|
4846
|
-
|
|
4847
|
-
if (!
|
|
4848
|
-
|
|
5285
|
+
_ret3 = _context11.t3;
|
|
5286
|
+
if (!_ret3) {
|
|
5287
|
+
_context11.next = 49;
|
|
4849
5288
|
break;
|
|
4850
5289
|
}
|
|
4851
|
-
return
|
|
5290
|
+
return _context11.abrupt("return", _ret3.v);
|
|
4852
5291
|
case 49:
|
|
4853
|
-
|
|
5292
|
+
_context11.next = 44;
|
|
4854
5293
|
break;
|
|
4855
5294
|
case 51:
|
|
4856
|
-
|
|
5295
|
+
_context11.next = 19;
|
|
4857
5296
|
break;
|
|
4858
5297
|
case 53:
|
|
4859
5298
|
case "end":
|
|
4860
|
-
return
|
|
5299
|
+
return _context11.stop();
|
|
4861
5300
|
}
|
|
4862
|
-
},
|
|
5301
|
+
}, _callee8);
|
|
4863
5302
|
}));
|
|
4864
5303
|
return _executeVectorSync.apply(this, arguments);
|
|
4865
5304
|
}
|
|
4866
|
-
function vectorQueryEngine(
|
|
5305
|
+
function vectorQueryEngine(_x4) {
|
|
4867
5306
|
return _vectorQueryEngine.apply(this, arguments);
|
|
4868
5307
|
}
|
|
4869
5308
|
function _vectorQueryEngine() {
|
|
4870
|
-
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4871
|
-
var vector_provider,
|
|
4872
|
-
return _regeneratorRuntime().wrap(function
|
|
4873
|
-
while (1) switch (
|
|
5309
|
+
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref4) {
|
|
5310
|
+
var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
|
|
5311
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context12) {
|
|
5312
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
4874
5313
|
case 0:
|
|
4875
|
-
vector_provider =
|
|
5314
|
+
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;
|
|
4876
5315
|
vp = getVectorProvider(vector_provider);
|
|
4877
5316
|
if (vp) {
|
|
4878
|
-
|
|
5317
|
+
_context12.next = 5;
|
|
4879
5318
|
break;
|
|
4880
5319
|
}
|
|
4881
5320
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4882
|
-
return
|
|
5321
|
+
return _context12.abrupt("return");
|
|
4883
5322
|
case 5:
|
|
4884
5323
|
index = vp.index(indexName);
|
|
4885
|
-
|
|
5324
|
+
_context12.next = 8;
|
|
4886
5325
|
return ai.embed({
|
|
4887
5326
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4888
5327
|
value: content
|
|
4889
5328
|
});
|
|
4890
5329
|
case 8:
|
|
4891
|
-
_yield$
|
|
4892
|
-
embedding = _yield$
|
|
5330
|
+
_yield$embed4 = _context12.sent;
|
|
5331
|
+
embedding = _yield$embed4.embedding;
|
|
4893
5332
|
console.log(embedding, 'EMBEDDING');
|
|
4894
|
-
|
|
5333
|
+
_context12.next = 13;
|
|
4895
5334
|
return index.namespace(entityType).query({
|
|
4896
5335
|
vector: embedding,
|
|
4897
5336
|
topK: topK,
|
|
4898
5337
|
includeMetadata: true
|
|
4899
5338
|
});
|
|
4900
5339
|
case 13:
|
|
4901
|
-
queryResponse =
|
|
4902
|
-
return
|
|
5340
|
+
queryResponse = _context12.sent;
|
|
5341
|
+
return _context12.abrupt("return", queryResponse);
|
|
4903
5342
|
case 15:
|
|
4904
5343
|
case "end":
|
|
4905
|
-
return
|
|
5344
|
+
return _context12.stop();
|
|
4906
5345
|
}
|
|
4907
|
-
},
|
|
5346
|
+
}, _callee9);
|
|
4908
5347
|
}));
|
|
4909
5348
|
return _vectorQueryEngine.apply(this, arguments);
|
|
4910
5349
|
}
|
|
4911
|
-
function
|
|
4912
|
-
var
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
5350
|
+
var fetchPineconeIndexes = /*#__PURE__*/function () {
|
|
5351
|
+
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
5352
|
+
var response, _ref6, indexes;
|
|
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;
|
|
5398
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5399
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5400
|
+
case 0:
|
|
5401
|
+
_context2.prev = 0;
|
|
5402
|
+
_context2.next = 3;
|
|
5403
|
+
return fetch("https://" + host + "/describe_index_stats", {
|
|
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
|
+
});
|
|
5411
|
+
case 3:
|
|
5412
|
+
response = _context2.sent;
|
|
5413
|
+
_context2.next = 6;
|
|
5414
|
+
return response.json();
|
|
5415
|
+
case 6:
|
|
5416
|
+
_context2.t0 = _context2.sent;
|
|
5417
|
+
if (_context2.t0) {
|
|
5418
|
+
_context2.next = 9;
|
|
5419
|
+
break;
|
|
5420
|
+
}
|
|
5421
|
+
_context2.t0 = {};
|
|
5422
|
+
case 9:
|
|
5423
|
+
data = _context2.t0;
|
|
5424
|
+
return _context2.abrupt("return", data);
|
|
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:
|
|
5430
|
+
case "end":
|
|
5431
|
+
return _context2.stop();
|
|
5432
|
+
}
|
|
5433
|
+
}, _callee2, null, [[0, 13]]);
|
|
5434
|
+
}));
|
|
5435
|
+
return function fetchPineconeIndexStats(_x5) {
|
|
5436
|
+
return _ref7.apply(this, arguments);
|
|
5437
|
+
};
|
|
5438
|
+
}();
|
|
5439
|
+
var pineconeIndexes = [];
|
|
5440
|
+
function getVectorQueryApis(_x6) {
|
|
5441
|
+
return _getVectorQueryApis.apply(this, arguments);
|
|
5442
|
+
}
|
|
5443
|
+
function _getVectorQueryApis() {
|
|
5444
|
+
_getVectorQueryApis = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref8) {
|
|
5445
|
+
var mastra, vectorProvider, vectorApis, _loop4, _iterator8, _step8;
|
|
5446
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context16) {
|
|
5447
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
5448
|
+
case 0:
|
|
5449
|
+
mastra = _ref8.mastra;
|
|
5450
|
+
vectorProvider = mastra.config.agents.vectorProvider;
|
|
5451
|
+
if (vectorProvider) {
|
|
5452
|
+
_context16.next = 5;
|
|
5453
|
+
break;
|
|
5454
|
+
}
|
|
5455
|
+
console.error('NO VECTOR PROVIDER');
|
|
5456
|
+
return _context16.abrupt("return", []);
|
|
5457
|
+
case 5:
|
|
5458
|
+
vectorApis = [];
|
|
5459
|
+
_loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
|
|
5460
|
+
var provider, indexes, indexesWithStats;
|
|
5461
|
+
return _regeneratorRuntime().wrap(function _loop4$(_context15) {
|
|
5462
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
5463
|
+
case 0:
|
|
5464
|
+
provider = _step8.value;
|
|
5465
|
+
if (!(provider.name === 'pinecone')) {
|
|
5466
|
+
_context15.next = 13;
|
|
5467
|
+
break;
|
|
5468
|
+
}
|
|
5469
|
+
if (!(pineconeIndexes.length === 0)) {
|
|
5470
|
+
_context15.next = 12;
|
|
5471
|
+
break;
|
|
5472
|
+
}
|
|
5473
|
+
console.log('FETCHING PINECONE INDEXES');
|
|
5474
|
+
_context15.next = 6;
|
|
5475
|
+
return fetchPineconeIndexes();
|
|
5476
|
+
case 6:
|
|
5477
|
+
indexes = _context15.sent;
|
|
5478
|
+
if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
|
|
5479
|
+
_context15.next = 12;
|
|
5480
|
+
break;
|
|
5481
|
+
}
|
|
5482
|
+
_context15.next = 10;
|
|
5483
|
+
return Promise.all(indexes.map(/*#__PURE__*/function () {
|
|
5484
|
+
var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(index) {
|
|
5485
|
+
var stats, namespaces;
|
|
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;
|
|
5574
|
+
}
|
|
5575
|
+
return _context16.delegateYield(_loop4(), "t0", 10);
|
|
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();
|
|
5584
|
+
}
|
|
5585
|
+
}, _callee12);
|
|
5586
|
+
}));
|
|
5587
|
+
return _getVectorQueryApis.apply(this, arguments);
|
|
4982
5588
|
}
|
|
4983
5589
|
function agentVectorSyncEvent() {
|
|
4984
5590
|
return {
|
|
@@ -4996,6 +5602,13 @@ function genericVectorySyncEvent() {
|
|
|
4996
5602
|
executor: executeGenericVectorSync
|
|
4997
5603
|
};
|
|
4998
5604
|
}
|
|
5605
|
+
function vectorIndexSync() {
|
|
5606
|
+
return {
|
|
5607
|
+
id: 'vector-index-sync',
|
|
5608
|
+
event: 'VECTOR_INDEX_SYNC',
|
|
5609
|
+
executor: executeIndexSync
|
|
5610
|
+
};
|
|
5611
|
+
}
|
|
4999
5612
|
|
|
5000
5613
|
function getAgentSystemApis(_ref) {
|
|
5001
5614
|
var mastra = _ref.mastra;
|
|
@@ -5004,11 +5617,14 @@ function getAgentSystemApis(_ref) {
|
|
|
5004
5617
|
agentDir: agentDir
|
|
5005
5618
|
});
|
|
5006
5619
|
// Remove the .json extension from the agent names
|
|
5007
|
-
var agentList =
|
|
5008
|
-
|
|
5009
|
-
|
|
5620
|
+
var agentList = [];
|
|
5621
|
+
if (agents) {
|
|
5622
|
+
agentList = agents.map(function (agent) {
|
|
5623
|
+
return agent.slice(0, -5);
|
|
5624
|
+
});
|
|
5625
|
+
}
|
|
5010
5626
|
return [{
|
|
5011
|
-
integrationName:
|
|
5627
|
+
integrationName: mastra.config.name,
|
|
5012
5628
|
type: 'message_agent',
|
|
5013
5629
|
label: 'Send Message To Agent',
|
|
5014
5630
|
description: 'Sends a message to an Agent',
|
|
@@ -5021,55 +5637,58 @@ function getAgentSystemApis(_ref) {
|
|
|
5021
5637
|
}),
|
|
5022
5638
|
executor: function () {
|
|
5023
5639
|
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5024
|
-
var data, executor, result, _run$content, thread, run;
|
|
5640
|
+
var data, ctx, executor, result, _run$content, thread, run;
|
|
5025
5641
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5026
5642
|
while (1) switch (_context.prev = _context.next) {
|
|
5027
5643
|
case 0:
|
|
5028
|
-
data = _ref2.data;
|
|
5644
|
+
data = _ref2.data, ctx = _ref2.ctx;
|
|
5029
5645
|
_context.next = 3;
|
|
5030
5646
|
return mastra.getAgent({
|
|
5031
5647
|
agentId: data.agentId,
|
|
5032
|
-
connectionId:
|
|
5648
|
+
connectionId: ctx.connectionId
|
|
5033
5649
|
});
|
|
5034
5650
|
case 3:
|
|
5035
5651
|
executor = _context.sent;
|
|
5652
|
+
console.log('executor====', {
|
|
5653
|
+
executor: executor
|
|
5654
|
+
});
|
|
5036
5655
|
if (executor) {
|
|
5037
|
-
_context.next =
|
|
5656
|
+
_context.next = 7;
|
|
5038
5657
|
break;
|
|
5039
5658
|
}
|
|
5040
5659
|
throw new Error('Could not create agent executor');
|
|
5041
|
-
case
|
|
5660
|
+
case 7:
|
|
5042
5661
|
if (!(typeof executor === 'function')) {
|
|
5043
|
-
_context.next =
|
|
5662
|
+
_context.next = 14;
|
|
5044
5663
|
break;
|
|
5045
5664
|
}
|
|
5046
|
-
_context.next =
|
|
5665
|
+
_context.next = 10;
|
|
5047
5666
|
return executor({
|
|
5048
5667
|
prompt: data == null ? void 0 : data.message
|
|
5049
5668
|
});
|
|
5050
|
-
case
|
|
5669
|
+
case 10:
|
|
5051
5670
|
result = _context.sent;
|
|
5052
5671
|
return _context.abrupt("return", {
|
|
5053
5672
|
message: result == null ? void 0 : result.text
|
|
5054
5673
|
});
|
|
5055
|
-
case
|
|
5056
|
-
_context.next =
|
|
5674
|
+
case 14:
|
|
5675
|
+
_context.next = 16;
|
|
5057
5676
|
return executor.initializeThread([{
|
|
5058
5677
|
role: 'user',
|
|
5059
5678
|
content: data == null ? void 0 : data.message
|
|
5060
5679
|
}]);
|
|
5061
|
-
case
|
|
5680
|
+
case 16:
|
|
5062
5681
|
thread = _context.sent;
|
|
5063
|
-
_context.next =
|
|
5682
|
+
_context.next = 19;
|
|
5064
5683
|
return executor.watchRun({
|
|
5065
5684
|
threadId: thread.id
|
|
5066
5685
|
});
|
|
5067
|
-
case
|
|
5686
|
+
case 19:
|
|
5068
5687
|
run = _context.sent;
|
|
5069
5688
|
return _context.abrupt("return", {
|
|
5070
5689
|
message: run == null || (_run$content = run.content) == null || (_run$content = _run$content[0]) == null || (_run$content = _run$content.text) == null ? void 0 : _run$content.value
|
|
5071
5690
|
});
|
|
5072
|
-
case
|
|
5691
|
+
case 21:
|
|
5073
5692
|
case "end":
|
|
5074
5693
|
return _context.stop();
|
|
5075
5694
|
}
|
|
@@ -5083,427 +5702,502 @@ function getAgentSystemApis(_ref) {
|
|
|
5083
5702
|
}];
|
|
5084
5703
|
}
|
|
5085
5704
|
|
|
5086
|
-
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
5087
|
-
function createFileLogger(_ref) {
|
|
5088
|
-
var destinationPath = _ref.destinationPath;
|
|
5089
|
-
var fullPath = path.join(loggerPath, destinationPath);
|
|
5090
|
-
return function (log) {
|
|
5091
|
-
if (!fs.existsSync(loggerPath)) {
|
|
5092
|
-
fs.mkdirSync(loggerPath, {
|
|
5093
|
-
recursive: true
|
|
5094
|
-
});
|
|
5095
|
-
return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
5096
|
-
createdAt: new Date()
|
|
5097
|
-
})], null, 2));
|
|
5098
|
-
}
|
|
5099
|
-
var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
5100
|
-
logs.push(_extends({}, log, {
|
|
5101
|
-
createdAt: new Date()
|
|
5102
|
-
}));
|
|
5103
|
-
return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
5104
|
-
};
|
|
5105
|
-
}
|
|
5106
|
-
|
|
5107
5705
|
var client;
|
|
5108
5706
|
if (process.env.OPENAI_API_KEY) {
|
|
5109
5707
|
client = /*#__PURE__*/new OpenAI({
|
|
5110
5708
|
apiKey: process.env.OPENAI_API_KEY
|
|
5111
5709
|
});
|
|
5112
5710
|
}
|
|
5113
|
-
function
|
|
5114
|
-
return
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
_context3.next = 4;
|
|
5142
|
-
return client.beta.threads.messages.list(threadId);
|
|
5143
|
-
case 4:
|
|
5144
|
-
messages = _context3.sent;
|
|
5145
|
-
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5146
|
-
case 8:
|
|
5147
|
-
if (!(run.status === 'requires_action')) {
|
|
5148
|
-
_context3.next = 14;
|
|
5149
|
-
break;
|
|
5150
|
-
}
|
|
5151
|
-
_context3.next = 11;
|
|
5152
|
-
return handleRequiresAction({
|
|
5153
|
-
run: run,
|
|
5154
|
-
threadId: threadId
|
|
5155
|
-
});
|
|
5156
|
-
case 11:
|
|
5157
|
-
return _context3.abrupt("return", _context3.sent);
|
|
5158
|
-
case 14:
|
|
5159
|
-
console.error('Run did not complete:', run);
|
|
5160
|
-
logger({
|
|
5161
|
-
statusCode: 400,
|
|
5162
|
-
message: JSON.stringify({
|
|
5163
|
-
message: "Run did not complete",
|
|
5164
|
-
event_type: 'run_error',
|
|
5165
|
-
metadata: {
|
|
5166
|
-
run: run
|
|
5167
|
-
}
|
|
5168
|
-
}, null, 2)
|
|
5169
|
-
});
|
|
5170
|
-
case 16:
|
|
5171
|
-
case "end":
|
|
5172
|
-
return _context3.stop();
|
|
5173
|
-
}
|
|
5174
|
-
}, _callee3);
|
|
5175
|
-
}));
|
|
5176
|
-
return function handleRunStatus(_x4) {
|
|
5177
|
-
return _ref5.apply(this, arguments);
|
|
5178
|
-
};
|
|
5179
|
-
}();
|
|
5180
|
-
handleRequiresAction = /*#__PURE__*/function () {
|
|
5181
|
-
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5182
|
-
var threadId, run, toolOutputs;
|
|
5183
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5184
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
5185
|
-
case 0:
|
|
5186
|
-
threadId = _ref6.threadId, run = _ref6.run;
|
|
5187
|
-
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5188
|
-
_context5.next = 23;
|
|
5189
|
-
break;
|
|
5190
|
-
}
|
|
5191
|
-
_context5.t0 = _.compact;
|
|
5192
|
-
_context5.next = 5;
|
|
5193
|
-
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5194
|
-
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5195
|
-
var callInfo, toolMetadata, toolFn, args, output;
|
|
5196
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5197
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
5198
|
-
case 0:
|
|
5199
|
-
callInfo = index + 1 + " of " + tools.length;
|
|
5200
|
-
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5201
|
-
toolMetadata = {
|
|
5202
|
-
id: tool.id,
|
|
5203
|
-
fn: tool["function"].name,
|
|
5204
|
-
availableTools: Object.keys(toolMap)
|
|
5205
|
-
};
|
|
5206
|
-
logger({
|
|
5207
|
-
statusCode: 100,
|
|
5208
|
-
message: JSON.stringify({
|
|
5209
|
-
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5210
|
-
metadata: {
|
|
5211
|
-
tool: toolMetadata
|
|
5212
|
-
}
|
|
5213
|
-
}, null, 2)
|
|
5214
|
-
});
|
|
5215
|
-
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5216
|
-
if (toolFn) {
|
|
5217
|
-
_context4.next = 8;
|
|
5218
|
-
break;
|
|
5219
|
-
}
|
|
5220
|
-
logger({
|
|
5221
|
-
statusCode: 404,
|
|
5222
|
-
message: JSON.stringify({
|
|
5223
|
-
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5224
|
-
metadata: {
|
|
5225
|
-
tool: toolMetadata
|
|
5226
|
-
}
|
|
5227
|
-
}, null, 2)
|
|
5228
|
-
});
|
|
5229
|
-
return _context4.abrupt("return");
|
|
5230
|
-
case 8:
|
|
5231
|
-
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5232
|
-
args = {};
|
|
5233
|
-
try {
|
|
5234
|
-
if (tool["function"].arguments) {
|
|
5235
|
-
args = JSON.parse(tool["function"].arguments);
|
|
5236
|
-
logger({
|
|
5237
|
-
statusCode: 100,
|
|
5238
|
-
message: JSON.stringify({
|
|
5239
|
-
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5240
|
-
metadata: {
|
|
5241
|
-
args: args,
|
|
5242
|
-
tool: toolMetadata
|
|
5243
|
-
}
|
|
5244
|
-
}, null, 2)
|
|
5245
|
-
});
|
|
5246
|
-
}
|
|
5247
|
-
} catch (e) {
|
|
5248
|
-
console.error(e);
|
|
5249
|
-
}
|
|
5250
|
-
_context4.next = 13;
|
|
5251
|
-
return toolFn(args);
|
|
5252
|
-
case 13:
|
|
5253
|
-
output = _context4.sent;
|
|
5254
|
-
logger({
|
|
5255
|
-
statusCode: 200,
|
|
5256
|
-
message: JSON.stringify({
|
|
5257
|
-
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5258
|
-
metadata: {
|
|
5259
|
-
output: output,
|
|
5260
|
-
tool: toolMetadata
|
|
5261
|
-
}
|
|
5262
|
-
}, null, 2)
|
|
5263
|
-
});
|
|
5264
|
-
return _context4.abrupt("return", {
|
|
5265
|
-
tool_call_id: tool.id,
|
|
5266
|
-
output: JSON.stringify(output)
|
|
5267
|
-
});
|
|
5268
|
-
case 16:
|
|
5269
|
-
case "end":
|
|
5270
|
-
return _context4.stop();
|
|
5271
|
-
}
|
|
5272
|
-
}, _callee4);
|
|
5273
|
-
}));
|
|
5274
|
-
return function (_x6, _x7, _x8) {
|
|
5275
|
-
return _ref8.apply(this, arguments);
|
|
5276
|
-
};
|
|
5277
|
-
}()));
|
|
5278
|
-
case 5:
|
|
5279
|
-
_context5.t1 = _context5.sent;
|
|
5280
|
-
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5281
|
-
if (toolOutputs) {
|
|
5282
|
-
_context5.next = 11;
|
|
5283
|
-
break;
|
|
5284
|
-
}
|
|
5285
|
-
console.error('No tool outputs to submit.');
|
|
5286
|
-
logger({
|
|
5287
|
-
statusCode: 404,
|
|
5288
|
-
message: JSON.stringify({
|
|
5289
|
-
message: "No tool outputs submitted",
|
|
5290
|
-
metadata: {}
|
|
5291
|
-
}, null, 2)
|
|
5292
|
-
});
|
|
5293
|
-
return _context5.abrupt("return", handleRunStatus({
|
|
5294
|
-
threadId: threadId,
|
|
5295
|
-
run: run
|
|
5296
|
-
}));
|
|
5297
|
-
case 11:
|
|
5298
|
-
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5299
|
-
_context5.next = 20;
|
|
5300
|
-
break;
|
|
5301
|
-
}
|
|
5302
|
-
console.log(toolOutputs, '###### YOOOOOO');
|
|
5303
|
-
_context5.next = 15;
|
|
5304
|
-
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5305
|
-
tool_outputs: toolOutputs
|
|
5306
|
-
});
|
|
5307
|
-
case 15:
|
|
5308
|
-
run = _context5.sent;
|
|
5309
|
-
logger({
|
|
5310
|
-
statusCode: 200,
|
|
5311
|
-
message: JSON.stringify({
|
|
5312
|
-
message: "Tool outputs submitted",
|
|
5313
|
-
metadata: {
|
|
5314
|
-
run: run
|
|
5315
|
-
}
|
|
5316
|
-
}, null, 2)
|
|
5317
|
-
});
|
|
5318
|
-
console.log('Tool outputs submitted successfully.');
|
|
5319
|
-
_context5.next = 22;
|
|
5320
|
-
break;
|
|
5321
|
-
case 20:
|
|
5322
|
-
logger({
|
|
5323
|
-
statusCode: 404,
|
|
5324
|
-
message: JSON.stringify({
|
|
5325
|
-
message: "No tool outputs to submit",
|
|
5326
|
-
metadata: {}
|
|
5327
|
-
}, null, 2)
|
|
5328
|
-
});
|
|
5329
|
-
console.log('No tool outputs to submit.');
|
|
5330
|
-
case 22:
|
|
5331
|
-
return _context5.abrupt("return", handleRunStatus({
|
|
5332
|
-
threadId: threadId,
|
|
5333
|
-
run: run
|
|
5334
|
-
}));
|
|
5335
|
-
case 23:
|
|
5336
|
-
case "end":
|
|
5337
|
-
return _context5.stop();
|
|
5711
|
+
function createAssistantAgentHandler(logger) {
|
|
5712
|
+
return /*#__PURE__*/function () {
|
|
5713
|
+
var _createAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
5714
|
+
var name, instructions, model, tools, response_format, assistant;
|
|
5715
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5716
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5717
|
+
case 0:
|
|
5718
|
+
name = _ref.name, instructions = _ref.instructions, model = _ref.model, tools = _ref.tools, response_format = _ref.response_format;
|
|
5719
|
+
_context.next = 3;
|
|
5720
|
+
return client.beta.assistants.create({
|
|
5721
|
+
name: name,
|
|
5722
|
+
model: model,
|
|
5723
|
+
instructions: instructions,
|
|
5724
|
+
tools: tools,
|
|
5725
|
+
response_format: response_format
|
|
5726
|
+
});
|
|
5727
|
+
case 3:
|
|
5728
|
+
assistant = _context.sent;
|
|
5729
|
+
logger({
|
|
5730
|
+
destinationPath: assistant.id + ".json",
|
|
5731
|
+
statusCode: 201,
|
|
5732
|
+
message: JSON.stringify({
|
|
5733
|
+
message: 'Created assistant',
|
|
5734
|
+
metadata: {
|
|
5735
|
+
name: name,
|
|
5736
|
+
model: model,
|
|
5737
|
+
instructions: instructions,
|
|
5738
|
+
tools: tools
|
|
5338
5739
|
}
|
|
5339
|
-
},
|
|
5340
|
-
})
|
|
5341
|
-
return
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5740
|
+
}, null, 2)
|
|
5741
|
+
});
|
|
5742
|
+
return _context.abrupt("return", assistant);
|
|
5743
|
+
case 6:
|
|
5744
|
+
case "end":
|
|
5745
|
+
return _context.stop();
|
|
5746
|
+
}
|
|
5747
|
+
}, _callee);
|
|
5748
|
+
}));
|
|
5749
|
+
function createAssistantAgent(_x) {
|
|
5750
|
+
return _createAssistantAgent.apply(this, arguments);
|
|
5751
|
+
}
|
|
5752
|
+
return createAssistantAgent;
|
|
5753
|
+
}();
|
|
5754
|
+
}
|
|
5755
|
+
function updateAssistantAgentHandler(logger) {
|
|
5756
|
+
return /*#__PURE__*/function () {
|
|
5757
|
+
var _updateAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
5758
|
+
var assistantId, name, instructions, model, tools, response_format, assistant;
|
|
5759
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5760
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5761
|
+
case 0:
|
|
5762
|
+
assistantId = _ref2.assistantId, name = _ref2.name, instructions = _ref2.instructions, model = _ref2.model, tools = _ref2.tools, response_format = _ref2.response_format;
|
|
5763
|
+
_context2.next = 3;
|
|
5764
|
+
return client.beta.assistants.update(assistantId, {
|
|
5765
|
+
name: name,
|
|
5766
|
+
model: model,
|
|
5767
|
+
instructions: instructions,
|
|
5768
|
+
tools: tools,
|
|
5769
|
+
response_format: response_format
|
|
5770
|
+
});
|
|
5771
|
+
case 3:
|
|
5772
|
+
assistant = _context2.sent;
|
|
5773
|
+
logger({
|
|
5774
|
+
destinationPath: assistant.id + ".json",
|
|
5775
|
+
statusCode: 200,
|
|
5776
|
+
message: JSON.stringify({
|
|
5777
|
+
message: 'Updated assistant',
|
|
5778
|
+
metadata: {
|
|
5779
|
+
name: name,
|
|
5780
|
+
model: model,
|
|
5781
|
+
instructions: instructions,
|
|
5782
|
+
tools: tools,
|
|
5783
|
+
response_format: response_format
|
|
5359
5784
|
}
|
|
5360
|
-
},
|
|
5361
|
-
})
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5785
|
+
}, null, 2)
|
|
5786
|
+
});
|
|
5787
|
+
case 5:
|
|
5788
|
+
case "end":
|
|
5789
|
+
return _context2.stop();
|
|
5790
|
+
}
|
|
5791
|
+
}, _callee2);
|
|
5792
|
+
}));
|
|
5793
|
+
function updateAssistantAgent(_x2) {
|
|
5794
|
+
return _updateAssistantAgent.apply(this, arguments);
|
|
5795
|
+
}
|
|
5796
|
+
return updateAssistantAgent;
|
|
5797
|
+
}();
|
|
5798
|
+
}
|
|
5799
|
+
function getAssistantAgentHandler(logger) {
|
|
5800
|
+
return /*#__PURE__*/function () {
|
|
5801
|
+
var _getAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref3) {
|
|
5802
|
+
var id, toolMap, tool_choice, agent, handleRunStatus, handleRequiresAction, getRun;
|
|
5803
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
5804
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
5805
|
+
case 0:
|
|
5806
|
+
id = _ref3.id, toolMap = _ref3.toolMap, tool_choice = _ref3.tool_choice;
|
|
5807
|
+
_context11.next = 3;
|
|
5808
|
+
return client.beta.assistants.retrieve(id);
|
|
5809
|
+
case 3:
|
|
5810
|
+
agent = _context11.sent;
|
|
5811
|
+
handleRunStatus = /*#__PURE__*/function () {
|
|
5812
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
5813
|
+
var threadId, run, _messages$data, messages;
|
|
5814
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5815
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5372
5816
|
case 0:
|
|
5373
|
-
|
|
5374
|
-
|
|
5817
|
+
threadId = _ref4.threadId, run = _ref4.run;
|
|
5818
|
+
if (!(run.status === 'completed')) {
|
|
5819
|
+
_context3.next = 8;
|
|
5820
|
+
break;
|
|
5375
5821
|
}
|
|
5376
|
-
|
|
5377
|
-
return client.beta.threads.create({
|
|
5378
|
-
messages: messages
|
|
5379
|
-
});
|
|
5380
|
-
case 3:
|
|
5381
|
-
return _context7.abrupt("return", _context7.sent);
|
|
5382
|
-
case 4:
|
|
5383
|
-
case "end":
|
|
5384
|
-
return _context7.stop();
|
|
5385
|
-
}
|
|
5386
|
-
}, _callee7);
|
|
5387
|
-
}));
|
|
5388
|
-
function initializeThread(_x10) {
|
|
5389
|
-
return _initializeThread.apply(this, arguments);
|
|
5390
|
-
}
|
|
5391
|
-
return initializeThread;
|
|
5392
|
-
}(),
|
|
5393
|
-
listMessages: function () {
|
|
5394
|
-
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
5395
|
-
var threadId;
|
|
5396
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5397
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
5398
|
-
case 0:
|
|
5399
|
-
threadId = _ref11.threadId;
|
|
5400
|
-
_context8.next = 3;
|
|
5822
|
+
_context3.next = 4;
|
|
5401
5823
|
return client.beta.threads.messages.list(threadId);
|
|
5402
|
-
case 3:
|
|
5403
|
-
return _context8.abrupt("return", _context8.sent);
|
|
5404
5824
|
case 4:
|
|
5405
|
-
|
|
5406
|
-
return
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
handleRunStatus: handleRunStatus,
|
|
5417
|
-
handleRequiresAction: handleRequiresAction,
|
|
5418
|
-
createUserMessage: function () {
|
|
5419
|
-
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
5420
|
-
var threadId, content;
|
|
5421
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
5422
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
5423
|
-
case 0:
|
|
5424
|
-
threadId = _ref12.threadId, content = _ref12.content;
|
|
5425
|
-
_context9.next = 3;
|
|
5426
|
-
return client.beta.threads.messages.create(threadId, {
|
|
5427
|
-
role: 'user',
|
|
5428
|
-
content: content
|
|
5825
|
+
messages = _context3.sent;
|
|
5826
|
+
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5827
|
+
case 8:
|
|
5828
|
+
if (!(run.status === 'requires_action')) {
|
|
5829
|
+
_context3.next = 14;
|
|
5830
|
+
break;
|
|
5831
|
+
}
|
|
5832
|
+
_context3.next = 11;
|
|
5833
|
+
return handleRequiresAction({
|
|
5834
|
+
run: run,
|
|
5835
|
+
threadId: threadId
|
|
5429
5836
|
});
|
|
5430
|
-
case
|
|
5431
|
-
return
|
|
5432
|
-
case
|
|
5837
|
+
case 11:
|
|
5838
|
+
return _context3.abrupt("return", _context3.sent);
|
|
5839
|
+
case 14:
|
|
5840
|
+
console.error('Run did not complete:', run);
|
|
5841
|
+
logger({
|
|
5842
|
+
destinationPath: id + ".json",
|
|
5843
|
+
statusCode: 400,
|
|
5844
|
+
message: JSON.stringify({
|
|
5845
|
+
message: "Run did not complete",
|
|
5846
|
+
event_type: 'run_error',
|
|
5847
|
+
metadata: {
|
|
5848
|
+
run: run
|
|
5849
|
+
}
|
|
5850
|
+
}, null, 2)
|
|
5851
|
+
});
|
|
5852
|
+
case 16:
|
|
5433
5853
|
case "end":
|
|
5434
|
-
return
|
|
5854
|
+
return _context3.stop();
|
|
5435
5855
|
}
|
|
5436
|
-
},
|
|
5856
|
+
}, _callee3);
|
|
5437
5857
|
}));
|
|
5438
|
-
function
|
|
5439
|
-
return
|
|
5440
|
-
}
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
5858
|
+
return function handleRunStatus(_x4) {
|
|
5859
|
+
return _ref5.apply(this, arguments);
|
|
5860
|
+
};
|
|
5861
|
+
}();
|
|
5862
|
+
handleRequiresAction = /*#__PURE__*/function () {
|
|
5863
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5864
|
+
var threadId, run, toolOutputs;
|
|
5865
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5866
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
5448
5867
|
case 0:
|
|
5449
|
-
|
|
5450
|
-
if (!
|
|
5451
|
-
|
|
5868
|
+
threadId = _ref6.threadId, run = _ref6.run;
|
|
5869
|
+
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5870
|
+
_context5.next = 23;
|
|
5452
5871
|
break;
|
|
5453
5872
|
}
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5873
|
+
_context5.t0 = _.compact;
|
|
5874
|
+
_context5.next = 5;
|
|
5875
|
+
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5876
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5877
|
+
var callInfo, toolMetadata, toolFn, args, output;
|
|
5878
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5879
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5880
|
+
case 0:
|
|
5881
|
+
callInfo = index + 1 + " of " + tools.length;
|
|
5882
|
+
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5883
|
+
toolMetadata = {
|
|
5884
|
+
id: tool.id,
|
|
5885
|
+
fn: tool["function"].name,
|
|
5886
|
+
availableTools: Object.keys(toolMap)
|
|
5887
|
+
};
|
|
5888
|
+
logger({
|
|
5889
|
+
destinationPath: id + ".json",
|
|
5890
|
+
statusCode: 100,
|
|
5891
|
+
message: JSON.stringify({
|
|
5892
|
+
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5893
|
+
metadata: {
|
|
5894
|
+
tool: toolMetadata
|
|
5895
|
+
}
|
|
5896
|
+
}, null, 2)
|
|
5897
|
+
});
|
|
5898
|
+
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5899
|
+
if (toolFn) {
|
|
5900
|
+
_context4.next = 8;
|
|
5901
|
+
break;
|
|
5902
|
+
}
|
|
5903
|
+
logger({
|
|
5904
|
+
destinationPath: id + ".json",
|
|
5905
|
+
statusCode: 404,
|
|
5906
|
+
message: JSON.stringify({
|
|
5907
|
+
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5908
|
+
metadata: {
|
|
5909
|
+
tool: toolMetadata
|
|
5910
|
+
}
|
|
5911
|
+
}, null, 2)
|
|
5912
|
+
});
|
|
5913
|
+
return _context4.abrupt("return");
|
|
5914
|
+
case 8:
|
|
5915
|
+
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5916
|
+
args = {};
|
|
5917
|
+
try {
|
|
5918
|
+
if (tool["function"].arguments) {
|
|
5919
|
+
args = JSON.parse(tool["function"].arguments);
|
|
5920
|
+
logger({
|
|
5921
|
+
destinationPath: id + ".json",
|
|
5922
|
+
statusCode: 200,
|
|
5923
|
+
message: JSON.stringify({
|
|
5924
|
+
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5925
|
+
metadata: {
|
|
5926
|
+
args: args,
|
|
5927
|
+
tool: toolMetadata
|
|
5928
|
+
}
|
|
5929
|
+
}, null, 2)
|
|
5930
|
+
});
|
|
5931
|
+
}
|
|
5932
|
+
} catch (e) {
|
|
5933
|
+
console.error(e);
|
|
5934
|
+
}
|
|
5935
|
+
_context4.next = 13;
|
|
5936
|
+
return toolFn(args);
|
|
5937
|
+
case 13:
|
|
5938
|
+
output = _context4.sent;
|
|
5939
|
+
logger({
|
|
5940
|
+
destinationPath: id + ".json",
|
|
5941
|
+
statusCode: 200,
|
|
5942
|
+
message: JSON.stringify({
|
|
5943
|
+
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5944
|
+
metadata: {
|
|
5945
|
+
output: output,
|
|
5946
|
+
tool: toolMetadata
|
|
5947
|
+
}
|
|
5948
|
+
}, null, 2)
|
|
5949
|
+
});
|
|
5950
|
+
return _context4.abrupt("return", {
|
|
5951
|
+
tool_call_id: tool.id,
|
|
5952
|
+
output: JSON.stringify(output)
|
|
5953
|
+
});
|
|
5954
|
+
case 16:
|
|
5955
|
+
case "end":
|
|
5956
|
+
return _context4.stop();
|
|
5957
|
+
}
|
|
5958
|
+
}, _callee4);
|
|
5959
|
+
}));
|
|
5960
|
+
return function (_x6, _x7, _x8) {
|
|
5961
|
+
return _ref8.apply(this, arguments);
|
|
5962
|
+
};
|
|
5963
|
+
}()));
|
|
5964
|
+
case 5:
|
|
5965
|
+
_context5.t1 = _context5.sent;
|
|
5966
|
+
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5967
|
+
if (toolOutputs) {
|
|
5968
|
+
_context5.next = 11;
|
|
5969
|
+
break;
|
|
5970
|
+
}
|
|
5971
|
+
console.error('No tool outputs to submit.');
|
|
5972
|
+
logger({
|
|
5973
|
+
destinationPath: id + ".json",
|
|
5974
|
+
statusCode: 404,
|
|
5975
|
+
message: JSON.stringify({
|
|
5976
|
+
message: "No tool outputs submitted",
|
|
5977
|
+
metadata: {}
|
|
5978
|
+
}, null, 2)
|
|
5458
5979
|
});
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
case
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5980
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5981
|
+
threadId: threadId,
|
|
5982
|
+
run: run
|
|
5983
|
+
}));
|
|
5984
|
+
case 11:
|
|
5985
|
+
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5986
|
+
_context5.next = 20;
|
|
5987
|
+
break;
|
|
5988
|
+
}
|
|
5989
|
+
console.log(toolOutputs, '###### YOOOOOO');
|
|
5990
|
+
_context5.next = 15;
|
|
5991
|
+
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5992
|
+
tool_outputs: toolOutputs
|
|
5468
5993
|
});
|
|
5469
|
-
case
|
|
5470
|
-
run =
|
|
5994
|
+
case 15:
|
|
5995
|
+
run = _context5.sent;
|
|
5471
5996
|
logger({
|
|
5472
|
-
|
|
5997
|
+
destinationPath: id + ".json",
|
|
5998
|
+
statusCode: 200,
|
|
5473
5999
|
message: JSON.stringify({
|
|
5474
|
-
message: "
|
|
6000
|
+
message: "Tool outputs submitted",
|
|
5475
6001
|
metadata: {
|
|
5476
|
-
run: run
|
|
5477
|
-
tool_choice: 'required',
|
|
5478
|
-
threadId: threadId,
|
|
5479
|
-
assistant_id: id
|
|
6002
|
+
run: run
|
|
5480
6003
|
}
|
|
5481
6004
|
}, null, 2)
|
|
5482
6005
|
});
|
|
5483
|
-
|
|
5484
|
-
|
|
6006
|
+
console.log('Tool outputs submitted successfully.');
|
|
6007
|
+
_context5.next = 22;
|
|
6008
|
+
break;
|
|
6009
|
+
case 20:
|
|
6010
|
+
logger({
|
|
6011
|
+
destinationPath: id + ".json",
|
|
6012
|
+
statusCode: 404,
|
|
6013
|
+
message: JSON.stringify({
|
|
6014
|
+
message: "No tool outputs to submit",
|
|
6015
|
+
metadata: {}
|
|
6016
|
+
}, null, 2)
|
|
6017
|
+
});
|
|
6018
|
+
console.log('No tool outputs to submit.');
|
|
6019
|
+
case 22:
|
|
6020
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5485
6021
|
threadId: threadId,
|
|
5486
6022
|
run: run
|
|
5487
6023
|
}));
|
|
5488
|
-
case
|
|
6024
|
+
case 23:
|
|
6025
|
+
case "end":
|
|
6026
|
+
return _context5.stop();
|
|
6027
|
+
}
|
|
6028
|
+
}, _callee5);
|
|
6029
|
+
}));
|
|
6030
|
+
return function handleRequiresAction(_x5) {
|
|
6031
|
+
return _ref7.apply(this, arguments);
|
|
6032
|
+
};
|
|
6033
|
+
}();
|
|
6034
|
+
getRun = /*#__PURE__*/function () {
|
|
6035
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref9) {
|
|
6036
|
+
var threadId, runId;
|
|
6037
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
6038
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
6039
|
+
case 0:
|
|
6040
|
+
threadId = _ref9.threadId, runId = _ref9.runId;
|
|
6041
|
+
_context6.next = 3;
|
|
6042
|
+
return client.beta.threads.runs.retrieve(threadId, runId);
|
|
6043
|
+
case 3:
|
|
6044
|
+
return _context6.abrupt("return", _context6.sent);
|
|
6045
|
+
case 4:
|
|
5489
6046
|
case "end":
|
|
5490
|
-
return
|
|
6047
|
+
return _context6.stop();
|
|
5491
6048
|
}
|
|
5492
|
-
},
|
|
6049
|
+
}, _callee6);
|
|
5493
6050
|
}));
|
|
5494
|
-
function
|
|
5495
|
-
return
|
|
5496
|
-
}
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
6051
|
+
return function getRun(_x9) {
|
|
6052
|
+
return _ref10.apply(this, arguments);
|
|
6053
|
+
};
|
|
6054
|
+
}();
|
|
6055
|
+
return _context11.abrupt("return", {
|
|
6056
|
+
agent: agent,
|
|
6057
|
+
initializeThread: function () {
|
|
6058
|
+
var _initializeThread = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(messages) {
|
|
6059
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
6060
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
6061
|
+
case 0:
|
|
6062
|
+
if (messages === void 0) {
|
|
6063
|
+
messages = [];
|
|
6064
|
+
}
|
|
6065
|
+
_context7.next = 3;
|
|
6066
|
+
return client.beta.threads.create({
|
|
6067
|
+
messages: messages
|
|
6068
|
+
});
|
|
6069
|
+
case 3:
|
|
6070
|
+
return _context7.abrupt("return", _context7.sent);
|
|
6071
|
+
case 4:
|
|
6072
|
+
case "end":
|
|
6073
|
+
return _context7.stop();
|
|
6074
|
+
}
|
|
6075
|
+
}, _callee7);
|
|
6076
|
+
}));
|
|
6077
|
+
function initializeThread(_x10) {
|
|
6078
|
+
return _initializeThread.apply(this, arguments);
|
|
6079
|
+
}
|
|
6080
|
+
return initializeThread;
|
|
6081
|
+
}(),
|
|
6082
|
+
listMessages: function () {
|
|
6083
|
+
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
6084
|
+
var threadId;
|
|
6085
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
6086
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
6087
|
+
case 0:
|
|
6088
|
+
threadId = _ref11.threadId;
|
|
6089
|
+
_context8.next = 3;
|
|
6090
|
+
return client.beta.threads.messages.list(threadId);
|
|
6091
|
+
case 3:
|
|
6092
|
+
return _context8.abrupt("return", _context8.sent);
|
|
6093
|
+
case 4:
|
|
6094
|
+
case "end":
|
|
6095
|
+
return _context8.stop();
|
|
6096
|
+
}
|
|
6097
|
+
}, _callee8);
|
|
6098
|
+
}));
|
|
6099
|
+
function listMessages(_x11) {
|
|
6100
|
+
return _listMessages.apply(this, arguments);
|
|
6101
|
+
}
|
|
6102
|
+
return listMessages;
|
|
6103
|
+
}(),
|
|
6104
|
+
getRun: getRun,
|
|
6105
|
+
handleRunStatus: handleRunStatus,
|
|
6106
|
+
handleRequiresAction: handleRequiresAction,
|
|
6107
|
+
createUserMessage: function () {
|
|
6108
|
+
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
6109
|
+
var threadId, content;
|
|
6110
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
6111
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
6112
|
+
case 0:
|
|
6113
|
+
threadId = _ref12.threadId, content = _ref12.content;
|
|
6114
|
+
_context9.next = 3;
|
|
6115
|
+
return client.beta.threads.messages.create(threadId, {
|
|
6116
|
+
role: 'user',
|
|
6117
|
+
content: content
|
|
6118
|
+
});
|
|
6119
|
+
case 3:
|
|
6120
|
+
return _context9.abrupt("return", _context9.sent);
|
|
6121
|
+
case 4:
|
|
6122
|
+
case "end":
|
|
6123
|
+
return _context9.stop();
|
|
6124
|
+
}
|
|
6125
|
+
}, _callee9);
|
|
6126
|
+
}));
|
|
6127
|
+
function createUserMessage(_x12) {
|
|
6128
|
+
return _createUserMessage.apply(this, arguments);
|
|
6129
|
+
}
|
|
6130
|
+
return createUserMessage;
|
|
6131
|
+
}(),
|
|
6132
|
+
watchRun: function () {
|
|
6133
|
+
var _watchRun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref13) {
|
|
6134
|
+
var runId, threadId, run;
|
|
6135
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
6136
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
6137
|
+
case 0:
|
|
6138
|
+
runId = _ref13.runId, threadId = _ref13.threadId;
|
|
6139
|
+
if (!runId) {
|
|
6140
|
+
_context10.next = 7;
|
|
6141
|
+
break;
|
|
6142
|
+
}
|
|
6143
|
+
_context10.next = 4;
|
|
6144
|
+
return getRun({
|
|
6145
|
+
threadId: threadId,
|
|
6146
|
+
runId: runId
|
|
6147
|
+
});
|
|
6148
|
+
case 4:
|
|
6149
|
+
run = _context10.sent;
|
|
6150
|
+
_context10.next = 11;
|
|
6151
|
+
break;
|
|
6152
|
+
case 7:
|
|
6153
|
+
_context10.next = 9;
|
|
6154
|
+
return client.beta.threads.runs.createAndPoll(threadId, {
|
|
6155
|
+
assistant_id: id,
|
|
6156
|
+
tool_choice: tool_choice
|
|
6157
|
+
});
|
|
6158
|
+
case 9:
|
|
6159
|
+
run = _context10.sent;
|
|
6160
|
+
logger({
|
|
6161
|
+
destinationPath: id + ".json",
|
|
6162
|
+
statusCode: 202,
|
|
6163
|
+
message: JSON.stringify({
|
|
6164
|
+
message: "Creating and polling run, tool choice required",
|
|
6165
|
+
metadata: {
|
|
6166
|
+
run: run,
|
|
6167
|
+
tool_choice: tool_choice,
|
|
6168
|
+
threadId: threadId,
|
|
6169
|
+
assistant_id: id
|
|
6170
|
+
}
|
|
6171
|
+
}, null, 2)
|
|
6172
|
+
});
|
|
6173
|
+
case 11:
|
|
6174
|
+
return _context10.abrupt("return", handleRunStatus({
|
|
6175
|
+
threadId: threadId,
|
|
6176
|
+
run: run
|
|
6177
|
+
}));
|
|
6178
|
+
case 12:
|
|
6179
|
+
case "end":
|
|
6180
|
+
return _context10.stop();
|
|
6181
|
+
}
|
|
6182
|
+
}, _callee10);
|
|
6183
|
+
}));
|
|
6184
|
+
function watchRun(_x13) {
|
|
6185
|
+
return _watchRun.apply(this, arguments);
|
|
6186
|
+
}
|
|
6187
|
+
return watchRun;
|
|
6188
|
+
}()
|
|
6189
|
+
});
|
|
6190
|
+
case 8:
|
|
6191
|
+
case "end":
|
|
6192
|
+
return _context11.stop();
|
|
6193
|
+
}
|
|
6194
|
+
}, _callee11);
|
|
6195
|
+
}));
|
|
6196
|
+
function getAssistantAgent(_x3) {
|
|
6197
|
+
return _getAssistantAgent.apply(this, arguments);
|
|
6198
|
+
}
|
|
6199
|
+
return getAssistantAgent;
|
|
6200
|
+
}();
|
|
5507
6201
|
}
|
|
5508
6202
|
|
|
5509
6203
|
var delay = function delay(ms) {
|
|
@@ -5730,20 +6424,24 @@ function getAgent(_x) {
|
|
|
5730
6424
|
}
|
|
5731
6425
|
function _getAgent() {
|
|
5732
6426
|
_getAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
5733
|
-
var
|
|
6427
|
+
var _agent$model$provider, _agent$model$provider2;
|
|
6428
|
+
var connectionId, agent, apis, logger, tools, toolMap, getAssistantAgent, assistant, _agent$model2, keyToModel, _tools, _toolMap, resultTool, schema, _agent$model;
|
|
5734
6429
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5735
6430
|
while (1) switch (_context3.prev = _context3.next) {
|
|
5736
6431
|
case 0:
|
|
5737
|
-
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis;
|
|
5738
|
-
|
|
5739
|
-
|
|
6432
|
+
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis, logger = _ref.logger;
|
|
6433
|
+
console.log('get agent start, model provider====', agent.model.provider);
|
|
6434
|
+
if (!(((_agent$model$provider = agent.model.provider) == null ? void 0 : _agent$model$provider.toUpperCase()) === 'OPEN_AI_ASSISTANT')) {
|
|
6435
|
+
_context3.next = 15;
|
|
5740
6436
|
break;
|
|
5741
6437
|
}
|
|
6438
|
+
console.log('===in the model if block===');
|
|
5742
6439
|
tools = Object.keys(agent.tools);
|
|
5743
6440
|
toolMap = Object.entries(apis).reduce(function (memo, _ref2) {
|
|
5744
6441
|
var k = _ref2[0],
|
|
5745
6442
|
def = _ref2[1];
|
|
5746
6443
|
if (tools.includes(k)) {
|
|
6444
|
+
console.log(k + " tool included, run executorx====");
|
|
5747
6445
|
memo[k] = /*#__PURE__*/function () {
|
|
5748
6446
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
5749
6447
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -5768,17 +6466,21 @@ function _getAgent() {
|
|
|
5768
6466
|
}
|
|
5769
6467
|
return memo;
|
|
5770
6468
|
}, {});
|
|
5771
|
-
|
|
6469
|
+
console.log('toolmap====', JSON.stringify(toolMap, null, 2));
|
|
6470
|
+
getAssistantAgent = getAssistantAgentHandler(logger);
|
|
6471
|
+
_context3.next = 10;
|
|
5772
6472
|
return getAssistantAgent({
|
|
5773
6473
|
id: agent.id,
|
|
5774
|
-
toolMap: toolMap
|
|
6474
|
+
toolMap: toolMap,
|
|
6475
|
+
tool_choice: agent.model.toolChoice
|
|
5775
6476
|
});
|
|
5776
|
-
case
|
|
6477
|
+
case 10:
|
|
5777
6478
|
assistant = _context3.sent;
|
|
6479
|
+
console.log('got assistant===', assistant);
|
|
5778
6480
|
return _context3.abrupt("return", assistant);
|
|
5779
|
-
case
|
|
5780
|
-
if (!['OPEN_AI_VERCEL', 'ANTHROPIC_VERCEL', 'GROQ_VERCEL', 'PERPLEXITY_VERCEL', 'FIREWORKS_VERCEL'].includes(agent.model.provider)) {
|
|
5781
|
-
_context3.next =
|
|
6481
|
+
case 15:
|
|
6482
|
+
if (!['OPEN_AI_VERCEL', 'ANTHROPIC_VERCEL', 'GROQ_VERCEL', 'PERPLEXITY_VERCEL', 'FIREWORKS_VERCEL'].includes((_agent$model$provider2 = agent.model.provider) == null ? void 0 : _agent$model$provider2.toUpperCase())) {
|
|
6483
|
+
_context3.next = 24;
|
|
5782
6484
|
break;
|
|
5783
6485
|
}
|
|
5784
6486
|
keyToModel = {
|
|
@@ -5845,7 +6547,7 @@ function _getAgent() {
|
|
|
5845
6547
|
};
|
|
5846
6548
|
}
|
|
5847
6549
|
if (!(agent.model.generation_type === 'stream')) {
|
|
5848
|
-
_context3.next =
|
|
6550
|
+
_context3.next = 23;
|
|
5849
6551
|
break;
|
|
5850
6552
|
}
|
|
5851
6553
|
return _context3.abrupt("return", createStreamAgent({
|
|
@@ -5858,7 +6560,7 @@ function _getAgent() {
|
|
|
5858
6560
|
tools: _toolMap,
|
|
5859
6561
|
resultTool: resultTool
|
|
5860
6562
|
}));
|
|
5861
|
-
case
|
|
6563
|
+
case 23:
|
|
5862
6564
|
return _context3.abrupt("return", createAgent({
|
|
5863
6565
|
agent_instructions: agent.agent_instructions,
|
|
5864
6566
|
model: {
|
|
@@ -5869,7 +6571,7 @@ function _getAgent() {
|
|
|
5869
6571
|
tools: _toolMap,
|
|
5870
6572
|
resultTool: resultTool
|
|
5871
6573
|
}));
|
|
5872
|
-
case
|
|
6574
|
+
case 24:
|
|
5873
6575
|
case "end":
|
|
5874
6576
|
return _context3.stop();
|
|
5875
6577
|
}
|
|
@@ -5878,6 +6580,67 @@ function _getAgent() {
|
|
|
5878
6580
|
return _getAgent.apply(this, arguments);
|
|
5879
6581
|
}
|
|
5880
6582
|
|
|
6583
|
+
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
6584
|
+
function createFileLogger() {
|
|
6585
|
+
return function (log) {
|
|
6586
|
+
var fullPath = path.join(loggerPath, log.destinationPath);
|
|
6587
|
+
if (!fs.existsSync(loggerPath)) {
|
|
6588
|
+
fs.mkdirSync(loggerPath, {
|
|
6589
|
+
recursive: true
|
|
6590
|
+
});
|
|
6591
|
+
return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
6592
|
+
createdAt: new Date()
|
|
6593
|
+
})], null, 2));
|
|
6594
|
+
}
|
|
6595
|
+
if (!fs.existsSync(fullPath)) {
|
|
6596
|
+
return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
6597
|
+
createdAt: new Date()
|
|
6598
|
+
})], null, 2));
|
|
6599
|
+
}
|
|
6600
|
+
var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
6601
|
+
logs.push(_extends({}, log, {
|
|
6602
|
+
createdAt: new Date()
|
|
6603
|
+
}));
|
|
6604
|
+
return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
6605
|
+
};
|
|
6606
|
+
}
|
|
6607
|
+
function getUpstashLogs(_x) {
|
|
6608
|
+
return _getUpstashLogs.apply(this, arguments);
|
|
6609
|
+
}
|
|
6610
|
+
function _getUpstashLogs() {
|
|
6611
|
+
_getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
6612
|
+
var id, url, token, redis$1;
|
|
6613
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
6614
|
+
while (1) switch (_context.prev = _context.next) {
|
|
6615
|
+
case 0:
|
|
6616
|
+
id = _ref.id, url = _ref.url, token = _ref.token;
|
|
6617
|
+
redis$1 = new redis.Redis({
|
|
6618
|
+
url: url,
|
|
6619
|
+
token: token
|
|
6620
|
+
});
|
|
6621
|
+
return _context.abrupt("return", redis$1.lrange(id, 0, -1));
|
|
6622
|
+
case 3:
|
|
6623
|
+
case "end":
|
|
6624
|
+
return _context.stop();
|
|
6625
|
+
}
|
|
6626
|
+
}, _callee);
|
|
6627
|
+
}));
|
|
6628
|
+
return _getUpstashLogs.apply(this, arguments);
|
|
6629
|
+
}
|
|
6630
|
+
function createUpstashLogger(_ref2) {
|
|
6631
|
+
var url = _ref2.url,
|
|
6632
|
+
token = _ref2.token;
|
|
6633
|
+
var redis$1 = new redis.Redis({
|
|
6634
|
+
url: url,
|
|
6635
|
+
token: token
|
|
6636
|
+
});
|
|
6637
|
+
return function (log) {
|
|
6638
|
+
redis$1.lpush(log.destinationPath, JSON.stringify(_extends({}, log, {
|
|
6639
|
+
createdAt: new Date()
|
|
6640
|
+
})));
|
|
6641
|
+
};
|
|
6642
|
+
}
|
|
6643
|
+
|
|
5881
6644
|
var Mastra = /*#__PURE__*/function () {
|
|
5882
6645
|
function Mastra(_ref) {
|
|
5883
6646
|
var _this = this;
|
|
@@ -5895,6 +6658,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
5895
6658
|
agentDirPath: '',
|
|
5896
6659
|
vectorProvider: []
|
|
5897
6660
|
};
|
|
6661
|
+
this.logger = void 0;
|
|
5898
6662
|
this.config = void 0;
|
|
5899
6663
|
this.runBlueprint = /*#__PURE__*/function () {
|
|
5900
6664
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
@@ -5945,7 +6709,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
5945
6709
|
this.config = config;
|
|
5946
6710
|
}
|
|
5947
6711
|
Mastra.init = function init(config) {
|
|
5948
|
-
var _config$workflows$sys;
|
|
6712
|
+
var _config$logs, _config$logs2, _config$workflows$sys;
|
|
5949
6713
|
if (!config.db.uri) {
|
|
5950
6714
|
throw new Error('No database config/provider found');
|
|
5951
6715
|
}
|
|
@@ -5959,6 +6723,19 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
5959
6723
|
dataLayer: dataLayer,
|
|
5960
6724
|
vectorLayer: vectorLayer
|
|
5961
6725
|
});
|
|
6726
|
+
var logger;
|
|
6727
|
+
if (!(config != null && config.logs)) {
|
|
6728
|
+
logger = console.log;
|
|
6729
|
+
} else if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
|
|
6730
|
+
logger = createFileLogger();
|
|
6731
|
+
} else if (((_config$logs2 = config.logs) == null ? void 0 : _config$logs2.provider) === 'UPSTASH') {
|
|
6732
|
+
var _config$logs$config, _config$logs$config2;
|
|
6733
|
+
logger = createUpstashLogger({
|
|
6734
|
+
url: (_config$logs$config = config.logs.config) == null ? void 0 : _config$logs$config.url,
|
|
6735
|
+
token: (_config$logs$config2 = config.logs.config) == null ? void 0 : _config$logs$config2.token
|
|
6736
|
+
});
|
|
6737
|
+
}
|
|
6738
|
+
framework.attachLogger(logger);
|
|
5962
6739
|
// Register integrations
|
|
5963
6740
|
config.integrations.forEach(function (integration) {
|
|
5964
6741
|
framework.__registerIntgeration(integration);
|
|
@@ -5971,9 +6748,68 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
5971
6748
|
return _extends({}, api, {
|
|
5972
6749
|
integrationName: config.name
|
|
5973
6750
|
});
|
|
5974
|
-
}),
|
|
5975
|
-
|
|
5976
|
-
|
|
6751
|
+
}), [{
|
|
6752
|
+
integrationName: config.name,
|
|
6753
|
+
type: 'trigger_event',
|
|
6754
|
+
label: 'Trigger event',
|
|
6755
|
+
// getSchemaOptions({ ctx }) {
|
|
6756
|
+
// const options = Promise.resolve({
|
|
6757
|
+
// event: {
|
|
6758
|
+
// options: Array.from(framework.globalEvents.values()).flatMap(
|
|
6759
|
+
// (eventRecord) =>
|
|
6760
|
+
// Object.values(eventRecord).map((event) => ({
|
|
6761
|
+
// value: event.key || event.label || '',
|
|
6762
|
+
// label: event.key || event.label || '',
|
|
6763
|
+
// })).filter((event) => event.value !== '')
|
|
6764
|
+
// ),
|
|
6765
|
+
// },
|
|
6766
|
+
// });
|
|
6767
|
+
// return options;
|
|
6768
|
+
// },
|
|
6769
|
+
description: 'Trigger event',
|
|
6770
|
+
schema: zod.z.object({
|
|
6771
|
+
event: zod.z.string(),
|
|
6772
|
+
data: zod.z.record(zod.z.any())
|
|
6773
|
+
}),
|
|
6774
|
+
executor: function () {
|
|
6775
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
|
|
6776
|
+
var data, ctx, event;
|
|
6777
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
6778
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
6779
|
+
case 0:
|
|
6780
|
+
data = _ref7.data, ctx = _ref7.ctx;
|
|
6781
|
+
event = data.event;
|
|
6782
|
+
_context2.next = 4;
|
|
6783
|
+
return framework.triggerEvent({
|
|
6784
|
+
key: event,
|
|
6785
|
+
data: data.data,
|
|
6786
|
+
user: {
|
|
6787
|
+
connectionId: ctx.connectionId
|
|
6788
|
+
}
|
|
6789
|
+
});
|
|
6790
|
+
case 4:
|
|
6791
|
+
return _context2.abrupt("return", _context2.sent);
|
|
6792
|
+
case 5:
|
|
6793
|
+
case "end":
|
|
6794
|
+
return _context2.stop();
|
|
6795
|
+
}
|
|
6796
|
+
}, _callee2);
|
|
6797
|
+
}));
|
|
6798
|
+
function executor(_x2) {
|
|
6799
|
+
return _executor.apply(this, arguments);
|
|
6800
|
+
}
|
|
6801
|
+
return executor;
|
|
6802
|
+
}()
|
|
6803
|
+
}])
|
|
6804
|
+
});
|
|
6805
|
+
getVectorQueryApis({
|
|
6806
|
+
mastra: framework
|
|
6807
|
+
}).then(function (d) {
|
|
6808
|
+
framework.__registerApis({
|
|
6809
|
+
apis: d
|
|
6810
|
+
});
|
|
6811
|
+
})["catch"](function (e) {
|
|
6812
|
+
console.error(e);
|
|
5977
6813
|
});
|
|
5978
6814
|
// Register System events
|
|
5979
6815
|
framework.__registerEvents({
|
|
@@ -6006,6 +6842,17 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6006
6842
|
}))
|
|
6007
6843
|
}),
|
|
6008
6844
|
handler: genericVectorySyncEvent
|
|
6845
|
+
},
|
|
6846
|
+
VECTOR_INDEX_SYNC: {
|
|
6847
|
+
label: 'Sync vector index',
|
|
6848
|
+
description: 'Sync vector index',
|
|
6849
|
+
schema: zod.z.object({
|
|
6850
|
+
data: zod.z.array(zod.z.object({
|
|
6851
|
+
provider: zod.z.string(),
|
|
6852
|
+
indexes: zod.z.array(zod.z.string())
|
|
6853
|
+
}))
|
|
6854
|
+
}),
|
|
6855
|
+
handler: vectorIndexSync
|
|
6009
6856
|
}
|
|
6010
6857
|
},
|
|
6011
6858
|
integrationName: config.name
|
|
@@ -6015,60 +6862,63 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6015
6862
|
return framework;
|
|
6016
6863
|
};
|
|
6017
6864
|
var _proto = Mastra.prototype;
|
|
6865
|
+
_proto.attachLogger = function attachLogger(logger) {
|
|
6866
|
+
this.logger = logger;
|
|
6867
|
+
};
|
|
6018
6868
|
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
6019
|
-
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
6869
|
+
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref8) {
|
|
6020
6870
|
var _this2 = this;
|
|
6021
6871
|
var context, ints, connectionChecks;
|
|
6022
|
-
return _regeneratorRuntime().wrap(function
|
|
6023
|
-
while (1) switch (
|
|
6872
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
6873
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
6024
6874
|
case 0:
|
|
6025
|
-
context =
|
|
6875
|
+
context = _ref8.context;
|
|
6026
6876
|
ints = this.availableIntegrations();
|
|
6027
|
-
|
|
6877
|
+
_context4.next = 4;
|
|
6028
6878
|
return Promise.all(ints.map(/*#__PURE__*/function () {
|
|
6029
|
-
var
|
|
6879
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref9) {
|
|
6030
6880
|
var integration, connection;
|
|
6031
|
-
return _regeneratorRuntime().wrap(function
|
|
6032
|
-
while (1) switch (
|
|
6881
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
6882
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
6033
6883
|
case 0:
|
|
6034
|
-
integration =
|
|
6035
|
-
|
|
6884
|
+
integration = _ref9.integration;
|
|
6885
|
+
_context3.next = 3;
|
|
6036
6886
|
return _this2.dataLayer.getConnection({
|
|
6037
6887
|
connectionId: context.connectionId,
|
|
6038
6888
|
name: integration.name
|
|
6039
6889
|
});
|
|
6040
6890
|
case 3:
|
|
6041
|
-
connection =
|
|
6042
|
-
return
|
|
6891
|
+
connection = _context3.sent;
|
|
6892
|
+
return _context3.abrupt("return", {
|
|
6043
6893
|
integration: integration,
|
|
6044
6894
|
connected: !!connection
|
|
6045
6895
|
});
|
|
6046
6896
|
case 5:
|
|
6047
6897
|
case "end":
|
|
6048
|
-
return
|
|
6898
|
+
return _context3.stop();
|
|
6049
6899
|
}
|
|
6050
|
-
},
|
|
6900
|
+
}, _callee3);
|
|
6051
6901
|
}));
|
|
6052
|
-
return function (
|
|
6053
|
-
return
|
|
6902
|
+
return function (_x4) {
|
|
6903
|
+
return _ref10.apply(this, arguments);
|
|
6054
6904
|
};
|
|
6055
6905
|
}()));
|
|
6056
6906
|
case 4:
|
|
6057
|
-
connectionChecks =
|
|
6058
|
-
return
|
|
6059
|
-
var connected =
|
|
6907
|
+
connectionChecks = _context4.sent;
|
|
6908
|
+
return _context4.abrupt("return", connectionChecks.filter(function (_ref11) {
|
|
6909
|
+
var connected = _ref11.connected;
|
|
6060
6910
|
return connected;
|
|
6061
|
-
}).map(function (
|
|
6062
|
-
var integration =
|
|
6911
|
+
}).map(function (_ref12) {
|
|
6912
|
+
var integration = _ref12.integration;
|
|
6063
6913
|
return integration;
|
|
6064
6914
|
}));
|
|
6065
6915
|
case 6:
|
|
6066
6916
|
case "end":
|
|
6067
|
-
return
|
|
6917
|
+
return _context4.stop();
|
|
6068
6918
|
}
|
|
6069
|
-
},
|
|
6919
|
+
}, _callee4, this);
|
|
6070
6920
|
}));
|
|
6071
|
-
function connectedIntegrations(
|
|
6921
|
+
function connectedIntegrations(_x3) {
|
|
6072
6922
|
return _connectedIntegrations.apply(this, arguments);
|
|
6073
6923
|
}
|
|
6074
6924
|
return connectedIntegrations;
|
|
@@ -6107,17 +6957,17 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6107
6957
|
var integrationEvents = this.globalEvents.get('SYSTEM') || {};
|
|
6108
6958
|
this.globalEvents.set('SYSTEM', _extends({}, integrationEvents, (_extends3 = {}, _extends3[name] = event, _extends3)));
|
|
6109
6959
|
};
|
|
6110
|
-
_proto.__registerEvents = function __registerEvents(
|
|
6111
|
-
var events =
|
|
6112
|
-
|
|
6113
|
-
integrationName =
|
|
6960
|
+
_proto.__registerEvents = function __registerEvents(_ref13) {
|
|
6961
|
+
var events = _ref13.events,
|
|
6962
|
+
_ref13$integrationNam = _ref13.integrationName,
|
|
6963
|
+
integrationName = _ref13$integrationNam === void 0 ? this.config.name : _ref13$integrationNam;
|
|
6114
6964
|
var integrationEvents = this.globalEvents.get(integrationName) || {};
|
|
6115
6965
|
this.globalEvents.set(integrationName, _extends({}, integrationEvents, events));
|
|
6116
6966
|
};
|
|
6117
|
-
_proto.__registerApis = function __registerApis(
|
|
6118
|
-
var apis =
|
|
6119
|
-
|
|
6120
|
-
integrationName =
|
|
6967
|
+
_proto.__registerApis = function __registerApis(_ref14) {
|
|
6968
|
+
var apis = _ref14.apis,
|
|
6969
|
+
_ref14$integrationNam = _ref14.integrationName,
|
|
6970
|
+
integrationName = _ref14$integrationNam === void 0 ? this.config.name : _ref14$integrationNam;
|
|
6121
6971
|
var integrationApis = this.globalApis.get(integrationName) || {};
|
|
6122
6972
|
this.globalApis.set(integrationName, _extends({}, integrationApis, apis.reduce(function (acc, api) {
|
|
6123
6973
|
var _extends4;
|
|
@@ -6125,9 +6975,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6125
6975
|
}, {})));
|
|
6126
6976
|
};
|
|
6127
6977
|
_proto.availableIntegrations = function availableIntegrations() {
|
|
6128
|
-
return Array.from(this.integrations.entries()).map(function (
|
|
6129
|
-
var name =
|
|
6130
|
-
integration =
|
|
6978
|
+
return Array.from(this.integrations.entries()).map(function (_ref15) {
|
|
6979
|
+
var name = _ref15[0],
|
|
6980
|
+
integration = _ref15[1];
|
|
6131
6981
|
return {
|
|
6132
6982
|
name: name,
|
|
6133
6983
|
integration: integration
|
|
@@ -6149,9 +6999,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6149
6999
|
};
|
|
6150
7000
|
_proto.getGlobalEventHandlers = function getGlobalEventHandlers() {
|
|
6151
7001
|
var _this3 = this;
|
|
6152
|
-
return Array.from(this.globalEvents.entries()).flatMap(function (
|
|
6153
|
-
var integrationName =
|
|
6154
|
-
events =
|
|
7002
|
+
return Array.from(this.globalEvents.entries()).flatMap(function (_ref16) {
|
|
7003
|
+
var integrationName = _ref16[0],
|
|
7004
|
+
events = _ref16[1];
|
|
6155
7005
|
var groupedHandlers = Object.keys(events).map(function (eventKey) {
|
|
6156
7006
|
var _events$eventKey;
|
|
6157
7007
|
var eventHandler = (_events$eventKey = events[eventKey]) == null ? void 0 : _events$eventKey.handler;
|
|
@@ -6200,8 +7050,8 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6200
7050
|
});
|
|
6201
7051
|
};
|
|
6202
7052
|
_proto.authenticatableIntegrations = function authenticatableIntegrations() {
|
|
6203
|
-
return this.availableIntegrations().filter(function (
|
|
6204
|
-
var integration =
|
|
7053
|
+
return this.availableIntegrations().filter(function (_ref17) {
|
|
7054
|
+
var integration = _ref17.integration;
|
|
6205
7055
|
try {
|
|
6206
7056
|
integration.getAuthenticator();
|
|
6207
7057
|
return true;
|
|
@@ -6218,20 +7068,20 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6218
7068
|
return _int.getAuthenticator();
|
|
6219
7069
|
};
|
|
6220
7070
|
_proto.connectIntegrationByCredential = /*#__PURE__*/function () {
|
|
6221
|
-
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7071
|
+
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref18) {
|
|
6222
7072
|
var name, connectionId, credential, authenticator, integration;
|
|
6223
|
-
return _regeneratorRuntime().wrap(function
|
|
6224
|
-
while (1) switch (
|
|
7073
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
7074
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
6225
7075
|
case 0:
|
|
6226
|
-
name =
|
|
7076
|
+
name = _ref18.name, connectionId = _ref18.connectionId, credential = _ref18.credential;
|
|
6227
7077
|
authenticator = this.authenticator(name);
|
|
6228
7078
|
if (authenticator) {
|
|
6229
|
-
|
|
7079
|
+
_context5.next = 4;
|
|
6230
7080
|
break;
|
|
6231
7081
|
}
|
|
6232
7082
|
throw new Error("Authenticator for " + name + " not found");
|
|
6233
7083
|
case 4:
|
|
6234
|
-
|
|
7084
|
+
_context5.next = 6;
|
|
6235
7085
|
return authenticator.dataAccess.createConnection({
|
|
6236
7086
|
connection: {
|
|
6237
7087
|
name: name,
|
|
@@ -6240,157 +7090,198 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6240
7090
|
credential: credential
|
|
6241
7091
|
});
|
|
6242
7092
|
case 6:
|
|
6243
|
-
integration =
|
|
7093
|
+
integration = _context5.sent;
|
|
6244
7094
|
if (!authenticator.onConnectionCreated) {
|
|
6245
|
-
|
|
7095
|
+
_context5.next = 10;
|
|
6246
7096
|
break;
|
|
6247
7097
|
}
|
|
6248
|
-
|
|
7098
|
+
_context5.next = 10;
|
|
6249
7099
|
return authenticator.onConnectionCreated(integration, credential);
|
|
6250
7100
|
case 10:
|
|
6251
7101
|
case "end":
|
|
6252
|
-
return
|
|
7102
|
+
return _context5.stop();
|
|
6253
7103
|
}
|
|
6254
|
-
},
|
|
7104
|
+
}, _callee5, this);
|
|
6255
7105
|
}));
|
|
6256
|
-
function connectIntegrationByCredential(
|
|
7106
|
+
function connectIntegrationByCredential(_x5) {
|
|
6257
7107
|
return _connectIntegrationByCredential.apply(this, arguments);
|
|
6258
7108
|
}
|
|
6259
7109
|
return connectIntegrationByCredential;
|
|
6260
7110
|
}();
|
|
6261
7111
|
_proto.disconnectIntegration = /*#__PURE__*/function () {
|
|
6262
|
-
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7112
|
+
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref19) {
|
|
6263
7113
|
var _yield$this$dataLayer;
|
|
6264
7114
|
var name, connectionId, integration, k_id, authenticator;
|
|
6265
|
-
return _regeneratorRuntime().wrap(function
|
|
6266
|
-
while (1) switch (
|
|
7115
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
7116
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
6267
7117
|
case 0:
|
|
6268
|
-
name =
|
|
7118
|
+
name = _ref19.name, connectionId = _ref19.connectionId;
|
|
6269
7119
|
integration = this.getIntegration(name);
|
|
6270
|
-
|
|
7120
|
+
_context6.next = 4;
|
|
6271
7121
|
return this.dataLayer.getConnection({
|
|
6272
7122
|
name: name,
|
|
6273
7123
|
connectionId: connectionId
|
|
6274
7124
|
});
|
|
6275
7125
|
case 4:
|
|
6276
|
-
|
|
6277
|
-
if (!(
|
|
6278
|
-
|
|
7126
|
+
_context6.t0 = _yield$this$dataLayer = _context6.sent;
|
|
7127
|
+
if (!(_context6.t0 == null)) {
|
|
7128
|
+
_context6.next = 9;
|
|
6279
7129
|
break;
|
|
6280
7130
|
}
|
|
6281
|
-
|
|
6282
|
-
|
|
7131
|
+
_context6.t1 = void 0;
|
|
7132
|
+
_context6.next = 10;
|
|
6283
7133
|
break;
|
|
6284
7134
|
case 9:
|
|
6285
|
-
|
|
7135
|
+
_context6.t1 = _yield$this$dataLayer.id;
|
|
6286
7136
|
case 10:
|
|
6287
|
-
k_id =
|
|
7137
|
+
k_id = _context6.t1;
|
|
6288
7138
|
if (k_id) {
|
|
6289
|
-
|
|
7139
|
+
_context6.next = 13;
|
|
6290
7140
|
break;
|
|
6291
7141
|
}
|
|
6292
7142
|
throw new Error("No connection found for " + name);
|
|
6293
7143
|
case 13:
|
|
6294
7144
|
if (!(integration != null && integration.dataLayer)) {
|
|
6295
|
-
|
|
7145
|
+
_context6.next = 16;
|
|
6296
7146
|
break;
|
|
6297
7147
|
}
|
|
6298
|
-
|
|
7148
|
+
_context6.next = 16;
|
|
6299
7149
|
return integration.onDisconnect({
|
|
6300
7150
|
connectionId: connectionId
|
|
6301
7151
|
});
|
|
6302
7152
|
case 16:
|
|
6303
7153
|
if (!((integration == null ? void 0 : integration.config.authType) === exports.IntegrationCredentialType.OAUTH)) {
|
|
6304
|
-
|
|
7154
|
+
_context6.next = 20;
|
|
6305
7155
|
break;
|
|
6306
7156
|
}
|
|
6307
7157
|
authenticator = this.authenticator(name);
|
|
6308
|
-
|
|
7158
|
+
_context6.next = 20;
|
|
6309
7159
|
return authenticator.revokeAuth({
|
|
6310
7160
|
k_id: k_id
|
|
6311
7161
|
});
|
|
6312
7162
|
case 20:
|
|
6313
|
-
|
|
7163
|
+
_context6.next = 22;
|
|
6314
7164
|
return this.dataLayer.deleteConnection({
|
|
6315
7165
|
connectionId: connectionId
|
|
6316
7166
|
});
|
|
6317
7167
|
case 22:
|
|
6318
7168
|
case "end":
|
|
6319
|
-
return
|
|
7169
|
+
return _context6.stop();
|
|
6320
7170
|
}
|
|
6321
|
-
},
|
|
7171
|
+
}, _callee6, this);
|
|
6322
7172
|
}));
|
|
6323
|
-
function disconnectIntegration(
|
|
7173
|
+
function disconnectIntegration(_x6) {
|
|
6324
7174
|
return _disconnectIntegration.apply(this, arguments);
|
|
6325
7175
|
}
|
|
6326
7176
|
return disconnectIntegration;
|
|
6327
7177
|
}();
|
|
7178
|
+
_proto.createSystemConnection = /*#__PURE__*/function () {
|
|
7179
|
+
var _createSystemConnection = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
7180
|
+
var systemConnectionId, existingSystemConnection;
|
|
7181
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
7182
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
7183
|
+
case 0:
|
|
7184
|
+
systemConnectionId = 'SYSTEM';
|
|
7185
|
+
_context7.next = 3;
|
|
7186
|
+
return this.dataLayer.getConnection({
|
|
7187
|
+
connectionId: systemConnectionId,
|
|
7188
|
+
name: this.config.name
|
|
7189
|
+
});
|
|
7190
|
+
case 3:
|
|
7191
|
+
existingSystemConnection = _context7.sent;
|
|
7192
|
+
if (!existingSystemConnection) {
|
|
7193
|
+
_context7.next = 6;
|
|
7194
|
+
break;
|
|
7195
|
+
}
|
|
7196
|
+
return _context7.abrupt("return", existingSystemConnection);
|
|
7197
|
+
case 6:
|
|
7198
|
+
return _context7.abrupt("return", this.dataLayer.createConnection({
|
|
7199
|
+
connection: {
|
|
7200
|
+
connectionId: systemConnectionId,
|
|
7201
|
+
name: this.config.name
|
|
7202
|
+
},
|
|
7203
|
+
credential: {
|
|
7204
|
+
type: 'SYSTEM',
|
|
7205
|
+
value: systemConnectionId
|
|
7206
|
+
}
|
|
7207
|
+
}));
|
|
7208
|
+
case 7:
|
|
7209
|
+
case "end":
|
|
7210
|
+
return _context7.stop();
|
|
7211
|
+
}
|
|
7212
|
+
}, _callee7, this);
|
|
7213
|
+
}));
|
|
7214
|
+
function createSystemConnection() {
|
|
7215
|
+
return _createSystemConnection.apply(this, arguments);
|
|
7216
|
+
}
|
|
7217
|
+
return createSystemConnection;
|
|
7218
|
+
}();
|
|
6328
7219
|
_proto.callApi = /*#__PURE__*/function () {
|
|
6329
|
-
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7220
|
+
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
|
|
6330
7221
|
var _int2$getApis;
|
|
6331
|
-
var
|
|
6332
|
-
return _regeneratorRuntime().wrap(function
|
|
6333
|
-
while (1) switch (
|
|
7222
|
+
var _ref20$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
|
|
7223
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
7224
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
6334
7225
|
case 0:
|
|
6335
|
-
|
|
7226
|
+
_ref20$integrationNam = _ref20.integrationName, integrationName = _ref20$integrationNam === void 0 ? this.config.name : _ref20$integrationNam, api = _ref20.api, payload = _ref20.payload;
|
|
6336
7227
|
if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
|
|
6337
|
-
|
|
7228
|
+
_context8.next = 6;
|
|
6338
7229
|
break;
|
|
6339
7230
|
}
|
|
6340
7231
|
_apiExecutor = (_this$globalApis$get = this.globalApis.get(this.config.name)) == null ? void 0 : _this$globalApis$get[api];
|
|
6341
7232
|
if (_apiExecutor) {
|
|
6342
|
-
|
|
7233
|
+
_context8.next = 5;
|
|
6343
7234
|
break;
|
|
6344
7235
|
}
|
|
6345
7236
|
throw new Error("No global api exists for " + api);
|
|
6346
7237
|
case 5:
|
|
6347
|
-
return
|
|
7238
|
+
return _context8.abrupt("return", _apiExecutor.executor(payload));
|
|
6348
7239
|
case 6:
|
|
6349
7240
|
_int2 = this.getIntegration(integrationName);
|
|
6350
7241
|
if (_int2) {
|
|
6351
|
-
|
|
7242
|
+
_context8.next = 9;
|
|
6352
7243
|
break;
|
|
6353
7244
|
}
|
|
6354
7245
|
throw new Error("No Integration exists for " + integrationName);
|
|
6355
7246
|
case 9:
|
|
6356
7247
|
apiExecutor = (_int2$getApis = _int2.getApis()) == null ? void 0 : _int2$getApis[api];
|
|
6357
7248
|
if (apiExecutor) {
|
|
6358
|
-
|
|
7249
|
+
_context8.next = 12;
|
|
6359
7250
|
break;
|
|
6360
7251
|
}
|
|
6361
7252
|
throw new Error("No api exists for " + api + " in " + integrationName);
|
|
6362
7253
|
case 12:
|
|
6363
|
-
return
|
|
7254
|
+
return _context8.abrupt("return", apiExecutor.executor(payload));
|
|
6364
7255
|
case 13:
|
|
6365
7256
|
case "end":
|
|
6366
|
-
return
|
|
7257
|
+
return _context8.stop();
|
|
6367
7258
|
}
|
|
6368
|
-
},
|
|
7259
|
+
}, _callee8, this);
|
|
6369
7260
|
}));
|
|
6370
|
-
function callApi(
|
|
7261
|
+
function callApi(_x7) {
|
|
6371
7262
|
return _callApi.apply(this, arguments);
|
|
6372
7263
|
}
|
|
6373
7264
|
return callApi;
|
|
6374
7265
|
}();
|
|
6375
7266
|
_proto.subscribeEvent = /*#__PURE__*/function () {
|
|
6376
|
-
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
6377
|
-
var _this$config$runner$u, _this$config$runner,
|
|
6378
|
-
var id,
|
|
6379
|
-
return _regeneratorRuntime().wrap(function
|
|
6380
|
-
while (1) switch (
|
|
7267
|
+
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref21) {
|
|
7268
|
+
var _this$config$runner$u, _this$config$runner, _ref22, _this$config$runner$s, _this$config$runner2;
|
|
7269
|
+
var id, _ref21$interval, interval, _ref21$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
|
|
7270
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
7271
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
6381
7272
|
case 0:
|
|
6382
|
-
id =
|
|
7273
|
+
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;
|
|
6383
7274
|
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;
|
|
6384
|
-
inngestApiToken = (
|
|
7275
|
+
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';
|
|
6385
7276
|
startTime = Date.now();
|
|
6386
7277
|
_poll = /*#__PURE__*/function () {
|
|
6387
|
-
var
|
|
7278
|
+
var _ref23 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
6388
7279
|
var response, obj, data, error, lastRun, elapsedTime;
|
|
6389
|
-
return _regeneratorRuntime().wrap(function
|
|
6390
|
-
while (1) switch (
|
|
7280
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
7281
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
6391
7282
|
case 0:
|
|
6392
|
-
|
|
6393
|
-
|
|
7283
|
+
_context9.prev = 0;
|
|
7284
|
+
_context9.next = 3;
|
|
6394
7285
|
return fetch(inngestApiUrl + "/v1/events/" + id + "/runs", {
|
|
6395
7286
|
method: 'GET',
|
|
6396
7287
|
headers: {
|
|
@@ -6399,169 +7290,175 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6399
7290
|
}
|
|
6400
7291
|
});
|
|
6401
7292
|
case 3:
|
|
6402
|
-
response =
|
|
7293
|
+
response = _context9.sent;
|
|
6403
7294
|
console.log("Polling for event " + id + "...", response.ok);
|
|
6404
7295
|
if (!response.ok) {
|
|
6405
|
-
|
|
7296
|
+
_context9.next = 28;
|
|
6406
7297
|
break;
|
|
6407
7298
|
}
|
|
6408
|
-
|
|
7299
|
+
_context9.next = 8;
|
|
6409
7300
|
return response.json();
|
|
6410
7301
|
case 8:
|
|
6411
|
-
obj =
|
|
7302
|
+
obj = _context9.sent;
|
|
6412
7303
|
console.log({
|
|
6413
7304
|
obj: obj
|
|
6414
7305
|
});
|
|
6415
7306
|
data = obj.data, error = obj.error;
|
|
6416
7307
|
console.log("Got data for event " + id + "...", data, error);
|
|
6417
7308
|
if (!error) {
|
|
6418
|
-
|
|
7309
|
+
_context9.next = 15;
|
|
6419
7310
|
break;
|
|
6420
7311
|
}
|
|
6421
7312
|
console.error(error);
|
|
6422
|
-
return
|
|
7313
|
+
return _context9.abrupt("return", null);
|
|
6423
7314
|
case 15:
|
|
6424
7315
|
if (!((data == null ? void 0 : data.length) === 0)) {
|
|
6425
|
-
|
|
7316
|
+
_context9.next = 19;
|
|
6426
7317
|
break;
|
|
6427
7318
|
}
|
|
6428
|
-
|
|
7319
|
+
_context9.next = 18;
|
|
6429
7320
|
return new Promise(function (resolve) {
|
|
6430
7321
|
return setTimeout(resolve, interval);
|
|
6431
7322
|
});
|
|
6432
7323
|
case 18:
|
|
6433
|
-
return
|
|
7324
|
+
return _context9.abrupt("return", _poll());
|
|
6434
7325
|
case 19:
|
|
6435
7326
|
lastRun = data == null ? void 0 : data[0];
|
|
6436
7327
|
console.log(lastRun);
|
|
6437
7328
|
if (lastRun) {
|
|
6438
|
-
|
|
7329
|
+
_context9.next = 23;
|
|
6439
7330
|
break;
|
|
6440
7331
|
}
|
|
6441
|
-
return
|
|
7332
|
+
return _context9.abrupt("return", null);
|
|
6442
7333
|
case 23:
|
|
6443
7334
|
if (!(lastRun.status === 'Running')) {
|
|
6444
|
-
|
|
7335
|
+
_context9.next = 27;
|
|
6445
7336
|
break;
|
|
6446
7337
|
}
|
|
6447
|
-
|
|
7338
|
+
_context9.next = 26;
|
|
6448
7339
|
return new Promise(function (resolve) {
|
|
6449
7340
|
return setTimeout(resolve, interval);
|
|
6450
7341
|
});
|
|
6451
7342
|
case 26:
|
|
6452
|
-
return
|
|
7343
|
+
return _context9.abrupt("return", _poll());
|
|
6453
7344
|
case 27:
|
|
6454
|
-
return
|
|
7345
|
+
return _context9.abrupt("return", {
|
|
6455
7346
|
status: lastRun.status,
|
|
6456
7347
|
startedAt: lastRun.run_started_at,
|
|
6457
7348
|
endedAt: lastRun.ended_at
|
|
6458
7349
|
});
|
|
6459
7350
|
case 28:
|
|
6460
|
-
|
|
7351
|
+
_context9.next = 33;
|
|
6461
7352
|
break;
|
|
6462
7353
|
case 30:
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
console.error("Request failed: " +
|
|
7354
|
+
_context9.prev = 30;
|
|
7355
|
+
_context9.t0 = _context9["catch"](0);
|
|
7356
|
+
console.error("Request failed: " + _context9.t0);
|
|
6466
7357
|
case 33:
|
|
6467
7358
|
// Check if timeout has been reached
|
|
6468
7359
|
elapsedTime = Date.now() - startTime;
|
|
6469
7360
|
if (!(elapsedTime >= timeout)) {
|
|
6470
|
-
|
|
7361
|
+
_context9.next = 37;
|
|
6471
7362
|
break;
|
|
6472
7363
|
}
|
|
6473
7364
|
console.log('Polling timeout reached.');
|
|
6474
|
-
return
|
|
7365
|
+
return _context9.abrupt("return", null);
|
|
6475
7366
|
case 37:
|
|
6476
|
-
|
|
7367
|
+
_context9.next = 39;
|
|
6477
7368
|
return new Promise(function (resolve) {
|
|
6478
7369
|
return setTimeout(resolve, interval);
|
|
6479
7370
|
});
|
|
6480
7371
|
case 39:
|
|
6481
|
-
return
|
|
7372
|
+
return _context9.abrupt("return", _poll());
|
|
6482
7373
|
case 40:
|
|
6483
7374
|
case "end":
|
|
6484
|
-
return
|
|
7375
|
+
return _context9.stop();
|
|
6485
7376
|
}
|
|
6486
|
-
},
|
|
7377
|
+
}, _callee9, null, [[0, 30]]);
|
|
6487
7378
|
}));
|
|
6488
7379
|
return function poll() {
|
|
6489
|
-
return
|
|
7380
|
+
return _ref23.apply(this, arguments);
|
|
6490
7381
|
};
|
|
6491
7382
|
}();
|
|
6492
|
-
return
|
|
7383
|
+
return _context10.abrupt("return", _poll());
|
|
6493
7384
|
case 6:
|
|
6494
7385
|
case "end":
|
|
6495
|
-
return
|
|
7386
|
+
return _context10.stop();
|
|
6496
7387
|
}
|
|
6497
|
-
},
|
|
7388
|
+
}, _callee10, this);
|
|
6498
7389
|
}));
|
|
6499
|
-
function subscribeEvent(
|
|
7390
|
+
function subscribeEvent(_x8) {
|
|
6500
7391
|
return _subscribeEvent.apply(this, arguments);
|
|
6501
7392
|
}
|
|
6502
7393
|
return subscribeEvent;
|
|
6503
7394
|
}();
|
|
6504
7395
|
_proto.triggerEvent = /*#__PURE__*/function () {
|
|
6505
|
-
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7396
|
+
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref24) {
|
|
6506
7397
|
var _this4 = this;
|
|
6507
|
-
var key, data, user,
|
|
6508
|
-
return _regeneratorRuntime().wrap(function
|
|
6509
|
-
while (1) switch (
|
|
7398
|
+
var key, data, user, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
|
|
7399
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
7400
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
6510
7401
|
case 0:
|
|
6511
|
-
key =
|
|
6512
|
-
|
|
7402
|
+
key = _ref24.key, data = _ref24.data, user = _ref24.user, integrationName = _ref24.integrationName;
|
|
7403
|
+
_context13.prev = 1;
|
|
6513
7404
|
returnObj = {
|
|
6514
7405
|
event: {}
|
|
6515
7406
|
};
|
|
6516
|
-
|
|
7407
|
+
if (integrationName) {
|
|
7408
|
+
integrationEvents = this.getEventsByIntegration(integrationName);
|
|
7409
|
+
} else {
|
|
7410
|
+
integrationEvents = Array.from(this.globalEvents.values()).reduce(function (acc, curr) {
|
|
7411
|
+
return _extends({}, acc, curr);
|
|
7412
|
+
}, {});
|
|
7413
|
+
}
|
|
6517
7414
|
if (integrationEvents) {
|
|
6518
|
-
|
|
7415
|
+
_context13.next = 6;
|
|
6519
7416
|
break;
|
|
6520
7417
|
}
|
|
6521
|
-
throw new Error("No events
|
|
7418
|
+
throw new Error("No integration events found");
|
|
6522
7419
|
case 6:
|
|
6523
7420
|
integrationEvent = integrationEvents[key];
|
|
6524
7421
|
if (integrationEvent) {
|
|
6525
|
-
|
|
7422
|
+
_context13.next = 9;
|
|
6526
7423
|
break;
|
|
6527
7424
|
}
|
|
6528
|
-
throw new Error("No event exists for " + key + " in " + integrationName);
|
|
7425
|
+
throw new Error("No event exists for " + key + " in " + (integrationName || 'system'));
|
|
6529
7426
|
case 9:
|
|
6530
|
-
|
|
7427
|
+
_context13.next = 11;
|
|
6531
7428
|
return client$1.send({
|
|
6532
7429
|
name: key,
|
|
6533
7430
|
data: data,
|
|
6534
7431
|
user: user
|
|
6535
7432
|
});
|
|
6536
7433
|
case 11:
|
|
6537
|
-
event =
|
|
7434
|
+
event = _context13.sent;
|
|
6538
7435
|
returnObj['event'] = _extends({}, event, {
|
|
6539
7436
|
subscribe: function () {
|
|
6540
|
-
var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7437
|
+
var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_temp) {
|
|
6541
7438
|
var _event$ids;
|
|
6542
|
-
var
|
|
6543
|
-
return _regeneratorRuntime().wrap(function
|
|
6544
|
-
while (1) switch (
|
|
7439
|
+
var _ref25, interval, timeout;
|
|
7440
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
7441
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
6545
7442
|
case 0:
|
|
6546
|
-
|
|
6547
|
-
return
|
|
7443
|
+
_ref25 = _temp === void 0 ? {} : _temp, interval = _ref25.interval, timeout = _ref25.timeout;
|
|
7444
|
+
return _context11.abrupt("return", _this4.subscribeEvent({
|
|
6548
7445
|
id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
|
|
6549
7446
|
interval: interval,
|
|
6550
7447
|
timeout: timeout
|
|
6551
7448
|
}));
|
|
6552
7449
|
case 2:
|
|
6553
7450
|
case "end":
|
|
6554
|
-
return
|
|
7451
|
+
return _context11.stop();
|
|
6555
7452
|
}
|
|
6556
|
-
},
|
|
7453
|
+
}, _callee11);
|
|
6557
7454
|
}));
|
|
6558
|
-
function subscribe(
|
|
7455
|
+
function subscribe(_x10) {
|
|
6559
7456
|
return _subscribe.apply(this, arguments);
|
|
6560
7457
|
}
|
|
6561
7458
|
return subscribe;
|
|
6562
7459
|
}()
|
|
6563
7460
|
});
|
|
6564
|
-
|
|
7461
|
+
_context13.next = 15;
|
|
6565
7462
|
return client$1.send({
|
|
6566
7463
|
name: 'workflow/run-automations',
|
|
6567
7464
|
data: {
|
|
@@ -6571,45 +7468,45 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6571
7468
|
user: user
|
|
6572
7469
|
});
|
|
6573
7470
|
case 15:
|
|
6574
|
-
workflowEvent =
|
|
7471
|
+
workflowEvent = _context13.sent;
|
|
6575
7472
|
returnObj['workflowEvent'] = _extends({}, workflowEvent, {
|
|
6576
7473
|
subscribe: function () {
|
|
6577
|
-
var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7474
|
+
var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_temp2) {
|
|
6578
7475
|
var _workflowEvent$ids;
|
|
6579
|
-
var
|
|
6580
|
-
return _regeneratorRuntime().wrap(function
|
|
6581
|
-
while (1) switch (
|
|
7476
|
+
var _ref26, interval, timeout;
|
|
7477
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
7478
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
6582
7479
|
case 0:
|
|
6583
|
-
|
|
6584
|
-
return
|
|
7480
|
+
_ref26 = _temp2 === void 0 ? {} : _temp2, interval = _ref26.interval, timeout = _ref26.timeout;
|
|
7481
|
+
return _context12.abrupt("return", _this4.subscribeEvent({
|
|
6585
7482
|
id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
|
|
6586
7483
|
interval: interval,
|
|
6587
7484
|
timeout: timeout
|
|
6588
7485
|
}));
|
|
6589
7486
|
case 2:
|
|
6590
7487
|
case "end":
|
|
6591
|
-
return
|
|
7488
|
+
return _context12.stop();
|
|
6592
7489
|
}
|
|
6593
|
-
},
|
|
7490
|
+
}, _callee12);
|
|
6594
7491
|
}));
|
|
6595
|
-
function subscribe(
|
|
7492
|
+
function subscribe(_x11) {
|
|
6596
7493
|
return _subscribe2.apply(this, arguments);
|
|
6597
7494
|
}
|
|
6598
7495
|
return subscribe;
|
|
6599
7496
|
}()
|
|
6600
7497
|
});
|
|
6601
|
-
return
|
|
7498
|
+
return _context13.abrupt("return", returnObj);
|
|
6602
7499
|
case 20:
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
throw new Error("Error triggering event: " +
|
|
7500
|
+
_context13.prev = 20;
|
|
7501
|
+
_context13.t0 = _context13["catch"](1);
|
|
7502
|
+
throw new Error("Error triggering event: " + _context13.t0);
|
|
6606
7503
|
case 23:
|
|
6607
7504
|
case "end":
|
|
6608
|
-
return
|
|
7505
|
+
return _context13.stop();
|
|
6609
7506
|
}
|
|
6610
|
-
},
|
|
7507
|
+
}, _callee13, this, [[1, 20]]);
|
|
6611
7508
|
}));
|
|
6612
|
-
function triggerEvent(
|
|
7509
|
+
function triggerEvent(_x9) {
|
|
6613
7510
|
return _triggerEvent.apply(this, arguments);
|
|
6614
7511
|
}
|
|
6615
7512
|
return triggerEvent;
|
|
@@ -6618,26 +7515,26 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6618
7515
|
_proto.triggerSystemEvent =
|
|
6619
7516
|
/*#__PURE__*/
|
|
6620
7517
|
function () {
|
|
6621
|
-
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7518
|
+
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref27) {
|
|
6622
7519
|
var key, data, user, event, systemEvent;
|
|
6623
|
-
return _regeneratorRuntime().wrap(function
|
|
6624
|
-
while (1) switch (
|
|
7520
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
7521
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
6625
7522
|
case 0:
|
|
6626
|
-
key =
|
|
6627
|
-
|
|
7523
|
+
key = _ref27.key, data = _ref27.data, user = _ref27.user;
|
|
7524
|
+
_context14.next = 3;
|
|
6628
7525
|
return client$1.send({
|
|
6629
7526
|
name: key,
|
|
6630
7527
|
data: data,
|
|
6631
7528
|
user: user
|
|
6632
7529
|
});
|
|
6633
7530
|
case 3:
|
|
6634
|
-
event =
|
|
7531
|
+
event = _context14.sent;
|
|
6635
7532
|
systemEvent = this.getSystemEvents()[key];
|
|
6636
7533
|
if (!systemEvent) {
|
|
6637
|
-
|
|
7534
|
+
_context14.next = 8;
|
|
6638
7535
|
break;
|
|
6639
7536
|
}
|
|
6640
|
-
|
|
7537
|
+
_context14.next = 8;
|
|
6641
7538
|
return client$1.send({
|
|
6642
7539
|
name: 'workflow/run-automations',
|
|
6643
7540
|
data: {
|
|
@@ -6647,24 +7544,24 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6647
7544
|
user: user
|
|
6648
7545
|
});
|
|
6649
7546
|
case 8:
|
|
6650
|
-
return
|
|
7547
|
+
return _context14.abrupt("return", event);
|
|
6651
7548
|
case 9:
|
|
6652
7549
|
case "end":
|
|
6653
|
-
return
|
|
7550
|
+
return _context14.stop();
|
|
6654
7551
|
}
|
|
6655
|
-
},
|
|
7552
|
+
}, _callee14, this);
|
|
6656
7553
|
}));
|
|
6657
|
-
function triggerSystemEvent(
|
|
7554
|
+
function triggerSystemEvent(_x12) {
|
|
6658
7555
|
return _triggerSystemEvent.apply(this, arguments);
|
|
6659
7556
|
}
|
|
6660
7557
|
return triggerSystemEvent;
|
|
6661
7558
|
}();
|
|
6662
7559
|
_proto.createRouter = function createRouter() {
|
|
6663
7560
|
var self = this;
|
|
6664
|
-
var makeWebhookUrl = function makeWebhookUrl(
|
|
7561
|
+
var makeWebhookUrl = function makeWebhookUrl(_ref28) {
|
|
6665
7562
|
var _self$config;
|
|
6666
|
-
var event =
|
|
6667
|
-
name =
|
|
7563
|
+
var event = _ref28.event,
|
|
7564
|
+
name = _ref28.name;
|
|
6668
7565
|
return encodeURI("" + (self == null || (_self$config = self.config) == null ? void 0 : _self$config.systemHostURL) + self.routes.webhook + "?name=" + name + "&event=" + event);
|
|
6669
7566
|
};
|
|
6670
7567
|
var makeRedirectURI = function makeRedirectURI() {
|
|
@@ -6695,36 +7592,38 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6695
7592
|
};
|
|
6696
7593
|
};
|
|
6697
7594
|
_proto.getAgent = /*#__PURE__*/function () {
|
|
6698
|
-
var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
7595
|
+
var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref29) {
|
|
6699
7596
|
var connectionId, agentId, agentBlueprint, arrMap, finalApis;
|
|
6700
|
-
return _regeneratorRuntime().wrap(function
|
|
6701
|
-
while (1) switch (
|
|
7597
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
7598
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
6702
7599
|
case 0:
|
|
6703
|
-
connectionId =
|
|
6704
|
-
|
|
7600
|
+
connectionId = _ref29.connectionId, agentId = _ref29.agentId;
|
|
7601
|
+
_context15.next = 3;
|
|
6705
7602
|
return getAgentBlueprint({
|
|
6706
7603
|
agentDir: this.config.agents.agentDirPath,
|
|
6707
7604
|
agentId: agentId
|
|
6708
7605
|
});
|
|
6709
7606
|
case 3:
|
|
6710
|
-
agentBlueprint =
|
|
7607
|
+
agentBlueprint = _context15.sent;
|
|
6711
7608
|
arrMap = Array.from(this.getApis());
|
|
6712
|
-
finalApis = arrMap.reduce(function (acc,
|
|
6713
|
-
var v =
|
|
7609
|
+
finalApis = arrMap.reduce(function (acc, _ref30) {
|
|
7610
|
+
var v = _ref30[1];
|
|
6714
7611
|
return _extends({}, acc, v);
|
|
6715
7612
|
}, {});
|
|
6716
|
-
|
|
7613
|
+
console.log('got finalApis===');
|
|
7614
|
+
return _context15.abrupt("return", getAgent({
|
|
6717
7615
|
connectionId: connectionId,
|
|
6718
7616
|
agent: agentBlueprint,
|
|
6719
|
-
apis: finalApis
|
|
7617
|
+
apis: finalApis,
|
|
7618
|
+
logger: this.logger
|
|
6720
7619
|
}));
|
|
6721
|
-
case
|
|
7620
|
+
case 8:
|
|
6722
7621
|
case "end":
|
|
6723
|
-
return
|
|
7622
|
+
return _context15.stop();
|
|
6724
7623
|
}
|
|
6725
|
-
},
|
|
7624
|
+
}, _callee15, this);
|
|
6726
7625
|
}));
|
|
6727
|
-
function getAgent$1(
|
|
7626
|
+
function getAgent$1(_x13) {
|
|
6728
7627
|
return _getAgent2.apply(this, arguments);
|
|
6729
7628
|
}
|
|
6730
7629
|
return getAgent$1;
|
|
@@ -6739,13 +7638,22 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6739
7638
|
inngest: '/inngest',
|
|
6740
7639
|
webhook: '/webhook'
|
|
6741
7640
|
};
|
|
6742
|
-
return Object.entries(registry).reduce(function (acc,
|
|
7641
|
+
return Object.entries(registry).reduce(function (acc, _ref31) {
|
|
6743
7642
|
var _extends5;
|
|
6744
|
-
var key =
|
|
6745
|
-
value =
|
|
7643
|
+
var key = _ref31[0],
|
|
7644
|
+
value = _ref31[1];
|
|
6746
7645
|
return _extends({}, acc, (_extends5 = {}, _extends5[key] = "" + _this5.config.routeRegistrationPath + value, _extends5));
|
|
6747
7646
|
}, {});
|
|
6748
7647
|
}
|
|
7648
|
+
}, {
|
|
7649
|
+
key: "openAIAssistant",
|
|
7650
|
+
get: function get() {
|
|
7651
|
+
return {
|
|
7652
|
+
createAssistantAgent: createAssistantAgentHandler(this.logger),
|
|
7653
|
+
getAssistantAgent: getAssistantAgentHandler(this.logger),
|
|
7654
|
+
updateAssistantAgent: updateAssistantAgentHandler(this.logger)
|
|
7655
|
+
};
|
|
7656
|
+
}
|
|
6749
7657
|
}]);
|
|
6750
7658
|
}();
|
|
6751
7659
|
|
|
@@ -6779,6 +7687,7 @@ exports.getEntityKey = getEntityKey;
|
|
|
6779
7687
|
exports.getJSONField = getJSONField;
|
|
6780
7688
|
exports.getPath = getPath;
|
|
6781
7689
|
exports.getResponseDataKey = getResponseDataKey;
|
|
7690
|
+
exports.getUpstashLogs = getUpstashLogs;
|
|
6782
7691
|
exports.isLiteralObject = isLiteralObject;
|
|
6783
7692
|
exports.isObjectEmpty = isObjectEmpty;
|
|
6784
7693
|
exports.mergeWithDefinedOnly = mergeWithDefinedOnly;
|