@mastra/core 0.1.27-alpha.21 → 0.1.27-alpha.22
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/agent/index.d.ts +44 -9
- package/dist/core.cjs.development.js +985 -233
- 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 +985 -233
- package/dist/core.esm.js.map +1 -1
- package/dist/llm/index.d.ts +30 -16
- package/dist/llm/types.d.ts +16 -16
- package/dist/mastra/index.d.ts +5 -2
- package/dist/memory/index.d.ts +83 -9
- package/dist/sync/types.d.ts +2 -1
- package/dist/tools/types.d.ts +10 -8
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
+
var crypto$1 = require('crypto');
|
|
7
|
+
var zod = require('zod');
|
|
6
8
|
var amazonBedrock = require('@ai-sdk/amazon-bedrock');
|
|
7
9
|
var anthropic = require('@ai-sdk/anthropic');
|
|
8
10
|
var azure = require('@ai-sdk/azure');
|
|
@@ -13,7 +15,6 @@ var openai = require('@ai-sdk/openai');
|
|
|
13
15
|
var xai = require('@ai-sdk/xai');
|
|
14
16
|
var ai = require('ai');
|
|
15
17
|
var anthropicVertexAi = require('anthropic-vertex-ai');
|
|
16
|
-
var zod = require('zod');
|
|
17
18
|
var redis = require('@upstash/redis');
|
|
18
19
|
var fs = require('fs');
|
|
19
20
|
var path = require('path');
|
|
@@ -28,6 +29,11 @@ var radash = require('radash');
|
|
|
28
29
|
var sift = require('sift');
|
|
29
30
|
var xstate = require('xstate');
|
|
30
31
|
|
|
32
|
+
function _arrayLikeToArray(r, a) {
|
|
33
|
+
(null == a || a > r.length) && (a = r.length);
|
|
34
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
35
|
+
return n;
|
|
36
|
+
}
|
|
31
37
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
32
38
|
try {
|
|
33
39
|
var i = n[a](c),
|
|
@@ -72,6 +78,23 @@ function _createClass(e, r, t) {
|
|
|
72
78
|
writable: !1
|
|
73
79
|
}), e;
|
|
74
80
|
}
|
|
81
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
82
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
83
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
84
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
85
|
+
t && (r = t);
|
|
86
|
+
var o = 0;
|
|
87
|
+
return function () {
|
|
88
|
+
return o >= r.length ? {
|
|
89
|
+
done: !0
|
|
90
|
+
} : {
|
|
91
|
+
done: !1,
|
|
92
|
+
value: r[o++]
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
|
+
}
|
|
75
98
|
function _extends() {
|
|
76
99
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
77
100
|
for (var e = 1; e < arguments.length; e++) {
|
|
@@ -413,6 +436,13 @@ function _toPropertyKey(t) {
|
|
|
413
436
|
var i = _toPrimitive(t, "string");
|
|
414
437
|
return "symbol" == typeof i ? i : i + "";
|
|
415
438
|
}
|
|
439
|
+
function _unsupportedIterableToArray(r, a) {
|
|
440
|
+
if (r) {
|
|
441
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
442
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
443
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
416
446
|
|
|
417
447
|
// Constants and Types
|
|
418
448
|
var RegisteredLogger = {
|
|
@@ -1021,9 +1051,10 @@ var delay = function delay(ms) {
|
|
|
1021
1051
|
});
|
|
1022
1052
|
};
|
|
1023
1053
|
|
|
1024
|
-
var _tools, _logger$2, _telemetry$4, _log$2;
|
|
1025
|
-
var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"), _telemetry$4 = /*#__PURE__*/_classPrivateFieldLooseKey("telemetry"), _log$2 = /*#__PURE__*/_classPrivateFieldLooseKey("log"), /*#__PURE__*/function () {
|
|
1026
|
-
function LLM() {
|
|
1054
|
+
var _model, _tools$1, _logger$2, _telemetry$4, _log$2;
|
|
1055
|
+
var LLM = (_model = /*#__PURE__*/_classPrivateFieldLooseKey("model"), _tools$1 = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"), _telemetry$4 = /*#__PURE__*/_classPrivateFieldLooseKey("telemetry"), _log$2 = /*#__PURE__*/_classPrivateFieldLooseKey("log"), /*#__PURE__*/function () {
|
|
1056
|
+
function LLM(_ref) {
|
|
1057
|
+
var model = _ref.model;
|
|
1027
1058
|
/**
|
|
1028
1059
|
* Internal logging helper that formats and sends logs to the configured logger
|
|
1029
1060
|
* @param level - Severity level of the log
|
|
@@ -1033,7 +1064,11 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1033
1064
|
Object.defineProperty(this, _log$2, {
|
|
1034
1065
|
value: _log2$2
|
|
1035
1066
|
});
|
|
1036
|
-
Object.defineProperty(this,
|
|
1067
|
+
Object.defineProperty(this, _model, {
|
|
1068
|
+
writable: true,
|
|
1069
|
+
value: void 0
|
|
1070
|
+
});
|
|
1071
|
+
Object.defineProperty(this, _tools$1, {
|
|
1037
1072
|
writable: true,
|
|
1038
1073
|
value: void 0
|
|
1039
1074
|
});
|
|
@@ -1045,7 +1080,8 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1045
1080
|
writable: true,
|
|
1046
1081
|
value: void 0
|
|
1047
1082
|
});
|
|
1048
|
-
_classPrivateFieldLooseBase(this,
|
|
1083
|
+
_classPrivateFieldLooseBase(this, _model)[_model] = model;
|
|
1084
|
+
_classPrivateFieldLooseBase(this, _tools$1)[_tools$1] = {};
|
|
1049
1085
|
_classPrivateFieldLooseBase(this, _logger$2)[_logger$2] = createLogger({
|
|
1050
1086
|
type: 'CONSOLE'
|
|
1051
1087
|
});
|
|
@@ -1056,7 +1092,7 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1056
1092
|
* @param tools
|
|
1057
1093
|
*/
|
|
1058
1094
|
_proto.__setTools = function __setTools(tools) {
|
|
1059
|
-
_classPrivateFieldLooseBase(this, _tools)[_tools] = tools;
|
|
1095
|
+
_classPrivateFieldLooseBase(this, _tools$1)[_tools$1] = tools;
|
|
1060
1096
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Tools set for LLM");
|
|
1061
1097
|
}
|
|
1062
1098
|
/**
|
|
@@ -1078,8 +1114,9 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1078
1114
|
/*
|
|
1079
1115
|
get experimental_telemetry config
|
|
1080
1116
|
*/;
|
|
1081
|
-
_proto.getModelType = function getModelType(
|
|
1117
|
+
_proto.getModelType = function getModelType() {
|
|
1082
1118
|
var _providerToType$model;
|
|
1119
|
+
var model = _classPrivateFieldLooseBase(this, _model)[_model];
|
|
1083
1120
|
if (!('provider' in model)) {
|
|
1084
1121
|
throw new Error('Model provider is required');
|
|
1085
1122
|
}
|
|
@@ -1105,12 +1142,12 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1105
1142
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Model type resolved to " + type + " for provider " + model.provider);
|
|
1106
1143
|
return type;
|
|
1107
1144
|
};
|
|
1108
|
-
_proto.createOpenAICompatibleModel = function createOpenAICompatibleModel(
|
|
1109
|
-
var baseURL =
|
|
1110
|
-
apiKey =
|
|
1111
|
-
defaultModelName =
|
|
1112
|
-
modelName =
|
|
1113
|
-
fetch =
|
|
1145
|
+
_proto.createOpenAICompatibleModel = function createOpenAICompatibleModel(_ref2) {
|
|
1146
|
+
var baseURL = _ref2.baseURL,
|
|
1147
|
+
apiKey = _ref2.apiKey,
|
|
1148
|
+
defaultModelName = _ref2.defaultModelName,
|
|
1149
|
+
modelName = _ref2.modelName,
|
|
1150
|
+
fetch = _ref2.fetch;
|
|
1114
1151
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Creating OpenAI compatible model with baseURL: " + baseURL);
|
|
1115
1152
|
var client = openai.createOpenAI({
|
|
1116
1153
|
baseURL: baseURL,
|
|
@@ -1119,8 +1156,8 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1119
1156
|
});
|
|
1120
1157
|
return client(modelName || defaultModelName);
|
|
1121
1158
|
};
|
|
1122
|
-
_proto.createModelDef = function createModelDef(
|
|
1123
|
-
var model =
|
|
1159
|
+
_proto.createModelDef = function createModelDef(_ref3) {
|
|
1160
|
+
var model = _ref3.model;
|
|
1124
1161
|
var modelDef;
|
|
1125
1162
|
if (model.type === 'openai') {
|
|
1126
1163
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.INFO, "Initializing OpenAI model " + (model.name || 'gpt-4o-2024-08-06'));
|
|
@@ -1256,12 +1293,12 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1256
1293
|
return modelDef;
|
|
1257
1294
|
};
|
|
1258
1295
|
_proto.createEmbedding = /*#__PURE__*/function () {
|
|
1259
|
-
var _createEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(
|
|
1296
|
+
var _createEmbedding = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref4) {
|
|
1260
1297
|
var model, value, maxRetries, embeddingModel, openai$1, cohere$1;
|
|
1261
1298
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1262
1299
|
while (1) switch (_context.prev = _context.next) {
|
|
1263
1300
|
case 0:
|
|
1264
|
-
model =
|
|
1301
|
+
model = _ref4.model, value = _ref4.value, maxRetries = _ref4.maxRetries;
|
|
1265
1302
|
if (!(model.provider === 'OPEN_AI')) {
|
|
1266
1303
|
_context.next = 6;
|
|
1267
1304
|
break;
|
|
@@ -1319,15 +1356,15 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1319
1356
|
return createEmbedding;
|
|
1320
1357
|
}();
|
|
1321
1358
|
_proto.getParams = /*#__PURE__*/function () {
|
|
1322
|
-
var _getParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(
|
|
1359
|
+
var _getParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref5) {
|
|
1323
1360
|
var tools, resultTool, model, toolsConverted, answerTool, modelDef;
|
|
1324
1361
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1325
1362
|
while (1) switch (_context2.prev = _context2.next) {
|
|
1326
1363
|
case 0:
|
|
1327
|
-
tools =
|
|
1328
|
-
toolsConverted = Object.entries(tools).reduce(function (memo,
|
|
1329
|
-
var key =
|
|
1330
|
-
val =
|
|
1364
|
+
tools = _ref5.tools, resultTool = _ref5.resultTool, model = _ref5.model;
|
|
1365
|
+
toolsConverted = Object.entries(tools).reduce(function (memo, _ref6) {
|
|
1366
|
+
var key = _ref6[0],
|
|
1367
|
+
val = _ref6[1];
|
|
1331
1368
|
memo[key] = ai.tool(val);
|
|
1332
1369
|
return memo;
|
|
1333
1370
|
}, {});
|
|
@@ -1364,7 +1401,7 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1364
1401
|
toolsConverted: toolsConverted,
|
|
1365
1402
|
modelDef: modelDef,
|
|
1366
1403
|
answerTool: answerTool,
|
|
1367
|
-
toolChoice: model.toolChoice || '
|
|
1404
|
+
toolChoice: model.toolChoice || 'auto'
|
|
1368
1405
|
});
|
|
1369
1406
|
case 16:
|
|
1370
1407
|
case "end":
|
|
@@ -1382,7 +1419,7 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1382
1419
|
var converted = Object.entries(enabledTools || {}).reduce(function (memo, value) {
|
|
1383
1420
|
var k = value[0];
|
|
1384
1421
|
var enabled = value[1];
|
|
1385
|
-
var tool = _classPrivateFieldLooseBase(_this, _tools)[_tools][k];
|
|
1422
|
+
var tool = _classPrivateFieldLooseBase(_this, _tools$1)[_tools$1][k];
|
|
1386
1423
|
if (enabled && tool) {
|
|
1387
1424
|
memo[k] = {
|
|
1388
1425
|
description: tool.description,
|
|
@@ -1409,16 +1446,16 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1409
1446
|
case 'boolean':
|
|
1410
1447
|
return zod.z["boolean"]();
|
|
1411
1448
|
case 'date':
|
|
1412
|
-
return zod.z.string().
|
|
1449
|
+
return zod.z.string().describe('ISO 8601 date string');
|
|
1413
1450
|
default:
|
|
1414
1451
|
return zod.z.string();
|
|
1415
1452
|
}
|
|
1416
1453
|
};
|
|
1417
1454
|
_proto.createOutputSchema = function createOutputSchema(output) {
|
|
1418
1455
|
var _this2 = this;
|
|
1419
|
-
var schema = Object.entries(output).reduce(function (memo,
|
|
1420
|
-
var k =
|
|
1421
|
-
v =
|
|
1456
|
+
var schema = Object.entries(output).reduce(function (memo, _ref7) {
|
|
1457
|
+
var k = _ref7[0],
|
|
1458
|
+
v = _ref7[1];
|
|
1422
1459
|
if (_this2.isBaseOutputType(v.type)) {
|
|
1423
1460
|
memo[k] = _this2.baseOutputTypeSchema(v.type);
|
|
1424
1461
|
}
|
|
@@ -1442,18 +1479,108 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1442
1479
|
}, {});
|
|
1443
1480
|
return zod.z.object(schema);
|
|
1444
1481
|
};
|
|
1445
|
-
_proto.
|
|
1446
|
-
var
|
|
1482
|
+
_proto.generate = /*#__PURE__*/function () {
|
|
1483
|
+
var _generate = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(messages, _temp) {
|
|
1484
|
+
var _ref8, schema, stream, _ref8$maxSteps, maxSteps, onFinish, onStepFinish, enabledTools, convertedTools, runId, msgs;
|
|
1485
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1486
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1487
|
+
case 0:
|
|
1488
|
+
_ref8 = _temp === void 0 ? {} : _temp, schema = _ref8.schema, stream = _ref8.stream, _ref8$maxSteps = _ref8.maxSteps, maxSteps = _ref8$maxSteps === void 0 ? 5 : _ref8$maxSteps, onFinish = _ref8.onFinish, onStepFinish = _ref8.onStepFinish, enabledTools = _ref8.enabledTools, convertedTools = _ref8.convertedTools, runId = _ref8.runId;
|
|
1489
|
+
if (Array.isArray(messages)) {
|
|
1490
|
+
msgs = messages;
|
|
1491
|
+
} else {
|
|
1492
|
+
msgs = [{
|
|
1493
|
+
role: 'user',
|
|
1494
|
+
content: messages
|
|
1495
|
+
}];
|
|
1496
|
+
}
|
|
1497
|
+
if (!(stream && schema)) {
|
|
1498
|
+
_context3.next = 6;
|
|
1499
|
+
break;
|
|
1500
|
+
}
|
|
1501
|
+
_context3.next = 5;
|
|
1502
|
+
return this.__streamObject({
|
|
1503
|
+
messages: msgs,
|
|
1504
|
+
structuredOutput: schema,
|
|
1505
|
+
onStepFinish: onStepFinish,
|
|
1506
|
+
onFinish: onFinish,
|
|
1507
|
+
maxSteps: maxSteps,
|
|
1508
|
+
enabledTools: enabledTools,
|
|
1509
|
+
convertedTools: convertedTools,
|
|
1510
|
+
runId: runId
|
|
1511
|
+
});
|
|
1512
|
+
case 5:
|
|
1513
|
+
return _context3.abrupt("return", _context3.sent);
|
|
1514
|
+
case 6:
|
|
1515
|
+
if (!stream) {
|
|
1516
|
+
_context3.next = 10;
|
|
1517
|
+
break;
|
|
1518
|
+
}
|
|
1519
|
+
_context3.next = 9;
|
|
1520
|
+
return this.__stream({
|
|
1521
|
+
messages: msgs,
|
|
1522
|
+
onStepFinish: onStepFinish,
|
|
1523
|
+
onFinish: onFinish,
|
|
1524
|
+
maxSteps: maxSteps,
|
|
1525
|
+
enabledTools: enabledTools,
|
|
1526
|
+
convertedTools: convertedTools,
|
|
1527
|
+
runId: runId
|
|
1528
|
+
});
|
|
1529
|
+
case 9:
|
|
1530
|
+
return _context3.abrupt("return", _context3.sent);
|
|
1531
|
+
case 10:
|
|
1532
|
+
if (!schema) {
|
|
1533
|
+
_context3.next = 14;
|
|
1534
|
+
break;
|
|
1535
|
+
}
|
|
1536
|
+
_context3.next = 13;
|
|
1537
|
+
return this.__textObject({
|
|
1538
|
+
messages: msgs,
|
|
1539
|
+
structuredOutput: schema,
|
|
1540
|
+
onStepFinish: onStepFinish,
|
|
1541
|
+
maxSteps: maxSteps,
|
|
1542
|
+
enabledTools: enabledTools,
|
|
1543
|
+
convertedTools: convertedTools,
|
|
1544
|
+
runId: runId
|
|
1545
|
+
});
|
|
1546
|
+
case 13:
|
|
1547
|
+
return _context3.abrupt("return", _context3.sent);
|
|
1548
|
+
case 14:
|
|
1549
|
+
_context3.next = 16;
|
|
1550
|
+
return this.__text({
|
|
1551
|
+
messages: msgs,
|
|
1552
|
+
onStepFinish: onStepFinish,
|
|
1553
|
+
maxSteps: maxSteps,
|
|
1554
|
+
enabledTools: enabledTools,
|
|
1555
|
+
convertedTools: convertedTools,
|
|
1556
|
+
runId: runId
|
|
1557
|
+
});
|
|
1558
|
+
case 16:
|
|
1559
|
+
return _context3.abrupt("return", _context3.sent);
|
|
1560
|
+
case 17:
|
|
1561
|
+
case "end":
|
|
1562
|
+
return _context3.stop();
|
|
1563
|
+
}
|
|
1564
|
+
}, _callee3, this);
|
|
1565
|
+
}));
|
|
1566
|
+
function generate(_x3, _x4) {
|
|
1567
|
+
return _generate.apply(this, arguments);
|
|
1568
|
+
}
|
|
1569
|
+
return generate;
|
|
1570
|
+
}();
|
|
1571
|
+
_proto.__text = /*#__PURE__*/function () {
|
|
1572
|
+
var _text = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref9) {
|
|
1447
1573
|
var _this3 = this;
|
|
1448
|
-
var
|
|
1449
|
-
return _regeneratorRuntime().wrap(function
|
|
1450
|
-
while (1) switch (
|
|
1574
|
+
var messages, _onStepFinish, _ref9$maxSteps, maxSteps, enabledTools, runId, convertedTools, model, modelToPass, params, argsForExecute;
|
|
1575
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
1576
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
1451
1577
|
case 0:
|
|
1452
|
-
|
|
1578
|
+
messages = _ref9.messages, _onStepFinish = _ref9.onStepFinish, _ref9$maxSteps = _ref9.maxSteps, maxSteps = _ref9$maxSteps === void 0 ? 5 : _ref9$maxSteps, enabledTools = _ref9.enabledTools, runId = _ref9.runId, convertedTools = _ref9.convertedTools;
|
|
1579
|
+
model = _classPrivateFieldLooseBase(this, _model)[_model];
|
|
1453
1580
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Generating text with " + messages.length + " messages", runId);
|
|
1454
1581
|
if ('name' in model) {
|
|
1455
1582
|
modelToPass = {
|
|
1456
|
-
type: this.getModelType(
|
|
1583
|
+
type: this.getModelType(),
|
|
1457
1584
|
name: model.name,
|
|
1458
1585
|
toolChoice: model.toolChoice,
|
|
1459
1586
|
apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
|
|
@@ -1463,75 +1590,76 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1463
1590
|
} else {
|
|
1464
1591
|
modelToPass = model;
|
|
1465
1592
|
}
|
|
1466
|
-
|
|
1593
|
+
_context5.next = 6;
|
|
1467
1594
|
return this.getParams({
|
|
1468
|
-
tools: this.convertTools(enabledTools || {}),
|
|
1595
|
+
tools: convertedTools || this.convertTools(enabledTools || {}),
|
|
1469
1596
|
model: modelToPass
|
|
1470
1597
|
});
|
|
1471
|
-
case
|
|
1472
|
-
params =
|
|
1598
|
+
case 6:
|
|
1599
|
+
params = _context5.sent;
|
|
1473
1600
|
argsForExecute = {
|
|
1474
1601
|
model: params.modelDef,
|
|
1475
1602
|
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1476
1603
|
toolChoice: params.toolChoice,
|
|
1477
1604
|
maxSteps: maxSteps,
|
|
1478
1605
|
onStepFinish: function () {
|
|
1479
|
-
var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1606
|
+
var _onStepFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props) {
|
|
1480
1607
|
var _props$response, _props$response2;
|
|
1481
|
-
return _regeneratorRuntime().wrap(function
|
|
1482
|
-
while (1) switch (
|
|
1608
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1609
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
1483
1610
|
case 0:
|
|
1484
1611
|
_onStepFinish == null || _onStepFinish(JSON.stringify(props, null, 2));
|
|
1485
1612
|
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)) {
|
|
1486
|
-
|
|
1613
|
+
_context4.next = 5;
|
|
1487
1614
|
break;
|
|
1488
1615
|
}
|
|
1489
1616
|
_classPrivateFieldLooseBase(_this3, _logger$2)[_logger$2].warn('Rate limit approaching, waiting 10 seconds');
|
|
1490
|
-
|
|
1617
|
+
_context4.next = 5;
|
|
1491
1618
|
return delay(10 * 1000);
|
|
1492
1619
|
case 5:
|
|
1493
1620
|
case "end":
|
|
1494
|
-
return
|
|
1621
|
+
return _context4.stop();
|
|
1495
1622
|
}
|
|
1496
|
-
},
|
|
1623
|
+
}, _callee4);
|
|
1497
1624
|
}));
|
|
1498
|
-
function onStepFinish(
|
|
1625
|
+
function onStepFinish(_x6) {
|
|
1499
1626
|
return _onStepFinish2.apply(this, arguments);
|
|
1500
1627
|
}
|
|
1501
1628
|
return onStepFinish;
|
|
1502
1629
|
}()
|
|
1503
1630
|
};
|
|
1504
|
-
|
|
1631
|
+
_context5.next = 10;
|
|
1505
1632
|
return ai.generateText(_extends({
|
|
1506
1633
|
messages: messages
|
|
1507
1634
|
}, argsForExecute, {
|
|
1508
1635
|
experimental_telemetry: this.experimental_telemetry
|
|
1509
1636
|
}));
|
|
1510
|
-
case 9:
|
|
1511
|
-
return _context4.abrupt("return", _context4.sent);
|
|
1512
1637
|
case 10:
|
|
1638
|
+
return _context5.abrupt("return", _context5.sent);
|
|
1639
|
+
case 11:
|
|
1513
1640
|
case "end":
|
|
1514
|
-
return
|
|
1641
|
+
return _context5.stop();
|
|
1515
1642
|
}
|
|
1516
|
-
},
|
|
1643
|
+
}, _callee5, this);
|
|
1517
1644
|
}));
|
|
1518
|
-
function
|
|
1645
|
+
function __text(_x5) {
|
|
1519
1646
|
return _text.apply(this, arguments);
|
|
1520
1647
|
}
|
|
1521
|
-
return
|
|
1648
|
+
return __text;
|
|
1522
1649
|
}();
|
|
1523
|
-
_proto.
|
|
1524
|
-
var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1650
|
+
_proto.__textObject = /*#__PURE__*/function () {
|
|
1651
|
+
var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref10) {
|
|
1525
1652
|
var _this4 = this;
|
|
1526
|
-
var
|
|
1527
|
-
return _regeneratorRuntime().wrap(function
|
|
1528
|
-
while (1) switch (
|
|
1653
|
+
var messages, _onStepFinish3, _ref10$maxSteps, maxSteps, enabledTools, convertedTools, structuredOutput, runId, model, modelToPass, params, argsForExecute, schema, output;
|
|
1654
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1655
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1529
1656
|
case 0:
|
|
1530
|
-
|
|
1657
|
+
messages = _ref10.messages, _onStepFinish3 = _ref10.onStepFinish, _ref10$maxSteps = _ref10.maxSteps, maxSteps = _ref10$maxSteps === void 0 ? 5 : _ref10$maxSteps, enabledTools = _ref10.enabledTools, convertedTools = _ref10.convertedTools, structuredOutput = _ref10.structuredOutput, runId = _ref10.runId;
|
|
1658
|
+
model = _classPrivateFieldLooseBase(this, _model)[_model];
|
|
1531
1659
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Generating text with " + messages.length + " messages", runId);
|
|
1532
1660
|
if ('name' in model) {
|
|
1533
1661
|
modelToPass = {
|
|
1534
|
-
type: this.getModelType(
|
|
1662
|
+
type: this.getModelType(),
|
|
1535
1663
|
name: model.name,
|
|
1536
1664
|
toolChoice: model.toolChoice,
|
|
1537
1665
|
apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
|
|
@@ -1541,39 +1669,39 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1541
1669
|
} else {
|
|
1542
1670
|
modelToPass = model;
|
|
1543
1671
|
}
|
|
1544
|
-
|
|
1672
|
+
_context7.next = 6;
|
|
1545
1673
|
return this.getParams({
|
|
1546
|
-
tools: this.convertTools(enabledTools || {}),
|
|
1674
|
+
tools: convertedTools || this.convertTools(enabledTools || {}),
|
|
1547
1675
|
model: modelToPass
|
|
1548
1676
|
});
|
|
1549
|
-
case
|
|
1550
|
-
params =
|
|
1677
|
+
case 6:
|
|
1678
|
+
params = _context7.sent;
|
|
1551
1679
|
argsForExecute = {
|
|
1552
1680
|
model: params.modelDef,
|
|
1553
1681
|
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1554
1682
|
toolChoice: params.toolChoice,
|
|
1555
1683
|
maxSteps: maxSteps,
|
|
1556
1684
|
onStepFinish: function () {
|
|
1557
|
-
var _onStepFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1685
|
+
var _onStepFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(props) {
|
|
1558
1686
|
var _props$response3, _props$response4;
|
|
1559
|
-
return _regeneratorRuntime().wrap(function
|
|
1560
|
-
while (1) switch (
|
|
1687
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
1688
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
1561
1689
|
case 0:
|
|
1562
1690
|
_onStepFinish3 == null || _onStepFinish3(JSON.stringify(props, null, 2));
|
|
1563
1691
|
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)) {
|
|
1564
|
-
|
|
1692
|
+
_context6.next = 5;
|
|
1565
1693
|
break;
|
|
1566
1694
|
}
|
|
1567
1695
|
_classPrivateFieldLooseBase(_this4, _logger$2)[_logger$2].warn('Rate limit approaching, waiting 10 seconds', runId);
|
|
1568
|
-
|
|
1696
|
+
_context6.next = 5;
|
|
1569
1697
|
return delay(10 * 1000);
|
|
1570
1698
|
case 5:
|
|
1571
1699
|
case "end":
|
|
1572
|
-
return
|
|
1700
|
+
return _context6.stop();
|
|
1573
1701
|
}
|
|
1574
|
-
},
|
|
1702
|
+
}, _callee6);
|
|
1575
1703
|
}));
|
|
1576
|
-
function onStepFinish(
|
|
1704
|
+
function onStepFinish(_x8) {
|
|
1577
1705
|
return _onStepFinish4.apply(this, arguments);
|
|
1578
1706
|
}
|
|
1579
1707
|
return onStepFinish;
|
|
@@ -1589,7 +1717,7 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1589
1717
|
} else {
|
|
1590
1718
|
schema = this.createOutputSchema(structuredOutput);
|
|
1591
1719
|
}
|
|
1592
|
-
|
|
1720
|
+
_context7.next = 12;
|
|
1593
1721
|
return ai.generateObject(_extends({
|
|
1594
1722
|
messages: messages
|
|
1595
1723
|
}, argsForExecute, {
|
|
@@ -1597,31 +1725,32 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1597
1725
|
schema: schema,
|
|
1598
1726
|
experimental_telemetry: this.experimental_telemetry
|
|
1599
1727
|
}));
|
|
1600
|
-
case 11:
|
|
1601
|
-
return _context6.abrupt("return", _context6.sent);
|
|
1602
1728
|
case 12:
|
|
1729
|
+
return _context7.abrupt("return", _context7.sent);
|
|
1730
|
+
case 13:
|
|
1603
1731
|
case "end":
|
|
1604
|
-
return
|
|
1732
|
+
return _context7.stop();
|
|
1605
1733
|
}
|
|
1606
|
-
},
|
|
1734
|
+
}, _callee7, this);
|
|
1607
1735
|
}));
|
|
1608
|
-
function
|
|
1736
|
+
function __textObject(_x7) {
|
|
1609
1737
|
return _textObject.apply(this, arguments);
|
|
1610
1738
|
}
|
|
1611
|
-
return
|
|
1739
|
+
return __textObject;
|
|
1612
1740
|
}();
|
|
1613
|
-
_proto.
|
|
1614
|
-
var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1741
|
+
_proto.__stream = /*#__PURE__*/function () {
|
|
1742
|
+
var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref11) {
|
|
1615
1743
|
var _this5 = this;
|
|
1616
|
-
var
|
|
1617
|
-
return _regeneratorRuntime().wrap(function
|
|
1618
|
-
while (1) switch (
|
|
1744
|
+
var messages, _onStepFinish5, _onFinish, _ref11$maxSteps, maxSteps, enabledTools, runId, convertedTools, model, modelToPass, params, argsForExecute;
|
|
1745
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1746
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1619
1747
|
case 0:
|
|
1620
|
-
|
|
1748
|
+
messages = _ref11.messages, _onStepFinish5 = _ref11.onStepFinish, _onFinish = _ref11.onFinish, _ref11$maxSteps = _ref11.maxSteps, maxSteps = _ref11$maxSteps === void 0 ? 5 : _ref11$maxSteps, enabledTools = _ref11.enabledTools, runId = _ref11.runId, convertedTools = _ref11.convertedTools;
|
|
1749
|
+
model = _classPrivateFieldLooseBase(this, _model)[_model];
|
|
1621
1750
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Streaming text with " + messages.length + " messages", runId);
|
|
1622
1751
|
if ('name' in model) {
|
|
1623
1752
|
modelToPass = {
|
|
1624
|
-
type: this.getModelType(
|
|
1753
|
+
type: this.getModelType(),
|
|
1625
1754
|
name: model.name,
|
|
1626
1755
|
toolChoice: model.toolChoice,
|
|
1627
1756
|
apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
|
|
@@ -1631,92 +1760,93 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1631
1760
|
} else {
|
|
1632
1761
|
modelToPass = model;
|
|
1633
1762
|
}
|
|
1634
|
-
|
|
1763
|
+
_context10.next = 6;
|
|
1635
1764
|
return this.getParams({
|
|
1636
|
-
tools: this.convertTools(enabledTools),
|
|
1765
|
+
tools: convertedTools || this.convertTools(enabledTools),
|
|
1637
1766
|
model: modelToPass
|
|
1638
1767
|
});
|
|
1639
|
-
case
|
|
1640
|
-
params =
|
|
1768
|
+
case 6:
|
|
1769
|
+
params = _context10.sent;
|
|
1641
1770
|
argsForExecute = {
|
|
1642
1771
|
model: params.modelDef,
|
|
1643
1772
|
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1644
1773
|
toolChoice: params.toolChoice,
|
|
1645
1774
|
maxSteps: maxSteps,
|
|
1646
1775
|
onStepFinish: function () {
|
|
1647
|
-
var _onStepFinish6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1776
|
+
var _onStepFinish6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(props) {
|
|
1648
1777
|
var _props$response5, _props$response6;
|
|
1649
|
-
return _regeneratorRuntime().wrap(function
|
|
1650
|
-
while (1) switch (
|
|
1778
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1779
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1651
1780
|
case 0:
|
|
1652
1781
|
_onStepFinish5 == null || _onStepFinish5(JSON.stringify(props, null, 2));
|
|
1653
1782
|
if (!(props != null && (_props$response5 = props.response) != null && (_props$response5 = _props$response5.headers) != null && _props$response5['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response6 = props.response) == null || (_props$response6 = _props$response6.headers) == null ? void 0 : _props$response6['x-ratelimit-remaining-tokens'], 10) < 2000)) {
|
|
1654
|
-
|
|
1783
|
+
_context8.next = 5;
|
|
1655
1784
|
break;
|
|
1656
1785
|
}
|
|
1657
1786
|
_classPrivateFieldLooseBase(_this5, _logger$2)[_logger$2].warn('Rate limit approaching, waiting 10 seconds', runId);
|
|
1658
|
-
|
|
1787
|
+
_context8.next = 5;
|
|
1659
1788
|
return delay(10 * 1000);
|
|
1660
1789
|
case 5:
|
|
1661
1790
|
case "end":
|
|
1662
|
-
return
|
|
1791
|
+
return _context8.stop();
|
|
1663
1792
|
}
|
|
1664
|
-
},
|
|
1793
|
+
}, _callee8);
|
|
1665
1794
|
}));
|
|
1666
|
-
function onStepFinish(
|
|
1795
|
+
function onStepFinish(_x10) {
|
|
1667
1796
|
return _onStepFinish6.apply(this, arguments);
|
|
1668
1797
|
}
|
|
1669
1798
|
return onStepFinish;
|
|
1670
1799
|
}(),
|
|
1671
1800
|
onFinish: function () {
|
|
1672
|
-
var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1673
|
-
return _regeneratorRuntime().wrap(function
|
|
1674
|
-
while (1) switch (
|
|
1801
|
+
var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(props) {
|
|
1802
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1803
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1675
1804
|
case 0:
|
|
1676
1805
|
_onFinish == null || _onFinish(JSON.stringify(props, null, 2));
|
|
1677
1806
|
case 1:
|
|
1678
1807
|
case "end":
|
|
1679
|
-
return
|
|
1808
|
+
return _context9.stop();
|
|
1680
1809
|
}
|
|
1681
|
-
},
|
|
1810
|
+
}, _callee9);
|
|
1682
1811
|
}));
|
|
1683
|
-
function onFinish(
|
|
1812
|
+
function onFinish(_x11) {
|
|
1684
1813
|
return _onFinish2.apply(this, arguments);
|
|
1685
1814
|
}
|
|
1686
1815
|
return onFinish;
|
|
1687
1816
|
}()
|
|
1688
1817
|
};
|
|
1689
|
-
|
|
1818
|
+
_context10.next = 10;
|
|
1690
1819
|
return ai.streamText(_extends({
|
|
1691
1820
|
messages: messages
|
|
1692
1821
|
}, argsForExecute, {
|
|
1693
1822
|
experimental_telemetry: this.experimental_telemetry
|
|
1694
1823
|
}));
|
|
1695
|
-
case 9:
|
|
1696
|
-
return _context9.abrupt("return", _context9.sent);
|
|
1697
1824
|
case 10:
|
|
1825
|
+
return _context10.abrupt("return", _context10.sent);
|
|
1826
|
+
case 11:
|
|
1698
1827
|
case "end":
|
|
1699
|
-
return
|
|
1828
|
+
return _context10.stop();
|
|
1700
1829
|
}
|
|
1701
|
-
},
|
|
1830
|
+
}, _callee10, this);
|
|
1702
1831
|
}));
|
|
1703
|
-
function
|
|
1832
|
+
function __stream(_x9) {
|
|
1704
1833
|
return _stream.apply(this, arguments);
|
|
1705
1834
|
}
|
|
1706
|
-
return
|
|
1835
|
+
return __stream;
|
|
1707
1836
|
}();
|
|
1708
|
-
_proto.
|
|
1709
|
-
var
|
|
1837
|
+
_proto.__streamObject = /*#__PURE__*/function () {
|
|
1838
|
+
var _streamObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref12) {
|
|
1710
1839
|
var _this6 = this;
|
|
1711
|
-
var
|
|
1712
|
-
return _regeneratorRuntime().wrap(function
|
|
1713
|
-
while (1) switch (
|
|
1840
|
+
var messages, _onStepFinish7, _onFinish3, _ref12$maxSteps, maxSteps, enabledTools, convertedTools, structuredOutput, runId, model, modelToPass, params, argsForExecute, schema, output;
|
|
1841
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1842
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1714
1843
|
case 0:
|
|
1715
|
-
|
|
1844
|
+
messages = _ref12.messages, _onStepFinish7 = _ref12.onStepFinish, _onFinish3 = _ref12.onFinish, _ref12$maxSteps = _ref12.maxSteps, maxSteps = _ref12$maxSteps === void 0 ? 5 : _ref12$maxSteps, enabledTools = _ref12.enabledTools, convertedTools = _ref12.convertedTools, structuredOutput = _ref12.structuredOutput, runId = _ref12.runId;
|
|
1845
|
+
model = _classPrivateFieldLooseBase(this, _model)[_model];
|
|
1716
1846
|
_classPrivateFieldLooseBase(this, _log$2)[_log$2](LogLevel.DEBUG, "Streaming text with " + messages.length + " messages", runId);
|
|
1717
1847
|
if ('name' in model) {
|
|
1718
1848
|
modelToPass = {
|
|
1719
|
-
type: this.getModelType(
|
|
1849
|
+
type: this.getModelType(),
|
|
1720
1850
|
name: model.name,
|
|
1721
1851
|
toolChoice: model.toolChoice,
|
|
1722
1852
|
apiKey: model.provider !== 'LM_STUDIO' ? model == null ? void 0 : model.apiKey : undefined,
|
|
@@ -1726,56 +1856,56 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1726
1856
|
} else {
|
|
1727
1857
|
modelToPass = model;
|
|
1728
1858
|
}
|
|
1729
|
-
|
|
1859
|
+
_context13.next = 6;
|
|
1730
1860
|
return this.getParams({
|
|
1731
|
-
tools: this.convertTools(enabledTools),
|
|
1861
|
+
tools: convertedTools || this.convertTools(enabledTools),
|
|
1732
1862
|
model: modelToPass
|
|
1733
1863
|
});
|
|
1734
|
-
case
|
|
1735
|
-
params =
|
|
1864
|
+
case 6:
|
|
1865
|
+
params = _context13.sent;
|
|
1736
1866
|
argsForExecute = {
|
|
1737
1867
|
model: params.modelDef,
|
|
1738
1868
|
tools: _extends({}, params.toolsConverted, params.answerTool),
|
|
1739
1869
|
toolChoice: params.toolChoice,
|
|
1740
1870
|
maxSteps: maxSteps,
|
|
1741
1871
|
onStepFinish: function () {
|
|
1742
|
-
var _onStepFinish8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1872
|
+
var _onStepFinish8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(props) {
|
|
1743
1873
|
var _props$response7, _props$response8;
|
|
1744
|
-
return _regeneratorRuntime().wrap(function
|
|
1745
|
-
while (1) switch (
|
|
1874
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1875
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1746
1876
|
case 0:
|
|
1747
1877
|
_onStepFinish7 == null || _onStepFinish7(JSON.stringify(props, null, 2));
|
|
1748
1878
|
if (!(props != null && (_props$response7 = props.response) != null && (_props$response7 = _props$response7.headers) != null && _props$response7['x-ratelimit-remaining-tokens'] && parseInt(props == null || (_props$response8 = props.response) == null || (_props$response8 = _props$response8.headers) == null ? void 0 : _props$response8['x-ratelimit-remaining-tokens'], 10) < 2000)) {
|
|
1749
|
-
|
|
1879
|
+
_context11.next = 5;
|
|
1750
1880
|
break;
|
|
1751
1881
|
}
|
|
1752
1882
|
_classPrivateFieldLooseBase(_this6, _logger$2)[_logger$2].warn('Rate limit approaching, waiting 10 seconds', runId);
|
|
1753
|
-
|
|
1883
|
+
_context11.next = 5;
|
|
1754
1884
|
return delay(10 * 1000);
|
|
1755
1885
|
case 5:
|
|
1756
1886
|
case "end":
|
|
1757
|
-
return
|
|
1887
|
+
return _context11.stop();
|
|
1758
1888
|
}
|
|
1759
|
-
},
|
|
1889
|
+
}, _callee11);
|
|
1760
1890
|
}));
|
|
1761
|
-
function onStepFinish(
|
|
1891
|
+
function onStepFinish(_x13) {
|
|
1762
1892
|
return _onStepFinish8.apply(this, arguments);
|
|
1763
1893
|
}
|
|
1764
1894
|
return onStepFinish;
|
|
1765
1895
|
}(),
|
|
1766
1896
|
onFinish: function () {
|
|
1767
|
-
var _onFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1768
|
-
return _regeneratorRuntime().wrap(function
|
|
1769
|
-
while (1) switch (
|
|
1897
|
+
var _onFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(props) {
|
|
1898
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1899
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1770
1900
|
case 0:
|
|
1771
1901
|
_onFinish3 == null || _onFinish3(JSON.stringify(props, null, 2));
|
|
1772
1902
|
case 1:
|
|
1773
1903
|
case "end":
|
|
1774
|
-
return
|
|
1904
|
+
return _context12.stop();
|
|
1775
1905
|
}
|
|
1776
|
-
},
|
|
1906
|
+
}, _callee12);
|
|
1777
1907
|
}));
|
|
1778
|
-
function onFinish(
|
|
1908
|
+
function onFinish(_x14) {
|
|
1779
1909
|
return _onFinish4.apply(this, arguments);
|
|
1780
1910
|
}
|
|
1781
1911
|
return onFinish;
|
|
@@ -1791,7 +1921,7 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1791
1921
|
} else {
|
|
1792
1922
|
schema = this.createOutputSchema(structuredOutput);
|
|
1793
1923
|
}
|
|
1794
|
-
|
|
1924
|
+
_context13.next = 12;
|
|
1795
1925
|
return ai.streamObject(_extends({
|
|
1796
1926
|
messages: messages
|
|
1797
1927
|
}, argsForExecute, {
|
|
@@ -1799,18 +1929,18 @@ var LLM = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$2
|
|
|
1799
1929
|
schema: schema,
|
|
1800
1930
|
experimental_telemetry: this.experimental_telemetry
|
|
1801
1931
|
}));
|
|
1802
|
-
case 11:
|
|
1803
|
-
return _context12.abrupt("return", _context12.sent);
|
|
1804
1932
|
case 12:
|
|
1933
|
+
return _context13.abrupt("return", _context13.sent);
|
|
1934
|
+
case 13:
|
|
1805
1935
|
case "end":
|
|
1806
|
-
return
|
|
1936
|
+
return _context13.stop();
|
|
1807
1937
|
}
|
|
1808
|
-
},
|
|
1938
|
+
}, _callee13, this);
|
|
1809
1939
|
}));
|
|
1810
|
-
function
|
|
1811
|
-
return
|
|
1940
|
+
function __streamObject(_x12) {
|
|
1941
|
+
return _streamObject.apply(this, arguments);
|
|
1812
1942
|
}
|
|
1813
|
-
return
|
|
1943
|
+
return __streamObject;
|
|
1814
1944
|
}();
|
|
1815
1945
|
return _createClass(LLM, [{
|
|
1816
1946
|
key: "experimental_telemetry",
|
|
@@ -1837,7 +1967,7 @@ function _log2$2(level, message, runId) {
|
|
|
1837
1967
|
LLM = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/InstrumentClass({
|
|
1838
1968
|
prefix: 'llm',
|
|
1839
1969
|
excludeMethods: ['__setTools', '__setLogger', '__setTelemetry', '#log']
|
|
1840
|
-
}), /*#__PURE__*/tslib.__metadata("design:paramtypes", [])], LLM);
|
|
1970
|
+
}), /*#__PURE__*/tslib.__metadata("design:paramtypes", [Object])], LLM);
|
|
1841
1971
|
|
|
1842
1972
|
// Store SDK instance outside the class to persist across HMR
|
|
1843
1973
|
var sdkInstance = null;
|
|
@@ -2080,8 +2210,8 @@ var Telemetry = /*#__PURE__*/function () {
|
|
|
2080
2210
|
}();
|
|
2081
2211
|
Telemetry.isInitialized = false;
|
|
2082
2212
|
|
|
2083
|
-
var _logger$1, _telemetry$3, _log$1;
|
|
2084
|
-
exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"), _telemetry$3 = /*#__PURE__*/_classPrivateFieldLooseKey("telemetry"), _log$1 = /*#__PURE__*/_classPrivateFieldLooseKey("log"), /*#__PURE__*/function () {
|
|
2213
|
+
var _tools, _logger$1, _telemetry$3, _log$1;
|
|
2214
|
+
exports.Agent = (_tools = /*#__PURE__*/_classPrivateFieldLooseKey("tools"), _logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"), _telemetry$3 = /*#__PURE__*/_classPrivateFieldLooseKey("telemetry"), _log$1 = /*#__PURE__*/_classPrivateFieldLooseKey("log"), /*#__PURE__*/function () {
|
|
2085
2215
|
function Agent(config) {
|
|
2086
2216
|
/**
|
|
2087
2217
|
* Internal logging helper that formats and sends logs to the configured logger
|
|
@@ -2093,10 +2223,15 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2093
2223
|
value: _log2$1
|
|
2094
2224
|
});
|
|
2095
2225
|
this.name = void 0;
|
|
2226
|
+
this.memory = void 0;
|
|
2096
2227
|
this.llm = void 0;
|
|
2097
2228
|
this.instructions = void 0;
|
|
2098
2229
|
this.model = void 0;
|
|
2099
2230
|
this.enabledTools = void 0;
|
|
2231
|
+
Object.defineProperty(this, _tools, {
|
|
2232
|
+
writable: true,
|
|
2233
|
+
value: void 0
|
|
2234
|
+
});
|
|
2100
2235
|
Object.defineProperty(this, _logger$1, {
|
|
2101
2236
|
writable: true,
|
|
2102
2237
|
value: void 0
|
|
@@ -2107,13 +2242,16 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2107
2242
|
});
|
|
2108
2243
|
this.name = config.name;
|
|
2109
2244
|
this.instructions = config.instructions;
|
|
2110
|
-
this.llm = new LLM(
|
|
2245
|
+
this.llm = new LLM({
|
|
2246
|
+
model: config.model
|
|
2247
|
+
});
|
|
2111
2248
|
this.model = config.model;
|
|
2112
2249
|
this.enabledTools = config.enabledTools || {};
|
|
2113
2250
|
_classPrivateFieldLooseBase(this, _logger$1)[_logger$1] = createLogger({
|
|
2114
2251
|
type: 'CONSOLE'
|
|
2115
2252
|
});
|
|
2116
2253
|
_classPrivateFieldLooseBase(this, _logger$1)[_logger$1].info("Agent " + this.name + " initialized with model " + this.model.provider);
|
|
2254
|
+
_classPrivateFieldLooseBase(this, _tools)[_tools] = {};
|
|
2117
2255
|
}
|
|
2118
2256
|
/**
|
|
2119
2257
|
* Set the concrete tools for the agent
|
|
@@ -2122,6 +2260,7 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2122
2260
|
var _proto = Agent.prototype;
|
|
2123
2261
|
_proto.__setTools = function __setTools(tools) {
|
|
2124
2262
|
this.llm.__setTools(tools);
|
|
2263
|
+
_classPrivateFieldLooseBase(this, _tools)[_tools] = tools;
|
|
2125
2264
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.DEBUG, "Tools set for agent " + this.name);
|
|
2126
2265
|
}
|
|
2127
2266
|
/**
|
|
@@ -2132,6 +2271,10 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2132
2271
|
_classPrivateFieldLooseBase(this, _logger$1)[_logger$1] = logger;
|
|
2133
2272
|
this.llm.__setLogger(logger);
|
|
2134
2273
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.DEBUG, "Logger updated for agent " + this.name);
|
|
2274
|
+
};
|
|
2275
|
+
_proto.__setMemory = function __setMemory(memory) {
|
|
2276
|
+
this.memory = memory;
|
|
2277
|
+
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.DEBUG, "Memory set for agent " + this.name);
|
|
2135
2278
|
}
|
|
2136
2279
|
/**
|
|
2137
2280
|
* Set the telemetry for the agent
|
|
@@ -2142,17 +2285,445 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2142
2285
|
this.llm.__setTelemetry(_classPrivateFieldLooseBase(this, _telemetry$3)[_telemetry$3]);
|
|
2143
2286
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.DEBUG, "Telemetry updated for agent " + this.name);
|
|
2144
2287
|
};
|
|
2145
|
-
_proto.
|
|
2146
|
-
var
|
|
2147
|
-
var
|
|
2288
|
+
_proto.generateTitleFromUserMessage = /*#__PURE__*/function () {
|
|
2289
|
+
var _generateTitleFromUserMessage = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
2290
|
+
var message, _yield$this$llm$__tex, title;
|
|
2148
2291
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2149
2292
|
while (1) switch (_context.prev = _context.next) {
|
|
2150
2293
|
case 0:
|
|
2151
|
-
|
|
2294
|
+
message = _ref.message;
|
|
2295
|
+
_context.next = 3;
|
|
2296
|
+
return this.llm.__text({
|
|
2297
|
+
messages: [{
|
|
2298
|
+
role: 'system',
|
|
2299
|
+
content: "\n\n - you will generate a short title based on the first message a user begins a conversation with\n - ensure it is not more than 80 characters long\n - the title should be a summary of the user's message\n - do not use quotes or colons"
|
|
2300
|
+
}, {
|
|
2301
|
+
role: 'user',
|
|
2302
|
+
content: JSON.stringify(message)
|
|
2303
|
+
}]
|
|
2304
|
+
});
|
|
2305
|
+
case 3:
|
|
2306
|
+
_yield$this$llm$__tex = _context.sent;
|
|
2307
|
+
title = _yield$this$llm$__tex.text;
|
|
2308
|
+
return _context.abrupt("return", title);
|
|
2309
|
+
case 6:
|
|
2310
|
+
case "end":
|
|
2311
|
+
return _context.stop();
|
|
2312
|
+
}
|
|
2313
|
+
}, _callee, this);
|
|
2314
|
+
}));
|
|
2315
|
+
function generateTitleFromUserMessage(_x) {
|
|
2316
|
+
return _generateTitleFromUserMessage.apply(this, arguments);
|
|
2317
|
+
}
|
|
2318
|
+
return generateTitleFromUserMessage;
|
|
2319
|
+
}();
|
|
2320
|
+
_proto.getMostRecentUserMessage = function getMostRecentUserMessage(messages) {
|
|
2321
|
+
var userMessages = messages.filter(function (message) {
|
|
2322
|
+
return message.role === 'user';
|
|
2323
|
+
});
|
|
2324
|
+
return userMessages.at(-1);
|
|
2325
|
+
};
|
|
2326
|
+
_proto.genTitle = /*#__PURE__*/function () {
|
|
2327
|
+
var _genTitle = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(userMessage) {
|
|
2328
|
+
var title;
|
|
2329
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
2330
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
2331
|
+
case 0:
|
|
2332
|
+
title = 'New Thread';
|
|
2333
|
+
_context2.prev = 1;
|
|
2334
|
+
if (!userMessage) {
|
|
2335
|
+
_context2.next = 6;
|
|
2336
|
+
break;
|
|
2337
|
+
}
|
|
2338
|
+
_context2.next = 5;
|
|
2339
|
+
return this.generateTitleFromUserMessage({
|
|
2340
|
+
message: userMessage
|
|
2341
|
+
});
|
|
2342
|
+
case 5:
|
|
2343
|
+
title = _context2.sent;
|
|
2344
|
+
case 6:
|
|
2345
|
+
_context2.next = 11;
|
|
2346
|
+
break;
|
|
2347
|
+
case 8:
|
|
2348
|
+
_context2.prev = 8;
|
|
2349
|
+
_context2.t0 = _context2["catch"](1);
|
|
2350
|
+
console.error('Error generating title:', _context2.t0);
|
|
2351
|
+
case 11:
|
|
2352
|
+
return _context2.abrupt("return", title);
|
|
2353
|
+
case 12:
|
|
2354
|
+
case "end":
|
|
2355
|
+
return _context2.stop();
|
|
2356
|
+
}
|
|
2357
|
+
}, _callee2, this, [[1, 8]]);
|
|
2358
|
+
}));
|
|
2359
|
+
function genTitle(_x2) {
|
|
2360
|
+
return _genTitle.apply(this, arguments);
|
|
2361
|
+
}
|
|
2362
|
+
return genTitle;
|
|
2363
|
+
}();
|
|
2364
|
+
_proto.saveMemory = /*#__PURE__*/function () {
|
|
2365
|
+
var _saveMemory = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
|
|
2366
|
+
var _this = this;
|
|
2367
|
+
var threadId, resourceid, userMessages, userMessage, _thread, thread, title, _title, newMessages, _context$object, messages, contextCallMessages, context, memoryMessages, _context$object2, _context$object3, _context$object4, _context$object5, contextWindowMessages, _contextWindowMessages;
|
|
2368
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
2369
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
2370
|
+
case 0:
|
|
2371
|
+
threadId = _ref2.threadId, resourceid = _ref2.resourceid, userMessages = _ref2.userMessages;
|
|
2372
|
+
userMessage = this.getMostRecentUserMessage(userMessages);
|
|
2373
|
+
if (!this.memory) {
|
|
2374
|
+
_context3.next = 47;
|
|
2375
|
+
break;
|
|
2376
|
+
}
|
|
2377
|
+
console.log({
|
|
2378
|
+
threadId: threadId,
|
|
2379
|
+
resourceid: resourceid
|
|
2380
|
+
}, 'SAVING');
|
|
2381
|
+
if (threadId) {
|
|
2382
|
+
_context3.next = 13;
|
|
2383
|
+
break;
|
|
2384
|
+
}
|
|
2385
|
+
_context3.next = 7;
|
|
2386
|
+
return this.genTitle(userMessage);
|
|
2387
|
+
case 7:
|
|
2388
|
+
title = _context3.sent;
|
|
2389
|
+
_context3.next = 10;
|
|
2390
|
+
return this.memory.createThread({
|
|
2391
|
+
threadId: threadId,
|
|
2392
|
+
resourceid: resourceid,
|
|
2393
|
+
title: title
|
|
2394
|
+
});
|
|
2395
|
+
case 10:
|
|
2396
|
+
thread = _context3.sent;
|
|
2397
|
+
_context3.next = 23;
|
|
2398
|
+
break;
|
|
2399
|
+
case 13:
|
|
2400
|
+
_context3.next = 15;
|
|
2401
|
+
return this.memory.getThreadById({
|
|
2402
|
+
threadId: threadId
|
|
2403
|
+
});
|
|
2404
|
+
case 15:
|
|
2405
|
+
thread = _context3.sent;
|
|
2406
|
+
if (thread) {
|
|
2407
|
+
_context3.next = 23;
|
|
2408
|
+
break;
|
|
2409
|
+
}
|
|
2410
|
+
_context3.next = 19;
|
|
2411
|
+
return this.genTitle(userMessage);
|
|
2412
|
+
case 19:
|
|
2413
|
+
_title = _context3.sent;
|
|
2414
|
+
_context3.next = 22;
|
|
2415
|
+
return this.memory.createThread({
|
|
2416
|
+
threadId: threadId,
|
|
2417
|
+
resourceid: resourceid,
|
|
2418
|
+
title: _title
|
|
2419
|
+
});
|
|
2420
|
+
case 22:
|
|
2421
|
+
thread = _context3.sent;
|
|
2422
|
+
case 23:
|
|
2423
|
+
console.log({
|
|
2424
|
+
thread: thread
|
|
2425
|
+
});
|
|
2426
|
+
newMessages = userMessage ? [userMessage] : userMessages;
|
|
2427
|
+
if (!thread) {
|
|
2428
|
+
_context3.next = 46;
|
|
2429
|
+
break;
|
|
2430
|
+
}
|
|
2431
|
+
messages = newMessages.map(function (u) {
|
|
2432
|
+
var _this$memory;
|
|
2433
|
+
return _extends({
|
|
2434
|
+
id: (_this$memory = _this.memory) == null ? void 0 : _this$memory.generateId(),
|
|
2435
|
+
createdAt: new Date(),
|
|
2436
|
+
threadId: thread.id
|
|
2437
|
+
}, u, {
|
|
2438
|
+
content: u.content,
|
|
2439
|
+
role: u.role,
|
|
2440
|
+
type: 'text'
|
|
2441
|
+
});
|
|
2442
|
+
});
|
|
2443
|
+
contextCallMessages = [{
|
|
2444
|
+
role: 'system',
|
|
2445
|
+
content: "Analyze this message to determine if the user is referring to a previous conversation with the LLM. Specifically, identify if the user wants to reference specific information from that chat or if they want the LLM to use the previous chat messages as context for the current conversation. Extract any date ranges mentioned in the user message that could help identify the previous chat. Return dates in ISO format. If no specific dates are mentioned but time periods are (like \"last week\" or \"past month\"), calculate the appropriate date range. For the end date, return the date 1 day after the end of the time period. Today's date is " + new Date().toISOString()
|
|
2446
|
+
}].concat(newMessages);
|
|
2447
|
+
_context3.next = 30;
|
|
2448
|
+
return this.llm.__textObject({
|
|
2449
|
+
messages: contextCallMessages,
|
|
2450
|
+
structuredOutput: {
|
|
2451
|
+
usesContext: {
|
|
2452
|
+
type: 'boolean'
|
|
2453
|
+
},
|
|
2454
|
+
startDate: {
|
|
2455
|
+
type: 'date'
|
|
2456
|
+
},
|
|
2457
|
+
endDate: {
|
|
2458
|
+
type: 'date'
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
case 30:
|
|
2463
|
+
context = _context3.sent;
|
|
2464
|
+
console.log('context object===', JSON.stringify(context.object, null, 2));
|
|
2465
|
+
if (!((_context$object = context.object) != null && _context$object.usesContext)) {
|
|
2466
|
+
_context3.next = 39;
|
|
2467
|
+
break;
|
|
2468
|
+
}
|
|
2469
|
+
_context3.next = 35;
|
|
2470
|
+
return this.memory.getContextWindow({
|
|
2471
|
+
threadId: thread.id,
|
|
2472
|
+
startDate: (_context$object2 = context.object) != null && _context$object2.startDate ? new Date((_context$object3 = context.object) == null ? void 0 : _context$object3.startDate) : undefined,
|
|
2473
|
+
endDate: (_context$object4 = context.object) != null && _context$object4.endDate ? new Date((_context$object5 = context.object) == null ? void 0 : _context$object5.endDate) : undefined
|
|
2474
|
+
});
|
|
2475
|
+
case 35:
|
|
2476
|
+
contextWindowMessages = _context3.sent;
|
|
2477
|
+
memoryMessages = contextWindowMessages == null ? void 0 : contextWindowMessages.map(function (_ref3) {
|
|
2478
|
+
var role = _ref3.role,
|
|
2479
|
+
content = _ref3.content;
|
|
2480
|
+
return {
|
|
2481
|
+
role: role,
|
|
2482
|
+
content: content
|
|
2483
|
+
};
|
|
2484
|
+
});
|
|
2485
|
+
_context3.next = 43;
|
|
2486
|
+
break;
|
|
2487
|
+
case 39:
|
|
2488
|
+
_context3.next = 41;
|
|
2489
|
+
return this.memory.getContextWindow({
|
|
2490
|
+
threadId: thread.id
|
|
2491
|
+
});
|
|
2492
|
+
case 41:
|
|
2493
|
+
_contextWindowMessages = _context3.sent;
|
|
2494
|
+
memoryMessages = _contextWindowMessages == null ? void 0 : _contextWindowMessages.map(function (_ref4) {
|
|
2495
|
+
var role = _ref4.role,
|
|
2496
|
+
content = _ref4.content;
|
|
2497
|
+
return {
|
|
2498
|
+
role: role,
|
|
2499
|
+
content: content
|
|
2500
|
+
};
|
|
2501
|
+
});
|
|
2502
|
+
case 43:
|
|
2503
|
+
_context3.next = 45;
|
|
2504
|
+
return this.memory.saveMessages({
|
|
2505
|
+
messages: messages
|
|
2506
|
+
});
|
|
2507
|
+
case 45:
|
|
2508
|
+
return _context3.abrupt("return", {
|
|
2509
|
+
threadId: thread.id,
|
|
2510
|
+
messages: [].concat(memoryMessages, newMessages)
|
|
2511
|
+
});
|
|
2512
|
+
case 46:
|
|
2513
|
+
return _context3.abrupt("return", {
|
|
2514
|
+
threadId: ((_thread = thread) == null ? void 0 : _thread.id) || threadId || '',
|
|
2515
|
+
messages: userMessages
|
|
2516
|
+
});
|
|
2517
|
+
case 47:
|
|
2518
|
+
return _context3.abrupt("return", {
|
|
2519
|
+
threadId: threadId || '',
|
|
2520
|
+
messages: userMessages
|
|
2521
|
+
});
|
|
2522
|
+
case 48:
|
|
2523
|
+
case "end":
|
|
2524
|
+
return _context3.stop();
|
|
2525
|
+
}
|
|
2526
|
+
}, _callee3, this);
|
|
2527
|
+
}));
|
|
2528
|
+
function saveMemory(_x3) {
|
|
2529
|
+
return _saveMemory.apply(this, arguments);
|
|
2530
|
+
}
|
|
2531
|
+
return saveMemory;
|
|
2532
|
+
}();
|
|
2533
|
+
_proto.saveMemoryOnFinish = /*#__PURE__*/function () {
|
|
2534
|
+
var _saveMemoryOnFinish = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref5) {
|
|
2535
|
+
var result, threadId, _ref6, response, ms, responseMessagesWithoutIncompleteToolCalls;
|
|
2536
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
2537
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
2538
|
+
case 0:
|
|
2539
|
+
result = _ref5.result, threadId = _ref5.threadId;
|
|
2540
|
+
_ref6 = JSON.parse(result) || {}, response = _ref6.response;
|
|
2541
|
+
_context4.prev = 2;
|
|
2542
|
+
if (!response.messages) {
|
|
2543
|
+
_context4.next = 10;
|
|
2544
|
+
break;
|
|
2545
|
+
}
|
|
2546
|
+
ms = Array.isArray(response.messages) ? response.messages : [response.messages];
|
|
2547
|
+
responseMessagesWithoutIncompleteToolCalls = this.sanitizeResponseMessages(ms);
|
|
2548
|
+
if (!this.memory) {
|
|
2549
|
+
_context4.next = 10;
|
|
2550
|
+
break;
|
|
2551
|
+
}
|
|
2552
|
+
console.log('saving memory on finish====', {
|
|
2553
|
+
threadId: threadId
|
|
2554
|
+
});
|
|
2555
|
+
_context4.next = 10;
|
|
2556
|
+
return this.memory.saveMessages({
|
|
2557
|
+
messages: responseMessagesWithoutIncompleteToolCalls.map(function (message) {
|
|
2558
|
+
var _toolCallIds, _toolCallArgs, _toolNames;
|
|
2559
|
+
var messageId = crypto$1.randomUUID();
|
|
2560
|
+
var toolCallIds;
|
|
2561
|
+
var toolCallArgs;
|
|
2562
|
+
var toolNames;
|
|
2563
|
+
var type = 'text';
|
|
2564
|
+
if (message.role === 'tool') {
|
|
2565
|
+
toolCallIds = message.content.map(function (content) {
|
|
2566
|
+
return content.toolCallId;
|
|
2567
|
+
});
|
|
2568
|
+
type = 'tool-result';
|
|
2569
|
+
}
|
|
2570
|
+
if (message.role === 'assistant') {
|
|
2571
|
+
var _assistantContent$map, _assistantContent$;
|
|
2572
|
+
var assistantContent = message.content;
|
|
2573
|
+
var assistantToolCalls = (_assistantContent$map = assistantContent.map(function (content) {
|
|
2574
|
+
if (content.type === 'tool-call') {
|
|
2575
|
+
return {
|
|
2576
|
+
toolCallId: content.toolCallId,
|
|
2577
|
+
toolArgs: content.args,
|
|
2578
|
+
toolName: content.toolName
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
return undefined;
|
|
2582
|
+
})) == null ? void 0 : _assistantContent$map.filter(Boolean);
|
|
2583
|
+
toolCallIds = assistantToolCalls == null ? void 0 : assistantToolCalls.map(function (toolCall) {
|
|
2584
|
+
return toolCall.toolCallId;
|
|
2585
|
+
});
|
|
2586
|
+
toolCallArgs = assistantToolCalls == null ? void 0 : assistantToolCalls.map(function (toolCall) {
|
|
2587
|
+
return toolCall.toolArgs;
|
|
2588
|
+
});
|
|
2589
|
+
toolNames = assistantToolCalls == null ? void 0 : assistantToolCalls.map(function (toolCall) {
|
|
2590
|
+
return toolCall.toolName;
|
|
2591
|
+
});
|
|
2592
|
+
type = assistantContent == null || (_assistantContent$ = assistantContent[0]) == null ? void 0 : _assistantContent$.type;
|
|
2593
|
+
}
|
|
2594
|
+
return {
|
|
2595
|
+
id: messageId,
|
|
2596
|
+
threadId: threadId,
|
|
2597
|
+
role: message.role,
|
|
2598
|
+
content: message.content,
|
|
2599
|
+
createdAt: new Date(),
|
|
2600
|
+
toolCallIds: (_toolCallIds = toolCallIds) != null && _toolCallIds.length ? toolCallIds : undefined,
|
|
2601
|
+
toolCallArgs: (_toolCallArgs = toolCallArgs) != null && _toolCallArgs.length ? toolCallArgs : undefined,
|
|
2602
|
+
toolNames: (_toolNames = toolNames) != null && _toolNames.length ? toolNames : undefined,
|
|
2603
|
+
type: type
|
|
2604
|
+
};
|
|
2605
|
+
})
|
|
2606
|
+
});
|
|
2607
|
+
case 10:
|
|
2608
|
+
_context4.next = 15;
|
|
2609
|
+
break;
|
|
2610
|
+
case 12:
|
|
2611
|
+
_context4.prev = 12;
|
|
2612
|
+
_context4.t0 = _context4["catch"](2);
|
|
2613
|
+
console.error('Failed to save chat', _context4.t0);
|
|
2614
|
+
case 15:
|
|
2615
|
+
case "end":
|
|
2616
|
+
return _context4.stop();
|
|
2617
|
+
}
|
|
2618
|
+
}, _callee4, this, [[2, 12]]);
|
|
2619
|
+
}));
|
|
2620
|
+
function saveMemoryOnFinish(_x4) {
|
|
2621
|
+
return _saveMemoryOnFinish.apply(this, arguments);
|
|
2622
|
+
}
|
|
2623
|
+
return saveMemoryOnFinish;
|
|
2624
|
+
}();
|
|
2625
|
+
_proto.sanitizeResponseMessages = function sanitizeResponseMessages(messages) {
|
|
2626
|
+
var toolResultIds = [];
|
|
2627
|
+
for (var _iterator = _createForOfIteratorHelperLoose(messages), _step; !(_step = _iterator()).done;) {
|
|
2628
|
+
var message = _step.value;
|
|
2629
|
+
console.log(message);
|
|
2630
|
+
if (message.role === 'tool') {
|
|
2631
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(message.content), _step2; !(_step2 = _iterator2()).done;) {
|
|
2632
|
+
var content = _step2.value;
|
|
2633
|
+
if (content.type === 'tool-result') {
|
|
2634
|
+
toolResultIds.push(content.toolCallId);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
var messagesBySanitizedContent = messages.map(function (message) {
|
|
2640
|
+
if (message.role !== 'assistant') return message;
|
|
2641
|
+
if (typeof message.content === 'string') return message;
|
|
2642
|
+
var sanitizedContent = message.content.filter(function (content) {
|
|
2643
|
+
return content.type === 'tool-call' ? toolResultIds.includes(content.toolCallId) : content.type === 'text' ? content.text.length > 0 : true;
|
|
2644
|
+
});
|
|
2645
|
+
return _extends({}, message, {
|
|
2646
|
+
content: sanitizedContent
|
|
2647
|
+
});
|
|
2648
|
+
});
|
|
2649
|
+
return messagesBySanitizedContent.filter(function (message) {
|
|
2650
|
+
return message.content.length > 0;
|
|
2651
|
+
});
|
|
2652
|
+
};
|
|
2653
|
+
_proto.convertTools = function convertTools(_ref7) {
|
|
2654
|
+
var _this2 = this;
|
|
2655
|
+
var enabledTools = _ref7.enabledTools,
|
|
2656
|
+
threadId = _ref7.threadId,
|
|
2657
|
+
runId = _ref7.runId;
|
|
2658
|
+
var converted = Object.entries(enabledTools || {}).reduce(function (memo, value) {
|
|
2659
|
+
var k = value[0];
|
|
2660
|
+
var enabled = value[1];
|
|
2661
|
+
var tool = _classPrivateFieldLooseBase(_this2, _tools)[_tools][k];
|
|
2662
|
+
if (enabled && tool) {
|
|
2663
|
+
memo[k] = {
|
|
2664
|
+
description: tool.description,
|
|
2665
|
+
parameters: zod.z.object({
|
|
2666
|
+
data: tool.schema
|
|
2667
|
+
}),
|
|
2668
|
+
execute: function () {
|
|
2669
|
+
var _execute = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(args) {
|
|
2670
|
+
var _this2$memory, cachedResult;
|
|
2671
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
2672
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
2673
|
+
case 0:
|
|
2674
|
+
console.log('args====', JSON.stringify(args, null, 2));
|
|
2675
|
+
console.log('tool name====', k);
|
|
2676
|
+
if (!tool.enableCache) {
|
|
2677
|
+
_context5.next = 10;
|
|
2678
|
+
break;
|
|
2679
|
+
}
|
|
2680
|
+
console.log('cache enabled,checking cache');
|
|
2681
|
+
_context5.next = 6;
|
|
2682
|
+
return (_this2$memory = _this2.memory) == null ? void 0 : _this2$memory.getCachedToolResult({
|
|
2683
|
+
threadId: threadId,
|
|
2684
|
+
toolArgs: args,
|
|
2685
|
+
toolName: k
|
|
2686
|
+
});
|
|
2687
|
+
case 6:
|
|
2688
|
+
cachedResult = _context5.sent;
|
|
2689
|
+
if (!cachedResult) {
|
|
2690
|
+
_context5.next = 10;
|
|
2691
|
+
break;
|
|
2692
|
+
}
|
|
2693
|
+
console.log('cachedResult====', JSON.stringify(cachedResult, null, 2));
|
|
2694
|
+
return _context5.abrupt("return", cachedResult);
|
|
2695
|
+
case 10:
|
|
2696
|
+
console.log('cache not found or not enabled, executing tool');
|
|
2697
|
+
return _context5.abrupt("return", tool.executor(args));
|
|
2698
|
+
case 12:
|
|
2699
|
+
case "end":
|
|
2700
|
+
return _context5.stop();
|
|
2701
|
+
}
|
|
2702
|
+
}, _callee5);
|
|
2703
|
+
}));
|
|
2704
|
+
function execute(_x5) {
|
|
2705
|
+
return _execute.apply(this, arguments);
|
|
2706
|
+
}
|
|
2707
|
+
return execute;
|
|
2708
|
+
}()
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
return memo;
|
|
2712
|
+
}, {});
|
|
2713
|
+
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.DEBUG, "Converted tools for Agent " + this.name, runId);
|
|
2714
|
+
return converted;
|
|
2715
|
+
};
|
|
2716
|
+
_proto.text = /*#__PURE__*/function () {
|
|
2717
|
+
var _text = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref8) {
|
|
2718
|
+
var messages, onStepFinish, _ref8$maxSteps, maxSteps, threadId, resourceid, runId, systemMessage, userMessages, coreMessages, convertedTools, threadIdToUse, saveMessageResponse, messageObjects;
|
|
2719
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
2720
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
2721
|
+
case 0:
|
|
2722
|
+
messages = _ref8.messages, onStepFinish = _ref8.onStepFinish, _ref8$maxSteps = _ref8.maxSteps, maxSteps = _ref8$maxSteps === void 0 ? 5 : _ref8$maxSteps, threadId = _ref8.threadId, resourceid = _ref8.resourceid, runId = _ref8.runId;
|
|
2152
2723
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Starting text generation for agent " + this.name, runId);
|
|
2153
2724
|
systemMessage = {
|
|
2154
2725
|
role: 'system',
|
|
2155
|
-
content: this.instructions
|
|
2726
|
+
content: this.instructions + ". Today's date is " + new Date().toISOString()
|
|
2156
2727
|
};
|
|
2157
2728
|
userMessages = messages.map(function (content) {
|
|
2158
2729
|
return {
|
|
@@ -2160,37 +2731,61 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2160
2731
|
content: content
|
|
2161
2732
|
};
|
|
2162
2733
|
});
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2734
|
+
coreMessages = userMessages;
|
|
2735
|
+
threadIdToUse = threadId;
|
|
2736
|
+
if (!(this.memory && resourceid)) {
|
|
2737
|
+
_context6.next = 15;
|
|
2738
|
+
break;
|
|
2739
|
+
}
|
|
2740
|
+
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Saving user messages in memory for agent " + this.name, runId);
|
|
2741
|
+
_context6.next = 10;
|
|
2742
|
+
return this.saveMemory({
|
|
2743
|
+
threadId: threadIdToUse,
|
|
2744
|
+
resourceid: resourceid,
|
|
2745
|
+
userMessages: userMessages
|
|
2746
|
+
});
|
|
2747
|
+
case 10:
|
|
2748
|
+
saveMessageResponse = _context6.sent;
|
|
2749
|
+
coreMessages = saveMessageResponse.messages;
|
|
2750
|
+
threadIdToUse = saveMessageResponse.threadId;
|
|
2751
|
+
convertedTools = this.convertTools({
|
|
2752
|
+
enabledTools: this.enabledTools,
|
|
2753
|
+
threadId: threadIdToUse,
|
|
2754
|
+
runId: runId
|
|
2755
|
+
});
|
|
2756
|
+
console.log('convertedTools====', JSON.stringify(convertedTools, null, 2));
|
|
2757
|
+
case 15:
|
|
2758
|
+
messageObjects = [systemMessage].concat(coreMessages);
|
|
2759
|
+
return _context6.abrupt("return", this.llm.__text({
|
|
2166
2760
|
messages: messageObjects,
|
|
2167
2761
|
enabledTools: this.enabledTools,
|
|
2762
|
+
convertedTools: convertedTools,
|
|
2168
2763
|
onStepFinish: onStepFinish,
|
|
2169
2764
|
maxSteps: maxSteps,
|
|
2170
2765
|
runId: runId
|
|
2171
2766
|
}));
|
|
2172
|
-
case
|
|
2767
|
+
case 17:
|
|
2173
2768
|
case "end":
|
|
2174
|
-
return
|
|
2769
|
+
return _context6.stop();
|
|
2175
2770
|
}
|
|
2176
|
-
},
|
|
2771
|
+
}, _callee6, this);
|
|
2177
2772
|
}));
|
|
2178
|
-
function text(
|
|
2773
|
+
function text(_x6) {
|
|
2179
2774
|
return _text.apply(this, arguments);
|
|
2180
2775
|
}
|
|
2181
2776
|
return text;
|
|
2182
2777
|
}();
|
|
2183
2778
|
_proto.textObject = /*#__PURE__*/function () {
|
|
2184
|
-
var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2185
|
-
var messages, structuredOutput, onStepFinish,
|
|
2186
|
-
return _regeneratorRuntime().wrap(function
|
|
2187
|
-
while (1) switch (
|
|
2779
|
+
var _textObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref9) {
|
|
2780
|
+
var messages, structuredOutput, onStepFinish, _ref9$maxSteps, maxSteps, threadId, resourceid, runId, systemMessage, userMessages, coreMessages, convertedTools, threadIdToUse, saveMessageResponse, messageObjects;
|
|
2781
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
2782
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
2188
2783
|
case 0:
|
|
2189
|
-
messages =
|
|
2784
|
+
messages = _ref9.messages, structuredOutput = _ref9.structuredOutput, onStepFinish = _ref9.onStepFinish, _ref9$maxSteps = _ref9.maxSteps, maxSteps = _ref9$maxSteps === void 0 ? 5 : _ref9$maxSteps, threadId = _ref9.threadId, resourceid = _ref9.resourceid, runId = _ref9.runId;
|
|
2190
2785
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Starting text generation for agent " + this.name, runId);
|
|
2191
2786
|
systemMessage = {
|
|
2192
2787
|
role: 'system',
|
|
2193
|
-
content: this.instructions
|
|
2788
|
+
content: this.instructions + ". Today's date is " + new Date().toISOString()
|
|
2194
2789
|
};
|
|
2195
2790
|
userMessages = messages.map(function (content) {
|
|
2196
2791
|
return {
|
|
@@ -2198,38 +2793,63 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2198
2793
|
content: content
|
|
2199
2794
|
};
|
|
2200
2795
|
});
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2796
|
+
coreMessages = userMessages;
|
|
2797
|
+
threadIdToUse = threadId;
|
|
2798
|
+
if (!(this.memory && resourceid)) {
|
|
2799
|
+
_context7.next = 15;
|
|
2800
|
+
break;
|
|
2801
|
+
}
|
|
2802
|
+
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Saving user messages in memory for agent " + this.name, runId);
|
|
2803
|
+
_context7.next = 10;
|
|
2804
|
+
return this.saveMemory({
|
|
2805
|
+
threadId: threadIdToUse,
|
|
2806
|
+
resourceid: resourceid,
|
|
2807
|
+
userMessages: userMessages
|
|
2808
|
+
});
|
|
2809
|
+
case 10:
|
|
2810
|
+
saveMessageResponse = _context7.sent;
|
|
2811
|
+
coreMessages = saveMessageResponse.messages;
|
|
2812
|
+
threadIdToUse = saveMessageResponse.threadId;
|
|
2813
|
+
convertedTools = this.convertTools({
|
|
2814
|
+
enabledTools: this.enabledTools,
|
|
2815
|
+
threadId: threadIdToUse,
|
|
2816
|
+
runId: runId
|
|
2817
|
+
});
|
|
2818
|
+
console.log('convertedTools====', JSON.stringify(convertedTools, null, 2));
|
|
2819
|
+
case 15:
|
|
2820
|
+
messageObjects = [systemMessage].concat(coreMessages);
|
|
2821
|
+
return _context7.abrupt("return", this.llm.__textObject({
|
|
2204
2822
|
messages: messageObjects,
|
|
2205
2823
|
structuredOutput: structuredOutput,
|
|
2206
2824
|
enabledTools: this.enabledTools,
|
|
2825
|
+
convertedTools: convertedTools,
|
|
2207
2826
|
onStepFinish: onStepFinish,
|
|
2208
2827
|
maxSteps: maxSteps,
|
|
2209
2828
|
runId: runId
|
|
2210
2829
|
}));
|
|
2211
|
-
case
|
|
2830
|
+
case 17:
|
|
2212
2831
|
case "end":
|
|
2213
|
-
return
|
|
2832
|
+
return _context7.stop();
|
|
2214
2833
|
}
|
|
2215
|
-
},
|
|
2834
|
+
}, _callee7, this);
|
|
2216
2835
|
}));
|
|
2217
|
-
function textObject(
|
|
2836
|
+
function textObject(_x7) {
|
|
2218
2837
|
return _textObject.apply(this, arguments);
|
|
2219
2838
|
}
|
|
2220
2839
|
return textObject;
|
|
2221
2840
|
}();
|
|
2222
2841
|
_proto.stream = /*#__PURE__*/function () {
|
|
2223
|
-
var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2224
|
-
var
|
|
2225
|
-
|
|
2226
|
-
|
|
2842
|
+
var _stream = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref10) {
|
|
2843
|
+
var _this3 = this;
|
|
2844
|
+
var messages, onStepFinish, _onFinish, _ref10$maxSteps, maxSteps, threadId, resourceid, runId, systemMessage, userMessages, coreMessages, convertedTools, threadIdToUse, saveMessageResponse, messageObjects;
|
|
2845
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
2846
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
2227
2847
|
case 0:
|
|
2228
|
-
messages =
|
|
2848
|
+
messages = _ref10.messages, onStepFinish = _ref10.onStepFinish, _onFinish = _ref10.onFinish, _ref10$maxSteps = _ref10.maxSteps, maxSteps = _ref10$maxSteps === void 0 ? 5 : _ref10$maxSteps, threadId = _ref10.threadId, resourceid = _ref10.resourceid, runId = _ref10.runId;
|
|
2229
2849
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Starting stream generation for agent " + this.name, runId);
|
|
2230
2850
|
systemMessage = {
|
|
2231
2851
|
role: 'system',
|
|
2232
|
-
content: this.instructions
|
|
2852
|
+
content: this.instructions + ". Today's date is " + new Date().toISOString()
|
|
2233
2853
|
};
|
|
2234
2854
|
userMessages = messages.map(function (content) {
|
|
2235
2855
|
return {
|
|
@@ -2237,38 +2857,91 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2237
2857
|
content: content
|
|
2238
2858
|
};
|
|
2239
2859
|
});
|
|
2240
|
-
|
|
2241
|
-
|
|
2860
|
+
coreMessages = userMessages;
|
|
2861
|
+
threadIdToUse = threadId;
|
|
2862
|
+
if (!(this.memory && resourceid)) {
|
|
2863
|
+
_context9.next = 14;
|
|
2864
|
+
break;
|
|
2865
|
+
}
|
|
2866
|
+
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Saving user messages in memory for agent " + this.name, runId);
|
|
2867
|
+
_context9.next = 10;
|
|
2868
|
+
return this.saveMemory({
|
|
2869
|
+
threadId: threadIdToUse,
|
|
2870
|
+
resourceid: resourceid,
|
|
2871
|
+
userMessages: userMessages
|
|
2872
|
+
});
|
|
2873
|
+
case 10:
|
|
2874
|
+
saveMessageResponse = _context9.sent;
|
|
2875
|
+
coreMessages = saveMessageResponse.messages;
|
|
2876
|
+
threadIdToUse = saveMessageResponse.threadId;
|
|
2877
|
+
convertedTools = this.convertTools({
|
|
2878
|
+
enabledTools: this.enabledTools,
|
|
2879
|
+
threadId: threadIdToUse,
|
|
2880
|
+
runId: runId
|
|
2881
|
+
});
|
|
2882
|
+
case 14:
|
|
2883
|
+
messageObjects = [systemMessage].concat(coreMessages);
|
|
2884
|
+
console.log('start streaming in agent');
|
|
2885
|
+
return _context9.abrupt("return", this.llm.__stream({
|
|
2242
2886
|
messages: messageObjects,
|
|
2243
|
-
model: this.model,
|
|
2244
2887
|
enabledTools: this.enabledTools,
|
|
2888
|
+
convertedTools: convertedTools,
|
|
2245
2889
|
onStepFinish: onStepFinish,
|
|
2246
|
-
onFinish:
|
|
2890
|
+
onFinish: function () {
|
|
2891
|
+
var _onFinish2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(result) {
|
|
2892
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
2893
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
2894
|
+
case 0:
|
|
2895
|
+
console.log('onFinish====', result);
|
|
2896
|
+
if (!(_this3.memory && resourceid)) {
|
|
2897
|
+
_context8.next = 5;
|
|
2898
|
+
break;
|
|
2899
|
+
}
|
|
2900
|
+
_classPrivateFieldLooseBase(_this3, _log$1)[_log$1](LogLevel.INFO, "Saving assistant message in memory for agent " + _this3.name, runId);
|
|
2901
|
+
_context8.next = 5;
|
|
2902
|
+
return _this3.saveMemoryOnFinish({
|
|
2903
|
+
result: result,
|
|
2904
|
+
threadId: threadIdToUse
|
|
2905
|
+
});
|
|
2906
|
+
case 5:
|
|
2907
|
+
_onFinish == null || _onFinish(result);
|
|
2908
|
+
case 6:
|
|
2909
|
+
case "end":
|
|
2910
|
+
return _context8.stop();
|
|
2911
|
+
}
|
|
2912
|
+
}, _callee8);
|
|
2913
|
+
}));
|
|
2914
|
+
function onFinish(_x9) {
|
|
2915
|
+
return _onFinish2.apply(this, arguments);
|
|
2916
|
+
}
|
|
2917
|
+
return onFinish;
|
|
2918
|
+
}(),
|
|
2247
2919
|
maxSteps: maxSteps,
|
|
2248
2920
|
runId: runId
|
|
2249
2921
|
}));
|
|
2250
|
-
case
|
|
2922
|
+
case 17:
|
|
2251
2923
|
case "end":
|
|
2252
|
-
return
|
|
2924
|
+
return _context9.stop();
|
|
2253
2925
|
}
|
|
2254
|
-
},
|
|
2926
|
+
}, _callee9, this);
|
|
2255
2927
|
}));
|
|
2256
|
-
function stream(
|
|
2928
|
+
function stream(_x8) {
|
|
2257
2929
|
return _stream.apply(this, arguments);
|
|
2258
2930
|
}
|
|
2259
2931
|
return stream;
|
|
2260
2932
|
}();
|
|
2261
2933
|
_proto.streamObject = /*#__PURE__*/function () {
|
|
2262
|
-
var _streamObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2263
|
-
var
|
|
2264
|
-
|
|
2265
|
-
|
|
2934
|
+
var _streamObject = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref11) {
|
|
2935
|
+
var _this4 = this;
|
|
2936
|
+
var messages, structuredOutput, onStepFinish, _onFinish3, _ref11$maxSteps, maxSteps, threadId, resourceid, runId, systemMessage, userMessages, coreMessages, convertedTools, threadIdToUse, saveMessageResponse, messageObjects;
|
|
2937
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
2938
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
2266
2939
|
case 0:
|
|
2267
|
-
messages =
|
|
2940
|
+
messages = _ref11.messages, structuredOutput = _ref11.structuredOutput, onStepFinish = _ref11.onStepFinish, _onFinish3 = _ref11.onFinish, _ref11$maxSteps = _ref11.maxSteps, maxSteps = _ref11$maxSteps === void 0 ? 5 : _ref11$maxSteps, threadId = _ref11.threadId, resourceid = _ref11.resourceid, runId = _ref11.runId;
|
|
2268
2941
|
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Starting stream generation for agent " + this.name, runId);
|
|
2269
2942
|
systemMessage = {
|
|
2270
2943
|
role: 'system',
|
|
2271
|
-
content: this.instructions
|
|
2944
|
+
content: this.instructions + ". Today's date is " + new Date().toISOString()
|
|
2272
2945
|
};
|
|
2273
2946
|
userMessages = messages.map(function (content) {
|
|
2274
2947
|
return {
|
|
@@ -2276,24 +2949,75 @@ exports.Agent = (_logger$1 = /*#__PURE__*/_classPrivateFieldLooseKey("logger"),
|
|
|
2276
2949
|
content: content
|
|
2277
2950
|
};
|
|
2278
2951
|
});
|
|
2279
|
-
|
|
2280
|
-
|
|
2952
|
+
coreMessages = userMessages;
|
|
2953
|
+
threadIdToUse = threadId;
|
|
2954
|
+
if (!(this.memory && resourceid)) {
|
|
2955
|
+
_context11.next = 15;
|
|
2956
|
+
break;
|
|
2957
|
+
}
|
|
2958
|
+
_classPrivateFieldLooseBase(this, _log$1)[_log$1](LogLevel.INFO, "Saving user messages in memory for agent " + this.name, runId);
|
|
2959
|
+
_context11.next = 10;
|
|
2960
|
+
return this.saveMemory({
|
|
2961
|
+
threadId: threadIdToUse,
|
|
2962
|
+
resourceid: resourceid,
|
|
2963
|
+
userMessages: userMessages
|
|
2964
|
+
});
|
|
2965
|
+
case 10:
|
|
2966
|
+
saveMessageResponse = _context11.sent;
|
|
2967
|
+
coreMessages = saveMessageResponse.messages;
|
|
2968
|
+
threadIdToUse = saveMessageResponse.threadId;
|
|
2969
|
+
convertedTools = this.convertTools({
|
|
2970
|
+
enabledTools: this.enabledTools,
|
|
2971
|
+
threadId: threadIdToUse,
|
|
2972
|
+
runId: runId
|
|
2973
|
+
});
|
|
2974
|
+
console.log('convertedTools====', JSON.stringify(convertedTools, null, 2));
|
|
2975
|
+
case 15:
|
|
2976
|
+
messageObjects = [systemMessage].concat(coreMessages);
|
|
2977
|
+
return _context11.abrupt("return", this.llm.__streamObject({
|
|
2281
2978
|
messages: messageObjects,
|
|
2282
2979
|
structuredOutput: structuredOutput,
|
|
2283
|
-
model: this.model,
|
|
2284
2980
|
enabledTools: this.enabledTools,
|
|
2981
|
+
convertedTools: convertedTools,
|
|
2285
2982
|
onStepFinish: onStepFinish,
|
|
2286
|
-
onFinish:
|
|
2983
|
+
onFinish: function () {
|
|
2984
|
+
var _onFinish4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(result) {
|
|
2985
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
2986
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
2987
|
+
case 0:
|
|
2988
|
+
if (!(_this4.memory && resourceid)) {
|
|
2989
|
+
_context10.next = 4;
|
|
2990
|
+
break;
|
|
2991
|
+
}
|
|
2992
|
+
_classPrivateFieldLooseBase(_this4, _log$1)[_log$1](LogLevel.INFO, "Saving assistant message in memory for agent " + _this4.name, runId);
|
|
2993
|
+
_context10.next = 4;
|
|
2994
|
+
return _this4.saveMemoryOnFinish({
|
|
2995
|
+
result: result,
|
|
2996
|
+
threadId: threadIdToUse
|
|
2997
|
+
});
|
|
2998
|
+
case 4:
|
|
2999
|
+
_onFinish3 == null || _onFinish3(result);
|
|
3000
|
+
case 5:
|
|
3001
|
+
case "end":
|
|
3002
|
+
return _context10.stop();
|
|
3003
|
+
}
|
|
3004
|
+
}, _callee10);
|
|
3005
|
+
}));
|
|
3006
|
+
function onFinish(_x11) {
|
|
3007
|
+
return _onFinish4.apply(this, arguments);
|
|
3008
|
+
}
|
|
3009
|
+
return onFinish;
|
|
3010
|
+
}(),
|
|
2287
3011
|
maxSteps: maxSteps,
|
|
2288
3012
|
runId: runId
|
|
2289
3013
|
}));
|
|
2290
|
-
case
|
|
3014
|
+
case 17:
|
|
2291
3015
|
case "end":
|
|
2292
|
-
return
|
|
3016
|
+
return _context11.stop();
|
|
2293
3017
|
}
|
|
2294
|
-
},
|
|
3018
|
+
}, _callee11, this);
|
|
2295
3019
|
}));
|
|
2296
|
-
function streamObject(
|
|
3020
|
+
function streamObject(_x10) {
|
|
2297
3021
|
return _streamObject.apply(this, arguments);
|
|
2298
3022
|
}
|
|
2299
3023
|
return streamObject;
|
|
@@ -2527,11 +3251,11 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2527
3251
|
this.vectors = void 0;
|
|
2528
3252
|
this.tools = void 0;
|
|
2529
3253
|
this.agents = void 0;
|
|
2530
|
-
this.llm = void 0;
|
|
2531
3254
|
this.integrations = void 0;
|
|
2532
3255
|
this.logger = void 0;
|
|
2533
3256
|
this.syncs = void 0;
|
|
2534
3257
|
this.telemetry = void 0;
|
|
3258
|
+
this.memory = void 0;
|
|
2535
3259
|
/*
|
|
2536
3260
|
Logger
|
|
2537
3261
|
*/
|
|
@@ -2616,7 +3340,7 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2616
3340
|
};
|
|
2617
3341
|
},
|
|
2618
3342
|
agents: _this.agents,
|
|
2619
|
-
llm: _this.
|
|
3343
|
+
llm: _this.LLM,
|
|
2620
3344
|
engine: _this.engine,
|
|
2621
3345
|
vectors: _this.vectors
|
|
2622
3346
|
}));
|
|
@@ -2640,15 +3364,6 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2640
3364
|
}
|
|
2641
3365
|
this.syncs = config.syncs || {};
|
|
2642
3366
|
/*
|
|
2643
|
-
LLM
|
|
2644
|
-
*/
|
|
2645
|
-
this.llm = new LLM();
|
|
2646
|
-
this.llm.__setTools(this.tools);
|
|
2647
|
-
if (this.telemetry) {
|
|
2648
|
-
this.llm.__setTelemetry(this.telemetry);
|
|
2649
|
-
}
|
|
2650
|
-
this.llm.__setLogger(this.getLogger());
|
|
2651
|
-
/*
|
|
2652
3367
|
Agents
|
|
2653
3368
|
*/
|
|
2654
3369
|
this.agents = new Map();
|
|
@@ -2662,9 +3377,34 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2662
3377
|
agent.__setTelemetry(_this.telemetry);
|
|
2663
3378
|
}
|
|
2664
3379
|
agent.__setLogger(_this.getLogger());
|
|
3380
|
+
if (config.memory) {
|
|
3381
|
+
agent.__setMemory(config.memory);
|
|
3382
|
+
}
|
|
2665
3383
|
});
|
|
3384
|
+
if (config.syncs && !config.engine) {
|
|
3385
|
+
throw new Error('Engine is required to run syncs');
|
|
3386
|
+
}
|
|
3387
|
+
this.syncs = config.syncs || {};
|
|
3388
|
+
if (config.engine) {
|
|
3389
|
+
this.engine = config.engine;
|
|
3390
|
+
}
|
|
3391
|
+
if (config.vectors) {
|
|
3392
|
+
this.vectors = config.vectors;
|
|
3393
|
+
}
|
|
3394
|
+
this.memory = config.memory;
|
|
2666
3395
|
}
|
|
2667
3396
|
var _proto = Mastra.prototype;
|
|
3397
|
+
_proto.LLM = function LLM$1(modelConfig) {
|
|
3398
|
+
var llm = new LLM({
|
|
3399
|
+
model: modelConfig
|
|
3400
|
+
});
|
|
3401
|
+
llm.__setTools(this.tools);
|
|
3402
|
+
if (this.telemetry) {
|
|
3403
|
+
llm.__setTelemetry(this.telemetry);
|
|
3404
|
+
}
|
|
3405
|
+
llm.__setLogger(this.getLogger());
|
|
3406
|
+
return llm;
|
|
3407
|
+
};
|
|
2668
3408
|
_proto.sync = /*#__PURE__*/function () {
|
|
2669
3409
|
var _sync = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, params, runId) {
|
|
2670
3410
|
var _this$syncs,
|
|
@@ -2700,7 +3440,7 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2700
3440
|
engine: this.engine,
|
|
2701
3441
|
agents: this.agents,
|
|
2702
3442
|
vectors: this.vectors,
|
|
2703
|
-
llm: this.
|
|
3443
|
+
llm: this.LLM,
|
|
2704
3444
|
integrationsRegistry: function integrationsRegistry() {
|
|
2705
3445
|
return {
|
|
2706
3446
|
get: function get(name) {
|
|
@@ -2744,9 +3484,6 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2744
3484
|
}
|
|
2745
3485
|
return integration;
|
|
2746
3486
|
};
|
|
2747
|
-
_proto.getLLM = function getLLM() {
|
|
2748
|
-
return this.llm;
|
|
2749
|
-
};
|
|
2750
3487
|
_proto.getTool = function getTool(name) {
|
|
2751
3488
|
var _this3 = this;
|
|
2752
3489
|
var tools = this.tools;
|
|
@@ -2770,7 +3507,7 @@ exports.Mastra = /*#__PURE__*/function () {
|
|
|
2770
3507
|
};
|
|
2771
3508
|
},
|
|
2772
3509
|
agents: _this3.agents,
|
|
2773
|
-
llm: _this3.
|
|
3510
|
+
llm: _this3.LLM,
|
|
2774
3511
|
engine: _this3.engine,
|
|
2775
3512
|
vectors: _this3.vectors
|
|
2776
3513
|
}));
|
|
@@ -3712,26 +4449,30 @@ var MastraMemory = /*#__PURE__*/function () {
|
|
|
3712
4449
|
_proto.createThread =
|
|
3713
4450
|
/*#__PURE__*/
|
|
3714
4451
|
function () {
|
|
3715
|
-
var _createThread = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(
|
|
3716
|
-
var thread;
|
|
4452
|
+
var _createThread = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
4453
|
+
var threadId, resourceid, title, metadata, thread;
|
|
3717
4454
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3718
4455
|
while (1) switch (_context.prev = _context.next) {
|
|
3719
4456
|
case 0:
|
|
4457
|
+
threadId = _ref.threadId, resourceid = _ref.resourceid, title = _ref.title, metadata = _ref.metadata;
|
|
3720
4458
|
thread = {
|
|
3721
|
-
id: this.generateId(),
|
|
4459
|
+
id: threadId || this.generateId(),
|
|
3722
4460
|
title: title,
|
|
4461
|
+
resourceid: resourceid,
|
|
3723
4462
|
createdAt: new Date(),
|
|
3724
4463
|
updatedAt: new Date(),
|
|
3725
4464
|
metadata: metadata
|
|
3726
4465
|
};
|
|
3727
|
-
return _context.abrupt("return", this.saveThread(
|
|
3728
|
-
|
|
4466
|
+
return _context.abrupt("return", this.saveThread({
|
|
4467
|
+
thread: thread
|
|
4468
|
+
}));
|
|
4469
|
+
case 3:
|
|
3729
4470
|
case "end":
|
|
3730
4471
|
return _context.stop();
|
|
3731
4472
|
}
|
|
3732
4473
|
}, _callee, this);
|
|
3733
4474
|
}));
|
|
3734
|
-
function createThread(_x
|
|
4475
|
+
function createThread(_x) {
|
|
3735
4476
|
return _createThread.apply(this, arguments);
|
|
3736
4477
|
}
|
|
3737
4478
|
return createThread;
|
|
@@ -3741,36 +4482,47 @@ var MastraMemory = /*#__PURE__*/function () {
|
|
|
3741
4482
|
* @param threadId - The thread to add the message to
|
|
3742
4483
|
* @param content - The message content
|
|
3743
4484
|
* @param role - The role of the message sender
|
|
4485
|
+
* @param type - The type of the message
|
|
4486
|
+
* @param toolNames - Optional array of tool names that were called
|
|
4487
|
+
* @param toolCallArgs - Optional array of tool call arguments
|
|
4488
|
+
* @param toolCallIds - Optional array of tool call ids
|
|
3744
4489
|
* @returns Promise resolving to the saved message
|
|
3745
4490
|
*/
|
|
3746
4491
|
;
|
|
3747
4492
|
_proto.addMessage =
|
|
3748
4493
|
/*#__PURE__*/
|
|
3749
4494
|
function () {
|
|
3750
|
-
var _addMessage = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(
|
|
3751
|
-
var message, savedMessages;
|
|
4495
|
+
var _addMessage = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
4496
|
+
var threadId, content, role, type, toolNames, toolCallArgs, toolCallIds, message, savedMessages;
|
|
3752
4497
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3753
4498
|
while (1) switch (_context2.prev = _context2.next) {
|
|
3754
4499
|
case 0:
|
|
4500
|
+
threadId = _ref2.threadId, content = _ref2.content, role = _ref2.role, type = _ref2.type, toolNames = _ref2.toolNames, toolCallArgs = _ref2.toolCallArgs, toolCallIds = _ref2.toolCallIds;
|
|
3755
4501
|
message = {
|
|
3756
4502
|
id: this.generateId(),
|
|
3757
4503
|
content: content,
|
|
3758
4504
|
role: role,
|
|
3759
4505
|
createdAt: new Date(),
|
|
3760
|
-
threadId: threadId
|
|
4506
|
+
threadId: threadId,
|
|
4507
|
+
type: type,
|
|
4508
|
+
toolNames: toolNames,
|
|
4509
|
+
toolCallArgs: toolCallArgs,
|
|
4510
|
+
toolCallIds: toolCallIds
|
|
3761
4511
|
};
|
|
3762
|
-
_context2.next =
|
|
3763
|
-
return this.saveMessages(
|
|
3764
|
-
|
|
4512
|
+
_context2.next = 4;
|
|
4513
|
+
return this.saveMessages({
|
|
4514
|
+
messages: [message]
|
|
4515
|
+
});
|
|
4516
|
+
case 4:
|
|
3765
4517
|
savedMessages = _context2.sent;
|
|
3766
4518
|
return _context2.abrupt("return", savedMessages[0]);
|
|
3767
|
-
case
|
|
4519
|
+
case 6:
|
|
3768
4520
|
case "end":
|
|
3769
4521
|
return _context2.stop();
|
|
3770
4522
|
}
|
|
3771
4523
|
}, _callee2, this);
|
|
3772
4524
|
}));
|
|
3773
|
-
function addMessage(
|
|
4525
|
+
function addMessage(_x2) {
|
|
3774
4526
|
return _addMessage.apply(this, arguments);
|
|
3775
4527
|
}
|
|
3776
4528
|
return addMessage;
|