@mastra/core 0.1.2 → 0.1.4
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 +2155 -374
- 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 +2140 -358
- 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/prisma/migrations/20241008024219_initial_migration/migration.sql +69 -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 +59 -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 +7 -3
package/dist/core.esm.js
CHANGED
|
@@ -11,11 +11,17 @@ import qs from 'qs';
|
|
|
11
11
|
import { serve } from 'inngest/next';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import * as fs from 'fs';
|
|
14
|
+
import { readdirSync, readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
14
15
|
import first from 'lodash-es/first';
|
|
15
16
|
import last from 'lodash-es/last';
|
|
16
17
|
import { Inngest } from 'inngest';
|
|
17
18
|
import { OAuth2Client } from '@badgateway/oauth2-client';
|
|
18
|
-
import _, { isEmpty, omit, omitBy } from 'lodash-es';
|
|
19
|
+
import _, { isEmpty, omit, pick, compact, omitBy } from 'lodash-es';
|
|
20
|
+
import { openai, createOpenAI } from '@ai-sdk/openai';
|
|
21
|
+
import { embed, tool, generateText, streamText } from 'ai';
|
|
22
|
+
import { Pinecone } from '@pinecone-database/pinecone';
|
|
23
|
+
import OpenAI from 'openai';
|
|
24
|
+
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
19
25
|
|
|
20
26
|
var WorkflowStatusEnum = {
|
|
21
27
|
DRAFT: 'DRAFT',
|
|
@@ -1357,7 +1363,7 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1357
1363
|
}
|
|
1358
1364
|
uniqueRecords = Array.from(uniqueRecordsMap.values());
|
|
1359
1365
|
externalIds = uniqueRecords.map(function (record) {
|
|
1360
|
-
return record.externalId;
|
|
1366
|
+
return String(record.externalId);
|
|
1361
1367
|
});
|
|
1362
1368
|
_context16.next = 9;
|
|
1363
1369
|
return this.db.record.findMany({
|
|
@@ -1379,7 +1385,7 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1379
1385
|
toUpdate = [];
|
|
1380
1386
|
uniqueRecords.forEach(function (record) {
|
|
1381
1387
|
var existing = existingRecords.find(function (existingRecord) {
|
|
1382
|
-
return existingRecord.externalId === record.externalId;
|
|
1388
|
+
return existingRecord.externalId === String(record.externalId);
|
|
1383
1389
|
});
|
|
1384
1390
|
if (existing) {
|
|
1385
1391
|
toUpdate.push(_extends({}, record, {
|
|
@@ -1387,6 +1393,7 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1387
1393
|
}));
|
|
1388
1394
|
} else {
|
|
1389
1395
|
toCreate.push(_extends({}, record, {
|
|
1396
|
+
externalId: String(record.externalId),
|
|
1390
1397
|
entityId: entityId
|
|
1391
1398
|
}));
|
|
1392
1399
|
}
|
|
@@ -1394,6 +1401,7 @@ var DataLayer = /*#__PURE__*/function () {
|
|
|
1394
1401
|
createPromise = toCreate.length ? this.db.record.createMany({
|
|
1395
1402
|
data: toCreate.map(function (record) {
|
|
1396
1403
|
return _extends({}, record, {
|
|
1404
|
+
externalId: String(record.externalId),
|
|
1397
1405
|
data: record.data
|
|
1398
1406
|
});
|
|
1399
1407
|
})
|
|
@@ -1839,7 +1847,7 @@ var makeCallback = function makeCallback(framework) {
|
|
|
1839
1847
|
};
|
|
1840
1848
|
|
|
1841
1849
|
var APP_ID = 'mastra';
|
|
1842
|
-
var client = /*#__PURE__*/new Inngest({
|
|
1850
|
+
var client$1 = /*#__PURE__*/new Inngest({
|
|
1843
1851
|
id: APP_ID
|
|
1844
1852
|
});
|
|
1845
1853
|
|
|
@@ -1946,7 +1954,7 @@ function _getBlueprints() {
|
|
|
1946
1954
|
var createWorkflowHandler = function createWorkflowHandler(_ref2) {
|
|
1947
1955
|
var blueprintDirPath = _ref2.blueprintDirPath,
|
|
1948
1956
|
runBlueprint = _ref2.runBlueprint;
|
|
1949
|
-
return client.createFunction({
|
|
1957
|
+
return client$1.createFunction({
|
|
1950
1958
|
id: 'workflow-executor',
|
|
1951
1959
|
retries: 0
|
|
1952
1960
|
}, {
|
|
@@ -2041,18 +2049,35 @@ var makeInngest = function makeInngest(framework) {
|
|
|
2041
2049
|
// TODO: hook into framework to add framework functions to the inngest client
|
|
2042
2050
|
var eventHandlers = framework.getGlobalEventHandlers();
|
|
2043
2051
|
var globalEventHandlers = eventHandlers.map(function (eh) {
|
|
2044
|
-
return client.createFunction({
|
|
2052
|
+
return client$1.createFunction({
|
|
2045
2053
|
id: eh.id
|
|
2046
2054
|
}, {
|
|
2047
2055
|
event: eh.event
|
|
2048
|
-
},
|
|
2056
|
+
}, /*#__PURE__*/function () {
|
|
2057
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
2058
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2059
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2060
|
+
case 0:
|
|
2061
|
+
return _context.abrupt("return", eh.executor(_extends({}, props, {
|
|
2062
|
+
mastra: framework
|
|
2063
|
+
})));
|
|
2064
|
+
case 1:
|
|
2065
|
+
case "end":
|
|
2066
|
+
return _context.stop();
|
|
2067
|
+
}
|
|
2068
|
+
}, _callee);
|
|
2069
|
+
}));
|
|
2070
|
+
return function (_x) {
|
|
2071
|
+
return _ref.apply(this, arguments);
|
|
2072
|
+
};
|
|
2073
|
+
}());
|
|
2049
2074
|
});
|
|
2050
2075
|
var systemWorkflowHandler = createWorkflowHandler({
|
|
2051
2076
|
blueprintDirPath: (_framework$config$wor = framework.config.workflows) == null ? void 0 : _framework$config$wor.blueprintDirPath,
|
|
2052
2077
|
runBlueprint: framework.runBlueprint
|
|
2053
2078
|
});
|
|
2054
2079
|
var handler = serve({
|
|
2055
|
-
client: client,
|
|
2080
|
+
client: client$1,
|
|
2056
2081
|
functions: [].concat(globalEventHandlers, [systemWorkflowHandler])
|
|
2057
2082
|
});
|
|
2058
2083
|
// @ts-ignore
|
|
@@ -2411,19 +2436,6 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2411
2436
|
return _ref4.apply(this, arguments);
|
|
2412
2437
|
};
|
|
2413
2438
|
}();
|
|
2414
|
-
this.getEventHandlers = function (_ref5) {
|
|
2415
|
-
var makeWebhookUrl = _ref5.makeWebhookUrl;
|
|
2416
|
-
return Object.keys(_this.events).map(function (eventKey) {
|
|
2417
|
-
var _this$events$eventKey;
|
|
2418
|
-
var eventHandler = (_this$events$eventKey = _this.events[eventKey]) == null ? void 0 : _this$events$eventKey.handler;
|
|
2419
|
-
if (!eventHandler) return null;
|
|
2420
|
-
return eventHandler({
|
|
2421
|
-
integrationInstance: _this,
|
|
2422
|
-
eventKey: eventKey,
|
|
2423
|
-
makeWebhookUrl: makeWebhookUrl
|
|
2424
|
-
});
|
|
2425
|
-
}).filter(Boolean);
|
|
2426
|
-
};
|
|
2427
2439
|
if (!(config != null && config.name)) {
|
|
2428
2440
|
throw new IntegrationError('Integration name must be defined');
|
|
2429
2441
|
}
|
|
@@ -2468,12 +2480,12 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2468
2480
|
return getApiClient;
|
|
2469
2481
|
}();
|
|
2470
2482
|
_proto.getApi = /*#__PURE__*/function () {
|
|
2471
|
-
var _getApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(
|
|
2483
|
+
var _getApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
|
|
2472
2484
|
var connectionId;
|
|
2473
2485
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
2474
2486
|
while (1) switch (_context5.prev = _context5.next) {
|
|
2475
2487
|
case 0:
|
|
2476
|
-
connectionId =
|
|
2488
|
+
connectionId = _ref5.connectionId;
|
|
2477
2489
|
_context5.next = 3;
|
|
2478
2490
|
return this.getApiClient({
|
|
2479
2491
|
connectionId: connectionId
|
|
@@ -2497,8 +2509,8 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2497
2509
|
_proto.getAuthenticator = function getAuthenticator() {
|
|
2498
2510
|
throw new IntegrationError('Authenticator not implemented');
|
|
2499
2511
|
};
|
|
2500
|
-
_proto.attachDataLayer = function attachDataLayer(
|
|
2501
|
-
var dataLayer =
|
|
2512
|
+
_proto.attachDataLayer = function attachDataLayer(_ref6) {
|
|
2513
|
+
var dataLayer = _ref6.dataLayer;
|
|
2502
2514
|
this.dataLayer = dataLayer;
|
|
2503
2515
|
};
|
|
2504
2516
|
_proto.registerApis = function registerApis() {
|
|
@@ -2555,14 +2567,14 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2555
2567
|
return processWebhookRequest;
|
|
2556
2568
|
}();
|
|
2557
2569
|
_proto.triggerEvent = /*#__PURE__*/function () {
|
|
2558
|
-
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(
|
|
2570
|
+
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref7) {
|
|
2559
2571
|
var key, data, user, event;
|
|
2560
2572
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
2561
2573
|
while (1) switch (_context8.prev = _context8.next) {
|
|
2562
2574
|
case 0:
|
|
2563
|
-
key =
|
|
2575
|
+
key = _ref7.key, data = _ref7.data, user = _ref7.user;
|
|
2564
2576
|
_context8.next = 3;
|
|
2565
|
-
return client.send({
|
|
2577
|
+
return client$1.send({
|
|
2566
2578
|
name: key,
|
|
2567
2579
|
data: data,
|
|
2568
2580
|
user: user
|
|
@@ -2582,13 +2594,13 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2582
2594
|
return triggerEvent;
|
|
2583
2595
|
}();
|
|
2584
2596
|
_proto.test = /*#__PURE__*/function () {
|
|
2585
|
-
var _test = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(
|
|
2597
|
+
var _test = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref8) {
|
|
2586
2598
|
var _this$dataLayer;
|
|
2587
2599
|
var connectionId, connection, _this$config$scopes, authenticator, bearer, desiredScopes, _bearer$scope, actualScopes, isMissingScopes;
|
|
2588
2600
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
2589
2601
|
while (1) switch (_context9.prev = _context9.next) {
|
|
2590
2602
|
case 0:
|
|
2591
|
-
connectionId =
|
|
2603
|
+
connectionId = _ref8.connectionId;
|
|
2592
2604
|
_context9.next = 3;
|
|
2593
2605
|
return (_this$dataLayer = this.dataLayer) == null ? void 0 : _this$dataLayer.getConnection({
|
|
2594
2606
|
connectionId: connectionId,
|
|
@@ -2639,7 +2651,7 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2639
2651
|
return test;
|
|
2640
2652
|
}();
|
|
2641
2653
|
_proto.onConnectionCreated = /*#__PURE__*/function () {
|
|
2642
|
-
var _onConnectionCreated = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(
|
|
2654
|
+
var _onConnectionCreated = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref9) {
|
|
2643
2655
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
2644
2656
|
while (1) switch (_context10.prev = _context10.next) {
|
|
2645
2657
|
case 0:
|
|
@@ -2655,7 +2667,7 @@ var Integration = /*#__PURE__*/function () {
|
|
|
2655
2667
|
return onConnectionCreated;
|
|
2656
2668
|
}();
|
|
2657
2669
|
_proto.onDisconnect = /*#__PURE__*/function () {
|
|
2658
|
-
var _onDisconnect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(
|
|
2670
|
+
var _onDisconnect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref10) {
|
|
2659
2671
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
2660
2672
|
while (1) switch (_context11.prev = _context11.next) {
|
|
2661
2673
|
case 0:
|
|
@@ -3206,19 +3218,6 @@ function allowedKey(key) {
|
|
|
3206
3218
|
}
|
|
3207
3219
|
return false;
|
|
3208
3220
|
}
|
|
3209
|
-
function transformKey(input) {
|
|
3210
|
-
// Use a regular expression to match 'get', followed by any characters and then the first uppercase letter
|
|
3211
|
-
return input.replace(/^(get|Get)([A-Z][a-z]*)/, function (_, __, firstPart) {
|
|
3212
|
-
// Convert the first meaningful part to lowercase
|
|
3213
|
-
return firstPart.toLowerCase();
|
|
3214
|
-
}).replace(/^([a-z]+)([A-Z].*)?$/, function (_, firstPart) {
|
|
3215
|
-
// Return the first part in lowercase
|
|
3216
|
-
return firstPart.toLowerCase();
|
|
3217
|
-
}).replace(/^([a-z]+)([A-Z].*)?$/, function (_, firstPart) {
|
|
3218
|
-
// Return the first part in lowercase
|
|
3219
|
-
return firstPart.toLowerCase();
|
|
3220
|
-
});
|
|
3221
|
-
}
|
|
3222
3221
|
function extractPlural(input) {
|
|
3223
3222
|
// Use a regular expression to match the pattern
|
|
3224
3223
|
var regex = /^get([A-Z][a-z]*(?:[A-Z][a-z]*)*)(?:([A-Z][a-z]+))?$/;
|
|
@@ -3256,7 +3255,8 @@ function getEntityKey(key) {
|
|
|
3256
3255
|
}
|
|
3257
3256
|
return removeDuplicateWord(pluralS.toLowerCase());
|
|
3258
3257
|
}
|
|
3259
|
-
return
|
|
3258
|
+
return key;
|
|
3259
|
+
// return transformKey(key);
|
|
3260
3260
|
}
|
|
3261
3261
|
function generateSyncs(_ref4) {
|
|
3262
3262
|
var client = _ref4.client,
|
|
@@ -3291,7 +3291,7 @@ function generateSyncs(_ref4) {
|
|
|
3291
3291
|
event: eventKey,
|
|
3292
3292
|
executor: function () {
|
|
3293
3293
|
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
|
|
3294
|
-
var event, connectionId, options, api, result, resultData, records;
|
|
3294
|
+
var event, connectionId, options, api, result, resultData, fallbackIDKey, records;
|
|
3295
3295
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3296
3296
|
while (1) switch (_context.prev = _context.next) {
|
|
3297
3297
|
case 0:
|
|
@@ -3316,14 +3316,17 @@ function generateSyncs(_ref4) {
|
|
|
3316
3316
|
result = _context.sent;
|
|
3317
3317
|
// First see if we are getting the list data
|
|
3318
3318
|
resultData = (result == null ? void 0 : result[listDataKey]) || [result];
|
|
3319
|
+
fallbackIDKey = Object.keys(resultData[0]).find(function (k) {
|
|
3320
|
+
return k.includes('id');
|
|
3321
|
+
}) || 'id';
|
|
3319
3322
|
records = resultData == null ? void 0 : resultData.map(function (d) {
|
|
3320
3323
|
return {
|
|
3321
|
-
externalId: d[idKey],
|
|
3324
|
+
externalId: d[idKey] || d[fallbackIDKey],
|
|
3322
3325
|
data: d,
|
|
3323
3326
|
entityType: entityKey.toUpperCase()
|
|
3324
3327
|
};
|
|
3325
3328
|
});
|
|
3326
|
-
_context.next =
|
|
3329
|
+
_context.next = 15;
|
|
3327
3330
|
return dataLayer == null ? void 0 : dataLayer.syncData({
|
|
3328
3331
|
name: name,
|
|
3329
3332
|
connectionId: connectionId,
|
|
@@ -3332,7 +3335,7 @@ function generateSyncs(_ref4) {
|
|
|
3332
3335
|
type: entityKey.toUpperCase(),
|
|
3333
3336
|
lastSyncId: event == null ? void 0 : event.id
|
|
3334
3337
|
});
|
|
3335
|
-
case
|
|
3338
|
+
case 15:
|
|
3336
3339
|
case "end":
|
|
3337
3340
|
return _context.stop();
|
|
3338
3341
|
}
|
|
@@ -3347,7 +3350,9 @@ function generateSyncs(_ref4) {
|
|
|
3347
3350
|
};
|
|
3348
3351
|
events[name + "." + entityKey + "/sync"] = {
|
|
3349
3352
|
schema: inputSchema,
|
|
3350
|
-
handler: handler
|
|
3353
|
+
handler: handler,
|
|
3354
|
+
fields: properties,
|
|
3355
|
+
entityType: entityKey
|
|
3351
3356
|
};
|
|
3352
3357
|
}
|
|
3353
3358
|
});
|
|
@@ -4052,9 +4057,9 @@ function _runActionsRecursively() {
|
|
|
4052
4057
|
data: data
|
|
4053
4058
|
});
|
|
4054
4059
|
executorResult = {};
|
|
4055
|
-
_ctx = mastraConnectionId ? {
|
|
4060
|
+
_ctx = mastraConnectionId ? _extends({}, ctx, {
|
|
4056
4061
|
connectionId: mastraConnectionId
|
|
4057
|
-
} : ctx;
|
|
4062
|
+
}) : ctx;
|
|
4058
4063
|
_context2.prev = 46;
|
|
4059
4064
|
_context2.next = 49;
|
|
4060
4065
|
return actionExecutor({
|
|
@@ -4221,253 +4226,1967 @@ function _blueprintRunner() {
|
|
|
4221
4226
|
return _blueprintRunner.apply(this, arguments);
|
|
4222
4227
|
}
|
|
4223
4228
|
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
systemApis = _this.getSystemApis();
|
|
4247
|
-
systemEvents = _this.getSystemEvents();
|
|
4248
|
-
availableIntegrations = (_this$availableIntegr = _this.availableIntegrations()) == null ? void 0 : _this$availableIntegr.map(function (_ref4) {
|
|
4249
|
-
var integration = _ref4.integration;
|
|
4250
|
-
return integration;
|
|
4251
|
-
});
|
|
4252
|
-
availableIntegrationApis = availableIntegrations.reduce(function (acc, _ref5) {
|
|
4253
|
-
var name = _ref5.name;
|
|
4254
|
-
var apis = _this.getApisByIntegration(name);
|
|
4255
|
-
return _extends({}, acc, apis);
|
|
4256
|
-
}, {});
|
|
4257
|
-
availableIntegrationEvents = availableIntegrations.reduce(function (acc, _ref6) {
|
|
4258
|
-
var name = _ref6.name;
|
|
4259
|
-
var events = _this.getEventsByIntegration(name);
|
|
4260
|
-
return _extends({}, acc, events);
|
|
4261
|
-
}, {});
|
|
4262
|
-
frameworkApis = _extends({}, systemApis, availableIntegrationApis);
|
|
4263
|
-
frameworkEvents = _extends({}, systemEvents, availableIntegrationEvents);
|
|
4264
|
-
_context.next = 10;
|
|
4265
|
-
return blueprintRunner({
|
|
4266
|
-
dataCtx: dataCtx,
|
|
4267
|
-
blueprint: blueprint,
|
|
4268
|
-
frameworkApis: frameworkApis,
|
|
4269
|
-
frameworkEvents: frameworkEvents,
|
|
4270
|
-
ctx: ctx
|
|
4271
|
-
});
|
|
4272
|
-
case 10:
|
|
4273
|
-
case "end":
|
|
4274
|
-
return _context.stop();
|
|
4275
|
-
}
|
|
4276
|
-
}, _callee);
|
|
4277
|
-
}));
|
|
4278
|
-
return function (_x) {
|
|
4279
|
-
return _ref3.apply(this, arguments);
|
|
4280
|
-
};
|
|
4281
|
-
}();
|
|
4282
|
-
this.dataLayer = dataLayer;
|
|
4283
|
-
this.config = config;
|
|
4229
|
+
function getAgentDir(_ref) {
|
|
4230
|
+
var agentDir = _ref.agentDir;
|
|
4231
|
+
var ARK_APP_DIR = process.env.ARK_APP_DIR || process.cwd();
|
|
4232
|
+
return path.join(ARK_APP_DIR, agentDir);
|
|
4233
|
+
}
|
|
4234
|
+
function listAgentsJson(_ref2) {
|
|
4235
|
+
var agentDir = _ref2.agentDir;
|
|
4236
|
+
var agentDirPath = getAgentDir({
|
|
4237
|
+
agentDir: agentDir
|
|
4238
|
+
});
|
|
4239
|
+
var agents = readdirSync(agentDirPath);
|
|
4240
|
+
return agents;
|
|
4241
|
+
}
|
|
4242
|
+
function getAgentFile(agentFilePath) {
|
|
4243
|
+
try {
|
|
4244
|
+
var fileP = agentFilePath;
|
|
4245
|
+
var fileB = readFileSync(fileP, 'utf8');
|
|
4246
|
+
var json = JSON.parse(fileB);
|
|
4247
|
+
return json;
|
|
4248
|
+
} catch (e) {
|
|
4249
|
+
console.error('No agent blueprint found:', agentFilePath);
|
|
4250
|
+
return;
|
|
4284
4251
|
}
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
return _extends({}, api, {
|
|
4306
|
-
integrationName: config.name
|
|
4307
|
-
});
|
|
4308
|
-
})
|
|
4309
|
-
});
|
|
4310
|
-
// Register System events
|
|
4311
|
-
framework.__registerEvents({
|
|
4312
|
-
events: config.workflows.systemEvents
|
|
4313
|
-
});
|
|
4314
|
-
return framework;
|
|
4315
|
-
};
|
|
4316
|
-
var _proto = Framework.prototype;
|
|
4317
|
-
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
4318
|
-
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
|
|
4319
|
-
var _this2 = this;
|
|
4320
|
-
var context, ints, connectionChecks;
|
|
4321
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4322
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
4252
|
+
}
|
|
4253
|
+
function getAgentBlueprint(_ref3) {
|
|
4254
|
+
var agentId = _ref3.agentId,
|
|
4255
|
+
agentDir = _ref3.agentDir;
|
|
4256
|
+
var agentDirPath = getAgentDir({
|
|
4257
|
+
agentDir: agentDir
|
|
4258
|
+
});
|
|
4259
|
+
var agentBlueprintPath = path.join(agentDirPath, agentId + ".json");
|
|
4260
|
+
return getAgentFile(agentBlueprintPath);
|
|
4261
|
+
}
|
|
4262
|
+
|
|
4263
|
+
var VectorLayer = /*#__PURE__*/function () {
|
|
4264
|
+
function VectorLayer() {
|
|
4265
|
+
this.supportedProviders = ['PINECONE'];
|
|
4266
|
+
}
|
|
4267
|
+
var _proto = VectorLayer.prototype;
|
|
4268
|
+
_proto.getPineconeIndexes = /*#__PURE__*/function () {
|
|
4269
|
+
var _getPineconeIndexes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
4270
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4271
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4323
4272
|
case 0:
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
_context3.next = 4;
|
|
4327
|
-
return Promise.all(ints.map(/*#__PURE__*/function () {
|
|
4328
|
-
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
|
|
4329
|
-
var integration, connection;
|
|
4330
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4331
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
4332
|
-
case 0:
|
|
4333
|
-
integration = _ref8.integration;
|
|
4334
|
-
_context2.next = 3;
|
|
4335
|
-
return _this2.dataLayer.getConnection({
|
|
4336
|
-
connectionId: context.connectionId,
|
|
4337
|
-
name: integration.name
|
|
4338
|
-
});
|
|
4339
|
-
case 3:
|
|
4340
|
-
connection = _context2.sent;
|
|
4341
|
-
return _context2.abrupt("return", {
|
|
4342
|
-
integration: integration,
|
|
4343
|
-
connected: !!connection
|
|
4344
|
-
});
|
|
4345
|
-
case 5:
|
|
4346
|
-
case "end":
|
|
4347
|
-
return _context2.stop();
|
|
4348
|
-
}
|
|
4349
|
-
}, _callee2);
|
|
4350
|
-
}));
|
|
4351
|
-
return function (_x3) {
|
|
4352
|
-
return _ref9.apply(this, arguments);
|
|
4353
|
-
};
|
|
4354
|
-
}()));
|
|
4355
|
-
case 4:
|
|
4356
|
-
connectionChecks = _context3.sent;
|
|
4357
|
-
return _context3.abrupt("return", connectionChecks.filter(function (_ref10) {
|
|
4358
|
-
var connected = _ref10.connected;
|
|
4359
|
-
return connected;
|
|
4360
|
-
}).map(function (_ref11) {
|
|
4361
|
-
var integration = _ref11.integration;
|
|
4362
|
-
return integration;
|
|
4363
|
-
}));
|
|
4364
|
-
case 6:
|
|
4273
|
+
return _context.abrupt("return", this.Pinecone.listIndexes());
|
|
4274
|
+
case 1:
|
|
4365
4275
|
case "end":
|
|
4366
|
-
return
|
|
4276
|
+
return _context.stop();
|
|
4367
4277
|
}
|
|
4368
|
-
},
|
|
4278
|
+
}, _callee, this);
|
|
4369
4279
|
}));
|
|
4370
|
-
function
|
|
4371
|
-
return
|
|
4280
|
+
function getPineconeIndexes() {
|
|
4281
|
+
return _getPineconeIndexes.apply(this, arguments);
|
|
4372
4282
|
}
|
|
4373
|
-
return
|
|
4283
|
+
return getPineconeIndexes;
|
|
4374
4284
|
}();
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
});
|
|
4381
|
-
var router = this.createRouter();
|
|
4382
|
-
definition.corePresets = {
|
|
4383
|
-
redirectURI: router.makeRedirectURI()
|
|
4384
|
-
};
|
|
4385
|
-
this.integrations.set(name, definition);
|
|
4386
|
-
definition.registerEvents();
|
|
4387
|
-
this.__registerEvents({
|
|
4388
|
-
events: definition.getEvents(),
|
|
4389
|
-
integrationName: name
|
|
4390
|
-
});
|
|
4391
|
-
definition.registerApis();
|
|
4392
|
-
definition._convertApiClientToSystemApis();
|
|
4393
|
-
this.__registerApis({
|
|
4394
|
-
apis: Object.values(definition.getApis()),
|
|
4395
|
-
integrationName: name
|
|
4396
|
-
});
|
|
4397
|
-
(_this$globalEventHand = this.globalEventHandlers).push.apply(_this$globalEventHand, definition.getEventHandlers({
|
|
4398
|
-
makeWebhookUrl: router.makeWebhookUrl
|
|
4399
|
-
}));
|
|
4400
|
-
};
|
|
4401
|
-
_proto.__registerEvents = function __registerEvents(_ref12) {
|
|
4402
|
-
var events = _ref12.events,
|
|
4403
|
-
_ref12$integrationNam = _ref12.integrationName,
|
|
4404
|
-
integrationName = _ref12$integrationNam === void 0 ? this.config.name : _ref12$integrationNam;
|
|
4405
|
-
var integrationEvents = this.globalEvents.get(integrationName) || {};
|
|
4406
|
-
this.globalEvents.set(integrationName, _extends({}, integrationEvents, events));
|
|
4407
|
-
};
|
|
4408
|
-
_proto.__registerApis = function __registerApis(_ref13) {
|
|
4409
|
-
var apis = _ref13.apis,
|
|
4410
|
-
_ref13$integrationNam = _ref13.integrationName,
|
|
4411
|
-
integrationName = _ref13$integrationNam === void 0 ? this.config.name : _ref13$integrationNam;
|
|
4412
|
-
var integrationApis = this.globalApis.get(integrationName) || {};
|
|
4413
|
-
this.globalApis.set(integrationName, _extends({}, integrationApis, apis.reduce(function (acc, api) {
|
|
4414
|
-
var _extends2;
|
|
4415
|
-
return _extends({}, acc, (_extends2 = {}, _extends2[api.type] = api, _extends2));
|
|
4416
|
-
}, {})));
|
|
4417
|
-
};
|
|
4418
|
-
_proto.availableIntegrations = function availableIntegrations() {
|
|
4419
|
-
return Array.from(this.integrations.entries()).map(function (_ref14) {
|
|
4420
|
-
var name = _ref14[0],
|
|
4421
|
-
integration = _ref14[1];
|
|
4422
|
-
return {
|
|
4423
|
-
name: name,
|
|
4424
|
-
integration: integration
|
|
4425
|
-
};
|
|
4426
|
-
});
|
|
4427
|
-
};
|
|
4428
|
-
_proto.getIntegration = function getIntegration(name) {
|
|
4429
|
-
return this.integrations.get(name);
|
|
4430
|
-
};
|
|
4431
|
-
_proto.getGlobalEvents = function getGlobalEvents() {
|
|
4432
|
-
return this.globalEvents;
|
|
4433
|
-
};
|
|
4434
|
-
_proto.getSystemEvents = function getSystemEvents() {
|
|
4435
|
-
var events = this.globalEvents.get(this.config.name);
|
|
4436
|
-
return events || {};
|
|
4437
|
-
};
|
|
4438
|
-
_proto.getEventsByIntegration = function getEventsByIntegration(name) {
|
|
4439
|
-
return this.globalEvents.get(name);
|
|
4440
|
-
};
|
|
4441
|
-
_proto.getGlobalEventHandlers = function getGlobalEventHandlers() {
|
|
4442
|
-
return this.globalEventHandlers;
|
|
4443
|
-
};
|
|
4444
|
-
_proto.getApis = function getApis() {
|
|
4445
|
-
return this.globalApis;
|
|
4446
|
-
};
|
|
4447
|
-
_proto.getSystemApis = function getSystemApis() {
|
|
4448
|
-
return this.globalApis.get(this.config.name);
|
|
4449
|
-
};
|
|
4450
|
-
_proto.getApisByIntegration = function getApisByIntegration(name, includeHidden) {
|
|
4451
|
-
var integrationApis = this.globalApis.get(name);
|
|
4452
|
-
if (includeHidden) {
|
|
4453
|
-
return integrationApis;
|
|
4454
|
-
}
|
|
4455
|
-
return omitBy(integrationApis, function (value) {
|
|
4456
|
-
return value.isHidden;
|
|
4457
|
-
});
|
|
4458
|
-
};
|
|
4459
|
-
_proto.authenticatableIntegrations = function authenticatableIntegrations() {
|
|
4460
|
-
return this.availableIntegrations().filter(function (_ref15) {
|
|
4461
|
-
var integration = _ref15.integration;
|
|
4462
|
-
try {
|
|
4463
|
-
integration.getAuthenticator();
|
|
4464
|
-
return true;
|
|
4465
|
-
} catch (e) {
|
|
4466
|
-
return false;
|
|
4285
|
+
return _createClass(VectorLayer, [{
|
|
4286
|
+
key: "Pinecone",
|
|
4287
|
+
get: function get() {
|
|
4288
|
+
if (!process.env.PINECONE_API_KEY) {
|
|
4289
|
+
throw new Error('Pinecone API key not found');
|
|
4467
4290
|
}
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4291
|
+
return new Pinecone({
|
|
4292
|
+
apiKey: process.env.PINECONE_API_KEY
|
|
4293
|
+
});
|
|
4294
|
+
}
|
|
4295
|
+
}]);
|
|
4296
|
+
}();
|
|
4297
|
+
|
|
4298
|
+
function getVectorProvider(provider) {
|
|
4299
|
+
if (provider === 'PINECONE') {
|
|
4300
|
+
var _VectorLayer = new VectorLayer(),
|
|
4301
|
+
Pinecone = _VectorLayer.Pinecone;
|
|
4302
|
+
return Pinecone;
|
|
4303
|
+
}
|
|
4304
|
+
}
|
|
4305
|
+
var delay$1 = function delay(ms) {
|
|
4306
|
+
return new Promise(function (resolve) {
|
|
4307
|
+
return setTimeout(resolve, ms);
|
|
4308
|
+
});
|
|
4309
|
+
};
|
|
4310
|
+
function executeGenericVectorSync(_x) {
|
|
4311
|
+
return _executeGenericVectorSync.apply(this, arguments);
|
|
4312
|
+
}
|
|
4313
|
+
function _executeGenericVectorSync() {
|
|
4314
|
+
_executeGenericVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
4315
|
+
var _event$user, _event$data, _event$data2;
|
|
4316
|
+
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;
|
|
4317
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
4318
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4319
|
+
case 0:
|
|
4320
|
+
event = _ref.event, mastra = _ref.mastra;
|
|
4321
|
+
connectionId = event == null || (_event$user = event.user) == null ? void 0 : _event$user.connectionId;
|
|
4322
|
+
vector_provider = event == null || (_event$data = event.data) == null ? void 0 : _event$data.vector_provider;
|
|
4323
|
+
entities = event == null || (_event$data2 = event.data) == null ? void 0 : _event$data2.entities;
|
|
4324
|
+
systemName = mastra.config.name;
|
|
4325
|
+
if (vector_provider) {
|
|
4326
|
+
_context4.next = 8;
|
|
4327
|
+
break;
|
|
4328
|
+
}
|
|
4329
|
+
console.error("No vector_provider defined for agent");
|
|
4330
|
+
return _context4.abrupt("return");
|
|
4331
|
+
case 8:
|
|
4332
|
+
vp = getVectorProvider(vector_provider);
|
|
4333
|
+
if (vp) {
|
|
4334
|
+
_context4.next = 12;
|
|
4335
|
+
break;
|
|
4336
|
+
}
|
|
4337
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4338
|
+
return _context4.abrupt("return");
|
|
4339
|
+
case 12:
|
|
4340
|
+
if (process.env.OPENAI_API_KEY) {
|
|
4341
|
+
_context4.next = 15;
|
|
4342
|
+
break;
|
|
4343
|
+
}
|
|
4344
|
+
console.error('NO OPENAI_API_KEY');
|
|
4345
|
+
return _context4.abrupt("return");
|
|
4346
|
+
case 15:
|
|
4347
|
+
_iterator = _createForOfIteratorHelperLoose(entities);
|
|
4348
|
+
case 16:
|
|
4349
|
+
if ((_step = _iterator()).done) {
|
|
4350
|
+
_context4.next = 50;
|
|
4351
|
+
break;
|
|
4352
|
+
}
|
|
4353
|
+
vectorE = _step.value;
|
|
4354
|
+
integrationName = vectorE.integration;
|
|
4355
|
+
_context4.next = 21;
|
|
4356
|
+
return (_mastra$dataLayer = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer.getConnection({
|
|
4357
|
+
connectionId: connectionId,
|
|
4358
|
+
name: integrationName
|
|
4359
|
+
});
|
|
4360
|
+
case 21:
|
|
4361
|
+
_context4.t1 = _yield$mastra$dataLay = _context4.sent;
|
|
4362
|
+
if (!(_context4.t1 == null)) {
|
|
4363
|
+
_context4.next = 26;
|
|
4364
|
+
break;
|
|
4365
|
+
}
|
|
4366
|
+
_context4.t2 = void 0;
|
|
4367
|
+
_context4.next = 27;
|
|
4368
|
+
break;
|
|
4369
|
+
case 26:
|
|
4370
|
+
_context4.t2 = _yield$mastra$dataLay.id;
|
|
4371
|
+
case 27:
|
|
4372
|
+
_context4.t0 = _context4.t2;
|
|
4373
|
+
if (_context4.t0) {
|
|
4374
|
+
_context4.next = 30;
|
|
4375
|
+
break;
|
|
4376
|
+
}
|
|
4377
|
+
_context4.t0 = '';
|
|
4378
|
+
case 30:
|
|
4379
|
+
k_id = _context4.t0;
|
|
4380
|
+
if (!(!k_id && integrationName === systemName)) {
|
|
4381
|
+
_context4.next = 36;
|
|
4382
|
+
break;
|
|
4383
|
+
}
|
|
4384
|
+
_context4.next = 34;
|
|
4385
|
+
return (_mastra$dataLayer2 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer2.createConnection({
|
|
4386
|
+
connection: {
|
|
4387
|
+
connectionId: connectionId,
|
|
4388
|
+
name: integrationName
|
|
4389
|
+
},
|
|
4390
|
+
credential: {
|
|
4391
|
+
type: 'API_KEY',
|
|
4392
|
+
value: connectionId,
|
|
4393
|
+
scope: []
|
|
4394
|
+
}
|
|
4395
|
+
});
|
|
4396
|
+
case 34:
|
|
4397
|
+
connection = _context4.sent;
|
|
4398
|
+
k_id = connection.id;
|
|
4399
|
+
case 36:
|
|
4400
|
+
if (k_id) {
|
|
4401
|
+
_context4.next = 39;
|
|
4402
|
+
break;
|
|
4403
|
+
}
|
|
4404
|
+
console.error('Error bootstrapping shit');
|
|
4405
|
+
return _context4.abrupt("return");
|
|
4406
|
+
case 39:
|
|
4407
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
4408
|
+
var _mastra$dataLayer3, _entityRecords, _records;
|
|
4409
|
+
var entity, entityRecords, records, _mastra$dataLayer4, _entityRecords2, _records2, _yield$mastra$trigger, _event, res, recordsMapped, entityTypeIndex, _recordsMapped$map, vectors;
|
|
4410
|
+
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
4411
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
4412
|
+
case 0:
|
|
4413
|
+
entity = _step2.value;
|
|
4414
|
+
_context3.next = 3;
|
|
4415
|
+
return (_mastra$dataLayer3 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer3.getEntityRecordsByConnectionAndType({
|
|
4416
|
+
k_id: k_id,
|
|
4417
|
+
type: entity.name
|
|
4418
|
+
});
|
|
4419
|
+
case 3:
|
|
4420
|
+
entityRecords = _context3.sent;
|
|
4421
|
+
records = (_entityRecords = entityRecords) == null ? void 0 : _entityRecords.records;
|
|
4422
|
+
if (!(!records || ((_records = records) == null ? void 0 : _records.length) === 0)) {
|
|
4423
|
+
_context3.next = 23;
|
|
4424
|
+
break;
|
|
4425
|
+
}
|
|
4426
|
+
// @TODO: SYNC THEM
|
|
4427
|
+
console.error('NO RECORDS');
|
|
4428
|
+
_context3.next = 9;
|
|
4429
|
+
return mastra.triggerEvent({
|
|
4430
|
+
key: entity.syncEvent,
|
|
4431
|
+
data: {},
|
|
4432
|
+
user: {
|
|
4433
|
+
connectionId: connectionId
|
|
4434
|
+
}
|
|
4435
|
+
});
|
|
4436
|
+
case 9:
|
|
4437
|
+
_yield$mastra$trigger = _context3.sent;
|
|
4438
|
+
_event = _yield$mastra$trigger.event;
|
|
4439
|
+
console.log(_event, '####');
|
|
4440
|
+
_context3.next = 14;
|
|
4441
|
+
return _event.subscribe();
|
|
4442
|
+
case 14:
|
|
4443
|
+
res = _context3.sent;
|
|
4444
|
+
console.log('Subscribe result', res);
|
|
4445
|
+
_context3.next = 18;
|
|
4446
|
+
return (_mastra$dataLayer4 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer4.getEntityRecordsByConnectionAndType({
|
|
4447
|
+
k_id: k_id,
|
|
4448
|
+
type: entity.name
|
|
4449
|
+
});
|
|
4450
|
+
case 18:
|
|
4451
|
+
entityRecords = _context3.sent;
|
|
4452
|
+
records = (_entityRecords2 = entityRecords) == null ? void 0 : _entityRecords2.records;
|
|
4453
|
+
if (!(!records || ((_records2 = records) == null ? void 0 : _records2.length) === 0)) {
|
|
4454
|
+
_context3.next = 23;
|
|
4455
|
+
break;
|
|
4456
|
+
}
|
|
4457
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
4458
|
+
return _context3.abrupt("return", {
|
|
4459
|
+
v: void 0
|
|
4460
|
+
});
|
|
4461
|
+
case 23:
|
|
4462
|
+
recordsMapped = records.map(function (_ref7) {
|
|
4463
|
+
var data = _ref7.data,
|
|
4464
|
+
externalId = _ref7.externalId;
|
|
4465
|
+
return _extends({
|
|
4466
|
+
id: externalId
|
|
4467
|
+
}, pick(data, entity.fields));
|
|
4468
|
+
});
|
|
4469
|
+
console.log(recordsMapped, 'RECORDS');
|
|
4470
|
+
_context3.next = 27;
|
|
4471
|
+
return vp.createIndex({
|
|
4472
|
+
suppressConflicts: true,
|
|
4473
|
+
name: entity.name,
|
|
4474
|
+
dimension: 1536,
|
|
4475
|
+
metric: 'cosine',
|
|
4476
|
+
spec: {
|
|
4477
|
+
serverless: {
|
|
4478
|
+
cloud: 'aws',
|
|
4479
|
+
region: 'us-east-1'
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
});
|
|
4483
|
+
case 27:
|
|
4484
|
+
_context3.next = 29;
|
|
4485
|
+
return delay$1(5000);
|
|
4486
|
+
case 29:
|
|
4487
|
+
entityTypeIndex = vp.index(entity.name);
|
|
4488
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
4489
|
+
_context3.prev = 31;
|
|
4490
|
+
_context3.next = 34;
|
|
4491
|
+
return Promise.all((_recordsMapped$map = recordsMapped.map(/*#__PURE__*/function () {
|
|
4492
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(record) {
|
|
4493
|
+
var _yield$embed, embedding;
|
|
4494
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4495
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
4496
|
+
case 0:
|
|
4497
|
+
_context2.next = 2;
|
|
4498
|
+
return embed({
|
|
4499
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
4500
|
+
value: JSON.stringify(record)
|
|
4501
|
+
});
|
|
4502
|
+
case 2:
|
|
4503
|
+
_yield$embed = _context2.sent;
|
|
4504
|
+
embedding = _yield$embed.embedding;
|
|
4505
|
+
return _context2.abrupt("return", {
|
|
4506
|
+
id: record.id,
|
|
4507
|
+
values: embedding,
|
|
4508
|
+
metadata: record
|
|
4509
|
+
});
|
|
4510
|
+
case 5:
|
|
4511
|
+
case "end":
|
|
4512
|
+
return _context2.stop();
|
|
4513
|
+
}
|
|
4514
|
+
}, _callee2);
|
|
4515
|
+
}));
|
|
4516
|
+
return function (_x5) {
|
|
4517
|
+
return _ref8.apply(this, arguments);
|
|
4518
|
+
};
|
|
4519
|
+
}())) != null ? _recordsMapped$map : []);
|
|
4520
|
+
case 34:
|
|
4521
|
+
vectors = _context3.sent;
|
|
4522
|
+
console.log('UPSERTING', vectors);
|
|
4523
|
+
if (!(vectors.length > 0)) {
|
|
4524
|
+
_context3.next = 39;
|
|
4525
|
+
break;
|
|
4526
|
+
}
|
|
4527
|
+
_context3.next = 39;
|
|
4528
|
+
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4529
|
+
case 39:
|
|
4530
|
+
_context3.next = 44;
|
|
4531
|
+
break;
|
|
4532
|
+
case 41:
|
|
4533
|
+
_context3.prev = 41;
|
|
4534
|
+
_context3.t0 = _context3["catch"](31);
|
|
4535
|
+
console.error(_context3.t0);
|
|
4536
|
+
case 44:
|
|
4537
|
+
return _context3.abrupt("return", {
|
|
4538
|
+
v: void 0
|
|
4539
|
+
});
|
|
4540
|
+
case 45:
|
|
4541
|
+
case "end":
|
|
4542
|
+
return _context3.stop();
|
|
4543
|
+
}
|
|
4544
|
+
}, _loop, null, [[31, 41]]);
|
|
4545
|
+
});
|
|
4546
|
+
_iterator2 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4547
|
+
case 41:
|
|
4548
|
+
if ((_step2 = _iterator2()).done) {
|
|
4549
|
+
_context4.next = 48;
|
|
4550
|
+
break;
|
|
4551
|
+
}
|
|
4552
|
+
return _context4.delegateYield(_loop(), "t3", 43);
|
|
4553
|
+
case 43:
|
|
4554
|
+
_ret = _context4.t3;
|
|
4555
|
+
if (!_ret) {
|
|
4556
|
+
_context4.next = 46;
|
|
4557
|
+
break;
|
|
4558
|
+
}
|
|
4559
|
+
return _context4.abrupt("return", _ret.v);
|
|
4560
|
+
case 46:
|
|
4561
|
+
_context4.next = 41;
|
|
4562
|
+
break;
|
|
4563
|
+
case 48:
|
|
4564
|
+
_context4.next = 16;
|
|
4565
|
+
break;
|
|
4566
|
+
case 50:
|
|
4567
|
+
case "end":
|
|
4568
|
+
return _context4.stop();
|
|
4569
|
+
}
|
|
4570
|
+
}, _callee3);
|
|
4571
|
+
}));
|
|
4572
|
+
return _executeGenericVectorSync.apply(this, arguments);
|
|
4573
|
+
}
|
|
4574
|
+
function executeVectorSync(_x2) {
|
|
4575
|
+
return _executeVectorSync.apply(this, arguments);
|
|
4576
|
+
}
|
|
4577
|
+
function _executeVectorSync() {
|
|
4578
|
+
_executeVectorSync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref2) {
|
|
4579
|
+
var _event$user2, _agent$knowledge_sour3;
|
|
4580
|
+
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;
|
|
4581
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context7) {
|
|
4582
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4583
|
+
case 0:
|
|
4584
|
+
event = _ref2.event, mastra = _ref2.mastra;
|
|
4585
|
+
agentDir = mastra.config.agents.agentDirPath;
|
|
4586
|
+
agent = getAgentBlueprint({
|
|
4587
|
+
agentDir: agentDir,
|
|
4588
|
+
agentId: event.data.agentId
|
|
4589
|
+
});
|
|
4590
|
+
connectionId = event == null || (_event$user2 = event.user) == null ? void 0 : _event$user2.connectionId;
|
|
4591
|
+
systemName = mastra.config.name;
|
|
4592
|
+
if (agent.knowledge_sources.vector_provider) {
|
|
4593
|
+
_context7.next = 8;
|
|
4594
|
+
break;
|
|
4595
|
+
}
|
|
4596
|
+
console.error("No vector_provider defined for agent");
|
|
4597
|
+
return _context7.abrupt("return");
|
|
4598
|
+
case 8:
|
|
4599
|
+
vp = getVectorProvider(agent == null || (_agent$knowledge_sour3 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour3.vector_provider);
|
|
4600
|
+
if (vp) {
|
|
4601
|
+
_context7.next = 12;
|
|
4602
|
+
break;
|
|
4603
|
+
}
|
|
4604
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', agent == null || (_agent$knowledge_sour4 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour4.vector_provider);
|
|
4605
|
+
return _context7.abrupt("return");
|
|
4606
|
+
case 12:
|
|
4607
|
+
if (process.env.OPENAI_API_KEY) {
|
|
4608
|
+
_context7.next = 15;
|
|
4609
|
+
break;
|
|
4610
|
+
}
|
|
4611
|
+
console.error('NO OPENAI_API_KEY');
|
|
4612
|
+
return _context7.abrupt("return");
|
|
4613
|
+
case 15:
|
|
4614
|
+
if (!(!agent || !(agent != null && agent.knowledge_sources))) {
|
|
4615
|
+
_context7.next = 18;
|
|
4616
|
+
break;
|
|
4617
|
+
}
|
|
4618
|
+
console.error('NO AGENT OR KNOWLEDGE SOURCES');
|
|
4619
|
+
return _context7.abrupt("return");
|
|
4620
|
+
case 18:
|
|
4621
|
+
_iterator3 = _createForOfIteratorHelperLoose(agent.knowledge_sources.entities);
|
|
4622
|
+
case 19:
|
|
4623
|
+
if ((_step3 = _iterator3()).done) {
|
|
4624
|
+
_context7.next = 53;
|
|
4625
|
+
break;
|
|
4626
|
+
}
|
|
4627
|
+
vectorE = _step3.value;
|
|
4628
|
+
integrationName = vectorE.integration;
|
|
4629
|
+
_context7.next = 24;
|
|
4630
|
+
return (_mastra$dataLayer5 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer5.getConnection({
|
|
4631
|
+
connectionId: connectionId,
|
|
4632
|
+
name: integrationName
|
|
4633
|
+
});
|
|
4634
|
+
case 24:
|
|
4635
|
+
_context7.t1 = _yield$mastra$dataLay2 = _context7.sent;
|
|
4636
|
+
if (!(_context7.t1 == null)) {
|
|
4637
|
+
_context7.next = 29;
|
|
4638
|
+
break;
|
|
4639
|
+
}
|
|
4640
|
+
_context7.t2 = void 0;
|
|
4641
|
+
_context7.next = 30;
|
|
4642
|
+
break;
|
|
4643
|
+
case 29:
|
|
4644
|
+
_context7.t2 = _yield$mastra$dataLay2.id;
|
|
4645
|
+
case 30:
|
|
4646
|
+
_context7.t0 = _context7.t2;
|
|
4647
|
+
if (_context7.t0) {
|
|
4648
|
+
_context7.next = 33;
|
|
4649
|
+
break;
|
|
4650
|
+
}
|
|
4651
|
+
_context7.t0 = '';
|
|
4652
|
+
case 33:
|
|
4653
|
+
k_id = _context7.t0;
|
|
4654
|
+
if (!(!k_id && integrationName === systemName)) {
|
|
4655
|
+
_context7.next = 39;
|
|
4656
|
+
break;
|
|
4657
|
+
}
|
|
4658
|
+
_context7.next = 37;
|
|
4659
|
+
return (_mastra$dataLayer6 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer6.createConnection({
|
|
4660
|
+
connection: {
|
|
4661
|
+
connectionId: connectionId,
|
|
4662
|
+
name: integrationName
|
|
4663
|
+
},
|
|
4664
|
+
credential: {
|
|
4665
|
+
type: 'API_KEY',
|
|
4666
|
+
value: connectionId,
|
|
4667
|
+
scope: []
|
|
4668
|
+
}
|
|
4669
|
+
});
|
|
4670
|
+
case 37:
|
|
4671
|
+
connection = _context7.sent;
|
|
4672
|
+
k_id = connection.id;
|
|
4673
|
+
case 39:
|
|
4674
|
+
if (k_id) {
|
|
4675
|
+
_context7.next = 42;
|
|
4676
|
+
break;
|
|
4677
|
+
}
|
|
4678
|
+
console.error('Error bootstrapping shit');
|
|
4679
|
+
return _context7.abrupt("return");
|
|
4680
|
+
case 42:
|
|
4681
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
4682
|
+
var _mastra$dataLayer7, _entityRecords3, _records3;
|
|
4683
|
+
var entity, entityRecords, records, _mastra$dataLayer8, _entityRecords4, _records4, _yield$mastra$trigger2, _event2, res, recordsMapped, entityTypeIndex, _recordsMapped$map2, vectors;
|
|
4684
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context6) {
|
|
4685
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4686
|
+
case 0:
|
|
4687
|
+
entity = _step4.value;
|
|
4688
|
+
_context6.next = 3;
|
|
4689
|
+
return (_mastra$dataLayer7 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer7.getEntityRecordsByConnectionAndType({
|
|
4690
|
+
k_id: k_id,
|
|
4691
|
+
type: entity.name
|
|
4692
|
+
});
|
|
4693
|
+
case 3:
|
|
4694
|
+
entityRecords = _context6.sent;
|
|
4695
|
+
records = (_entityRecords3 = entityRecords) == null ? void 0 : _entityRecords3.records;
|
|
4696
|
+
if (!(!records || ((_records3 = records) == null ? void 0 : _records3.length) === 0)) {
|
|
4697
|
+
_context6.next = 23;
|
|
4698
|
+
break;
|
|
4699
|
+
}
|
|
4700
|
+
// @TODO: SYNC THEM
|
|
4701
|
+
console.error('NO RECORDS');
|
|
4702
|
+
_context6.next = 9;
|
|
4703
|
+
return mastra.triggerEvent({
|
|
4704
|
+
key: entity.syncEvent,
|
|
4705
|
+
data: {},
|
|
4706
|
+
user: {
|
|
4707
|
+
connectionId: connectionId
|
|
4708
|
+
}
|
|
4709
|
+
});
|
|
4710
|
+
case 9:
|
|
4711
|
+
_yield$mastra$trigger2 = _context6.sent;
|
|
4712
|
+
_event2 = _yield$mastra$trigger2.event;
|
|
4713
|
+
console.log(_event2, '####');
|
|
4714
|
+
_context6.next = 14;
|
|
4715
|
+
return _event2.subscribe();
|
|
4716
|
+
case 14:
|
|
4717
|
+
res = _context6.sent;
|
|
4718
|
+
console.log('Subscribe result', res);
|
|
4719
|
+
_context6.next = 18;
|
|
4720
|
+
return (_mastra$dataLayer8 = mastra.dataLayer) == null ? void 0 : _mastra$dataLayer8.getEntityRecordsByConnectionAndType({
|
|
4721
|
+
k_id: k_id,
|
|
4722
|
+
type: entity.name
|
|
4723
|
+
});
|
|
4724
|
+
case 18:
|
|
4725
|
+
entityRecords = _context6.sent;
|
|
4726
|
+
records = (_entityRecords4 = entityRecords) == null ? void 0 : _entityRecords4.records;
|
|
4727
|
+
if (!(!records || ((_records4 = records) == null ? void 0 : _records4.length) === 0)) {
|
|
4728
|
+
_context6.next = 23;
|
|
4729
|
+
break;
|
|
4730
|
+
}
|
|
4731
|
+
console.error('NO RECORDS AFTER SYNC');
|
|
4732
|
+
return _context6.abrupt("return", {
|
|
4733
|
+
v: void 0
|
|
4734
|
+
});
|
|
4735
|
+
case 23:
|
|
4736
|
+
recordsMapped = records.map(function (_ref9) {
|
|
4737
|
+
var data = _ref9.data,
|
|
4738
|
+
externalId = _ref9.externalId;
|
|
4739
|
+
return _extends({
|
|
4740
|
+
id: externalId
|
|
4741
|
+
}, pick(data, entity.fields));
|
|
4742
|
+
});
|
|
4743
|
+
console.log(recordsMapped, 'RECORDS');
|
|
4744
|
+
_context6.next = 27;
|
|
4745
|
+
return vp.createIndex({
|
|
4746
|
+
suppressConflicts: true,
|
|
4747
|
+
name: entity.name,
|
|
4748
|
+
dimension: 1536,
|
|
4749
|
+
metric: 'cosine',
|
|
4750
|
+
spec: {
|
|
4751
|
+
serverless: {
|
|
4752
|
+
cloud: 'aws',
|
|
4753
|
+
region: 'us-east-1'
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
});
|
|
4757
|
+
case 27:
|
|
4758
|
+
entityTypeIndex = vp.index(entity.name);
|
|
4759
|
+
console.log(entityTypeIndex, 'INDEX');
|
|
4760
|
+
_context6.prev = 29;
|
|
4761
|
+
_context6.next = 32;
|
|
4762
|
+
return Promise.all((_recordsMapped$map2 = recordsMapped.map(/*#__PURE__*/function () {
|
|
4763
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(record) {
|
|
4764
|
+
var _yield$embed2, embedding;
|
|
4765
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
4766
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4767
|
+
case 0:
|
|
4768
|
+
_context5.next = 2;
|
|
4769
|
+
return embed({
|
|
4770
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
4771
|
+
value: JSON.stringify(record)
|
|
4772
|
+
});
|
|
4773
|
+
case 2:
|
|
4774
|
+
_yield$embed2 = _context5.sent;
|
|
4775
|
+
embedding = _yield$embed2.embedding;
|
|
4776
|
+
return _context5.abrupt("return", {
|
|
4777
|
+
id: record.id,
|
|
4778
|
+
values: embedding,
|
|
4779
|
+
metadata: record
|
|
4780
|
+
});
|
|
4781
|
+
case 5:
|
|
4782
|
+
case "end":
|
|
4783
|
+
return _context5.stop();
|
|
4784
|
+
}
|
|
4785
|
+
}, _callee4);
|
|
4786
|
+
}));
|
|
4787
|
+
return function (_x6) {
|
|
4788
|
+
return _ref10.apply(this, arguments);
|
|
4789
|
+
};
|
|
4790
|
+
}())) != null ? _recordsMapped$map2 : []);
|
|
4791
|
+
case 32:
|
|
4792
|
+
vectors = _context6.sent;
|
|
4793
|
+
console.log('UPSERTING', vectors);
|
|
4794
|
+
if (!(vectors.length > 0)) {
|
|
4795
|
+
_context6.next = 37;
|
|
4796
|
+
break;
|
|
4797
|
+
}
|
|
4798
|
+
_context6.next = 37;
|
|
4799
|
+
return entityTypeIndex.namespace(entity.name).upsert(vectors);
|
|
4800
|
+
case 37:
|
|
4801
|
+
_context6.next = 42;
|
|
4802
|
+
break;
|
|
4803
|
+
case 39:
|
|
4804
|
+
_context6.prev = 39;
|
|
4805
|
+
_context6.t0 = _context6["catch"](29);
|
|
4806
|
+
console.error(_context6.t0);
|
|
4807
|
+
case 42:
|
|
4808
|
+
return _context6.abrupt("return", {
|
|
4809
|
+
v: void 0
|
|
4810
|
+
});
|
|
4811
|
+
case 43:
|
|
4812
|
+
case "end":
|
|
4813
|
+
return _context6.stop();
|
|
4814
|
+
}
|
|
4815
|
+
}, _loop2, null, [[29, 39]]);
|
|
4816
|
+
});
|
|
4817
|
+
_iterator4 = _createForOfIteratorHelperLoose(vectorE.data);
|
|
4818
|
+
case 44:
|
|
4819
|
+
if ((_step4 = _iterator4()).done) {
|
|
4820
|
+
_context7.next = 51;
|
|
4821
|
+
break;
|
|
4822
|
+
}
|
|
4823
|
+
return _context7.delegateYield(_loop2(), "t3", 46);
|
|
4824
|
+
case 46:
|
|
4825
|
+
_ret2 = _context7.t3;
|
|
4826
|
+
if (!_ret2) {
|
|
4827
|
+
_context7.next = 49;
|
|
4828
|
+
break;
|
|
4829
|
+
}
|
|
4830
|
+
return _context7.abrupt("return", _ret2.v);
|
|
4831
|
+
case 49:
|
|
4832
|
+
_context7.next = 44;
|
|
4833
|
+
break;
|
|
4834
|
+
case 51:
|
|
4835
|
+
_context7.next = 19;
|
|
4836
|
+
break;
|
|
4837
|
+
case 53:
|
|
4838
|
+
case "end":
|
|
4839
|
+
return _context7.stop();
|
|
4840
|
+
}
|
|
4841
|
+
}, _callee5);
|
|
4842
|
+
}));
|
|
4843
|
+
return _executeVectorSync.apply(this, arguments);
|
|
4844
|
+
}
|
|
4845
|
+
function vectorQueryEngine(_x3) {
|
|
4846
|
+
return _vectorQueryEngine.apply(this, arguments);
|
|
4847
|
+
}
|
|
4848
|
+
function _vectorQueryEngine() {
|
|
4849
|
+
_vectorQueryEngine = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
|
|
4850
|
+
var vector_provider, _ref3$topK, topK, indexName, content, entityType, vp, index, _yield$embed3, embedding, queryResponse;
|
|
4851
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
4852
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
4853
|
+
case 0:
|
|
4854
|
+
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;
|
|
4855
|
+
vp = getVectorProvider(vector_provider);
|
|
4856
|
+
if (vp) {
|
|
4857
|
+
_context8.next = 5;
|
|
4858
|
+
break;
|
|
4859
|
+
}
|
|
4860
|
+
console.error('UNSUPPORTED VECTOR PROVIDER', vector_provider);
|
|
4861
|
+
return _context8.abrupt("return");
|
|
4862
|
+
case 5:
|
|
4863
|
+
index = vp.index(indexName);
|
|
4864
|
+
_context8.next = 8;
|
|
4865
|
+
return embed({
|
|
4866
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
4867
|
+
value: content
|
|
4868
|
+
});
|
|
4869
|
+
case 8:
|
|
4870
|
+
_yield$embed3 = _context8.sent;
|
|
4871
|
+
embedding = _yield$embed3.embedding;
|
|
4872
|
+
console.log(embedding, 'EMBEDDING');
|
|
4873
|
+
_context8.next = 13;
|
|
4874
|
+
return index.namespace(entityType).query({
|
|
4875
|
+
vector: embedding,
|
|
4876
|
+
topK: topK,
|
|
4877
|
+
includeMetadata: true
|
|
4878
|
+
});
|
|
4879
|
+
case 13:
|
|
4880
|
+
queryResponse = _context8.sent;
|
|
4881
|
+
return _context8.abrupt("return", queryResponse);
|
|
4882
|
+
case 15:
|
|
4883
|
+
case "end":
|
|
4884
|
+
return _context8.stop();
|
|
4885
|
+
}
|
|
4886
|
+
}, _callee6);
|
|
4887
|
+
}));
|
|
4888
|
+
return _vectorQueryEngine.apply(this, arguments);
|
|
4889
|
+
}
|
|
4890
|
+
function getVectorQueryApis(_ref4) {
|
|
4891
|
+
var mastra = _ref4.mastra;
|
|
4892
|
+
var agentDir = mastra.config.agents.agentDirPath;
|
|
4893
|
+
var agents = listAgentsJson({
|
|
4894
|
+
agentDir: agentDir
|
|
4895
|
+
});
|
|
4896
|
+
var agentData = agents.map(function (agentFile) {
|
|
4897
|
+
var _agent$knowledge_sour;
|
|
4898
|
+
var agentDirPath = getAgentDir({
|
|
4899
|
+
agentDir: agentDir
|
|
4900
|
+
});
|
|
4901
|
+
var agent = getAgentFile(path.join(agentDirPath, agentFile));
|
|
4902
|
+
if (!(agent != null && (_agent$knowledge_sour = agent.knowledge_sources) != null && _agent$knowledge_sour.vector_provider)) {
|
|
4903
|
+
console.error("No vector_provider defined for agent");
|
|
4904
|
+
return;
|
|
4905
|
+
}
|
|
4906
|
+
return agent;
|
|
4907
|
+
}).filter(Boolean);
|
|
4908
|
+
return agentData.flatMap(function (agent) {
|
|
4909
|
+
var entities = agent == null ? void 0 : agent.knowledge_sources.entities;
|
|
4910
|
+
return entities.flatMap(function (_ref5) {
|
|
4911
|
+
var data = _ref5.data,
|
|
4912
|
+
integration = _ref5.integration;
|
|
4913
|
+
return data.map(function (entity) {
|
|
4914
|
+
return {
|
|
4915
|
+
integrationName: integration,
|
|
4916
|
+
type: "get_" + entity.name + "_from_vector_" + entity.index,
|
|
4917
|
+
label: "Provides " + entity.name + " information from Vector " + entity.index + " Store",
|
|
4918
|
+
description: "Provides " + entity.name + " information from Vector " + entity.index + " Store",
|
|
4919
|
+
schema: z.object({
|
|
4920
|
+
content: z.string(),
|
|
4921
|
+
topResult: z.number()
|
|
4922
|
+
}),
|
|
4923
|
+
executor: function () {
|
|
4924
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
|
|
4925
|
+
var _agent$knowledge_sour2;
|
|
4926
|
+
var data, res;
|
|
4927
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4928
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4929
|
+
case 0:
|
|
4930
|
+
data = _ref6.data;
|
|
4931
|
+
_context.next = 3;
|
|
4932
|
+
return vectorQueryEngine({
|
|
4933
|
+
vector_provider: agent == null || (_agent$knowledge_sour2 = agent.knowledge_sources) == null ? void 0 : _agent$knowledge_sour2.vector_provider,
|
|
4934
|
+
indexName: entity.index,
|
|
4935
|
+
content: data.content,
|
|
4936
|
+
topK: data.topResult || 1,
|
|
4937
|
+
entityType: entity.name
|
|
4938
|
+
});
|
|
4939
|
+
case 3:
|
|
4940
|
+
res = _context.sent;
|
|
4941
|
+
console.log(JSON.stringify({
|
|
4942
|
+
res: res
|
|
4943
|
+
}, null, 2));
|
|
4944
|
+
// @TODO: make this a proper response
|
|
4945
|
+
return _context.abrupt("return", res);
|
|
4946
|
+
case 6:
|
|
4947
|
+
case "end":
|
|
4948
|
+
return _context.stop();
|
|
4949
|
+
}
|
|
4950
|
+
}, _callee);
|
|
4951
|
+
}));
|
|
4952
|
+
function executor(_x4) {
|
|
4953
|
+
return _executor.apply(this, arguments);
|
|
4954
|
+
}
|
|
4955
|
+
return executor;
|
|
4956
|
+
}()
|
|
4957
|
+
};
|
|
4958
|
+
});
|
|
4959
|
+
});
|
|
4960
|
+
}).filter(Boolean);
|
|
4961
|
+
}
|
|
4962
|
+
function agentVectorSyncEvent() {
|
|
4963
|
+
return {
|
|
4964
|
+
// @TODO: naming convention
|
|
4965
|
+
id: 'agent-vector-sync',
|
|
4966
|
+
event: 'AGENT_VECTOR_SYNC',
|
|
4967
|
+
executor: executeVectorSync
|
|
4968
|
+
};
|
|
4969
|
+
}
|
|
4970
|
+
function genericVectorySyncEvent() {
|
|
4971
|
+
return {
|
|
4972
|
+
// @TODO: naming convention
|
|
4973
|
+
id: 'vector-sync',
|
|
4974
|
+
event: 'VECTOR_SYNC',
|
|
4975
|
+
executor: executeGenericVectorSync
|
|
4976
|
+
};
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4979
|
+
function getAgentSystemApis(_ref) {
|
|
4980
|
+
var mastra = _ref.mastra;
|
|
4981
|
+
var agentDir = mastra.config.agents.agentDirPath;
|
|
4982
|
+
var agents = listAgentsJson({
|
|
4983
|
+
agentDir: agentDir
|
|
4984
|
+
});
|
|
4985
|
+
// Remove the .json extension from the agent names
|
|
4986
|
+
var agentList = agents.map(function (agent) {
|
|
4987
|
+
return agent.slice(0, -5);
|
|
4988
|
+
});
|
|
4989
|
+
return [{
|
|
4990
|
+
integrationName: 'SYSTEM',
|
|
4991
|
+
type: 'message_agent',
|
|
4992
|
+
label: 'Send Message To Agent',
|
|
4993
|
+
description: 'Sends a message to an Agent',
|
|
4994
|
+
schema: z.object({
|
|
4995
|
+
agentId: z["enum"](agentList),
|
|
4996
|
+
message: z.string()
|
|
4997
|
+
}),
|
|
4998
|
+
outputSchema: z.object({
|
|
4999
|
+
message: z.string()
|
|
5000
|
+
}),
|
|
5001
|
+
executor: function () {
|
|
5002
|
+
var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5003
|
+
var data, executor, result, _run$content, thread, run;
|
|
5004
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5005
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5006
|
+
case 0:
|
|
5007
|
+
data = _ref2.data;
|
|
5008
|
+
_context.next = 3;
|
|
5009
|
+
return mastra.getAgent({
|
|
5010
|
+
agentId: data.agentId,
|
|
5011
|
+
connectionId: data.connectionId
|
|
5012
|
+
});
|
|
5013
|
+
case 3:
|
|
5014
|
+
executor = _context.sent;
|
|
5015
|
+
if (executor) {
|
|
5016
|
+
_context.next = 6;
|
|
5017
|
+
break;
|
|
5018
|
+
}
|
|
5019
|
+
throw new Error('Could not create agent executor');
|
|
5020
|
+
case 6:
|
|
5021
|
+
if (!(typeof executor === 'function')) {
|
|
5022
|
+
_context.next = 13;
|
|
5023
|
+
break;
|
|
5024
|
+
}
|
|
5025
|
+
_context.next = 9;
|
|
5026
|
+
return executor({
|
|
5027
|
+
prompt: data == null ? void 0 : data.message
|
|
5028
|
+
});
|
|
5029
|
+
case 9:
|
|
5030
|
+
result = _context.sent;
|
|
5031
|
+
return _context.abrupt("return", {
|
|
5032
|
+
message: result == null ? void 0 : result.text
|
|
5033
|
+
});
|
|
5034
|
+
case 13:
|
|
5035
|
+
_context.next = 15;
|
|
5036
|
+
return executor.initializeThread([{
|
|
5037
|
+
role: 'user',
|
|
5038
|
+
content: data == null ? void 0 : data.message
|
|
5039
|
+
}]);
|
|
5040
|
+
case 15:
|
|
5041
|
+
thread = _context.sent;
|
|
5042
|
+
_context.next = 18;
|
|
5043
|
+
return executor.watchRun({
|
|
5044
|
+
threadId: thread.id
|
|
5045
|
+
});
|
|
5046
|
+
case 18:
|
|
5047
|
+
run = _context.sent;
|
|
5048
|
+
return _context.abrupt("return", {
|
|
5049
|
+
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
|
|
5050
|
+
});
|
|
5051
|
+
case 20:
|
|
5052
|
+
case "end":
|
|
5053
|
+
return _context.stop();
|
|
5054
|
+
}
|
|
5055
|
+
}, _callee);
|
|
5056
|
+
}));
|
|
5057
|
+
function executor(_x) {
|
|
5058
|
+
return _executor.apply(this, arguments);
|
|
5059
|
+
}
|
|
5060
|
+
return executor;
|
|
5061
|
+
}()
|
|
5062
|
+
}];
|
|
5063
|
+
}
|
|
5064
|
+
|
|
5065
|
+
var loggerPath = /*#__PURE__*/path.join(/*#__PURE__*/process.cwd(), 'mastra-agent-logs');
|
|
5066
|
+
function createFileLogger(_ref) {
|
|
5067
|
+
var destinationPath = _ref.destinationPath;
|
|
5068
|
+
var fullPath = path.join(loggerPath, destinationPath);
|
|
5069
|
+
return function (log) {
|
|
5070
|
+
if (!existsSync(loggerPath)) {
|
|
5071
|
+
mkdirSync(loggerPath, {
|
|
5072
|
+
recursive: true
|
|
5073
|
+
});
|
|
5074
|
+
return writeFileSync(fullPath, JSON.stringify([_extends({}, log, {
|
|
5075
|
+
createdAt: new Date()
|
|
5076
|
+
})], null, 2));
|
|
5077
|
+
}
|
|
5078
|
+
var logs = JSON.parse(readFileSync(fullPath, 'utf-8'));
|
|
5079
|
+
logs.push(_extends({}, log, {
|
|
5080
|
+
createdAt: new Date()
|
|
5081
|
+
}));
|
|
5082
|
+
return writeFileSync(fullPath, JSON.stringify(logs, null, 2));
|
|
5083
|
+
};
|
|
5084
|
+
}
|
|
5085
|
+
|
|
5086
|
+
var client = /*#__PURE__*/new OpenAI({
|
|
5087
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
5088
|
+
});
|
|
5089
|
+
function getAssistantAgent(_x3) {
|
|
5090
|
+
return _getAssistantAgent.apply(this, arguments);
|
|
5091
|
+
}
|
|
5092
|
+
function _getAssistantAgent() {
|
|
5093
|
+
_getAssistantAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref3) {
|
|
5094
|
+
var id, toolMap, logger, agent, handleRunStatus, handleRequiresAction, getRun;
|
|
5095
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
5096
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
5097
|
+
case 0:
|
|
5098
|
+
id = _ref3.id, toolMap = _ref3.toolMap;
|
|
5099
|
+
logger = createFileLogger({
|
|
5100
|
+
destinationPath: id + ".json"
|
|
5101
|
+
});
|
|
5102
|
+
_context11.next = 4;
|
|
5103
|
+
return client.beta.assistants.retrieve(id);
|
|
5104
|
+
case 4:
|
|
5105
|
+
agent = _context11.sent;
|
|
5106
|
+
handleRunStatus = /*#__PURE__*/function () {
|
|
5107
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
5108
|
+
var threadId, run, _messages$data, messages;
|
|
5109
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5110
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5111
|
+
case 0:
|
|
5112
|
+
threadId = _ref4.threadId, run = _ref4.run;
|
|
5113
|
+
if (!(run.status === 'completed')) {
|
|
5114
|
+
_context3.next = 8;
|
|
5115
|
+
break;
|
|
5116
|
+
}
|
|
5117
|
+
_context3.next = 4;
|
|
5118
|
+
return client.beta.threads.messages.list(threadId);
|
|
5119
|
+
case 4:
|
|
5120
|
+
messages = _context3.sent;
|
|
5121
|
+
return _context3.abrupt("return", (_messages$data = messages.data) == null ? void 0 : _messages$data[0]);
|
|
5122
|
+
case 8:
|
|
5123
|
+
if (!(run.status === 'requires_action')) {
|
|
5124
|
+
_context3.next = 14;
|
|
5125
|
+
break;
|
|
5126
|
+
}
|
|
5127
|
+
_context3.next = 11;
|
|
5128
|
+
return handleRequiresAction({
|
|
5129
|
+
run: run,
|
|
5130
|
+
threadId: threadId
|
|
5131
|
+
});
|
|
5132
|
+
case 11:
|
|
5133
|
+
return _context3.abrupt("return", _context3.sent);
|
|
5134
|
+
case 14:
|
|
5135
|
+
console.error('Run did not complete:', run);
|
|
5136
|
+
logger({
|
|
5137
|
+
statusCode: 400,
|
|
5138
|
+
message: JSON.stringify({
|
|
5139
|
+
message: "Run did not complete",
|
|
5140
|
+
event_type: 'run_error',
|
|
5141
|
+
metadata: {
|
|
5142
|
+
run: run
|
|
5143
|
+
}
|
|
5144
|
+
}, null, 2)
|
|
5145
|
+
});
|
|
5146
|
+
case 16:
|
|
5147
|
+
case "end":
|
|
5148
|
+
return _context3.stop();
|
|
5149
|
+
}
|
|
5150
|
+
}, _callee3);
|
|
5151
|
+
}));
|
|
5152
|
+
return function handleRunStatus(_x4) {
|
|
5153
|
+
return _ref5.apply(this, arguments);
|
|
5154
|
+
};
|
|
5155
|
+
}();
|
|
5156
|
+
handleRequiresAction = /*#__PURE__*/function () {
|
|
5157
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
5158
|
+
var threadId, run, toolOutputs;
|
|
5159
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5160
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
5161
|
+
case 0:
|
|
5162
|
+
threadId = _ref6.threadId, run = _ref6.run;
|
|
5163
|
+
if (!(run.required_action && run.required_action.submit_tool_outputs && run.required_action.submit_tool_outputs.tool_calls)) {
|
|
5164
|
+
_context5.next = 23;
|
|
5165
|
+
break;
|
|
5166
|
+
}
|
|
5167
|
+
_context5.t0 = compact;
|
|
5168
|
+
_context5.next = 5;
|
|
5169
|
+
return Promise.all(run.required_action.submit_tool_outputs.tool_calls.map(/*#__PURE__*/function () {
|
|
5170
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tool, index, tools) {
|
|
5171
|
+
var callInfo, toolMetadata, toolFn, args, output;
|
|
5172
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5173
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5174
|
+
case 0:
|
|
5175
|
+
callInfo = index + 1 + " of " + tools.length;
|
|
5176
|
+
console.log('Tool:', tool["function"].name, tool.id, Object.keys(toolMap));
|
|
5177
|
+
toolMetadata = {
|
|
5178
|
+
id: tool.id,
|
|
5179
|
+
fn: tool["function"].name,
|
|
5180
|
+
availableTools: Object.keys(toolMap)
|
|
5181
|
+
};
|
|
5182
|
+
logger({
|
|
5183
|
+
statusCode: 100,
|
|
5184
|
+
message: JSON.stringify({
|
|
5185
|
+
message: "[local] Starting tool call " + callInfo + ": " + tool["function"].name,
|
|
5186
|
+
metadata: {
|
|
5187
|
+
tool: toolMetadata
|
|
5188
|
+
}
|
|
5189
|
+
}, null, 2)
|
|
5190
|
+
});
|
|
5191
|
+
toolFn = toolMap == null ? void 0 : toolMap[tool["function"].name];
|
|
5192
|
+
if (toolFn) {
|
|
5193
|
+
_context4.next = 8;
|
|
5194
|
+
break;
|
|
5195
|
+
}
|
|
5196
|
+
logger({
|
|
5197
|
+
statusCode: 404,
|
|
5198
|
+
message: JSON.stringify({
|
|
5199
|
+
message: "[local] No tool fn found: " + tool["function"].name,
|
|
5200
|
+
metadata: {
|
|
5201
|
+
tool: toolMetadata
|
|
5202
|
+
}
|
|
5203
|
+
}, null, 2)
|
|
5204
|
+
});
|
|
5205
|
+
return _context4.abrupt("return");
|
|
5206
|
+
case 8:
|
|
5207
|
+
console.log('Executing tool:', tool["function"].name, tool.id, tool["function"].arguments);
|
|
5208
|
+
args = {};
|
|
5209
|
+
try {
|
|
5210
|
+
if (tool["function"].arguments) {
|
|
5211
|
+
args = JSON.parse(tool["function"].arguments);
|
|
5212
|
+
logger({
|
|
5213
|
+
statusCode: 100,
|
|
5214
|
+
message: JSON.stringify({
|
|
5215
|
+
message: "[local] Passing args to tool call: " + tool["function"].name,
|
|
5216
|
+
metadata: {
|
|
5217
|
+
args: args,
|
|
5218
|
+
tool: toolMetadata
|
|
5219
|
+
}
|
|
5220
|
+
}, null, 2)
|
|
5221
|
+
});
|
|
5222
|
+
}
|
|
5223
|
+
} catch (e) {
|
|
5224
|
+
console.error(e);
|
|
5225
|
+
}
|
|
5226
|
+
_context4.next = 13;
|
|
5227
|
+
return toolFn(args);
|
|
5228
|
+
case 13:
|
|
5229
|
+
output = _context4.sent;
|
|
5230
|
+
logger({
|
|
5231
|
+
statusCode: 200,
|
|
5232
|
+
message: JSON.stringify({
|
|
5233
|
+
message: "[local] Completed tool call " + callInfo + ": " + tool["function"].name,
|
|
5234
|
+
metadata: {
|
|
5235
|
+
output: output,
|
|
5236
|
+
tool: toolMetadata
|
|
5237
|
+
}
|
|
5238
|
+
}, null, 2)
|
|
5239
|
+
});
|
|
5240
|
+
return _context4.abrupt("return", {
|
|
5241
|
+
tool_call_id: tool.id,
|
|
5242
|
+
output: JSON.stringify(output)
|
|
5243
|
+
});
|
|
5244
|
+
case 16:
|
|
5245
|
+
case "end":
|
|
5246
|
+
return _context4.stop();
|
|
5247
|
+
}
|
|
5248
|
+
}, _callee4);
|
|
5249
|
+
}));
|
|
5250
|
+
return function (_x6, _x7, _x8) {
|
|
5251
|
+
return _ref8.apply(this, arguments);
|
|
5252
|
+
};
|
|
5253
|
+
}()));
|
|
5254
|
+
case 5:
|
|
5255
|
+
_context5.t1 = _context5.sent;
|
|
5256
|
+
toolOutputs = (0, _context5.t0)(_context5.t1);
|
|
5257
|
+
if (toolOutputs) {
|
|
5258
|
+
_context5.next = 11;
|
|
5259
|
+
break;
|
|
5260
|
+
}
|
|
5261
|
+
console.error('No tool outputs to submit.');
|
|
5262
|
+
logger({
|
|
5263
|
+
statusCode: 404,
|
|
5264
|
+
message: JSON.stringify({
|
|
5265
|
+
message: "No tool outputs submitted",
|
|
5266
|
+
metadata: {}
|
|
5267
|
+
}, null, 2)
|
|
5268
|
+
});
|
|
5269
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5270
|
+
threadId: threadId,
|
|
5271
|
+
run: run
|
|
5272
|
+
}));
|
|
5273
|
+
case 11:
|
|
5274
|
+
if (!(toolOutputs && (toolOutputs == null ? void 0 : toolOutputs.length) > 0)) {
|
|
5275
|
+
_context5.next = 20;
|
|
5276
|
+
break;
|
|
5277
|
+
}
|
|
5278
|
+
console.log(toolOutputs, '###### YOOOOOO');
|
|
5279
|
+
_context5.next = 15;
|
|
5280
|
+
return client.beta.threads.runs.submitToolOutputsAndPoll(threadId, run.id, {
|
|
5281
|
+
tool_outputs: toolOutputs
|
|
5282
|
+
});
|
|
5283
|
+
case 15:
|
|
5284
|
+
run = _context5.sent;
|
|
5285
|
+
logger({
|
|
5286
|
+
statusCode: 200,
|
|
5287
|
+
message: JSON.stringify({
|
|
5288
|
+
message: "Tool outputs submitted",
|
|
5289
|
+
metadata: {
|
|
5290
|
+
run: run
|
|
5291
|
+
}
|
|
5292
|
+
}, null, 2)
|
|
5293
|
+
});
|
|
5294
|
+
console.log('Tool outputs submitted successfully.');
|
|
5295
|
+
_context5.next = 22;
|
|
5296
|
+
break;
|
|
5297
|
+
case 20:
|
|
5298
|
+
logger({
|
|
5299
|
+
statusCode: 404,
|
|
5300
|
+
message: JSON.stringify({
|
|
5301
|
+
message: "No tool outputs to submit",
|
|
5302
|
+
metadata: {}
|
|
5303
|
+
}, null, 2)
|
|
5304
|
+
});
|
|
5305
|
+
console.log('No tool outputs to submit.');
|
|
5306
|
+
case 22:
|
|
5307
|
+
return _context5.abrupt("return", handleRunStatus({
|
|
5308
|
+
threadId: threadId,
|
|
5309
|
+
run: run
|
|
5310
|
+
}));
|
|
5311
|
+
case 23:
|
|
5312
|
+
case "end":
|
|
5313
|
+
return _context5.stop();
|
|
5314
|
+
}
|
|
5315
|
+
}, _callee5);
|
|
5316
|
+
}));
|
|
5317
|
+
return function handleRequiresAction(_x5) {
|
|
5318
|
+
return _ref7.apply(this, arguments);
|
|
5319
|
+
};
|
|
5320
|
+
}();
|
|
5321
|
+
getRun = /*#__PURE__*/function () {
|
|
5322
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref9) {
|
|
5323
|
+
var threadId, runId;
|
|
5324
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
5325
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
5326
|
+
case 0:
|
|
5327
|
+
threadId = _ref9.threadId, runId = _ref9.runId;
|
|
5328
|
+
_context6.next = 3;
|
|
5329
|
+
return client.beta.threads.runs.retrieve(threadId, runId);
|
|
5330
|
+
case 3:
|
|
5331
|
+
return _context6.abrupt("return", _context6.sent);
|
|
5332
|
+
case 4:
|
|
5333
|
+
case "end":
|
|
5334
|
+
return _context6.stop();
|
|
5335
|
+
}
|
|
5336
|
+
}, _callee6);
|
|
5337
|
+
}));
|
|
5338
|
+
return function getRun(_x9) {
|
|
5339
|
+
return _ref10.apply(this, arguments);
|
|
5340
|
+
};
|
|
5341
|
+
}();
|
|
5342
|
+
return _context11.abrupt("return", {
|
|
5343
|
+
agent: agent,
|
|
5344
|
+
initializeThread: function () {
|
|
5345
|
+
var _initializeThread = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(messages) {
|
|
5346
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
5347
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
5348
|
+
case 0:
|
|
5349
|
+
if (messages === void 0) {
|
|
5350
|
+
messages = [];
|
|
5351
|
+
}
|
|
5352
|
+
_context7.next = 3;
|
|
5353
|
+
return client.beta.threads.create({
|
|
5354
|
+
messages: messages
|
|
5355
|
+
});
|
|
5356
|
+
case 3:
|
|
5357
|
+
return _context7.abrupt("return", _context7.sent);
|
|
5358
|
+
case 4:
|
|
5359
|
+
case "end":
|
|
5360
|
+
return _context7.stop();
|
|
5361
|
+
}
|
|
5362
|
+
}, _callee7);
|
|
5363
|
+
}));
|
|
5364
|
+
function initializeThread(_x10) {
|
|
5365
|
+
return _initializeThread.apply(this, arguments);
|
|
5366
|
+
}
|
|
5367
|
+
return initializeThread;
|
|
5368
|
+
}(),
|
|
5369
|
+
listMessages: function () {
|
|
5370
|
+
var _listMessages = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref11) {
|
|
5371
|
+
var threadId;
|
|
5372
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5373
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
5374
|
+
case 0:
|
|
5375
|
+
threadId = _ref11.threadId;
|
|
5376
|
+
_context8.next = 3;
|
|
5377
|
+
return client.beta.threads.messages.list(threadId);
|
|
5378
|
+
case 3:
|
|
5379
|
+
return _context8.abrupt("return", _context8.sent);
|
|
5380
|
+
case 4:
|
|
5381
|
+
case "end":
|
|
5382
|
+
return _context8.stop();
|
|
5383
|
+
}
|
|
5384
|
+
}, _callee8);
|
|
5385
|
+
}));
|
|
5386
|
+
function listMessages(_x11) {
|
|
5387
|
+
return _listMessages.apply(this, arguments);
|
|
5388
|
+
}
|
|
5389
|
+
return listMessages;
|
|
5390
|
+
}(),
|
|
5391
|
+
getRun: getRun,
|
|
5392
|
+
handleRunStatus: handleRunStatus,
|
|
5393
|
+
handleRequiresAction: handleRequiresAction,
|
|
5394
|
+
createUserMessage: function () {
|
|
5395
|
+
var _createUserMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref12) {
|
|
5396
|
+
var threadId, content;
|
|
5397
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
5398
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
5399
|
+
case 0:
|
|
5400
|
+
threadId = _ref12.threadId, content = _ref12.content;
|
|
5401
|
+
_context9.next = 3;
|
|
5402
|
+
return client.beta.threads.messages.create(threadId, {
|
|
5403
|
+
role: 'user',
|
|
5404
|
+
content: content
|
|
5405
|
+
});
|
|
5406
|
+
case 3:
|
|
5407
|
+
return _context9.abrupt("return", _context9.sent);
|
|
5408
|
+
case 4:
|
|
5409
|
+
case "end":
|
|
5410
|
+
return _context9.stop();
|
|
5411
|
+
}
|
|
5412
|
+
}, _callee9);
|
|
5413
|
+
}));
|
|
5414
|
+
function createUserMessage(_x12) {
|
|
5415
|
+
return _createUserMessage.apply(this, arguments);
|
|
5416
|
+
}
|
|
5417
|
+
return createUserMessage;
|
|
5418
|
+
}(),
|
|
5419
|
+
watchRun: function () {
|
|
5420
|
+
var _watchRun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref13) {
|
|
5421
|
+
var runId, threadId, run;
|
|
5422
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
5423
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
5424
|
+
case 0:
|
|
5425
|
+
runId = _ref13.runId, threadId = _ref13.threadId;
|
|
5426
|
+
if (!runId) {
|
|
5427
|
+
_context10.next = 7;
|
|
5428
|
+
break;
|
|
5429
|
+
}
|
|
5430
|
+
_context10.next = 4;
|
|
5431
|
+
return getRun({
|
|
5432
|
+
threadId: threadId,
|
|
5433
|
+
runId: runId
|
|
5434
|
+
});
|
|
5435
|
+
case 4:
|
|
5436
|
+
run = _context10.sent;
|
|
5437
|
+
_context10.next = 11;
|
|
5438
|
+
break;
|
|
5439
|
+
case 7:
|
|
5440
|
+
_context10.next = 9;
|
|
5441
|
+
return client.beta.threads.runs.createAndPoll(threadId, {
|
|
5442
|
+
assistant_id: id,
|
|
5443
|
+
tool_choice: 'required'
|
|
5444
|
+
});
|
|
5445
|
+
case 9:
|
|
5446
|
+
run = _context10.sent;
|
|
5447
|
+
logger({
|
|
5448
|
+
statusCode: 202,
|
|
5449
|
+
message: JSON.stringify({
|
|
5450
|
+
message: "Creating and polling run, tool choice required",
|
|
5451
|
+
metadata: {
|
|
5452
|
+
run: run,
|
|
5453
|
+
tool_choice: 'required',
|
|
5454
|
+
threadId: threadId,
|
|
5455
|
+
assistant_id: id
|
|
5456
|
+
}
|
|
5457
|
+
}, null, 2)
|
|
5458
|
+
});
|
|
5459
|
+
case 11:
|
|
5460
|
+
return _context10.abrupt("return", handleRunStatus({
|
|
5461
|
+
threadId: threadId,
|
|
5462
|
+
run: run
|
|
5463
|
+
}));
|
|
5464
|
+
case 12:
|
|
5465
|
+
case "end":
|
|
5466
|
+
return _context10.stop();
|
|
5467
|
+
}
|
|
5468
|
+
}, _callee10);
|
|
5469
|
+
}));
|
|
5470
|
+
function watchRun(_x13) {
|
|
5471
|
+
return _watchRun.apply(this, arguments);
|
|
5472
|
+
}
|
|
5473
|
+
return watchRun;
|
|
5474
|
+
}()
|
|
5475
|
+
});
|
|
5476
|
+
case 9:
|
|
5477
|
+
case "end":
|
|
5478
|
+
return _context11.stop();
|
|
5479
|
+
}
|
|
5480
|
+
}, _callee11);
|
|
5481
|
+
}));
|
|
5482
|
+
return _getAssistantAgent.apply(this, arguments);
|
|
5483
|
+
}
|
|
5484
|
+
|
|
5485
|
+
var delay = function delay(ms) {
|
|
5486
|
+
return new Promise(function (resolve) {
|
|
5487
|
+
return setTimeout(resolve, ms);
|
|
5488
|
+
});
|
|
5489
|
+
};
|
|
5490
|
+
function getAgentParams(_ref) {
|
|
5491
|
+
var tools = _ref.tools,
|
|
5492
|
+
resultTool = _ref.resultTool,
|
|
5493
|
+
model = _ref.model;
|
|
5494
|
+
var toolsConverted = Object.entries(tools).reduce(function (memo, _ref2) {
|
|
5495
|
+
var key = _ref2[0],
|
|
5496
|
+
val = _ref2[1];
|
|
5497
|
+
memo[key] = tool(val);
|
|
5498
|
+
return memo;
|
|
5499
|
+
}, {});
|
|
5500
|
+
var answerTool = {};
|
|
5501
|
+
if (resultTool) {
|
|
5502
|
+
answerTool = {
|
|
5503
|
+
answer: tool(resultTool)
|
|
5504
|
+
};
|
|
5505
|
+
}
|
|
5506
|
+
var modelDef;
|
|
5507
|
+
if (model.type === 'openai') {
|
|
5508
|
+
var mName = model.name;
|
|
5509
|
+
if (!mName) {
|
|
5510
|
+
mName = "gpt-4o-2024-08-06";
|
|
5511
|
+
}
|
|
5512
|
+
var openai = createOpenAI({
|
|
5513
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
5514
|
+
});
|
|
5515
|
+
modelDef = openai(mName, {
|
|
5516
|
+
structuredOutputs: true
|
|
5517
|
+
});
|
|
5518
|
+
} else if (model.type === 'anthropic') {
|
|
5519
|
+
var _mName = model.name;
|
|
5520
|
+
if (!_mName) {
|
|
5521
|
+
_mName = "claude-3-5-sonnet-20240620";
|
|
5522
|
+
}
|
|
5523
|
+
var anthropic = createAnthropic({
|
|
5524
|
+
apiKey: process.env.ANTHROPIC_API_KEY
|
|
5525
|
+
});
|
|
5526
|
+
modelDef = anthropic(_mName);
|
|
5527
|
+
} else if (model.type === 'groq') {
|
|
5528
|
+
var _process$env$GROQ_API;
|
|
5529
|
+
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);
|
|
5530
|
+
} else if (model.type === 'perplexity') {
|
|
5531
|
+
var _process$env$PERPLEXI;
|
|
5532
|
+
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);
|
|
5533
|
+
} else if (model.type === 'fireworks') {
|
|
5534
|
+
var _process$env$FIREWORK;
|
|
5535
|
+
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);
|
|
5536
|
+
}
|
|
5537
|
+
return {
|
|
5538
|
+
toolsConverted: toolsConverted,
|
|
5539
|
+
modelDef: modelDef,
|
|
5540
|
+
answerTool: answerTool,
|
|
5541
|
+
toolChoice: (model == null ? void 0 : model.toolChoice) || 'required'
|
|
5542
|
+
};
|
|
5543
|
+
}
|
|
5544
|
+
function createStreamAgent(_ref3) {
|
|
5545
|
+
var agent_instructions = _ref3.agent_instructions,
|
|
5546
|
+
_ref3$maxSteps = _ref3.maxSteps,
|
|
5547
|
+
maxSteps = _ref3$maxSteps === void 0 ? 5 : _ref3$maxSteps,
|
|
5548
|
+
tools = _ref3.tools,
|
|
5549
|
+
resultTool = _ref3.resultTool,
|
|
5550
|
+
_ref3$context = _ref3.context,
|
|
5551
|
+
context = _ref3$context === void 0 ? [] : _ref3$context,
|
|
5552
|
+
model = _ref3.model;
|
|
5553
|
+
var params = getAgentParams({
|
|
5554
|
+
tools: tools,
|
|
5555
|
+
resultTool: resultTool,
|
|
5556
|
+
model: model
|
|
5557
|
+
});
|
|
5558
|
+
return /*#__PURE__*/function () {
|
|
5559
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
|
|
5560
|
+
var prompt, argsForExecute;
|
|
5561
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5562
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5563
|
+
case 0:
|
|
5564
|
+
prompt = _ref4.prompt;
|
|
5565
|
+
argsForExecute = {
|
|
5566
|
+
model: params.modelDef,
|
|
5567
|
+
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
5568
|
+
toolChoice: (params == null ? void 0 : params.toolChoice) || 'required',
|
|
5569
|
+
maxSteps: maxSteps,
|
|
5570
|
+
// system: systemPrompt,
|
|
5571
|
+
onStepFinish: function () {
|
|
5572
|
+
var _onStepFinish = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
5573
|
+
var _props$response, _props$response2;
|
|
5574
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5575
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5576
|
+
case 0:
|
|
5577
|
+
console.log(JSON.stringify(props, null, 2));
|
|
5578
|
+
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)) {
|
|
5579
|
+
_context.next = 5;
|
|
5580
|
+
break;
|
|
5581
|
+
}
|
|
5582
|
+
console.log('Rate limit reached, waiting 10 seconds');
|
|
5583
|
+
_context.next = 5;
|
|
5584
|
+
return delay(10 * 1000);
|
|
5585
|
+
case 5:
|
|
5586
|
+
case "end":
|
|
5587
|
+
return _context.stop();
|
|
5588
|
+
}
|
|
5589
|
+
}, _callee);
|
|
5590
|
+
}));
|
|
5591
|
+
function onStepFinish(_x2) {
|
|
5592
|
+
return _onStepFinish.apply(this, arguments);
|
|
5593
|
+
}
|
|
5594
|
+
return onStepFinish;
|
|
5595
|
+
}()
|
|
5596
|
+
};
|
|
5597
|
+
_context2.next = 4;
|
|
5598
|
+
return streamText(_extends({
|
|
5599
|
+
messages: [].concat(context, [{
|
|
5600
|
+
role: 'user',
|
|
5601
|
+
content: prompt
|
|
5602
|
+
}, {
|
|
5603
|
+
role: 'system',
|
|
5604
|
+
content: agent_instructions
|
|
5605
|
+
}])
|
|
5606
|
+
}, argsForExecute));
|
|
5607
|
+
case 4:
|
|
5608
|
+
return _context2.abrupt("return", _context2.sent);
|
|
5609
|
+
case 5:
|
|
5610
|
+
case "end":
|
|
5611
|
+
return _context2.stop();
|
|
5612
|
+
}
|
|
5613
|
+
}, _callee2);
|
|
5614
|
+
}));
|
|
5615
|
+
return function (_x) {
|
|
5616
|
+
return _ref5.apply(this, arguments);
|
|
5617
|
+
};
|
|
5618
|
+
}();
|
|
5619
|
+
}
|
|
5620
|
+
function createAgent(_ref6) {
|
|
5621
|
+
var agent_instructions = _ref6.agent_instructions,
|
|
5622
|
+
_ref6$maxSteps = _ref6.maxSteps,
|
|
5623
|
+
maxSteps = _ref6$maxSteps === void 0 ? 5 : _ref6$maxSteps,
|
|
5624
|
+
tools = _ref6.tools,
|
|
5625
|
+
resultTool = _ref6.resultTool,
|
|
5626
|
+
_ref6$context = _ref6.context,
|
|
5627
|
+
context = _ref6$context === void 0 ? [] : _ref6$context,
|
|
5628
|
+
model = _ref6.model;
|
|
5629
|
+
var params = getAgentParams({
|
|
5630
|
+
tools: tools,
|
|
5631
|
+
resultTool: resultTool,
|
|
5632
|
+
model: model
|
|
5633
|
+
});
|
|
5634
|
+
return /*#__PURE__*/function () {
|
|
5635
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref7) {
|
|
5636
|
+
var prompt, argsForExecute;
|
|
5637
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5638
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
5639
|
+
case 0:
|
|
5640
|
+
prompt = _ref7.prompt;
|
|
5641
|
+
argsForExecute = {
|
|
5642
|
+
model: params.modelDef,
|
|
5643
|
+
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
5644
|
+
toolChoice: (params == null ? void 0 : params.toolChoice) || 'required',
|
|
5645
|
+
maxSteps: maxSteps,
|
|
5646
|
+
// system: systemPrompt,
|
|
5647
|
+
onStepFinish: function () {
|
|
5648
|
+
var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(props) {
|
|
5649
|
+
var _props$response3, _props$response4;
|
|
5650
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5651
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5652
|
+
case 0:
|
|
5653
|
+
console.log(JSON.stringify(props, null, 2));
|
|
5654
|
+
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)) {
|
|
5655
|
+
_context3.next = 5;
|
|
5656
|
+
break;
|
|
5657
|
+
}
|
|
5658
|
+
console.log('Rate limit reached, waiting 10 seconds');
|
|
5659
|
+
_context3.next = 5;
|
|
5660
|
+
return delay(10 * 1000);
|
|
5661
|
+
case 5:
|
|
5662
|
+
case "end":
|
|
5663
|
+
return _context3.stop();
|
|
5664
|
+
}
|
|
5665
|
+
}, _callee3);
|
|
5666
|
+
}));
|
|
5667
|
+
function onStepFinish(_x4) {
|
|
5668
|
+
return _onStepFinish2.apply(this, arguments);
|
|
5669
|
+
}
|
|
5670
|
+
return onStepFinish;
|
|
5671
|
+
}()
|
|
5672
|
+
};
|
|
5673
|
+
_context4.next = 4;
|
|
5674
|
+
return generateText(_extends({
|
|
5675
|
+
messages: [].concat(context, [{
|
|
5676
|
+
role: 'user',
|
|
5677
|
+
content: prompt
|
|
5678
|
+
}, {
|
|
5679
|
+
role: 'system',
|
|
5680
|
+
content: agent_instructions
|
|
5681
|
+
}])
|
|
5682
|
+
}, argsForExecute));
|
|
5683
|
+
case 4:
|
|
5684
|
+
return _context4.abrupt("return", _context4.sent);
|
|
5685
|
+
case 5:
|
|
5686
|
+
case "end":
|
|
5687
|
+
return _context4.stop();
|
|
5688
|
+
}
|
|
5689
|
+
}, _callee4);
|
|
5690
|
+
}));
|
|
5691
|
+
return function (_x3) {
|
|
5692
|
+
return _ref8.apply(this, arguments);
|
|
5693
|
+
};
|
|
5694
|
+
}();
|
|
5695
|
+
}
|
|
5696
|
+
function createOpenAICompatibleModel(baseURL, apiKey, defaultModelName, modelName) {
|
|
5697
|
+
var client = createOpenAI({
|
|
5698
|
+
baseURL: baseURL,
|
|
5699
|
+
apiKey: apiKey
|
|
5700
|
+
});
|
|
5701
|
+
return client(modelName || defaultModelName);
|
|
5702
|
+
}
|
|
5703
|
+
|
|
5704
|
+
function getAgent(_x) {
|
|
5705
|
+
return _getAgent.apply(this, arguments);
|
|
5706
|
+
}
|
|
5707
|
+
function _getAgent() {
|
|
5708
|
+
_getAgent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
5709
|
+
var connectionId, agent, apis, tools, toolMap, assistant, _agent$model2, keyToModel, _tools, _toolMap, resultTool, schema, _agent$model;
|
|
5710
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5711
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
5712
|
+
case 0:
|
|
5713
|
+
connectionId = _ref.connectionId, agent = _ref.agent, apis = _ref.apis;
|
|
5714
|
+
if (!(agent.model.provider === 'OPEN_AI_ASSISTANT')) {
|
|
5715
|
+
_context3.next = 10;
|
|
5716
|
+
break;
|
|
5717
|
+
}
|
|
5718
|
+
tools = Object.keys(agent.tools);
|
|
5719
|
+
toolMap = Object.entries(apis).reduce(function (memo, _ref2) {
|
|
5720
|
+
var k = _ref2[0],
|
|
5721
|
+
def = _ref2[1];
|
|
5722
|
+
if (tools.includes(k)) {
|
|
5723
|
+
memo[k] = /*#__PURE__*/function () {
|
|
5724
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(props) {
|
|
5725
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5726
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5727
|
+
case 0:
|
|
5728
|
+
return _context.abrupt("return", def.executor({
|
|
5729
|
+
data: props,
|
|
5730
|
+
ctx: {
|
|
5731
|
+
connectionId: connectionId
|
|
5732
|
+
}
|
|
5733
|
+
}));
|
|
5734
|
+
case 1:
|
|
5735
|
+
case "end":
|
|
5736
|
+
return _context.stop();
|
|
5737
|
+
}
|
|
5738
|
+
}, _callee);
|
|
5739
|
+
}));
|
|
5740
|
+
return function (_x2) {
|
|
5741
|
+
return _ref3.apply(this, arguments);
|
|
5742
|
+
};
|
|
5743
|
+
}();
|
|
5744
|
+
}
|
|
5745
|
+
return memo;
|
|
5746
|
+
}, {});
|
|
5747
|
+
_context3.next = 6;
|
|
5748
|
+
return getAssistantAgent({
|
|
5749
|
+
id: agent.id,
|
|
5750
|
+
toolMap: toolMap
|
|
5751
|
+
});
|
|
5752
|
+
case 6:
|
|
5753
|
+
assistant = _context3.sent;
|
|
5754
|
+
return _context3.abrupt("return", assistant);
|
|
5755
|
+
case 10:
|
|
5756
|
+
if (!['OPEN_AI_VERCEL', 'ANTHROPIC_VERCEL', 'GROQ_VERCEL', 'PERPLEXITY_VERCEL', 'FIREWORKS_VERCEL'].includes(agent.model.provider)) {
|
|
5757
|
+
_context3.next = 19;
|
|
5758
|
+
break;
|
|
5759
|
+
}
|
|
5760
|
+
keyToModel = {
|
|
5761
|
+
OPEN_AI_VERCEL: 'openai',
|
|
5762
|
+
ANTHROPIC_VERCEL: 'anthropic',
|
|
5763
|
+
GROQ_VERCEL: 'groq',
|
|
5764
|
+
PERPLEXITY_VERCEL: 'perplexity',
|
|
5765
|
+
FIREWORKS_VERCEL: 'fireworks'
|
|
5766
|
+
};
|
|
5767
|
+
_tools = Object.keys(agent.tools);
|
|
5768
|
+
_toolMap = Object.entries(apis).reduce(function (memo, _ref4) {
|
|
5769
|
+
var k = _ref4[0],
|
|
5770
|
+
def = _ref4[1];
|
|
5771
|
+
if (_tools.includes(k)) {
|
|
5772
|
+
memo[k] = {
|
|
5773
|
+
description: def.label,
|
|
5774
|
+
parameters: def.schema,
|
|
5775
|
+
execute: function () {
|
|
5776
|
+
var _execute = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(props) {
|
|
5777
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
5778
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5779
|
+
case 0:
|
|
5780
|
+
return _context2.abrupt("return", def.executor({
|
|
5781
|
+
data: props,
|
|
5782
|
+
ctx: {
|
|
5783
|
+
connectionId: connectionId
|
|
5784
|
+
}
|
|
5785
|
+
}));
|
|
5786
|
+
case 1:
|
|
5787
|
+
case "end":
|
|
5788
|
+
return _context2.stop();
|
|
5789
|
+
}
|
|
5790
|
+
}, _callee2);
|
|
5791
|
+
}));
|
|
5792
|
+
function execute(_x3) {
|
|
5793
|
+
return _execute.apply(this, arguments);
|
|
5794
|
+
}
|
|
5795
|
+
return execute;
|
|
5796
|
+
}()
|
|
5797
|
+
};
|
|
5798
|
+
}
|
|
5799
|
+
return memo;
|
|
5800
|
+
}, {});
|
|
5801
|
+
resultTool = undefined;
|
|
5802
|
+
if (agent.outputs.structured) {
|
|
5803
|
+
schema = Object.entries(agent.outputs.structured.schema).reduce(function (memo, _ref5) {
|
|
5804
|
+
var k = _ref5[0],
|
|
5805
|
+
v = _ref5[1];
|
|
5806
|
+
if (v.type === 'string') {
|
|
5807
|
+
memo[k] = z.string();
|
|
5808
|
+
}
|
|
5809
|
+
if (v.type === 'array') {
|
|
5810
|
+
var _v$items;
|
|
5811
|
+
var itemType = v == null || (_v$items = v.items) == null ? void 0 : _v$items.type;
|
|
5812
|
+
if (itemType === 'string') {
|
|
5813
|
+
memo[k] = z.array(z.string());
|
|
5814
|
+
}
|
|
5815
|
+
}
|
|
5816
|
+
return memo;
|
|
5817
|
+
}, {});
|
|
5818
|
+
resultTool = {
|
|
5819
|
+
description: agent.outputs.structured.description,
|
|
5820
|
+
parameters: z.object(schema)
|
|
5821
|
+
};
|
|
5822
|
+
}
|
|
5823
|
+
if (!(agent.model.generation_type === 'stream')) {
|
|
5824
|
+
_context3.next = 18;
|
|
5825
|
+
break;
|
|
5826
|
+
}
|
|
5827
|
+
return _context3.abrupt("return", createStreamAgent({
|
|
5828
|
+
agent_instructions: agent.agent_instructions,
|
|
5829
|
+
model: {
|
|
5830
|
+
type: keyToModel[agent.model.provider],
|
|
5831
|
+
name: agent.model.name,
|
|
5832
|
+
toolChoice: ((_agent$model = agent.model) == null ? void 0 : _agent$model.toolChoice) || 'required'
|
|
5833
|
+
},
|
|
5834
|
+
tools: _toolMap,
|
|
5835
|
+
resultTool: resultTool
|
|
5836
|
+
}));
|
|
5837
|
+
case 18:
|
|
5838
|
+
return _context3.abrupt("return", createAgent({
|
|
5839
|
+
agent_instructions: agent.agent_instructions,
|
|
5840
|
+
model: {
|
|
5841
|
+
type: keyToModel[agent.model.provider],
|
|
5842
|
+
name: agent.model.name,
|
|
5843
|
+
toolChoice: ((_agent$model2 = agent.model) == null ? void 0 : _agent$model2.toolChoice) || 'required'
|
|
5844
|
+
},
|
|
5845
|
+
tools: _toolMap,
|
|
5846
|
+
resultTool: resultTool
|
|
5847
|
+
}));
|
|
5848
|
+
case 19:
|
|
5849
|
+
case "end":
|
|
5850
|
+
return _context3.stop();
|
|
5851
|
+
}
|
|
5852
|
+
}, _callee3);
|
|
5853
|
+
}));
|
|
5854
|
+
return _getAgent.apply(this, arguments);
|
|
5855
|
+
}
|
|
5856
|
+
|
|
5857
|
+
var Mastra = /*#__PURE__*/function () {
|
|
5858
|
+
function Mastra(_ref) {
|
|
5859
|
+
var _this = this;
|
|
5860
|
+
var dataLayer = _ref.dataLayer,
|
|
5861
|
+
vectorLayer = _ref.vectorLayer,
|
|
5862
|
+
config = _ref.config;
|
|
5863
|
+
//global events grouped by Integration
|
|
5864
|
+
this.globalEvents = new Map();
|
|
5865
|
+
// global apis grouped by Integration
|
|
5866
|
+
this.globalApis = new Map();
|
|
5867
|
+
this.integrations = new Map();
|
|
5868
|
+
this.dataLayer = void 0;
|
|
5869
|
+
this.vectorLayer = void 0;
|
|
5870
|
+
this.agentsConfig = {
|
|
5871
|
+
agentDirPath: '',
|
|
5872
|
+
vectorProvider: []
|
|
5873
|
+
};
|
|
5874
|
+
this.config = void 0;
|
|
5875
|
+
this.runBlueprint = /*#__PURE__*/function () {
|
|
5876
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
5877
|
+
var _this$availableIntegr;
|
|
5878
|
+
var blueprint, _ref2$dataCtx, dataCtx, ctx, systemApis, systemEvents, availableIntegrations, availableIntegrationApis, availableIntegrationEvents, frameworkApis, frameworkEvents;
|
|
5879
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5880
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5881
|
+
case 0:
|
|
5882
|
+
blueprint = _ref2.blueprint, _ref2$dataCtx = _ref2.dataCtx, dataCtx = _ref2$dataCtx === void 0 ? {} : _ref2$dataCtx, ctx = _ref2.ctx;
|
|
5883
|
+
systemApis = _this.getSystemApis();
|
|
5884
|
+
systemEvents = _this.getSystemEvents();
|
|
5885
|
+
availableIntegrations = (_this$availableIntegr = _this.availableIntegrations()) == null ? void 0 : _this$availableIntegr.map(function (_ref4) {
|
|
5886
|
+
var integration = _ref4.integration;
|
|
5887
|
+
return integration;
|
|
5888
|
+
});
|
|
5889
|
+
availableIntegrationApis = availableIntegrations.reduce(function (acc, _ref5) {
|
|
5890
|
+
var name = _ref5.name;
|
|
5891
|
+
var apis = _this.getApisByIntegration(name);
|
|
5892
|
+
return _extends({}, acc, apis);
|
|
5893
|
+
}, {});
|
|
5894
|
+
availableIntegrationEvents = availableIntegrations.reduce(function (acc, _ref6) {
|
|
5895
|
+
var name = _ref6.name;
|
|
5896
|
+
var events = _this.getEventsByIntegration(name);
|
|
5897
|
+
return _extends({}, acc, events);
|
|
5898
|
+
}, {});
|
|
5899
|
+
frameworkApis = _extends({}, systemApis, availableIntegrationApis);
|
|
5900
|
+
frameworkEvents = _extends({}, systemEvents, availableIntegrationEvents);
|
|
5901
|
+
_context.next = 10;
|
|
5902
|
+
return blueprintRunner({
|
|
5903
|
+
dataCtx: dataCtx,
|
|
5904
|
+
blueprint: blueprint,
|
|
5905
|
+
frameworkApis: frameworkApis,
|
|
5906
|
+
frameworkEvents: frameworkEvents,
|
|
5907
|
+
ctx: ctx
|
|
5908
|
+
});
|
|
5909
|
+
case 10:
|
|
5910
|
+
case "end":
|
|
5911
|
+
return _context.stop();
|
|
5912
|
+
}
|
|
5913
|
+
}, _callee);
|
|
5914
|
+
}));
|
|
5915
|
+
return function (_x) {
|
|
5916
|
+
return _ref3.apply(this, arguments);
|
|
5917
|
+
};
|
|
5918
|
+
}();
|
|
5919
|
+
this.dataLayer = dataLayer;
|
|
5920
|
+
this.vectorLayer = vectorLayer;
|
|
5921
|
+
this.config = config;
|
|
5922
|
+
}
|
|
5923
|
+
Mastra.init = function init(config) {
|
|
5924
|
+
var _config$workflows$sys;
|
|
5925
|
+
if (!config.db.uri) {
|
|
5926
|
+
throw new Error('No database config/provider found');
|
|
5927
|
+
}
|
|
5928
|
+
var dataLayer = new DataLayer({
|
|
5929
|
+
url: config.db.uri,
|
|
5930
|
+
provider: config.db.provider
|
|
5931
|
+
});
|
|
5932
|
+
var vectorLayer = new VectorLayer();
|
|
5933
|
+
var framework = new Mastra({
|
|
5934
|
+
config: config,
|
|
5935
|
+
dataLayer: dataLayer,
|
|
5936
|
+
vectorLayer: vectorLayer
|
|
5937
|
+
});
|
|
5938
|
+
// Register integrations
|
|
5939
|
+
config.integrations.forEach(function (integration) {
|
|
5940
|
+
framework.__registerIntgeration(integration);
|
|
5941
|
+
});
|
|
5942
|
+
// Register system apis
|
|
5943
|
+
framework.__registerApis({
|
|
5944
|
+
apis: [].concat(getAgentSystemApis({
|
|
5945
|
+
mastra: framework
|
|
5946
|
+
}), (_config$workflows$sys = config.workflows.systemApis) == null ? void 0 : _config$workflows$sys.map(function (api) {
|
|
5947
|
+
return _extends({}, api, {
|
|
5948
|
+
integrationName: config.name
|
|
5949
|
+
});
|
|
5950
|
+
}), getVectorQueryApis({
|
|
5951
|
+
mastra: framework
|
|
5952
|
+
}))
|
|
5953
|
+
});
|
|
5954
|
+
// Register System events
|
|
5955
|
+
framework.__registerEvents({
|
|
5956
|
+
events: config.workflows.systemEvents
|
|
5957
|
+
});
|
|
5958
|
+
// Register vector sync event
|
|
5959
|
+
framework.__registerEvents({
|
|
5960
|
+
events: {
|
|
5961
|
+
AGENT_VECTOR_SYNC: {
|
|
5962
|
+
label: 'Sync vector data for an agent',
|
|
5963
|
+
description: 'Sync vector data for an agent',
|
|
5964
|
+
schema: z.object({
|
|
5965
|
+
agentId: z.string()
|
|
5966
|
+
}),
|
|
5967
|
+
handler: agentVectorSyncEvent
|
|
5968
|
+
},
|
|
5969
|
+
VECTOR_SYNC: {
|
|
5970
|
+
label: 'Sync vector data',
|
|
5971
|
+
description: 'Sync vector data',
|
|
5972
|
+
schema: z.object({
|
|
5973
|
+
vector_provider: z.string(),
|
|
5974
|
+
entities: z.array(z.object({
|
|
5975
|
+
integration: z.string(),
|
|
5976
|
+
data: z.array(z.object({
|
|
5977
|
+
name: z.string(),
|
|
5978
|
+
fields: z.array(z.string()),
|
|
5979
|
+
syncEvent: z.string(),
|
|
5980
|
+
index: z.string()
|
|
5981
|
+
}))
|
|
5982
|
+
}))
|
|
5983
|
+
}),
|
|
5984
|
+
handler: genericVectorySyncEvent
|
|
5985
|
+
}
|
|
5986
|
+
},
|
|
5987
|
+
integrationName: config.name
|
|
5988
|
+
});
|
|
5989
|
+
// Register agent config
|
|
5990
|
+
framework.agentsConfig = config.agents;
|
|
5991
|
+
return framework;
|
|
5992
|
+
};
|
|
5993
|
+
var _proto = Mastra.prototype;
|
|
5994
|
+
_proto.connectedIntegrations = /*#__PURE__*/function () {
|
|
5995
|
+
var _connectedIntegrations = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
|
|
5996
|
+
var _this2 = this;
|
|
5997
|
+
var context, ints, connectionChecks;
|
|
5998
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
5999
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
6000
|
+
case 0:
|
|
6001
|
+
context = _ref7.context;
|
|
6002
|
+
ints = this.availableIntegrations();
|
|
6003
|
+
_context3.next = 4;
|
|
6004
|
+
return Promise.all(ints.map(/*#__PURE__*/function () {
|
|
6005
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref8) {
|
|
6006
|
+
var integration, connection;
|
|
6007
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
6008
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
6009
|
+
case 0:
|
|
6010
|
+
integration = _ref8.integration;
|
|
6011
|
+
_context2.next = 3;
|
|
6012
|
+
return _this2.dataLayer.getConnection({
|
|
6013
|
+
connectionId: context.connectionId,
|
|
6014
|
+
name: integration.name
|
|
6015
|
+
});
|
|
6016
|
+
case 3:
|
|
6017
|
+
connection = _context2.sent;
|
|
6018
|
+
return _context2.abrupt("return", {
|
|
6019
|
+
integration: integration,
|
|
6020
|
+
connected: !!connection
|
|
6021
|
+
});
|
|
6022
|
+
case 5:
|
|
6023
|
+
case "end":
|
|
6024
|
+
return _context2.stop();
|
|
6025
|
+
}
|
|
6026
|
+
}, _callee2);
|
|
6027
|
+
}));
|
|
6028
|
+
return function (_x3) {
|
|
6029
|
+
return _ref9.apply(this, arguments);
|
|
6030
|
+
};
|
|
6031
|
+
}()));
|
|
6032
|
+
case 4:
|
|
6033
|
+
connectionChecks = _context3.sent;
|
|
6034
|
+
return _context3.abrupt("return", connectionChecks.filter(function (_ref10) {
|
|
6035
|
+
var connected = _ref10.connected;
|
|
6036
|
+
return connected;
|
|
6037
|
+
}).map(function (_ref11) {
|
|
6038
|
+
var integration = _ref11.integration;
|
|
6039
|
+
return integration;
|
|
6040
|
+
}));
|
|
6041
|
+
case 6:
|
|
6042
|
+
case "end":
|
|
6043
|
+
return _context3.stop();
|
|
6044
|
+
}
|
|
6045
|
+
}, _callee3, this);
|
|
6046
|
+
}));
|
|
6047
|
+
function connectedIntegrations(_x2) {
|
|
6048
|
+
return _connectedIntegrations.apply(this, arguments);
|
|
6049
|
+
}
|
|
6050
|
+
return connectedIntegrations;
|
|
6051
|
+
}();
|
|
6052
|
+
_proto.__registerIntgeration = function __registerIntgeration(definition) {
|
|
6053
|
+
var name = definition.name;
|
|
6054
|
+
definition.attachDataLayer({
|
|
6055
|
+
dataLayer: this.dataLayer
|
|
6056
|
+
});
|
|
6057
|
+
var router = this.createRouter();
|
|
6058
|
+
definition.corePresets = {
|
|
6059
|
+
redirectURI: router.makeRedirectURI()
|
|
6060
|
+
};
|
|
6061
|
+
this.integrations.set(name, definition);
|
|
6062
|
+
definition.registerEvents();
|
|
6063
|
+
this.__registerEvents({
|
|
6064
|
+
events: definition.getEvents(),
|
|
6065
|
+
integrationName: name
|
|
6066
|
+
});
|
|
6067
|
+
definition.registerApis();
|
|
6068
|
+
definition._convertApiClientToSystemApis();
|
|
6069
|
+
this.__registerApis({
|
|
6070
|
+
apis: Object.values(definition.getApis()),
|
|
6071
|
+
integrationName: name
|
|
6072
|
+
});
|
|
6073
|
+
};
|
|
6074
|
+
_proto.registerApi = function registerApi(name, api) {
|
|
6075
|
+
var _extends2;
|
|
6076
|
+
var integrationApis = this.globalApis.get(this.config.name) || {};
|
|
6077
|
+
this.globalApis.set(this.config.name, _extends({}, integrationApis, (_extends2 = {}, _extends2[name] = _extends({}, api, {
|
|
6078
|
+
integrationName: this.config.name
|
|
6079
|
+
}), _extends2)));
|
|
6080
|
+
};
|
|
6081
|
+
_proto.registerEvent = function registerEvent(name, event) {
|
|
6082
|
+
var _extends3;
|
|
6083
|
+
var integrationEvents = this.globalEvents.get('SYSTEM') || {};
|
|
6084
|
+
this.globalEvents.set('SYSTEM', _extends({}, integrationEvents, (_extends3 = {}, _extends3[name] = event, _extends3)));
|
|
6085
|
+
};
|
|
6086
|
+
_proto.__registerEvents = function __registerEvents(_ref12) {
|
|
6087
|
+
var events = _ref12.events,
|
|
6088
|
+
_ref12$integrationNam = _ref12.integrationName,
|
|
6089
|
+
integrationName = _ref12$integrationNam === void 0 ? this.config.name : _ref12$integrationNam;
|
|
6090
|
+
var integrationEvents = this.globalEvents.get(integrationName) || {};
|
|
6091
|
+
this.globalEvents.set(integrationName, _extends({}, integrationEvents, events));
|
|
6092
|
+
};
|
|
6093
|
+
_proto.__registerApis = function __registerApis(_ref13) {
|
|
6094
|
+
var apis = _ref13.apis,
|
|
6095
|
+
_ref13$integrationNam = _ref13.integrationName,
|
|
6096
|
+
integrationName = _ref13$integrationNam === void 0 ? this.config.name : _ref13$integrationNam;
|
|
6097
|
+
var integrationApis = this.globalApis.get(integrationName) || {};
|
|
6098
|
+
this.globalApis.set(integrationName, _extends({}, integrationApis, apis.reduce(function (acc, api) {
|
|
6099
|
+
var _extends4;
|
|
6100
|
+
return _extends({}, acc, (_extends4 = {}, _extends4[api.type] = api, _extends4));
|
|
6101
|
+
}, {})));
|
|
6102
|
+
};
|
|
6103
|
+
_proto.availableIntegrations = function availableIntegrations() {
|
|
6104
|
+
return Array.from(this.integrations.entries()).map(function (_ref14) {
|
|
6105
|
+
var name = _ref14[0],
|
|
6106
|
+
integration = _ref14[1];
|
|
6107
|
+
return {
|
|
6108
|
+
name: name,
|
|
6109
|
+
integration: integration
|
|
6110
|
+
};
|
|
6111
|
+
});
|
|
6112
|
+
};
|
|
6113
|
+
_proto.getIntegration = function getIntegration(name) {
|
|
6114
|
+
return this.integrations.get(name);
|
|
6115
|
+
};
|
|
6116
|
+
_proto.getGlobalEvents = function getGlobalEvents() {
|
|
6117
|
+
return this.globalEvents;
|
|
6118
|
+
};
|
|
6119
|
+
_proto.getSystemEvents = function getSystemEvents() {
|
|
6120
|
+
var events = this.globalEvents.get(this.config.name);
|
|
6121
|
+
return events || {};
|
|
6122
|
+
};
|
|
6123
|
+
_proto.getEventsByIntegration = function getEventsByIntegration(name) {
|
|
6124
|
+
return this.globalEvents.get(name);
|
|
6125
|
+
};
|
|
6126
|
+
_proto.getGlobalEventHandlers = function getGlobalEventHandlers() {
|
|
6127
|
+
var _this3 = this;
|
|
6128
|
+
return Array.from(this.globalEvents.entries()).flatMap(function (_ref15) {
|
|
6129
|
+
var integrationName = _ref15[0],
|
|
6130
|
+
events = _ref15[1];
|
|
6131
|
+
var groupedHandlers = Object.keys(events).map(function (eventKey) {
|
|
6132
|
+
var _events$eventKey;
|
|
6133
|
+
var eventHandler = (_events$eventKey = events[eventKey]) == null ? void 0 : _events$eventKey.handler;
|
|
6134
|
+
if (!eventHandler) return null;
|
|
6135
|
+
var isSystemEvent = integrationName === _this3.config.name;
|
|
6136
|
+
var _this3$createRouter = _this3.createRouter(),
|
|
6137
|
+
makeWebhookUrl = _this3$createRouter.makeWebhookUrl;
|
|
6138
|
+
if (isSystemEvent) {
|
|
6139
|
+
return eventHandler({
|
|
6140
|
+
getIntegration: function getIntegration(name) {
|
|
6141
|
+
return _this3.getIntegration(name);
|
|
6142
|
+
},
|
|
6143
|
+
eventKey: eventKey,
|
|
6144
|
+
getVectorProvider: function getVectorProvider(name) {
|
|
6145
|
+
return _this3.agentsConfig.vectorProvider.find(function (provider) {
|
|
6146
|
+
return provider.name === name;
|
|
6147
|
+
});
|
|
6148
|
+
},
|
|
6149
|
+
makeWebhookUrl: makeWebhookUrl
|
|
6150
|
+
});
|
|
6151
|
+
} else {
|
|
6152
|
+
var integration = _this3.getIntegration(integrationName);
|
|
6153
|
+
return eventHandler({
|
|
6154
|
+
integrationInstance: integration,
|
|
6155
|
+
eventKey: eventKey,
|
|
6156
|
+
makeWebhookUrl: makeWebhookUrl
|
|
6157
|
+
});
|
|
6158
|
+
}
|
|
6159
|
+
}).filter(Boolean);
|
|
6160
|
+
return groupedHandlers;
|
|
6161
|
+
});
|
|
6162
|
+
};
|
|
6163
|
+
_proto.getApis = function getApis() {
|
|
6164
|
+
return this.globalApis;
|
|
6165
|
+
};
|
|
6166
|
+
_proto.getSystemApis = function getSystemApis() {
|
|
6167
|
+
return this.globalApis.get(this.config.name);
|
|
6168
|
+
};
|
|
6169
|
+
_proto.getApisByIntegration = function getApisByIntegration(name, includeHidden) {
|
|
6170
|
+
var integrationApis = this.globalApis.get(name);
|
|
6171
|
+
if (includeHidden) {
|
|
6172
|
+
return integrationApis;
|
|
6173
|
+
}
|
|
6174
|
+
return omitBy(integrationApis, function (value) {
|
|
6175
|
+
return value.isHidden;
|
|
6176
|
+
});
|
|
6177
|
+
};
|
|
6178
|
+
_proto.authenticatableIntegrations = function authenticatableIntegrations() {
|
|
6179
|
+
return this.availableIntegrations().filter(function (_ref16) {
|
|
6180
|
+
var integration = _ref16.integration;
|
|
6181
|
+
try {
|
|
6182
|
+
integration.getAuthenticator();
|
|
6183
|
+
return true;
|
|
6184
|
+
} catch (e) {
|
|
6185
|
+
return false;
|
|
6186
|
+
}
|
|
6187
|
+
});
|
|
6188
|
+
};
|
|
6189
|
+
_proto.authenticator = function authenticator(name) {
|
|
4471
6190
|
var _int = this.getIntegration(name);
|
|
4472
6191
|
if (!_int) {
|
|
4473
6192
|
throw new Error("No integration exists for " + name);
|
|
@@ -4475,12 +6194,12 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4475
6194
|
return _int.getAuthenticator();
|
|
4476
6195
|
};
|
|
4477
6196
|
_proto.connectIntegrationByCredential = /*#__PURE__*/function () {
|
|
4478
|
-
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(
|
|
6197
|
+
var _connectIntegrationByCredential = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref17) {
|
|
4479
6198
|
var name, connectionId, credential, authenticator, integration;
|
|
4480
6199
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4481
6200
|
while (1) switch (_context4.prev = _context4.next) {
|
|
4482
6201
|
case 0:
|
|
4483
|
-
name =
|
|
6202
|
+
name = _ref17.name, connectionId = _ref17.connectionId, credential = _ref17.credential;
|
|
4484
6203
|
authenticator = this.authenticator(name);
|
|
4485
6204
|
if (authenticator) {
|
|
4486
6205
|
_context4.next = 4;
|
|
@@ -4516,13 +6235,13 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4516
6235
|
return connectIntegrationByCredential;
|
|
4517
6236
|
}();
|
|
4518
6237
|
_proto.disconnectIntegration = /*#__PURE__*/function () {
|
|
4519
|
-
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(
|
|
6238
|
+
var _disconnectIntegration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref18) {
|
|
4520
6239
|
var _yield$this$dataLayer;
|
|
4521
6240
|
var name, connectionId, integration, k_id, authenticator;
|
|
4522
6241
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4523
6242
|
while (1) switch (_context5.prev = _context5.next) {
|
|
4524
6243
|
case 0:
|
|
4525
|
-
name =
|
|
6244
|
+
name = _ref18.name, connectionId = _ref18.connectionId;
|
|
4526
6245
|
integration = this.getIntegration(name);
|
|
4527
6246
|
_context5.next = 4;
|
|
4528
6247
|
return this.dataLayer.getConnection({
|
|
@@ -4583,14 +6302,14 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4583
6302
|
return disconnectIntegration;
|
|
4584
6303
|
}();
|
|
4585
6304
|
_proto.callApi = /*#__PURE__*/function () {
|
|
4586
|
-
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(
|
|
6305
|
+
var _callApi = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref19) {
|
|
4587
6306
|
var _int2$getApis;
|
|
4588
|
-
var
|
|
6307
|
+
var _ref19$integrationNam, integrationName, api, payload, _this$globalApis$get, _apiExecutor, _int2, apiExecutor;
|
|
4589
6308
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4590
6309
|
while (1) switch (_context6.prev = _context6.next) {
|
|
4591
6310
|
case 0:
|
|
4592
|
-
|
|
4593
|
-
if (!(integrationName === this.config.name)) {
|
|
6311
|
+
_ref19$integrationNam = _ref19.integrationName, integrationName = _ref19$integrationNam === void 0 ? this.config.name : _ref19$integrationNam, api = _ref19.api, payload = _ref19.payload;
|
|
6312
|
+
if (!(integrationName === this.config.name || integrationName === 'SYSTEM')) {
|
|
4594
6313
|
_context6.next = 6;
|
|
4595
6314
|
break;
|
|
4596
6315
|
}
|
|
@@ -4630,19 +6349,19 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4630
6349
|
return callApi;
|
|
4631
6350
|
}();
|
|
4632
6351
|
_proto.subscribeEvent = /*#__PURE__*/function () {
|
|
4633
|
-
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(
|
|
4634
|
-
var
|
|
4635
|
-
var id,
|
|
6352
|
+
var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
|
|
6353
|
+
var _this$config$runner$u, _this$config$runner, _ref21, _this$config$runner$s, _this$config$runner2;
|
|
6354
|
+
var id, _ref20$interval, interval, _ref20$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
|
|
4636
6355
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
4637
6356
|
while (1) switch (_context8.prev = _context8.next) {
|
|
4638
6357
|
case 0:
|
|
4639
|
-
id =
|
|
4640
|
-
inngestApiUrl = process.env.INNGEST_URL;
|
|
4641
|
-
inngestApiToken = (
|
|
6358
|
+
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;
|
|
6359
|
+
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;
|
|
6360
|
+
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';
|
|
4642
6361
|
startTime = Date.now();
|
|
4643
6362
|
_poll = /*#__PURE__*/function () {
|
|
4644
|
-
var
|
|
4645
|
-
var response,
|
|
6363
|
+
var _ref22 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
6364
|
+
var response, obj, data, error, lastRun, elapsedTime;
|
|
4646
6365
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4647
6366
|
while (1) switch (_context7.prev = _context7.next) {
|
|
4648
6367
|
case 0:
|
|
@@ -4657,65 +6376,93 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4657
6376
|
});
|
|
4658
6377
|
case 3:
|
|
4659
6378
|
response = _context7.sent;
|
|
6379
|
+
console.log("Polling for event " + id + "...", response.ok);
|
|
4660
6380
|
if (!response.ok) {
|
|
4661
|
-
_context7.next =
|
|
6381
|
+
_context7.next = 28;
|
|
4662
6382
|
break;
|
|
4663
6383
|
}
|
|
4664
|
-
_context7.next =
|
|
6384
|
+
_context7.next = 8;
|
|
4665
6385
|
return response.json();
|
|
4666
|
-
case
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
6386
|
+
case 8:
|
|
6387
|
+
obj = _context7.sent;
|
|
6388
|
+
console.log({
|
|
6389
|
+
obj: obj
|
|
6390
|
+
});
|
|
6391
|
+
data = obj.data, error = obj.error;
|
|
6392
|
+
console.log("Got data for event " + id + "...", data, error);
|
|
4670
6393
|
if (!error) {
|
|
4671
|
-
_context7.next =
|
|
6394
|
+
_context7.next = 15;
|
|
4672
6395
|
break;
|
|
4673
6396
|
}
|
|
6397
|
+
console.error(error);
|
|
4674
6398
|
return _context7.abrupt("return", null);
|
|
4675
|
-
case
|
|
6399
|
+
case 15:
|
|
6400
|
+
if (!((data == null ? void 0 : data.length) === 0)) {
|
|
6401
|
+
_context7.next = 19;
|
|
6402
|
+
break;
|
|
6403
|
+
}
|
|
6404
|
+
_context7.next = 18;
|
|
6405
|
+
return new Promise(function (resolve) {
|
|
6406
|
+
return setTimeout(resolve, interval);
|
|
6407
|
+
});
|
|
6408
|
+
case 18:
|
|
6409
|
+
return _context7.abrupt("return", _poll());
|
|
6410
|
+
case 19:
|
|
4676
6411
|
lastRun = data == null ? void 0 : data[0];
|
|
6412
|
+
console.log(lastRun);
|
|
4677
6413
|
if (lastRun) {
|
|
4678
|
-
_context7.next =
|
|
6414
|
+
_context7.next = 23;
|
|
4679
6415
|
break;
|
|
4680
6416
|
}
|
|
4681
6417
|
return _context7.abrupt("return", null);
|
|
4682
|
-
case
|
|
6418
|
+
case 23:
|
|
6419
|
+
if (!(lastRun.status === 'Running')) {
|
|
6420
|
+
_context7.next = 27;
|
|
6421
|
+
break;
|
|
6422
|
+
}
|
|
6423
|
+
_context7.next = 26;
|
|
6424
|
+
return new Promise(function (resolve) {
|
|
6425
|
+
return setTimeout(resolve, interval);
|
|
6426
|
+
});
|
|
6427
|
+
case 26:
|
|
6428
|
+
return _context7.abrupt("return", _poll());
|
|
6429
|
+
case 27:
|
|
4683
6430
|
return _context7.abrupt("return", {
|
|
4684
6431
|
status: lastRun.status,
|
|
4685
6432
|
startedAt: lastRun.run_started_at,
|
|
4686
6433
|
endedAt: lastRun.ended_at
|
|
4687
6434
|
});
|
|
4688
|
-
case
|
|
4689
|
-
_context7.next =
|
|
6435
|
+
case 28:
|
|
6436
|
+
_context7.next = 33;
|
|
4690
6437
|
break;
|
|
4691
|
-
case
|
|
4692
|
-
_context7.prev =
|
|
6438
|
+
case 30:
|
|
6439
|
+
_context7.prev = 30;
|
|
4693
6440
|
_context7.t0 = _context7["catch"](0);
|
|
4694
6441
|
console.error("Request failed: " + _context7.t0);
|
|
4695
|
-
case
|
|
6442
|
+
case 33:
|
|
4696
6443
|
// Check if timeout has been reached
|
|
4697
6444
|
elapsedTime = Date.now() - startTime;
|
|
4698
6445
|
if (!(elapsedTime >= timeout)) {
|
|
4699
|
-
_context7.next =
|
|
6446
|
+
_context7.next = 37;
|
|
4700
6447
|
break;
|
|
4701
6448
|
}
|
|
4702
6449
|
console.log('Polling timeout reached.');
|
|
4703
6450
|
return _context7.abrupt("return", null);
|
|
4704
|
-
case
|
|
4705
|
-
_context7.next =
|
|
6451
|
+
case 37:
|
|
6452
|
+
_context7.next = 39;
|
|
4706
6453
|
return new Promise(function (resolve) {
|
|
4707
6454
|
return setTimeout(resolve, interval);
|
|
4708
6455
|
});
|
|
4709
|
-
case
|
|
6456
|
+
case 39:
|
|
4710
6457
|
return _context7.abrupt("return", _poll());
|
|
4711
|
-
case
|
|
6458
|
+
case 40:
|
|
4712
6459
|
case "end":
|
|
4713
6460
|
return _context7.stop();
|
|
4714
6461
|
}
|
|
4715
|
-
}, _callee7, null, [[0,
|
|
6462
|
+
}, _callee7, null, [[0, 30]]);
|
|
4716
6463
|
}));
|
|
4717
6464
|
return function poll() {
|
|
4718
|
-
return
|
|
6465
|
+
return _ref22.apply(this, arguments);
|
|
4719
6466
|
};
|
|
4720
6467
|
}();
|
|
4721
6468
|
return _context8.abrupt("return", _poll());
|
|
@@ -4723,7 +6470,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4723
6470
|
case "end":
|
|
4724
6471
|
return _context8.stop();
|
|
4725
6472
|
}
|
|
4726
|
-
}, _callee8);
|
|
6473
|
+
}, _callee8, this);
|
|
4727
6474
|
}));
|
|
4728
6475
|
function subscribeEvent(_x7) {
|
|
4729
6476
|
return _subscribeEvent.apply(this, arguments);
|
|
@@ -4731,13 +6478,13 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4731
6478
|
return subscribeEvent;
|
|
4732
6479
|
}();
|
|
4733
6480
|
_proto.triggerEvent = /*#__PURE__*/function () {
|
|
4734
|
-
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(
|
|
4735
|
-
var
|
|
4736
|
-
var key, data, user,
|
|
6481
|
+
var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref23) {
|
|
6482
|
+
var _this4 = this;
|
|
6483
|
+
var key, data, user, _ref23$integrationNam, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
|
|
4737
6484
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
4738
6485
|
while (1) switch (_context11.prev = _context11.next) {
|
|
4739
6486
|
case 0:
|
|
4740
|
-
key =
|
|
6487
|
+
key = _ref23.key, data = _ref23.data, user = _ref23.user, _ref23$integrationNam = _ref23.integrationName, integrationName = _ref23$integrationNam === void 0 ? this.config.name : _ref23$integrationNam;
|
|
4741
6488
|
_context11.prev = 1;
|
|
4742
6489
|
returnObj = {
|
|
4743
6490
|
event: {}
|
|
@@ -4757,7 +6504,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4757
6504
|
throw new Error("No event exists for " + key + " in " + integrationName);
|
|
4758
6505
|
case 9:
|
|
4759
6506
|
_context11.next = 11;
|
|
4760
|
-
return client.send({
|
|
6507
|
+
return client$1.send({
|
|
4761
6508
|
name: key,
|
|
4762
6509
|
data: data,
|
|
4763
6510
|
user: user
|
|
@@ -4768,12 +6515,12 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4768
6515
|
subscribe: function () {
|
|
4769
6516
|
var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_temp) {
|
|
4770
6517
|
var _event$ids;
|
|
4771
|
-
var
|
|
6518
|
+
var _ref24, interval, timeout;
|
|
4772
6519
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
4773
6520
|
while (1) switch (_context9.prev = _context9.next) {
|
|
4774
6521
|
case 0:
|
|
4775
|
-
|
|
4776
|
-
return _context9.abrupt("return",
|
|
6522
|
+
_ref24 = _temp === void 0 ? {} : _temp, interval = _ref24.interval, timeout = _ref24.timeout;
|
|
6523
|
+
return _context9.abrupt("return", _this4.subscribeEvent({
|
|
4777
6524
|
id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
|
|
4778
6525
|
interval: interval,
|
|
4779
6526
|
timeout: timeout
|
|
@@ -4791,7 +6538,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4791
6538
|
}()
|
|
4792
6539
|
});
|
|
4793
6540
|
_context11.next = 15;
|
|
4794
|
-
return client.send({
|
|
6541
|
+
return client$1.send({
|
|
4795
6542
|
name: 'workflow/run-automations',
|
|
4796
6543
|
data: {
|
|
4797
6544
|
trigger: key,
|
|
@@ -4805,12 +6552,12 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4805
6552
|
subscribe: function () {
|
|
4806
6553
|
var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp2) {
|
|
4807
6554
|
var _workflowEvent$ids;
|
|
4808
|
-
var
|
|
6555
|
+
var _ref25, interval, timeout;
|
|
4809
6556
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
4810
6557
|
while (1) switch (_context10.prev = _context10.next) {
|
|
4811
6558
|
case 0:
|
|
4812
|
-
|
|
4813
|
-
return _context10.abrupt("return",
|
|
6559
|
+
_ref25 = _temp2 === void 0 ? {} : _temp2, interval = _ref25.interval, timeout = _ref25.timeout;
|
|
6560
|
+
return _context10.abrupt("return", _this4.subscribeEvent({
|
|
4814
6561
|
id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
|
|
4815
6562
|
interval: interval,
|
|
4816
6563
|
timeout: timeout
|
|
@@ -4847,14 +6594,14 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4847
6594
|
_proto.triggerSystemEvent =
|
|
4848
6595
|
/*#__PURE__*/
|
|
4849
6596
|
function () {
|
|
4850
|
-
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(
|
|
6597
|
+
var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref26) {
|
|
4851
6598
|
var key, data, user, event, systemEvent;
|
|
4852
6599
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
4853
6600
|
while (1) switch (_context12.prev = _context12.next) {
|
|
4854
6601
|
case 0:
|
|
4855
|
-
key =
|
|
6602
|
+
key = _ref26.key, data = _ref26.data, user = _ref26.user;
|
|
4856
6603
|
_context12.next = 3;
|
|
4857
|
-
return client.send({
|
|
6604
|
+
return client$1.send({
|
|
4858
6605
|
name: key,
|
|
4859
6606
|
data: data,
|
|
4860
6607
|
user: user
|
|
@@ -4867,7 +6614,7 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4867
6614
|
break;
|
|
4868
6615
|
}
|
|
4869
6616
|
_context12.next = 8;
|
|
4870
|
-
return client.send({
|
|
6617
|
+
return client$1.send({
|
|
4871
6618
|
name: 'workflow/run-automations',
|
|
4872
6619
|
data: {
|
|
4873
6620
|
trigger: key,
|
|
@@ -4890,10 +6637,10 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4890
6637
|
}();
|
|
4891
6638
|
_proto.createRouter = function createRouter() {
|
|
4892
6639
|
var self = this;
|
|
4893
|
-
var makeWebhookUrl = function makeWebhookUrl(
|
|
6640
|
+
var makeWebhookUrl = function makeWebhookUrl(_ref27) {
|
|
4894
6641
|
var _self$config;
|
|
4895
|
-
var event =
|
|
4896
|
-
name =
|
|
6642
|
+
var event = _ref27.event,
|
|
6643
|
+
name = _ref27.name;
|
|
4897
6644
|
return encodeURI("" + (self == null || (_self$config = self.config) == null ? void 0 : _self$config.systemHostURL) + self.routes.webhook + "?name=" + name + "&event=" + event);
|
|
4898
6645
|
};
|
|
4899
6646
|
var makeRedirectURI = function makeRedirectURI() {
|
|
@@ -4923,25 +6670,60 @@ var Framework = /*#__PURE__*/function () {
|
|
|
4923
6670
|
registerRoutes: registerRoutes
|
|
4924
6671
|
};
|
|
4925
6672
|
};
|
|
4926
|
-
|
|
6673
|
+
_proto.getAgent = /*#__PURE__*/function () {
|
|
6674
|
+
var _getAgent2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref28) {
|
|
6675
|
+
var connectionId, agentId, agentBlueprint, arrMap, finalApis;
|
|
6676
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
6677
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
6678
|
+
case 0:
|
|
6679
|
+
connectionId = _ref28.connectionId, agentId = _ref28.agentId;
|
|
6680
|
+
_context13.next = 3;
|
|
6681
|
+
return getAgentBlueprint({
|
|
6682
|
+
agentDir: this.config.agents.agentDirPath,
|
|
6683
|
+
agentId: agentId
|
|
6684
|
+
});
|
|
6685
|
+
case 3:
|
|
6686
|
+
agentBlueprint = _context13.sent;
|
|
6687
|
+
arrMap = Array.from(this.getApis());
|
|
6688
|
+
finalApis = arrMap.reduce(function (acc, _ref29) {
|
|
6689
|
+
var v = _ref29[1];
|
|
6690
|
+
return _extends({}, acc, v);
|
|
6691
|
+
}, {});
|
|
6692
|
+
return _context13.abrupt("return", getAgent({
|
|
6693
|
+
connectionId: connectionId,
|
|
6694
|
+
agent: agentBlueprint,
|
|
6695
|
+
apis: finalApis
|
|
6696
|
+
}));
|
|
6697
|
+
case 7:
|
|
6698
|
+
case "end":
|
|
6699
|
+
return _context13.stop();
|
|
6700
|
+
}
|
|
6701
|
+
}, _callee13, this);
|
|
6702
|
+
}));
|
|
6703
|
+
function getAgent$1(_x12) {
|
|
6704
|
+
return _getAgent2.apply(this, arguments);
|
|
6705
|
+
}
|
|
6706
|
+
return getAgent$1;
|
|
6707
|
+
}();
|
|
6708
|
+
return _createClass(Mastra, [{
|
|
4927
6709
|
key: "routes",
|
|
4928
6710
|
get: function get() {
|
|
4929
|
-
var
|
|
6711
|
+
var _this5 = this;
|
|
4930
6712
|
var registry = {
|
|
4931
6713
|
connect: '/connect',
|
|
4932
6714
|
callback: '/connect/callback',
|
|
4933
6715
|
inngest: '/inngest',
|
|
4934
6716
|
webhook: '/webhook'
|
|
4935
6717
|
};
|
|
4936
|
-
return Object.entries(registry).reduce(function (acc,
|
|
4937
|
-
var
|
|
4938
|
-
var key =
|
|
4939
|
-
value =
|
|
4940
|
-
return _extends({}, acc, (
|
|
6718
|
+
return Object.entries(registry).reduce(function (acc, _ref30) {
|
|
6719
|
+
var _extends5;
|
|
6720
|
+
var key = _ref30[0],
|
|
6721
|
+
value = _ref30[1];
|
|
6722
|
+
return _extends({}, acc, (_extends5 = {}, _extends5[key] = "" + _this5.config.routeRegistrationPath + value, _extends5));
|
|
4941
6723
|
}, {});
|
|
4942
6724
|
}
|
|
4943
6725
|
}]);
|
|
4944
6726
|
}();
|
|
4945
6727
|
|
|
4946
|
-
export { DataLayer, FieldTypePrimitiveMap, FilterOperatorToSQL, FilterOperators,
|
|
6728
|
+
export { DataLayer, FieldTypePrimitiveMap, FilterOperatorToSQL, FilterOperators, Integration, IntegrationAuth, IntegrationCredentialType, IntegrationError, IntegrationErrors, IntegrationFieldTypeEnum, Mastra, RunStatus, SORT_MODE_TO_ABBR, WorkflowStatusEnum, allowedKey, apiKeyConnectionOptions, buildQueryString, callbackParams, connectParams, constructObjFromStringPath, extractSchemaOptions, fieldsWithCommaSeparatedValues, filterQuerySchema, flattenObject, generateSyncs, getEntityKey, getJSONField, getPath, getResponseDataKey, isLiteralObject, isObjectEmpty, mergeWithDefinedOnly, nextHeaders, oauthState, parseQueryParams, recordHasData, registerRoutes, sortQuerySchema, splitAndStripQuotes, transformFilterValueArray, transformFilterValueBoolean, webhookQueryParams };
|
|
4947
6729
|
//# sourceMappingURL=core.esm.js.map
|