@mastra/core 0.1.3 → 0.1.5
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 +31 -0
- package/dist/agents/agent-apis.d.ts.map +1 -0
- package/dist/agents/file-logger.d.ts +7 -0
- package/dist/agents/file-logger.d.ts.map +1 -0
- package/dist/agents/index.d.ts +49 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/openai/assistant.d.ts +55 -0
- package/dist/agents/openai/assistant.d.ts.map +1 -0
- package/dist/agents/utils.d.ts +12 -0
- package/dist/agents/utils.d.ts.map +1 -0
- package/dist/agents/vector-sync.d.ts +46 -0
- package/dist/agents/vector-sync.d.ts.map +1 -0
- package/dist/agents/vercel/index.d.ts +44 -0
- package/dist/agents/vercel/index.d.ts.map +1 -0
- package/dist/authenticator.d.ts +1 -0
- package/dist/authenticator.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core.cjs.development.js +2143 -354
- 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 +2128 -338
- package/dist/core.esm.js.map +1 -1
- package/dist/data-access/index.d.ts +1 -0
- package/dist/data-access/index.d.ts.map +1 -0
- package/dist/framework.d.ts +54 -6
- package/dist/framework.d.ts.map +1 -0
- package/dist/generated-types/index.d.ts +1 -0
- package/dist/generated-types/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/integration.d.ts +2 -4
- package/dist/integration.d.ts.map +1 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/query-builder/constants.d.ts +1 -0
- package/dist/lib/query-builder/constants.d.ts.map +1 -0
- package/dist/lib/query-builder/filters/sql.d.ts +1 -0
- package/dist/lib/query-builder/filters/sql.d.ts.map +1 -0
- package/dist/lib/query-builder/schema.d.ts +1 -0
- package/dist/lib/query-builder/schema.d.ts.map +1 -0
- package/dist/lib/query-builder/sorts/sql.d.ts +1 -0
- package/dist/lib/query-builder/sorts/sql.d.ts.map +1 -0
- package/dist/lib/query-builder/types.d.ts +1 -0
- package/dist/lib/query-builder/types.d.ts.map +1 -0
- package/dist/lib/query-builder/utils.d.ts +1 -0
- package/dist/lib/query-builder/utils.d.ts.map +1 -0
- package/dist/lib/utils/object.d.ts +1 -0
- package/dist/lib/utils/object.d.ts.map +1 -0
- package/dist/next/callback.d.ts +3 -2
- package/dist/next/callback.d.ts.map +1 -0
- package/dist/next/connect.d.ts +3 -2
- package/dist/next/connect.d.ts.map +1 -0
- package/dist/next/index.d.ts +3 -2
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/inngest.d.ts +3 -2
- package/dist/next/inngest.d.ts.map +1 -0
- package/dist/next/utils.d.ts +1 -0
- package/dist/next/utils.d.ts.map +1 -0
- package/dist/next/webhook.d.ts +3 -2
- package/dist/next/webhook.d.ts.map +1 -0
- package/dist/prisma/client.d.ts +1 -0
- package/dist/prisma/client.d.ts.map +1 -0
- package/dist/schemas.d.ts +1 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/service/service.property.d.ts +1 -0
- package/dist/service/service.property.d.ts.map +1 -0
- package/dist/service/service.record.d.ts +1 -0
- package/dist/service/service.record.d.ts.map +1 -0
- package/dist/sync-factory.d.ts +1 -0
- package/dist/sync-factory.d.ts.map +1 -0
- package/dist/sync-fixtures/github.d.ts +1 -0
- package/dist/sync-fixtures/github.d.ts.map +1 -0
- package/dist/sync-fixtures/stripe.d.ts +1 -0
- package/dist/sync-fixtures/stripe.d.ts.map +1 -0
- package/dist/types.d.ts +46 -30
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/inngest.d.ts +1 -0
- package/dist/utils/inngest.d.ts.map +1 -0
- package/dist/vector-access/index.d.ts +7 -0
- package/dist/vector-access/index.d.ts.map +1 -0
- package/dist/workflows/conditions/constants.d.ts +1 -0
- package/dist/workflows/conditions/constants.d.ts.map +1 -0
- package/dist/workflows/conditions/types.d.ts +1 -0
- package/dist/workflows/conditions/types.d.ts.map +1 -0
- package/dist/workflows/handler.d.ts +1 -0
- package/dist/workflows/handler.d.ts.map +1 -0
- package/dist/workflows/runner.d.ts +1 -0
- package/dist/workflows/runner.d.ts.map +1 -0
- package/dist/workflows/schemas.d.ts +1 -0
- package/dist/workflows/schemas.d.ts.map +1 -0
- package/dist/workflows/types.d.ts +1 -0
- package/dist/workflows/types.d.ts.map +1 -0
- package/dist/workflows/utils.d.ts +1 -0
- package/dist/workflows/utils.d.ts.map +1 -0
- package/package.json +6 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client$
|
|
5
|
+
var client$2 = require('@prisma-app/client');
|
|
6
6
|
var utc = require('@date-fns/utc');
|
|
7
7
|
var dateFns = require('date-fns');
|
|
8
8
|
var library = require('@prisma/client/runtime/library');
|
|
@@ -18,6 +18,11 @@ var last = require('lodash/last');
|
|
|
18
18
|
var inngest = require('inngest');
|
|
19
19
|
var oauth2Client = require('@badgateway/oauth2-client');
|
|
20
20
|
var _ = require('lodash');
|
|
21
|
+
var openai = require('@ai-sdk/openai');
|
|
22
|
+
var ai = require('ai');
|
|
23
|
+
var pinecone = require('@pinecone-database/pinecone');
|
|
24
|
+
var OpenAI = require('openai');
|
|
25
|
+
var anthropic = require('@ai-sdk/anthropic');
|
|
21
26
|
|
|
22
27
|
function _interopNamespaceDefault(e) {
|
|
23
28
|
var n = Object.create(null);
|
|
@@ -529,7 +534,7 @@ var prisma = function prisma(url) {
|
|
|
529
534
|
console.log('Reusing Global Prisma Client...');
|
|
530
535
|
prismaInstance = globalForPrisma.standardPrisma;
|
|
531
536
|
} else {
|
|
532
|
-
prismaInstance = new client$
|
|
537
|
+
prismaInstance = new client$2.PrismaClient({
|
|
533
538
|
datasourceUrl: url,
|
|
534
539
|
log: logLevels
|
|
535
540
|
});
|
|
@@ -595,7 +600,7 @@ exports.FilterOperators = void 0;
|
|
|
595
600
|
|
|
596
601
|
var _FieldTypePrimitiveMa, _FilterOperatorToSQL;
|
|
597
602
|
var fieldsWithCommaSeparatedValues = ['SINGLE_SELECT', 'MULTI_SELECT', 'USER', 'COMPANY', 'CONTACT'];
|
|
598
|
-
var FieldTypePrimitiveMap = (_FieldTypePrimitiveMa = {}, _FieldTypePrimitiveMa[client$
|
|
603
|
+
var FieldTypePrimitiveMap = (_FieldTypePrimitiveMa = {}, _FieldTypePrimitiveMa[client$2.PropertyType.BADGE_LIST] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.CHECKBOX] = 'boolean', _FieldTypePrimitiveMa[client$2.PropertyType.BOOLEAN] = 'boolean', _FieldTypePrimitiveMa[client$2.PropertyType.NUMBER] = 'number', _FieldTypePrimitiveMa[client$2.PropertyType.FLOAT] = 'number', _FieldTypePrimitiveMa[client$2.PropertyType.JSON_ARRAY] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.JSON_OBJECT] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.CURRENCY] = 'number', _FieldTypePrimitiveMa[client$2.PropertyType.DATE] = 'date', _FieldTypePrimitiveMa[client$2.PropertyType.LONG_TEXT] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.MULTI_SELECT] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.PHONE] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.SINGLE_LINE_TEXT] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.SINGLE_SELECT] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.URL] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.USER] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.CONTACT] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.COMPANY] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.COMPOSITE] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.PERSON] = 'string', _FieldTypePrimitiveMa[client$2.PropertyType.ENRICHMENT] = 'string', _FieldTypePrimitiveMa);
|
|
599
604
|
var SORT_MODE_TO_ABBR = {
|
|
600
605
|
ascending: 'asc',
|
|
601
606
|
descending: 'desc'
|
|
@@ -714,7 +719,7 @@ var getFilterClauseSQL = function getFilterClauseSQL(_ref) {
|
|
|
714
719
|
var _fields$find;
|
|
715
720
|
var fieldType = (fields == null || (_fields$find = fields.find(function (f) {
|
|
716
721
|
return field.startsWith(f.name);
|
|
717
|
-
})) == null ? void 0 : _fields$find.type) || client$
|
|
722
|
+
})) == null ? void 0 : _fields$find.type) || client$2.PropertyType.SINGLE_LINE_TEXT;
|
|
718
723
|
var column = "\"mastra\".\"" + table + "\".\"" + field + "\"";
|
|
719
724
|
var operators = Object.keys(filter);
|
|
720
725
|
var logicOperator = filter.op || 'or';
|
|
@@ -727,11 +732,11 @@ var getFilterClauseSQL = function getFilterClauseSQL(_ref) {
|
|
|
727
732
|
childField = _field$split[1];
|
|
728
733
|
fieldType = (fields == null || (_fields$find2 = fields.find(function (f) {
|
|
729
734
|
return f.name === childField;
|
|
730
|
-
})) == null ? void 0 : _fields$find2.type) || client$
|
|
735
|
+
})) == null ? void 0 : _fields$find2.type) || client$2.PropertyType.SINGLE_LINE_TEXT;
|
|
731
736
|
var JSONField = "\"mastra\".\"" + table + "\".\"" + parentField + "\"->>'" + childField + "'";
|
|
732
737
|
column = getJSONField(JSONField, fieldType);
|
|
733
738
|
}
|
|
734
|
-
var primitiveType = FieldTypePrimitiveMap[fieldType || client$
|
|
739
|
+
var primitiveType = FieldTypePrimitiveMap[fieldType || client$2.PropertyType.SINGLE_LINE_TEXT];
|
|
735
740
|
var clauses = operators.filter(function (op) {
|
|
736
741
|
return op !== exports.FilterOperators.OP;
|
|
737
742
|
}).map(function (op) {
|
|
@@ -830,7 +835,7 @@ var getSortClauseSQL = function getSortClauseSQL(_ref) {
|
|
|
830
835
|
childField = _field$split[1];
|
|
831
836
|
var fieldType = (fields == null || (_fields$find = fields.find(function (f) {
|
|
832
837
|
return f.name === childField;
|
|
833
|
-
})) == null ? void 0 : _fields$find.type) || client$
|
|
838
|
+
})) == null ? void 0 : _fields$find.type) || client$2.PropertyType.SINGLE_LINE_TEXT;
|
|
834
839
|
var JSONField = "\"mastra\".\"" + parentTableRef + "\".\"" + parentField + "\"->>'" + childField + "'";
|
|
835
840
|
var column = getJSONField(JSONField, fieldType);
|
|
836
841
|
return column + " " + order.toUpperCase();
|
|
@@ -1422,7 +1427,7 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1422
1427
|
});
|
|
1423
1428
|
})
|
|
1424
1429
|
}) : undefined;
|
|
1425
|
-
updatePromise = toUpdate.length ? this.db.$executeRaw(client$
|
|
1430
|
+
updatePromise = toUpdate.length ? this.db.$executeRaw(client$2.Prisma.raw("\n WITH updated_records (\"externalId\", \"data\") AS (\n VALUES\n " + toUpdate.map(function (_ref14) {
|
|
1426
1431
|
var externalId = _ref14.externalId,
|
|
1427
1432
|
data = _ref14.data;
|
|
1428
1433
|
return "('" + externalId + "', '" + JSON.stringify(data).replace(/'/g, "''") + "'::jsonb)";
|
|
@@ -1573,7 +1578,7 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1573
1578
|
},
|
|
1574
1579
|
data: {
|
|
1575
1580
|
path: [propertyName],
|
|
1576
|
-
not: client$
|
|
1581
|
+
not: client$2.Prisma.JsonNull
|
|
1577
1582
|
}
|
|
1578
1583
|
}
|
|
1579
1584
|
}));
|
|
@@ -1863,7 +1868,7 @@ var makeCallback = function makeCallback(framework) {
|
|
|
1863
1868
|
};
|
|
1864
1869
|
|
|
1865
1870
|
var APP_ID = 'mastra';
|
|
1866
|
-
var client = /*#__PURE__*/new inngest.Inngest({
|
|
1871
|
+
var client$1 = /*#__PURE__*/new inngest.Inngest({
|
|
1867
1872
|
id: APP_ID
|
|
1868
1873
|
});
|
|
1869
1874
|
|
|
@@ -1970,7 +1975,7 @@ function _getBlueprints() {
|
|
|
1970
1975
|
var createWorkflowHandler = function createWorkflowHandler(_ref2) {
|
|
1971
1976
|
var blueprintDirPath = _ref2.blueprintDirPath,
|
|
1972
1977
|
runBlueprint = _ref2.runBlueprint;
|
|
1973
|
-
return client.createFunction({
|
|
1978
|
+
return client$1.createFunction({
|
|
1974
1979
|
id: 'workflow-executor',
|
|
1975
1980
|
retries: 0
|
|
1976
1981
|
}, {
|
|
@@ -2065,18 +2070,35 @@ var makeInngest = function makeInngest(framework) {
|
|
|
2065
2070
|
// TODO: hook into framework to add framework functions to the inngest client
|
|
2066
2071
|
var eventHandlers = framework.getGlobalEventHandlers();
|
|
2067
2072
|
var globalEventHandlers = eventHandlers.map(function (eh) {
|
|
2068
|
-
return client.createFunction({
|
|
2073
|
+
return client$1.createFunction({
|
|
2069
2074
|
id: eh.id
|
|
2070
2075
|
}, {
|
|
2071
2076
|
event: eh.event
|
|
2072
|
-
},
|
|
2077
|
+
}, /*#__PURE__*/function () {
|
|
2078
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
2079
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2080
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2081
|
+
case 0:
|
|
2082
|
+
return _context.abrupt("return", eh.executor(_extends({}, props, {
|
|
2083
|
+
mastra: framework
|
|
2084
|
+
})));
|
|
2085
|
+
case 1:
|
|
2086
|
+
case "end":
|
|
2087
|
+
return _context.stop();
|
|
2088
|
+
}
|
|
2089
|
+
}, _callee);
|
|
2090
|
+
}));
|
|
2091
|
+
return function (_x) {
|
|
2092
|
+
return _ref.apply(this, arguments);
|
|
2093
|
+
};
|
|
2094
|
+
}());
|
|
2073
2095
|
});
|
|
2074
2096
|
var systemWorkflowHandler = createWorkflowHandler({
|
|
2075
2097
|
blueprintDirPath: (_framework$config$wor = framework.config.workflows) == null ? void 0 : _framework$config$wor.blueprintDirPath,
|
|
2076
2098
|
runBlueprint: framework.runBlueprint
|
|
2077
2099
|
});
|
|
2078
2100
|
var handler = next.serve({
|
|
2079
|
-
client: client,
|
|
2101
|
+
client: client$1,
|
|
2080
2102
|
functions: [].concat(globalEventHandlers, [systemWorkflowHandler])
|
|
2081
2103
|
});
|
|
2082
2104
|
// @ts-ignore
|
|
@@ -2435,19 +2457,6 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2435
2457
|
return _ref4.apply(this, arguments);
|
|
2436
2458
|
};
|
|
2437
2459
|
}();
|
|
2438
|
-
this.getEventHandlers = function (_ref5) {
|
|
2439
|
-
var makeWebhookUrl = _ref5.makeWebhookUrl;
|
|
2440
|
-
return Object.keys(_this.events).map(function (eventKey) {
|
|
2441
|
-
var _this$events$eventKey;
|
|
2442
|
-
var eventHandler = (_this$events$eventKey = _this.events[eventKey]) == null ? void 0 : _this$events$eventKey.handler;
|
|
2443
|
-
if (!eventHandler) return null;
|
|
2444
|
-
return eventHandler({
|
|
2445
|
-
integrationInstance: _this,
|
|
2446
|
-
eventKey: eventKey,
|
|
2447
|
-
makeWebhookUrl: makeWebhookUrl
|
|
2448
|
-
});
|
|
2449
|
-
}).filter(Boolean);
|
|
2450
|
-
};
|
|
2451
2460
|
if (!(config != null && config.name)) {
|
|
2452
2461
|
throw new IntegrationError('Integration name must be defined');
|
|
2453
2462
|
}
|
|
@@ -2492,12 +2501,12 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2492
2501
|
return getApiClient;
|
|
2493
2502
|
}();
|
|
2494
2503
|
_proto.getApi = /*#__PURE__*/function () {
|
|
2495
|
-
var _getApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(
|
|
2504
|
+
var _getApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
|
|
2496
2505
|
var connectionId;
|
|
2497
2506
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
2498
2507
|
while (1) switch (_context5.prev = _context5.next) {
|
|
2499
2508
|
case 0:
|
|
2500
|
-
connectionId =
|
|
2509
|
+
connectionId = _ref5.connectionId;
|
|
2501
2510
|
_context5.next = 3;
|
|
2502
2511
|
return this.getApiClient({
|
|
2503
2512
|
connectionId: connectionId
|
|
@@ -2521,8 +2530,8 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2521
2530
|
_proto.getAuthenticator = function getAuthenticator() {
|
|
2522
2531
|
throw new IntegrationError('Authenticator not implemented');
|
|
2523
2532
|
};
|
|
2524
|
-
_proto.attachDataLayer = function attachDataLayer(
|
|
2525
|
-
var dataLayer =
|
|
2533
|
+
_proto.attachDataLayer = function attachDataLayer(_ref6) {
|
|
2534
|
+
var dataLayer = _ref6.dataLayer;
|
|
2526
2535
|
this.dataLayer = dataLayer;
|
|
2527
2536
|
};
|
|
2528
2537
|
_proto.registerApis = function registerApis() {
|
|
@@ -2579,14 +2588,14 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2579
2588
|
return processWebhookRequest;
|
|
2580
2589
|
}();
|
|
2581
2590
|
_proto.triggerEvent = /*#__PURE__*/function () {
|
|
2582
|
-
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(
|
|
2591
|
+
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
|
|
2583
2592
|
var key, data, user, event;
|
|
2584
2593
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
2585
2594
|
while (1) switch (_context8.prev = _context8.next) {
|
|
2586
2595
|
case 0:
|
|
2587
|
-
key =
|
|
2596
|
+
key = _ref7.key, data = _ref7.data, user = _ref7.user;
|
|
2588
2597
|
_context8.next = 3;
|
|
2589
|
-
return client.send({
|
|
2598
|
+
return client$1.send({
|
|
2590
2599
|
name: key,
|
|
2591
2600
|
data: data,
|
|
2592
2601
|
user: user
|
|
@@ -2606,13 +2615,13 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2606
2615
|
return triggerEvent;
|
|
2607
2616
|
}();
|
|
2608
2617
|
_proto.test = /*#__PURE__*/function () {
|
|
2609
|
-
var _test = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(
|
|
2618
|
+
var _test = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref8) {
|
|
2610
2619
|
var _this$dataLayer;
|
|
2611
2620
|
var connectionId, connection, _this$config$scopes, authenticator, bearer, desiredScopes, _bearer$scope, actualScopes, isMissingScopes;
|
|
2612
2621
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
2613
2622
|
while (1) switch (_context9.prev = _context9.next) {
|
|
2614
2623
|
case 0:
|
|
2615
|
-
connectionId =
|
|
2624
|
+
connectionId = _ref8.connectionId;
|
|
2616
2625
|
_context9.next = 3;
|
|
2617
2626
|
return (_this$dataLayer = this.dataLayer) == null ? void 0 : _this$dataLayer.getConnection({
|
|
2618
2627
|
connectionId: connectionId,
|
|
@@ -2663,7 +2672,7 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2663
2672
|
return test;
|
|
2664
2673
|
}();
|
|
2665
2674
|
_proto.onConnectionCreated = /*#__PURE__*/function () {
|
|
2666
|
-
var _onConnectionCreated = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(
|
|
2675
|
+
var _onConnectionCreated = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref9) {
|
|
2667
2676
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
2668
2677
|
while (1) switch (_context10.prev = _context10.next) {
|
|
2669
2678
|
case 0:
|
|
@@ -2679,7 +2688,7 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2679
2688
|
return onConnectionCreated;
|
|
2680
2689
|
}();
|
|
2681
2690
|
_proto.onDisconnect = /*#__PURE__*/function () {
|
|
2682
|
-
var _onDisconnect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(
|
|
2691
|
+
var _onDisconnect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref10) {
|
|
2683
2692
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
2684
2693
|
while (1) switch (_context11.prev = _context11.next) {
|
|
2685
2694
|
case 0:
|
|
@@ -3123,19 +3132,19 @@ function setFieldOptions(_ref3) {
|
|
|
3123
3132
|
|
|
3124
3133
|
function zodToPropertType(zodType) {
|
|
3125
3134
|
if (zodType instanceof zod.z.ZodString) {
|
|
3126
|
-
return client$
|
|
3135
|
+
return client$2.PropertyType.SINGLE_LINE_TEXT;
|
|
3127
3136
|
}
|
|
3128
3137
|
if (zodType instanceof zod.z.ZodBoolean) {
|
|
3129
|
-
return client$
|
|
3138
|
+
return client$2.PropertyType.BOOLEAN;
|
|
3130
3139
|
}
|
|
3131
3140
|
if (zodType instanceof zod.z.ZodRecord) {
|
|
3132
|
-
return client$
|
|
3141
|
+
return client$2.PropertyType.JSON_OBJECT;
|
|
3133
3142
|
}
|
|
3134
3143
|
if (zodType instanceof zod.z.ZodNumber) {
|
|
3135
|
-
return client$
|
|
3144
|
+
return client$2.PropertyType.NUMBER;
|
|
3136
3145
|
}
|
|
3137
3146
|
if (zodType instanceof zod.z.ZodArray) {
|
|
3138
|
-
return client$
|
|
3147
|
+
return client$2.PropertyType.JSON_ARRAY;
|
|
3139
3148
|
}
|
|
3140
3149
|
if (zodType instanceof zod.z.ZodOptional) {
|
|
3141
3150
|
return zodToPropertType(zodType._def.innerType);
|
|
@@ -3144,10 +3153,10 @@ function zodToPropertType(zodType) {
|
|
|
3144
3153
|
return zodToPropertType(zodType._def.innerType);
|
|
3145
3154
|
}
|
|
3146
3155
|
if (zodType instanceof zod.z.ZodLiteral) {
|
|
3147
|
-
return client$
|
|
3156
|
+
return client$2.PropertyType.SINGLE_LINE_TEXT;
|
|
3148
3157
|
}
|
|
3149
3158
|
if (zodType instanceof zod.z.ZodObject) {
|
|
3150
|
-
return client$
|
|
3159
|
+
return client$2.PropertyType.JSON_OBJECT;
|
|
3151
3160
|
}
|
|
3152
3161
|
// TODO UNIONS
|
|
3153
3162
|
return undefined;
|
|
@@ -4069,9 +4078,9 @@ function _runActionsRecursively() {
|
|
|
4069
4078
|
data: data
|
|
4070
4079
|
});
|
|
4071
4080
|
executorResult = {};
|
|
4072
|
-
_ctx = mastraConnectionId ? {
|
|
4081
|
+
_ctx = mastraConnectionId ? _extends({}, ctx, {
|
|
4073
4082
|
connectionId: mastraConnectionId
|
|
4074
|
-
} : ctx;
|
|
4083
|
+
}) : ctx;
|
|
4075
4084
|
_context2.prev = 46;
|
|
4076
4085
|
_context2.next = 49;
|
|
4077
4086
|
return actionExecutor({
|
|
@@ -4238,266 +4247,1983 @@ function _blueprintRunner() {
|
|
|
4238
4247
|
return _blueprintRunner.apply(this, arguments);
|
|
4239
4248
|
}
|
|
4240
4249
|
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
systemApis = _this.getSystemApis();
|
|
4264
|
-
systemEvents = _this.getSystemEvents();
|
|
4265
|
-
availableIntegrations = (_this$availableIntegr = _this.availableIntegrations()) == null ? void 0 : _this$availableIntegr.map(function (_ref4) {
|
|
4266
|
-
var integration = _ref4.integration;
|
|
4267
|
-
return integration;
|
|
4268
|
-
});
|
|
4269
|
-
availableIntegrationApis = availableIntegrations.reduce(function (acc, _ref5) {
|
|
4270
|
-
var name = _ref5.name;
|
|
4271
|
-
var apis = _this.getApisByIntegration(name);
|
|
4272
|
-
return _extends({}, acc, apis);
|
|
4273
|
-
}, {});
|
|
4274
|
-
availableIntegrationEvents = availableIntegrations.reduce(function (acc, _ref6) {
|
|
4275
|
-
var name = _ref6.name;
|
|
4276
|
-
var events = _this.getEventsByIntegration(name);
|
|
4277
|
-
return _extends({}, acc, events);
|
|
4278
|
-
}, {});
|
|
4279
|
-
frameworkApis = _extends({}, systemApis, availableIntegrationApis);
|
|
4280
|
-
frameworkEvents = _extends({}, systemEvents, availableIntegrationEvents);
|
|
4281
|
-
_context.next = 10;
|
|
4282
|
-
return blueprintRunner({
|
|
4283
|
-
dataCtx: dataCtx,
|
|
4284
|
-
blueprint: blueprint,
|
|
4285
|
-
frameworkApis: frameworkApis,
|
|
4286
|
-
frameworkEvents: frameworkEvents,
|
|
4287
|
-
ctx: ctx
|
|
4288
|
-
});
|
|
4289
|
-
case 10:
|
|
4290
|
-
case "end":
|
|
4291
|
-
return _context.stop();
|
|
4292
|
-
}
|
|
4293
|
-
}, _callee);
|
|
4294
|
-
}));
|
|
4295
|
-
return function (_x) {
|
|
4296
|
-
return _ref3.apply(this, arguments);
|
|
4297
|
-
};
|
|
4298
|
-
}();
|
|
4299
|
-
this.dataLayer = dataLayer;
|
|
4300
|
-
this.config = config;
|
|
4250
|
+
function getAgentDir(_ref) {
|
|
4251
|
+
var agentDir = _ref.agentDir;
|
|
4252
|
+
var ARK_APP_DIR = process.env.ARK_APP_DIR || process.cwd();
|
|
4253
|
+
return path.join(ARK_APP_DIR, agentDir);
|
|
4254
|
+
}
|
|
4255
|
+
function listAgentsJson(_ref2) {
|
|
4256
|
+
var agentDir = _ref2.agentDir;
|
|
4257
|
+
var agentDirPath = getAgentDir({
|
|
4258
|
+
agentDir: agentDir
|
|
4259
|
+
});
|
|
4260
|
+
var agents = fs.readdirSync(agentDirPath);
|
|
4261
|
+
return agents;
|
|
4262
|
+
}
|
|
4263
|
+
function getAgentFile(agentFilePath) {
|
|
4264
|
+
try {
|
|
4265
|
+
var fileP = agentFilePath;
|
|
4266
|
+
var fileB = fs.readFileSync(fileP, 'utf8');
|
|
4267
|
+
var json = JSON.parse(fileB);
|
|
4268
|
+
return json;
|
|
4269
|
+
} catch (e) {
|
|
4270
|
+
console.error('No agent blueprint found:', agentFilePath);
|
|
4271
|
+
return;
|
|
4301
4272
|
}
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
return _extends({}, api, {
|
|
4323
|
-
integrationName: config.name
|
|
4324
|
-
});
|
|
4325
|
-
})
|
|
4326
|
-
});
|
|
4327
|
-
// Register System events
|
|
4328
|
-
framework.__registerEvents({
|
|
4329
|
-
events: config.workflows.systemEvents
|
|
4330
|
-
});
|
|
4331
|
-
return framework;
|
|
4332
|
-
};
|
|
4333
|
-
var _proto = Framework.prototype;
|
|
4334
|
-
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
4335
|
-
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
|
|
4336
|
-
var _this2 = this;
|
|
4337
|
-
var context, ints, connectionChecks;
|
|
4338
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4339
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
4273
|
+
}
|
|
4274
|
+
function getAgentBlueprint(_ref3) {
|
|
4275
|
+
var agentId = _ref3.agentId,
|
|
4276
|
+
agentDir = _ref3.agentDir;
|
|
4277
|
+
var agentDirPath = getAgentDir({
|
|
4278
|
+
agentDir: agentDir
|
|
4279
|
+
});
|
|
4280
|
+
var agentBlueprintPath = path.join(agentDirPath, agentId + ".json");
|
|
4281
|
+
return getAgentFile(agentBlueprintPath);
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
var VectorLayer = /*#__PURE__*/function () {
|
|
4285
|
+
function VectorLayer() {
|
|
4286
|
+
this.supportedProviders = ['PINECONE'];
|
|
4287
|
+
}
|
|
4288
|
+
var _proto = VectorLayer.prototype;
|
|
4289
|
+
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4290
|
+
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4291
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4292
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4340
4293
|
case 0:
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
_context3.next = 4;
|
|
4344
|
-
return Promise.all(ints.map(/*#__PURE__*/function () {
|
|
4345
|
-
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
|
|
4346
|
-
var integration, connection;
|
|
4347
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4348
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
4349
|
-
case 0:
|
|
4350
|
-
integration = _ref8.integration;
|
|
4351
|
-
_context2.next = 3;
|
|
4352
|
-
return _this2.dataLayer.getConnection({
|
|
4353
|
-
connectionId: context.connectionId,
|
|
4354
|
-
name: integration.name
|
|
4355
|
-
});
|
|
4356
|
-
case 3:
|
|
4357
|
-
connection = _context2.sent;
|
|
4358
|
-
return _context2.abrupt("return", {
|
|
4359
|
-
integration: integration,
|
|
4360
|
-
connected: !!connection
|
|
4361
|
-
});
|
|
4362
|
-
case 5:
|
|
4363
|
-
case "end":
|
|
4364
|
-
return _context2.stop();
|
|
4365
|
-
}
|
|
4366
|
-
}, _callee2);
|
|
4367
|
-
}));
|
|
4368
|
-
return function (_x3) {
|
|
4369
|
-
return _ref9.apply(this, arguments);
|
|
4370
|
-
};
|
|
4371
|
-
}()));
|
|
4372
|
-
case 4:
|
|
4373
|
-
connectionChecks = _context3.sent;
|
|
4374
|
-
return _context3.abrupt("return", connectionChecks.filter(function (_ref10) {
|
|
4375
|
-
var connected = _ref10.connected;
|
|
4376
|
-
return connected;
|
|
4377
|
-
}).map(function (_ref11) {
|
|
4378
|
-
var integration = _ref11.integration;
|
|
4379
|
-
return integration;
|
|
4380
|
-
}));
|
|
4381
|
-
case 6:
|
|
4294
|
+
return _context.abrupt("return", this.Pinecone.listIndexes());
|
|
4295
|
+
case 1:
|
|
4382
4296
|
case "end":
|
|
4383
|
-
return
|
|
4297
|
+
return _context.stop();
|
|
4384
4298
|
}
|
|
4385
|
-
},
|
|
4299
|
+
}, _callee, this);
|
|
4386
4300
|
}));
|
|
4387
|
-
function
|
|
4388
|
-
return
|
|
4301
|
+
function getPineconeIndexes() {
|
|
4302
|
+
return _getPineconeIndexes.apply(this, arguments);
|
|
4389
4303
|
}
|
|
4390
|
-
return
|
|
4304
|
+
return getPineconeIndexes;
|
|
4391
4305
|
}();
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
});
|
|
4398
|
-
var router = this.createRouter();
|
|
4399
|
-
definition.corePresets = {
|
|
4400
|
-
redirectURI: router.makeRedirectURI()
|
|
4401
|
-
};
|
|
4402
|
-
this.integrations.set(name, definition);
|
|
4403
|
-
definition.registerEvents();
|
|
4404
|
-
this.__registerEvents({
|
|
4405
|
-
events: definition.getEvents(),
|
|
4406
|
-
integrationName: name
|
|
4407
|
-
});
|
|
4408
|
-
definition.registerApis();
|
|
4409
|
-
definition._convertApiClientToSystemApis();
|
|
4410
|
-
this.__registerApis({
|
|
4411
|
-
apis: Object.values(definition.getApis()),
|
|
4412
|
-
integrationName: name
|
|
4413
|
-
});
|
|
4414
|
-
(_this$globalEventHand = this.globalEventHandlers).push.apply(_this$globalEventHand, definition.getEventHandlers({
|
|
4415
|
-
makeWebhookUrl: router.makeWebhookUrl
|
|
4416
|
-
}));
|
|
4417
|
-
};
|
|
4418
|
-
_proto.__registerEvents = function __registerEvents(_ref12) {
|
|
4419
|
-
var events = _ref12.events,
|
|
4420
|
-
_ref12$integrationNam = _ref12.integrationName,
|
|
4421
|
-
integrationName = _ref12$integrationNam === void 0 ? this.config.name : _ref12$integrationNam;
|
|
4422
|
-
var integrationEvents = this.globalEvents.get(integrationName) || {};
|
|
4423
|
-
this.globalEvents.set(integrationName, _extends({}, integrationEvents, events));
|
|
4424
|
-
};
|
|
4425
|
-
_proto.__registerApis = function __registerApis(_ref13) {
|
|
4426
|
-
var apis = _ref13.apis,
|
|
4427
|
-
_ref13$integrationNam = _ref13.integrationName,
|
|
4428
|
-
integrationName = _ref13$integrationNam === void 0 ? this.config.name : _ref13$integrationNam;
|
|
4429
|
-
var integrationApis = this.globalApis.get(integrationName) || {};
|
|
4430
|
-
this.globalApis.set(integrationName, _extends({}, integrationApis, apis.reduce(function (acc, api) {
|
|
4431
|
-
var _extends2;
|
|
4432
|
-
return _extends({}, acc, (_extends2 = {}, _extends2[api.type] = api, _extends2));
|
|
4433
|
-
}, {})));
|
|
4434
|
-
};
|
|
4435
|
-
_proto.availableIntegrations = function availableIntegrations() {
|
|
4436
|
-
return Array.from(this.integrations.entries()).map(function (_ref14) {
|
|
4437
|
-
var name = _ref14[0],
|
|
4438
|
-
integration = _ref14[1];
|
|
4439
|
-
return {
|
|
4440
|
-
name: name,
|
|
4441
|
-
integration: integration
|
|
4442
|
-
};
|
|
4443
|
-
});
|
|
4444
|
-
};
|
|
4445
|
-
_proto.getIntegration = function getIntegration(name) {
|
|
4446
|
-
return this.integrations.get(name);
|
|
4447
|
-
};
|
|
4448
|
-
_proto.getGlobalEvents = function getGlobalEvents() {
|
|
4449
|
-
return this.globalEvents;
|
|
4450
|
-
};
|
|
4451
|
-
_proto.getSystemEvents = function getSystemEvents() {
|
|
4452
|
-
var events = this.globalEvents.get(this.config.name);
|
|
4453
|
-
return events || {};
|
|
4454
|
-
};
|
|
4455
|
-
_proto.getEventsByIntegration = function getEventsByIntegration(name) {
|
|
4456
|
-
return this.globalEvents.get(name);
|
|
4457
|
-
};
|
|
4458
|
-
_proto.getGlobalEventHandlers = function getGlobalEventHandlers() {
|
|
4459
|
-
return this.globalEventHandlers;
|
|
4460
|
-
};
|
|
4461
|
-
_proto.getApis = function getApis() {
|
|
4462
|
-
return this.globalApis;
|
|
4463
|
-
};
|
|
4464
|
-
_proto.getSystemApis = function getSystemApis() {
|
|
4465
|
-
return this.globalApis.get(this.config.name);
|
|
4466
|
-
};
|
|
4467
|
-
_proto.getApisByIntegration = function getApisByIntegration(name, includeHidden) {
|
|
4468
|
-
var integrationApis = this.globalApis.get(name);
|
|
4469
|
-
if (includeHidden) {
|
|
4470
|
-
return integrationApis;
|
|
4471
|
-
}
|
|
4472
|
-
return _.omitBy(integrationApis, function (value) {
|
|
4473
|
-
return value.isHidden;
|
|
4474
|
-
});
|
|
4475
|
-
};
|
|
4476
|
-
_proto.authenticatableIntegrations = function authenticatableIntegrations() {
|
|
4477
|
-
return this.availableIntegrations().filter(function (_ref15) {
|
|
4478
|
-
var integration = _ref15.integration;
|
|
4479
|
-
try {
|
|
4480
|
-
integration.getAuthenticator();
|
|
4481
|
-
return true;
|
|
4482
|
-
} catch (e) {
|
|
4483
|
-
return false;
|
|
4306
|
+
return _createClass(VectorLayer, [{
|
|
4307
|
+
key: "Pinecone",
|
|
4308
|
+
get: function get() {
|
|
4309
|
+
if (!process.env.PINECONE_API_KEY) {
|
|
4310
|
+
throw new Error('Pinecone API key not found');
|
|
4484
4311
|
}
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4312
|
+
return new pinecone.Pinecone({
|
|
4313
|
+
apiKey: process.env.PINECONE_API_KEY
|
|
4314
|
+
});
|
|
4315
|
+
}
|
|
4316
|
+
}]);
|
|
4317
|
+
}();
|
|
4318
|
+
|
|
4319
|
+
function getVectorProvider(provider) {
|
|
4320
|
+
if (provider === 'PINECONE') {
|
|
4321
|
+
var _VectorLayer = new VectorLayer(),
|
|
4322
|
+
Pinecone = _VectorLayer.Pinecone;
|
|
4323
|
+
return Pinecone;
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
var delay$1 = function delay(ms) {
|
|
4327
|
+
return new Promise(function (resolve) {
|
|
4328
|
+
return setTimeout(resolve, ms);
|
|
4329
|
+
});
|
|
4330
|
+
};
|
|
4331
|
+
function executeGenericVectorSync(_x) {
|
|
4332
|
+
return _executeGenericVectorSync.apply(this, arguments);
|
|
4333
|
+
}
|
|
4334
|
+
function _executeGenericVectorSync() {
|
|
4335
|
+
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
4336
|
+
var _event$user, _event$data, _event$data2;
|
|
4337
|
+
var event, mastra, connectionId, vector_provider, entities, systemName, vp, _iterator, _step, _yield$mastra$dataLay, _mastra$dataLayer, vectorE, integrationName, k_id, _mastra$dataLayer2, connection, _loop, _ret, _iterator2, _step2;
|
|
4338
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
4339
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4340
|
+
case 0:
|
|
4341
|
+
event = _ref.event, mastra = _ref.mastra;
|
|
4342
|
+
connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
|
|
4343
|
+
vector_provider = event == null || (_event$data = event.data) == null ? void 0 : _event$data.vector_provider;
|
|
4344
|
+
entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
|
|
4345
|
+
systemName = mastra.config.name;
|
|
4346
|
+
if (vector_provider) {
|
|
4347
|
+
_context4.next = 8;
|
|
4348
|
+
break;
|
|
4349
|
+
}
|
|
4350
|
+
console.error("No vector_provider defined for agent");
|
|
4351
|
+
return _context4.abrupt("return");
|
|
4352
|
+
case 8:
|
|
4353
|
+
vp = getVectorProvider(vector_provider);
|
|
4354
|
+
if (vp) {
|
|
4355
|
+
_context4.next = 12;
|
|
4356
|
+
break;
|
|
4357
|
+
}
|
|
4358
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4359
|
+
return _context4.abrupt("return");
|
|
4360
|
+
case 12:
|
|
4361
|
+
if (process.env.OPENAI_API_KEY) {
|
|
4362
|
+
_context4.next = 15;
|
|
4363
|
+
break;
|
|
4364
|
+
}
|
|
4365
|
+
console.error('NO OPENAI_API_KEY');
|
|
4366
|
+
return _context4.abrupt("return");
|
|
4367
|
+
case 15:
|
|
4368
|
+
_iterator = _createForOfIteratorHelperLoose(entities);
|
|
4369
|
+
case 16:
|
|
4370
|
+
if ((_step = _iterator()).done) {
|
|
4371
|
+
_context4.next = 50;
|
|
4372
|
+
break;
|
|
4373
|
+
}
|
|
4374
|
+
vectorE = _step.value;
|
|
4375
|
+
integrationName = vectorE.integration;
|
|
4376
|
+
_context4.next = 21;
|
|
4377
|
+
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4378
|
+
connectionId: connectionId,
|
|
4379
|
+
name: integrationName
|
|
4380
|
+
});
|
|
4381
|
+
case 21:
|
|
4382
|
+
_context4.t1 = _yield$mastra$dataLay = _context4.sent;
|
|
4383
|
+
if (!(_context4.t1 == null)) {
|
|
4384
|
+
_context4.next = 26;
|
|
4385
|
+
break;
|
|
4386
|
+
}
|
|
4387
|
+
_context4.t2 = void 0;
|
|
4388
|
+
_context4.next = 27;
|
|
4389
|
+
break;
|
|
4390
|
+
case 26:
|
|
4391
|
+
_context4.t2 = _yield$mastra$dataLay.id;
|
|
4392
|
+
case 27:
|
|
4393
|
+
_context4.t0 = _context4.t2;
|
|
4394
|
+
if (_context4.t0) {
|
|
4395
|
+
_context4.next = 30;
|
|
4396
|
+
break;
|
|
4397
|
+
}
|
|
4398
|
+
_context4.t0 = '';
|
|
4399
|
+
case 30:
|
|
4400
|
+
k_id = _context4.t0;
|
|
4401
|
+
if (!(!k_id && integrationName === systemName)) {
|
|
4402
|
+
_context4.next = 36;
|
|
4403
|
+
break;
|
|
4404
|
+
}
|
|
4405
|
+
_context4.next = 34;
|
|
4406
|
+
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4407
|
+
connection: {
|
|
4408
|
+
connectionId: connectionId,
|
|
4409
|
+
name: integrationName
|
|
4410
|
+
},
|
|
4411
|
+
credential: {
|
|
4412
|
+
type: 'API_KEY',
|
|
4413
|
+
value: connectionId,
|
|
4414
|
+
scope: []
|
|
4415
|
+
}
|
|
4416
|
+
});
|
|
4417
|
+
case 34:
|
|
4418
|
+
connection = _context4.sent;
|
|
4419
|
+
k_id = connection.id;
|
|
4420
|
+
case 36:
|
|
4421
|
+
if (k_id) {
|
|
4422
|
+
_context4.next = 39;
|
|
4423
|
+
break;
|
|
4424
|
+
}
|
|
4425
|
+
console.error('Error bootstrapping shit');
|
|
4426
|
+
return _context4.abrupt("return");
|
|
4427
|
+
case 39:
|
|
4428
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
4429
|
+
var _mastra$dataLayer3, _entityRecords, _records;
|
|
4430
|
+
var entity, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, _yield$mastra$trigger, _event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
|
|
4431
|
+
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
4432
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4433
|
+
case 0:
|
|
4434
|
+
entity = _step2.value;
|
|
4435
|
+
_context3.next = 3;
|
|
4436
|
+
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
4437
|
+
k_id: k_id,
|
|
4438
|
+
type: entity.name
|
|
4439
|
+
});
|
|
4440
|
+
case 3:
|
|
4441
|
+
entityRecords = _context3.sent;
|
|
4442
|
+
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
4443
|
+
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
4444
|
+
_context3.next = 23;
|
|
4445
|
+
break;
|
|
4446
|
+
}
|
|
4447
|
+
// @TODO: SYNC THEM
|
|
4448
|
+
console.error('NO RECORDS');
|
|
4449
|
+
_context3.next = 9;
|
|
4450
|
+
return mastra.triggerEvent({
|
|
4451
|
+
key: entity.syncEvent,
|
|
4452
|
+
data: {},
|
|
4453
|
+
user: {
|
|
4454
|
+
connectionId: connectionId
|
|
4455
|
+
}
|
|
4456
|
+
});
|
|
4457
|
+
case 9:
|
|
4458
|
+
_yield$mastra$trigger = _context3.sent;
|
|
4459
|
+
_event = _yield$mastra$trigger.event;
|
|
4460
|
+
console.log(_event, '####');
|
|
4461
|
+
_context3.next = 14;
|
|
4462
|
+
return _event.subscribe();
|
|
4463
|
+
case 14:
|
|
4464
|
+
res = _context3.sent;
|
|
4465
|
+
console.log('Subscribe result', res);
|
|
4466
|
+
_context3.next = 18;
|
|
4467
|
+
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
4468
|
+
k_id: k_id,
|
|
4469
|
+
type: entity.name
|
|
4470
|
+
});
|
|
4471
|
+
case 18:
|
|
4472
|
+
entityRecords = _context3.sent;
|
|
4473
|
+
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
4474
|
+
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
4475
|
+
_context3.next = 23;
|
|
4476
|
+
break;
|
|
4477
|
+
}
|
|
4478
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
4479
|
+
return _context3.abrupt("return", {
|
|
4480
|
+
v: void 0
|
|
4481
|
+
});
|
|
4482
|
+
case 23:
|
|
4483
|
+
recordsMapped = records.map(function (_ref7) {
|
|
4484
|
+
var data = _ref7.data,
|
|
4485
|
+
externalId = _ref7.externalId;
|
|
4486
|
+
return _extends({
|
|
4487
|
+
id: externalId
|
|
4488
|
+
}, _.pick(data, entity.fields));
|
|
4489
|
+
});
|
|
4490
|
+
console.log(recordsMapped, 'RECORDS');
|
|
4491
|
+
_context3.next = 27;
|
|
4492
|
+
return vp.createIndex({
|
|
4493
|
+
suppressConflicts: true,
|
|
4494
|
+
name: entity.name,
|
|
4495
|
+
dimension: 1536,
|
|
4496
|
+
metric: 'cosine',
|
|
4497
|
+
spec: {
|
|
4498
|
+
serverless: {
|
|
4499
|
+
cloud: 'aws',
|
|
4500
|
+
region: 'us-east-1'
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
});
|
|
4504
|
+
case 27:
|
|
4505
|
+
_context3.next = 29;
|
|
4506
|
+
return delay$1(5000);
|
|
4507
|
+
case 29:
|
|
4508
|
+
entityTypeIndex = vp.index(entity.name);
|
|
4509
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
4510
|
+
_context3.prev = 31;
|
|
4511
|
+
_context3.next = 34;
|
|
4512
|
+
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4513
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(record) {
|
|
4514
|
+
var _yield$embed, embedding;
|
|
4515
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4516
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
4517
|
+
case 0:
|
|
4518
|
+
_context2.next = 2;
|
|
4519
|
+
return ai.embed({
|
|
4520
|
+
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4521
|
+
value: JSON.stringify(record)
|
|
4522
|
+
});
|
|
4523
|
+
case 2:
|
|
4524
|
+
_yield$embed = _context2.sent;
|
|
4525
|
+
embedding = _yield$embed.embedding;
|
|
4526
|
+
return _context2.abrupt("return", {
|
|
4527
|
+
id: record.id,
|
|
4528
|
+
values: embedding,
|
|
4529
|
+
metadata: record
|
|
4530
|
+
});
|
|
4531
|
+
case 5:
|
|
4532
|
+
case "end":
|
|
4533
|
+
return _context2.stop();
|
|
4534
|
+
}
|
|
4535
|
+
}, _callee2);
|
|
4536
|
+
}));
|
|
4537
|
+
return function (_x5) {
|
|
4538
|
+
return _ref8.apply(this, arguments);
|
|
4539
|
+
};
|
|
4540
|
+
}())) != null ? _recordsMapped$map : []);
|
|
4541
|
+
case 34:
|
|
4542
|
+
vectors = _context3.sent;
|
|
4543
|
+
console.log('UPSERTING', vectors);
|
|
4544
|
+
if (!(vectors.length > 0)) {
|
|
4545
|
+
_context3.next = 39;
|
|
4546
|
+
break;
|
|
4547
|
+
}
|
|
4548
|
+
_context3.next = 39;
|
|
4549
|
+
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4550
|
+
case 39:
|
|
4551
|
+
_context3.next = 44;
|
|
4552
|
+
break;
|
|
4553
|
+
case 41:
|
|
4554
|
+
_context3.prev = 41;
|
|
4555
|
+
_context3.t0 = _context3["catch"](31);
|
|
4556
|
+
console.error(_context3.t0);
|
|
4557
|
+
case 44:
|
|
4558
|
+
return _context3.abrupt("return", {
|
|
4559
|
+
v: void 0
|
|
4560
|
+
});
|
|
4561
|
+
case 45:
|
|
4562
|
+
case "end":
|
|
4563
|
+
return _context3.stop();
|
|
4564
|
+
}
|
|
4565
|
+
}, _loop, null, [[31, 41]]);
|
|
4566
|
+
});
|
|
4567
|
+
_iterator2 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4568
|
+
case 41:
|
|
4569
|
+
if ((_step2 = _iterator2()).done) {
|
|
4570
|
+
_context4.next = 48;
|
|
4571
|
+
break;
|
|
4572
|
+
}
|
|
4573
|
+
return _context4.delegateYield(_loop(), "t3", 43);
|
|
4574
|
+
case 43:
|
|
4575
|
+
_ret = _context4.t3;
|
|
4576
|
+
if (!_ret) {
|
|
4577
|
+
_context4.next = 46;
|
|
4578
|
+
break;
|
|
4579
|
+
}
|
|
4580
|
+
return _context4.abrupt("return", _ret.v);
|
|
4581
|
+
case 46:
|
|
4582
|
+
_context4.next = 41;
|
|
4583
|
+
break;
|
|
4584
|
+
case 48:
|
|
4585
|
+
_context4.next = 16;
|
|
4586
|
+
break;
|
|
4587
|
+
case 50:
|
|
4588
|
+
case "end":
|
|
4589
|
+
return _context4.stop();
|
|
4590
|
+
}
|
|
4591
|
+
}, _callee3);
|
|
4592
|
+
}));
|
|
4593
|
+
return _executeGenericVectorSync.apply(this, arguments);
|
|
4594
|
+
}
|
|
4595
|
+
function executeVectorSync(_x2) {
|
|
4596
|
+
return _executeVectorSync.apply(this, arguments);
|
|
4597
|
+
}
|
|
4598
|
+
function _executeVectorSync() {
|
|
4599
|
+
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref2) {
|
|
4600
|
+
var _event$user2, _agent$knowledge_sour3;
|
|
4601
|
+
var event, mastra, agentDir, agent, connectionId, systemName, vp, _agent$knowledge_sour4, _iterator3, _step3, _yield$mastra$dataLay2, _mastra$dataLayer5, vectorE, integrationName, k_id, _mastra$dataLayer6, connection, _loop2, _ret2, _iterator4, _step4;
|
|
4602
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context7) {
|
|
4603
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4604
|
+
case 0:
|
|
4605
|
+
event = _ref2.event, mastra = _ref2.mastra;
|
|
4606
|
+
agentDir = mastra.config.agents.agentDirPath;
|
|
4607
|
+
agent = getAgentBlueprint({
|
|
4608
|
+
agentDir: agentDir,
|
|
4609
|
+
agentId: event.data.agentId
|
|
4610
|
+
});
|
|
4611
|
+
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
4612
|
+
systemName = mastra.config.name;
|
|
4613
|
+
if (agent.knowledge_sources.vector_provider) {
|
|
4614
|
+
_context7.next = 8;
|
|
4615
|
+
break;
|
|
4616
|
+
}
|
|
4617
|
+
console.error("No vector_provider defined for agent");
|
|
4618
|
+
return _context7.abrupt("return");
|
|
4619
|
+
case 8:
|
|
4620
|
+
vp = getVectorProvider(agent == null || (_agent$knowledge_sour3 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour3.vector_provider);
|
|
4621
|
+
if (vp) {
|
|
4622
|
+
_context7.next = 12;
|
|
4623
|
+
break;
|
|
4624
|
+
}
|
|
4625
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour4 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour4.vector_provider);
|
|
4626
|
+
return _context7.abrupt("return");
|
|
4627
|
+
case 12:
|
|
4628
|
+
if (process.env.OPENAI_API_KEY) {
|
|
4629
|
+
_context7.next = 15;
|
|
4630
|
+
break;
|
|
4631
|
+
}
|
|
4632
|
+
console.error('NO OPENAI_API_KEY');
|
|
4633
|
+
return _context7.abrupt("return");
|
|
4634
|
+
case 15:
|
|
4635
|
+
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
4636
|
+
_context7.next = 18;
|
|
4637
|
+
break;
|
|
4638
|
+
}
|
|
4639
|
+
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
4640
|
+
return _context7.abrupt("return");
|
|
4641
|
+
case 18:
|
|
4642
|
+
_iterator3 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
4643
|
+
case 19:
|
|
4644
|
+
if ((_step3 = _iterator3()).done) {
|
|
4645
|
+
_context7.next = 53;
|
|
4646
|
+
break;
|
|
4647
|
+
}
|
|
4648
|
+
vectorE = _step3.value;
|
|
4649
|
+
integrationName = vectorE.integration;
|
|
4650
|
+
_context7.next = 24;
|
|
4651
|
+
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
4652
|
+
connectionId: connectionId,
|
|
4653
|
+
name: integrationName
|
|
4654
|
+
});
|
|
4655
|
+
case 24:
|
|
4656
|
+
_context7.t1 = _yield$mastra$dataLay2 = _context7.sent;
|
|
4657
|
+
if (!(_context7.t1 == null)) {
|
|
4658
|
+
_context7.next = 29;
|
|
4659
|
+
break;
|
|
4660
|
+
}
|
|
4661
|
+
_context7.t2 = void 0;
|
|
4662
|
+
_context7.next = 30;
|
|
4663
|
+
break;
|
|
4664
|
+
case 29:
|
|
4665
|
+
_context7.t2 = _yield$mastra$dataLay2.id;
|
|
4666
|
+
case 30:
|
|
4667
|
+
_context7.t0 = _context7.t2;
|
|
4668
|
+
if (_context7.t0) {
|
|
4669
|
+
_context7.next = 33;
|
|
4670
|
+
break;
|
|
4671
|
+
}
|
|
4672
|
+
_context7.t0 = '';
|
|
4673
|
+
case 33:
|
|
4674
|
+
k_id = _context7.t0;
|
|
4675
|
+
if (!(!k_id && integrationName === systemName)) {
|
|
4676
|
+
_context7.next = 39;
|
|
4677
|
+
break;
|
|
4678
|
+
}
|
|
4679
|
+
_context7.next = 37;
|
|
4680
|
+
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4681
|
+
connection: {
|
|
4682
|
+
connectionId: connectionId,
|
|
4683
|
+
name: integrationName
|
|
4684
|
+
},
|
|
4685
|
+
credential: {
|
|
4686
|
+
type: 'API_KEY',
|
|
4687
|
+
value: connectionId,
|
|
4688
|
+
scope: []
|
|
4689
|
+
}
|
|
4690
|
+
});
|
|
4691
|
+
case 37:
|
|
4692
|
+
connection = _context7.sent;
|
|
4693
|
+
k_id = connection.id;
|
|
4694
|
+
case 39:
|
|
4695
|
+
if (k_id) {
|
|
4696
|
+
_context7.next = 42;
|
|
4697
|
+
break;
|
|
4698
|
+
}
|
|
4699
|
+
console.error('Error bootstrapping shit');
|
|
4700
|
+
return _context7.abrupt("return");
|
|
4701
|
+
case 42:
|
|
4702
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4703
|
+
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4704
|
+
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4705
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context6) {
|
|
4706
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4707
|
+
case 0:
|
|
4708
|
+
entity = _step4.value;
|
|
4709
|
+
_context6.next = 3;
|
|
4710
|
+
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4711
|
+
k_id: k_id,
|
|
4712
|
+
type: entity.name
|
|
4713
|
+
});
|
|
4714
|
+
case 3:
|
|
4715
|
+
entityRecords = _context6.sent;
|
|
4716
|
+
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4717
|
+
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4718
|
+
_context6.next = 23;
|
|
4719
|
+
break;
|
|
4720
|
+
}
|
|
4721
|
+
// @TODO: SYNC THEM
|
|
4722
|
+
console.error('NO RECORDS');
|
|
4723
|
+
_context6.next = 9;
|
|
4724
|
+
return mastra.triggerEvent({
|
|
4725
|
+
key: entity.syncEvent,
|
|
4726
|
+
data: {},
|
|
4727
|
+
user: {
|
|
4728
|
+
connectionId: connectionId
|
|
4729
|
+
}
|
|
4730
|
+
});
|
|
4731
|
+
case 9:
|
|
4732
|
+
_yield$mastra$trigger2 = _context6.sent;
|
|
4733
|
+
_event2 = _yield$mastra$trigger2.event;
|
|
4734
|
+
console.log(_event2, '####');
|
|
4735
|
+
_context6.next = 14;
|
|
4736
|
+
return _event2.subscribe();
|
|
4737
|
+
case 14:
|
|
4738
|
+
res = _context6.sent;
|
|
4739
|
+
console.log('Subscribe result', res);
|
|
4740
|
+
_context6.next = 18;
|
|
4741
|
+
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4742
|
+
k_id: k_id,
|
|
4743
|
+
type: entity.name
|
|
4744
|
+
});
|
|
4745
|
+
case 18:
|
|
4746
|
+
entityRecords = _context6.sent;
|
|
4747
|
+
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4748
|
+
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4749
|
+
_context6.next = 23;
|
|
4750
|
+
break;
|
|
4751
|
+
}
|
|
4752
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
4753
|
+
return _context6.abrupt("return", {
|
|
4754
|
+
v: void 0
|
|
4755
|
+
});
|
|
4756
|
+
case 23:
|
|
4757
|
+
recordsMapped = records.map(function (_ref9) {
|
|
4758
|
+
var data = _ref9.data,
|
|
4759
|
+
externalId = _ref9.externalId;
|
|
4760
|
+
return _extends({
|
|
4761
|
+
id: externalId
|
|
4762
|
+
}, _.pick(data, entity.fields));
|
|
4763
|
+
});
|
|
4764
|
+
console.log(recordsMapped, 'RECORDS');
|
|
4765
|
+
_context6.next = 27;
|
|
4766
|
+
return vp.createIndex({
|
|
4767
|
+
suppressConflicts: true,
|
|
4768
|
+
name: entity.name,
|
|
4769
|
+
dimension: 1536,
|
|
4770
|
+
metric: 'cosine',
|
|
4771
|
+
spec: {
|
|
4772
|
+
serverless: {
|
|
4773
|
+
cloud: 'aws',
|
|
4774
|
+
region: 'us-east-1'
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
});
|
|
4778
|
+
case 27:
|
|
4779
|
+
entityTypeIndex = vp.index(entity.name);
|
|
4780
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
4781
|
+
_context6.prev = 29;
|
|
4782
|
+
_context6.next = 32;
|
|
4783
|
+
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4784
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(record) {
|
|
4785
|
+
var _yield$embed2, embedding;
|
|
4786
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
4787
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4788
|
+
case 0:
|
|
4789
|
+
_context5.next = 2;
|
|
4790
|
+
return ai.embed({
|
|
4791
|
+
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4792
|
+
value: JSON.stringify(record)
|
|
4793
|
+
});
|
|
4794
|
+
case 2:
|
|
4795
|
+
_yield$embed2 = _context5.sent;
|
|
4796
|
+
embedding = _yield$embed2.embedding;
|
|
4797
|
+
return _context5.abrupt("return", {
|
|
4798
|
+
id: record.id,
|
|
4799
|
+
values: embedding,
|
|
4800
|
+
metadata: record
|
|
4801
|
+
});
|
|
4802
|
+
case 5:
|
|
4803
|
+
case "end":
|
|
4804
|
+
return _context5.stop();
|
|
4805
|
+
}
|
|
4806
|
+
}, _callee4);
|
|
4807
|
+
}));
|
|
4808
|
+
return function (_x6) {
|
|
4809
|
+
return _ref10.apply(this, arguments);
|
|
4810
|
+
};
|
|
4811
|
+
}())) != null ? _recordsMapped$map2 : []);
|
|
4812
|
+
case 32:
|
|
4813
|
+
vectors = _context6.sent;
|
|
4814
|
+
console.log('UPSERTING', vectors);
|
|
4815
|
+
if (!(vectors.length > 0)) {
|
|
4816
|
+
_context6.next = 37;
|
|
4817
|
+
break;
|
|
4818
|
+
}
|
|
4819
|
+
_context6.next = 37;
|
|
4820
|
+
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4821
|
+
case 37:
|
|
4822
|
+
_context6.next = 42;
|
|
4823
|
+
break;
|
|
4824
|
+
case 39:
|
|
4825
|
+
_context6.prev = 39;
|
|
4826
|
+
_context6.t0 = _context6["catch"](29);
|
|
4827
|
+
console.error(_context6.t0);
|
|
4828
|
+
case 42:
|
|
4829
|
+
return _context6.abrupt("return", {
|
|
4830
|
+
v: void 0
|
|
4831
|
+
});
|
|
4832
|
+
case 43:
|
|
4833
|
+
case "end":
|
|
4834
|
+
return _context6.stop();
|
|
4835
|
+
}
|
|
4836
|
+
}, _loop2, null, [[29, 39]]);
|
|
4837
|
+
});
|
|
4838
|
+
_iterator4 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4839
|
+
case 44:
|
|
4840
|
+
if ((_step4 = _iterator4()).done) {
|
|
4841
|
+
_context7.next = 51;
|
|
4842
|
+
break;
|
|
4843
|
+
}
|
|
4844
|
+
return _context7.delegateYield(_loop2(), "t3", 46);
|
|
4845
|
+
case 46:
|
|
4846
|
+
_ret2 = _context7.t3;
|
|
4847
|
+
if (!_ret2) {
|
|
4848
|
+
_context7.next = 49;
|
|
4849
|
+
break;
|
|
4850
|
+
}
|
|
4851
|
+
return _context7.abrupt("return", _ret2.v);
|
|
4852
|
+
case 49:
|
|
4853
|
+
_context7.next = 44;
|
|
4854
|
+
break;
|
|
4855
|
+
case 51:
|
|
4856
|
+
_context7.next = 19;
|
|
4857
|
+
break;
|
|
4858
|
+
case 53:
|
|
4859
|
+
case "end":
|
|
4860
|
+
return _context7.stop();
|
|
4861
|
+
}
|
|
4862
|
+
}, _callee5);
|
|
4863
|
+
}));
|
|
4864
|
+
return _executeVectorSync.apply(this, arguments);
|
|
4865
|
+
}
|
|
4866
|
+
function vectorQueryEngine(_x3) {
|
|
4867
|
+
return _vectorQueryEngine.apply(this, arguments);
|
|
4868
|
+
}
|
|
4869
|
+
function _vectorQueryEngine() {
|
|
4870
|
+
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
|
|
4871
|
+
var vector_provider, _ref3$topK, topK, indexName, content, entityType, vp, index, _yield$embed3, embedding, queryResponse;
|
|
4872
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
4873
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4874
|
+
case 0:
|
|
4875
|
+
vector_provider = _ref3.vector_provider, _ref3$topK = _ref3.topK, topK = _ref3$topK === void 0 ? 1 : _ref3$topK, indexName = _ref3.indexName, content = _ref3.content, entityType = _ref3.entityType;
|
|
4876
|
+
vp = getVectorProvider(vector_provider);
|
|
4877
|
+
if (vp) {
|
|
4878
|
+
_context8.next = 5;
|
|
4879
|
+
break;
|
|
4880
|
+
}
|
|
4881
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4882
|
+
return _context8.abrupt("return");
|
|
4883
|
+
case 5:
|
|
4884
|
+
index = vp.index(indexName);
|
|
4885
|
+
_context8.next = 8;
|
|
4886
|
+
return ai.embed({
|
|
4887
|
+
model: openai.openai.embedding('text-embedding-3-small'),
|
|
4888
|
+
value: content
|
|
4889
|
+
});
|
|
4890
|
+
case 8:
|
|
4891
|
+
_yield$embed3 = _context8.sent;
|
|
4892
|
+
embedding = _yield$embed3.embedding;
|
|
4893
|
+
console.log(embedding, 'EMBEDDING');
|
|
4894
|
+
_context8.next = 13;
|
|
4895
|
+
return index.namespace(entityType).query({
|
|
4896
|
+
vector: embedding,
|
|
4897
|
+
topK: topK,
|
|
4898
|
+
includeMetadata: true
|
|
4899
|
+
});
|
|
4900
|
+
case 13:
|
|
4901
|
+
queryResponse = _context8.sent;
|
|
4902
|
+
return _context8.abrupt("return", queryResponse);
|
|
4903
|
+
case 15:
|
|
4904
|
+
case "end":
|
|
4905
|
+
return _context8.stop();
|
|
4906
|
+
}
|
|
4907
|
+
}, _callee6);
|
|
4908
|
+
}));
|
|
4909
|
+
return _vectorQueryEngine.apply(this, arguments);
|
|
4910
|
+
}
|
|
4911
|
+
function getVectorQueryApis(_ref4) {
|
|
4912
|
+
var mastra = _ref4.mastra;
|
|
4913
|
+
var agentDir = mastra.config.agents.agentDirPath;
|
|
4914
|
+
var agents = listAgentsJson({
|
|
4915
|
+
agentDir: agentDir
|
|
4916
|
+
});
|
|
4917
|
+
var agentData = agents.map(function (agentFile) {
|
|
4918
|
+
var _agent$knowledge_sour;
|
|
4919
|
+
var agentDirPath = getAgentDir({
|
|
4920
|
+
agentDir: agentDir
|
|
4921
|
+
});
|
|
4922
|
+
var agent = getAgentFile(path.join(agentDirPath, agentFile));
|
|
4923
|
+
if (!(agent != null && (_agent$knowledge_sour = agent.knowledge_sources) != null && _agent$knowledge_sour.vector_provider)) {
|
|
4924
|
+
console.error("No vector_provider defined for agent");
|
|
4925
|
+
return;
|
|
4926
|
+
}
|
|
4927
|
+
return agent;
|
|
4928
|
+
}).filter(Boolean);
|
|
4929
|
+
return agentData.flatMap(function (agent) {
|
|
4930
|
+
var entities = agent == null ? void 0 : agent.knowledge_sources.entities;
|
|
4931
|
+
return entities.flatMap(function (_ref5) {
|
|
4932
|
+
var data = _ref5.data,
|
|
4933
|
+
integration = _ref5.integration;
|
|
4934
|
+
return data.map(function (entity) {
|
|
4935
|
+
return {
|
|
4936
|
+
integrationName: integration,
|
|
4937
|
+
type: "get_" + entity.name + "_from_vector_" + entity.index,
|
|
4938
|
+
label: "Provides " + entity.name + " information from Vector " + entity.index + " Store",
|
|
4939
|
+
description: "Provides " + entity.name + " information from Vector " + entity.index + " Store",
|
|
4940
|
+
schema: zod.z.object({
|
|
4941
|
+
content: zod.z.string(),
|
|
4942
|
+
topResult: zod.z.number()
|
|
4943
|
+
}),
|
|
4944
|
+
executor: function () {
|
|
4945
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
|
|
4946
|
+
var _agent$knowledge_sour2;
|
|
4947
|
+
var data, res;
|
|
4948
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4949
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4950
|
+
case 0:
|
|
4951
|
+
data = _ref6.data;
|
|
4952
|
+
_context.next = 3;
|
|
4953
|
+
return vectorQueryEngine({
|
|
4954
|
+
vector_provider: agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider,
|
|
4955
|
+
indexName: entity.index,
|
|
4956
|
+
content: data.content,
|
|
4957
|
+
topK: data.topResult || 1,
|
|
4958
|
+
entityType: entity.name
|
|
4959
|
+
});
|
|
4960
|
+
case 3:
|
|
4961
|
+
res = _context.sent;
|
|
4962
|
+
console.log(JSON.stringify({
|
|
4963
|
+
res: res
|
|
4964
|
+
}, null, 2));
|
|
4965
|
+
// @TODO: make this a proper response
|
|
4966
|
+
return _context.abrupt("return", res);
|
|
4967
|
+
case 6:
|
|
4968
|
+
case "end":
|
|
4969
|
+
return _context.stop();
|
|
4970
|
+
}
|
|
4971
|
+
}, _callee);
|
|
4972
|
+
}));
|
|
4973
|
+
function executor(_x4) {
|
|
4974
|
+
return _executor.apply(this, arguments);
|
|
4975
|
+
}
|
|
4976
|
+
return executor;
|
|
4977
|
+
}()
|
|
4978
|
+
};
|
|
4979
|
+
});
|
|
4980
|
+
});
|
|
4981
|
+
}).filter(Boolean);
|
|
4982
|
+
}
|
|
4983
|
+
function agentVectorSyncEvent() {
|
|
4984
|
+
return {
|
|
4985
|
+
// @TODO: naming convention
|
|
4986
|
+
id: 'agent-vector-sync',
|
|
4987
|
+
event: 'AGENT_VECTOR_SYNC',
|
|
4988
|
+
executor: executeVectorSync
|
|
4989
|
+
};
|
|
4990
|
+
}
|
|
4991
|
+
function genericVectorySyncEvent() {
|
|
4992
|
+
return {
|
|
4993
|
+
// @TODO: naming convention
|
|
4994
|
+
id: 'vector-sync',
|
|
4995
|
+
event: 'VECTOR_SYNC',
|
|
4996
|
+
executor: executeGenericVectorSync
|
|
4997
|
+
};
|
|
4998
|
+
}
|
|
4999
|
+
|
|
5000
|
+
function getAgentSystemApis(_ref) {
|
|
5001
|
+
var mastra = _ref.mastra;
|
|
5002
|
+
var agentDir = mastra.config.agents.agentDirPath;
|
|
5003
|
+
var agents = listAgentsJson({
|
|
5004
|
+
agentDir: agentDir
|
|
5005
|
+
});
|
|
5006
|
+
// Remove the .json extension from the agent names
|
|
5007
|
+
var agentList = agents.map(function (agent) {
|
|
5008
|
+
return agent.slice(0, -5);
|
|
5009
|
+
});
|
|
5010
|
+
return [{
|
|
5011
|
+
integrationName: 'SYSTEM',
|
|
5012
|
+
type: 'message_agent',
|
|
5013
|
+
label: 'Send Message To Agent',
|
|
5014
|
+
description: 'Sends a message to an Agent',
|
|
5015
|
+
schema: zod.z.object({
|
|
5016
|
+
agentId: zod.z["enum"](agentList),
|
|
5017
|
+
message: zod.z.string()
|
|
5018
|
+
}),
|
|
5019
|
+
outputSchema: zod.z.object({
|
|
5020
|
+
message: zod.z.string()
|
|
5021
|
+
}),
|
|
5022
|
+
executor: function () {
|
|
5023
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5024
|
+
var data, executor, result, _run$content, thread, run;
|
|
5025
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5026
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5027
|
+
case 0:
|
|
5028
|
+
data = _ref2.data;
|
|
5029
|
+
_context.next = 3;
|
|
5030
|
+
return mastra.getAgent({
|
|
5031
|
+
agentId: data.agentId,
|
|
5032
|
+
connectionId: data.connectionId
|
|
5033
|
+
});
|
|
5034
|
+
case 3:
|
|
5035
|
+
executor = _context.sent;
|
|
5036
|
+
if (executor) {
|
|
5037
|
+
_context.next = 6;
|
|
5038
|
+
break;
|
|
5039
|
+
}
|
|
5040
|
+
throw new Error('Could not create agent executor');
|
|
5041
|
+
case 6:
|
|
5042
|
+
if (!(typeof executor === 'function')) {
|
|
5043
|
+
_context.next = 13;
|
|
5044
|
+
break;
|
|
5045
|
+
}
|
|
5046
|
+
_context.next = 9;
|
|
5047
|
+
return executor({
|
|
5048
|
+
prompt: data == null ? void 0 : data.message
|
|
5049
|
+
});
|
|
5050
|
+
case 9:
|
|
5051
|
+
result = _context.sent;
|
|
5052
|
+
return _context.abrupt("return", {
|
|
5053
|
+
message: result == null ? void 0 : result.text
|
|
5054
|
+
});
|
|
5055
|
+
case 13:
|
|
5056
|
+
_context.next = 15;
|
|
5057
|
+
return executor.initializeThread([{
|
|
5058
|
+
role: 'user',
|
|
5059
|
+
content: data == null ? void 0 : data.message
|
|
5060
|
+
}]);
|
|
5061
|
+
case 15:
|
|
5062
|
+
thread = _context.sent;
|
|
5063
|
+
_context.next = 18;
|
|
5064
|
+
return executor.watchRun({
|
|
5065
|
+
threadId: thread.id
|
|
5066
|
+
});
|
|
5067
|
+
case 18:
|
|
5068
|
+
run = _context.sent;
|
|
5069
|
+
return _context.abrupt("return", {
|
|
5070
|
+
message: run == null || (_run$content = run.content) == null || (_run$content = _run$content[0]) == null || (_run$content = _run$content.text) == null ? void 0 : _run$content.value
|
|
5071
|
+
});
|
|
5072
|
+
case 20:
|
|
5073
|
+
case "end":
|
|
5074
|
+
return _context.stop();
|
|
5075
|
+
}
|
|
5076
|
+
}, _callee);
|
|
5077
|
+
}));
|
|
5078
|
+
function executor(_x) {
|
|
5079
|
+
return _executor.apply(this, arguments);
|
|
5080
|
+
}
|
|
5081
|
+
return executor;
|
|
5082
|
+
}()
|
|
5083
|
+
}];
|
|
5084
|
+
}
|
|
5085
|
+
|
|
5086
|
+
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
5087
|
+
function createFileLogger(_ref) {
|
|
5088
|
+
var destinationPath = _ref.destinationPath;
|
|
5089
|
+
var fullPath = path.join(loggerPath, destinationPath);
|
|
5090
|
+
return function (log) {
|
|
5091
|
+
if (!fs.existsSync(loggerPath)) {
|
|
5092
|
+
fs.mkdirSync(loggerPath, {
|
|
5093
|
+
recursive: true
|
|
5094
|
+
});
|
|
5095
|
+
return fs.writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
5096
|
+
createdAt: new Date()
|
|
5097
|
+
})], null, 2));
|
|
5098
|
+
}
|
|
5099
|
+
var logs = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
5100
|
+
logs.push(_extends({}, log, {
|
|
5101
|
+
createdAt: new Date()
|
|
5102
|
+
}));
|
|
5103
|
+
return fs.writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
5104
|
+
};
|
|
5105
|
+
}
|
|
5106
|
+
|
|
5107
|
+
var client;
|
|
5108
|
+
if (process.env.OPENAI_API_KEY) {
|
|
5109
|
+
client = /*#__PURE__*/new OpenAI({
|
|
5110
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
5111
|
+
});
|
|
5112
|
+
}
|
|
5113
|
+
function getAssistantAgent(_x3) {
|
|
5114
|
+
return _getAssistantAgent.apply(this, arguments);
|
|
5115
|
+
}
|
|
5116
|
+
function _getAssistantAgent() {
|
|
5117
|
+
_getAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref3) {
|
|
5118
|
+
var id, toolMap, logger, agent, handleRunStatus, handleRequiresAction, getRun;
|
|
5119
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
5120
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
5121
|
+
case 0:
|
|
5122
|
+
id = _ref3.id, toolMap = _ref3.toolMap;
|
|
5123
|
+
logger = createFileLogger({
|
|
5124
|
+
destinationPath: id + ".json"
|
|
5125
|
+
});
|
|
5126
|
+
_context11.next = 4;
|
|
5127
|
+
return client.beta.assistants.retrieve(id);
|
|
5128
|
+
case 4:
|
|
5129
|
+
agent = _context11.sent;
|
|
5130
|
+
handleRunStatus = /*#__PURE__*/function () {
|
|
5131
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
5132
|
+
var threadId, run, _messages$data, messages;
|
|
5133
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5134
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5135
|
+
case 0:
|
|
5136
|
+
threadId = _ref4.threadId, run = _ref4.run;
|
|
5137
|
+
if (!(run.status === 'completed')) {
|
|
5138
|
+
_context3.next = 8;
|
|
5139
|
+
break;
|
|
5140
|
+
}
|
|
5141
|
+
_context3.next = 4;
|
|
5142
|
+
return client.beta.threads.messages.list(threadId);
|
|
5143
|
+
case 4:
|
|
5144
|
+
messages = _context3.sent;
|
|
5145
|
+
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5146
|
+
case 8:
|
|
5147
|
+
if (!(run.status === 'requires_action')) {
|
|
5148
|
+
_context3.next = 14;
|
|
5149
|
+
break;
|
|
5150
|
+
}
|
|
5151
|
+
_context3.next = 11;
|
|
5152
|
+
return handleRequiresAction({
|
|
5153
|
+
run: run,
|
|
5154
|
+
threadId: threadId
|
|
5155
|
+
});
|
|
5156
|
+
case 11:
|
|
5157
|
+
return _context3.abrupt("return", _context3.sent);
|
|
5158
|
+
case 14:
|
|
5159
|
+
console.error('Run did not complete:', run);
|
|
5160
|
+
logger({
|
|
5161
|
+
statusCode: 400,
|
|
5162
|
+
message: JSON.stringify({
|
|
5163
|
+
message: "Run did not complete",
|
|
5164
|
+
event_type: 'run_error',
|
|
5165
|
+
metadata: {
|
|
5166
|
+
run: run
|
|
5167
|
+
}
|
|
5168
|
+
}, null, 2)
|
|
5169
|
+
});
|
|
5170
|
+
case 16:
|
|
5171
|
+
case "end":
|
|
5172
|
+
return _context3.stop();
|
|
5173
|
+
}
|
|
5174
|
+
}, _callee3);
|
|
5175
|
+
}));
|
|
5176
|
+
return function handleRunStatus(_x4) {
|
|
5177
|
+
return _ref5.apply(this, arguments);
|
|
5178
|
+
};
|
|
5179
|
+
}();
|
|
5180
|
+
handleRequiresAction = /*#__PURE__*/function () {
|
|
5181
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5182
|
+
var threadId, run, toolOutputs;
|
|
5183
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5184
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
5185
|
+
case 0:
|
|
5186
|
+
threadId = _ref6.threadId, run = _ref6.run;
|
|
5187
|
+
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5188
|
+
_context5.next = 23;
|
|
5189
|
+
break;
|
|
5190
|
+
}
|
|
5191
|
+
_context5.t0 = _.compact;
|
|
5192
|
+
_context5.next = 5;
|
|
5193
|
+
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5194
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5195
|
+
var callInfo, toolMetadata, toolFn, args, output;
|
|
5196
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5197
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5198
|
+
case 0:
|
|
5199
|
+
callInfo = index + 1 + " of " + tools.length;
|
|
5200
|
+
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5201
|
+
toolMetadata = {
|
|
5202
|
+
id: tool.id,
|
|
5203
|
+
fn: tool["function"].name,
|
|
5204
|
+
availableTools: Object.keys(toolMap)
|
|
5205
|
+
};
|
|
5206
|
+
logger({
|
|
5207
|
+
statusCode: 100,
|
|
5208
|
+
message: JSON.stringify({
|
|
5209
|
+
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5210
|
+
metadata: {
|
|
5211
|
+
tool: toolMetadata
|
|
5212
|
+
}
|
|
5213
|
+
}, null, 2)
|
|
5214
|
+
});
|
|
5215
|
+
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5216
|
+
if (toolFn) {
|
|
5217
|
+
_context4.next = 8;
|
|
5218
|
+
break;
|
|
5219
|
+
}
|
|
5220
|
+
logger({
|
|
5221
|
+
statusCode: 404,
|
|
5222
|
+
message: JSON.stringify({
|
|
5223
|
+
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5224
|
+
metadata: {
|
|
5225
|
+
tool: toolMetadata
|
|
5226
|
+
}
|
|
5227
|
+
}, null, 2)
|
|
5228
|
+
});
|
|
5229
|
+
return _context4.abrupt("return");
|
|
5230
|
+
case 8:
|
|
5231
|
+
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5232
|
+
args = {};
|
|
5233
|
+
try {
|
|
5234
|
+
if (tool["function"].arguments) {
|
|
5235
|
+
args = JSON.parse(tool["function"].arguments);
|
|
5236
|
+
logger({
|
|
5237
|
+
statusCode: 100,
|
|
5238
|
+
message: JSON.stringify({
|
|
5239
|
+
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5240
|
+
metadata: {
|
|
5241
|
+
args: args,
|
|
5242
|
+
tool: toolMetadata
|
|
5243
|
+
}
|
|
5244
|
+
}, null, 2)
|
|
5245
|
+
});
|
|
5246
|
+
}
|
|
5247
|
+
} catch (e) {
|
|
5248
|
+
console.error(e);
|
|
5249
|
+
}
|
|
5250
|
+
_context4.next = 13;
|
|
5251
|
+
return toolFn(args);
|
|
5252
|
+
case 13:
|
|
5253
|
+
output = _context4.sent;
|
|
5254
|
+
logger({
|
|
5255
|
+
statusCode: 200,
|
|
5256
|
+
message: JSON.stringify({
|
|
5257
|
+
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5258
|
+
metadata: {
|
|
5259
|
+
output: output,
|
|
5260
|
+
tool: toolMetadata
|
|
5261
|
+
}
|
|
5262
|
+
}, null, 2)
|
|
5263
|
+
});
|
|
5264
|
+
return _context4.abrupt("return", {
|
|
5265
|
+
tool_call_id: tool.id,
|
|
5266
|
+
output: JSON.stringify(output)
|
|
5267
|
+
});
|
|
5268
|
+
case 16:
|
|
5269
|
+
case "end":
|
|
5270
|
+
return _context4.stop();
|
|
5271
|
+
}
|
|
5272
|
+
}, _callee4);
|
|
5273
|
+
}));
|
|
5274
|
+
return function (_x6, _x7, _x8) {
|
|
5275
|
+
return _ref8.apply(this, arguments);
|
|
5276
|
+
};
|
|
5277
|
+
}()));
|
|
5278
|
+
case 5:
|
|
5279
|
+
_context5.t1 = _context5.sent;
|
|
5280
|
+
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5281
|
+
if (toolOutputs) {
|
|
5282
|
+
_context5.next = 11;
|
|
5283
|
+
break;
|
|
5284
|
+
}
|
|
5285
|
+
console.error('No tool outputs to submit.');
|
|
5286
|
+
logger({
|
|
5287
|
+
statusCode: 404,
|
|
5288
|
+
message: JSON.stringify({
|
|
5289
|
+
message: "No tool outputs submitted",
|
|
5290
|
+
metadata: {}
|
|
5291
|
+
}, null, 2)
|
|
5292
|
+
});
|
|
5293
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5294
|
+
threadId: threadId,
|
|
5295
|
+
run: run
|
|
5296
|
+
}));
|
|
5297
|
+
case 11:
|
|
5298
|
+
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5299
|
+
_context5.next = 20;
|
|
5300
|
+
break;
|
|
5301
|
+
}
|
|
5302
|
+
console.log(toolOutputs, '###### YOOOOOO');
|
|
5303
|
+
_context5.next = 15;
|
|
5304
|
+
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5305
|
+
tool_outputs: toolOutputs
|
|
5306
|
+
});
|
|
5307
|
+
case 15:
|
|
5308
|
+
run = _context5.sent;
|
|
5309
|
+
logger({
|
|
5310
|
+
statusCode: 200,
|
|
5311
|
+
message: JSON.stringify({
|
|
5312
|
+
message: "Tool outputs submitted",
|
|
5313
|
+
metadata: {
|
|
5314
|
+
run: run
|
|
5315
|
+
}
|
|
5316
|
+
}, null, 2)
|
|
5317
|
+
});
|
|
5318
|
+
console.log('Tool outputs submitted successfully.');
|
|
5319
|
+
_context5.next = 22;
|
|
5320
|
+
break;
|
|
5321
|
+
case 20:
|
|
5322
|
+
logger({
|
|
5323
|
+
statusCode: 404,
|
|
5324
|
+
message: JSON.stringify({
|
|
5325
|
+
message: "No tool outputs to submit",
|
|
5326
|
+
metadata: {}
|
|
5327
|
+
}, null, 2)
|
|
5328
|
+
});
|
|
5329
|
+
console.log('No tool outputs to submit.');
|
|
5330
|
+
case 22:
|
|
5331
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5332
|
+
threadId: threadId,
|
|
5333
|
+
run: run
|
|
5334
|
+
}));
|
|
5335
|
+
case 23:
|
|
5336
|
+
case "end":
|
|
5337
|
+
return _context5.stop();
|
|
5338
|
+
}
|
|
5339
|
+
}, _callee5);
|
|
5340
|
+
}));
|
|
5341
|
+
return function handleRequiresAction(_x5) {
|
|
5342
|
+
return _ref7.apply(this, arguments);
|
|
5343
|
+
};
|
|
5344
|
+
}();
|
|
5345
|
+
getRun = /*#__PURE__*/function () {
|
|
5346
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref9) {
|
|
5347
|
+
var threadId, runId;
|
|
5348
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
5349
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
5350
|
+
case 0:
|
|
5351
|
+
threadId = _ref9.threadId, runId = _ref9.runId;
|
|
5352
|
+
_context6.next = 3;
|
|
5353
|
+
return client.beta.threads.runs.retrieve(threadId, runId);
|
|
5354
|
+
case 3:
|
|
5355
|
+
return _context6.abrupt("return", _context6.sent);
|
|
5356
|
+
case 4:
|
|
5357
|
+
case "end":
|
|
5358
|
+
return _context6.stop();
|
|
5359
|
+
}
|
|
5360
|
+
}, _callee6);
|
|
5361
|
+
}));
|
|
5362
|
+
return function getRun(_x9) {
|
|
5363
|
+
return _ref10.apply(this, arguments);
|
|
5364
|
+
};
|
|
5365
|
+
}();
|
|
5366
|
+
return _context11.abrupt("return", {
|
|
5367
|
+
agent: agent,
|
|
5368
|
+
initializeThread: function () {
|
|
5369
|
+
var _initializeThread = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(messages) {
|
|
5370
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
5371
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
5372
|
+
case 0:
|
|
5373
|
+
if (messages === void 0) {
|
|
5374
|
+
messages = [];
|
|
5375
|
+
}
|
|
5376
|
+
_context7.next = 3;
|
|
5377
|
+
return client.beta.threads.create({
|
|
5378
|
+
messages: messages
|
|
5379
|
+
});
|
|
5380
|
+
case 3:
|
|
5381
|
+
return _context7.abrupt("return", _context7.sent);
|
|
5382
|
+
case 4:
|
|
5383
|
+
case "end":
|
|
5384
|
+
return _context7.stop();
|
|
5385
|
+
}
|
|
5386
|
+
}, _callee7);
|
|
5387
|
+
}));
|
|
5388
|
+
function initializeThread(_x10) {
|
|
5389
|
+
return _initializeThread.apply(this, arguments);
|
|
5390
|
+
}
|
|
5391
|
+
return initializeThread;
|
|
5392
|
+
}(),
|
|
5393
|
+
listMessages: function () {
|
|
5394
|
+
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
5395
|
+
var threadId;
|
|
5396
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5397
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
5398
|
+
case 0:
|
|
5399
|
+
threadId = _ref11.threadId;
|
|
5400
|
+
_context8.next = 3;
|
|
5401
|
+
return client.beta.threads.messages.list(threadId);
|
|
5402
|
+
case 3:
|
|
5403
|
+
return _context8.abrupt("return", _context8.sent);
|
|
5404
|
+
case 4:
|
|
5405
|
+
case "end":
|
|
5406
|
+
return _context8.stop();
|
|
5407
|
+
}
|
|
5408
|
+
}, _callee8);
|
|
5409
|
+
}));
|
|
5410
|
+
function listMessages(_x11) {
|
|
5411
|
+
return _listMessages.apply(this, arguments);
|
|
5412
|
+
}
|
|
5413
|
+
return listMessages;
|
|
5414
|
+
}(),
|
|
5415
|
+
getRun: getRun,
|
|
5416
|
+
handleRunStatus: handleRunStatus,
|
|
5417
|
+
handleRequiresAction: handleRequiresAction,
|
|
5418
|
+
createUserMessage: function () {
|
|
5419
|
+
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
5420
|
+
var threadId, content;
|
|
5421
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
5422
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
5423
|
+
case 0:
|
|
5424
|
+
threadId = _ref12.threadId, content = _ref12.content;
|
|
5425
|
+
_context9.next = 3;
|
|
5426
|
+
return client.beta.threads.messages.create(threadId, {
|
|
5427
|
+
role: 'user',
|
|
5428
|
+
content: content
|
|
5429
|
+
});
|
|
5430
|
+
case 3:
|
|
5431
|
+
return _context9.abrupt("return", _context9.sent);
|
|
5432
|
+
case 4:
|
|
5433
|
+
case "end":
|
|
5434
|
+
return _context9.stop();
|
|
5435
|
+
}
|
|
5436
|
+
}, _callee9);
|
|
5437
|
+
}));
|
|
5438
|
+
function createUserMessage(_x12) {
|
|
5439
|
+
return _createUserMessage.apply(this, arguments);
|
|
5440
|
+
}
|
|
5441
|
+
return createUserMessage;
|
|
5442
|
+
}(),
|
|
5443
|
+
watchRun: function () {
|
|
5444
|
+
var _watchRun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref13) {
|
|
5445
|
+
var runId, threadId, run;
|
|
5446
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
5447
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
5448
|
+
case 0:
|
|
5449
|
+
runId = _ref13.runId, threadId = _ref13.threadId;
|
|
5450
|
+
if (!runId) {
|
|
5451
|
+
_context10.next = 7;
|
|
5452
|
+
break;
|
|
5453
|
+
}
|
|
5454
|
+
_context10.next = 4;
|
|
5455
|
+
return getRun({
|
|
5456
|
+
threadId: threadId,
|
|
5457
|
+
runId: runId
|
|
5458
|
+
});
|
|
5459
|
+
case 4:
|
|
5460
|
+
run = _context10.sent;
|
|
5461
|
+
_context10.next = 11;
|
|
5462
|
+
break;
|
|
5463
|
+
case 7:
|
|
5464
|
+
_context10.next = 9;
|
|
5465
|
+
return client.beta.threads.runs.createAndPoll(threadId, {
|
|
5466
|
+
assistant_id: id,
|
|
5467
|
+
tool_choice: 'required'
|
|
5468
|
+
});
|
|
5469
|
+
case 9:
|
|
5470
|
+
run = _context10.sent;
|
|
5471
|
+
logger({
|
|
5472
|
+
statusCode: 202,
|
|
5473
|
+
message: JSON.stringify({
|
|
5474
|
+
message: "Creating and polling run, tool choice required",
|
|
5475
|
+
metadata: {
|
|
5476
|
+
run: run,
|
|
5477
|
+
tool_choice: 'required',
|
|
5478
|
+
threadId: threadId,
|
|
5479
|
+
assistant_id: id
|
|
5480
|
+
}
|
|
5481
|
+
}, null, 2)
|
|
5482
|
+
});
|
|
5483
|
+
case 11:
|
|
5484
|
+
return _context10.abrupt("return", handleRunStatus({
|
|
5485
|
+
threadId: threadId,
|
|
5486
|
+
run: run
|
|
5487
|
+
}));
|
|
5488
|
+
case 12:
|
|
5489
|
+
case "end":
|
|
5490
|
+
return _context10.stop();
|
|
5491
|
+
}
|
|
5492
|
+
}, _callee10);
|
|
5493
|
+
}));
|
|
5494
|
+
function watchRun(_x13) {
|
|
5495
|
+
return _watchRun.apply(this, arguments);
|
|
5496
|
+
}
|
|
5497
|
+
return watchRun;
|
|
5498
|
+
}()
|
|
5499
|
+
});
|
|
5500
|
+
case 9:
|
|
5501
|
+
case "end":
|
|
5502
|
+
return _context11.stop();
|
|
5503
|
+
}
|
|
5504
|
+
}, _callee11);
|
|
5505
|
+
}));
|
|
5506
|
+
return _getAssistantAgent.apply(this, arguments);
|
|
5507
|
+
}
|
|
5508
|
+
|
|
5509
|
+
var delay = function delay(ms) {
|
|
5510
|
+
return new Promise(function (resolve) {
|
|
5511
|
+
return setTimeout(resolve, ms);
|
|
5512
|
+
});
|
|
5513
|
+
};
|
|
5514
|
+
function getAgentParams(_ref) {
|
|
5515
|
+
var tools = _ref.tools,
|
|
5516
|
+
resultTool = _ref.resultTool,
|
|
5517
|
+
model = _ref.model;
|
|
5518
|
+
var toolsConverted = Object.entries(tools).reduce(function (memo, _ref2) {
|
|
5519
|
+
var key = _ref2[0],
|
|
5520
|
+
val = _ref2[1];
|
|
5521
|
+
memo[key] = ai.tool(val);
|
|
5522
|
+
return memo;
|
|
5523
|
+
}, {});
|
|
5524
|
+
var answerTool = {};
|
|
5525
|
+
if (resultTool) {
|
|
5526
|
+
answerTool = {
|
|
5527
|
+
answer: ai.tool(resultTool)
|
|
5528
|
+
};
|
|
5529
|
+
}
|
|
5530
|
+
var modelDef;
|
|
5531
|
+
if (model.type === 'openai') {
|
|
5532
|
+
var mName = model.name;
|
|
5533
|
+
if (!mName) {
|
|
5534
|
+
mName = "gpt-4o-2024-08-06";
|
|
5535
|
+
}
|
|
5536
|
+
var openai$1 = openai.createOpenAI({
|
|
5537
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
5538
|
+
});
|
|
5539
|
+
modelDef = openai$1(mName, {
|
|
5540
|
+
structuredOutputs: true
|
|
5541
|
+
});
|
|
5542
|
+
} else if (model.type === 'anthropic') {
|
|
5543
|
+
var _mName = model.name;
|
|
5544
|
+
if (!_mName) {
|
|
5545
|
+
_mName = "claude-3-5-sonnet-20240620";
|
|
5546
|
+
}
|
|
5547
|
+
var anthropic$1 = anthropic.createAnthropic({
|
|
5548
|
+
apiKey: process.env.ANTHROPIC_API_KEY
|
|
5549
|
+
});
|
|
5550
|
+
modelDef = anthropic$1(_mName);
|
|
5551
|
+
} else if (model.type === 'groq') {
|
|
5552
|
+
var _process$env$GROQ_API;
|
|
5553
|
+
modelDef = createOpenAICompatibleModel('https://api.groq.com/openai/v1', (_process$env$GROQ_API = process.env.GROQ_API_KEY) != null ? _process$env$GROQ_API : '', 'llama-3.2-90b-text-preview', model.name);
|
|
5554
|
+
} else if (model.type === 'perplexity') {
|
|
5555
|
+
var _process$env$PERPLEXI;
|
|
5556
|
+
modelDef = createOpenAICompatibleModel('https://api.perplexity.ai/', (_process$env$PERPLEXI = process.env.PERPLEXITY_API_KEY) != null ? _process$env$PERPLEXI : '', 'llama-3.1-sonar-large-128k-chat', model.name);
|
|
5557
|
+
} else if (model.type === 'fireworks') {
|
|
5558
|
+
var _process$env$FIREWORK;
|
|
5559
|
+
modelDef = createOpenAICompatibleModel('https://api.fireworks.ai/inference/v1', (_process$env$FIREWORK = process.env.FIREWORKS_API_KEY) != null ? _process$env$FIREWORK : '', 'llama-v3p1-70b-instruct', model.name);
|
|
5560
|
+
}
|
|
5561
|
+
return {
|
|
5562
|
+
toolsConverted: toolsConverted,
|
|
5563
|
+
modelDef: modelDef,
|
|
5564
|
+
answerTool: answerTool,
|
|
5565
|
+
toolChoice: (model == null ? void 0 : model.toolChoice) || 'required'
|
|
5566
|
+
};
|
|
5567
|
+
}
|
|
5568
|
+
function createStreamAgent(_ref3) {
|
|
5569
|
+
var agent_instructions = _ref3.agent_instructions,
|
|
5570
|
+
_ref3$maxSteps = _ref3.maxSteps,
|
|
5571
|
+
maxSteps = _ref3$maxSteps === void 0 ? 5 : _ref3$maxSteps,
|
|
5572
|
+
tools = _ref3.tools,
|
|
5573
|
+
resultTool = _ref3.resultTool,
|
|
5574
|
+
_ref3$context = _ref3.context,
|
|
5575
|
+
context = _ref3$context === void 0 ? [] : _ref3$context,
|
|
5576
|
+
model = _ref3.model;
|
|
5577
|
+
var params = getAgentParams({
|
|
5578
|
+
tools: tools,
|
|
5579
|
+
resultTool: resultTool,
|
|
5580
|
+
model: model
|
|
5581
|
+
});
|
|
5582
|
+
return /*#__PURE__*/function () {
|
|
5583
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
|
|
5584
|
+
var prompt, argsForExecute;
|
|
5585
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5586
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5587
|
+
case 0:
|
|
5588
|
+
prompt = _ref4.prompt;
|
|
5589
|
+
argsForExecute = {
|
|
5590
|
+
model: params.modelDef,
|
|
5591
|
+
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
5592
|
+
toolChoice: (params == null ? void 0 : params.toolChoice) || 'required',
|
|
5593
|
+
maxSteps: maxSteps,
|
|
5594
|
+
// system: systemPrompt,
|
|
5595
|
+
onStepFinish: function () {
|
|
5596
|
+
var _onStepFinish = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
5597
|
+
var _props$response, _props$response2;
|
|
5598
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5599
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5600
|
+
case 0:
|
|
5601
|
+
console.log(JSON.stringify(props, null, 2));
|
|
5602
|
+
if (!(props != null && (_props$response = props.response) != null && (_props$response = _props$response.headers) != null && _props$response['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response2 = props.response) == null || (_props$response2 = _props$response2.headers) == null ? void 0 : _props$response2['x-ratelimit-remaining-tokens'], 10) < 2000)) {
|
|
5603
|
+
_context.next = 5;
|
|
5604
|
+
break;
|
|
5605
|
+
}
|
|
5606
|
+
console.log('Rate limit reached, waiting 10 seconds');
|
|
5607
|
+
_context.next = 5;
|
|
5608
|
+
return delay(10 * 1000);
|
|
5609
|
+
case 5:
|
|
5610
|
+
case "end":
|
|
5611
|
+
return _context.stop();
|
|
5612
|
+
}
|
|
5613
|
+
}, _callee);
|
|
5614
|
+
}));
|
|
5615
|
+
function onStepFinish(_x2) {
|
|
5616
|
+
return _onStepFinish.apply(this, arguments);
|
|
5617
|
+
}
|
|
5618
|
+
return onStepFinish;
|
|
5619
|
+
}()
|
|
5620
|
+
};
|
|
5621
|
+
_context2.next = 4;
|
|
5622
|
+
return ai.streamText(_extends({
|
|
5623
|
+
messages: [].concat(context, [{
|
|
5624
|
+
role: 'user',
|
|
5625
|
+
content: prompt
|
|
5626
|
+
}, {
|
|
5627
|
+
role: 'system',
|
|
5628
|
+
content: agent_instructions
|
|
5629
|
+
}])
|
|
5630
|
+
}, argsForExecute));
|
|
5631
|
+
case 4:
|
|
5632
|
+
return _context2.abrupt("return", _context2.sent);
|
|
5633
|
+
case 5:
|
|
5634
|
+
case "end":
|
|
5635
|
+
return _context2.stop();
|
|
5636
|
+
}
|
|
5637
|
+
}, _callee2);
|
|
5638
|
+
}));
|
|
5639
|
+
return function (_x) {
|
|
5640
|
+
return _ref5.apply(this, arguments);
|
|
5641
|
+
};
|
|
5642
|
+
}();
|
|
5643
|
+
}
|
|
5644
|
+
function createAgent(_ref6) {
|
|
5645
|
+
var agent_instructions = _ref6.agent_instructions,
|
|
5646
|
+
_ref6$maxSteps = _ref6.maxSteps,
|
|
5647
|
+
maxSteps = _ref6$maxSteps === void 0 ? 5 : _ref6$maxSteps,
|
|
5648
|
+
tools = _ref6.tools,
|
|
5649
|
+
resultTool = _ref6.resultTool,
|
|
5650
|
+
_ref6$context = _ref6.context,
|
|
5651
|
+
context = _ref6$context === void 0 ? [] : _ref6$context,
|
|
5652
|
+
model = _ref6.model;
|
|
5653
|
+
var params = getAgentParams({
|
|
5654
|
+
tools: tools,
|
|
5655
|
+
resultTool: resultTool,
|
|
5656
|
+
model: model
|
|
5657
|
+
});
|
|
5658
|
+
return /*#__PURE__*/function () {
|
|
5659
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref7) {
|
|
5660
|
+
var prompt, argsForExecute;
|
|
5661
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5662
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5663
|
+
case 0:
|
|
5664
|
+
prompt = _ref7.prompt;
|
|
5665
|
+
argsForExecute = {
|
|
5666
|
+
model: params.modelDef,
|
|
5667
|
+
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
5668
|
+
toolChoice: (params == null ? void 0 : params.toolChoice) || 'required',
|
|
5669
|
+
maxSteps: maxSteps,
|
|
5670
|
+
// system: systemPrompt,
|
|
5671
|
+
onStepFinish: function () {
|
|
5672
|
+
var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(props) {
|
|
5673
|
+
var _props$response3, _props$response4;
|
|
5674
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5675
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5676
|
+
case 0:
|
|
5677
|
+
console.log(JSON.stringify(props, null, 2));
|
|
5678
|
+
if (!(props != null && (_props$response3 = props.response) != null && (_props$response3 = _props$response3.headers) != null && _props$response3['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response4 = props.response) == null || (_props$response4 = _props$response4.headers) == null ? void 0 : _props$response4['x-ratelimit-remaining-tokens'], 10) < 2000)) {
|
|
5679
|
+
_context3.next = 5;
|
|
5680
|
+
break;
|
|
5681
|
+
}
|
|
5682
|
+
console.log('Rate limit reached, waiting 10 seconds');
|
|
5683
|
+
_context3.next = 5;
|
|
5684
|
+
return delay(10 * 1000);
|
|
5685
|
+
case 5:
|
|
5686
|
+
case "end":
|
|
5687
|
+
return _context3.stop();
|
|
5688
|
+
}
|
|
5689
|
+
}, _callee3);
|
|
5690
|
+
}));
|
|
5691
|
+
function onStepFinish(_x4) {
|
|
5692
|
+
return _onStepFinish2.apply(this, arguments);
|
|
5693
|
+
}
|
|
5694
|
+
return onStepFinish;
|
|
5695
|
+
}()
|
|
5696
|
+
};
|
|
5697
|
+
_context4.next = 4;
|
|
5698
|
+
return ai.generateText(_extends({
|
|
5699
|
+
messages: [].concat(context, [{
|
|
5700
|
+
role: 'user',
|
|
5701
|
+
content: prompt
|
|
5702
|
+
}, {
|
|
5703
|
+
role: 'system',
|
|
5704
|
+
content: agent_instructions
|
|
5705
|
+
}])
|
|
5706
|
+
}, argsForExecute));
|
|
5707
|
+
case 4:
|
|
5708
|
+
return _context4.abrupt("return", _context4.sent);
|
|
5709
|
+
case 5:
|
|
5710
|
+
case "end":
|
|
5711
|
+
return _context4.stop();
|
|
5712
|
+
}
|
|
5713
|
+
}, _callee4);
|
|
5714
|
+
}));
|
|
5715
|
+
return function (_x3) {
|
|
5716
|
+
return _ref8.apply(this, arguments);
|
|
5717
|
+
};
|
|
5718
|
+
}();
|
|
5719
|
+
}
|
|
5720
|
+
function createOpenAICompatibleModel(baseURL, apiKey, defaultModelName, modelName) {
|
|
5721
|
+
var client = openai.createOpenAI({
|
|
5722
|
+
baseURL: baseURL,
|
|
5723
|
+
apiKey: apiKey
|
|
5724
|
+
});
|
|
5725
|
+
return client(modelName || defaultModelName);
|
|
5726
|
+
}
|
|
5727
|
+
|
|
5728
|
+
function getAgent(_x) {
|
|
5729
|
+
return _getAgent.apply(this, arguments);
|
|
5730
|
+
}
|
|
5731
|
+
function _getAgent() {
|
|
5732
|
+
_getAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
5733
|
+
var connectionId, agent, apis, tools, toolMap, assistant, _agent$model2, keyToModel, _tools, _toolMap, resultTool, schema, _agent$model;
|
|
5734
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5735
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5736
|
+
case 0:
|
|
5737
|
+
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis;
|
|
5738
|
+
if (!(agent.model.provider === 'OPEN_AI_ASSISTANT')) {
|
|
5739
|
+
_context3.next = 10;
|
|
5740
|
+
break;
|
|
5741
|
+
}
|
|
5742
|
+
tools = Object.keys(agent.tools);
|
|
5743
|
+
toolMap = Object.entries(apis).reduce(function (memo, _ref2) {
|
|
5744
|
+
var k = _ref2[0],
|
|
5745
|
+
def = _ref2[1];
|
|
5746
|
+
if (tools.includes(k)) {
|
|
5747
|
+
memo[k] = /*#__PURE__*/function () {
|
|
5748
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
5749
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5750
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5751
|
+
case 0:
|
|
5752
|
+
return _context.abrupt("return", def.executor({
|
|
5753
|
+
data: props,
|
|
5754
|
+
ctx: {
|
|
5755
|
+
connectionId: connectionId
|
|
5756
|
+
}
|
|
5757
|
+
}));
|
|
5758
|
+
case 1:
|
|
5759
|
+
case "end":
|
|
5760
|
+
return _context.stop();
|
|
5761
|
+
}
|
|
5762
|
+
}, _callee);
|
|
5763
|
+
}));
|
|
5764
|
+
return function (_x2) {
|
|
5765
|
+
return _ref3.apply(this, arguments);
|
|
5766
|
+
};
|
|
5767
|
+
}();
|
|
5768
|
+
}
|
|
5769
|
+
return memo;
|
|
5770
|
+
}, {});
|
|
5771
|
+
_context3.next = 6;
|
|
5772
|
+
return getAssistantAgent({
|
|
5773
|
+
id: agent.id,
|
|
5774
|
+
toolMap: toolMap
|
|
5775
|
+
});
|
|
5776
|
+
case 6:
|
|
5777
|
+
assistant = _context3.sent;
|
|
5778
|
+
return _context3.abrupt("return", assistant);
|
|
5779
|
+
case 10:
|
|
5780
|
+
if (!['OPEN_AI_VERCEL', 'ANTHROPIC_VERCEL', 'GROQ_VERCEL', 'PERPLEXITY_VERCEL', 'FIREWORKS_VERCEL'].includes(agent.model.provider)) {
|
|
5781
|
+
_context3.next = 19;
|
|
5782
|
+
break;
|
|
5783
|
+
}
|
|
5784
|
+
keyToModel = {
|
|
5785
|
+
OPEN_AI_VERCEL: 'openai',
|
|
5786
|
+
ANTHROPIC_VERCEL: 'anthropic',
|
|
5787
|
+
GROQ_VERCEL: 'groq',
|
|
5788
|
+
PERPLEXITY_VERCEL: 'perplexity',
|
|
5789
|
+
FIREWORKS_VERCEL: 'fireworks'
|
|
5790
|
+
};
|
|
5791
|
+
_tools = Object.keys(agent.tools);
|
|
5792
|
+
_toolMap = Object.entries(apis).reduce(function (memo, _ref4) {
|
|
5793
|
+
var k = _ref4[0],
|
|
5794
|
+
def = _ref4[1];
|
|
5795
|
+
if (_tools.includes(k)) {
|
|
5796
|
+
memo[k] = {
|
|
5797
|
+
description: def.label,
|
|
5798
|
+
parameters: def.schema,
|
|
5799
|
+
execute: function () {
|
|
5800
|
+
var _execute = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(props) {
|
|
5801
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5802
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5803
|
+
case 0:
|
|
5804
|
+
return _context2.abrupt("return", def.executor({
|
|
5805
|
+
data: props,
|
|
5806
|
+
ctx: {
|
|
5807
|
+
connectionId: connectionId
|
|
5808
|
+
}
|
|
5809
|
+
}));
|
|
5810
|
+
case 1:
|
|
5811
|
+
case "end":
|
|
5812
|
+
return _context2.stop();
|
|
5813
|
+
}
|
|
5814
|
+
}, _callee2);
|
|
5815
|
+
}));
|
|
5816
|
+
function execute(_x3) {
|
|
5817
|
+
return _execute.apply(this, arguments);
|
|
5818
|
+
}
|
|
5819
|
+
return execute;
|
|
5820
|
+
}()
|
|
5821
|
+
};
|
|
5822
|
+
}
|
|
5823
|
+
return memo;
|
|
5824
|
+
}, {});
|
|
5825
|
+
resultTool = undefined;
|
|
5826
|
+
if (agent.outputs.structured) {
|
|
5827
|
+
schema = Object.entries(agent.outputs.structured.schema).reduce(function (memo, _ref5) {
|
|
5828
|
+
var k = _ref5[0],
|
|
5829
|
+
v = _ref5[1];
|
|
5830
|
+
if (v.type === 'string') {
|
|
5831
|
+
memo[k] = zod.z.string();
|
|
5832
|
+
}
|
|
5833
|
+
if (v.type === 'array') {
|
|
5834
|
+
var _v$items;
|
|
5835
|
+
var itemType = v == null || (_v$items = v.items) == null ? void 0 : _v$items.type;
|
|
5836
|
+
if (itemType === 'string') {
|
|
5837
|
+
memo[k] = zod.z.array(zod.z.string());
|
|
5838
|
+
}
|
|
5839
|
+
}
|
|
5840
|
+
return memo;
|
|
5841
|
+
}, {});
|
|
5842
|
+
resultTool = {
|
|
5843
|
+
description: agent.outputs.structured.description,
|
|
5844
|
+
parameters: zod.z.object(schema)
|
|
5845
|
+
};
|
|
5846
|
+
}
|
|
5847
|
+
if (!(agent.model.generation_type === 'stream')) {
|
|
5848
|
+
_context3.next = 18;
|
|
5849
|
+
break;
|
|
5850
|
+
}
|
|
5851
|
+
return _context3.abrupt("return", createStreamAgent({
|
|
5852
|
+
agent_instructions: agent.agent_instructions,
|
|
5853
|
+
model: {
|
|
5854
|
+
type: keyToModel[agent.model.provider],
|
|
5855
|
+
name: agent.model.name,
|
|
5856
|
+
toolChoice: ((_agent$model = agent.model) == null ? void 0 : _agent$model.toolChoice) || 'required'
|
|
5857
|
+
},
|
|
5858
|
+
tools: _toolMap,
|
|
5859
|
+
resultTool: resultTool
|
|
5860
|
+
}));
|
|
5861
|
+
case 18:
|
|
5862
|
+
return _context3.abrupt("return", createAgent({
|
|
5863
|
+
agent_instructions: agent.agent_instructions,
|
|
5864
|
+
model: {
|
|
5865
|
+
type: keyToModel[agent.model.provider],
|
|
5866
|
+
name: agent.model.name,
|
|
5867
|
+
toolChoice: ((_agent$model2 = agent.model) == null ? void 0 : _agent$model2.toolChoice) || 'required'
|
|
5868
|
+
},
|
|
5869
|
+
tools: _toolMap,
|
|
5870
|
+
resultTool: resultTool
|
|
5871
|
+
}));
|
|
5872
|
+
case 19:
|
|
5873
|
+
case "end":
|
|
5874
|
+
return _context3.stop();
|
|
5875
|
+
}
|
|
5876
|
+
}, _callee3);
|
|
5877
|
+
}));
|
|
5878
|
+
return _getAgent.apply(this, arguments);
|
|
5879
|
+
}
|
|
5880
|
+
|
|
5881
|
+
var Mastra = /*#__PURE__*/function () {
|
|
5882
|
+
function Mastra(_ref) {
|
|
5883
|
+
var _this = this;
|
|
5884
|
+
var dataLayer = _ref.dataLayer,
|
|
5885
|
+
vectorLayer = _ref.vectorLayer,
|
|
5886
|
+
config = _ref.config;
|
|
5887
|
+
//global events grouped by Integration
|
|
5888
|
+
this.globalEvents = new Map();
|
|
5889
|
+
// global apis grouped by Integration
|
|
5890
|
+
this.globalApis = new Map();
|
|
5891
|
+
this.integrations = new Map();
|
|
5892
|
+
this.dataLayer = void 0;
|
|
5893
|
+
this.vectorLayer = void 0;
|
|
5894
|
+
this.agentsConfig = {
|
|
5895
|
+
agentDirPath: '',
|
|
5896
|
+
vectorProvider: []
|
|
5897
|
+
};
|
|
5898
|
+
this.config = void 0;
|
|
5899
|
+
this.runBlueprint = /*#__PURE__*/function () {
|
|
5900
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5901
|
+
var _this$availableIntegr;
|
|
5902
|
+
var blueprint, _ref2$dataCtx, dataCtx, ctx, systemApis, systemEvents, availableIntegrations, availableIntegrationApis, availableIntegrationEvents, frameworkApis, frameworkEvents;
|
|
5903
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5904
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5905
|
+
case 0:
|
|
5906
|
+
blueprint = _ref2.blueprint, _ref2$dataCtx = _ref2.dataCtx, dataCtx = _ref2$dataCtx === void 0 ? {} : _ref2$dataCtx, ctx = _ref2.ctx;
|
|
5907
|
+
systemApis = _this.getSystemApis();
|
|
5908
|
+
systemEvents = _this.getSystemEvents();
|
|
5909
|
+
availableIntegrations = (_this$availableIntegr = _this.availableIntegrations()) == null ? void 0 : _this$availableIntegr.map(function (_ref4) {
|
|
5910
|
+
var integration = _ref4.integration;
|
|
5911
|
+
return integration;
|
|
5912
|
+
});
|
|
5913
|
+
availableIntegrationApis = availableIntegrations.reduce(function (acc, _ref5) {
|
|
5914
|
+
var name = _ref5.name;
|
|
5915
|
+
var apis = _this.getApisByIntegration(name);
|
|
5916
|
+
return _extends({}, acc, apis);
|
|
5917
|
+
}, {});
|
|
5918
|
+
availableIntegrationEvents = availableIntegrations.reduce(function (acc, _ref6) {
|
|
5919
|
+
var name = _ref6.name;
|
|
5920
|
+
var events = _this.getEventsByIntegration(name);
|
|
5921
|
+
return _extends({}, acc, events);
|
|
5922
|
+
}, {});
|
|
5923
|
+
frameworkApis = _extends({}, systemApis, availableIntegrationApis);
|
|
5924
|
+
frameworkEvents = _extends({}, systemEvents, availableIntegrationEvents);
|
|
5925
|
+
_context.next = 10;
|
|
5926
|
+
return blueprintRunner({
|
|
5927
|
+
dataCtx: dataCtx,
|
|
5928
|
+
blueprint: blueprint,
|
|
5929
|
+
frameworkApis: frameworkApis,
|
|
5930
|
+
frameworkEvents: frameworkEvents,
|
|
5931
|
+
ctx: ctx
|
|
5932
|
+
});
|
|
5933
|
+
case 10:
|
|
5934
|
+
case "end":
|
|
5935
|
+
return _context.stop();
|
|
5936
|
+
}
|
|
5937
|
+
}, _callee);
|
|
5938
|
+
}));
|
|
5939
|
+
return function (_x) {
|
|
5940
|
+
return _ref3.apply(this, arguments);
|
|
5941
|
+
};
|
|
5942
|
+
}();
|
|
5943
|
+
this.dataLayer = dataLayer;
|
|
5944
|
+
this.vectorLayer = vectorLayer;
|
|
5945
|
+
this.config = config;
|
|
5946
|
+
}
|
|
5947
|
+
Mastra.init = function init(config) {
|
|
5948
|
+
var _config$workflows$sys;
|
|
5949
|
+
if (!config.db.uri) {
|
|
5950
|
+
throw new Error('No database config/provider found');
|
|
5951
|
+
}
|
|
5952
|
+
var dataLayer = new DataLayer({
|
|
5953
|
+
url: config.db.uri,
|
|
5954
|
+
provider: config.db.provider
|
|
5955
|
+
});
|
|
5956
|
+
var vectorLayer = new VectorLayer();
|
|
5957
|
+
var framework = new Mastra({
|
|
5958
|
+
config: config,
|
|
5959
|
+
dataLayer: dataLayer,
|
|
5960
|
+
vectorLayer: vectorLayer
|
|
5961
|
+
});
|
|
5962
|
+
// Register integrations
|
|
5963
|
+
config.integrations.forEach(function (integration) {
|
|
5964
|
+
framework.__registerIntgeration(integration);
|
|
5965
|
+
});
|
|
5966
|
+
// Register system apis
|
|
5967
|
+
framework.__registerApis({
|
|
5968
|
+
apis: [].concat(getAgentSystemApis({
|
|
5969
|
+
mastra: framework
|
|
5970
|
+
}), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
|
|
5971
|
+
return _extends({}, api, {
|
|
5972
|
+
integrationName: config.name
|
|
5973
|
+
});
|
|
5974
|
+
}), getVectorQueryApis({
|
|
5975
|
+
mastra: framework
|
|
5976
|
+
}))
|
|
5977
|
+
});
|
|
5978
|
+
// Register System events
|
|
5979
|
+
framework.__registerEvents({
|
|
5980
|
+
events: config.workflows.systemEvents
|
|
5981
|
+
});
|
|
5982
|
+
// Register vector sync event
|
|
5983
|
+
framework.__registerEvents({
|
|
5984
|
+
events: {
|
|
5985
|
+
AGENT_VECTOR_SYNC: {
|
|
5986
|
+
label: 'Sync vector data for an agent',
|
|
5987
|
+
description: 'Sync vector data for an agent',
|
|
5988
|
+
schema: zod.z.object({
|
|
5989
|
+
agentId: zod.z.string()
|
|
5990
|
+
}),
|
|
5991
|
+
handler: agentVectorSyncEvent
|
|
5992
|
+
},
|
|
5993
|
+
VECTOR_SYNC: {
|
|
5994
|
+
label: 'Sync vector data',
|
|
5995
|
+
description: 'Sync vector data',
|
|
5996
|
+
schema: zod.z.object({
|
|
5997
|
+
vector_provider: zod.z.string(),
|
|
5998
|
+
entities: zod.z.array(zod.z.object({
|
|
5999
|
+
integration: zod.z.string(),
|
|
6000
|
+
data: zod.z.array(zod.z.object({
|
|
6001
|
+
name: zod.z.string(),
|
|
6002
|
+
fields: zod.z.array(zod.z.string()),
|
|
6003
|
+
syncEvent: zod.z.string(),
|
|
6004
|
+
index: zod.z.string()
|
|
6005
|
+
}))
|
|
6006
|
+
}))
|
|
6007
|
+
}),
|
|
6008
|
+
handler: genericVectorySyncEvent
|
|
6009
|
+
}
|
|
6010
|
+
},
|
|
6011
|
+
integrationName: config.name
|
|
6012
|
+
});
|
|
6013
|
+
// Register agent config
|
|
6014
|
+
framework.agentsConfig = config.agents;
|
|
6015
|
+
return framework;
|
|
6016
|
+
};
|
|
6017
|
+
var _proto = Mastra.prototype;
|
|
6018
|
+
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
6019
|
+
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
|
|
6020
|
+
var _this2 = this;
|
|
6021
|
+
var context, ints, connectionChecks;
|
|
6022
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
6023
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
6024
|
+
case 0:
|
|
6025
|
+
context = _ref7.context;
|
|
6026
|
+
ints = this.availableIntegrations();
|
|
6027
|
+
_context3.next = 4;
|
|
6028
|
+
return Promise.all(ints.map(/*#__PURE__*/function () {
|
|
6029
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
|
|
6030
|
+
var integration, connection;
|
|
6031
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
6032
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
6033
|
+
case 0:
|
|
6034
|
+
integration = _ref8.integration;
|
|
6035
|
+
_context2.next = 3;
|
|
6036
|
+
return _this2.dataLayer.getConnection({
|
|
6037
|
+
connectionId: context.connectionId,
|
|
6038
|
+
name: integration.name
|
|
6039
|
+
});
|
|
6040
|
+
case 3:
|
|
6041
|
+
connection = _context2.sent;
|
|
6042
|
+
return _context2.abrupt("return", {
|
|
6043
|
+
integration: integration,
|
|
6044
|
+
connected: !!connection
|
|
6045
|
+
});
|
|
6046
|
+
case 5:
|
|
6047
|
+
case "end":
|
|
6048
|
+
return _context2.stop();
|
|
6049
|
+
}
|
|
6050
|
+
}, _callee2);
|
|
6051
|
+
}));
|
|
6052
|
+
return function (_x3) {
|
|
6053
|
+
return _ref9.apply(this, arguments);
|
|
6054
|
+
};
|
|
6055
|
+
}()));
|
|
6056
|
+
case 4:
|
|
6057
|
+
connectionChecks = _context3.sent;
|
|
6058
|
+
return _context3.abrupt("return", connectionChecks.filter(function (_ref10) {
|
|
6059
|
+
var connected = _ref10.connected;
|
|
6060
|
+
return connected;
|
|
6061
|
+
}).map(function (_ref11) {
|
|
6062
|
+
var integration = _ref11.integration;
|
|
6063
|
+
return integration;
|
|
6064
|
+
}));
|
|
6065
|
+
case 6:
|
|
6066
|
+
case "end":
|
|
6067
|
+
return _context3.stop();
|
|
6068
|
+
}
|
|
6069
|
+
}, _callee3, this);
|
|
6070
|
+
}));
|
|
6071
|
+
function connectedIntegrations(_x2) {
|
|
6072
|
+
return _connectedIntegrations.apply(this, arguments);
|
|
6073
|
+
}
|
|
6074
|
+
return connectedIntegrations;
|
|
6075
|
+
}();
|
|
6076
|
+
_proto.__registerIntgeration = function __registerIntgeration(definition) {
|
|
6077
|
+
var name = definition.name;
|
|
6078
|
+
definition.attachDataLayer({
|
|
6079
|
+
dataLayer: this.dataLayer
|
|
6080
|
+
});
|
|
6081
|
+
var router = this.createRouter();
|
|
6082
|
+
definition.corePresets = {
|
|
6083
|
+
redirectURI: router.makeRedirectURI()
|
|
6084
|
+
};
|
|
6085
|
+
this.integrations.set(name, definition);
|
|
6086
|
+
definition.registerEvents();
|
|
6087
|
+
this.__registerEvents({
|
|
6088
|
+
events: definition.getEvents(),
|
|
6089
|
+
integrationName: name
|
|
6090
|
+
});
|
|
6091
|
+
definition.registerApis();
|
|
6092
|
+
definition._convertApiClientToSystemApis();
|
|
6093
|
+
this.__registerApis({
|
|
6094
|
+
apis: Object.values(definition.getApis()),
|
|
6095
|
+
integrationName: name
|
|
6096
|
+
});
|
|
6097
|
+
};
|
|
6098
|
+
_proto.registerApi = function registerApi(name, api) {
|
|
6099
|
+
var _extends2;
|
|
6100
|
+
var integrationApis = this.globalApis.get(this.config.name) || {};
|
|
6101
|
+
this.globalApis.set(this.config.name, _extends({}, integrationApis, (_extends2 = {}, _extends2[name] = _extends({}, api, {
|
|
6102
|
+
integrationName: this.config.name
|
|
6103
|
+
}), _extends2)));
|
|
6104
|
+
};
|
|
6105
|
+
_proto.registerEvent = function registerEvent(name, event) {
|
|
6106
|
+
var _extends3;
|
|
6107
|
+
var integrationEvents = this.globalEvents.get('SYSTEM') || {};
|
|
6108
|
+
this.globalEvents.set('SYSTEM', _extends({}, integrationEvents, (_extends3 = {}, _extends3[name] = event, _extends3)));
|
|
6109
|
+
};
|
|
6110
|
+
_proto.__registerEvents = function __registerEvents(_ref12) {
|
|
6111
|
+
var events = _ref12.events,
|
|
6112
|
+
_ref12$integrationNam = _ref12.integrationName,
|
|
6113
|
+
integrationName = _ref12$integrationNam === void 0 ? this.config.name : _ref12$integrationNam;
|
|
6114
|
+
var integrationEvents = this.globalEvents.get(integrationName) || {};
|
|
6115
|
+
this.globalEvents.set(integrationName, _extends({}, integrationEvents, events));
|
|
6116
|
+
};
|
|
6117
|
+
_proto.__registerApis = function __registerApis(_ref13) {
|
|
6118
|
+
var apis = _ref13.apis,
|
|
6119
|
+
_ref13$integrationNam = _ref13.integrationName,
|
|
6120
|
+
integrationName = _ref13$integrationNam === void 0 ? this.config.name : _ref13$integrationNam;
|
|
6121
|
+
var integrationApis = this.globalApis.get(integrationName) || {};
|
|
6122
|
+
this.globalApis.set(integrationName, _extends({}, integrationApis, apis.reduce(function (acc, api) {
|
|
6123
|
+
var _extends4;
|
|
6124
|
+
return _extends({}, acc, (_extends4 = {}, _extends4[api.type] = api, _extends4));
|
|
6125
|
+
}, {})));
|
|
6126
|
+
};
|
|
6127
|
+
_proto.availableIntegrations = function availableIntegrations() {
|
|
6128
|
+
return Array.from(this.integrations.entries()).map(function (_ref14) {
|
|
6129
|
+
var name = _ref14[0],
|
|
6130
|
+
integration = _ref14[1];
|
|
6131
|
+
return {
|
|
6132
|
+
name: name,
|
|
6133
|
+
integration: integration
|
|
6134
|
+
};
|
|
6135
|
+
});
|
|
6136
|
+
};
|
|
6137
|
+
_proto.getIntegration = function getIntegration(name) {
|
|
6138
|
+
return this.integrations.get(name);
|
|
6139
|
+
};
|
|
6140
|
+
_proto.getGlobalEvents = function getGlobalEvents() {
|
|
6141
|
+
return this.globalEvents;
|
|
6142
|
+
};
|
|
6143
|
+
_proto.getSystemEvents = function getSystemEvents() {
|
|
6144
|
+
var events = this.globalEvents.get(this.config.name);
|
|
6145
|
+
return events || {};
|
|
6146
|
+
};
|
|
6147
|
+
_proto.getEventsByIntegration = function getEventsByIntegration(name) {
|
|
6148
|
+
return this.globalEvents.get(name);
|
|
6149
|
+
};
|
|
6150
|
+
_proto.getGlobalEventHandlers = function getGlobalEventHandlers() {
|
|
6151
|
+
var _this3 = this;
|
|
6152
|
+
return Array.from(this.globalEvents.entries()).flatMap(function (_ref15) {
|
|
6153
|
+
var integrationName = _ref15[0],
|
|
6154
|
+
events = _ref15[1];
|
|
6155
|
+
var groupedHandlers = Object.keys(events).map(function (eventKey) {
|
|
6156
|
+
var _events$eventKey;
|
|
6157
|
+
var eventHandler = (_events$eventKey = events[eventKey]) == null ? void 0 : _events$eventKey.handler;
|
|
6158
|
+
if (!eventHandler) return null;
|
|
6159
|
+
var isSystemEvent = integrationName === _this3.config.name;
|
|
6160
|
+
var _this3$createRouter = _this3.createRouter(),
|
|
6161
|
+
makeWebhookUrl = _this3$createRouter.makeWebhookUrl;
|
|
6162
|
+
if (isSystemEvent) {
|
|
6163
|
+
return eventHandler({
|
|
6164
|
+
getIntegration: function getIntegration(name) {
|
|
6165
|
+
return _this3.getIntegration(name);
|
|
6166
|
+
},
|
|
6167
|
+
eventKey: eventKey,
|
|
6168
|
+
getVectorProvider: function getVectorProvider(name) {
|
|
6169
|
+
return _this3.agentsConfig.vectorProvider.find(function (provider) {
|
|
6170
|
+
return provider.name === name;
|
|
6171
|
+
});
|
|
6172
|
+
},
|
|
6173
|
+
makeWebhookUrl: makeWebhookUrl
|
|
6174
|
+
});
|
|
6175
|
+
} else {
|
|
6176
|
+
var integration = _this3.getIntegration(integrationName);
|
|
6177
|
+
return eventHandler({
|
|
6178
|
+
integrationInstance: integration,
|
|
6179
|
+
eventKey: eventKey,
|
|
6180
|
+
makeWebhookUrl: makeWebhookUrl
|
|
6181
|
+
});
|
|
6182
|
+
}
|
|
6183
|
+
}).filter(Boolean);
|
|
6184
|
+
return groupedHandlers;
|
|
6185
|
+
});
|
|
6186
|
+
};
|
|
6187
|
+
_proto.getApis = function getApis() {
|
|
6188
|
+
return this.globalApis;
|
|
6189
|
+
};
|
|
6190
|
+
_proto.getSystemApis = function getSystemApis() {
|
|
6191
|
+
return this.globalApis.get(this.config.name);
|
|
6192
|
+
};
|
|
6193
|
+
_proto.getApisByIntegration = function getApisByIntegration(name, includeHidden) {
|
|
6194
|
+
var integrationApis = this.globalApis.get(name);
|
|
6195
|
+
if (includeHidden) {
|
|
6196
|
+
return integrationApis;
|
|
6197
|
+
}
|
|
6198
|
+
return _.omitBy(integrationApis, function (value) {
|
|
6199
|
+
return value.isHidden;
|
|
6200
|
+
});
|
|
6201
|
+
};
|
|
6202
|
+
_proto.authenticatableIntegrations = function authenticatableIntegrations() {
|
|
6203
|
+
return this.availableIntegrations().filter(function (_ref16) {
|
|
6204
|
+
var integration = _ref16.integration;
|
|
6205
|
+
try {
|
|
6206
|
+
integration.getAuthenticator();
|
|
6207
|
+
return true;
|
|
6208
|
+
} catch (e) {
|
|
6209
|
+
return false;
|
|
6210
|
+
}
|
|
6211
|
+
});
|
|
6212
|
+
};
|
|
6213
|
+
_proto.authenticator = function authenticator(name) {
|
|
6214
|
+
var _int = this.getIntegration(name);
|
|
6215
|
+
if (!_int) {
|
|
6216
|
+
throw new Error("No integration exists for " + name);
|
|
4491
6217
|
}
|
|
4492
6218
|
return _int.getAuthenticator();
|
|
4493
6219
|
};
|
|
4494
6220
|
_proto.connectIntegrationByCredential = /*#__PURE__*/function () {
|
|
4495
|
-
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(
|
|
6221
|
+
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref17) {
|
|
4496
6222
|
var name, connectionId, credential, authenticator, integration;
|
|
4497
6223
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4498
6224
|
while (1) switch (_context4.prev = _context4.next) {
|
|
4499
6225
|
case 0:
|
|
4500
|
-
name =
|
|
6226
|
+
name = _ref17.name, connectionId = _ref17.connectionId, credential = _ref17.credential;
|
|
4501
6227
|
authenticator = this.authenticator(name);
|
|
4502
6228
|
if (authenticator) {
|
|
4503
6229
|
_context4.next = 4;
|
|
@@ -4533,13 +6259,13 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4533
6259
|
return connectIntegrationByCredential;
|
|
4534
6260
|
}();
|
|
4535
6261
|
_proto.disconnectIntegration = /*#__PURE__*/function () {
|
|
4536
|
-
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(
|
|
6262
|
+
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref18) {
|
|
4537
6263
|
var _yield$this$dataLayer;
|
|
4538
6264
|
var name, connectionId, integration, k_id, authenticator;
|
|
4539
6265
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4540
6266
|
while (1) switch (_context5.prev = _context5.next) {
|
|
4541
6267
|
case 0:
|
|
4542
|
-
name =
|
|
6268
|
+
name = _ref18.name, connectionId = _ref18.connectionId;
|
|
4543
6269
|
integration = this.getIntegration(name);
|
|
4544
6270
|
_context5.next = 4;
|
|
4545
6271
|
return this.dataLayer.getConnection({
|
|
@@ -4600,14 +6326,14 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4600
6326
|
return disconnectIntegration;
|
|
4601
6327
|
}();
|
|
4602
6328
|
_proto.callApi = /*#__PURE__*/function () {
|
|
4603
|
-
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(
|
|
6329
|
+
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref19) {
|
|
4604
6330
|
var _int2$getApis;
|
|
4605
|
-
var
|
|
6331
|
+
var _ref19$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
|
|
4606
6332
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4607
6333
|
while (1) switch (_context6.prev = _context6.next) {
|
|
4608
6334
|
case 0:
|
|
4609
|
-
|
|
4610
|
-
if (!(integrationName === this.config.name)) {
|
|
6335
|
+
_ref19$integrationNam = _ref19.integrationName, integrationName = _ref19$integrationNam === void 0 ? this.config.name : _ref19$integrationNam, api = _ref19.api, payload = _ref19.payload;
|
|
6336
|
+
if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
|
|
4611
6337
|
_context6.next = 6;
|
|
4612
6338
|
break;
|
|
4613
6339
|
}
|
|
@@ -4647,19 +6373,19 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4647
6373
|
return callApi;
|
|
4648
6374
|
}();
|
|
4649
6375
|
_proto.subscribeEvent = /*#__PURE__*/function () {
|
|
4650
|
-
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(
|
|
4651
|
-
var _this$config$runner$u, _this$config$runner,
|
|
4652
|
-
var id,
|
|
6376
|
+
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
|
|
6377
|
+
var _this$config$runner$u, _this$config$runner, _ref21, _this$config$runner$s, _this$config$runner2;
|
|
6378
|
+
var id, _ref20$interval, interval, _ref20$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
|
|
4653
6379
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
4654
6380
|
while (1) switch (_context8.prev = _context8.next) {
|
|
4655
6381
|
case 0:
|
|
4656
|
-
id =
|
|
6382
|
+
id = _ref20.id, _ref20$interval = _ref20.interval, interval = _ref20$interval === void 0 ? 5000 : _ref20$interval, _ref20$timeout = _ref20.timeout, timeout = _ref20$timeout === void 0 ? 60000 : _ref20$timeout;
|
|
4657
6383
|
inngestApiUrl = (_this$config$runner$u = (_this$config$runner = this.config.runner) == null ? void 0 : _this$config$runner.uri) != null ? _this$config$runner$u : process.env.INNGEST_URL;
|
|
4658
|
-
inngestApiToken = (
|
|
6384
|
+
inngestApiToken = (_ref21 = (_this$config$runner$s = (_this$config$runner2 = this.config.runner) == null ? void 0 : _this$config$runner2.signingKey) != null ? _this$config$runner$s : process.env.INNGEST_SIGNING_KEY) != null ? _ref21 : '123';
|
|
4659
6385
|
startTime = Date.now();
|
|
4660
6386
|
_poll = /*#__PURE__*/function () {
|
|
4661
|
-
var
|
|
4662
|
-
var response,
|
|
6387
|
+
var _ref22 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
6388
|
+
var response, obj, data, error, lastRun, elapsedTime;
|
|
4663
6389
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4664
6390
|
while (1) switch (_context7.prev = _context7.next) {
|
|
4665
6391
|
case 0:
|
|
@@ -4674,65 +6400,93 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4674
6400
|
});
|
|
4675
6401
|
case 3:
|
|
4676
6402
|
response = _context7.sent;
|
|
6403
|
+
console.log("Polling for event " + id + "...", response.ok);
|
|
4677
6404
|
if (!response.ok) {
|
|
4678
|
-
_context7.next =
|
|
6405
|
+
_context7.next = 28;
|
|
4679
6406
|
break;
|
|
4680
6407
|
}
|
|
4681
|
-
_context7.next =
|
|
6408
|
+
_context7.next = 8;
|
|
4682
6409
|
return response.json();
|
|
4683
|
-
case
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
6410
|
+
case 8:
|
|
6411
|
+
obj = _context7.sent;
|
|
6412
|
+
console.log({
|
|
6413
|
+
obj: obj
|
|
6414
|
+
});
|
|
6415
|
+
data = obj.data, error = obj.error;
|
|
6416
|
+
console.log("Got data for event " + id + "...", data, error);
|
|
4687
6417
|
if (!error) {
|
|
4688
|
-
_context7.next =
|
|
6418
|
+
_context7.next = 15;
|
|
4689
6419
|
break;
|
|
4690
6420
|
}
|
|
6421
|
+
console.error(error);
|
|
4691
6422
|
return _context7.abrupt("return", null);
|
|
4692
|
-
case
|
|
6423
|
+
case 15:
|
|
6424
|
+
if (!((data == null ? void 0 : data.length) === 0)) {
|
|
6425
|
+
_context7.next = 19;
|
|
6426
|
+
break;
|
|
6427
|
+
}
|
|
6428
|
+
_context7.next = 18;
|
|
6429
|
+
return new Promise(function (resolve) {
|
|
6430
|
+
return setTimeout(resolve, interval);
|
|
6431
|
+
});
|
|
6432
|
+
case 18:
|
|
6433
|
+
return _context7.abrupt("return", _poll());
|
|
6434
|
+
case 19:
|
|
4693
6435
|
lastRun = data == null ? void 0 : data[0];
|
|
6436
|
+
console.log(lastRun);
|
|
4694
6437
|
if (lastRun) {
|
|
4695
|
-
_context7.next =
|
|
6438
|
+
_context7.next = 23;
|
|
4696
6439
|
break;
|
|
4697
6440
|
}
|
|
4698
6441
|
return _context7.abrupt("return", null);
|
|
4699
|
-
case
|
|
6442
|
+
case 23:
|
|
6443
|
+
if (!(lastRun.status === 'Running')) {
|
|
6444
|
+
_context7.next = 27;
|
|
6445
|
+
break;
|
|
6446
|
+
}
|
|
6447
|
+
_context7.next = 26;
|
|
6448
|
+
return new Promise(function (resolve) {
|
|
6449
|
+
return setTimeout(resolve, interval);
|
|
6450
|
+
});
|
|
6451
|
+
case 26:
|
|
6452
|
+
return _context7.abrupt("return", _poll());
|
|
6453
|
+
case 27:
|
|
4700
6454
|
return _context7.abrupt("return", {
|
|
4701
6455
|
status: lastRun.status,
|
|
4702
6456
|
startedAt: lastRun.run_started_at,
|
|
4703
6457
|
endedAt: lastRun.ended_at
|
|
4704
6458
|
});
|
|
4705
|
-
case
|
|
4706
|
-
_context7.next =
|
|
6459
|
+
case 28:
|
|
6460
|
+
_context7.next = 33;
|
|
4707
6461
|
break;
|
|
4708
|
-
case
|
|
4709
|
-
_context7.prev =
|
|
6462
|
+
case 30:
|
|
6463
|
+
_context7.prev = 30;
|
|
4710
6464
|
_context7.t0 = _context7["catch"](0);
|
|
4711
6465
|
console.error("Request failed: " + _context7.t0);
|
|
4712
|
-
case
|
|
6466
|
+
case 33:
|
|
4713
6467
|
// Check if timeout has been reached
|
|
4714
6468
|
elapsedTime = Date.now() - startTime;
|
|
4715
6469
|
if (!(elapsedTime >= timeout)) {
|
|
4716
|
-
_context7.next =
|
|
6470
|
+
_context7.next = 37;
|
|
4717
6471
|
break;
|
|
4718
6472
|
}
|
|
4719
6473
|
console.log('Polling timeout reached.');
|
|
4720
6474
|
return _context7.abrupt("return", null);
|
|
4721
|
-
case
|
|
4722
|
-
_context7.next =
|
|
6475
|
+
case 37:
|
|
6476
|
+
_context7.next = 39;
|
|
4723
6477
|
return new Promise(function (resolve) {
|
|
4724
6478
|
return setTimeout(resolve, interval);
|
|
4725
6479
|
});
|
|
4726
|
-
case
|
|
6480
|
+
case 39:
|
|
4727
6481
|
return _context7.abrupt("return", _poll());
|
|
4728
|
-
case
|
|
6482
|
+
case 40:
|
|
4729
6483
|
case "end":
|
|
4730
6484
|
return _context7.stop();
|
|
4731
6485
|
}
|
|
4732
|
-
}, _callee7, null, [[0,
|
|
6486
|
+
}, _callee7, null, [[0, 30]]);
|
|
4733
6487
|
}));
|
|
4734
6488
|
return function poll() {
|
|
4735
|
-
return
|
|
6489
|
+
return _ref22.apply(this, arguments);
|
|
4736
6490
|
};
|
|
4737
6491
|
}();
|
|
4738
6492
|
return _context8.abrupt("return", _poll());
|
|
@@ -4748,13 +6502,13 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4748
6502
|
return subscribeEvent;
|
|
4749
6503
|
}();
|
|
4750
6504
|
_proto.triggerEvent = /*#__PURE__*/function () {
|
|
4751
|
-
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(
|
|
4752
|
-
var
|
|
4753
|
-
var key, data, user,
|
|
6505
|
+
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref23) {
|
|
6506
|
+
var _this4 = this;
|
|
6507
|
+
var key, data, user, _ref23$integrationNam, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
|
|
4754
6508
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
4755
6509
|
while (1) switch (_context11.prev = _context11.next) {
|
|
4756
6510
|
case 0:
|
|
4757
|
-
key =
|
|
6511
|
+
key = _ref23.key, data = _ref23.data, user = _ref23.user, _ref23$integrationNam = _ref23.integrationName, integrationName = _ref23$integrationNam === void 0 ? this.config.name : _ref23$integrationNam;
|
|
4758
6512
|
_context11.prev = 1;
|
|
4759
6513
|
returnObj = {
|
|
4760
6514
|
event: {}
|
|
@@ -4774,7 +6528,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4774
6528
|
throw new Error("No event exists for " + key + " in " + integrationName);
|
|
4775
6529
|
case 9:
|
|
4776
6530
|
_context11.next = 11;
|
|
4777
|
-
return client.send({
|
|
6531
|
+
return client$1.send({
|
|
4778
6532
|
name: key,
|
|
4779
6533
|
data: data,
|
|
4780
6534
|
user: user
|
|
@@ -4785,12 +6539,12 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4785
6539
|
subscribe: function () {
|
|
4786
6540
|
var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_temp) {
|
|
4787
6541
|
var _event$ids;
|
|
4788
|
-
var
|
|
6542
|
+
var _ref24, interval, timeout;
|
|
4789
6543
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
4790
6544
|
while (1) switch (_context9.prev = _context9.next) {
|
|
4791
6545
|
case 0:
|
|
4792
|
-
|
|
4793
|
-
return _context9.abrupt("return",
|
|
6546
|
+
_ref24 = _temp === void 0 ? {} : _temp, interval = _ref24.interval, timeout = _ref24.timeout;
|
|
6547
|
+
return _context9.abrupt("return", _this4.subscribeEvent({
|
|
4794
6548
|
id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
|
|
4795
6549
|
interval: interval,
|
|
4796
6550
|
timeout: timeout
|
|
@@ -4808,7 +6562,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4808
6562
|
}()
|
|
4809
6563
|
});
|
|
4810
6564
|
_context11.next = 15;
|
|
4811
|
-
return client.send({
|
|
6565
|
+
return client$1.send({
|
|
4812
6566
|
name: 'workflow/run-automations',
|
|
4813
6567
|
data: {
|
|
4814
6568
|
trigger: key,
|
|
@@ -4822,12 +6576,12 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4822
6576
|
subscribe: function () {
|
|
4823
6577
|
var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp2) {
|
|
4824
6578
|
var _workflowEvent$ids;
|
|
4825
|
-
var
|
|
6579
|
+
var _ref25, interval, timeout;
|
|
4826
6580
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
4827
6581
|
while (1) switch (_context10.prev = _context10.next) {
|
|
4828
6582
|
case 0:
|
|
4829
|
-
|
|
4830
|
-
return _context10.abrupt("return",
|
|
6583
|
+
_ref25 = _temp2 === void 0 ? {} : _temp2, interval = _ref25.interval, timeout = _ref25.timeout;
|
|
6584
|
+
return _context10.abrupt("return", _this4.subscribeEvent({
|
|
4831
6585
|
id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
|
|
4832
6586
|
interval: interval,
|
|
4833
6587
|
timeout: timeout
|
|
@@ -4864,14 +6618,14 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4864
6618
|
_proto.triggerSystemEvent =
|
|
4865
6619
|
/*#__PURE__*/
|
|
4866
6620
|
function () {
|
|
4867
|
-
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(
|
|
6621
|
+
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref26) {
|
|
4868
6622
|
var key, data, user, event, systemEvent;
|
|
4869
6623
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
4870
6624
|
while (1) switch (_context12.prev = _context12.next) {
|
|
4871
6625
|
case 0:
|
|
4872
|
-
key =
|
|
6626
|
+
key = _ref26.key, data = _ref26.data, user = _ref26.user;
|
|
4873
6627
|
_context12.next = 3;
|
|
4874
|
-
return client.send({
|
|
6628
|
+
return client$1.send({
|
|
4875
6629
|
name: key,
|
|
4876
6630
|
data: data,
|
|
4877
6631
|
user: user
|
|
@@ -4884,7 +6638,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4884
6638
|
break;
|
|
4885
6639
|
}
|
|
4886
6640
|
_context12.next = 8;
|
|
4887
|
-
return client.send({
|
|
6641
|
+
return client$1.send({
|
|
4888
6642
|
name: 'workflow/run-automations',
|
|
4889
6643
|
data: {
|
|
4890
6644
|
trigger: key,
|
|
@@ -4907,10 +6661,10 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4907
6661
|
}();
|
|
4908
6662
|
_proto.createRouter = function createRouter() {
|
|
4909
6663
|
var self = this;
|
|
4910
|
-
var makeWebhookUrl = function makeWebhookUrl(
|
|
6664
|
+
var makeWebhookUrl = function makeWebhookUrl(_ref27) {
|
|
4911
6665
|
var _self$config;
|
|
4912
|
-
var event =
|
|
4913
|
-
name =
|
|
6666
|
+
var event = _ref27.event,
|
|
6667
|
+
name = _ref27.name;
|
|
4914
6668
|
return encodeURI("" + (self == null || (_self$config = self.config) == null ? void 0 : _self$config.systemHostURL) + self.routes.webhook + "?name=" + name + "&event=" + event);
|
|
4915
6669
|
};
|
|
4916
6670
|
var makeRedirectURI = function makeRedirectURI() {
|
|
@@ -4940,21 +6694,56 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4940
6694
|
registerRoutes: registerRoutes
|
|
4941
6695
|
};
|
|
4942
6696
|
};
|
|
4943
|
-
|
|
6697
|
+
_proto.getAgent = /*#__PURE__*/function () {
|
|
6698
|
+
var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref28) {
|
|
6699
|
+
var connectionId, agentId, agentBlueprint, arrMap, finalApis;
|
|
6700
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
6701
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
6702
|
+
case 0:
|
|
6703
|
+
connectionId = _ref28.connectionId, agentId = _ref28.agentId;
|
|
6704
|
+
_context13.next = 3;
|
|
6705
|
+
return getAgentBlueprint({
|
|
6706
|
+
agentDir: this.config.agents.agentDirPath,
|
|
6707
|
+
agentId: agentId
|
|
6708
|
+
});
|
|
6709
|
+
case 3:
|
|
6710
|
+
agentBlueprint = _context13.sent;
|
|
6711
|
+
arrMap = Array.from(this.getApis());
|
|
6712
|
+
finalApis = arrMap.reduce(function (acc, _ref29) {
|
|
6713
|
+
var v = _ref29[1];
|
|
6714
|
+
return _extends({}, acc, v);
|
|
6715
|
+
}, {});
|
|
6716
|
+
return _context13.abrupt("return", getAgent({
|
|
6717
|
+
connectionId: connectionId,
|
|
6718
|
+
agent: agentBlueprint,
|
|
6719
|
+
apis: finalApis
|
|
6720
|
+
}));
|
|
6721
|
+
case 7:
|
|
6722
|
+
case "end":
|
|
6723
|
+
return _context13.stop();
|
|
6724
|
+
}
|
|
6725
|
+
}, _callee13, this);
|
|
6726
|
+
}));
|
|
6727
|
+
function getAgent$1(_x12) {
|
|
6728
|
+
return _getAgent2.apply(this, arguments);
|
|
6729
|
+
}
|
|
6730
|
+
return getAgent$1;
|
|
6731
|
+
}();
|
|
6732
|
+
return _createClass(Mastra, [{
|
|
4944
6733
|
key: "routes",
|
|
4945
6734
|
get: function get() {
|
|
4946
|
-
var
|
|
6735
|
+
var _this5 = this;
|
|
4947
6736
|
var registry = {
|
|
4948
6737
|
connect: '/connect',
|
|
4949
6738
|
callback: '/connect/callback',
|
|
4950
6739
|
inngest: '/inngest',
|
|
4951
6740
|
webhook: '/webhook'
|
|
4952
6741
|
};
|
|
4953
|
-
return Object.entries(registry).reduce(function (acc,
|
|
4954
|
-
var
|
|
4955
|
-
var key =
|
|
4956
|
-
value =
|
|
4957
|
-
return _extends({}, acc, (
|
|
6742
|
+
return Object.entries(registry).reduce(function (acc, _ref30) {
|
|
6743
|
+
var _extends5;
|
|
6744
|
+
var key = _ref30[0],
|
|
6745
|
+
value = _ref30[1];
|
|
6746
|
+
return _extends({}, acc, (_extends5 = {}, _extends5[key] = "" + _this5.config.routeRegistrationPath + value, _extends5));
|
|
4958
6747
|
}, {});
|
|
4959
6748
|
}
|
|
4960
6749
|
}]);
|
|
@@ -4962,16 +6751,16 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4962
6751
|
|
|
4963
6752
|
Object.defineProperty(exports, 'PropertyType', {
|
|
4964
6753
|
enumerable: true,
|
|
4965
|
-
get: function () { return client$
|
|
6754
|
+
get: function () { return client$2.PropertyType; }
|
|
4966
6755
|
});
|
|
4967
6756
|
exports.DataLayer = DataLayer;
|
|
4968
6757
|
exports.FieldTypePrimitiveMap = FieldTypePrimitiveMap;
|
|
4969
6758
|
exports.FilterOperatorToSQL = FilterOperatorToSQL;
|
|
4970
|
-
exports.Framework = Framework;
|
|
4971
6759
|
exports.Integration = Integration;
|
|
4972
6760
|
exports.IntegrationAuth = IntegrationAuth;
|
|
4973
6761
|
exports.IntegrationError = IntegrationError;
|
|
4974
6762
|
exports.IntegrationFieldTypeEnum = IntegrationFieldTypeEnum;
|
|
6763
|
+
exports.Mastra = Mastra;
|
|
4975
6764
|
exports.RunStatus = RunStatus;
|
|
4976
6765
|
exports.SORT_MODE_TO_ABBR = SORT_MODE_TO_ABBR;
|
|
4977
6766
|
exports.WorkflowStatusEnum = WorkflowStatusEnum;
|