@mastra/core 0.1.9 → 0.1.11
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 +6 -3
- package/dist/agents/utils.d.ts.map +1 -1
- package/dist/agents/vector-sync.d.ts +18 -24
- package/dist/agents/vector-sync.d.ts.map +1 -1
- package/dist/core.cjs.development.js +1112 -774
- 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 +1111 -775
- 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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/core.esm.js
CHANGED
|
@@ -22,6 +22,7 @@ import { embed, tool, generateText, streamText } from 'ai';
|
|
|
22
22
|
import { Pinecone } from '@pinecone-database/pinecone';
|
|
23
23
|
import OpenAI from 'openai';
|
|
24
24
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
25
|
+
import { Redis } from '@upstash/redis';
|
|
25
26
|
|
|
26
27
|
var WorkflowStatusEnum = {
|
|
27
28
|
DRAFT: 'DRAFT',
|
|
@@ -4233,18 +4234,23 @@ function _blueprintRunner() {
|
|
|
4233
4234
|
return _blueprintRunner.apply(this, arguments);
|
|
4234
4235
|
}
|
|
4235
4236
|
|
|
4236
|
-
function
|
|
4237
|
-
var
|
|
4237
|
+
function getProjectDir(_ref) {
|
|
4238
|
+
var dir = _ref.dir;
|
|
4238
4239
|
var ARK_APP_DIR = process.env.ARK_APP_DIR || process.cwd();
|
|
4239
|
-
return path.join(ARK_APP_DIR,
|
|
4240
|
+
return path.join(ARK_APP_DIR, dir);
|
|
4240
4241
|
}
|
|
4241
4242
|
function listAgentsJson(_ref2) {
|
|
4242
4243
|
var agentDir = _ref2.agentDir;
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4244
|
+
try {
|
|
4245
|
+
var agentDirPath = getProjectDir({
|
|
4246
|
+
dir: agentDir
|
|
4247
|
+
});
|
|
4248
|
+
var agents = readdirSync(agentDirPath);
|
|
4249
|
+
return agents;
|
|
4250
|
+
} catch (e) {
|
|
4251
|
+
console.error('No agent directory found:', agentDir);
|
|
4252
|
+
return;
|
|
4253
|
+
}
|
|
4248
4254
|
}
|
|
4249
4255
|
function getAgentFile(agentFilePath) {
|
|
4250
4256
|
try {
|
|
@@ -4260,12 +4266,20 @@ function getAgentFile(agentFilePath) {
|
|
|
4260
4266
|
function getAgentBlueprint(_ref3) {
|
|
4261
4267
|
var agentId = _ref3.agentId,
|
|
4262
4268
|
agentDir = _ref3.agentDir;
|
|
4263
|
-
var agentDirPath =
|
|
4264
|
-
|
|
4269
|
+
var agentDirPath = getProjectDir({
|
|
4270
|
+
dir: agentDir
|
|
4265
4271
|
});
|
|
4266
4272
|
var agentBlueprintPath = path.join(agentDirPath, agentId + ".json");
|
|
4267
4273
|
return getAgentFile(agentBlueprintPath);
|
|
4268
4274
|
}
|
|
4275
|
+
function getPineconeConfig(_ref4) {
|
|
4276
|
+
var dir = _ref4.dir;
|
|
4277
|
+
var agentDirPath = getProjectDir({
|
|
4278
|
+
dir: dir
|
|
4279
|
+
});
|
|
4280
|
+
var agentBlueprintPath = path.join(agentDirPath, "pinecone.json");
|
|
4281
|
+
return getAgentFile(agentBlueprintPath);
|
|
4282
|
+
}
|
|
4269
4283
|
|
|
4270
4284
|
var VectorLayer = /*#__PURE__*/function () {
|
|
4271
4285
|
function VectorLayer() {
|
|
@@ -4464,7 +4478,7 @@ var VectorLayer = /*#__PURE__*/function () {
|
|
|
4464
4478
|
}();
|
|
4465
4479
|
|
|
4466
4480
|
function getVectorProvider(provider) {
|
|
4467
|
-
if (provider === '
|
|
4481
|
+
if (provider === 'pinecone') {
|
|
4468
4482
|
var _VectorLayer = new VectorLayer(),
|
|
4469
4483
|
Pinecone = _VectorLayer.Pinecone;
|
|
4470
4484
|
return Pinecone;
|
|
@@ -4480,96 +4494,96 @@ function executeIndexSync(_x) {
|
|
|
4480
4494
|
}
|
|
4481
4495
|
//Generic vector sync from event data
|
|
4482
4496
|
function _executeIndexSync() {
|
|
4483
|
-
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4497
|
+
_executeIndexSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref) {
|
|
4484
4498
|
var _event$user, _event$data;
|
|
4485
|
-
var event, mastra, connectionId, providedIndexes, systemName,
|
|
4486
|
-
return _regeneratorRuntime().wrap(function
|
|
4487
|
-
while (1) switch (
|
|
4499
|
+
var event, mastra, connectionId, providedIndexes, systemName, _iterator2, _step2, _step2$value, provider, indexes, vp, _iterator3, _step3, index, indexMetadata, _loop2, _ret, _iterator4, _step4;
|
|
4500
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
|
|
4501
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4488
4502
|
case 0:
|
|
4489
4503
|
event = _ref.event, mastra = _ref.mastra;
|
|
4490
4504
|
connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
|
|
4491
4505
|
providedIndexes = event == null || (_event$data = event.data) == null ? void 0 : _event$data.data;
|
|
4492
4506
|
systemName = mastra.config.name;
|
|
4493
|
-
|
|
4507
|
+
_iterator2 = _createForOfIteratorHelperLoose(providedIndexes);
|
|
4494
4508
|
case 5:
|
|
4495
|
-
if ((
|
|
4496
|
-
|
|
4509
|
+
if ((_step2 = _iterator2()).done) {
|
|
4510
|
+
_context8.next = 36;
|
|
4497
4511
|
break;
|
|
4498
4512
|
}
|
|
4499
|
-
|
|
4513
|
+
_step2$value = _step2.value, provider = _step2$value.provider, indexes = _step2$value.indexes;
|
|
4500
4514
|
vp = getVectorProvider(provider);
|
|
4501
4515
|
if (vp) {
|
|
4502
|
-
|
|
4516
|
+
_context8.next = 11;
|
|
4503
4517
|
break;
|
|
4504
4518
|
}
|
|
4505
4519
|
console.error('UNSUPPORTED VECTOR PROVIDER', provider);
|
|
4506
|
-
return
|
|
4520
|
+
return _context8.abrupt("return");
|
|
4507
4521
|
case 11:
|
|
4508
4522
|
if (process.env.OPENAI_API_KEY) {
|
|
4509
|
-
|
|
4523
|
+
_context8.next = 14;
|
|
4510
4524
|
break;
|
|
4511
4525
|
}
|
|
4512
4526
|
console.error('NO OPENAI_API_KEY');
|
|
4513
|
-
return
|
|
4527
|
+
return _context8.abrupt("return");
|
|
4514
4528
|
case 14:
|
|
4515
|
-
|
|
4529
|
+
_iterator3 = _createForOfIteratorHelperLoose(indexes);
|
|
4516
4530
|
case 15:
|
|
4517
|
-
if ((
|
|
4518
|
-
|
|
4531
|
+
if ((_step3 = _iterator3()).done) {
|
|
4532
|
+
_context8.next = 34;
|
|
4519
4533
|
break;
|
|
4520
4534
|
}
|
|
4521
|
-
index =
|
|
4522
|
-
|
|
4535
|
+
index = _step3.value;
|
|
4536
|
+
_context8.next = 19;
|
|
4523
4537
|
return mastra.vectorLayer.getPineconeIndexWithMetadata({
|
|
4524
4538
|
name: index
|
|
4525
4539
|
});
|
|
4526
4540
|
case 19:
|
|
4527
|
-
indexMetadata =
|
|
4541
|
+
indexMetadata = _context8.sent;
|
|
4528
4542
|
if (indexMetadata != null && indexMetadata.length) {
|
|
4529
|
-
|
|
4543
|
+
_context8.next = 23;
|
|
4530
4544
|
break;
|
|
4531
4545
|
}
|
|
4532
4546
|
console.error('No index metadata found for', index);
|
|
4533
|
-
return
|
|
4547
|
+
return _context8.abrupt("return");
|
|
4534
4548
|
case 23:
|
|
4535
|
-
|
|
4549
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4536
4550
|
var _yield$mastra$dataLay, _mastra$dataLayer, _mastra$dataLayer3, _entityRecords, _records;
|
|
4537
4551
|
var entity, fields, integration, name, syncEvent, k_id, _mastra$dataLayer2, connection, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, _yield$mastra$trigger, _event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
|
|
4538
|
-
return _regeneratorRuntime().wrap(function
|
|
4539
|
-
while (1) switch (
|
|
4552
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context7) {
|
|
4553
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4540
4554
|
case 0:
|
|
4541
|
-
entity =
|
|
4555
|
+
entity = _step4.value;
|
|
4542
4556
|
fields = entity.fields, integration = entity.integration, name = entity.name, syncEvent = entity.syncEvent;
|
|
4543
|
-
|
|
4557
|
+
_context7.next = 4;
|
|
4544
4558
|
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4545
4559
|
connectionId: connectionId,
|
|
4546
4560
|
name: integration
|
|
4547
4561
|
});
|
|
4548
4562
|
case 4:
|
|
4549
|
-
|
|
4550
|
-
if (!(
|
|
4551
|
-
|
|
4563
|
+
_context7.t1 = _yield$mastra$dataLay = _context7.sent;
|
|
4564
|
+
if (!(_context7.t1 == null)) {
|
|
4565
|
+
_context7.next = 9;
|
|
4552
4566
|
break;
|
|
4553
4567
|
}
|
|
4554
|
-
|
|
4555
|
-
|
|
4568
|
+
_context7.t2 = void 0;
|
|
4569
|
+
_context7.next = 10;
|
|
4556
4570
|
break;
|
|
4557
4571
|
case 9:
|
|
4558
|
-
|
|
4572
|
+
_context7.t2 = _yield$mastra$dataLay.id;
|
|
4559
4573
|
case 10:
|
|
4560
|
-
|
|
4561
|
-
if (
|
|
4562
|
-
|
|
4574
|
+
_context7.t0 = _context7.t2;
|
|
4575
|
+
if (_context7.t0) {
|
|
4576
|
+
_context7.next = 13;
|
|
4563
4577
|
break;
|
|
4564
4578
|
}
|
|
4565
|
-
|
|
4579
|
+
_context7.t0 = '';
|
|
4566
4580
|
case 13:
|
|
4567
|
-
k_id =
|
|
4581
|
+
k_id = _context7.t0;
|
|
4568
4582
|
if (!(!k_id && integration === systemName)) {
|
|
4569
|
-
|
|
4583
|
+
_context7.next = 19;
|
|
4570
4584
|
break;
|
|
4571
4585
|
}
|
|
4572
|
-
|
|
4586
|
+
_context7.next = 17;
|
|
4573
4587
|
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4574
4588
|
connection: {
|
|
4575
4589
|
connectionId: connectionId,
|
|
@@ -4582,32 +4596,32 @@ function _executeIndexSync() {
|
|
|
4582
4596
|
}
|
|
4583
4597
|
});
|
|
4584
4598
|
case 17:
|
|
4585
|
-
connection =
|
|
4599
|
+
connection = _context7.sent;
|
|
4586
4600
|
k_id = connection.id;
|
|
4587
4601
|
case 19:
|
|
4588
4602
|
if (k_id) {
|
|
4589
|
-
|
|
4603
|
+
_context7.next = 22;
|
|
4590
4604
|
break;
|
|
4591
4605
|
}
|
|
4592
4606
|
console.error('Error bootstrapping shit');
|
|
4593
|
-
return
|
|
4607
|
+
return _context7.abrupt("return", {
|
|
4594
4608
|
v: void 0
|
|
4595
4609
|
});
|
|
4596
4610
|
case 22:
|
|
4597
|
-
|
|
4611
|
+
_context7.next = 24;
|
|
4598
4612
|
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
4599
4613
|
k_id: k_id,
|
|
4600
4614
|
type: name
|
|
4601
4615
|
});
|
|
4602
4616
|
case 24:
|
|
4603
|
-
entityRecords =
|
|
4617
|
+
entityRecords = _context7.sent;
|
|
4604
4618
|
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
4605
4619
|
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
4606
|
-
|
|
4620
|
+
_context7.next = 44;
|
|
4607
4621
|
break;
|
|
4608
4622
|
}
|
|
4609
4623
|
console.error('NO RECORDS ATTEMPTING SYNC');
|
|
4610
|
-
|
|
4624
|
+
_context7.next = 30;
|
|
4611
4625
|
return mastra.triggerEvent({
|
|
4612
4626
|
key: syncEvent,
|
|
4613
4627
|
data: {},
|
|
@@ -4616,34 +4630,34 @@ function _executeIndexSync() {
|
|
|
4616
4630
|
}
|
|
4617
4631
|
});
|
|
4618
4632
|
case 30:
|
|
4619
|
-
_yield$mastra$trigger =
|
|
4633
|
+
_yield$mastra$trigger = _context7.sent;
|
|
4620
4634
|
_event = _yield$mastra$trigger.event;
|
|
4621
4635
|
console.log(_event, '####');
|
|
4622
|
-
|
|
4636
|
+
_context7.next = 35;
|
|
4623
4637
|
return _event.subscribe();
|
|
4624
4638
|
case 35:
|
|
4625
|
-
res =
|
|
4639
|
+
res = _context7.sent;
|
|
4626
4640
|
console.log('Subscribe result', res);
|
|
4627
|
-
|
|
4641
|
+
_context7.next = 39;
|
|
4628
4642
|
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
4629
4643
|
k_id: k_id,
|
|
4630
4644
|
type: entity.name
|
|
4631
4645
|
});
|
|
4632
4646
|
case 39:
|
|
4633
|
-
entityRecords =
|
|
4647
|
+
entityRecords = _context7.sent;
|
|
4634
4648
|
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
4635
4649
|
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
4636
|
-
|
|
4650
|
+
_context7.next = 44;
|
|
4637
4651
|
break;
|
|
4638
4652
|
}
|
|
4639
4653
|
console.error('NO RECORDS AFTER SYNC');
|
|
4640
|
-
return
|
|
4654
|
+
return _context7.abrupt("return", {
|
|
4641
4655
|
v: void 0
|
|
4642
4656
|
});
|
|
4643
4657
|
case 44:
|
|
4644
|
-
recordsMapped = records.map(function (
|
|
4645
|
-
var data =
|
|
4646
|
-
externalId =
|
|
4658
|
+
recordsMapped = records.map(function (_ref12) {
|
|
4659
|
+
var data = _ref12.data,
|
|
4660
|
+
externalId = _ref12.externalId;
|
|
4647
4661
|
return _extends({
|
|
4648
4662
|
id: externalId
|
|
4649
4663
|
}, pick(data, fields));
|
|
@@ -4651,91 +4665,91 @@ function _executeIndexSync() {
|
|
|
4651
4665
|
console.log(recordsMapped, 'RECORDS');
|
|
4652
4666
|
entityTypeIndex = vp.index(index);
|
|
4653
4667
|
console.log(entityTypeIndex, 'INDEX');
|
|
4654
|
-
|
|
4655
|
-
|
|
4668
|
+
_context7.prev = 48;
|
|
4669
|
+
_context7.next = 51;
|
|
4656
4670
|
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4657
|
-
var
|
|
4671
|
+
var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(record) {
|
|
4658
4672
|
var _yield$embed, embedding;
|
|
4659
|
-
return _regeneratorRuntime().wrap(function
|
|
4660
|
-
while (1) switch (
|
|
4673
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4674
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4661
4675
|
case 0:
|
|
4662
|
-
|
|
4676
|
+
_context6.next = 2;
|
|
4663
4677
|
return embed({
|
|
4664
4678
|
model: openai.embedding('text-embedding-3-small'),
|
|
4665
4679
|
value: JSON.stringify(record)
|
|
4666
4680
|
});
|
|
4667
4681
|
case 2:
|
|
4668
|
-
_yield$embed =
|
|
4682
|
+
_yield$embed = _context6.sent;
|
|
4669
4683
|
embedding = _yield$embed.embedding;
|
|
4670
|
-
return
|
|
4684
|
+
return _context6.abrupt("return", {
|
|
4671
4685
|
id: record.id,
|
|
4672
4686
|
values: embedding,
|
|
4673
4687
|
metadata: record
|
|
4674
4688
|
});
|
|
4675
4689
|
case 5:
|
|
4676
4690
|
case "end":
|
|
4677
|
-
return
|
|
4691
|
+
return _context6.stop();
|
|
4678
4692
|
}
|
|
4679
|
-
},
|
|
4693
|
+
}, _callee6);
|
|
4680
4694
|
}));
|
|
4681
|
-
return function (
|
|
4682
|
-
return
|
|
4695
|
+
return function (_x8) {
|
|
4696
|
+
return _ref13.apply(this, arguments);
|
|
4683
4697
|
};
|
|
4684
4698
|
}())) != null ? _recordsMapped$map : []);
|
|
4685
4699
|
case 51:
|
|
4686
|
-
vectors =
|
|
4700
|
+
vectors = _context7.sent;
|
|
4687
4701
|
console.log('UPSERTING', vectors);
|
|
4688
4702
|
if (!(vectors.length > 0)) {
|
|
4689
|
-
|
|
4703
|
+
_context7.next = 56;
|
|
4690
4704
|
break;
|
|
4691
4705
|
}
|
|
4692
|
-
|
|
4706
|
+
_context7.next = 56;
|
|
4693
4707
|
return entityTypeIndex.namespace(name).upsert(vectors);
|
|
4694
4708
|
case 56:
|
|
4695
|
-
|
|
4709
|
+
_context7.next = 61;
|
|
4696
4710
|
break;
|
|
4697
4711
|
case 58:
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
console.error(
|
|
4712
|
+
_context7.prev = 58;
|
|
4713
|
+
_context7.t3 = _context7["catch"](48);
|
|
4714
|
+
console.error(_context7.t3);
|
|
4701
4715
|
case 61:
|
|
4702
|
-
return
|
|
4716
|
+
return _context7.abrupt("return", {
|
|
4703
4717
|
v: void 0
|
|
4704
4718
|
});
|
|
4705
4719
|
case 62:
|
|
4706
4720
|
case "end":
|
|
4707
|
-
return
|
|
4721
|
+
return _context7.stop();
|
|
4708
4722
|
}
|
|
4709
|
-
},
|
|
4723
|
+
}, _loop2, null, [[48, 58]]);
|
|
4710
4724
|
});
|
|
4711
|
-
|
|
4725
|
+
_iterator4 = _createForOfIteratorHelperLoose(indexMetadata);
|
|
4712
4726
|
case 25:
|
|
4713
|
-
if ((
|
|
4714
|
-
|
|
4727
|
+
if ((_step4 = _iterator4()).done) {
|
|
4728
|
+
_context8.next = 32;
|
|
4715
4729
|
break;
|
|
4716
4730
|
}
|
|
4717
|
-
return
|
|
4731
|
+
return _context8.delegateYield(_loop2(), "t0", 27);
|
|
4718
4732
|
case 27:
|
|
4719
|
-
_ret =
|
|
4733
|
+
_ret = _context8.t0;
|
|
4720
4734
|
if (!_ret) {
|
|
4721
|
-
|
|
4735
|
+
_context8.next = 30;
|
|
4722
4736
|
break;
|
|
4723
4737
|
}
|
|
4724
|
-
return
|
|
4738
|
+
return _context8.abrupt("return", _ret.v);
|
|
4725
4739
|
case 30:
|
|
4726
|
-
|
|
4740
|
+
_context8.next = 25;
|
|
4727
4741
|
break;
|
|
4728
4742
|
case 32:
|
|
4729
|
-
|
|
4743
|
+
_context8.next = 15;
|
|
4730
4744
|
break;
|
|
4731
4745
|
case 34:
|
|
4732
|
-
|
|
4746
|
+
_context8.next = 5;
|
|
4733
4747
|
break;
|
|
4734
4748
|
case 36:
|
|
4735
4749
|
case "end":
|
|
4736
|
-
return
|
|
4750
|
+
return _context8.stop();
|
|
4737
4751
|
}
|
|
4738
|
-
},
|
|
4752
|
+
}, _callee7);
|
|
4739
4753
|
}));
|
|
4740
4754
|
return _executeIndexSync.apply(this, arguments);
|
|
4741
4755
|
}
|
|
@@ -4744,11 +4758,11 @@ function executeGenericVectorSync(_x2) {
|
|
|
4744
4758
|
}
|
|
4745
4759
|
// Vector Sync from agents Dir
|
|
4746
4760
|
function _executeGenericVectorSync() {
|
|
4747
|
-
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4761
|
+
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref2) {
|
|
4748
4762
|
var _event$user2, _event$data2, _event$data3;
|
|
4749
|
-
var event, mastra, connectionId, vector_provider, entities, systemName, vp,
|
|
4750
|
-
return _regeneratorRuntime().wrap(function
|
|
4751
|
-
while (1) switch (
|
|
4763
|
+
var event, mastra, connectionId, vector_provider, entities, systemName, vp, _iterator5, _step5, _yield$mastra$dataLay2, _mastra$dataLayer5, vectorE, integrationName, k_id, _mastra$dataLayer6, connection, _loop3, _ret2, _iterator6, _step6;
|
|
4764
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context11) {
|
|
4765
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
4752
4766
|
case 0:
|
|
4753
4767
|
event = _ref2.event, mastra = _ref2.mastra;
|
|
4754
4768
|
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
@@ -4756,65 +4770,65 @@ function _executeGenericVectorSync() {
|
|
|
4756
4770
|
entities = event == null || (_event$data3 = event.data) == null ? void 0 : _event$data3.entities;
|
|
4757
4771
|
systemName = mastra.config.name;
|
|
4758
4772
|
if (vector_provider) {
|
|
4759
|
-
|
|
4773
|
+
_context11.next = 8;
|
|
4760
4774
|
break;
|
|
4761
4775
|
}
|
|
4762
4776
|
console.error("No vector_provider defined for agent");
|
|
4763
|
-
return
|
|
4777
|
+
return _context11.abrupt("return");
|
|
4764
4778
|
case 8:
|
|
4765
4779
|
vp = getVectorProvider(vector_provider);
|
|
4766
4780
|
if (vp) {
|
|
4767
|
-
|
|
4781
|
+
_context11.next = 12;
|
|
4768
4782
|
break;
|
|
4769
4783
|
}
|
|
4770
4784
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4771
|
-
return
|
|
4785
|
+
return _context11.abrupt("return");
|
|
4772
4786
|
case 12:
|
|
4773
4787
|
if (process.env.OPENAI_API_KEY) {
|
|
4774
|
-
|
|
4788
|
+
_context11.next = 15;
|
|
4775
4789
|
break;
|
|
4776
4790
|
}
|
|
4777
4791
|
console.error('NO OPENAI_API_KEY');
|
|
4778
|
-
return
|
|
4792
|
+
return _context11.abrupt("return");
|
|
4779
4793
|
case 15:
|
|
4780
|
-
|
|
4794
|
+
_iterator5 = _createForOfIteratorHelperLoose(entities);
|
|
4781
4795
|
case 16:
|
|
4782
|
-
if ((
|
|
4783
|
-
|
|
4796
|
+
if ((_step5 = _iterator5()).done) {
|
|
4797
|
+
_context11.next = 50;
|
|
4784
4798
|
break;
|
|
4785
4799
|
}
|
|
4786
|
-
vectorE =
|
|
4800
|
+
vectorE = _step5.value;
|
|
4787
4801
|
integrationName = vectorE.integration;
|
|
4788
|
-
|
|
4802
|
+
_context11.next = 21;
|
|
4789
4803
|
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
4790
4804
|
connectionId: connectionId,
|
|
4791
4805
|
name: integrationName
|
|
4792
4806
|
});
|
|
4793
4807
|
case 21:
|
|
4794
|
-
|
|
4795
|
-
if (!(
|
|
4796
|
-
|
|
4808
|
+
_context11.t1 = _yield$mastra$dataLay2 = _context11.sent;
|
|
4809
|
+
if (!(_context11.t1 == null)) {
|
|
4810
|
+
_context11.next = 26;
|
|
4797
4811
|
break;
|
|
4798
4812
|
}
|
|
4799
|
-
|
|
4800
|
-
|
|
4813
|
+
_context11.t2 = void 0;
|
|
4814
|
+
_context11.next = 27;
|
|
4801
4815
|
break;
|
|
4802
4816
|
case 26:
|
|
4803
|
-
|
|
4817
|
+
_context11.t2 = _yield$mastra$dataLay2.id;
|
|
4804
4818
|
case 27:
|
|
4805
|
-
|
|
4806
|
-
if (
|
|
4807
|
-
|
|
4819
|
+
_context11.t0 = _context11.t2;
|
|
4820
|
+
if (_context11.t0) {
|
|
4821
|
+
_context11.next = 30;
|
|
4808
4822
|
break;
|
|
4809
4823
|
}
|
|
4810
|
-
|
|
4824
|
+
_context11.t0 = '';
|
|
4811
4825
|
case 30:
|
|
4812
|
-
k_id =
|
|
4826
|
+
k_id = _context11.t0;
|
|
4813
4827
|
if (!(!k_id && integrationName === systemName)) {
|
|
4814
|
-
|
|
4828
|
+
_context11.next = 36;
|
|
4815
4829
|
break;
|
|
4816
4830
|
}
|
|
4817
|
-
|
|
4831
|
+
_context11.next = 34;
|
|
4818
4832
|
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4819
4833
|
connection: {
|
|
4820
4834
|
connectionId: connectionId,
|
|
@@ -4827,38 +4841,38 @@ function _executeGenericVectorSync() {
|
|
|
4827
4841
|
}
|
|
4828
4842
|
});
|
|
4829
4843
|
case 34:
|
|
4830
|
-
connection =
|
|
4844
|
+
connection = _context11.sent;
|
|
4831
4845
|
k_id = connection.id;
|
|
4832
4846
|
case 36:
|
|
4833
4847
|
if (k_id) {
|
|
4834
|
-
|
|
4848
|
+
_context11.next = 39;
|
|
4835
4849
|
break;
|
|
4836
4850
|
}
|
|
4837
4851
|
console.error('Error bootstrapping shit');
|
|
4838
|
-
return
|
|
4852
|
+
return _context11.abrupt("return");
|
|
4839
4853
|
case 39:
|
|
4840
|
-
|
|
4854
|
+
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
4841
4855
|
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4842
4856
|
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4843
|
-
return _regeneratorRuntime().wrap(function
|
|
4844
|
-
while (1) switch (
|
|
4857
|
+
return _regeneratorRuntime().wrap(function _loop3$(_context10) {
|
|
4858
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
4845
4859
|
case 0:
|
|
4846
|
-
entity =
|
|
4847
|
-
|
|
4860
|
+
entity = _step6.value;
|
|
4861
|
+
_context10.next = 3;
|
|
4848
4862
|
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4849
4863
|
k_id: k_id,
|
|
4850
4864
|
type: entity.name
|
|
4851
4865
|
});
|
|
4852
4866
|
case 3:
|
|
4853
|
-
entityRecords =
|
|
4867
|
+
entityRecords = _context10.sent;
|
|
4854
4868
|
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4855
4869
|
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4856
|
-
|
|
4870
|
+
_context10.next = 23;
|
|
4857
4871
|
break;
|
|
4858
4872
|
}
|
|
4859
4873
|
// @TODO: SYNC THEM
|
|
4860
4874
|
console.error('NO RECORDS');
|
|
4861
|
-
|
|
4875
|
+
_context10.next = 9;
|
|
4862
4876
|
return mastra.triggerEvent({
|
|
4863
4877
|
key: entity.syncEvent,
|
|
4864
4878
|
data: {},
|
|
@@ -4867,40 +4881,40 @@ function _executeGenericVectorSync() {
|
|
|
4867
4881
|
}
|
|
4868
4882
|
});
|
|
4869
4883
|
case 9:
|
|
4870
|
-
_yield$mastra$trigger2 =
|
|
4884
|
+
_yield$mastra$trigger2 = _context10.sent;
|
|
4871
4885
|
_event2 = _yield$mastra$trigger2.event;
|
|
4872
4886
|
console.log(_event2, '####');
|
|
4873
|
-
|
|
4887
|
+
_context10.next = 14;
|
|
4874
4888
|
return _event2.subscribe();
|
|
4875
4889
|
case 14:
|
|
4876
|
-
res =
|
|
4890
|
+
res = _context10.sent;
|
|
4877
4891
|
console.log('Subscribe result', res);
|
|
4878
|
-
|
|
4892
|
+
_context10.next = 18;
|
|
4879
4893
|
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4880
4894
|
k_id: k_id,
|
|
4881
4895
|
type: entity.name
|
|
4882
4896
|
});
|
|
4883
4897
|
case 18:
|
|
4884
|
-
entityRecords =
|
|
4898
|
+
entityRecords = _context10.sent;
|
|
4885
4899
|
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4886
4900
|
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4887
|
-
|
|
4901
|
+
_context10.next = 23;
|
|
4888
4902
|
break;
|
|
4889
4903
|
}
|
|
4890
4904
|
console.error('NO RECORDS AFTER SYNC');
|
|
4891
|
-
return
|
|
4905
|
+
return _context10.abrupt("return", {
|
|
4892
4906
|
v: void 0
|
|
4893
4907
|
});
|
|
4894
4908
|
case 23:
|
|
4895
|
-
recordsMapped = records.map(function (
|
|
4896
|
-
var data =
|
|
4897
|
-
externalId =
|
|
4909
|
+
recordsMapped = records.map(function (_ref14) {
|
|
4910
|
+
var data = _ref14.data,
|
|
4911
|
+
externalId = _ref14.externalId;
|
|
4898
4912
|
return _extends({
|
|
4899
4913
|
id: externalId
|
|
4900
4914
|
}, pick(data, entity.fields));
|
|
4901
4915
|
});
|
|
4902
4916
|
console.log(recordsMapped, 'RECORDS');
|
|
4903
|
-
|
|
4917
|
+
_context10.next = 27;
|
|
4904
4918
|
return vp.createIndex({
|
|
4905
4919
|
suppressConflicts: true,
|
|
4906
4920
|
name: entity.name,
|
|
@@ -4914,93 +4928,93 @@ function _executeGenericVectorSync() {
|
|
|
4914
4928
|
}
|
|
4915
4929
|
});
|
|
4916
4930
|
case 27:
|
|
4917
|
-
|
|
4931
|
+
_context10.next = 29;
|
|
4918
4932
|
return delay$1(5000);
|
|
4919
4933
|
case 29:
|
|
4920
4934
|
entityTypeIndex = vp.index(entity.name);
|
|
4921
4935
|
console.log(entityTypeIndex, 'INDEX');
|
|
4922
|
-
|
|
4923
|
-
|
|
4936
|
+
_context10.prev = 31;
|
|
4937
|
+
_context10.next = 34;
|
|
4924
4938
|
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4925
|
-
var
|
|
4939
|
+
var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(record) {
|
|
4926
4940
|
var _yield$embed2, embedding;
|
|
4927
|
-
return _regeneratorRuntime().wrap(function
|
|
4928
|
-
while (1) switch (
|
|
4941
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context9) {
|
|
4942
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
4929
4943
|
case 0:
|
|
4930
|
-
|
|
4944
|
+
_context9.next = 2;
|
|
4931
4945
|
return embed({
|
|
4932
4946
|
model: openai.embedding('text-embedding-3-small'),
|
|
4933
4947
|
value: JSON.stringify(record)
|
|
4934
4948
|
});
|
|
4935
4949
|
case 2:
|
|
4936
|
-
_yield$embed2 =
|
|
4950
|
+
_yield$embed2 = _context9.sent;
|
|
4937
4951
|
embedding = _yield$embed2.embedding;
|
|
4938
|
-
return
|
|
4952
|
+
return _context9.abrupt("return", {
|
|
4939
4953
|
id: record.id,
|
|
4940
4954
|
values: embedding,
|
|
4941
4955
|
metadata: record
|
|
4942
4956
|
});
|
|
4943
4957
|
case 5:
|
|
4944
4958
|
case "end":
|
|
4945
|
-
return
|
|
4959
|
+
return _context9.stop();
|
|
4946
4960
|
}
|
|
4947
|
-
},
|
|
4961
|
+
}, _callee8);
|
|
4948
4962
|
}));
|
|
4949
|
-
return function (
|
|
4950
|
-
return
|
|
4963
|
+
return function (_x9) {
|
|
4964
|
+
return _ref15.apply(this, arguments);
|
|
4951
4965
|
};
|
|
4952
4966
|
}())) != null ? _recordsMapped$map2 : []);
|
|
4953
4967
|
case 34:
|
|
4954
|
-
vectors =
|
|
4968
|
+
vectors = _context10.sent;
|
|
4955
4969
|
console.log('UPSERTING', vectors);
|
|
4956
4970
|
if (!(vectors.length > 0)) {
|
|
4957
|
-
|
|
4971
|
+
_context10.next = 39;
|
|
4958
4972
|
break;
|
|
4959
4973
|
}
|
|
4960
|
-
|
|
4974
|
+
_context10.next = 39;
|
|
4961
4975
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4962
4976
|
case 39:
|
|
4963
|
-
|
|
4977
|
+
_context10.next = 44;
|
|
4964
4978
|
break;
|
|
4965
4979
|
case 41:
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
console.error(
|
|
4980
|
+
_context10.prev = 41;
|
|
4981
|
+
_context10.t0 = _context10["catch"](31);
|
|
4982
|
+
console.error(_context10.t0);
|
|
4969
4983
|
case 44:
|
|
4970
|
-
return
|
|
4984
|
+
return _context10.abrupt("return", {
|
|
4971
4985
|
v: void 0
|
|
4972
4986
|
});
|
|
4973
4987
|
case 45:
|
|
4974
4988
|
case "end":
|
|
4975
|
-
return
|
|
4989
|
+
return _context10.stop();
|
|
4976
4990
|
}
|
|
4977
|
-
},
|
|
4991
|
+
}, _loop3, null, [[31, 41]]);
|
|
4978
4992
|
});
|
|
4979
|
-
|
|
4993
|
+
_iterator6 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4980
4994
|
case 41:
|
|
4981
|
-
if ((
|
|
4982
|
-
|
|
4995
|
+
if ((_step6 = _iterator6()).done) {
|
|
4996
|
+
_context11.next = 48;
|
|
4983
4997
|
break;
|
|
4984
4998
|
}
|
|
4985
|
-
return
|
|
4999
|
+
return _context11.delegateYield(_loop3(), "t3", 43);
|
|
4986
5000
|
case 43:
|
|
4987
|
-
_ret2 =
|
|
5001
|
+
_ret2 = _context11.t3;
|
|
4988
5002
|
if (!_ret2) {
|
|
4989
|
-
|
|
5003
|
+
_context11.next = 46;
|
|
4990
5004
|
break;
|
|
4991
5005
|
}
|
|
4992
|
-
return
|
|
5006
|
+
return _context11.abrupt("return", _ret2.v);
|
|
4993
5007
|
case 46:
|
|
4994
|
-
|
|
5008
|
+
_context11.next = 41;
|
|
4995
5009
|
break;
|
|
4996
5010
|
case 48:
|
|
4997
|
-
|
|
5011
|
+
_context11.next = 16;
|
|
4998
5012
|
break;
|
|
4999
5013
|
case 50:
|
|
5000
5014
|
case "end":
|
|
5001
|
-
return
|
|
5015
|
+
return _context11.stop();
|
|
5002
5016
|
}
|
|
5003
|
-
},
|
|
5017
|
+
}, _callee9);
|
|
5004
5018
|
}));
|
|
5005
5019
|
return _executeGenericVectorSync.apply(this, arguments);
|
|
5006
5020
|
}
|
|
@@ -5008,11 +5022,11 @@ function executeVectorSync(_x3) {
|
|
|
5008
5022
|
return _executeVectorSync.apply(this, arguments);
|
|
5009
5023
|
}
|
|
5010
5024
|
function _executeVectorSync() {
|
|
5011
|
-
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5012
|
-
var _event$user3, _agent$
|
|
5013
|
-
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$
|
|
5014
|
-
return _regeneratorRuntime().wrap(function
|
|
5015
|
-
while (1) switch (
|
|
5025
|
+
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref3) {
|
|
5026
|
+
var _event$user3, _agent$knowledge_sour;
|
|
5027
|
+
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$knowledge_sour2, _iterator7, _step7, _yield$mastra$dataLay3, _mastra$dataLayer9, vectorE, integrationName, k_id, _mastra$dataLayer10, connection, _loop4, _ret3, _iterator8, _step8;
|
|
5028
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context14) {
|
|
5029
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
5016
5030
|
case 0:
|
|
5017
5031
|
event = _ref3.event, mastra = _ref3.mastra;
|
|
5018
5032
|
agentDir = mastra.config.agents.agentDirPath;
|
|
@@ -5023,72 +5037,72 @@ function _executeVectorSync() {
|
|
|
5023
5037
|
connectionId = event == null || (_event$user3 = event.user) == null ? void 0 : _event$user3.connectionId;
|
|
5024
5038
|
systemName = mastra.config.name;
|
|
5025
5039
|
if (agent.knowledge_sources.vector_provider) {
|
|
5026
|
-
|
|
5040
|
+
_context14.next = 8;
|
|
5027
5041
|
break;
|
|
5028
5042
|
}
|
|
5029
5043
|
console.error("No vector_provider defined for agent");
|
|
5030
|
-
return
|
|
5044
|
+
return _context14.abrupt("return");
|
|
5031
5045
|
case 8:
|
|
5032
|
-
vp = getVectorProvider(agent == null || (_agent$
|
|
5046
|
+
vp = getVectorProvider(agent == null || (_agent$knowledge_sour = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour.vector_provider);
|
|
5033
5047
|
if (vp) {
|
|
5034
|
-
|
|
5048
|
+
_context14.next = 12;
|
|
5035
5049
|
break;
|
|
5036
5050
|
}
|
|
5037
|
-
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$
|
|
5038
|
-
return
|
|
5051
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider);
|
|
5052
|
+
return _context14.abrupt("return");
|
|
5039
5053
|
case 12:
|
|
5040
5054
|
if (process.env.OPENAI_API_KEY) {
|
|
5041
|
-
|
|
5055
|
+
_context14.next = 15;
|
|
5042
5056
|
break;
|
|
5043
5057
|
}
|
|
5044
5058
|
console.error('NO OPENAI_API_KEY');
|
|
5045
|
-
return
|
|
5059
|
+
return _context14.abrupt("return");
|
|
5046
5060
|
case 15:
|
|
5047
5061
|
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
5048
|
-
|
|
5062
|
+
_context14.next = 18;
|
|
5049
5063
|
break;
|
|
5050
5064
|
}
|
|
5051
5065
|
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
5052
|
-
return
|
|
5066
|
+
return _context14.abrupt("return");
|
|
5053
5067
|
case 18:
|
|
5054
|
-
|
|
5068
|
+
_iterator7 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
5055
5069
|
case 19:
|
|
5056
|
-
if ((
|
|
5057
|
-
|
|
5070
|
+
if ((_step7 = _iterator7()).done) {
|
|
5071
|
+
_context14.next = 53;
|
|
5058
5072
|
break;
|
|
5059
5073
|
}
|
|
5060
|
-
vectorE =
|
|
5074
|
+
vectorE = _step7.value;
|
|
5061
5075
|
integrationName = vectorE.integration;
|
|
5062
|
-
|
|
5076
|
+
_context14.next = 24;
|
|
5063
5077
|
return (_mastra$dataLayer9 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer9.getConnection({
|
|
5064
5078
|
connectionId: connectionId,
|
|
5065
5079
|
name: integrationName
|
|
5066
5080
|
});
|
|
5067
5081
|
case 24:
|
|
5068
|
-
|
|
5069
|
-
if (!(
|
|
5070
|
-
|
|
5082
|
+
_context14.t1 = _yield$mastra$dataLay3 = _context14.sent;
|
|
5083
|
+
if (!(_context14.t1 == null)) {
|
|
5084
|
+
_context14.next = 29;
|
|
5071
5085
|
break;
|
|
5072
5086
|
}
|
|
5073
|
-
|
|
5074
|
-
|
|
5087
|
+
_context14.t2 = void 0;
|
|
5088
|
+
_context14.next = 30;
|
|
5075
5089
|
break;
|
|
5076
5090
|
case 29:
|
|
5077
|
-
|
|
5091
|
+
_context14.t2 = _yield$mastra$dataLay3.id;
|
|
5078
5092
|
case 30:
|
|
5079
|
-
|
|
5080
|
-
if (
|
|
5081
|
-
|
|
5093
|
+
_context14.t0 = _context14.t2;
|
|
5094
|
+
if (_context14.t0) {
|
|
5095
|
+
_context14.next = 33;
|
|
5082
5096
|
break;
|
|
5083
5097
|
}
|
|
5084
|
-
|
|
5098
|
+
_context14.t0 = '';
|
|
5085
5099
|
case 33:
|
|
5086
|
-
k_id =
|
|
5100
|
+
k_id = _context14.t0;
|
|
5087
5101
|
if (!(!k_id && integrationName === systemName)) {
|
|
5088
|
-
|
|
5102
|
+
_context14.next = 39;
|
|
5089
5103
|
break;
|
|
5090
5104
|
}
|
|
5091
|
-
|
|
5105
|
+
_context14.next = 37;
|
|
5092
5106
|
return (_mastra$dataLayer10 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer10.createConnection({
|
|
5093
5107
|
connection: {
|
|
5094
5108
|
connectionId: connectionId,
|
|
@@ -5101,38 +5115,38 @@ function _executeVectorSync() {
|
|
|
5101
5115
|
}
|
|
5102
5116
|
});
|
|
5103
5117
|
case 37:
|
|
5104
|
-
connection =
|
|
5118
|
+
connection = _context14.sent;
|
|
5105
5119
|
k_id = connection.id;
|
|
5106
5120
|
case 39:
|
|
5107
5121
|
if (k_id) {
|
|
5108
|
-
|
|
5122
|
+
_context14.next = 42;
|
|
5109
5123
|
break;
|
|
5110
5124
|
}
|
|
5111
5125
|
console.error('Error bootstrapping shit');
|
|
5112
|
-
return
|
|
5126
|
+
return _context14.abrupt("return");
|
|
5113
5127
|
case 42:
|
|
5114
|
-
|
|
5128
|
+
_loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
|
|
5115
5129
|
var _mastra$dataLayer11, _entityRecords5, _records5;
|
|
5116
5130
|
var entity, entityRecords, records, _mastra$dataLayer12, _entityRecords6, _records6, _yield$mastra$trigger3, _event3, res, recordsMapped, entityTypeIndex, _recordsMapped$map3, vectors;
|
|
5117
|
-
return _regeneratorRuntime().wrap(function
|
|
5118
|
-
while (1) switch (
|
|
5131
|
+
return _regeneratorRuntime().wrap(function _loop4$(_context13) {
|
|
5132
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
5119
5133
|
case 0:
|
|
5120
|
-
entity =
|
|
5121
|
-
|
|
5134
|
+
entity = _step8.value;
|
|
5135
|
+
_context13.next = 3;
|
|
5122
5136
|
return (_mastra$dataLayer11 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer11.getEntityRecordsByConnectionAndType({
|
|
5123
5137
|
k_id: k_id,
|
|
5124
5138
|
type: entity.name
|
|
5125
5139
|
});
|
|
5126
5140
|
case 3:
|
|
5127
|
-
entityRecords =
|
|
5141
|
+
entityRecords = _context13.sent;
|
|
5128
5142
|
records = (_entityRecords5 = entityRecords) == null ? void 0 : _entityRecords5.records;
|
|
5129
5143
|
if (!(!records || ((_records5 = records) == null ? void 0 : _records5.length) === 0)) {
|
|
5130
|
-
|
|
5144
|
+
_context13.next = 23;
|
|
5131
5145
|
break;
|
|
5132
5146
|
}
|
|
5133
5147
|
// @TODO: SYNC THEM
|
|
5134
5148
|
console.error('NO RECORDS');
|
|
5135
|
-
|
|
5149
|
+
_context13.next = 9;
|
|
5136
5150
|
return mastra.triggerEvent({
|
|
5137
5151
|
key: entity.syncEvent,
|
|
5138
5152
|
data: {},
|
|
@@ -5141,40 +5155,40 @@ function _executeVectorSync() {
|
|
|
5141
5155
|
}
|
|
5142
5156
|
});
|
|
5143
5157
|
case 9:
|
|
5144
|
-
_yield$mastra$trigger3 =
|
|
5158
|
+
_yield$mastra$trigger3 = _context13.sent;
|
|
5145
5159
|
_event3 = _yield$mastra$trigger3.event;
|
|
5146
5160
|
console.log(_event3, '####');
|
|
5147
|
-
|
|
5161
|
+
_context13.next = 14;
|
|
5148
5162
|
return _event3.subscribe();
|
|
5149
5163
|
case 14:
|
|
5150
|
-
res =
|
|
5164
|
+
res = _context13.sent;
|
|
5151
5165
|
console.log('Subscribe result', res);
|
|
5152
|
-
|
|
5166
|
+
_context13.next = 18;
|
|
5153
5167
|
return (_mastra$dataLayer12 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer12.getEntityRecordsByConnectionAndType({
|
|
5154
5168
|
k_id: k_id,
|
|
5155
5169
|
type: entity.name
|
|
5156
5170
|
});
|
|
5157
5171
|
case 18:
|
|
5158
|
-
entityRecords =
|
|
5172
|
+
entityRecords = _context13.sent;
|
|
5159
5173
|
records = (_entityRecords6 = entityRecords) == null ? void 0 : _entityRecords6.records;
|
|
5160
5174
|
if (!(!records || ((_records6 = records) == null ? void 0 : _records6.length) === 0)) {
|
|
5161
|
-
|
|
5175
|
+
_context13.next = 23;
|
|
5162
5176
|
break;
|
|
5163
5177
|
}
|
|
5164
5178
|
console.error('NO RECORDS AFTER SYNC');
|
|
5165
|
-
return
|
|
5179
|
+
return _context13.abrupt("return", {
|
|
5166
5180
|
v: void 0
|
|
5167
5181
|
});
|
|
5168
5182
|
case 23:
|
|
5169
|
-
recordsMapped = records.map(function (
|
|
5170
|
-
var data =
|
|
5171
|
-
externalId =
|
|
5183
|
+
recordsMapped = records.map(function (_ref16) {
|
|
5184
|
+
var data = _ref16.data,
|
|
5185
|
+
externalId = _ref16.externalId;
|
|
5172
5186
|
return _extends({
|
|
5173
5187
|
id: externalId
|
|
5174
5188
|
}, pick(data, entity.fields));
|
|
5175
5189
|
});
|
|
5176
5190
|
console.log(recordsMapped, 'RECORDS');
|
|
5177
|
-
|
|
5191
|
+
_context13.next = 27;
|
|
5178
5192
|
return vp.createIndex({
|
|
5179
5193
|
suppressConflicts: true,
|
|
5180
5194
|
name: entity.name,
|
|
@@ -5190,88 +5204,88 @@ function _executeVectorSync() {
|
|
|
5190
5204
|
case 27:
|
|
5191
5205
|
entityTypeIndex = vp.index(entity.name);
|
|
5192
5206
|
console.log(entityTypeIndex, 'INDEX');
|
|
5193
|
-
|
|
5194
|
-
|
|
5207
|
+
_context13.prev = 29;
|
|
5208
|
+
_context13.next = 32;
|
|
5195
5209
|
return Promise.all((_recordsMapped$map3 = recordsMapped.map(/*#__PURE__*/function () {
|
|
5196
|
-
var
|
|
5210
|
+
var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(record) {
|
|
5197
5211
|
var _yield$embed3, embedding;
|
|
5198
|
-
return _regeneratorRuntime().wrap(function
|
|
5199
|
-
while (1) switch (
|
|
5212
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context12) {
|
|
5213
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
5200
5214
|
case 0:
|
|
5201
|
-
|
|
5215
|
+
_context12.next = 2;
|
|
5202
5216
|
return embed({
|
|
5203
5217
|
model: openai.embedding('text-embedding-3-small'),
|
|
5204
5218
|
value: JSON.stringify(record)
|
|
5205
5219
|
});
|
|
5206
5220
|
case 2:
|
|
5207
|
-
_yield$embed3 =
|
|
5221
|
+
_yield$embed3 = _context12.sent;
|
|
5208
5222
|
embedding = _yield$embed3.embedding;
|
|
5209
|
-
return
|
|
5223
|
+
return _context12.abrupt("return", {
|
|
5210
5224
|
id: record.id,
|
|
5211
5225
|
values: embedding,
|
|
5212
5226
|
metadata: record
|
|
5213
5227
|
});
|
|
5214
5228
|
case 5:
|
|
5215
5229
|
case "end":
|
|
5216
|
-
return
|
|
5230
|
+
return _context12.stop();
|
|
5217
5231
|
}
|
|
5218
|
-
},
|
|
5232
|
+
}, _callee10);
|
|
5219
5233
|
}));
|
|
5220
|
-
return function (
|
|
5221
|
-
return
|
|
5234
|
+
return function (_x10) {
|
|
5235
|
+
return _ref17.apply(this, arguments);
|
|
5222
5236
|
};
|
|
5223
5237
|
}())) != null ? _recordsMapped$map3 : []);
|
|
5224
5238
|
case 32:
|
|
5225
|
-
vectors =
|
|
5239
|
+
vectors = _context13.sent;
|
|
5226
5240
|
console.log('UPSERTING', vectors);
|
|
5227
5241
|
if (!(vectors.length > 0)) {
|
|
5228
|
-
|
|
5242
|
+
_context13.next = 37;
|
|
5229
5243
|
break;
|
|
5230
5244
|
}
|
|
5231
|
-
|
|
5245
|
+
_context13.next = 37;
|
|
5232
5246
|
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
5233
5247
|
case 37:
|
|
5234
|
-
|
|
5248
|
+
_context13.next = 42;
|
|
5235
5249
|
break;
|
|
5236
5250
|
case 39:
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
console.error(
|
|
5251
|
+
_context13.prev = 39;
|
|
5252
|
+
_context13.t0 = _context13["catch"](29);
|
|
5253
|
+
console.error(_context13.t0);
|
|
5240
5254
|
case 42:
|
|
5241
|
-
return
|
|
5255
|
+
return _context13.abrupt("return", {
|
|
5242
5256
|
v: void 0
|
|
5243
5257
|
});
|
|
5244
5258
|
case 43:
|
|
5245
5259
|
case "end":
|
|
5246
|
-
return
|
|
5260
|
+
return _context13.stop();
|
|
5247
5261
|
}
|
|
5248
|
-
},
|
|
5262
|
+
}, _loop4, null, [[29, 39]]);
|
|
5249
5263
|
});
|
|
5250
|
-
|
|
5264
|
+
_iterator8 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
5251
5265
|
case 44:
|
|
5252
|
-
if ((
|
|
5253
|
-
|
|
5266
|
+
if ((_step8 = _iterator8()).done) {
|
|
5267
|
+
_context14.next = 51;
|
|
5254
5268
|
break;
|
|
5255
5269
|
}
|
|
5256
|
-
return
|
|
5270
|
+
return _context14.delegateYield(_loop4(), "t3", 46);
|
|
5257
5271
|
case 46:
|
|
5258
|
-
_ret3 =
|
|
5272
|
+
_ret3 = _context14.t3;
|
|
5259
5273
|
if (!_ret3) {
|
|
5260
|
-
|
|
5274
|
+
_context14.next = 49;
|
|
5261
5275
|
break;
|
|
5262
5276
|
}
|
|
5263
|
-
return
|
|
5277
|
+
return _context14.abrupt("return", _ret3.v);
|
|
5264
5278
|
case 49:
|
|
5265
|
-
|
|
5279
|
+
_context14.next = 44;
|
|
5266
5280
|
break;
|
|
5267
5281
|
case 51:
|
|
5268
|
-
|
|
5282
|
+
_context14.next = 19;
|
|
5269
5283
|
break;
|
|
5270
5284
|
case 53:
|
|
5271
5285
|
case "end":
|
|
5272
|
-
return
|
|
5286
|
+
return _context14.stop();
|
|
5273
5287
|
}
|
|
5274
|
-
},
|
|
5288
|
+
}, _callee11);
|
|
5275
5289
|
}));
|
|
5276
5290
|
return _executeVectorSync.apply(this, arguments);
|
|
5277
5291
|
}
|
|
@@ -5279,118 +5293,262 @@ function vectorQueryEngine(_x4) {
|
|
|
5279
5293
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5280
5294
|
}
|
|
5281
5295
|
function _vectorQueryEngine() {
|
|
5282
|
-
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5296
|
+
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref4) {
|
|
5283
5297
|
var vector_provider, _ref4$topK, topK, indexName, content, entityType, vp, index, _yield$embed4, embedding, queryResponse;
|
|
5284
|
-
return _regeneratorRuntime().wrap(function
|
|
5285
|
-
while (1) switch (
|
|
5298
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context15) {
|
|
5299
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
5286
5300
|
case 0:
|
|
5287
5301
|
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;
|
|
5288
5302
|
vp = getVectorProvider(vector_provider);
|
|
5289
5303
|
if (vp) {
|
|
5290
|
-
|
|
5304
|
+
_context15.next = 5;
|
|
5291
5305
|
break;
|
|
5292
5306
|
}
|
|
5293
5307
|
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
5294
|
-
return
|
|
5308
|
+
return _context15.abrupt("return");
|
|
5295
5309
|
case 5:
|
|
5296
5310
|
index = vp.index(indexName);
|
|
5297
|
-
|
|
5311
|
+
_context15.next = 8;
|
|
5298
5312
|
return embed({
|
|
5299
5313
|
model: openai.embedding('text-embedding-3-small'),
|
|
5300
5314
|
value: content
|
|
5301
5315
|
});
|
|
5302
5316
|
case 8:
|
|
5303
|
-
_yield$embed4 =
|
|
5317
|
+
_yield$embed4 = _context15.sent;
|
|
5304
5318
|
embedding = _yield$embed4.embedding;
|
|
5305
5319
|
console.log(embedding, 'EMBEDDING');
|
|
5306
|
-
|
|
5320
|
+
_context15.next = 13;
|
|
5307
5321
|
return index.namespace(entityType).query({
|
|
5308
5322
|
vector: embedding,
|
|
5309
5323
|
topK: topK,
|
|
5310
5324
|
includeMetadata: true
|
|
5311
5325
|
});
|
|
5312
5326
|
case 13:
|
|
5313
|
-
queryResponse =
|
|
5314
|
-
return
|
|
5327
|
+
queryResponse = _context15.sent;
|
|
5328
|
+
return _context15.abrupt("return", queryResponse);
|
|
5315
5329
|
case 15:
|
|
5316
5330
|
case "end":
|
|
5317
|
-
return
|
|
5331
|
+
return _context15.stop();
|
|
5318
5332
|
}
|
|
5319
|
-
},
|
|
5333
|
+
}, _callee12);
|
|
5320
5334
|
}));
|
|
5321
5335
|
return _vectorQueryEngine.apply(this, arguments);
|
|
5322
5336
|
}
|
|
5323
|
-
function
|
|
5324
|
-
var
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5337
|
+
var fetchPineconeIndexes = /*#__PURE__*/function () {
|
|
5338
|
+
var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
5339
|
+
var response, _ref6, indexes;
|
|
5340
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5341
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5342
|
+
case 0:
|
|
5343
|
+
_context.prev = 0;
|
|
5344
|
+
_context.next = 3;
|
|
5345
|
+
return fetch('https://api.pinecone.io/indexes', {
|
|
5346
|
+
method: 'GET',
|
|
5347
|
+
headers: {
|
|
5348
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
5349
|
+
'X-Pinecone-API-Version': 'unstable'
|
|
5350
|
+
},
|
|
5351
|
+
cache: 'no-store'
|
|
5352
|
+
});
|
|
5353
|
+
case 3:
|
|
5354
|
+
response = _context.sent;
|
|
5355
|
+
_context.next = 6;
|
|
5356
|
+
return response.json();
|
|
5357
|
+
case 6:
|
|
5358
|
+
_context.t0 = _context.sent;
|
|
5359
|
+
if (_context.t0) {
|
|
5360
|
+
_context.next = 9;
|
|
5361
|
+
break;
|
|
5362
|
+
}
|
|
5363
|
+
_context.t0 = {};
|
|
5364
|
+
case 9:
|
|
5365
|
+
_ref6 = _context.t0;
|
|
5366
|
+
indexes = _ref6.indexes;
|
|
5367
|
+
return _context.abrupt("return", indexes);
|
|
5368
|
+
case 14:
|
|
5369
|
+
_context.prev = 14;
|
|
5370
|
+
_context.t1 = _context["catch"](0);
|
|
5371
|
+
console.log('Error fetching indexes using JS fetch====', _context.t1);
|
|
5372
|
+
case 17:
|
|
5373
|
+
case "end":
|
|
5374
|
+
return _context.stop();
|
|
5375
|
+
}
|
|
5376
|
+
}, _callee, null, [[0, 14]]);
|
|
5377
|
+
}));
|
|
5378
|
+
return function fetchPineconeIndexes() {
|
|
5379
|
+
return _ref5.apply(this, arguments);
|
|
5380
|
+
};
|
|
5381
|
+
}();
|
|
5382
|
+
var fetchPineconeIndexStats = /*#__PURE__*/function () {
|
|
5383
|
+
var _ref7 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(host) {
|
|
5384
|
+
var response, data;
|
|
5385
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5386
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5387
|
+
case 0:
|
|
5388
|
+
_context2.prev = 0;
|
|
5389
|
+
_context2.next = 3;
|
|
5390
|
+
return fetch("https://" + host + "/describe_index_stats", {
|
|
5391
|
+
method: 'GET',
|
|
5392
|
+
headers: {
|
|
5393
|
+
'Api-Key': process.env.PINECONE_API_KEY,
|
|
5394
|
+
'X-Pinecone-API-Version': '2024-07'
|
|
5395
|
+
},
|
|
5396
|
+
cache: 'no-store'
|
|
5397
|
+
});
|
|
5398
|
+
case 3:
|
|
5399
|
+
response = _context2.sent;
|
|
5400
|
+
_context2.next = 6;
|
|
5401
|
+
return response.json();
|
|
5402
|
+
case 6:
|
|
5403
|
+
_context2.t0 = _context2.sent;
|
|
5404
|
+
if (_context2.t0) {
|
|
5405
|
+
_context2.next = 9;
|
|
5406
|
+
break;
|
|
5407
|
+
}
|
|
5408
|
+
_context2.t0 = {};
|
|
5409
|
+
case 9:
|
|
5410
|
+
data = _context2.t0;
|
|
5411
|
+
return _context2.abrupt("return", data);
|
|
5412
|
+
case 13:
|
|
5413
|
+
_context2.prev = 13;
|
|
5414
|
+
_context2.t1 = _context2["catch"](0);
|
|
5415
|
+
console.log('Error fetching indexes using JS fetch====', _context2.t1);
|
|
5416
|
+
case 16:
|
|
5417
|
+
case "end":
|
|
5418
|
+
return _context2.stop();
|
|
5419
|
+
}
|
|
5420
|
+
}, _callee2, null, [[0, 13]]);
|
|
5421
|
+
}));
|
|
5422
|
+
return function fetchPineconeIndexStats(_x5) {
|
|
5423
|
+
return _ref7.apply(this, arguments);
|
|
5424
|
+
};
|
|
5425
|
+
}();
|
|
5426
|
+
var getPineconeIndices = /*#__PURE__*/function () {
|
|
5427
|
+
var _ref8 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
5428
|
+
var indexes, indexesWithStats;
|
|
5429
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5430
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5431
|
+
case 0:
|
|
5432
|
+
_context4.next = 2;
|
|
5433
|
+
return fetchPineconeIndexes();
|
|
5434
|
+
case 2:
|
|
5435
|
+
indexes = _context4.sent;
|
|
5436
|
+
if (!(indexes && (indexes == null ? void 0 : indexes.length) > 0)) {
|
|
5437
|
+
_context4.next = 8;
|
|
5438
|
+
break;
|
|
5439
|
+
}
|
|
5440
|
+
_context4.next = 6;
|
|
5441
|
+
return Promise.all(indexes.map(/*#__PURE__*/function () {
|
|
5442
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(index) {
|
|
5443
|
+
var stats, namespaces;
|
|
5444
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5445
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5362
5446
|
case 0:
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
}
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
console.log(JSON.stringify({
|
|
5375
|
-
res: res
|
|
5376
|
-
}, null, 2));
|
|
5377
|
-
// @TODO: make this a proper response
|
|
5378
|
-
return _context.abrupt("return", res);
|
|
5447
|
+
_context3.next = 2;
|
|
5448
|
+
return fetchPineconeIndexStats(index.host);
|
|
5449
|
+
case 2:
|
|
5450
|
+
stats = _context3.sent;
|
|
5451
|
+
namespaces = [];
|
|
5452
|
+
if (stats != null && stats.namespaces) {
|
|
5453
|
+
namespaces = Object.keys(stats.namespaces);
|
|
5454
|
+
}
|
|
5455
|
+
return _context3.abrupt("return", _extends({}, index, {
|
|
5456
|
+
namespaces: namespaces
|
|
5457
|
+
}));
|
|
5379
5458
|
case 6:
|
|
5380
5459
|
case "end":
|
|
5381
|
-
return
|
|
5460
|
+
return _context3.stop();
|
|
5382
5461
|
}
|
|
5383
|
-
},
|
|
5462
|
+
}, _callee3);
|
|
5384
5463
|
}));
|
|
5385
|
-
function
|
|
5386
|
-
return
|
|
5387
|
-
}
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5464
|
+
return function (_x6) {
|
|
5465
|
+
return _ref9.apply(this, arguments);
|
|
5466
|
+
};
|
|
5467
|
+
}()));
|
|
5468
|
+
case 6:
|
|
5469
|
+
indexesWithStats = _context4.sent;
|
|
5470
|
+
return _context4.abrupt("return", indexesWithStats);
|
|
5471
|
+
case 8:
|
|
5472
|
+
return _context4.abrupt("return", []);
|
|
5473
|
+
case 9:
|
|
5474
|
+
case "end":
|
|
5475
|
+
return _context4.stop();
|
|
5476
|
+
}
|
|
5477
|
+
}, _callee4);
|
|
5478
|
+
}));
|
|
5479
|
+
return function getPineconeIndices() {
|
|
5480
|
+
return _ref8.apply(this, arguments);
|
|
5481
|
+
};
|
|
5482
|
+
}();
|
|
5483
|
+
function getVectorQueryApis(_ref10) {
|
|
5484
|
+
var mastra = _ref10.mastra;
|
|
5485
|
+
var vectorProvider = mastra.config.agents.vectorProvider;
|
|
5486
|
+
if (!vectorProvider) {
|
|
5487
|
+
console.error('NO VECTOR PROVIDER');
|
|
5488
|
+
return [];
|
|
5489
|
+
}
|
|
5490
|
+
var vectorApis = [];
|
|
5491
|
+
var _loop = function _loop() {
|
|
5492
|
+
var provider = _step.value;
|
|
5493
|
+
if (provider.name === 'pinecone') {
|
|
5494
|
+
var config = getPineconeConfig({
|
|
5495
|
+
dir: provider.dirPath
|
|
5391
5496
|
});
|
|
5392
|
-
|
|
5393
|
-
|
|
5497
|
+
config.forEach(function (index) {
|
|
5498
|
+
if (index != null && index.namespaces) {
|
|
5499
|
+
index == null || index.namespaces.forEach(function (namespace) {
|
|
5500
|
+
vectorApis.push({
|
|
5501
|
+
integrationName: 'SYSTEM',
|
|
5502
|
+
type: "vector_query_" + index.name + "_" + namespace,
|
|
5503
|
+
label: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5504
|
+
description: "Provides query tool for " + index.name + " index in " + namespace + " namespace",
|
|
5505
|
+
schema: z.object({
|
|
5506
|
+
content: z.string(),
|
|
5507
|
+
topResult: z.number()
|
|
5508
|
+
}),
|
|
5509
|
+
executor: function () {
|
|
5510
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref11) {
|
|
5511
|
+
var data, res;
|
|
5512
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5513
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
5514
|
+
case 0:
|
|
5515
|
+
data = _ref11.data;
|
|
5516
|
+
_context5.next = 3;
|
|
5517
|
+
return vectorQueryEngine({
|
|
5518
|
+
vector_provider: provider.name,
|
|
5519
|
+
indexName: index.name,
|
|
5520
|
+
content: data.content,
|
|
5521
|
+
topK: data.topResult || 1,
|
|
5522
|
+
entityType: namespace
|
|
5523
|
+
});
|
|
5524
|
+
case 3:
|
|
5525
|
+
res = _context5.sent;
|
|
5526
|
+
console.log(JSON.stringify({
|
|
5527
|
+
res: res
|
|
5528
|
+
}, null, 2));
|
|
5529
|
+
// @TODO: make this a proper response
|
|
5530
|
+
return _context5.abrupt("return", res);
|
|
5531
|
+
case 6:
|
|
5532
|
+
case "end":
|
|
5533
|
+
return _context5.stop();
|
|
5534
|
+
}
|
|
5535
|
+
}, _callee5);
|
|
5536
|
+
}));
|
|
5537
|
+
function executor(_x7) {
|
|
5538
|
+
return _executor.apply(this, arguments);
|
|
5539
|
+
}
|
|
5540
|
+
return executor;
|
|
5541
|
+
}()
|
|
5542
|
+
});
|
|
5543
|
+
});
|
|
5544
|
+
}
|
|
5545
|
+
});
|
|
5546
|
+
}
|
|
5547
|
+
};
|
|
5548
|
+
for (var _iterator = _createForOfIteratorHelperLoose(vectorProvider), _step; !(_step = _iterator()).done;) {
|
|
5549
|
+
_loop();
|
|
5550
|
+
}
|
|
5551
|
+
return vectorApis;
|
|
5394
5552
|
}
|
|
5395
5553
|
function agentVectorSyncEvent() {
|
|
5396
5554
|
return {
|
|
@@ -5423,11 +5581,14 @@ function getAgentSystemApis(_ref) {
|
|
|
5423
5581
|
agentDir: agentDir
|
|
5424
5582
|
});
|
|
5425
5583
|
// Remove the .json extension from the agent names
|
|
5426
|
-
var agentList =
|
|
5427
|
-
|
|
5428
|
-
|
|
5584
|
+
var agentList = [];
|
|
5585
|
+
if (agents) {
|
|
5586
|
+
agentList = agents.map(function (agent) {
|
|
5587
|
+
return agent.slice(0, -5);
|
|
5588
|
+
});
|
|
5589
|
+
}
|
|
5429
5590
|
return [{
|
|
5430
|
-
integrationName:
|
|
5591
|
+
integrationName: mastra.config.name,
|
|
5431
5592
|
type: 'message_agent',
|
|
5432
5593
|
label: 'Send Message To Agent',
|
|
5433
5594
|
description: 'Sends a message to an Agent',
|
|
@@ -5440,55 +5601,58 @@ function getAgentSystemApis(_ref) {
|
|
|
5440
5601
|
}),
|
|
5441
5602
|
executor: function () {
|
|
5442
5603
|
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5443
|
-
var data, executor, result, _run$content, thread, run;
|
|
5604
|
+
var data, ctx, executor, result, _run$content, thread, run;
|
|
5444
5605
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5445
5606
|
while (1) switch (_context.prev = _context.next) {
|
|
5446
5607
|
case 0:
|
|
5447
|
-
data = _ref2.data;
|
|
5608
|
+
data = _ref2.data, ctx = _ref2.ctx;
|
|
5448
5609
|
_context.next = 3;
|
|
5449
5610
|
return mastra.getAgent({
|
|
5450
5611
|
agentId: data.agentId,
|
|
5451
|
-
connectionId:
|
|
5612
|
+
connectionId: ctx.connectionId
|
|
5452
5613
|
});
|
|
5453
5614
|
case 3:
|
|
5454
5615
|
executor = _context.sent;
|
|
5616
|
+
console.log('executor====', {
|
|
5617
|
+
executor: executor
|
|
5618
|
+
});
|
|
5455
5619
|
if (executor) {
|
|
5456
|
-
_context.next =
|
|
5620
|
+
_context.next = 7;
|
|
5457
5621
|
break;
|
|
5458
5622
|
}
|
|
5459
5623
|
throw new Error('Could not create agent executor');
|
|
5460
|
-
case
|
|
5624
|
+
case 7:
|
|
5461
5625
|
if (!(typeof executor === 'function')) {
|
|
5462
|
-
_context.next =
|
|
5626
|
+
_context.next = 14;
|
|
5463
5627
|
break;
|
|
5464
5628
|
}
|
|
5465
|
-
_context.next =
|
|
5629
|
+
_context.next = 10;
|
|
5466
5630
|
return executor({
|
|
5467
5631
|
prompt: data == null ? void 0 : data.message
|
|
5468
5632
|
});
|
|
5469
|
-
case
|
|
5633
|
+
case 10:
|
|
5470
5634
|
result = _context.sent;
|
|
5471
5635
|
return _context.abrupt("return", {
|
|
5472
5636
|
message: result == null ? void 0 : result.text
|
|
5473
5637
|
});
|
|
5474
|
-
case
|
|
5475
|
-
_context.next =
|
|
5638
|
+
case 14:
|
|
5639
|
+
_context.next = 16;
|
|
5476
5640
|
return executor.initializeThread([{
|
|
5477
5641
|
role: 'user',
|
|
5478
5642
|
content: data == null ? void 0 : data.message
|
|
5479
5643
|
}]);
|
|
5480
|
-
case
|
|
5644
|
+
case 16:
|
|
5481
5645
|
thread = _context.sent;
|
|
5482
|
-
_context.next =
|
|
5646
|
+
_context.next = 19;
|
|
5483
5647
|
return executor.watchRun({
|
|
5484
5648
|
threadId: thread.id
|
|
5485
5649
|
});
|
|
5486
|
-
case
|
|
5650
|
+
case 19:
|
|
5487
5651
|
run = _context.sent;
|
|
5488
5652
|
return _context.abrupt("return", {
|
|
5489
5653
|
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
|
|
5490
5654
|
});
|
|
5491
|
-
case
|
|
5655
|
+
case 21:
|
|
5492
5656
|
case "end":
|
|
5493
5657
|
return _context.stop();
|
|
5494
5658
|
}
|
|
@@ -5502,427 +5666,502 @@ function getAgentSystemApis(_ref) {
|
|
|
5502
5666
|
}];
|
|
5503
5667
|
}
|
|
5504
5668
|
|
|
5505
|
-
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
5506
|
-
function createFileLogger(_ref) {
|
|
5507
|
-
var destinationPath = _ref.destinationPath;
|
|
5508
|
-
var fullPath = path.join(loggerPath, destinationPath);
|
|
5509
|
-
return function (log) {
|
|
5510
|
-
if (!existsSync(loggerPath)) {
|
|
5511
|
-
mkdirSync(loggerPath, {
|
|
5512
|
-
recursive: true
|
|
5513
|
-
});
|
|
5514
|
-
return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
5515
|
-
createdAt: new Date()
|
|
5516
|
-
})], null, 2));
|
|
5517
|
-
}
|
|
5518
|
-
var logs = JSON.parse(readFileSync(fullPath, 'utf-8'));
|
|
5519
|
-
logs.push(_extends({}, log, {
|
|
5520
|
-
createdAt: new Date()
|
|
5521
|
-
}));
|
|
5522
|
-
return writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
5523
|
-
};
|
|
5524
|
-
}
|
|
5525
|
-
|
|
5526
5669
|
var client;
|
|
5527
5670
|
if (process.env.OPENAI_API_KEY) {
|
|
5528
5671
|
client = /*#__PURE__*/new OpenAI({
|
|
5529
5672
|
apiKey: process.env.OPENAI_API_KEY
|
|
5530
5673
|
});
|
|
5531
5674
|
}
|
|
5532
|
-
function
|
|
5533
|
-
return
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
_context3.next = 4;
|
|
5561
|
-
return client.beta.threads.messages.list(threadId);
|
|
5562
|
-
case 4:
|
|
5563
|
-
messages = _context3.sent;
|
|
5564
|
-
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5565
|
-
case 8:
|
|
5566
|
-
if (!(run.status === 'requires_action')) {
|
|
5567
|
-
_context3.next = 14;
|
|
5568
|
-
break;
|
|
5569
|
-
}
|
|
5570
|
-
_context3.next = 11;
|
|
5571
|
-
return handleRequiresAction({
|
|
5572
|
-
run: run,
|
|
5573
|
-
threadId: threadId
|
|
5574
|
-
});
|
|
5575
|
-
case 11:
|
|
5576
|
-
return _context3.abrupt("return", _context3.sent);
|
|
5577
|
-
case 14:
|
|
5578
|
-
console.error('Run did not complete:', run);
|
|
5579
|
-
logger({
|
|
5580
|
-
statusCode: 400,
|
|
5581
|
-
message: JSON.stringify({
|
|
5582
|
-
message: "Run did not complete",
|
|
5583
|
-
event_type: 'run_error',
|
|
5584
|
-
metadata: {
|
|
5585
|
-
run: run
|
|
5586
|
-
}
|
|
5587
|
-
}, null, 2)
|
|
5588
|
-
});
|
|
5589
|
-
case 16:
|
|
5590
|
-
case "end":
|
|
5591
|
-
return _context3.stop();
|
|
5592
|
-
}
|
|
5593
|
-
}, _callee3);
|
|
5594
|
-
}));
|
|
5595
|
-
return function handleRunStatus(_x4) {
|
|
5596
|
-
return _ref5.apply(this, arguments);
|
|
5597
|
-
};
|
|
5598
|
-
}();
|
|
5599
|
-
handleRequiresAction = /*#__PURE__*/function () {
|
|
5600
|
-
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5601
|
-
var threadId, run, toolOutputs;
|
|
5602
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5603
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
5604
|
-
case 0:
|
|
5605
|
-
threadId = _ref6.threadId, run = _ref6.run;
|
|
5606
|
-
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5607
|
-
_context5.next = 23;
|
|
5608
|
-
break;
|
|
5609
|
-
}
|
|
5610
|
-
_context5.t0 = compact;
|
|
5611
|
-
_context5.next = 5;
|
|
5612
|
-
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5613
|
-
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5614
|
-
var callInfo, toolMetadata, toolFn, args, output;
|
|
5615
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5616
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
5617
|
-
case 0:
|
|
5618
|
-
callInfo = index + 1 + " of " + tools.length;
|
|
5619
|
-
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5620
|
-
toolMetadata = {
|
|
5621
|
-
id: tool.id,
|
|
5622
|
-
fn: tool["function"].name,
|
|
5623
|
-
availableTools: Object.keys(toolMap)
|
|
5624
|
-
};
|
|
5625
|
-
logger({
|
|
5626
|
-
statusCode: 100,
|
|
5627
|
-
message: JSON.stringify({
|
|
5628
|
-
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5629
|
-
metadata: {
|
|
5630
|
-
tool: toolMetadata
|
|
5631
|
-
}
|
|
5632
|
-
}, null, 2)
|
|
5633
|
-
});
|
|
5634
|
-
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5635
|
-
if (toolFn) {
|
|
5636
|
-
_context4.next = 8;
|
|
5637
|
-
break;
|
|
5638
|
-
}
|
|
5639
|
-
logger({
|
|
5640
|
-
statusCode: 404,
|
|
5641
|
-
message: JSON.stringify({
|
|
5642
|
-
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5643
|
-
metadata: {
|
|
5644
|
-
tool: toolMetadata
|
|
5645
|
-
}
|
|
5646
|
-
}, null, 2)
|
|
5647
|
-
});
|
|
5648
|
-
return _context4.abrupt("return");
|
|
5649
|
-
case 8:
|
|
5650
|
-
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5651
|
-
args = {};
|
|
5652
|
-
try {
|
|
5653
|
-
if (tool["function"].arguments) {
|
|
5654
|
-
args = JSON.parse(tool["function"].arguments);
|
|
5655
|
-
logger({
|
|
5656
|
-
statusCode: 100,
|
|
5657
|
-
message: JSON.stringify({
|
|
5658
|
-
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5659
|
-
metadata: {
|
|
5660
|
-
args: args,
|
|
5661
|
-
tool: toolMetadata
|
|
5662
|
-
}
|
|
5663
|
-
}, null, 2)
|
|
5664
|
-
});
|
|
5665
|
-
}
|
|
5666
|
-
} catch (e) {
|
|
5667
|
-
console.error(e);
|
|
5668
|
-
}
|
|
5669
|
-
_context4.next = 13;
|
|
5670
|
-
return toolFn(args);
|
|
5671
|
-
case 13:
|
|
5672
|
-
output = _context4.sent;
|
|
5673
|
-
logger({
|
|
5674
|
-
statusCode: 200,
|
|
5675
|
-
message: JSON.stringify({
|
|
5676
|
-
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5677
|
-
metadata: {
|
|
5678
|
-
output: output,
|
|
5679
|
-
tool: toolMetadata
|
|
5680
|
-
}
|
|
5681
|
-
}, null, 2)
|
|
5682
|
-
});
|
|
5683
|
-
return _context4.abrupt("return", {
|
|
5684
|
-
tool_call_id: tool.id,
|
|
5685
|
-
output: JSON.stringify(output)
|
|
5686
|
-
});
|
|
5687
|
-
case 16:
|
|
5688
|
-
case "end":
|
|
5689
|
-
return _context4.stop();
|
|
5690
|
-
}
|
|
5691
|
-
}, _callee4);
|
|
5692
|
-
}));
|
|
5693
|
-
return function (_x6, _x7, _x8) {
|
|
5694
|
-
return _ref8.apply(this, arguments);
|
|
5695
|
-
};
|
|
5696
|
-
}()));
|
|
5697
|
-
case 5:
|
|
5698
|
-
_context5.t1 = _context5.sent;
|
|
5699
|
-
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5700
|
-
if (toolOutputs) {
|
|
5701
|
-
_context5.next = 11;
|
|
5702
|
-
break;
|
|
5703
|
-
}
|
|
5704
|
-
console.error('No tool outputs to submit.');
|
|
5705
|
-
logger({
|
|
5706
|
-
statusCode: 404,
|
|
5707
|
-
message: JSON.stringify({
|
|
5708
|
-
message: "No tool outputs submitted",
|
|
5709
|
-
metadata: {}
|
|
5710
|
-
}, null, 2)
|
|
5711
|
-
});
|
|
5712
|
-
return _context5.abrupt("return", handleRunStatus({
|
|
5713
|
-
threadId: threadId,
|
|
5714
|
-
run: run
|
|
5715
|
-
}));
|
|
5716
|
-
case 11:
|
|
5717
|
-
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5718
|
-
_context5.next = 20;
|
|
5719
|
-
break;
|
|
5720
|
-
}
|
|
5721
|
-
console.log(toolOutputs, '###### YOOOOOO');
|
|
5722
|
-
_context5.next = 15;
|
|
5723
|
-
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5724
|
-
tool_outputs: toolOutputs
|
|
5725
|
-
});
|
|
5726
|
-
case 15:
|
|
5727
|
-
run = _context5.sent;
|
|
5728
|
-
logger({
|
|
5729
|
-
statusCode: 200,
|
|
5730
|
-
message: JSON.stringify({
|
|
5731
|
-
message: "Tool outputs submitted",
|
|
5732
|
-
metadata: {
|
|
5733
|
-
run: run
|
|
5734
|
-
}
|
|
5735
|
-
}, null, 2)
|
|
5736
|
-
});
|
|
5737
|
-
console.log('Tool outputs submitted successfully.');
|
|
5738
|
-
_context5.next = 22;
|
|
5739
|
-
break;
|
|
5740
|
-
case 20:
|
|
5741
|
-
logger({
|
|
5742
|
-
statusCode: 404,
|
|
5743
|
-
message: JSON.stringify({
|
|
5744
|
-
message: "No tool outputs to submit",
|
|
5745
|
-
metadata: {}
|
|
5746
|
-
}, null, 2)
|
|
5747
|
-
});
|
|
5748
|
-
console.log('No tool outputs to submit.');
|
|
5749
|
-
case 22:
|
|
5750
|
-
return _context5.abrupt("return", handleRunStatus({
|
|
5751
|
-
threadId: threadId,
|
|
5752
|
-
run: run
|
|
5753
|
-
}));
|
|
5754
|
-
case 23:
|
|
5755
|
-
case "end":
|
|
5756
|
-
return _context5.stop();
|
|
5675
|
+
function createAssistantAgentHandler(logger) {
|
|
5676
|
+
return /*#__PURE__*/function () {
|
|
5677
|
+
var _createAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
5678
|
+
var name, instructions, model, tools, response_format, assistant;
|
|
5679
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5680
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5681
|
+
case 0:
|
|
5682
|
+
name = _ref.name, instructions = _ref.instructions, model = _ref.model, tools = _ref.tools, response_format = _ref.response_format;
|
|
5683
|
+
_context.next = 3;
|
|
5684
|
+
return client.beta.assistants.create({
|
|
5685
|
+
name: name,
|
|
5686
|
+
model: model,
|
|
5687
|
+
instructions: instructions,
|
|
5688
|
+
tools: tools,
|
|
5689
|
+
response_format: response_format
|
|
5690
|
+
});
|
|
5691
|
+
case 3:
|
|
5692
|
+
assistant = _context.sent;
|
|
5693
|
+
logger({
|
|
5694
|
+
destinationPath: assistant.id + ".json",
|
|
5695
|
+
statusCode: 201,
|
|
5696
|
+
message: JSON.stringify({
|
|
5697
|
+
message: 'Created assistant',
|
|
5698
|
+
metadata: {
|
|
5699
|
+
name: name,
|
|
5700
|
+
model: model,
|
|
5701
|
+
instructions: instructions,
|
|
5702
|
+
tools: tools
|
|
5757
5703
|
}
|
|
5758
|
-
},
|
|
5759
|
-
})
|
|
5760
|
-
return
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5704
|
+
}, null, 2)
|
|
5705
|
+
});
|
|
5706
|
+
return _context.abrupt("return", assistant);
|
|
5707
|
+
case 6:
|
|
5708
|
+
case "end":
|
|
5709
|
+
return _context.stop();
|
|
5710
|
+
}
|
|
5711
|
+
}, _callee);
|
|
5712
|
+
}));
|
|
5713
|
+
function createAssistantAgent(_x) {
|
|
5714
|
+
return _createAssistantAgent.apply(this, arguments);
|
|
5715
|
+
}
|
|
5716
|
+
return createAssistantAgent;
|
|
5717
|
+
}();
|
|
5718
|
+
}
|
|
5719
|
+
function updateAssistantAgentHandler(logger) {
|
|
5720
|
+
return /*#__PURE__*/function () {
|
|
5721
|
+
var _updateAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
5722
|
+
var assistantId, name, instructions, model, tools, response_format, assistant;
|
|
5723
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5724
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5725
|
+
case 0:
|
|
5726
|
+
assistantId = _ref2.assistantId, name = _ref2.name, instructions = _ref2.instructions, model = _ref2.model, tools = _ref2.tools, response_format = _ref2.response_format;
|
|
5727
|
+
_context2.next = 3;
|
|
5728
|
+
return client.beta.assistants.update(assistantId, {
|
|
5729
|
+
name: name,
|
|
5730
|
+
model: model,
|
|
5731
|
+
instructions: instructions,
|
|
5732
|
+
tools: tools,
|
|
5733
|
+
response_format: response_format
|
|
5734
|
+
});
|
|
5735
|
+
case 3:
|
|
5736
|
+
assistant = _context2.sent;
|
|
5737
|
+
logger({
|
|
5738
|
+
destinationPath: assistant.id + ".json",
|
|
5739
|
+
statusCode: 200,
|
|
5740
|
+
message: JSON.stringify({
|
|
5741
|
+
message: 'Updated assistant',
|
|
5742
|
+
metadata: {
|
|
5743
|
+
name: name,
|
|
5744
|
+
model: model,
|
|
5745
|
+
instructions: instructions,
|
|
5746
|
+
tools: tools,
|
|
5747
|
+
response_format: response_format
|
|
5778
5748
|
}
|
|
5779
|
-
},
|
|
5780
|
-
})
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5749
|
+
}, null, 2)
|
|
5750
|
+
});
|
|
5751
|
+
case 5:
|
|
5752
|
+
case "end":
|
|
5753
|
+
return _context2.stop();
|
|
5754
|
+
}
|
|
5755
|
+
}, _callee2);
|
|
5756
|
+
}));
|
|
5757
|
+
function updateAssistantAgent(_x2) {
|
|
5758
|
+
return _updateAssistantAgent.apply(this, arguments);
|
|
5759
|
+
}
|
|
5760
|
+
return updateAssistantAgent;
|
|
5761
|
+
}();
|
|
5762
|
+
}
|
|
5763
|
+
function getAssistantAgentHandler(logger) {
|
|
5764
|
+
return /*#__PURE__*/function () {
|
|
5765
|
+
var _getAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref3) {
|
|
5766
|
+
var id, toolMap, tool_choice, agent, handleRunStatus, handleRequiresAction, getRun;
|
|
5767
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
5768
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
5769
|
+
case 0:
|
|
5770
|
+
id = _ref3.id, toolMap = _ref3.toolMap, tool_choice = _ref3.tool_choice;
|
|
5771
|
+
_context11.next = 3;
|
|
5772
|
+
return client.beta.assistants.retrieve(id);
|
|
5773
|
+
case 3:
|
|
5774
|
+
agent = _context11.sent;
|
|
5775
|
+
handleRunStatus = /*#__PURE__*/function () {
|
|
5776
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
5777
|
+
var threadId, run, _messages$data, messages;
|
|
5778
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5779
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5791
5780
|
case 0:
|
|
5792
|
-
|
|
5793
|
-
|
|
5781
|
+
threadId = _ref4.threadId, run = _ref4.run;
|
|
5782
|
+
if (!(run.status === 'completed')) {
|
|
5783
|
+
_context3.next = 8;
|
|
5784
|
+
break;
|
|
5794
5785
|
}
|
|
5795
|
-
|
|
5796
|
-
return client.beta.threads.create({
|
|
5797
|
-
messages: messages
|
|
5798
|
-
});
|
|
5799
|
-
case 3:
|
|
5800
|
-
return _context7.abrupt("return", _context7.sent);
|
|
5801
|
-
case 4:
|
|
5802
|
-
case "end":
|
|
5803
|
-
return _context7.stop();
|
|
5804
|
-
}
|
|
5805
|
-
}, _callee7);
|
|
5806
|
-
}));
|
|
5807
|
-
function initializeThread(_x10) {
|
|
5808
|
-
return _initializeThread.apply(this, arguments);
|
|
5809
|
-
}
|
|
5810
|
-
return initializeThread;
|
|
5811
|
-
}(),
|
|
5812
|
-
listMessages: function () {
|
|
5813
|
-
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
5814
|
-
var threadId;
|
|
5815
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5816
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
5817
|
-
case 0:
|
|
5818
|
-
threadId = _ref11.threadId;
|
|
5819
|
-
_context8.next = 3;
|
|
5786
|
+
_context3.next = 4;
|
|
5820
5787
|
return client.beta.threads.messages.list(threadId);
|
|
5821
|
-
case 3:
|
|
5822
|
-
return _context8.abrupt("return", _context8.sent);
|
|
5823
5788
|
case 4:
|
|
5824
|
-
|
|
5825
|
-
return
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
handleRunStatus: handleRunStatus,
|
|
5836
|
-
handleRequiresAction: handleRequiresAction,
|
|
5837
|
-
createUserMessage: function () {
|
|
5838
|
-
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
5839
|
-
var threadId, content;
|
|
5840
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
5841
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
5842
|
-
case 0:
|
|
5843
|
-
threadId = _ref12.threadId, content = _ref12.content;
|
|
5844
|
-
_context9.next = 3;
|
|
5845
|
-
return client.beta.threads.messages.create(threadId, {
|
|
5846
|
-
role: 'user',
|
|
5847
|
-
content: content
|
|
5789
|
+
messages = _context3.sent;
|
|
5790
|
+
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5791
|
+
case 8:
|
|
5792
|
+
if (!(run.status === 'requires_action')) {
|
|
5793
|
+
_context3.next = 14;
|
|
5794
|
+
break;
|
|
5795
|
+
}
|
|
5796
|
+
_context3.next = 11;
|
|
5797
|
+
return handleRequiresAction({
|
|
5798
|
+
run: run,
|
|
5799
|
+
threadId: threadId
|
|
5848
5800
|
});
|
|
5849
|
-
case
|
|
5850
|
-
return
|
|
5851
|
-
case
|
|
5801
|
+
case 11:
|
|
5802
|
+
return _context3.abrupt("return", _context3.sent);
|
|
5803
|
+
case 14:
|
|
5804
|
+
console.error('Run did not complete:', run);
|
|
5805
|
+
logger({
|
|
5806
|
+
destinationPath: id + ".json",
|
|
5807
|
+
statusCode: 400,
|
|
5808
|
+
message: JSON.stringify({
|
|
5809
|
+
message: "Run did not complete",
|
|
5810
|
+
event_type: 'run_error',
|
|
5811
|
+
metadata: {
|
|
5812
|
+
run: run
|
|
5813
|
+
}
|
|
5814
|
+
}, null, 2)
|
|
5815
|
+
});
|
|
5816
|
+
case 16:
|
|
5852
5817
|
case "end":
|
|
5853
|
-
return
|
|
5818
|
+
return _context3.stop();
|
|
5854
5819
|
}
|
|
5855
|
-
},
|
|
5820
|
+
}, _callee3);
|
|
5856
5821
|
}));
|
|
5857
|
-
function
|
|
5858
|
-
return
|
|
5859
|
-
}
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
5822
|
+
return function handleRunStatus(_x4) {
|
|
5823
|
+
return _ref5.apply(this, arguments);
|
|
5824
|
+
};
|
|
5825
|
+
}();
|
|
5826
|
+
handleRequiresAction = /*#__PURE__*/function () {
|
|
5827
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5828
|
+
var threadId, run, toolOutputs;
|
|
5829
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5830
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
5867
5831
|
case 0:
|
|
5868
|
-
|
|
5869
|
-
if (!
|
|
5870
|
-
|
|
5832
|
+
threadId = _ref6.threadId, run = _ref6.run;
|
|
5833
|
+
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5834
|
+
_context5.next = 23;
|
|
5871
5835
|
break;
|
|
5872
5836
|
}
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5837
|
+
_context5.t0 = compact;
|
|
5838
|
+
_context5.next = 5;
|
|
5839
|
+
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5840
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5841
|
+
var callInfo, toolMetadata, toolFn, args, output;
|
|
5842
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5843
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5844
|
+
case 0:
|
|
5845
|
+
callInfo = index + 1 + " of " + tools.length;
|
|
5846
|
+
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5847
|
+
toolMetadata = {
|
|
5848
|
+
id: tool.id,
|
|
5849
|
+
fn: tool["function"].name,
|
|
5850
|
+
availableTools: Object.keys(toolMap)
|
|
5851
|
+
};
|
|
5852
|
+
logger({
|
|
5853
|
+
destinationPath: id + ".json",
|
|
5854
|
+
statusCode: 100,
|
|
5855
|
+
message: JSON.stringify({
|
|
5856
|
+
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5857
|
+
metadata: {
|
|
5858
|
+
tool: toolMetadata
|
|
5859
|
+
}
|
|
5860
|
+
}, null, 2)
|
|
5861
|
+
});
|
|
5862
|
+
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5863
|
+
if (toolFn) {
|
|
5864
|
+
_context4.next = 8;
|
|
5865
|
+
break;
|
|
5866
|
+
}
|
|
5867
|
+
logger({
|
|
5868
|
+
destinationPath: id + ".json",
|
|
5869
|
+
statusCode: 404,
|
|
5870
|
+
message: JSON.stringify({
|
|
5871
|
+
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5872
|
+
metadata: {
|
|
5873
|
+
tool: toolMetadata
|
|
5874
|
+
}
|
|
5875
|
+
}, null, 2)
|
|
5876
|
+
});
|
|
5877
|
+
return _context4.abrupt("return");
|
|
5878
|
+
case 8:
|
|
5879
|
+
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5880
|
+
args = {};
|
|
5881
|
+
try {
|
|
5882
|
+
if (tool["function"].arguments) {
|
|
5883
|
+
args = JSON.parse(tool["function"].arguments);
|
|
5884
|
+
logger({
|
|
5885
|
+
destinationPath: id + ".json",
|
|
5886
|
+
statusCode: 200,
|
|
5887
|
+
message: JSON.stringify({
|
|
5888
|
+
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5889
|
+
metadata: {
|
|
5890
|
+
args: args,
|
|
5891
|
+
tool: toolMetadata
|
|
5892
|
+
}
|
|
5893
|
+
}, null, 2)
|
|
5894
|
+
});
|
|
5895
|
+
}
|
|
5896
|
+
} catch (e) {
|
|
5897
|
+
console.error(e);
|
|
5898
|
+
}
|
|
5899
|
+
_context4.next = 13;
|
|
5900
|
+
return toolFn(args);
|
|
5901
|
+
case 13:
|
|
5902
|
+
output = _context4.sent;
|
|
5903
|
+
logger({
|
|
5904
|
+
destinationPath: id + ".json",
|
|
5905
|
+
statusCode: 200,
|
|
5906
|
+
message: JSON.stringify({
|
|
5907
|
+
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5908
|
+
metadata: {
|
|
5909
|
+
output: output,
|
|
5910
|
+
tool: toolMetadata
|
|
5911
|
+
}
|
|
5912
|
+
}, null, 2)
|
|
5913
|
+
});
|
|
5914
|
+
return _context4.abrupt("return", {
|
|
5915
|
+
tool_call_id: tool.id,
|
|
5916
|
+
output: JSON.stringify(output)
|
|
5917
|
+
});
|
|
5918
|
+
case 16:
|
|
5919
|
+
case "end":
|
|
5920
|
+
return _context4.stop();
|
|
5921
|
+
}
|
|
5922
|
+
}, _callee4);
|
|
5923
|
+
}));
|
|
5924
|
+
return function (_x6, _x7, _x8) {
|
|
5925
|
+
return _ref8.apply(this, arguments);
|
|
5926
|
+
};
|
|
5927
|
+
}()));
|
|
5928
|
+
case 5:
|
|
5929
|
+
_context5.t1 = _context5.sent;
|
|
5930
|
+
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5931
|
+
if (toolOutputs) {
|
|
5932
|
+
_context5.next = 11;
|
|
5933
|
+
break;
|
|
5934
|
+
}
|
|
5935
|
+
console.error('No tool outputs to submit.');
|
|
5936
|
+
logger({
|
|
5937
|
+
destinationPath: id + ".json",
|
|
5938
|
+
statusCode: 404,
|
|
5939
|
+
message: JSON.stringify({
|
|
5940
|
+
message: "No tool outputs submitted",
|
|
5941
|
+
metadata: {}
|
|
5942
|
+
}, null, 2)
|
|
5877
5943
|
});
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
case
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5944
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5945
|
+
threadId: threadId,
|
|
5946
|
+
run: run
|
|
5947
|
+
}));
|
|
5948
|
+
case 11:
|
|
5949
|
+
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5950
|
+
_context5.next = 20;
|
|
5951
|
+
break;
|
|
5952
|
+
}
|
|
5953
|
+
console.log(toolOutputs, '###### YOOOOOO');
|
|
5954
|
+
_context5.next = 15;
|
|
5955
|
+
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5956
|
+
tool_outputs: toolOutputs
|
|
5887
5957
|
});
|
|
5888
|
-
case
|
|
5889
|
-
run =
|
|
5958
|
+
case 15:
|
|
5959
|
+
run = _context5.sent;
|
|
5890
5960
|
logger({
|
|
5891
|
-
|
|
5961
|
+
destinationPath: id + ".json",
|
|
5962
|
+
statusCode: 200,
|
|
5892
5963
|
message: JSON.stringify({
|
|
5893
|
-
message: "
|
|
5964
|
+
message: "Tool outputs submitted",
|
|
5894
5965
|
metadata: {
|
|
5895
|
-
run: run
|
|
5896
|
-
tool_choice: 'required',
|
|
5897
|
-
threadId: threadId,
|
|
5898
|
-
assistant_id: id
|
|
5966
|
+
run: run
|
|
5899
5967
|
}
|
|
5900
5968
|
}, null, 2)
|
|
5901
5969
|
});
|
|
5902
|
-
|
|
5903
|
-
|
|
5970
|
+
console.log('Tool outputs submitted successfully.');
|
|
5971
|
+
_context5.next = 22;
|
|
5972
|
+
break;
|
|
5973
|
+
case 20:
|
|
5974
|
+
logger({
|
|
5975
|
+
destinationPath: id + ".json",
|
|
5976
|
+
statusCode: 404,
|
|
5977
|
+
message: JSON.stringify({
|
|
5978
|
+
message: "No tool outputs to submit",
|
|
5979
|
+
metadata: {}
|
|
5980
|
+
}, null, 2)
|
|
5981
|
+
});
|
|
5982
|
+
console.log('No tool outputs to submit.');
|
|
5983
|
+
case 22:
|
|
5984
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5904
5985
|
threadId: threadId,
|
|
5905
5986
|
run: run
|
|
5906
5987
|
}));
|
|
5907
|
-
case
|
|
5988
|
+
case 23:
|
|
5908
5989
|
case "end":
|
|
5909
|
-
return
|
|
5990
|
+
return _context5.stop();
|
|
5910
5991
|
}
|
|
5911
|
-
},
|
|
5992
|
+
}, _callee5);
|
|
5912
5993
|
}));
|
|
5913
|
-
function
|
|
5914
|
-
return
|
|
5915
|
-
}
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5994
|
+
return function handleRequiresAction(_x5) {
|
|
5995
|
+
return _ref7.apply(this, arguments);
|
|
5996
|
+
};
|
|
5997
|
+
}();
|
|
5998
|
+
getRun = /*#__PURE__*/function () {
|
|
5999
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref9) {
|
|
6000
|
+
var threadId, runId;
|
|
6001
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
6002
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
6003
|
+
case 0:
|
|
6004
|
+
threadId = _ref9.threadId, runId = _ref9.runId;
|
|
6005
|
+
_context6.next = 3;
|
|
6006
|
+
return client.beta.threads.runs.retrieve(threadId, runId);
|
|
6007
|
+
case 3:
|
|
6008
|
+
return _context6.abrupt("return", _context6.sent);
|
|
6009
|
+
case 4:
|
|
6010
|
+
case "end":
|
|
6011
|
+
return _context6.stop();
|
|
6012
|
+
}
|
|
6013
|
+
}, _callee6);
|
|
6014
|
+
}));
|
|
6015
|
+
return function getRun(_x9) {
|
|
6016
|
+
return _ref10.apply(this, arguments);
|
|
6017
|
+
};
|
|
6018
|
+
}();
|
|
6019
|
+
return _context11.abrupt("return", {
|
|
6020
|
+
agent: agent,
|
|
6021
|
+
initializeThread: function () {
|
|
6022
|
+
var _initializeThread = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(messages) {
|
|
6023
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
6024
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
6025
|
+
case 0:
|
|
6026
|
+
if (messages === void 0) {
|
|
6027
|
+
messages = [];
|
|
6028
|
+
}
|
|
6029
|
+
_context7.next = 3;
|
|
6030
|
+
return client.beta.threads.create({
|
|
6031
|
+
messages: messages
|
|
6032
|
+
});
|
|
6033
|
+
case 3:
|
|
6034
|
+
return _context7.abrupt("return", _context7.sent);
|
|
6035
|
+
case 4:
|
|
6036
|
+
case "end":
|
|
6037
|
+
return _context7.stop();
|
|
6038
|
+
}
|
|
6039
|
+
}, _callee7);
|
|
6040
|
+
}));
|
|
6041
|
+
function initializeThread(_x10) {
|
|
6042
|
+
return _initializeThread.apply(this, arguments);
|
|
6043
|
+
}
|
|
6044
|
+
return initializeThread;
|
|
6045
|
+
}(),
|
|
6046
|
+
listMessages: function () {
|
|
6047
|
+
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
6048
|
+
var threadId;
|
|
6049
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
6050
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
6051
|
+
case 0:
|
|
6052
|
+
threadId = _ref11.threadId;
|
|
6053
|
+
_context8.next = 3;
|
|
6054
|
+
return client.beta.threads.messages.list(threadId);
|
|
6055
|
+
case 3:
|
|
6056
|
+
return _context8.abrupt("return", _context8.sent);
|
|
6057
|
+
case 4:
|
|
6058
|
+
case "end":
|
|
6059
|
+
return _context8.stop();
|
|
6060
|
+
}
|
|
6061
|
+
}, _callee8);
|
|
6062
|
+
}));
|
|
6063
|
+
function listMessages(_x11) {
|
|
6064
|
+
return _listMessages.apply(this, arguments);
|
|
6065
|
+
}
|
|
6066
|
+
return listMessages;
|
|
6067
|
+
}(),
|
|
6068
|
+
getRun: getRun,
|
|
6069
|
+
handleRunStatus: handleRunStatus,
|
|
6070
|
+
handleRequiresAction: handleRequiresAction,
|
|
6071
|
+
createUserMessage: function () {
|
|
6072
|
+
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
6073
|
+
var threadId, content;
|
|
6074
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
6075
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
6076
|
+
case 0:
|
|
6077
|
+
threadId = _ref12.threadId, content = _ref12.content;
|
|
6078
|
+
_context9.next = 3;
|
|
6079
|
+
return client.beta.threads.messages.create(threadId, {
|
|
6080
|
+
role: 'user',
|
|
6081
|
+
content: content
|
|
6082
|
+
});
|
|
6083
|
+
case 3:
|
|
6084
|
+
return _context9.abrupt("return", _context9.sent);
|
|
6085
|
+
case 4:
|
|
6086
|
+
case "end":
|
|
6087
|
+
return _context9.stop();
|
|
6088
|
+
}
|
|
6089
|
+
}, _callee9);
|
|
6090
|
+
}));
|
|
6091
|
+
function createUserMessage(_x12) {
|
|
6092
|
+
return _createUserMessage.apply(this, arguments);
|
|
6093
|
+
}
|
|
6094
|
+
return createUserMessage;
|
|
6095
|
+
}(),
|
|
6096
|
+
watchRun: function () {
|
|
6097
|
+
var _watchRun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref13) {
|
|
6098
|
+
var runId, threadId, run;
|
|
6099
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
6100
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
6101
|
+
case 0:
|
|
6102
|
+
runId = _ref13.runId, threadId = _ref13.threadId;
|
|
6103
|
+
if (!runId) {
|
|
6104
|
+
_context10.next = 7;
|
|
6105
|
+
break;
|
|
6106
|
+
}
|
|
6107
|
+
_context10.next = 4;
|
|
6108
|
+
return getRun({
|
|
6109
|
+
threadId: threadId,
|
|
6110
|
+
runId: runId
|
|
6111
|
+
});
|
|
6112
|
+
case 4:
|
|
6113
|
+
run = _context10.sent;
|
|
6114
|
+
_context10.next = 11;
|
|
6115
|
+
break;
|
|
6116
|
+
case 7:
|
|
6117
|
+
_context10.next = 9;
|
|
6118
|
+
return client.beta.threads.runs.createAndPoll(threadId, {
|
|
6119
|
+
assistant_id: id,
|
|
6120
|
+
tool_choice: tool_choice
|
|
6121
|
+
});
|
|
6122
|
+
case 9:
|
|
6123
|
+
run = _context10.sent;
|
|
6124
|
+
logger({
|
|
6125
|
+
destinationPath: id + ".json",
|
|
6126
|
+
statusCode: 202,
|
|
6127
|
+
message: JSON.stringify({
|
|
6128
|
+
message: "Creating and polling run, tool choice required",
|
|
6129
|
+
metadata: {
|
|
6130
|
+
run: run,
|
|
6131
|
+
tool_choice: tool_choice,
|
|
6132
|
+
threadId: threadId,
|
|
6133
|
+
assistant_id: id
|
|
6134
|
+
}
|
|
6135
|
+
}, null, 2)
|
|
6136
|
+
});
|
|
6137
|
+
case 11:
|
|
6138
|
+
return _context10.abrupt("return", handleRunStatus({
|
|
6139
|
+
threadId: threadId,
|
|
6140
|
+
run: run
|
|
6141
|
+
}));
|
|
6142
|
+
case 12:
|
|
6143
|
+
case "end":
|
|
6144
|
+
return _context10.stop();
|
|
6145
|
+
}
|
|
6146
|
+
}, _callee10);
|
|
6147
|
+
}));
|
|
6148
|
+
function watchRun(_x13) {
|
|
6149
|
+
return _watchRun.apply(this, arguments);
|
|
6150
|
+
}
|
|
6151
|
+
return watchRun;
|
|
6152
|
+
}()
|
|
6153
|
+
});
|
|
6154
|
+
case 8:
|
|
6155
|
+
case "end":
|
|
6156
|
+
return _context11.stop();
|
|
6157
|
+
}
|
|
6158
|
+
}, _callee11);
|
|
6159
|
+
}));
|
|
6160
|
+
function getAssistantAgent(_x3) {
|
|
6161
|
+
return _getAssistantAgent.apply(this, arguments);
|
|
6162
|
+
}
|
|
6163
|
+
return getAssistantAgent;
|
|
6164
|
+
}();
|
|
5926
6165
|
}
|
|
5927
6166
|
|
|
5928
6167
|
var delay = function delay(ms) {
|
|
@@ -6149,20 +6388,24 @@ function getAgent(_x) {
|
|
|
6149
6388
|
}
|
|
6150
6389
|
function _getAgent() {
|
|
6151
6390
|
_getAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
6152
|
-
var
|
|
6391
|
+
var _agent$model$provider, _agent$model$provider2;
|
|
6392
|
+
var connectionId, agent, apis, logger, tools, toolMap, getAssistantAgent, assistant, _agent$model2, keyToModel, _tools, _toolMap, resultTool, schema, _agent$model;
|
|
6153
6393
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
6154
6394
|
while (1) switch (_context3.prev = _context3.next) {
|
|
6155
6395
|
case 0:
|
|
6156
|
-
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis;
|
|
6157
|
-
|
|
6158
|
-
|
|
6396
|
+
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis, logger = _ref.logger;
|
|
6397
|
+
console.log('get agent start, model provider====', agent.model.provider);
|
|
6398
|
+
if (!(((_agent$model$provider = agent.model.provider) == null ? void 0 : _agent$model$provider.toUpperCase()) === 'OPEN_AI_ASSISTANT')) {
|
|
6399
|
+
_context3.next = 15;
|
|
6159
6400
|
break;
|
|
6160
6401
|
}
|
|
6402
|
+
console.log('===in the model if block===');
|
|
6161
6403
|
tools = Object.keys(agent.tools);
|
|
6162
6404
|
toolMap = Object.entries(apis).reduce(function (memo, _ref2) {
|
|
6163
6405
|
var k = _ref2[0],
|
|
6164
6406
|
def = _ref2[1];
|
|
6165
6407
|
if (tools.includes(k)) {
|
|
6408
|
+
console.log(k + " tool included, run executorx====");
|
|
6166
6409
|
memo[k] = /*#__PURE__*/function () {
|
|
6167
6410
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
6168
6411
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -6187,17 +6430,21 @@ function _getAgent() {
|
|
|
6187
6430
|
}
|
|
6188
6431
|
return memo;
|
|
6189
6432
|
}, {});
|
|
6190
|
-
|
|
6433
|
+
console.log('toolmap====', JSON.stringify(toolMap, null, 2));
|
|
6434
|
+
getAssistantAgent = getAssistantAgentHandler(logger);
|
|
6435
|
+
_context3.next = 10;
|
|
6191
6436
|
return getAssistantAgent({
|
|
6192
6437
|
id: agent.id,
|
|
6193
|
-
toolMap: toolMap
|
|
6438
|
+
toolMap: toolMap,
|
|
6439
|
+
tool_choice: agent.model.toolChoice
|
|
6194
6440
|
});
|
|
6195
|
-
case
|
|
6441
|
+
case 10:
|
|
6196
6442
|
assistant = _context3.sent;
|
|
6443
|
+
console.log('got assistant===', assistant);
|
|
6197
6444
|
return _context3.abrupt("return", assistant);
|
|
6198
|
-
case
|
|
6199
|
-
if (!['OPEN_AI_VERCEL', 'ANTHROPIC_VERCEL', 'GROQ_VERCEL', 'PERPLEXITY_VERCEL', 'FIREWORKS_VERCEL'].includes(agent.model.provider)) {
|
|
6200
|
-
_context3.next =
|
|
6445
|
+
case 15:
|
|
6446
|
+
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())) {
|
|
6447
|
+
_context3.next = 24;
|
|
6201
6448
|
break;
|
|
6202
6449
|
}
|
|
6203
6450
|
keyToModel = {
|
|
@@ -6264,7 +6511,7 @@ function _getAgent() {
|
|
|
6264
6511
|
};
|
|
6265
6512
|
}
|
|
6266
6513
|
if (!(agent.model.generation_type === 'stream')) {
|
|
6267
|
-
_context3.next =
|
|
6514
|
+
_context3.next = 23;
|
|
6268
6515
|
break;
|
|
6269
6516
|
}
|
|
6270
6517
|
return _context3.abrupt("return", createStreamAgent({
|
|
@@ -6277,7 +6524,7 @@ function _getAgent() {
|
|
|
6277
6524
|
tools: _toolMap,
|
|
6278
6525
|
resultTool: resultTool
|
|
6279
6526
|
}));
|
|
6280
|
-
case
|
|
6527
|
+
case 23:
|
|
6281
6528
|
return _context3.abrupt("return", createAgent({
|
|
6282
6529
|
agent_instructions: agent.agent_instructions,
|
|
6283
6530
|
model: {
|
|
@@ -6288,7 +6535,7 @@ function _getAgent() {
|
|
|
6288
6535
|
tools: _toolMap,
|
|
6289
6536
|
resultTool: resultTool
|
|
6290
6537
|
}));
|
|
6291
|
-
case
|
|
6538
|
+
case 24:
|
|
6292
6539
|
case "end":
|
|
6293
6540
|
return _context3.stop();
|
|
6294
6541
|
}
|
|
@@ -6297,6 +6544,67 @@ function _getAgent() {
|
|
|
6297
6544
|
return _getAgent.apply(this, arguments);
|
|
6298
6545
|
}
|
|
6299
6546
|
|
|
6547
|
+
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
6548
|
+
function createFileLogger() {
|
|
6549
|
+
return function (log) {
|
|
6550
|
+
var fullPath = path.join(loggerPath, log.destinationPath);
|
|
6551
|
+
if (!existsSync(loggerPath)) {
|
|
6552
|
+
mkdirSync(loggerPath, {
|
|
6553
|
+
recursive: true
|
|
6554
|
+
});
|
|
6555
|
+
return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
6556
|
+
createdAt: new Date()
|
|
6557
|
+
})], null, 2));
|
|
6558
|
+
}
|
|
6559
|
+
if (!existsSync(fullPath)) {
|
|
6560
|
+
return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
6561
|
+
createdAt: new Date()
|
|
6562
|
+
})], null, 2));
|
|
6563
|
+
}
|
|
6564
|
+
var logs = JSON.parse(readFileSync(fullPath, 'utf-8'));
|
|
6565
|
+
logs.push(_extends({}, log, {
|
|
6566
|
+
createdAt: new Date()
|
|
6567
|
+
}));
|
|
6568
|
+
return writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
6569
|
+
};
|
|
6570
|
+
}
|
|
6571
|
+
function getUpstashLogs(_x) {
|
|
6572
|
+
return _getUpstashLogs.apply(this, arguments);
|
|
6573
|
+
}
|
|
6574
|
+
function _getUpstashLogs() {
|
|
6575
|
+
_getUpstashLogs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
6576
|
+
var id, url, token, redis;
|
|
6577
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
6578
|
+
while (1) switch (_context.prev = _context.next) {
|
|
6579
|
+
case 0:
|
|
6580
|
+
id = _ref.id, url = _ref.url, token = _ref.token;
|
|
6581
|
+
redis = new Redis({
|
|
6582
|
+
url: url,
|
|
6583
|
+
token: token
|
|
6584
|
+
});
|
|
6585
|
+
return _context.abrupt("return", redis.lrange(id, 0, -1));
|
|
6586
|
+
case 3:
|
|
6587
|
+
case "end":
|
|
6588
|
+
return _context.stop();
|
|
6589
|
+
}
|
|
6590
|
+
}, _callee);
|
|
6591
|
+
}));
|
|
6592
|
+
return _getUpstashLogs.apply(this, arguments);
|
|
6593
|
+
}
|
|
6594
|
+
function createUpstashLogger(_ref2) {
|
|
6595
|
+
var url = _ref2.url,
|
|
6596
|
+
token = _ref2.token;
|
|
6597
|
+
var redis = new Redis({
|
|
6598
|
+
url: url,
|
|
6599
|
+
token: token
|
|
6600
|
+
});
|
|
6601
|
+
return function (log) {
|
|
6602
|
+
redis.lpush(log.destinationPath, JSON.stringify(_extends({}, log, {
|
|
6603
|
+
createdAt: new Date()
|
|
6604
|
+
})));
|
|
6605
|
+
};
|
|
6606
|
+
}
|
|
6607
|
+
|
|
6300
6608
|
var Mastra = /*#__PURE__*/function () {
|
|
6301
6609
|
function Mastra(_ref) {
|
|
6302
6610
|
var _this = this;
|
|
@@ -6314,6 +6622,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6314
6622
|
agentDirPath: '',
|
|
6315
6623
|
vectorProvider: []
|
|
6316
6624
|
};
|
|
6625
|
+
this.logger = void 0;
|
|
6317
6626
|
this.config = void 0;
|
|
6318
6627
|
this.runBlueprint = /*#__PURE__*/function () {
|
|
6319
6628
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
@@ -6364,7 +6673,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6364
6673
|
this.config = config;
|
|
6365
6674
|
}
|
|
6366
6675
|
Mastra.init = function init(config) {
|
|
6367
|
-
var _config$workflows$sys;
|
|
6676
|
+
var _config$logs, _config$logs2, _config$workflows$sys;
|
|
6368
6677
|
if (!config.db.uri) {
|
|
6369
6678
|
throw new Error('No database config/provider found');
|
|
6370
6679
|
}
|
|
@@ -6378,20 +6687,33 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6378
6687
|
dataLayer: dataLayer,
|
|
6379
6688
|
vectorLayer: vectorLayer
|
|
6380
6689
|
});
|
|
6690
|
+
var logger;
|
|
6691
|
+
if (!(config != null && config.logs)) {
|
|
6692
|
+
logger = console.log;
|
|
6693
|
+
} else if (((_config$logs = config.logs) == null ? void 0 : _config$logs.provider) === 'FILE') {
|
|
6694
|
+
logger = createFileLogger();
|
|
6695
|
+
} else if (((_config$logs2 = config.logs) == null ? void 0 : _config$logs2.provider) === 'UPSTASH') {
|
|
6696
|
+
var _config$logs$config, _config$logs$config2;
|
|
6697
|
+
logger = createUpstashLogger({
|
|
6698
|
+
url: (_config$logs$config = config.logs.config) == null ? void 0 : _config$logs$config.url,
|
|
6699
|
+
token: (_config$logs$config2 = config.logs.config) == null ? void 0 : _config$logs$config2.token
|
|
6700
|
+
});
|
|
6701
|
+
}
|
|
6702
|
+
framework.attachLogger(logger);
|
|
6381
6703
|
// Register integrations
|
|
6382
6704
|
config.integrations.forEach(function (integration) {
|
|
6383
6705
|
framework.__registerIntgeration(integration);
|
|
6384
6706
|
});
|
|
6385
6707
|
// Register system apis
|
|
6386
6708
|
framework.__registerApis({
|
|
6387
|
-
apis: [].concat(
|
|
6709
|
+
apis: [].concat(getVectorQueryApis({
|
|
6710
|
+
mastra: framework
|
|
6711
|
+
}), getAgentSystemApis({
|
|
6388
6712
|
mastra: framework
|
|
6389
6713
|
}), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
|
|
6390
6714
|
return _extends({}, api, {
|
|
6391
6715
|
integrationName: config.name
|
|
6392
6716
|
});
|
|
6393
|
-
}), getVectorQueryApis({
|
|
6394
|
-
mastra: framework
|
|
6395
6717
|
}), [{
|
|
6396
6718
|
integrationName: config.name,
|
|
6397
6719
|
type: 'trigger_event',
|
|
@@ -6497,6 +6819,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
6497
6819
|
return framework;
|
|
6498
6820
|
};
|
|
6499
6821
|
var _proto = Mastra.prototype;
|
|
6822
|
+
_proto.attachLogger = function attachLogger(logger) {
|
|
6823
|
+
this.logger = logger;
|
|
6824
|
+
};
|
|
6500
6825
|
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
6501
6826
|
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref8) {
|
|
6502
6827
|
var _this2 = this;
|
|
@@ -7242,12 +7567,14 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7242
7567
|
var v = _ref30[1];
|
|
7243
7568
|
return _extends({}, acc, v);
|
|
7244
7569
|
}, {});
|
|
7570
|
+
console.log('got finalApis===');
|
|
7245
7571
|
return _context15.abrupt("return", getAgent({
|
|
7246
7572
|
connectionId: connectionId,
|
|
7247
7573
|
agent: agentBlueprint,
|
|
7248
|
-
apis: finalApis
|
|
7574
|
+
apis: finalApis,
|
|
7575
|
+
logger: this.logger
|
|
7249
7576
|
}));
|
|
7250
|
-
case
|
|
7577
|
+
case 8:
|
|
7251
7578
|
case "end":
|
|
7252
7579
|
return _context15.stop();
|
|
7253
7580
|
}
|
|
@@ -7275,8 +7602,17 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
7275
7602
|
return _extends({}, acc, (_extends5 = {}, _extends5[key] = "" + _this5.config.routeRegistrationPath + value, _extends5));
|
|
7276
7603
|
}, {});
|
|
7277
7604
|
}
|
|
7605
|
+
}, {
|
|
7606
|
+
key: "openAIAssistant",
|
|
7607
|
+
get: function get() {
|
|
7608
|
+
return {
|
|
7609
|
+
createAssistantAgent: createAssistantAgentHandler(this.logger),
|
|
7610
|
+
getAssistantAgent: getAssistantAgentHandler(this.logger),
|
|
7611
|
+
updateAssistantAgent: updateAssistantAgentHandler(this.logger)
|
|
7612
|
+
};
|
|
7613
|
+
}
|
|
7278
7614
|
}]);
|
|
7279
7615
|
}();
|
|
7280
7616
|
|
|
7281
|
-
export { DataLayer, FieldTypePrimitiveMap, FilterOperatorToSQL, FilterOperators, Integration, IntegrationAuth, IntegrationCredentialType, IntegrationError, IntegrationErrors, IntegrationFieldTypeEnum, Mastra, RunStatus, SORT_MODE_TO_ABBR, WorkflowStatusEnum, allowedKey, apiKeyConnectionOptions, buildQueryString, callbackParams, connectParams, constructObjFromStringPath, extractSchemaOptions, fieldsWithCommaSeparatedValues, filterQuerySchema, flattenObject, generateSyncs, getEntityKey, getJSONField, getPath, getResponseDataKey, isLiteralObject, isObjectEmpty, mergeWithDefinedOnly, nextHeaders, oauthState, parseQueryParams, recordHasData, registerRoutes, sortQuerySchema, splitAndStripQuotes, transformFilterValueArray, transformFilterValueBoolean, webhookQueryParams };
|
|
7617
|
+
export { DataLayer, FieldTypePrimitiveMap, FilterOperatorToSQL, FilterOperators, Integration, IntegrationAuth, IntegrationCredentialType, IntegrationError, IntegrationErrors, IntegrationFieldTypeEnum, Mastra, RunStatus, SORT_MODE_TO_ABBR, WorkflowStatusEnum, allowedKey, apiKeyConnectionOptions, buildQueryString, callbackParams, connectParams, constructObjFromStringPath, extractSchemaOptions, fieldsWithCommaSeparatedValues, filterQuerySchema, flattenObject, generateSyncs, getEntityKey, getJSONField, getPath, getPineconeIndices, getResponseDataKey, getUpstashLogs, isLiteralObject, isObjectEmpty, mergeWithDefinedOnly, nextHeaders, oauthState, parseQueryParams, recordHasData, registerRoutes, sortQuerySchema, splitAndStripQuotes, transformFilterValueArray, transformFilterValueBoolean, webhookQueryParams };
|
|
7282
7618
|
//# sourceMappingURL=core.esm.js.map
|