@mastra/core 0.1.27-alpha.21 → 0.1.27-alpha.23

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