@mastra/core 0.1.9 → 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 +17 -24
- package/dist/agents/vector-sync.d.ts.map +1 -1
- package/dist/core.cjs.development.js +1104 -745
- 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 +1104 -746
- package/dist/core.esm.js.map +1 -1
- package/dist/framework.d.ts +60 -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 +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -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);
|
|
@@ -4261,11 +4262,16 @@ function getAgentDir(_ref) {
|
|
|
4261
4262
|
}
|
|
4262
4263
|
function listAgentsJson(_ref2) {
|
|
4263
4264
|
var agentDir = _ref2.agentDir;
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
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
|
+
}
|
|
4269
4275
|
}
|
|
4270
4276
|
function getAgentFile(agentFilePath) {
|
|
4271
4277
|
try {
|
|
@@ -4485,7 +4491,7 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4485
4491
|
}();
|
|
4486
4492
|
|
|
4487
4493
|
function getVectorProvider(provider) {
|
|
4488
|
-
if (provider === '
|
|
4494
|
+
if (provider === 'pinecone') {
|
|
4489
4495
|
var _VectorLayer = new VectorLayer(),
|
|
4490
4496
|
Pinecone = _VectorLayer.Pinecone;
|
|
4491
4497
|
return Pinecone;
|
|
@@ -4501,11 +4507,11 @@ function executeIndexSync(_x) {
|
|
|
4501
4507
|
}
|
|
4502
4508
|
//Generic vector sync from event data
|
|
4503
4509
|
function _executeIndexSync() {
|
|
4504
|
-
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4510
|
+
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
|
|
4505
4511
|
var _event$user, _event$data;
|
|
4506
4512
|
var event, mastra, connectionId, providedIndexes, systemName, _iterator, _step, _step$value, provider, indexes, vp, _iterator2, _step2, index, indexMetadata, _loop, _ret, _iterator3, _step3;
|
|
4507
|
-
return _regeneratorRuntime().wrap(function
|
|
4508
|
-
while (1) switch (
|
|
4513
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
4514
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4509
4515
|
case 0:
|
|
4510
4516
|
event = _ref.event, mastra = _ref.mastra;
|
|
4511
4517
|
connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
|
|
@@ -4514,83 +4520,83 @@ function _executeIndexSync() {
|
|
|
4514
4520
|
_iterator = _createForOfIteratorHelperLoose(providedIndexes);
|
|
4515
4521
|
case 5:
|
|
4516
4522
|
if ((_step = _iterator()).done) {
|
|
4517
|
-
|
|
4523
|
+
_context5.next = 36;
|
|
4518
4524
|
break;
|
|
4519
4525
|
}
|
|
4520
4526
|
_step$value = _step.value, provider = _step$value.provider, indexes = _step$value.indexes;
|
|
4521
4527
|
vp = getVectorProvider(provider);
|
|
4522
4528
|
if (vp) {
|
|
4523
|
-
|
|
4529
|
+
_context5.next = 11;
|
|
4524
4530
|
break;
|
|
4525
4531
|
}
|
|
4526
4532
|
console.error('UNSUPPORTED VECTOR PROVIDER', provider);
|
|
4527
|
-
return
|
|
4533
|
+
return _context5.abrupt("return");
|
|
4528
4534
|
case 11:
|
|
4529
4535
|
if (process.env.OPENAI_API_KEY) {
|
|
4530
|
-
|
|
4536
|
+
_context5.next = 14;
|
|
4531
4537
|
break;
|
|
4532
4538
|
}
|
|
4533
4539
|
console.error('NO OPENAI_API_KEY');
|
|
4534
|
-
return
|
|
4540
|
+
return _context5.abrupt("return");
|
|
4535
4541
|
case 14:
|
|
4536
4542
|
_iterator2 = _createForOfIteratorHelperLoose(indexes);
|
|
4537
4543
|
case 15:
|
|
4538
4544
|
if ((_step2 = _iterator2()).done) {
|
|
4539
|
-
|
|
4545
|
+
_context5.next = 34;
|
|
4540
4546
|
break;
|
|
4541
4547
|
}
|
|
4542
4548
|
index = _step2.value;
|
|
4543
|
-
|
|
4549
|
+
_context5.next = 19;
|
|
4544
4550
|
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
4545
4551
|
name: index
|
|
4546
4552
|
});
|
|
4547
4553
|
case 19:
|
|
4548
|
-
indexMetadata =
|
|
4554
|
+
indexMetadata = _context5.sent;
|
|
4549
4555
|
if (indexMetadata != null && indexMetadata.length) {
|
|
4550
|
-
|
|
4556
|
+
_context5.next = 23;
|
|
4551
4557
|
break;
|
|
4552
4558
|
}
|
|
4553
4559
|
console.error('No index metadata found for', index);
|
|
4554
|
-
return
|
|
4560
|
+
return _context5.abrupt("return");
|
|
4555
4561
|
case 23:
|
|
4556
4562
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
4557
4563
|
var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
|
|
4558
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;
|
|
4559
|
-
return _regeneratorRuntime().wrap(function _loop$(
|
|
4560
|
-
while (1) switch (
|
|
4565
|
+
return _regeneratorRuntime().wrap(function _loop$(_context4) {
|
|
4566
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4561
4567
|
case 0:
|
|
4562
4568
|
entity = _step3.value;
|
|
4563
4569
|
fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
|
|
4564
|
-
|
|
4570
|
+
_context4.next = 4;
|
|
4565
4571
|
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4566
4572
|
connectionId: connectionId,
|
|
4567
4573
|
name: integration
|
|
4568
4574
|
});
|
|
4569
4575
|
case 4:
|
|
4570
|
-
|
|
4571
|
-
if (!(
|
|
4572
|
-
|
|
4576
|
+
_context4.t1 = _yield$mastra$dataLay = _context4.sent;
|
|
4577
|
+
if (!(_context4.t1 == null)) {
|
|
4578
|
+
_context4.next = 9;
|
|
4573
4579
|
break;
|
|
4574
4580
|
}
|
|
4575
|
-
|
|
4576
|
-
|
|
4581
|
+
_context4.t2 = void 0;
|
|
4582
|
+
_context4.next = 10;
|
|
4577
4583
|
break;
|
|
4578
4584
|
case 9:
|
|
4579
|
-
|
|
4585
|
+
_context4.t2 = _yield$mastra$dataLay.id;
|
|
4580
4586
|
case 10:
|
|
4581
|
-
|
|
4582
|
-
if (
|
|
4583
|
-
|
|
4587
|
+
_context4.t0 = _context4.t2;
|
|
4588
|
+
if (_context4.t0) {
|
|
4589
|
+
_context4.next = 13;
|
|
4584
4590
|
break;
|
|
4585
4591
|
}
|
|
4586
|
-
|
|
4592
|
+
_context4.t0 = '';
|
|
4587
4593
|
case 13:
|
|
4588
|
-
k_id =
|
|
4594
|
+
k_id = _context4.t0;
|
|
4589
4595
|
if (!(!k_id && integration === systemName)) {
|
|
4590
|
-
|
|
4596
|
+
_context4.next = 19;
|
|
4591
4597
|
break;
|
|
4592
4598
|
}
|
|
4593
|
-
|
|
4599
|
+
_context4.next = 17;
|
|
4594
4600
|
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4595
4601
|
connection: {
|
|
4596
4602
|
connectionId: connectionId,
|
|
@@ -4603,32 +4609,32 @@ function _executeIndexSync() {
|
|
|
4603
4609
|
}
|
|
4604
4610
|
});
|
|
4605
4611
|
case 17:
|
|
4606
|
-
connection =
|
|
4612
|
+
connection = _context4.sent;
|
|
4607
4613
|
k_id = connection.id;
|
|
4608
4614
|
case 19:
|
|
4609
4615
|
if (k_id) {
|
|
4610
|
-
|
|
4616
|
+
_context4.next = 22;
|
|
4611
4617
|
break;
|
|
4612
4618
|
}
|
|
4613
4619
|
console.error('Error bootstrapping shit');
|
|
4614
|
-
return
|
|
4620
|
+
return _context4.abrupt("return", {
|
|
4615
4621
|
v: void 0
|
|
4616
4622
|
});
|
|
4617
4623
|
case 22:
|
|
4618
|
-
|
|
4624
|
+
_context4.next = 24;
|
|
4619
4625
|
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
4620
4626
|
k_id: k_id,
|
|
4621
4627
|
type: name
|
|
4622
4628
|
});
|
|
4623
4629
|
case 24:
|
|
4624
|
-
entityRecords =
|
|
4630
|
+
entityRecords = _context4.sent;
|
|
4625
4631
|
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
4626
4632
|
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
4627
|
-
|
|
4633
|
+
_context4.next = 44;
|
|
4628
4634
|
break;
|
|
4629
4635
|
}
|
|
4630
4636
|
console.error('NO RECORDS ATTEMPTING SYNC');
|
|
4631
|
-
|
|
4637
|
+
_context4.next = 30;
|
|
4632
4638
|
return mastra.triggerEvent({
|
|
4633
4639
|
key: syncEvent,
|
|
4634
4640
|
data: {},
|
|
@@ -4637,34 +4643,34 @@ function _executeIndexSync() {
|
|
|
4637
4643
|
}
|
|
4638
4644
|
});
|
|
4639
4645
|
case 30:
|
|
4640
|
-
_yield$mastra$trigger =
|
|
4646
|
+
_yield$mastra$trigger = _context4.sent;
|
|
4641
4647
|
_event = _yield$mastra$trigger.event;
|
|
4642
4648
|
console.log(_event, '####');
|
|
4643
|
-
|
|
4649
|
+
_context4.next = 35;
|
|
4644
4650
|
return _event.subscribe();
|
|
4645
4651
|
case 35:
|
|
4646
|
-
res =
|
|
4652
|
+
res = _context4.sent;
|
|
4647
4653
|
console.log('Subscribe result', res);
|
|
4648
|
-
|
|
4654
|
+
_context4.next = 39;
|
|
4649
4655
|
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
4650
4656
|
k_id: k_id,
|
|
4651
4657
|
type: entity.name
|
|
4652
4658
|
});
|
|
4653
4659
|
case 39:
|
|
4654
|
-
entityRecords =
|
|
4660
|
+
entityRecords = _context4.sent;
|
|
4655
4661
|
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
4656
4662
|
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
4657
|
-
|
|
4663
|
+
_context4.next = 44;
|
|
4658
4664
|
break;
|
|
4659
4665
|
}
|
|
4660
4666
|
console.error('NO RECORDS AFTER SYNC');
|
|
4661
|
-
return
|
|
4667
|
+
return _context4.abrupt("return", {
|
|
4662
4668
|
v: void 0
|
|
4663
4669
|
});
|
|
4664
4670
|
case 44:
|
|
4665
|
-
recordsMapped = records.map(function (
|
|
4666
|
-
var data =
|
|
4667
|
-
externalId =
|
|
4671
|
+
recordsMapped = records.map(function (_ref9) {
|
|
4672
|
+
var data = _ref9.data,
|
|
4673
|
+
externalId = _ref9.externalId;
|
|
4668
4674
|
return _extends({
|
|
4669
4675
|
id: externalId
|
|
4670
4676
|
}, _.pick(data, fields));
|
|
@@ -4672,91 +4678,91 @@ function _executeIndexSync() {
|
|
|
4672
4678
|
console.log(recordsMapped, 'RECORDS');
|
|
4673
4679
|
entityTypeIndex = vp.index(index);
|
|
4674
4680
|
console.log(entityTypeIndex, 'INDEX');
|
|
4675
|
-
|
|
4676
|
-
|
|
4681
|
+
_context4.prev = 48;
|
|
4682
|
+
_context4.next = 51;
|
|
4677
4683
|
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4678
|
-
var
|
|
4684
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(record) {
|
|
4679
4685
|
var _yield$embed, embedding;
|
|
4680
|
-
return _regeneratorRuntime().wrap(function
|
|
4681
|
-
while (1) switch (
|
|
4686
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4687
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4682
4688
|
case 0:
|
|
4683
|
-
|
|
4689
|
+
_context3.next = 2;
|
|
4684
4690
|
return ai.embed({
|
|
4685
4691
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4686
4692
|
value: JSON.stringify(record)
|
|
4687
4693
|
});
|
|
4688
4694
|
case 2:
|
|
4689
|
-
_yield$embed =
|
|
4695
|
+
_yield$embed = _context3.sent;
|
|
4690
4696
|
embedding = _yield$embed.embedding;
|
|
4691
|
-
return
|
|
4697
|
+
return _context3.abrupt("return", {
|
|
4692
4698
|
id: record.id,
|
|
4693
4699
|
values: embedding,
|
|
4694
4700
|
metadata: record
|
|
4695
4701
|
});
|
|
4696
4702
|
case 5:
|
|
4697
4703
|
case "end":
|
|
4698
|
-
return
|
|
4704
|
+
return _context3.stop();
|
|
4699
4705
|
}
|
|
4700
|
-
},
|
|
4706
|
+
}, _callee3);
|
|
4701
4707
|
}));
|
|
4702
|
-
return function (
|
|
4703
|
-
return
|
|
4708
|
+
return function (_x7) {
|
|
4709
|
+
return _ref10.apply(this, arguments);
|
|
4704
4710
|
};
|
|
4705
4711
|
}())) != null ? _recordsMapped$map : []);
|
|
4706
4712
|
case 51:
|
|
4707
|
-
vectors =
|
|
4713
|
+
vectors = _context4.sent;
|
|
4708
4714
|
console.log('UPSERTING', vectors);
|
|
4709
4715
|
if (!(vectors.length > 0)) {
|
|
4710
|
-
|
|
4716
|
+
_context4.next = 56;
|
|
4711
4717
|
break;
|
|
4712
4718
|
}
|
|
4713
|
-
|
|
4719
|
+
_context4.next = 56;
|
|
4714
4720
|
return entityTypeIndex.namespace(name).upsert(vectors);
|
|
4715
4721
|
case 56:
|
|
4716
|
-
|
|
4722
|
+
_context4.next = 61;
|
|
4717
4723
|
break;
|
|
4718
4724
|
case 58:
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
console.error(
|
|
4725
|
+
_context4.prev = 58;
|
|
4726
|
+
_context4.t3 = _context4["catch"](48);
|
|
4727
|
+
console.error(_context4.t3);
|
|
4722
4728
|
case 61:
|
|
4723
|
-
return
|
|
4729
|
+
return _context4.abrupt("return", {
|
|
4724
4730
|
v: void 0
|
|
4725
4731
|
});
|
|
4726
4732
|
case 62:
|
|
4727
4733
|
case "end":
|
|
4728
|
-
return
|
|
4734
|
+
return _context4.stop();
|
|
4729
4735
|
}
|
|
4730
4736
|
}, _loop, null, [[48, 58]]);
|
|
4731
4737
|
});
|
|
4732
4738
|
_iterator3 = _createForOfIteratorHelperLoose(indexMetadata);
|
|
4733
4739
|
case 25:
|
|
4734
4740
|
if ((_step3 = _iterator3()).done) {
|
|
4735
|
-
|
|
4741
|
+
_context5.next = 32;
|
|
4736
4742
|
break;
|
|
4737
4743
|
}
|
|
4738
|
-
return
|
|
4744
|
+
return _context5.delegateYield(_loop(), "t0", 27);
|
|
4739
4745
|
case 27:
|
|
4740
|
-
_ret =
|
|
4746
|
+
_ret = _context5.t0;
|
|
4741
4747
|
if (!_ret) {
|
|
4742
|
-
|
|
4748
|
+
_context5.next = 30;
|
|
4743
4749
|
break;
|
|
4744
4750
|
}
|
|
4745
|
-
return
|
|
4751
|
+
return _context5.abrupt("return", _ret.v);
|
|
4746
4752
|
case 30:
|
|
4747
|
-
|
|
4753
|
+
_context5.next = 25;
|
|
4748
4754
|
break;
|
|
4749
4755
|
case 32:
|
|
4750
|
-
|
|
4756
|
+
_context5.next = 15;
|
|
4751
4757
|
break;
|
|
4752
4758
|
case 34:
|
|
4753
|
-
|
|
4759
|
+
_context5.next = 5;
|
|
4754
4760
|
break;
|
|
4755
4761
|
case 36:
|
|
4756
4762
|
case "end":
|
|
4757
|
-
return
|
|
4763
|
+
return _context5.stop();
|
|
4758
4764
|
}
|
|
4759
|
-
},
|
|
4765
|
+
}, _callee4);
|
|
4760
4766
|
}));
|
|
4761
4767
|
return _executeIndexSync.apply(this, arguments);
|
|
4762
4768
|
}
|
|
@@ -4765,11 +4771,11 @@ function executeGenericVectorSync(_x2) {
|
|
|
4765
4771
|
}
|
|
4766
4772
|
// Vector Sync from agents Dir
|
|
4767
4773
|
function _executeGenericVectorSync() {
|
|
4768
|
-
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4774
|
+
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref2) {
|
|
4769
4775
|
var _event$user2, _event$data2, _event$data3;
|
|
4770
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;
|
|
4771
|
-
return _regeneratorRuntime().wrap(function
|
|
4772
|
-
while (1) switch (
|
|
4777
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
4778
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4773
4779
|
case 0:
|
|
4774
4780
|
event = _ref2.event, mastra = _ref2.mastra;
|
|
4775
4781
|
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
@@ -4777,65 +4783,65 @@ function _executeGenericVectorSync() {
|
|
|
4777
4783
|
entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
|
|
4778
4784
|
systemName = mastra.config.name;
|
|
4779
4785
|
if (vector_provider) {
|
|
4780
|
-
|
|
4786
|
+
_context8.next = 8;
|
|
4781
4787
|
break;
|
|
4782
4788
|
}
|
|
4783
4789
|
console.error("No vector_provider defined for agent");
|
|
4784
|
-
return
|
|
4790
|
+
return _context8.abrupt("return");
|
|
4785
4791
|
case 8:
|
|
4786
4792
|
vp = getVectorProvider(vector_provider);
|
|
4787
4793
|
if (vp) {
|
|
4788
|
-
|
|
4794
|
+
_context8.next = 12;
|
|
4789
4795
|
break;
|
|
4790
4796
|
}
|
|
4791
4797
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4792
|
-
return
|
|
4798
|
+
return _context8.abrupt("return");
|
|
4793
4799
|
case 12:
|
|
4794
4800
|
if (process.env.OPENAI_API_KEY) {
|
|
4795
|
-
|
|
4801
|
+
_context8.next = 15;
|
|
4796
4802
|
break;
|
|
4797
4803
|
}
|
|
4798
4804
|
console.error('NO OPENAI_API_KEY');
|
|
4799
|
-
return
|
|
4805
|
+
return _context8.abrupt("return");
|
|
4800
4806
|
case 15:
|
|
4801
4807
|
_iterator4 = _createForOfIteratorHelperLoose(entities);
|
|
4802
4808
|
case 16:
|
|
4803
4809
|
if ((_step4 = _iterator4()).done) {
|
|
4804
|
-
|
|
4810
|
+
_context8.next = 50;
|
|
4805
4811
|
break;
|
|
4806
4812
|
}
|
|
4807
4813
|
vectorE = _step4.value;
|
|
4808
4814
|
integrationName = vectorE.integration;
|
|
4809
|
-
|
|
4815
|
+
_context8.next = 21;
|
|
4810
4816
|
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
4811
4817
|
connectionId: connectionId,
|
|
4812
4818
|
name: integrationName
|
|
4813
4819
|
});
|
|
4814
4820
|
case 21:
|
|
4815
|
-
|
|
4816
|
-
if (!(
|
|
4817
|
-
|
|
4821
|
+
_context8.t1 = _yield$mastra$dataLay2 = _context8.sent;
|
|
4822
|
+
if (!(_context8.t1 == null)) {
|
|
4823
|
+
_context8.next = 26;
|
|
4818
4824
|
break;
|
|
4819
4825
|
}
|
|
4820
|
-
|
|
4821
|
-
|
|
4826
|
+
_context8.t2 = void 0;
|
|
4827
|
+
_context8.next = 27;
|
|
4822
4828
|
break;
|
|
4823
4829
|
case 26:
|
|
4824
|
-
|
|
4830
|
+
_context8.t2 = _yield$mastra$dataLay2.id;
|
|
4825
4831
|
case 27:
|
|
4826
|
-
|
|
4827
|
-
if (
|
|
4828
|
-
|
|
4832
|
+
_context8.t0 = _context8.t2;
|
|
4833
|
+
if (_context8.t0) {
|
|
4834
|
+
_context8.next = 30;
|
|
4829
4835
|
break;
|
|
4830
4836
|
}
|
|
4831
|
-
|
|
4837
|
+
_context8.t0 = '';
|
|
4832
4838
|
case 30:
|
|
4833
|
-
k_id =
|
|
4839
|
+
k_id = _context8.t0;
|
|
4834
4840
|
if (!(!k_id && integrationName === systemName)) {
|
|
4835
|
-
|
|
4841
|
+
_context8.next = 36;
|
|
4836
4842
|
break;
|
|
4837
4843
|
}
|
|
4838
|
-
|
|
4844
|
+
_context8.next = 34;
|
|
4839
4845
|
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4840
4846
|
connection: {
|
|
4841
4847
|
connectionId: connectionId,
|
|
@@ -4848,38 +4854,38 @@ function _executeGenericVectorSync() {
|
|
|
4848
4854
|
}
|
|
4849
4855
|
});
|
|
4850
4856
|
case 34:
|
|
4851
|
-
connection =
|
|
4857
|
+
connection = _context8.sent;
|
|
4852
4858
|
k_id = connection.id;
|
|
4853
4859
|
case 36:
|
|
4854
4860
|
if (k_id) {
|
|
4855
|
-
|
|
4861
|
+
_context8.next = 39;
|
|
4856
4862
|
break;
|
|
4857
4863
|
}
|
|
4858
4864
|
console.error('Error bootstrapping shit');
|
|
4859
|
-
return
|
|
4865
|
+
return _context8.abrupt("return");
|
|
4860
4866
|
case 39:
|
|
4861
4867
|
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4862
4868
|
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4863
4869
|
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4864
|
-
return _regeneratorRuntime().wrap(function _loop2$(
|
|
4865
|
-
while (1) switch (
|
|
4870
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context7) {
|
|
4871
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4866
4872
|
case 0:
|
|
4867
4873
|
entity = _step5.value;
|
|
4868
|
-
|
|
4874
|
+
_context7.next = 3;
|
|
4869
4875
|
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4870
4876
|
k_id: k_id,
|
|
4871
4877
|
type: entity.name
|
|
4872
4878
|
});
|
|
4873
4879
|
case 3:
|
|
4874
|
-
entityRecords =
|
|
4880
|
+
entityRecords = _context7.sent;
|
|
4875
4881
|
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4876
4882
|
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4877
|
-
|
|
4883
|
+
_context7.next = 23;
|
|
4878
4884
|
break;
|
|
4879
4885
|
}
|
|
4880
4886
|
// @TODO: SYNC THEM
|
|
4881
4887
|
console.error('NO RECORDS');
|
|
4882
|
-
|
|
4888
|
+
_context7.next = 9;
|
|
4883
4889
|
return mastra.triggerEvent({
|
|
4884
4890
|
key: entity.syncEvent,
|
|
4885
4891
|
data: {},
|
|
@@ -4888,40 +4894,40 @@ function _executeGenericVectorSync() {
|
|
|
4888
4894
|
}
|
|
4889
4895
|
});
|
|
4890
4896
|
case 9:
|
|
4891
|
-
_yield$mastra$trigger2 =
|
|
4897
|
+
_yield$mastra$trigger2 = _context7.sent;
|
|
4892
4898
|
_event2 = _yield$mastra$trigger2.event;
|
|
4893
4899
|
console.log(_event2, '####');
|
|
4894
|
-
|
|
4900
|
+
_context7.next = 14;
|
|
4895
4901
|
return _event2.subscribe();
|
|
4896
4902
|
case 14:
|
|
4897
|
-
res =
|
|
4903
|
+
res = _context7.sent;
|
|
4898
4904
|
console.log('Subscribe result', res);
|
|
4899
|
-
|
|
4905
|
+
_context7.next = 18;
|
|
4900
4906
|
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4901
4907
|
k_id: k_id,
|
|
4902
4908
|
type: entity.name
|
|
4903
4909
|
});
|
|
4904
4910
|
case 18:
|
|
4905
|
-
entityRecords =
|
|
4911
|
+
entityRecords = _context7.sent;
|
|
4906
4912
|
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4907
4913
|
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4908
|
-
|
|
4914
|
+
_context7.next = 23;
|
|
4909
4915
|
break;
|
|
4910
4916
|
}
|
|
4911
4917
|
console.error('NO RECORDS AFTER SYNC');
|
|
4912
|
-
return
|
|
4918
|
+
return _context7.abrupt("return", {
|
|
4913
4919
|
v: void 0
|
|
4914
4920
|
});
|
|
4915
4921
|
case 23:
|
|
4916
|
-
recordsMapped = records.map(function (
|
|
4917
|
-
var data =
|
|
4918
|
-
externalId =
|
|
4922
|
+
recordsMapped = records.map(function (_ref11) {
|
|
4923
|
+
var data = _ref11.data,
|
|
4924
|
+
externalId = _ref11.externalId;
|
|
4919
4925
|
return _extends({
|
|
4920
4926
|
id: externalId
|
|
4921
4927
|
}, _.pick(data, entity.fields));
|
|
4922
4928
|
});
|
|
4923
4929
|
console.log(recordsMapped, 'RECORDS');
|
|
4924
|
-
|
|
4930
|
+
_context7.next = 27;
|
|
4925
4931
|
return vp.createIndex({
|
|
4926
4932
|
suppressConflicts: true,
|
|
4927
4933
|
name: entity.name,
|
|
@@ -4935,93 +4941,93 @@ function _executeGenericVectorSync() {
|
|
|
4935
4941
|
}
|
|
4936
4942
|
});
|
|
4937
4943
|
case 27:
|
|
4938
|
-
|
|
4944
|
+
_context7.next = 29;
|
|
4939
4945
|
return delay$1(5000);
|
|
4940
4946
|
case 29:
|
|
4941
4947
|
entityTypeIndex = vp.index(entity.name);
|
|
4942
4948
|
console.log(entityTypeIndex, 'INDEX');
|
|
4943
|
-
|
|
4944
|
-
|
|
4949
|
+
_context7.prev = 31;
|
|
4950
|
+
_context7.next = 34;
|
|
4945
4951
|
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4946
|
-
var
|
|
4952
|
+
var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record) {
|
|
4947
4953
|
var _yield$embed2, embedding;
|
|
4948
|
-
return _regeneratorRuntime().wrap(function
|
|
4949
|
-
while (1) switch (
|
|
4954
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
|
|
4955
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4950
4956
|
case 0:
|
|
4951
|
-
|
|
4957
|
+
_context6.next = 2;
|
|
4952
4958
|
return ai.embed({
|
|
4953
4959
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4954
4960
|
value: JSON.stringify(record)
|
|
4955
4961
|
});
|
|
4956
4962
|
case 2:
|
|
4957
|
-
_yield$embed2 =
|
|
4963
|
+
_yield$embed2 = _context6.sent;
|
|
4958
4964
|
embedding = _yield$embed2.embedding;
|
|
4959
|
-
return
|
|
4965
|
+
return _context6.abrupt("return", {
|
|
4960
4966
|
id: record.id,
|
|
4961
4967
|
values: embedding,
|
|
4962
4968
|
metadata: record
|
|
4963
4969
|
});
|
|
4964
4970
|
case 5:
|
|
4965
4971
|
case "end":
|
|
4966
|
-
return
|
|
4972
|
+
return _context6.stop();
|
|
4967
4973
|
}
|
|
4968
|
-
},
|
|
4974
|
+
}, _callee5);
|
|
4969
4975
|
}));
|
|
4970
|
-
return function (
|
|
4971
|
-
return
|
|
4976
|
+
return function (_x8) {
|
|
4977
|
+
return _ref12.apply(this, arguments);
|
|
4972
4978
|
};
|
|
4973
4979
|
}())) != null ? _recordsMapped$map2 : []);
|
|
4974
4980
|
case 34:
|
|
4975
|
-
vectors =
|
|
4981
|
+
vectors = _context7.sent;
|
|
4976
4982
|
console.log('UPSERTING', vectors);
|
|
4977
4983
|
if (!(vectors.length > 0)) {
|
|
4978
|
-
|
|
4984
|
+
_context7.next = 39;
|
|
4979
4985
|
break;
|
|
4980
4986
|
}
|
|
4981
|
-
|
|
4987
|
+
_context7.next = 39;
|
|
4982
4988
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4983
4989
|
case 39:
|
|
4984
|
-
|
|
4990
|
+
_context7.next = 44;
|
|
4985
4991
|
break;
|
|
4986
4992
|
case 41:
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
console.error(
|
|
4993
|
+
_context7.prev = 41;
|
|
4994
|
+
_context7.t0 = _context7["catch"](31);
|
|
4995
|
+
console.error(_context7.t0);
|
|
4990
4996
|
case 44:
|
|
4991
|
-
return
|
|
4997
|
+
return _context7.abrupt("return", {
|
|
4992
4998
|
v: void 0
|
|
4993
4999
|
});
|
|
4994
5000
|
case 45:
|
|
4995
5001
|
case "end":
|
|
4996
|
-
return
|
|
5002
|
+
return _context7.stop();
|
|
4997
5003
|
}
|
|
4998
5004
|
}, _loop2, null, [[31, 41]]);
|
|
4999
5005
|
});
|
|
5000
5006
|
_iterator5 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5001
5007
|
case 41:
|
|
5002
5008
|
if ((_step5 = _iterator5()).done) {
|
|
5003
|
-
|
|
5009
|
+
_context8.next = 48;
|
|
5004
5010
|
break;
|
|
5005
5011
|
}
|
|
5006
|
-
return
|
|
5012
|
+
return _context8.delegateYield(_loop2(), "t3", 43);
|
|
5007
5013
|
case 43:
|
|
5008
|
-
_ret2 =
|
|
5014
|
+
_ret2 = _context8.t3;
|
|
5009
5015
|
if (!_ret2) {
|
|
5010
|
-
|
|
5016
|
+
_context8.next = 46;
|
|
5011
5017
|
break;
|
|
5012
5018
|
}
|
|
5013
|
-
return
|
|
5019
|
+
return _context8.abrupt("return", _ret2.v);
|
|
5014
5020
|
case 46:
|
|
5015
|
-
|
|
5021
|
+
_context8.next = 41;
|
|
5016
5022
|
break;
|
|
5017
5023
|
case 48:
|
|
5018
|
-
|
|
5024
|
+
_context8.next = 16;
|
|
5019
5025
|
break;
|
|
5020
5026
|
case 50:
|
|
5021
5027
|
case "end":
|
|
5022
|
-
return
|
|
5028
|
+
return _context8.stop();
|
|
5023
5029
|
}
|
|
5024
|
-
},
|
|
5030
|
+
}, _callee6);
|
|
5025
5031
|
}));
|
|
5026
5032
|
return _executeGenericVectorSync.apply(this, arguments);
|
|
5027
5033
|
}
|
|
@@ -5029,11 +5035,11 @@ function executeVectorSync(_x3) {
|
|
|
5029
5035
|
return _executeVectorSync.apply(this, arguments);
|
|
5030
5036
|
}
|
|
5031
5037
|
function _executeVectorSync() {
|
|
5032
|
-
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5033
|
-
var _event$user3, _agent$
|
|
5034
|
-
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$
|
|
5035
|
-
return _regeneratorRuntime().wrap(function
|
|
5036
|
-
while (1) switch (
|
|
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) {
|
|
5037
5043
|
case 0:
|
|
5038
5044
|
event = _ref3.event, mastra = _ref3.mastra;
|
|
5039
5045
|
agentDir = mastra.config.agents.agentDirPath;
|
|
@@ -5044,72 +5050,72 @@ function _executeVectorSync() {
|
|
|
5044
5050
|
connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
|
|
5045
5051
|
systemName = mastra.config.name;
|
|
5046
5052
|
if (agent.knowledge_sources.vector_provider) {
|
|
5047
|
-
|
|
5053
|
+
_context11.next = 8;
|
|
5048
5054
|
break;
|
|
5049
5055
|
}
|
|
5050
5056
|
console.error("No vector_provider defined for agent");
|
|
5051
|
-
return
|
|
5057
|
+
return _context11.abrupt("return");
|
|
5052
5058
|
case 8:
|
|
5053
|
-
vp = getVectorProvider(agent == null || (_agent$
|
|
5059
|
+
vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
|
|
5054
5060
|
if (vp) {
|
|
5055
|
-
|
|
5061
|
+
_context11.next = 12;
|
|
5056
5062
|
break;
|
|
5057
5063
|
}
|
|
5058
|
-
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$
|
|
5059
|
-
return
|
|
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");
|
|
5060
5066
|
case 12:
|
|
5061
5067
|
if (process.env.OPENAI_API_KEY) {
|
|
5062
|
-
|
|
5068
|
+
_context11.next = 15;
|
|
5063
5069
|
break;
|
|
5064
5070
|
}
|
|
5065
5071
|
console.error('NO OPENAI_API_KEY');
|
|
5066
|
-
return
|
|
5072
|
+
return _context11.abrupt("return");
|
|
5067
5073
|
case 15:
|
|
5068
5074
|
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
5069
|
-
|
|
5075
|
+
_context11.next = 18;
|
|
5070
5076
|
break;
|
|
5071
5077
|
}
|
|
5072
5078
|
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
5073
|
-
return
|
|
5079
|
+
return _context11.abrupt("return");
|
|
5074
5080
|
case 18:
|
|
5075
5081
|
_iterator6 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
5076
5082
|
case 19:
|
|
5077
5083
|
if ((_step6 = _iterator6()).done) {
|
|
5078
|
-
|
|
5084
|
+
_context11.next = 53;
|
|
5079
5085
|
break;
|
|
5080
5086
|
}
|
|
5081
5087
|
vectorE = _step6.value;
|
|
5082
5088
|
integrationName = vectorE.integration;
|
|
5083
|
-
|
|
5089
|
+
_context11.next = 24;
|
|
5084
5090
|
return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
|
|
5085
5091
|
connectionId: connectionId,
|
|
5086
5092
|
name: integrationName
|
|
5087
5093
|
});
|
|
5088
5094
|
case 24:
|
|
5089
|
-
|
|
5090
|
-
if (!(
|
|
5091
|
-
|
|
5095
|
+
_context11.t1 = _yield$mastra$dataLay3 = _context11.sent;
|
|
5096
|
+
if (!(_context11.t1 == null)) {
|
|
5097
|
+
_context11.next = 29;
|
|
5092
5098
|
break;
|
|
5093
5099
|
}
|
|
5094
|
-
|
|
5095
|
-
|
|
5100
|
+
_context11.t2 = void 0;
|
|
5101
|
+
_context11.next = 30;
|
|
5096
5102
|
break;
|
|
5097
5103
|
case 29:
|
|
5098
|
-
|
|
5104
|
+
_context11.t2 = _yield$mastra$dataLay3.id;
|
|
5099
5105
|
case 30:
|
|
5100
|
-
|
|
5101
|
-
if (
|
|
5102
|
-
|
|
5106
|
+
_context11.t0 = _context11.t2;
|
|
5107
|
+
if (_context11.t0) {
|
|
5108
|
+
_context11.next = 33;
|
|
5103
5109
|
break;
|
|
5104
5110
|
}
|
|
5105
|
-
|
|
5111
|
+
_context11.t0 = '';
|
|
5106
5112
|
case 33:
|
|
5107
|
-
k_id =
|
|
5113
|
+
k_id = _context11.t0;
|
|
5108
5114
|
if (!(!k_id && integrationName === systemName)) {
|
|
5109
|
-
|
|
5115
|
+
_context11.next = 39;
|
|
5110
5116
|
break;
|
|
5111
5117
|
}
|
|
5112
|
-
|
|
5118
|
+
_context11.next = 37;
|
|
5113
5119
|
return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
|
|
5114
5120
|
connection: {
|
|
5115
5121
|
connectionId: connectionId,
|
|
@@ -5122,38 +5128,38 @@ function _executeVectorSync() {
|
|
|
5122
5128
|
}
|
|
5123
5129
|
});
|
|
5124
5130
|
case 37:
|
|
5125
|
-
connection =
|
|
5131
|
+
connection = _context11.sent;
|
|
5126
5132
|
k_id = connection.id;
|
|
5127
5133
|
case 39:
|
|
5128
5134
|
if (k_id) {
|
|
5129
|
-
|
|
5135
|
+
_context11.next = 42;
|
|
5130
5136
|
break;
|
|
5131
5137
|
}
|
|
5132
5138
|
console.error('Error bootstrapping shit');
|
|
5133
|
-
return
|
|
5139
|
+
return _context11.abrupt("return");
|
|
5134
5140
|
case 42:
|
|
5135
5141
|
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
5136
5142
|
var _mastra$dataLayer11, _entityRecords5, _records5;
|
|
5137
5143
|
var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
|
|
5138
|
-
return _regeneratorRuntime().wrap(function _loop3$(
|
|
5139
|
-
while (1) switch (
|
|
5144
|
+
return _regeneratorRuntime().wrap(function _loop3$(_context10) {
|
|
5145
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
5140
5146
|
case 0:
|
|
5141
5147
|
entity = _step7.value;
|
|
5142
|
-
|
|
5148
|
+
_context10.next = 3;
|
|
5143
5149
|
return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
|
|
5144
5150
|
k_id: k_id,
|
|
5145
5151
|
type: entity.name
|
|
5146
5152
|
});
|
|
5147
5153
|
case 3:
|
|
5148
|
-
entityRecords =
|
|
5154
|
+
entityRecords = _context10.sent;
|
|
5149
5155
|
records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
|
|
5150
5156
|
if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
|
|
5151
|
-
|
|
5157
|
+
_context10.next = 23;
|
|
5152
5158
|
break;
|
|
5153
5159
|
}
|
|
5154
5160
|
// @TODO: SYNC THEM
|
|
5155
5161
|
console.error('NO RECORDS');
|
|
5156
|
-
|
|
5162
|
+
_context10.next = 9;
|
|
5157
5163
|
return mastra.triggerEvent({
|
|
5158
5164
|
key: entity.syncEvent,
|
|
5159
5165
|
data: {},
|
|
@@ -5162,40 +5168,40 @@ function _executeVectorSync() {
|
|
|
5162
5168
|
}
|
|
5163
5169
|
});
|
|
5164
5170
|
case 9:
|
|
5165
|
-
_yield$mastra$trigger3 =
|
|
5171
|
+
_yield$mastra$trigger3 = _context10.sent;
|
|
5166
5172
|
_event3 = _yield$mastra$trigger3.event;
|
|
5167
5173
|
console.log(_event3, '####');
|
|
5168
|
-
|
|
5174
|
+
_context10.next = 14;
|
|
5169
5175
|
return _event3.subscribe();
|
|
5170
5176
|
case 14:
|
|
5171
|
-
res =
|
|
5177
|
+
res = _context10.sent;
|
|
5172
5178
|
console.log('Subscribe result', res);
|
|
5173
|
-
|
|
5179
|
+
_context10.next = 18;
|
|
5174
5180
|
return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
|
|
5175
5181
|
k_id: k_id,
|
|
5176
5182
|
type: entity.name
|
|
5177
5183
|
});
|
|
5178
5184
|
case 18:
|
|
5179
|
-
entityRecords =
|
|
5185
|
+
entityRecords = _context10.sent;
|
|
5180
5186
|
records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
|
|
5181
5187
|
if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
|
|
5182
|
-
|
|
5188
|
+
_context10.next = 23;
|
|
5183
5189
|
break;
|
|
5184
5190
|
}
|
|
5185
5191
|
console.error('NO RECORDS AFTER SYNC');
|
|
5186
|
-
return
|
|
5192
|
+
return _context10.abrupt("return", {
|
|
5187
5193
|
v: void 0
|
|
5188
5194
|
});
|
|
5189
5195
|
case 23:
|
|
5190
|
-
recordsMapped = records.map(function (
|
|
5191
|
-
var data =
|
|
5192
|
-
externalId =
|
|
5196
|
+
recordsMapped = records.map(function (_ref13) {
|
|
5197
|
+
var data = _ref13.data,
|
|
5198
|
+
externalId = _ref13.externalId;
|
|
5193
5199
|
return _extends({
|
|
5194
5200
|
id: externalId
|
|
5195
5201
|
}, _.pick(data, entity.fields));
|
|
5196
5202
|
});
|
|
5197
5203
|
console.log(recordsMapped, 'RECORDS');
|
|
5198
|
-
|
|
5204
|
+
_context10.next = 27;
|
|
5199
5205
|
return vp.createIndex({
|
|
5200
5206
|
suppressConflicts: true,
|
|
5201
5207
|
name: entity.name,
|
|
@@ -5211,88 +5217,88 @@ function _executeVectorSync() {
|
|
|
5211
5217
|
case 27:
|
|
5212
5218
|
entityTypeIndex = vp.index(entity.name);
|
|
5213
5219
|
console.log(entityTypeIndex, 'INDEX');
|
|
5214
|
-
|
|
5215
|
-
|
|
5220
|
+
_context10.prev = 29;
|
|
5221
|
+
_context10.next = 32;
|
|
5216
5222
|
return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
|
|
5217
|
-
var
|
|
5223
|
+
var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(record) {
|
|
5218
5224
|
var _yield$embed3, embedding;
|
|
5219
|
-
return _regeneratorRuntime().wrap(function
|
|
5220
|
-
while (1) switch (
|
|
5225
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context9) {
|
|
5226
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
5221
5227
|
case 0:
|
|
5222
|
-
|
|
5228
|
+
_context9.next = 2;
|
|
5223
5229
|
return ai.embed({
|
|
5224
5230
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
5225
5231
|
value: JSON.stringify(record)
|
|
5226
5232
|
});
|
|
5227
5233
|
case 2:
|
|
5228
|
-
_yield$embed3 =
|
|
5234
|
+
_yield$embed3 = _context9.sent;
|
|
5229
5235
|
embedding = _yield$embed3.embedding;
|
|
5230
|
-
return
|
|
5236
|
+
return _context9.abrupt("return", {
|
|
5231
5237
|
id: record.id,
|
|
5232
5238
|
values: embedding,
|
|
5233
5239
|
metadata: record
|
|
5234
5240
|
});
|
|
5235
5241
|
case 5:
|
|
5236
5242
|
case "end":
|
|
5237
|
-
return
|
|
5243
|
+
return _context9.stop();
|
|
5238
5244
|
}
|
|
5239
|
-
},
|
|
5245
|
+
}, _callee7);
|
|
5240
5246
|
}));
|
|
5241
|
-
return function (
|
|
5242
|
-
return
|
|
5247
|
+
return function (_x9) {
|
|
5248
|
+
return _ref14.apply(this, arguments);
|
|
5243
5249
|
};
|
|
5244
5250
|
}())) != null ? _recordsMapped$map3 : []);
|
|
5245
5251
|
case 32:
|
|
5246
|
-
vectors =
|
|
5252
|
+
vectors = _context10.sent;
|
|
5247
5253
|
console.log('UPSERTING', vectors);
|
|
5248
5254
|
if (!(vectors.length > 0)) {
|
|
5249
|
-
|
|
5255
|
+
_context10.next = 37;
|
|
5250
5256
|
break;
|
|
5251
5257
|
}
|
|
5252
|
-
|
|
5258
|
+
_context10.next = 37;
|
|
5253
5259
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
5254
5260
|
case 37:
|
|
5255
|
-
|
|
5261
|
+
_context10.next = 42;
|
|
5256
5262
|
break;
|
|
5257
5263
|
case 39:
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
console.error(
|
|
5264
|
+
_context10.prev = 39;
|
|
5265
|
+
_context10.t0 = _context10["catch"](29);
|
|
5266
|
+
console.error(_context10.t0);
|
|
5261
5267
|
case 42:
|
|
5262
|
-
return
|
|
5268
|
+
return _context10.abrupt("return", {
|
|
5263
5269
|
v: void 0
|
|
5264
5270
|
});
|
|
5265
5271
|
case 43:
|
|
5266
5272
|
case "end":
|
|
5267
|
-
return
|
|
5273
|
+
return _context10.stop();
|
|
5268
5274
|
}
|
|
5269
5275
|
}, _loop3, null, [[29, 39]]);
|
|
5270
5276
|
});
|
|
5271
5277
|
_iterator7 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5272
5278
|
case 44:
|
|
5273
5279
|
if ((_step7 = _iterator7()).done) {
|
|
5274
|
-
|
|
5280
|
+
_context11.next = 51;
|
|
5275
5281
|
break;
|
|
5276
5282
|
}
|
|
5277
|
-
return
|
|
5283
|
+
return _context11.delegateYield(_loop3(), "t3", 46);
|
|
5278
5284
|
case 46:
|
|
5279
|
-
_ret3 =
|
|
5285
|
+
_ret3 = _context11.t3;
|
|
5280
5286
|
if (!_ret3) {
|
|
5281
|
-
|
|
5287
|
+
_context11.next = 49;
|
|
5282
5288
|
break;
|
|
5283
5289
|
}
|
|
5284
|
-
return
|
|
5290
|
+
return _context11.abrupt("return", _ret3.v);
|
|
5285
5291
|
case 49:
|
|
5286
|
-
|
|
5292
|
+
_context11.next = 44;
|
|
5287
5293
|
break;
|
|
5288
5294
|
case 51:
|
|
5289
|
-
|
|
5295
|
+
_context11.next = 19;
|
|
5290
5296
|
break;
|
|
5291
5297
|
case 53:
|
|
5292
5298
|
case "end":
|
|
5293
|
-
return
|
|
5299
|
+
return _context11.stop();
|
|
5294
5300
|
}
|
|
5295
|
-
},
|
|
5301
|
+
}, _callee8);
|
|
5296
5302
|
}));
|
|
5297
5303
|
return _executeVectorSync.apply(this, arguments);
|
|
5298
5304
|
}
|
|
@@ -5300,118 +5306,285 @@ function vectorQueryEngine(_x4) {
|
|
|
5300
5306
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5301
5307
|
}
|
|
5302
5308
|
function _vectorQueryEngine() {
|
|
5303
|
-
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5309
|
+
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref4) {
|
|
5304
5310
|
var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
|
|
5305
|
-
return _regeneratorRuntime().wrap(function
|
|
5306
|
-
while (1) switch (
|
|
5311
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context12) {
|
|
5312
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
5307
5313
|
case 0:
|
|
5308
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;
|
|
5309
5315
|
vp = getVectorProvider(vector_provider);
|
|
5310
5316
|
if (vp) {
|
|
5311
|
-
|
|
5317
|
+
_context12.next = 5;
|
|
5312
5318
|
break;
|
|
5313
5319
|
}
|
|
5314
5320
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
5315
|
-
return
|
|
5321
|
+
return _context12.abrupt("return");
|
|
5316
5322
|
case 5:
|
|
5317
5323
|
index = vp.index(indexName);
|
|
5318
|
-
|
|
5324
|
+
_context12.next = 8;
|
|
5319
5325
|
return ai.embed({
|
|
5320
5326
|
model: openai.openai.embedding('text-embedding-3-small'),
|
|
5321
5327
|
value: content
|
|
5322
5328
|
});
|
|
5323
5329
|
case 8:
|
|
5324
|
-
_yield$embed4 =
|
|
5330
|
+
_yield$embed4 = _context12.sent;
|
|
5325
5331
|
embedding = _yield$embed4.embedding;
|
|
5326
5332
|
console.log(embedding, 'EMBEDDING');
|
|
5327
|
-
|
|
5333
|
+
_context12.next = 13;
|
|
5328
5334
|
return index.namespace(entityType).query({
|
|
5329
5335
|
vector: embedding,
|
|
5330
5336
|
topK: topK,
|
|
5331
5337
|
includeMetadata: true
|
|
5332
5338
|
});
|
|
5333
5339
|
case 13:
|
|
5334
|
-
queryResponse =
|
|
5335
|
-
return
|
|
5340
|
+
queryResponse = _context12.sent;
|
|
5341
|
+
return _context12.abrupt("return", queryResponse);
|
|
5336
5342
|
case 15:
|
|
5337
5343
|
case "end":
|
|
5338
|
-
return
|
|
5344
|
+
return _context12.stop();
|
|
5339
5345
|
}
|
|
5340
|
-
},
|
|
5346
|
+
}, _callee9);
|
|
5341
5347
|
}));
|
|
5342
5348
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5343
5349
|
}
|
|
5344
|
-
function
|
|
5345
|
-
var
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
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);
|
|
5415
5588
|
}
|
|
5416
5589
|
function agentVectorSyncEvent() {
|
|
5417
5590
|
return {
|
|
@@ -5444,11 +5617,14 @@ function getAgentSystemApis(_ref) {
|
|
|
5444
5617
|
agentDir: agentDir
|
|
5445
5618
|
});
|
|
5446
5619
|
// Remove the .json extension from the agent names
|
|
5447
|
-
var agentList =
|
|
5448
|
-
|
|
5449
|
-
|
|
5620
|
+
var agentList = [];
|
|
5621
|
+
if (agents) {
|
|
5622
|
+
agentList = agents.map(function (agent) {
|
|
5623
|
+
return agent.slice(0, -5);
|
|
5624
|
+
});
|
|
5625
|
+
}
|
|
5450
5626
|
return [{
|
|
5451
|
-
integrationName:
|
|
5627
|
+
integrationName: mastra.config.name,
|
|
5452
5628
|
type: 'message_agent',
|
|
5453
5629
|
label: 'Send Message To Agent',
|
|
5454
5630
|
description: 'Sends a message to an Agent',
|
|
@@ -5461,55 +5637,58 @@ function getAgentSystemApis(_ref) {
|
|
|
5461
5637
|
}),
|
|
5462
5638
|
executor: function () {
|
|
5463
5639
|
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5464
|
-
var data, executor, result, _run$content, thread, run;
|
|
5640
|
+
var data, ctx, executor, result, _run$content, thread, run;
|
|
5465
5641
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5466
5642
|
while (1) switch (_context.prev = _context.next) {
|
|
5467
5643
|
case 0:
|
|
5468
|
-
data = _ref2.data;
|
|
5644
|
+
data = _ref2.data, ctx = _ref2.ctx;
|
|
5469
5645
|
_context.next = 3;
|
|
5470
5646
|
return mastra.getAgent({
|
|
5471
5647
|
agentId: data.agentId,
|
|
5472
|
-
connectionId:
|
|
5648
|
+
connectionId: ctx.connectionId
|
|
5473
5649
|
});
|
|
5474
5650
|
case 3:
|
|
5475
5651
|
executor = _context.sent;
|
|
5652
|
+
console.log('executor====', {
|
|
5653
|
+
executor: executor
|
|
5654
|
+
});
|
|
5476
5655
|
if (executor) {
|
|
5477
|
-
_context.next =
|
|
5656
|
+
_context.next = 7;
|
|
5478
5657
|
break;
|
|
5479
5658
|
}
|
|
5480
5659
|
throw new Error('Could not create agent executor');
|
|
5481
|
-
case
|
|
5660
|
+
case 7:
|
|
5482
5661
|
if (!(typeof executor === 'function')) {
|
|
5483
|
-
_context.next =
|
|
5662
|
+
_context.next = 14;
|
|
5484
5663
|
break;
|
|
5485
5664
|
}
|
|
5486
|
-
_context.next =
|
|
5665
|
+
_context.next = 10;
|
|
5487
5666
|
return executor({
|
|
5488
5667
|
prompt: data == null ? void 0 : data.message
|
|
5489
5668
|
});
|
|
5490
|
-
case
|
|
5669
|
+
case 10:
|
|
5491
5670
|
result = _context.sent;
|
|
5492
5671
|
return _context.abrupt("return", {
|
|
5493
5672
|
message: result == null ? void 0 : result.text
|
|
5494
5673
|
});
|
|
5495
|
-
case
|
|
5496
|
-
_context.next =
|
|
5674
|
+
case 14:
|
|
5675
|
+
_context.next = 16;
|
|
5497
5676
|
return executor.initializeThread([{
|
|
5498
5677
|
role: 'user',
|
|
5499
5678
|
content: data == null ? void 0 : data.message
|
|
5500
5679
|
}]);
|
|
5501
|
-
case
|
|
5680
|
+
case 16:
|
|
5502
5681
|
thread = _context.sent;
|
|
5503
|
-
_context.next =
|
|
5682
|
+
_context.next = 19;
|
|
5504
5683
|
return executor.watchRun({
|
|
5505
5684
|
threadId: thread.id
|
|
5506
5685
|
});
|
|
5507
|
-
case
|
|
5686
|
+
case 19:
|
|
5508
5687
|
run = _context.sent;
|
|
5509
5688
|
return _context.abrupt("return", {
|
|
5510
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
|
|
5511
5690
|
});
|
|
5512
|
-
case
|
|
5691
|
+
case 21:
|
|
5513
5692
|
case "end":
|
|
5514
5693
|
return _context.stop();
|
|
5515
5694
|
}
|
|
@@ -5523,427 +5702,502 @@ function getAgentSystemApis(_ref) {
|
|
|
5523
5702
|
}];
|
|
5524
5703
|
}
|
|
5525
5704
|
|
|
5526
|
-
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
5527
|
-
function createFileLogger(_ref) {
|
|
5528
|
-
var destinationPath = _ref.destinationPath;
|
|
5529
|
-
var fullPath = path.join(loggerPath, destinationPath);
|
|
5530
|
-
return function (log) {
|
|
5531
|
-
if (!fs.existsSync(loggerPath)) {
|
|
5532
|
-
fs.mkdirSync(loggerPath, {
|
|
5533
|
-
recursive: true
|
|
5534
|
-
});
|
|
5535
|
-
return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
5536
|
-
createdAt: new Date()
|
|
5537
|
-
})], null, 2));
|
|
5538
|
-
}
|
|
5539
|
-
var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
5540
|
-
logs.push(_extends({}, log, {
|
|
5541
|
-
createdAt: new Date()
|
|
5542
|
-
}));
|
|
5543
|
-
return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
5544
|
-
};
|
|
5545
|
-
}
|
|
5546
|
-
|
|
5547
5705
|
var client;
|
|
5548
5706
|
if (process.env.OPENAI_API_KEY) {
|
|
5549
5707
|
client = /*#__PURE__*/new OpenAI({
|
|
5550
5708
|
apiKey: process.env.OPENAI_API_KEY
|
|
5551
5709
|
});
|
|
5552
5710
|
}
|
|
5553
|
-
function
|
|
5554
|
-
return
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
_context3.next = 4;
|
|
5582
|
-
return client.beta.threads.messages.list(threadId);
|
|
5583
|
-
case 4:
|
|
5584
|
-
messages = _context3.sent;
|
|
5585
|
-
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5586
|
-
case 8:
|
|
5587
|
-
if (!(run.status === 'requires_action')) {
|
|
5588
|
-
_context3.next = 14;
|
|
5589
|
-
break;
|
|
5590
|
-
}
|
|
5591
|
-
_context3.next = 11;
|
|
5592
|
-
return handleRequiresAction({
|
|
5593
|
-
run: run,
|
|
5594
|
-
threadId: threadId
|
|
5595
|
-
});
|
|
5596
|
-
case 11:
|
|
5597
|
-
return _context3.abrupt("return", _context3.sent);
|
|
5598
|
-
case 14:
|
|
5599
|
-
console.error('Run did not complete:', run);
|
|
5600
|
-
logger({
|
|
5601
|
-
statusCode: 400,
|
|
5602
|
-
message: JSON.stringify({
|
|
5603
|
-
message: "Run did not complete",
|
|
5604
|
-
event_type: 'run_error',
|
|
5605
|
-
metadata: {
|
|
5606
|
-
run: run
|
|
5607
|
-
}
|
|
5608
|
-
}, null, 2)
|
|
5609
|
-
});
|
|
5610
|
-
case 16:
|
|
5611
|
-
case "end":
|
|
5612
|
-
return _context3.stop();
|
|
5613
|
-
}
|
|
5614
|
-
}, _callee3);
|
|
5615
|
-
}));
|
|
5616
|
-
return function handleRunStatus(_x4) {
|
|
5617
|
-
return _ref5.apply(this, arguments);
|
|
5618
|
-
};
|
|
5619
|
-
}();
|
|
5620
|
-
handleRequiresAction = /*#__PURE__*/function () {
|
|
5621
|
-
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5622
|
-
var threadId, run, toolOutputs;
|
|
5623
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5624
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
5625
|
-
case 0:
|
|
5626
|
-
threadId = _ref6.threadId, run = _ref6.run;
|
|
5627
|
-
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5628
|
-
_context5.next = 23;
|
|
5629
|
-
break;
|
|
5630
|
-
}
|
|
5631
|
-
_context5.t0 = _.compact;
|
|
5632
|
-
_context5.next = 5;
|
|
5633
|
-
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5634
|
-
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5635
|
-
var callInfo, toolMetadata, toolFn, args, output;
|
|
5636
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5637
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
5638
|
-
case 0:
|
|
5639
|
-
callInfo = index + 1 + " of " + tools.length;
|
|
5640
|
-
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5641
|
-
toolMetadata = {
|
|
5642
|
-
id: tool.id,
|
|
5643
|
-
fn: tool["function"].name,
|
|
5644
|
-
availableTools: Object.keys(toolMap)
|
|
5645
|
-
};
|
|
5646
|
-
logger({
|
|
5647
|
-
statusCode: 100,
|
|
5648
|
-
message: JSON.stringify({
|
|
5649
|
-
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5650
|
-
metadata: {
|
|
5651
|
-
tool: toolMetadata
|
|
5652
|
-
}
|
|
5653
|
-
}, null, 2)
|
|
5654
|
-
});
|
|
5655
|
-
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5656
|
-
if (toolFn) {
|
|
5657
|
-
_context4.next = 8;
|
|
5658
|
-
break;
|
|
5659
|
-
}
|
|
5660
|
-
logger({
|
|
5661
|
-
statusCode: 404,
|
|
5662
|
-
message: JSON.stringify({
|
|
5663
|
-
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5664
|
-
metadata: {
|
|
5665
|
-
tool: toolMetadata
|
|
5666
|
-
}
|
|
5667
|
-
}, null, 2)
|
|
5668
|
-
});
|
|
5669
|
-
return _context4.abrupt("return");
|
|
5670
|
-
case 8:
|
|
5671
|
-
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5672
|
-
args = {};
|
|
5673
|
-
try {
|
|
5674
|
-
if (tool["function"].arguments) {
|
|
5675
|
-
args = JSON.parse(tool["function"].arguments);
|
|
5676
|
-
logger({
|
|
5677
|
-
statusCode: 100,
|
|
5678
|
-
message: JSON.stringify({
|
|
5679
|
-
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5680
|
-
metadata: {
|
|
5681
|
-
args: args,
|
|
5682
|
-
tool: toolMetadata
|
|
5683
|
-
}
|
|
5684
|
-
}, null, 2)
|
|
5685
|
-
});
|
|
5686
|
-
}
|
|
5687
|
-
} catch (e) {
|
|
5688
|
-
console.error(e);
|
|
5689
|
-
}
|
|
5690
|
-
_context4.next = 13;
|
|
5691
|
-
return toolFn(args);
|
|
5692
|
-
case 13:
|
|
5693
|
-
output = _context4.sent;
|
|
5694
|
-
logger({
|
|
5695
|
-
statusCode: 200,
|
|
5696
|
-
message: JSON.stringify({
|
|
5697
|
-
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5698
|
-
metadata: {
|
|
5699
|
-
output: output,
|
|
5700
|
-
tool: toolMetadata
|
|
5701
|
-
}
|
|
5702
|
-
}, null, 2)
|
|
5703
|
-
});
|
|
5704
|
-
return _context4.abrupt("return", {
|
|
5705
|
-
tool_call_id: tool.id,
|
|
5706
|
-
output: JSON.stringify(output)
|
|
5707
|
-
});
|
|
5708
|
-
case 16:
|
|
5709
|
-
case "end":
|
|
5710
|
-
return _context4.stop();
|
|
5711
|
-
}
|
|
5712
|
-
}, _callee4);
|
|
5713
|
-
}));
|
|
5714
|
-
return function (_x6, _x7, _x8) {
|
|
5715
|
-
return _ref8.apply(this, arguments);
|
|
5716
|
-
};
|
|
5717
|
-
}()));
|
|
5718
|
-
case 5:
|
|
5719
|
-
_context5.t1 = _context5.sent;
|
|
5720
|
-
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5721
|
-
if (toolOutputs) {
|
|
5722
|
-
_context5.next = 11;
|
|
5723
|
-
break;
|
|
5724
|
-
}
|
|
5725
|
-
console.error('No tool outputs to submit.');
|
|
5726
|
-
logger({
|
|
5727
|
-
statusCode: 404,
|
|
5728
|
-
message: JSON.stringify({
|
|
5729
|
-
message: "No tool outputs submitted",
|
|
5730
|
-
metadata: {}
|
|
5731
|
-
}, null, 2)
|
|
5732
|
-
});
|
|
5733
|
-
return _context5.abrupt("return", handleRunStatus({
|
|
5734
|
-
threadId: threadId,
|
|
5735
|
-
run: run
|
|
5736
|
-
}));
|
|
5737
|
-
case 11:
|
|
5738
|
-
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5739
|
-
_context5.next = 20;
|
|
5740
|
-
break;
|
|
5741
|
-
}
|
|
5742
|
-
console.log(toolOutputs, '###### YOOOOOO');
|
|
5743
|
-
_context5.next = 15;
|
|
5744
|
-
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5745
|
-
tool_outputs: toolOutputs
|
|
5746
|
-
});
|
|
5747
|
-
case 15:
|
|
5748
|
-
run = _context5.sent;
|
|
5749
|
-
logger({
|
|
5750
|
-
statusCode: 200,
|
|
5751
|
-
message: JSON.stringify({
|
|
5752
|
-
message: "Tool outputs submitted",
|
|
5753
|
-
metadata: {
|
|
5754
|
-
run: run
|
|
5755
|
-
}
|
|
5756
|
-
}, null, 2)
|
|
5757
|
-
});
|
|
5758
|
-
console.log('Tool outputs submitted successfully.');
|
|
5759
|
-
_context5.next = 22;
|
|
5760
|
-
break;
|
|
5761
|
-
case 20:
|
|
5762
|
-
logger({
|
|
5763
|
-
statusCode: 404,
|
|
5764
|
-
message: JSON.stringify({
|
|
5765
|
-
message: "No tool outputs to submit",
|
|
5766
|
-
metadata: {}
|
|
5767
|
-
}, null, 2)
|
|
5768
|
-
});
|
|
5769
|
-
console.log('No tool outputs to submit.');
|
|
5770
|
-
case 22:
|
|
5771
|
-
return _context5.abrupt("return", handleRunStatus({
|
|
5772
|
-
threadId: threadId,
|
|
5773
|
-
run: run
|
|
5774
|
-
}));
|
|
5775
|
-
case 23:
|
|
5776
|
-
case "end":
|
|
5777
|
-
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
|
|
5778
5739
|
}
|
|
5779
|
-
},
|
|
5780
|
-
})
|
|
5781
|
-
return
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
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
|
|
5799
5784
|
}
|
|
5800
|
-
},
|
|
5801
|
-
})
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
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) {
|
|
5812
5816
|
case 0:
|
|
5813
|
-
|
|
5814
|
-
|
|
5817
|
+
threadId = _ref4.threadId, run = _ref4.run;
|
|
5818
|
+
if (!(run.status === 'completed')) {
|
|
5819
|
+
_context3.next = 8;
|
|
5820
|
+
break;
|
|
5815
5821
|
}
|
|
5816
|
-
|
|
5817
|
-
return client.beta.threads.create({
|
|
5818
|
-
messages: messages
|
|
5819
|
-
});
|
|
5820
|
-
case 3:
|
|
5821
|
-
return _context7.abrupt("return", _context7.sent);
|
|
5822
|
-
case 4:
|
|
5823
|
-
case "end":
|
|
5824
|
-
return _context7.stop();
|
|
5825
|
-
}
|
|
5826
|
-
}, _callee7);
|
|
5827
|
-
}));
|
|
5828
|
-
function initializeThread(_x10) {
|
|
5829
|
-
return _initializeThread.apply(this, arguments);
|
|
5830
|
-
}
|
|
5831
|
-
return initializeThread;
|
|
5832
|
-
}(),
|
|
5833
|
-
listMessages: function () {
|
|
5834
|
-
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
5835
|
-
var threadId;
|
|
5836
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5837
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
5838
|
-
case 0:
|
|
5839
|
-
threadId = _ref11.threadId;
|
|
5840
|
-
_context8.next = 3;
|
|
5822
|
+
_context3.next = 4;
|
|
5841
5823
|
return client.beta.threads.messages.list(threadId);
|
|
5842
|
-
case 3:
|
|
5843
|
-
return _context8.abrupt("return", _context8.sent);
|
|
5844
5824
|
case 4:
|
|
5845
|
-
|
|
5846
|
-
return
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
handleRunStatus: handleRunStatus,
|
|
5857
|
-
handleRequiresAction: handleRequiresAction,
|
|
5858
|
-
createUserMessage: function () {
|
|
5859
|
-
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
5860
|
-
var threadId, content;
|
|
5861
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
5862
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
5863
|
-
case 0:
|
|
5864
|
-
threadId = _ref12.threadId, content = _ref12.content;
|
|
5865
|
-
_context9.next = 3;
|
|
5866
|
-
return client.beta.threads.messages.create(threadId, {
|
|
5867
|
-
role: 'user',
|
|
5868
|
-
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
|
|
5869
5836
|
});
|
|
5870
|
-
case
|
|
5871
|
-
return
|
|
5872
|
-
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:
|
|
5873
5853
|
case "end":
|
|
5874
|
-
return
|
|
5854
|
+
return _context3.stop();
|
|
5875
5855
|
}
|
|
5876
|
-
},
|
|
5856
|
+
}, _callee3);
|
|
5877
5857
|
}));
|
|
5878
|
-
function
|
|
5879
|
-
return
|
|
5880
|
-
}
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
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) {
|
|
5888
5867
|
case 0:
|
|
5889
|
-
|
|
5890
|
-
if (!
|
|
5891
|
-
|
|
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;
|
|
5892
5871
|
break;
|
|
5893
5872
|
}
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
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)
|
|
5898
5979
|
});
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
case
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
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
|
|
5908
5993
|
});
|
|
5909
|
-
case
|
|
5910
|
-
run =
|
|
5994
|
+
case 15:
|
|
5995
|
+
run = _context5.sent;
|
|
5911
5996
|
logger({
|
|
5912
|
-
|
|
5997
|
+
destinationPath: id + ".json",
|
|
5998
|
+
statusCode: 200,
|
|
5913
5999
|
message: JSON.stringify({
|
|
5914
|
-
message: "
|
|
6000
|
+
message: "Tool outputs submitted",
|
|
5915
6001
|
metadata: {
|
|
5916
|
-
run: run
|
|
5917
|
-
tool_choice: 'required',
|
|
5918
|
-
threadId: threadId,
|
|
5919
|
-
assistant_id: id
|
|
6002
|
+
run: run
|
|
5920
6003
|
}
|
|
5921
6004
|
}, null, 2)
|
|
5922
6005
|
});
|
|
5923
|
-
|
|
5924
|
-
|
|
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({
|
|
5925
6021
|
threadId: threadId,
|
|
5926
6022
|
run: run
|
|
5927
6023
|
}));
|
|
5928
|
-
case
|
|
6024
|
+
case 23:
|
|
5929
6025
|
case "end":
|
|
5930
|
-
return
|
|
6026
|
+
return _context5.stop();
|
|
5931
6027
|
}
|
|
5932
|
-
},
|
|
6028
|
+
}, _callee5);
|
|
5933
6029
|
}));
|
|
5934
|
-
function
|
|
5935
|
-
return
|
|
5936
|
-
}
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
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:
|
|
6046
|
+
case "end":
|
|
6047
|
+
return _context6.stop();
|
|
6048
|
+
}
|
|
6049
|
+
}, _callee6);
|
|
6050
|
+
}));
|
|
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
|
+
}();
|
|
5947
6201
|
}
|
|
5948
6202
|
|
|
5949
6203
|
var delay = function delay(ms) {
|
|
@@ -6170,20 +6424,24 @@ function getAgent(_x) {
|
|
|
6170
6424
|
}
|
|
6171
6425
|
function _getAgent() {
|
|
6172
6426
|
_getAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
6173
|
-
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;
|
|
6174
6429
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
6175
6430
|
while (1) switch (_context3.prev = _context3.next) {
|
|
6176
6431
|
case 0:
|
|
6177
|
-
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis;
|
|
6178
|
-
|
|
6179
|
-
|
|
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;
|
|
6180
6436
|
break;
|
|
6181
6437
|
}
|
|
6438
|
+
console.log('===in the model if block===');
|
|
6182
6439
|
tools = Object.keys(agent.tools);
|
|
6183
6440
|
toolMap = Object.entries(apis).reduce(function (memo, _ref2) {
|
|
6184
6441
|
var k = _ref2[0],
|
|
6185
6442
|
def = _ref2[1];
|
|
6186
6443
|
if (tools.includes(k)) {
|
|
6444
|
+
console.log(k + " tool included, run executorx====");
|
|
6187
6445
|
memo[k] = /*#__PURE__*/function () {
|
|
6188
6446
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
6189
6447
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -6208,17 +6466,21 @@ function _getAgent() {
|
|
|
6208
6466
|
}
|
|
6209
6467
|
return memo;
|
|
6210
6468
|
}, {});
|
|
6211
|
-
|
|
6469
|
+
console.log('toolmap====', JSON.stringify(toolMap, null, 2));
|
|
6470
|
+
getAssistantAgent = getAssistantAgentHandler(logger);
|
|
6471
|
+
_context3.next = 10;
|
|
6212
6472
|
return getAssistantAgent({
|
|
6213
6473
|
id: agent.id,
|
|
6214
|
-
toolMap: toolMap
|
|
6474
|
+
toolMap: toolMap,
|
|
6475
|
+
tool_choice: agent.model.toolChoice
|
|
6215
6476
|
});
|
|
6216
|
-
case
|
|
6477
|
+
case 10:
|
|
6217
6478
|
assistant = _context3.sent;
|
|
6479
|
+
console.log('got assistant===', assistant);
|
|
6218
6480
|
return _context3.abrupt("return", assistant);
|
|
6219
|
-
case
|
|
6220
|
-
if (!['OPEN_AI_VERCEL', 'ANTHROPIC_VERCEL', 'GROQ_VERCEL', 'PERPLEXITY_VERCEL', 'FIREWORKS_VERCEL'].includes(agent.model.provider)) {
|
|
6221
|
-
_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;
|
|
6222
6484
|
break;
|
|
6223
6485
|
}
|
|
6224
6486
|
keyToModel = {
|
|
@@ -6285,7 +6547,7 @@ function _getAgent() {
|
|
|
6285
6547
|
};
|
|
6286
6548
|
}
|
|
6287
6549
|
if (!(agent.model.generation_type === 'stream')) {
|
|
6288
|
-
_context3.next =
|
|
6550
|
+
_context3.next = 23;
|
|
6289
6551
|
break;
|
|
6290
6552
|
}
|
|
6291
6553
|
return _context3.abrupt("return", createStreamAgent({
|
|
@@ -6298,7 +6560,7 @@ function _getAgent() {
|
|
|
6298
6560
|
tools: _toolMap,
|
|
6299
6561
|
resultTool: resultTool
|
|
6300
6562
|
}));
|
|
6301
|
-
case
|
|
6563
|
+
case 23:
|
|
6302
6564
|
return _context3.abrupt("return", createAgent({
|
|
6303
6565
|
agent_instructions: agent.agent_instructions,
|
|
6304
6566
|
model: {
|
|
@@ -6309,7 +6571,7 @@ function _getAgent() {
|
|
|
6309
6571
|
tools: _toolMap,
|
|
6310
6572
|
resultTool: resultTool
|
|
6311
6573
|
}));
|
|
6312
|
-
case
|
|
6574
|
+
case 24:
|
|
6313
6575
|
case "end":
|
|
6314
6576
|
return _context3.stop();
|
|
6315
6577
|
}
|
|
@@ -6318,6 +6580,67 @@ function _getAgent() {
|
|
|
6318
6580
|
return _getAgent.apply(this, arguments);
|
|
6319
6581
|
}
|
|
6320
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
|
+
|
|
6321
6644
|
var Mastra = /*#__PURE__*/function () {
|
|
6322
6645
|
function Mastra(_ref) {
|
|
6323
6646
|
var _this = this;
|
|
@@ -6335,6 +6658,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6335
6658
|
agentDirPath: '',
|
|
6336
6659
|
vectorProvider: []
|
|
6337
6660
|
};
|
|
6661
|
+
this.logger = void 0;
|
|
6338
6662
|
this.config = void 0;
|
|
6339
6663
|
this.runBlueprint = /*#__PURE__*/function () {
|
|
6340
6664
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
@@ -6385,7 +6709,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6385
6709
|
this.config = config;
|
|
6386
6710
|
}
|
|
6387
6711
|
Mastra.init = function init(config) {
|
|
6388
|
-
var _config$workflows$sys;
|
|
6712
|
+
var _config$logs, _config$logs2, _config$workflows$sys;
|
|
6389
6713
|
if (!config.db.uri) {
|
|
6390
6714
|
throw new Error('No database config/provider found');
|
|
6391
6715
|
}
|
|
@@ -6399,6 +6723,19 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6399
6723
|
dataLayer: dataLayer,
|
|
6400
6724
|
vectorLayer: vectorLayer
|
|
6401
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);
|
|
6402
6739
|
// Register integrations
|
|
6403
6740
|
config.integrations.forEach(function (integration) {
|
|
6404
6741
|
framework.__registerIntgeration(integration);
|
|
@@ -6411,8 +6748,6 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6411
6748
|
return _extends({}, api, {
|
|
6412
6749
|
integrationName: config.name
|
|
6413
6750
|
});
|
|
6414
|
-
}), getVectorQueryApis({
|
|
6415
|
-
mastra: framework
|
|
6416
6751
|
}), [{
|
|
6417
6752
|
integrationName: config.name,
|
|
6418
6753
|
type: 'trigger_event',
|
|
@@ -6467,6 +6802,15 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6467
6802
|
}()
|
|
6468
6803
|
}])
|
|
6469
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);
|
|
6813
|
+
});
|
|
6470
6814
|
// Register System events
|
|
6471
6815
|
framework.__registerEvents({
|
|
6472
6816
|
events: config.workflows.systemEvents
|
|
@@ -6518,6 +6862,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6518
6862
|
return framework;
|
|
6519
6863
|
};
|
|
6520
6864
|
var _proto = Mastra.prototype;
|
|
6865
|
+
_proto.attachLogger = function attachLogger(logger) {
|
|
6866
|
+
this.logger = logger;
|
|
6867
|
+
};
|
|
6521
6868
|
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
6522
6869
|
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref8) {
|
|
6523
6870
|
var _this2 = this;
|
|
@@ -7263,12 +7610,14 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7263
7610
|
var v = _ref30[1];
|
|
7264
7611
|
return _extends({}, acc, v);
|
|
7265
7612
|
}, {});
|
|
7613
|
+
console.log('got finalApis===');
|
|
7266
7614
|
return _context15.abrupt("return", getAgent({
|
|
7267
7615
|
connectionId: connectionId,
|
|
7268
7616
|
agent: agentBlueprint,
|
|
7269
|
-
apis: finalApis
|
|
7617
|
+
apis: finalApis,
|
|
7618
|
+
logger: this.logger
|
|
7270
7619
|
}));
|
|
7271
|
-
case
|
|
7620
|
+
case 8:
|
|
7272
7621
|
case "end":
|
|
7273
7622
|
return _context15.stop();
|
|
7274
7623
|
}
|
|
@@ -7296,6 +7645,15 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7296
7645
|
return _extends({}, acc, (_extends5 = {}, _extends5[key] = "" + _this5.config.routeRegistrationPath + value, _extends5));
|
|
7297
7646
|
}, {});
|
|
7298
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
|
+
}
|
|
7299
7657
|
}]);
|
|
7300
7658
|
}();
|
|
7301
7659
|
|
|
@@ -7329,6 +7687,7 @@ exports.getEntityKey = getEntityKey;
|
|
|
7329
7687
|
exports.getJSONField = getJSONField;
|
|
7330
7688
|
exports.getPath = getPath;
|
|
7331
7689
|
exports.getResponseDataKey = getResponseDataKey;
|
|
7690
|
+
exports.getUpstashLogs = getUpstashLogs;
|
|
7332
7691
|
exports.isLiteralObject = isLiteralObject;
|
|
7333
7692
|
exports.isObjectEmpty = isObjectEmpty;
|
|
7334
7693
|
exports.mergeWithDefinedOnly = mergeWithDefinedOnly;
|