supercompat 3.9.5 → 3.10.1

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/index.cjs CHANGED
@@ -211,7 +211,7 @@ function _unsupported_iterable_to_array(o, minLen) {
211
211
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
212
212
  }
213
213
  function _ts_generator(thisArg, body) {
214
- var f, y, t, g, _ = {
214
+ var f, y, t, _ = {
215
215
  label: 0,
216
216
  sent: function() {
217
217
  if (t[0] & 1) throw t[1];
@@ -219,12 +219,8 @@ function _ts_generator(thisArg, body) {
219
219
  },
220
220
  trys: [],
221
221
  ops: []
222
- };
223
- return g = {
224
- next: verb(0),
225
- "throw": verb(1),
226
- "return": verb(2)
227
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
222
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
223
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
228
224
  return this;
229
225
  }), g;
230
226
  function verb(n) {
@@ -237,7 +233,7 @@ function _ts_generator(thisArg, body) {
237
233
  }
238
234
  function step(op) {
239
235
  if (f) throw new TypeError("Generator is already executing.");
240
- while(_)try {
236
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
241
237
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
242
238
  if (y = 0, t) op = [
243
239
  op[0] & 2,
@@ -468,13 +464,13 @@ var findRequestHandler = function(param) {
468
464
  }
469
465
  };
470
466
  // src/supercompatFetch/originalFetch.ts
471
- var originalFetch = /*#__PURE__*/ function() {
472
- var _ref = _async_to_generator(function(param) {
473
- var args, client, _client_client, _args, url, options, clientHeaders, newOptions;
467
+ var originalFetch = function(param) {
468
+ var args = param.args, client = param.client;
469
+ return _async_to_generator(function() {
470
+ var _client_client, _args, url, options, clientHeaders, newOptions;
474
471
  return _ts_generator(this, function(_state) {
475
472
  switch(_state.label){
476
473
  case 0:
477
- args = param.args, client = param.client;
478
474
  if (!((_client_client = client.client) === null || _client_client === void 0 ? void 0 : _client_client.fetch)) return [
479
475
  3,
480
476
  2
@@ -510,11 +506,8 @@ var originalFetch = /*#__PURE__*/ function() {
510
506
  ];
511
507
  }
512
508
  });
513
- });
514
- return function originalFetch(_) {
515
- return _ref.apply(this, arguments);
516
- };
517
- }();
509
+ })();
510
+ };
518
511
  // src/supercompatFetch/index.ts
519
512
  var supercompatFetch = function(param) {
520
513
  var client = param.client, storage = param.storage, runAdapter = param.runAdapter;
@@ -523,44 +516,45 @@ var supercompatFetch = function(param) {
523
516
  storage: storage,
524
517
  runAdapter: runAdapter
525
518
  });
526
- return /*#__PURE__*/ _async_to_generator(function() {
527
- var _len, args, _key, _args, url, options, pathHandler, _options_method, method, requestHandler;
528
- var _arguments = arguments;
529
- return _ts_generator(this, function(_state) {
530
- for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
531
- args[_key] = _arguments[_key];
532
- }
533
- _args = _sliced_to_array(args, 2), url = _args[0], options = _args[1];
534
- pathHandler = findRequestHandler({
535
- url: url,
536
- requestHandlers: requestHandlers2
537
- });
538
- if (!pathHandler) {
539
- return [
540
- 2,
541
- originalFetch({
542
- client: client,
543
- args: args
544
- })
545
- ];
546
- }
547
- method = (_options_method = options === null || options === void 0 ? void 0 : options.method) !== null && _options_method !== void 0 ? _options_method : "";
548
- requestHandler = pathHandler[method.toLowerCase()];
549
- if (!requestHandler) {
519
+ return function() {
520
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
521
+ args[_key] = arguments[_key];
522
+ }
523
+ return _async_to_generator(function() {
524
+ var _args, url, options, pathHandler, _options_method, method, requestHandler;
525
+ return _ts_generator(this, function(_state) {
526
+ _args = _sliced_to_array(args, 2), url = _args[0], options = _args[1];
527
+ pathHandler = findRequestHandler({
528
+ url: url,
529
+ requestHandlers: requestHandlers2
530
+ });
531
+ if (!pathHandler) {
532
+ return [
533
+ 2,
534
+ originalFetch({
535
+ client: client,
536
+ args: args
537
+ })
538
+ ];
539
+ }
540
+ method = (_options_method = options === null || options === void 0 ? void 0 : options.method) !== null && _options_method !== void 0 ? _options_method : "";
541
+ requestHandler = pathHandler[method.toLowerCase()];
542
+ if (!requestHandler) {
543
+ return [
544
+ 2,
545
+ originalFetch({
546
+ client: client,
547
+ args: args
548
+ })
549
+ ];
550
+ }
550
551
  return [
551
552
  2,
552
- originalFetch({
553
- client: client,
554
- args: args
555
- })
553
+ requestHandler.apply(void 0, _to_consumable_array(args))
556
554
  ];
557
- }
558
- return [
559
- 2,
560
- requestHandler.apply(void 0, _to_consumable_array(args))
561
- ];
562
- });
563
- });
555
+ });
556
+ })();
557
+ };
564
558
  };
565
559
  // src/lib/azureOpenai/endpointFromBaseUrl.ts
566
560
  var endpointFromBaseUrl = function(param) {
@@ -596,8 +590,8 @@ var supercompat = function(param) {
596
590
  // src/adapters/client/groqClientAdapter/models/get.ts
597
591
  var get = function(param) {
598
592
  var groq = param.groq;
599
- return /*#__PURE__*/ function() {
600
- var _ref = _async_to_generator(function(_url, _options) {
593
+ return function(_url, _options) {
594
+ return _async_to_generator(function() {
601
595
  var data, error;
602
596
  return _ts_generator(this, function(_state) {
603
597
  switch(_state.label){
@@ -642,11 +636,8 @@ var get = function(param) {
642
636
  ];
643
637
  }
644
638
  });
645
- });
646
- return function(_url, _options) {
647
- return _ref.apply(this, arguments);
648
- };
649
- }();
639
+ })();
640
+ };
650
641
  };
651
642
  // src/adapters/client/groqClientAdapter/models/index.ts
652
643
  var models = function(param) {
@@ -660,8 +651,8 @@ var models = function(param) {
660
651
  // src/adapters/client/groqClientAdapter/completions/post.ts
661
652
  var post = function(param) {
662
653
  var groq = param.groq;
663
- return /*#__PURE__*/ function() {
664
- var _ref = _async_to_generator(function(_url, options) {
654
+ return function(_url, options) {
655
+ return _async_to_generator(function() {
665
656
  var body, response, stream, data, error;
666
657
  return _ts_generator(this, function(_state) {
667
658
  switch(_state.label){
@@ -823,11 +814,8 @@ var post = function(param) {
823
814
  ];
824
815
  }
825
816
  });
826
- });
827
- return function(_url, options) {
828
- return _ref.apply(this, arguments);
829
- };
830
- }();
817
+ })();
818
+ };
831
819
  };
832
820
  // src/adapters/client/groqClientAdapter/completions/index.ts
833
821
  var completions = function(param) {
@@ -856,8 +844,8 @@ var groqClientAdapter = function(param) {
856
844
  // src/adapters/client/openaiClientAdapter/models/get.ts
857
845
  var get2 = function(param) {
858
846
  var openai = param.openai;
859
- return /*#__PURE__*/ function() {
860
- var _ref = _async_to_generator(function(_url, _options) {
847
+ return function(_url, _options) {
848
+ return _async_to_generator(function() {
861
849
  var data, error;
862
850
  return _ts_generator(this, function(_state) {
863
851
  switch(_state.label){
@@ -902,11 +890,8 @@ var get2 = function(param) {
902
890
  ];
903
891
  }
904
892
  });
905
- });
906
- return function(_url, _options) {
907
- return _ref.apply(this, arguments);
908
- };
909
- }();
893
+ })();
894
+ };
910
895
  };
911
896
  // src/adapters/client/openaiClientAdapter/models/index.ts
912
897
  var models2 = function(param) {
@@ -957,8 +942,8 @@ var omitKeys = function(param) {
957
942
  };
958
943
  var post2 = function(param) {
959
944
  var openai = param.openai;
960
- return /*#__PURE__*/ function() {
961
- var _ref = _async_to_generator(function(_url, options) {
945
+ return function(_url, options) {
946
+ return _async_to_generator(function() {
962
947
  var body, messages4, resultOptions, response, stream, data, error;
963
948
  return _ts_generator(this, function(_state) {
964
949
  switch(_state.label){
@@ -1129,11 +1114,8 @@ var post2 = function(param) {
1129
1114
  ];
1130
1115
  }
1131
1116
  });
1132
- });
1133
- return function(_url, options) {
1134
- return _ref.apply(this, arguments);
1135
- };
1136
- }();
1117
+ })();
1118
+ };
1137
1119
  };
1138
1120
  // src/adapters/client/openaiClientAdapter/completions/index.ts
1139
1121
  var completions2 = function(param) {
@@ -1175,8 +1157,8 @@ var azureOpenaiClientAdapter = function(param) {
1175
1157
  // src/adapters/client/mistralClientAdapter/models/get.ts
1176
1158
  var get3 = function(param) {
1177
1159
  var mistral = param.mistral;
1178
- return /*#__PURE__*/ function() {
1179
- var _ref = _async_to_generator(function(_url, _options) {
1160
+ return function(_url, _options) {
1161
+ return _async_to_generator(function() {
1180
1162
  var data, error;
1181
1163
  return _ts_generator(this, function(_state) {
1182
1164
  switch(_state.label){
@@ -1221,11 +1203,8 @@ var get3 = function(param) {
1221
1203
  ];
1222
1204
  }
1223
1205
  });
1224
- });
1225
- return function(_url, _options) {
1226
- return _ref.apply(this, arguments);
1227
- };
1228
- }();
1206
+ })();
1207
+ };
1229
1208
  };
1230
1209
  // src/adapters/client/mistralClientAdapter/models/index.ts
1231
1210
  var models3 = function(param) {
@@ -1294,8 +1273,8 @@ var serializeBody = function(param) {
1294
1273
  // src/adapters/client/mistralClientAdapter/completions/post.ts
1295
1274
  var post3 = function(param) {
1296
1275
  var mistral = param.mistral;
1297
- return /*#__PURE__*/ function() {
1298
- var _ref = _async_to_generator(function(_url, options) {
1276
+ return function(_url, options) {
1277
+ return _async_to_generator(function() {
1299
1278
  var body, serializedBody, response, stream, data, error;
1300
1279
  return _ts_generator(this, function(_state) {
1301
1280
  switch(_state.label){
@@ -1463,11 +1442,8 @@ var post3 = function(param) {
1463
1442
  ];
1464
1443
  }
1465
1444
  });
1466
- });
1467
- return function(_url, options) {
1468
- return _ref.apply(this, arguments);
1469
- };
1470
- }();
1445
+ })();
1446
+ };
1471
1447
  };
1472
1448
  // src/adapters/client/mistralClientAdapter/completions/index.ts
1473
1449
  var completions3 = function(param) {
@@ -1506,8 +1482,8 @@ var models4 = [
1506
1482
  ];
1507
1483
  var get4 = function(param) {
1508
1484
  var perplexity = param.perplexity;
1509
- return /*#__PURE__*/ function() {
1510
- var _ref = _async_to_generator(function(_url, _options) {
1485
+ return function(_url, _options) {
1486
+ return _async_to_generator(function() {
1511
1487
  return _ts_generator(this, function(_state) {
1512
1488
  try {
1513
1489
  return [
@@ -1544,11 +1520,8 @@ var get4 = function(param) {
1544
1520
  2
1545
1521
  ];
1546
1522
  });
1547
- });
1548
- return function(_url, _options) {
1549
- return _ref.apply(this, arguments);
1550
- };
1551
- }();
1523
+ })();
1524
+ };
1552
1525
  };
1553
1526
  // src/adapters/client/perplexityClientAdapter/models/index.ts
1554
1527
  var models5 = function(param) {
@@ -1588,8 +1561,8 @@ var alternatingMessages = function(param) {
1588
1561
  // src/adapters/client/perplexityClientAdapter/completions/post.ts
1589
1562
  var post4 = function(param) {
1590
1563
  var perplexity = param.perplexity;
1591
- return /*#__PURE__*/ function() {
1592
- var _ref = _async_to_generator(function(_url, options) {
1564
+ return function(_url, options) {
1565
+ return _async_to_generator(function() {
1593
1566
  var body, messages4, response, stream, data, error;
1594
1567
  return _ts_generator(this, function(_state) {
1595
1568
  switch(_state.label){
@@ -1756,11 +1729,8 @@ var post4 = function(param) {
1756
1729
  ];
1757
1730
  }
1758
1731
  });
1759
- });
1760
- return function(_url, options) {
1761
- return _ref.apply(this, arguments);
1762
- };
1763
- }();
1732
+ })();
1733
+ };
1764
1734
  };
1765
1735
  // src/adapters/client/perplexityClientAdapter/completions/index.ts
1766
1736
  var completions4 = function(param) {
@@ -1789,8 +1759,8 @@ var perplexityClientAdapter = function(param) {
1789
1759
  // src/adapters/client/anthropicClientAdapter/models/get.ts
1790
1760
  var get5 = function(param) {
1791
1761
  var anthropic = param.anthropic;
1792
- return /*#__PURE__*/ function() {
1793
- var _ref = _async_to_generator(function(_url, _options) {
1762
+ return function(_url, _options) {
1763
+ return _async_to_generator(function() {
1794
1764
  var response, error;
1795
1765
  return _ts_generator(this, function(_state) {
1796
1766
  switch(_state.label){
@@ -1843,11 +1813,8 @@ var get5 = function(param) {
1843
1813
  ];
1844
1814
  }
1845
1815
  });
1846
- });
1847
- return function(_url, _options) {
1848
- return _ref.apply(this, arguments);
1849
- };
1850
- }();
1816
+ })();
1817
+ };
1851
1818
  };
1852
1819
  // src/adapters/client/anthropicClientAdapter/models/index.ts
1853
1820
  var models6 = function(param) {
@@ -1859,7 +1826,7 @@ var models6 = function(param) {
1859
1826
  };
1860
1827
  };
1861
1828
  // src/adapters/client/anthropicClientAdapter/completions/post.ts
1862
- var import_radash3 = require("radash");
1829
+ var import_radash4 = require("radash");
1863
1830
  // src/lib/messages/nonEmptyMessages.ts
1864
1831
  var nonEmptyContent = function(param) {
1865
1832
  var message = param.message;
@@ -1914,12 +1881,24 @@ var serializeTools = function(param) {
1914
1881
  }
1915
1882
  };
1916
1883
  }
1917
- return tool;
1884
+ return _object_spread({
1885
+ type: tool.type
1886
+ }, tool[tool.type] || {});
1918
1887
  });
1919
1888
  };
1920
1889
  // src/adapters/client/anthropicClientAdapter/completions/serializeMessages/serializeMessage.ts
1921
1890
  var serializeMessage2 = function(param) {
1922
1891
  var message = param.message;
1892
+ var parseArguments = function(value) {
1893
+ if (typeof value !== "string") return {};
1894
+ var trimmed = value.trim();
1895
+ if (!trimmed) return {};
1896
+ try {
1897
+ return JSON.parse(trimmed);
1898
+ } catch (e) {
1899
+ return {};
1900
+ }
1901
+ };
1923
1902
  if (message.role === "user") {
1924
1903
  return {
1925
1904
  role: "user",
@@ -1941,7 +1920,7 @@ var serializeMessage2 = function(param) {
1941
1920
  // @ts-expect-error todo
1942
1921
  name: toolCall.function.name,
1943
1922
  // @ts-expect-error todo
1944
- input: toolCall.function.arguments ? JSON.parse(toolCall.function.arguments) : {}
1923
+ input: parseArguments(toolCall.function.arguments)
1945
1924
  };
1946
1925
  })))
1947
1926
  };
@@ -1967,18 +1946,485 @@ var serializeMessages = function(param) {
1967
1946
  });
1968
1947
  });
1969
1948
  };
1949
+ // src/adapters/client/anthropicClientAdapter/completions/serializeBetas.ts
1950
+ var serializeBetas = function(param) {
1951
+ var _param_tools = param.tools, tools = _param_tools === void 0 ? [] : _param_tools;
1952
+ var betas = [];
1953
+ if (tools.some(function(tool) {
1954
+ return tool.type === "computer_20250124";
1955
+ })) {
1956
+ betas.push("computer-use-2025-01-24");
1957
+ }
1958
+ if (tools.some(function(tool) {
1959
+ return tool.type === "code_execution_20250825";
1960
+ })) {
1961
+ betas.push("code-execution-2025-08-25");
1962
+ }
1963
+ if (!betas.length) {
1964
+ return {};
1965
+ }
1966
+ return {
1967
+ betas: betas
1968
+ };
1969
+ };
1970
+ // src/adapters/client/anthropicClientAdapter/normalizeComputerToolCallPayload.ts
1971
+ var import_radash3 = require("radash");
1972
+ var coordinateKeys = [
1973
+ "coordinate",
1974
+ "coordinates",
1975
+ "coordinate_start",
1976
+ "coordinate_end",
1977
+ "start",
1978
+ "end",
1979
+ "from",
1980
+ "to",
1981
+ "target",
1982
+ "point",
1983
+ "position",
1984
+ "cursor_position",
1985
+ "path"
1986
+ ];
1987
+ var clickButtonMap = {
1988
+ left_click: "left",
1989
+ right_click: "right",
1990
+ middle_click: "wheel",
1991
+ double_click: "left",
1992
+ triple_click: "left",
1993
+ left_mouse_down: "left",
1994
+ left_mouse_up: "left"
1995
+ };
1996
+ var keyAliasMap = {
1997
+ ctrl: "ctrl",
1998
+ control: "ctrl",
1999
+ cmd: "meta",
2000
+ command: "meta",
2001
+ meta: "meta",
2002
+ win: "meta",
2003
+ option: "alt",
2004
+ alt: "alt",
2005
+ shift: "shift",
2006
+ enter: "enter",
2007
+ return: "enter",
2008
+ esc: "escape",
2009
+ escape: "escape",
2010
+ tab: "tab",
2011
+ space: "space",
2012
+ spacebar: "space",
2013
+ backspace: "backspace",
2014
+ del: "delete",
2015
+ delete: "delete",
2016
+ pageup: "pageup",
2017
+ pagedown: "pagedown",
2018
+ up: "up",
2019
+ down: "down",
2020
+ left: "left",
2021
+ right: "right"
2022
+ };
2023
+ var sanitizeNumber = function(value) {
2024
+ return typeof value === "number" ? value : void 0;
2025
+ };
2026
+ var toCoordinate = function(value) {
2027
+ if (!value) return void 0;
2028
+ if (Array.isArray(value)) {
2029
+ if (value.length === 2 && typeof value[0] === "number" && typeof value[1] === "number") {
2030
+ return {
2031
+ x: value[0],
2032
+ y: value[1]
2033
+ };
2034
+ }
2035
+ if (value.length > 0 && Array.isArray(value[0])) {
2036
+ var tuple = value[0];
2037
+ if (tuple.length === 2 && typeof tuple[0] === "number" && typeof tuple[1] === "number") {
2038
+ return {
2039
+ x: tuple[0],
2040
+ y: tuple[1]
2041
+ };
2042
+ }
2043
+ }
2044
+ }
2045
+ if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
2046
+ var maybe = value;
2047
+ var x = sanitizeNumber(maybe.x);
2048
+ var y = sanitizeNumber(maybe.y);
2049
+ if (typeof x === "number" && typeof y === "number") {
2050
+ return {
2051
+ x: x,
2052
+ y: y
2053
+ };
2054
+ }
2055
+ }
2056
+ if (typeof value === "string") {
2057
+ var parts = value.split(/[, ]+/).map(Number).filter(Number.isFinite);
2058
+ if (parts.length >= 2) {
2059
+ return {
2060
+ x: parts[0],
2061
+ y: parts[1]
2062
+ };
2063
+ }
2064
+ }
2065
+ return void 0;
2066
+ };
2067
+ var findCoordinatesInDetails = function(details) {
2068
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2069
+ try {
2070
+ for(var _iterator = coordinateKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2071
+ var key = _step.value;
2072
+ var value = details[key];
2073
+ var coords = toCoordinate(value);
2074
+ if (coords) {
2075
+ return coords;
2076
+ }
2077
+ }
2078
+ } catch (err) {
2079
+ _didIteratorError = true;
2080
+ _iteratorError = err;
2081
+ } finally{
2082
+ try {
2083
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2084
+ _iterator.return();
2085
+ }
2086
+ } finally{
2087
+ if (_didIteratorError) {
2088
+ throw _iteratorError;
2089
+ }
2090
+ }
2091
+ }
2092
+ return void 0;
2093
+ };
2094
+ var buildDragPath = function(details) {
2095
+ var path = [];
2096
+ if (Array.isArray(details.path)) {
2097
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2098
+ try {
2099
+ for(var _iterator = details.path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2100
+ var point = _step.value;
2101
+ var coords = toCoordinate(point);
2102
+ if (coords) {
2103
+ path.push(coords);
2104
+ }
2105
+ }
2106
+ } catch (err) {
2107
+ _didIteratorError = true;
2108
+ _iteratorError = err;
2109
+ } finally{
2110
+ try {
2111
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2112
+ _iterator.return();
2113
+ }
2114
+ } finally{
2115
+ if (_didIteratorError) {
2116
+ throw _iteratorError;
2117
+ }
2118
+ }
2119
+ }
2120
+ }
2121
+ if (!path.length) {
2122
+ var start = toCoordinate(details.coordinate_start) || toCoordinate(details.start) || toCoordinate(details.from);
2123
+ if (start) {
2124
+ path.push(start);
2125
+ }
2126
+ var end = toCoordinate(details.coordinate_end) || toCoordinate(details.end) || toCoordinate(details.to) || toCoordinate(details.target);
2127
+ if (end) {
2128
+ path.push(end);
2129
+ }
2130
+ }
2131
+ if (!path.length) {
2132
+ var coords1 = findCoordinatesInDetails(details);
2133
+ if (coords1) {
2134
+ path.push(coords1);
2135
+ }
2136
+ }
2137
+ if (!path.length) {
2138
+ path.push({
2139
+ x: 0,
2140
+ y: 0
2141
+ });
2142
+ }
2143
+ return path;
2144
+ };
2145
+ var parseKeys = function(input) {
2146
+ if (Array.isArray(input)) {
2147
+ return input.map(String).map(function(key) {
2148
+ return key.trim();
2149
+ }).filter(Boolean);
2150
+ }
2151
+ if (typeof input === "string") {
2152
+ return input.split(RegExp("(?:(?<!\\\\)\\+|\\s+)")).map(function(key) {
2153
+ return key.replace(/\\\+/g, "+");
2154
+ }).map(function(key) {
2155
+ return key.trim();
2156
+ }).filter(Boolean);
2157
+ }
2158
+ return [];
2159
+ };
2160
+ var normalizeKeys = function(keys) {
2161
+ return keys.map(function(key) {
2162
+ var lowerKey = key.toLowerCase();
2163
+ var _keyAliasMap_lowerKey;
2164
+ return (_keyAliasMap_lowerKey = keyAliasMap[lowerKey]) !== null && _keyAliasMap_lowerKey !== void 0 ? _keyAliasMap_lowerKey : lowerKey;
2165
+ });
2166
+ };
2167
+ var normalizeScroll = function(details) {
2168
+ var _sanitizeNumber;
2169
+ var scrollX = (_sanitizeNumber = sanitizeNumber(details.scroll_x)) !== null && _sanitizeNumber !== void 0 ? _sanitizeNumber : 0;
2170
+ var _sanitizeNumber1;
2171
+ var scrollY = (_sanitizeNumber1 = sanitizeNumber(details.scroll_y)) !== null && _sanitizeNumber1 !== void 0 ? _sanitizeNumber1 : 0;
2172
+ var _sanitizeNumber2, _ref;
2173
+ var amount = (_ref = (_sanitizeNumber2 = sanitizeNumber(details.scroll_amount)) !== null && _sanitizeNumber2 !== void 0 ? _sanitizeNumber2 : sanitizeNumber(details.amount)) !== null && _ref !== void 0 ? _ref : 0;
2174
+ var direction = typeof details.scroll_direction === "string" ? details.scroll_direction.toLowerCase() : typeof details.direction === "string" ? details.direction.toLowerCase() : void 0;
2175
+ if (!scrollX && !scrollY && direction && amount) {
2176
+ switch(direction){
2177
+ case "up":
2178
+ scrollY = -amount;
2179
+ break;
2180
+ case "down":
2181
+ scrollY = amount;
2182
+ break;
2183
+ case "left":
2184
+ scrollX = -amount;
2185
+ break;
2186
+ case "right":
2187
+ scrollX = amount;
2188
+ break;
2189
+ default:
2190
+ break;
2191
+ }
2192
+ }
2193
+ return {
2194
+ scroll_x: scrollX,
2195
+ scroll_y: scrollY
2196
+ };
2197
+ };
2198
+ var normalizeActionString = function(action, details) {
2199
+ var coords = findCoordinatesInDetails(details);
2200
+ switch(action){
2201
+ case "screenshot":
2202
+ return {
2203
+ type: "screenshot"
2204
+ };
2205
+ case "left_click":
2206
+ case "right_click":
2207
+ case "middle_click":
2208
+ {
2209
+ var _coords_x, _coords_y;
2210
+ return {
2211
+ type: "click",
2212
+ button: clickButtonMap[action],
2213
+ x: (_coords_x = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x !== void 0 ? _coords_x : 0,
2214
+ y: (_coords_y = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y !== void 0 ? _coords_y : 0
2215
+ };
2216
+ }
2217
+ case "double_click":
2218
+ var _coords_x1, _coords_y1;
2219
+ return {
2220
+ type: "double_click",
2221
+ x: (_coords_x1 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x1 !== void 0 ? _coords_x1 : 0,
2222
+ y: (_coords_y1 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y1 !== void 0 ? _coords_y1 : 0
2223
+ };
2224
+ case "triple_click":
2225
+ var _coords_x2, _coords_y2;
2226
+ return {
2227
+ type: "double_click",
2228
+ x: (_coords_x2 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x2 !== void 0 ? _coords_x2 : 0,
2229
+ y: (_coords_y2 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y2 !== void 0 ? _coords_y2 : 0,
2230
+ repetitions: 3
2231
+ };
2232
+ case "left_mouse_down":
2233
+ var _coords_x3, _coords_y3;
2234
+ return {
2235
+ type: "click",
2236
+ button: clickButtonMap[action],
2237
+ state: "down",
2238
+ x: (_coords_x3 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x3 !== void 0 ? _coords_x3 : 0,
2239
+ y: (_coords_y3 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y3 !== void 0 ? _coords_y3 : 0
2240
+ };
2241
+ case "left_mouse_up":
2242
+ var _coords_x4, _coords_y4;
2243
+ return {
2244
+ type: "click",
2245
+ button: clickButtonMap[action],
2246
+ state: "up",
2247
+ x: (_coords_x4 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x4 !== void 0 ? _coords_x4 : 0,
2248
+ y: (_coords_y4 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y4 !== void 0 ? _coords_y4 : 0
2249
+ };
2250
+ case "left_click_drag":
2251
+ {
2252
+ var path = buildDragPath(details).map(function(param) {
2253
+ var x = param.x, y = param.y;
2254
+ return {
2255
+ x: x,
2256
+ y: y
2257
+ };
2258
+ });
2259
+ return {
2260
+ type: "drag",
2261
+ path: path
2262
+ };
2263
+ }
2264
+ case "mouse_move":
2265
+ case "cursor_position":
2266
+ var _coords_x5, _coords_y5;
2267
+ return {
2268
+ type: "move",
2269
+ x: (_coords_x5 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x5 !== void 0 ? _coords_x5 : 0,
2270
+ y: (_coords_y5 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y5 !== void 0 ? _coords_y5 : 0
2271
+ };
2272
+ case "scroll":
2273
+ {
2274
+ var _normalizeScroll = normalizeScroll(details), scroll_x = _normalizeScroll.scroll_x, scroll_y = _normalizeScroll.scroll_y;
2275
+ var _coords_x6, _coords_y6;
2276
+ return _object_spread({
2277
+ type: "scroll",
2278
+ x: (_coords_x6 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x6 !== void 0 ? _coords_x6 : 0,
2279
+ y: (_coords_y6 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y6 !== void 0 ? _coords_y6 : 0,
2280
+ scroll_x: scroll_x,
2281
+ scroll_y: scroll_y
2282
+ }, typeof details.scroll_direction === "string" ? {
2283
+ direction: details.scroll_direction
2284
+ } : typeof details.direction === "string" ? {
2285
+ direction: details.direction
2286
+ } : {}, typeof details.scroll_amount === "number" ? {
2287
+ amount: details.scroll_amount
2288
+ } : typeof details.amount === "number" ? {
2289
+ amount: details.amount
2290
+ } : {});
2291
+ }
2292
+ case "type":
2293
+ {
2294
+ var text = typeof details.text === "string" ? details.text : typeof details.input === "string" ? details.input : "";
2295
+ return {
2296
+ type: "type",
2297
+ text: text
2298
+ };
2299
+ }
2300
+ case "key":
2301
+ case "hold_key":
2302
+ {
2303
+ var _details_text, _ref;
2304
+ var keys = normalizeKeys(parseKeys((_ref = (_details_text = details.text) !== null && _details_text !== void 0 ? _details_text : details.keys) !== null && _ref !== void 0 ? _ref : details.key));
2305
+ var normalized = {
2306
+ type: "keypress",
2307
+ keys: keys
2308
+ };
2309
+ if (action === "hold_key") {
2310
+ var duration = sanitizeNumber(details.duration);
2311
+ if (typeof duration === "number") {
2312
+ normalized.hold_duration_ms = Math.round(duration * 1e3);
2313
+ }
2314
+ }
2315
+ return normalized;
2316
+ }
2317
+ case "wait":
2318
+ {
2319
+ var duration1 = sanitizeNumber(details.duration);
2320
+ return _object_spread({
2321
+ type: "wait"
2322
+ }, typeof duration1 === "number" ? {
2323
+ duration_ms: Math.round(duration1 * 1e3)
2324
+ } : {});
2325
+ }
2326
+ default:
2327
+ {
2328
+ return _object_spread({
2329
+ type: action
2330
+ }, coords ? {
2331
+ x: coords.x,
2332
+ y: coords.y
2333
+ } : {}, (0, import_radash3.omit)(details, _to_consumable_array(coordinateKeys).concat([
2334
+ "text",
2335
+ "scroll_direction",
2336
+ "direction",
2337
+ "scroll_amount",
2338
+ "amount",
2339
+ "scroll_x",
2340
+ "scroll_y",
2341
+ "keys",
2342
+ "duration"
2343
+ ])));
2344
+ }
2345
+ }
2346
+ };
2347
+ var normalizeAction = function(payload) {
2348
+ if (payload && (typeof payload === "undefined" ? "undefined" : _type_of(payload)) === "object") {
2349
+ var rawAction = payload.action;
2350
+ if (typeof rawAction === "string") {
2351
+ var parsedAction = parseJson(rawAction);
2352
+ if (parsedAction && (typeof parsedAction === "undefined" ? "undefined" : _type_of(parsedAction)) === "object") {
2353
+ rawAction = parsedAction;
2354
+ }
2355
+ }
2356
+ if (rawAction && (typeof rawAction === "undefined" ? "undefined" : _type_of(rawAction)) === "object" && typeof rawAction.type === "string") {
2357
+ return rawAction;
2358
+ }
2359
+ if (typeof rawAction === "string") {
2360
+ var details = (0, import_radash3.omit)(payload, [
2361
+ "action",
2362
+ "pending_safety_checks",
2363
+ "status"
2364
+ ]);
2365
+ return normalizeActionString(rawAction, details);
2366
+ }
2367
+ if (typeof payload.type === "string") {
2368
+ return payload;
2369
+ }
2370
+ }
2371
+ if (typeof payload === "string") {
2372
+ var parsed = parseJson(payload);
2373
+ if (parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === "object") {
2374
+ return normalizeAction(parsed);
2375
+ }
2376
+ return {
2377
+ type: payload
2378
+ };
2379
+ }
2380
+ return {
2381
+ type: "unknown",
2382
+ value: payload
2383
+ };
2384
+ };
2385
+ var normalizeComputerToolCallPayload = function(payload) {
2386
+ var normalizedPayload = payload;
2387
+ if (typeof payload === "string") {
2388
+ var parsed = parseJson(payload);
2389
+ if (parsed !== void 0) {
2390
+ normalizedPayload = parsed;
2391
+ }
2392
+ }
2393
+ var pendingSafetyChecksRaw = normalizedPayload && (typeof normalizedPayload === "undefined" ? "undefined" : _type_of(normalizedPayload)) === "object" ? normalizedPayload.pending_safety_checks : void 0;
2394
+ if (typeof pendingSafetyChecksRaw === "string") {
2395
+ var parsed1 = parseJson(pendingSafetyChecksRaw);
2396
+ pendingSafetyChecksRaw = Array.isArray(parsed1) ? parsed1 : [];
2397
+ }
2398
+ var pendingSafetyChecks = Array.isArray(pendingSafetyChecksRaw) ? pendingSafetyChecksRaw : [];
2399
+ var normalizedAction = normalizeAction(normalizedPayload);
2400
+ var result = {
2401
+ action: normalizedAction,
2402
+ pending_safety_checks: pendingSafetyChecks
2403
+ };
2404
+ if (normalizedPayload && (typeof normalizedPayload === "undefined" ? "undefined" : _type_of(normalizedPayload)) === "object" && "status" in normalizedPayload) {
2405
+ result.status = normalizedPayload.status;
2406
+ }
2407
+ return result;
2408
+ };
2409
+ var parseJson = function(value) {
2410
+ try {
2411
+ return JSON.parse(value);
2412
+ } catch (e) {
2413
+ return void 0;
2414
+ }
2415
+ };
1970
2416
  // src/adapters/client/anthropicClientAdapter/completions/post.ts
1971
2417
  var post5 = function(param) {
1972
2418
  var anthropic = param.anthropic;
1973
- return /*#__PURE__*/ function() {
1974
- var _ref = _async_to_generator(function(_url, options) {
1975
- var body, messages4, _ref, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, error;
2419
+ return function(_url, options) {
2420
+ return _async_to_generator(function() {
2421
+ var body, messages4, _ref, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, normalizedContent, normalizedData, error;
1976
2422
  return _ts_generator(this, function(_state) {
1977
2423
  switch(_state.label){
1978
2424
  case 0:
1979
2425
  body = JSON.parse(options.body);
1980
2426
  messages4 = body.messages;
1981
- _ref = _sliced_to_array((0, import_radash3.fork)(messages4, function(message) {
2427
+ _ref = _sliced_to_array((0, import_radash4.fork)(messages4, function(message) {
1982
2428
  return message.role === "system";
1983
2429
  }), 2), systemMessages = _ref[0], otherMessages = _ref[1];
1984
2430
  system = systemMessages.map(function(message) {
@@ -1991,10 +2437,14 @@ var post5 = function(param) {
1991
2437
  })
1992
2438
  })
1993
2439
  });
1994
- resultOptions = _object_spread_props(_object_spread({}, (0, import_radash3.omit)(body, [
2440
+ resultOptions = _object_spread_props(_object_spread(_object_spread_props(_object_spread({}, (0, import_radash4.omit)(body, [
1995
2441
  "response_format"
1996
2442
  ])), {
1997
- stream: body.stream ? (0, import_radash3.isEmpty)(body.tools) : false,
2443
+ model: body.model
2444
+ }), serializeBetas({
2445
+ tools: body.tools
2446
+ })), {
2447
+ stream: body.stream,
1998
2448
  system: system,
1999
2449
  messages: serializeMessages({
2000
2450
  messages: chatMessages
@@ -2004,23 +2454,98 @@ var post5 = function(param) {
2004
2454
  tools: body.tools
2005
2455
  })
2006
2456
  });
2007
- if (!body.stream) return [
2457
+ if (!resultOptions.stream) return [
2008
2458
  3,
2009
2459
  2
2010
2460
  ];
2011
2461
  return [
2012
2462
  4,
2013
- anthropic.messages.stream(resultOptions)
2463
+ anthropic.beta.messages.create(resultOptions)
2014
2464
  ];
2015
2465
  case 1:
2016
2466
  response = _state.sent();
2017
2467
  stream = new ReadableStream({
2018
2468
  start: function start(controller) {
2019
2469
  return _async_to_generator(function() {
2020
- var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, messageDelta, delta1, messageDelta1, messageDelta2, err;
2470
+ var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex, parseJson2, getOrCreateIndexForToolUseId, assignBlockToToolUse, markComputerToolUse, getToolUseIdFromBlock, emitNormalizedToolCall, getOrCreateIndexForBlock, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _ref, chunk, toolUseId, _toolUseIdArgumentBuffer_get, buffered, parsed, normalized, toolCallIndex, chunkIndex, delta, toolUseId1, _toolUseIdArgumentBuffer_get1, existing, _chunk_delta_partial_json, updated, parsed1, normalized1, toolCallIndex1, chunkIndex1, _toolUseIdArgumentBuffer_get2, existing1, _chunk_delta_partial_json1, index, messageDelta, delta1, toolName, normalizedToolName, index1, index2, _chunk_content_block_content, outputPayload, _getToolUseIdFromBlock, toolCallId, index3, _getToolUseIdFromBlock1, toolCallId1, _chunk_content_block, _toolUseId, _type, _id, rest, index4, _chunk_content_block_content1, outputPayload1, messageDelta1, messageDelta2, err;
2021
2471
  return _ts_generator(this, function(_state) {
2022
2472
  switch(_state.label){
2023
2473
  case 0:
2474
+ blockIndexToToolUseId = /* @__PURE__ */ new Map();
2475
+ toolUseIdToIndex = /* @__PURE__ */ new Map();
2476
+ toolUseIdArgumentBuffer = /* @__PURE__ */ new Map();
2477
+ computerToolUseIds = /* @__PURE__ */ new Set();
2478
+ normalizedComputerCalls = /* @__PURE__ */ new Set();
2479
+ nextToolCallIndex = 0;
2480
+ parseJson2 = function(value) {
2481
+ try {
2482
+ return JSON.parse(value);
2483
+ } catch (e) {
2484
+ return void 0;
2485
+ }
2486
+ };
2487
+ getOrCreateIndexForToolUseId = function(toolUseId) {
2488
+ if (!toolUseId) {
2489
+ return 0;
2490
+ }
2491
+ if (!toolUseIdToIndex.has(toolUseId)) {
2492
+ toolUseIdToIndex.set(toolUseId, nextToolCallIndex++);
2493
+ }
2494
+ var _toolUseIdToIndex_get;
2495
+ return (_toolUseIdToIndex_get = toolUseIdToIndex.get(toolUseId)) !== null && _toolUseIdToIndex_get !== void 0 ? _toolUseIdToIndex_get : 0;
2496
+ };
2497
+ assignBlockToToolUse = function(param) {
2498
+ var blockIndex = param.blockIndex, toolUseId = param.toolUseId;
2499
+ if (typeof blockIndex === "number" && toolUseId) {
2500
+ blockIndexToToolUseId.set(blockIndex, toolUseId);
2501
+ }
2502
+ };
2503
+ markComputerToolUse = function(toolUseId) {
2504
+ if (!toolUseId) return;
2505
+ computerToolUseIds.add(toolUseId);
2506
+ normalizedComputerCalls.delete(toolUseId);
2507
+ toolUseIdArgumentBuffer.set(toolUseId, "");
2508
+ };
2509
+ getToolUseIdFromBlock = function(block) {
2510
+ if (!block || (typeof block === "undefined" ? "undefined" : _type_of(block)) !== "object") return void 0;
2511
+ if (typeof block.tool_use_id === "string") {
2512
+ return block.tool_use_id;
2513
+ }
2514
+ if (typeof block.id === "string") {
2515
+ return block.id;
2516
+ }
2517
+ return void 0;
2518
+ };
2519
+ emitNormalizedToolCall = function(param) {
2520
+ var normalized = param.normalized, toolCallIndex = param.toolCallIndex, chunkIndex = param.chunkIndex;
2521
+ var messageDelta = {
2522
+ id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
2523
+ object: "chat.completion.chunk",
2524
+ choices: [
2525
+ {
2526
+ index: chunkIndex,
2527
+ delta: {
2528
+ tool_calls: [
2529
+ {
2530
+ index: toolCallIndex,
2531
+ function: {
2532
+ arguments: JSON.stringify(normalized)
2533
+ }
2534
+ }
2535
+ ]
2536
+ }
2537
+ }
2538
+ ]
2539
+ };
2540
+ controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
2541
+ };
2542
+ getOrCreateIndexForBlock = function(blockIndex) {
2543
+ if (typeof blockIndex !== "number") {
2544
+ return 0;
2545
+ }
2546
+ var toolUseId = blockIndexToToolUseId.get(blockIndex);
2547
+ return getOrCreateIndexForToolUseId(toolUseId);
2548
+ };
2024
2549
  _iteratorAbruptCompletion = false, _didIteratorError = false;
2025
2550
  _state.label = 1;
2026
2551
  case 1:
@@ -2043,14 +2568,79 @@ var post5 = function(param) {
2043
2568
  5
2044
2569
  ];
2045
2570
  _value = _step.value;
2046
- chunk = _value;
2571
+ _ref = _value;
2572
+ chunk = _ref;
2573
+ if (chunk.type === "content_block_stop") {
2574
+ toolUseId = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
2575
+ if (toolUseId && computerToolUseIds.has(toolUseId) && !normalizedComputerCalls.has(toolUseId)) {
2576
+ ;
2577
+ buffered = (_toolUseIdArgumentBuffer_get = toolUseIdArgumentBuffer.get(toolUseId)) !== null && _toolUseIdArgumentBuffer_get !== void 0 ? _toolUseIdArgumentBuffer_get : "";
2578
+ parsed = buffered ? parseJson2(buffered) : void 0;
2579
+ if (parsed !== void 0) {
2580
+ normalized = normalizeComputerToolCallPayload(parsed);
2581
+ toolCallIndex = getOrCreateIndexForToolUseId(toolUseId);
2582
+ chunkIndex = typeof chunk.index === "number" ? chunk.index : 0;
2583
+ emitNormalizedToolCall({
2584
+ normalized: normalized,
2585
+ toolCallIndex: toolCallIndex,
2586
+ chunkIndex: chunkIndex
2587
+ });
2588
+ normalizedComputerCalls.add(toolUseId);
2589
+ }
2590
+ }
2591
+ if (toolUseId) {
2592
+ toolUseIdArgumentBuffer.delete(toolUseId);
2593
+ computerToolUseIds.delete(toolUseId);
2594
+ normalizedComputerCalls.delete(toolUseId);
2595
+ }
2596
+ if (typeof chunk.index === "number") {
2597
+ blockIndexToToolUseId.delete(chunk.index);
2598
+ }
2599
+ return [
2600
+ 3,
2601
+ 4
2602
+ ];
2603
+ }
2047
2604
  if (chunk.type === "content_block_delta") {
2048
2605
  delta = void 0;
2049
2606
  if (chunk.delta.type === "input_json_delta") {
2607
+ toolUseId1 = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
2608
+ if (toolUseId1 && computerToolUseIds.has(toolUseId1)) {
2609
+ ;
2610
+ existing = (_toolUseIdArgumentBuffer_get1 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get1 !== void 0 ? _toolUseIdArgumentBuffer_get1 : "";
2611
+ ;
2612
+ updated = "".concat(existing).concat((_chunk_delta_partial_json = chunk.delta.partial_json) !== null && _chunk_delta_partial_json !== void 0 ? _chunk_delta_partial_json : "");
2613
+ toolUseIdArgumentBuffer.set(toolUseId1, updated);
2614
+ if (!normalizedComputerCalls.has(toolUseId1)) {
2615
+ parsed1 = parseJson2(updated);
2616
+ if (parsed1 !== void 0) {
2617
+ normalized1 = normalizeComputerToolCallPayload(parsed1);
2618
+ toolCallIndex1 = getOrCreateIndexForToolUseId(toolUseId1);
2619
+ chunkIndex1 = typeof chunk.index === "number" ? chunk.index : 0;
2620
+ emitNormalizedToolCall({
2621
+ normalized: normalized1,
2622
+ toolCallIndex: toolCallIndex1,
2623
+ chunkIndex: chunkIndex1
2624
+ });
2625
+ normalizedComputerCalls.add(toolUseId1);
2626
+ }
2627
+ }
2628
+ return [
2629
+ 3,
2630
+ 4
2631
+ ];
2632
+ }
2633
+ if (toolUseId1) {
2634
+ ;
2635
+ existing1 = (_toolUseIdArgumentBuffer_get2 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get2 !== void 0 ? _toolUseIdArgumentBuffer_get2 : "";
2636
+ ;
2637
+ toolUseIdArgumentBuffer.set(toolUseId1, "".concat(existing1).concat((_chunk_delta_partial_json1 = chunk.delta.partial_json) !== null && _chunk_delta_partial_json1 !== void 0 ? _chunk_delta_partial_json1 : ""));
2638
+ }
2639
+ index = getOrCreateIndexForBlock(chunk.index);
2050
2640
  delta = {
2051
2641
  tool_calls: [
2052
2642
  {
2053
- index: 0,
2643
+ index: index,
2054
2644
  function: {
2055
2645
  arguments: chunk.delta.partial_json
2056
2646
  }
@@ -2067,7 +2657,7 @@ var post5 = function(param) {
2067
2657
  };
2068
2658
  }
2069
2659
  messageDelta = {
2070
- id: "chatcmpl-".concat((0, import_radash3.uid)(29)),
2660
+ id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
2071
2661
  object: "chat.completion.chunk",
2072
2662
  choices: [
2073
2663
  {
@@ -2080,11 +2670,46 @@ var post5 = function(param) {
2080
2670
  } else if (chunk.type === "content_block_start") {
2081
2671
  delta1 = void 0;
2082
2672
  if (chunk.content_block.type === "tool_use") {
2673
+ toolName = chunk.content_block.name;
2674
+ normalizedToolName = toolName === "computer" ? "computer_call" : toolName;
2675
+ index1 = getOrCreateIndexForToolUseId(chunk.content_block.id);
2676
+ assignBlockToToolUse({
2677
+ blockIndex: chunk.index,
2678
+ toolUseId: chunk.content_block.id
2679
+ });
2680
+ if (normalizedToolName === "computer_call") {
2681
+ markComputerToolUse(chunk.content_block.id);
2682
+ } else if (!toolUseIdArgumentBuffer.has(chunk.content_block.id)) {
2683
+ toolUseIdArgumentBuffer.set(chunk.content_block.id, "");
2684
+ }
2685
+ delta1 = {
2686
+ content: null,
2687
+ tool_calls: [
2688
+ {
2689
+ index: index1,
2690
+ id: chunk.content_block.id,
2691
+ type: "function",
2692
+ function: {
2693
+ name: normalizedToolName,
2694
+ arguments: ""
2695
+ }
2696
+ }
2697
+ ]
2698
+ };
2699
+ } else if (chunk.content_block.type === "server_tool_use") {
2700
+ index2 = getOrCreateIndexForToolUseId(chunk.content_block.id);
2701
+ assignBlockToToolUse({
2702
+ blockIndex: chunk.index,
2703
+ toolUseId: chunk.content_block.id
2704
+ });
2705
+ if (!toolUseIdArgumentBuffer.has(chunk.content_block.id)) {
2706
+ toolUseIdArgumentBuffer.set(chunk.content_block.id, "");
2707
+ }
2083
2708
  delta1 = {
2084
2709
  content: null,
2085
2710
  tool_calls: [
2086
2711
  {
2087
- index: 0,
2712
+ index: index2,
2088
2713
  id: chunk.content_block.id,
2089
2714
  type: "function",
2090
2715
  function: {
@@ -2094,6 +2719,65 @@ var post5 = function(param) {
2094
2719
  }
2095
2720
  ]
2096
2721
  };
2722
+ } else if (chunk.content_block.type === "web_search_tool_result") {
2723
+ ;
2724
+ outputPayload = {
2725
+ content: (_chunk_content_block_content = chunk.content_block.content) !== null && _chunk_content_block_content !== void 0 ? _chunk_content_block_content : []
2726
+ };
2727
+ ;
2728
+ toolCallId = (_getToolUseIdFromBlock = getToolUseIdFromBlock(chunk.content_block)) !== null && _getToolUseIdFromBlock !== void 0 ? _getToolUseIdFromBlock : "";
2729
+ index3 = getOrCreateIndexForToolUseId(toolCallId);
2730
+ assignBlockToToolUse({
2731
+ blockIndex: chunk.index,
2732
+ toolUseId: toolCallId
2733
+ });
2734
+ delta1 = {
2735
+ content: null,
2736
+ tool_calls: [
2737
+ {
2738
+ index: index3,
2739
+ id: toolCallId,
2740
+ type: "function",
2741
+ function: {
2742
+ output: JSON.stringify(outputPayload)
2743
+ }
2744
+ }
2745
+ ]
2746
+ };
2747
+ } else if ([
2748
+ "code_execution_tool_result",
2749
+ "bash_code_execution_tool_result",
2750
+ "python_code_execution_tool_result"
2751
+ ].includes(chunk.content_block.type)) {
2752
+ ;
2753
+ toolCallId1 = (_getToolUseIdFromBlock1 = getToolUseIdFromBlock(chunk.content_block)) !== null && _getToolUseIdFromBlock1 !== void 0 ? _getToolUseIdFromBlock1 : "";
2754
+ _chunk_content_block = chunk.content_block, _toolUseId = _chunk_content_block.tool_use_id, _type = _chunk_content_block.type, _id = _chunk_content_block.id, rest = _object_without_properties(_chunk_content_block, [
2755
+ "tool_use_id",
2756
+ "type",
2757
+ "id"
2758
+ ]);
2759
+ index4 = getOrCreateIndexForToolUseId(toolCallId1);
2760
+ assignBlockToToolUse({
2761
+ blockIndex: chunk.index,
2762
+ toolUseId: toolCallId1
2763
+ });
2764
+ ;
2765
+ outputPayload1 = Object.keys(rest).length > 0 ? rest : {
2766
+ content: (_chunk_content_block_content1 = chunk.content_block.content) !== null && _chunk_content_block_content1 !== void 0 ? _chunk_content_block_content1 : {}
2767
+ };
2768
+ delta1 = {
2769
+ content: null,
2770
+ tool_calls: [
2771
+ {
2772
+ index: index4,
2773
+ id: toolCallId1,
2774
+ type: "function",
2775
+ function: {
2776
+ output: JSON.stringify(outputPayload1)
2777
+ }
2778
+ }
2779
+ ]
2780
+ };
2097
2781
  } else if ("text" in chunk.content_block) {
2098
2782
  delta1 = {
2099
2783
  content: chunk.content_block.text
@@ -2104,7 +2788,7 @@ var post5 = function(param) {
2104
2788
  };
2105
2789
  }
2106
2790
  messageDelta1 = {
2107
- id: "chatcmpl-".concat((0, import_radash3.uid)(29)),
2791
+ id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
2108
2792
  object: "chat.completion.chunk",
2109
2793
  choices: [
2110
2794
  {
@@ -2116,7 +2800,7 @@ var post5 = function(param) {
2116
2800
  controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
2117
2801
  } else if (chunk.type === "message_start") {
2118
2802
  messageDelta2 = {
2119
- id: "chatcmpl-".concat((0, import_radash3.uid)(29)),
2803
+ id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
2120
2804
  object: "chat.completion.chunk",
2121
2805
  choices: [
2122
2806
  {
@@ -2214,10 +2898,22 @@ var post5 = function(param) {
2214
2898
  ];
2215
2899
  case 3:
2216
2900
  data = _state.sent();
2901
+ normalizedContent = Array.isArray(data === null || data === void 0 ? void 0 : data.content) ? data.content.map(function(block) {
2902
+ if ((block === null || block === void 0 ? void 0 : block.type) === "tool_use" && (block === null || block === void 0 ? void 0 : block.name) === "computer") {
2903
+ var _block_input;
2904
+ return _object_spread_props(_object_spread({}, block), {
2905
+ input: normalizeComputerToolCallPayload((_block_input = block.input) !== null && _block_input !== void 0 ? _block_input : {})
2906
+ });
2907
+ }
2908
+ return block;
2909
+ }) : data === null || data === void 0 ? void 0 : data.content;
2910
+ normalizedData = _object_spread({}, data, normalizedContent ? {
2911
+ content: normalizedContent
2912
+ } : {});
2217
2913
  return [
2218
2914
  2,
2219
2915
  new Response(JSON.stringify({
2220
- data: data
2916
+ data: normalizedData
2221
2917
  }), {
2222
2918
  status: 200,
2223
2919
  headers: {
@@ -2244,11 +2940,8 @@ var post5 = function(param) {
2244
2940
  ];
2245
2941
  }
2246
2942
  });
2247
- });
2248
- return function(_url, options) {
2249
- return _ref.apply(this, arguments);
2250
- };
2251
- }();
2943
+ })();
2944
+ };
2252
2945
  };
2253
2946
  // src/adapters/client/anthropicClientAdapter/completions/index.ts
2254
2947
  var completions5 = function(param) {
@@ -2277,8 +2970,8 @@ var anthropicClientAdapter = function(param) {
2277
2970
  // src/adapters/client/togetherClientAdapter/models/get.ts
2278
2971
  var get6 = function(param) {
2279
2972
  var together = param.together;
2280
- return /*#__PURE__*/ function() {
2281
- var _ref = _async_to_generator(function(_url, _options) {
2973
+ return function(_url, _options) {
2974
+ return _async_to_generator(function() {
2282
2975
  var data, error;
2283
2976
  return _ts_generator(this, function(_state) {
2284
2977
  switch(_state.label){
@@ -2327,11 +3020,8 @@ var get6 = function(param) {
2327
3020
  ];
2328
3021
  }
2329
3022
  });
2330
- });
2331
- return function(_url, _options) {
2332
- return _ref.apply(this, arguments);
2333
- };
2334
- }();
3023
+ })();
3024
+ };
2335
3025
  };
2336
3026
  // src/adapters/client/togetherClientAdapter/models/index.ts
2337
3027
  var models7 = function(param) {
@@ -2345,8 +3035,8 @@ var models7 = function(param) {
2345
3035
  // src/adapters/client/togetherClientAdapter/completions/post.ts
2346
3036
  var post6 = function(param) {
2347
3037
  var together = param.together;
2348
- return /*#__PURE__*/ function() {
2349
- var _ref = _async_to_generator(function(_url, options) {
3038
+ return function(_url, options) {
3039
+ return _async_to_generator(function() {
2350
3040
  var body, response, stream, data, error;
2351
3041
  return _ts_generator(this, function(_state) {
2352
3042
  switch(_state.label){
@@ -2508,11 +3198,8 @@ var post6 = function(param) {
2508
3198
  ];
2509
3199
  }
2510
3200
  });
2511
- });
2512
- return function(_url, options) {
2513
- return _ref.apply(this, arguments);
2514
- };
2515
- }();
3201
+ })();
3202
+ };
2516
3203
  };
2517
3204
  // src/adapters/client/togetherClientAdapter/completions/index.ts
2518
3205
  var completions6 = function(param) {
@@ -2550,8 +3237,8 @@ var models8 = [
2550
3237
  ];
2551
3238
  var get7 = function(param) {
2552
3239
  var google = param.google;
2553
- return /*#__PURE__*/ function() {
2554
- var _ref = _async_to_generator(function(_url, _options) {
3240
+ return function(_url, _options) {
3241
+ return _async_to_generator(function() {
2555
3242
  return _ts_generator(this, function(_state) {
2556
3243
  try {
2557
3244
  return [
@@ -2588,11 +3275,8 @@ var get7 = function(param) {
2588
3275
  2
2589
3276
  ];
2590
3277
  });
2591
- });
2592
- return function(_url, _options) {
2593
- return _ref.apply(this, arguments);
2594
- };
2595
- }();
3278
+ })();
3279
+ };
2596
3280
  };
2597
3281
  // src/adapters/client/googleClientAdapter/models/index.ts
2598
3282
  var models9 = function(param) {
@@ -2607,8 +3291,8 @@ var models9 = function(param) {
2607
3291
  var import_cuid2 = require("@paralleldrive/cuid2");
2608
3292
  var post7 = function(param) {
2609
3293
  var google = param.google;
2610
- return /*#__PURE__*/ function() {
2611
- var _ref = _async_to_generator(function(_url, options) {
3294
+ return function(_url, options) {
3295
+ return _async_to_generator(function() {
2612
3296
  var body, resultOptions, response, stream, data, error;
2613
3297
  return _ts_generator(this, function(_state) {
2614
3298
  switch(_state.label){
@@ -2802,11 +3486,8 @@ var post7 = function(param) {
2802
3486
  ];
2803
3487
  }
2804
3488
  });
2805
- });
2806
- return function(_url, options) {
2807
- return _ref.apply(this, arguments);
2808
- };
2809
- }();
3489
+ })();
3490
+ };
2810
3491
  };
2811
3492
  // src/adapters/client/googleClientAdapter/completions/index.ts
2812
3493
  var completions7 = function(param) {
@@ -2838,8 +3519,8 @@ var models10 = [
2838
3519
  ];
2839
3520
  var get8 = function(param) {
2840
3521
  var humiris = param.humiris;
2841
- return /*#__PURE__*/ function() {
2842
- var _ref = _async_to_generator(function(_url, _options) {
3522
+ return function(_url, _options) {
3523
+ return _async_to_generator(function() {
2843
3524
  return _ts_generator(this, function(_state) {
2844
3525
  try {
2845
3526
  return [
@@ -2876,11 +3557,8 @@ var get8 = function(param) {
2876
3557
  2
2877
3558
  ];
2878
3559
  });
2879
- });
2880
- return function(_url, _options) {
2881
- return _ref.apply(this, arguments);
2882
- };
2883
- }();
3560
+ })();
3561
+ };
2884
3562
  };
2885
3563
  // src/adapters/client/humirisClientAdapter/models/index.ts
2886
3564
  var models11 = function(param) {
@@ -2894,8 +3572,8 @@ var models11 = function(param) {
2894
3572
  // src/adapters/client/humirisClientAdapter/completions/post.ts
2895
3573
  var post8 = function(param) {
2896
3574
  var humiris = param.humiris;
2897
- return /*#__PURE__*/ function() {
2898
- var _ref = _async_to_generator(function(_url, options) {
3575
+ return function(_url, options) {
3576
+ return _async_to_generator(function() {
2899
3577
  var body, data, stream, data1, error;
2900
3578
  return _ts_generator(this, function(_state) {
2901
3579
  switch(_state.label){
@@ -2995,11 +3673,8 @@ var post8 = function(param) {
2995
3673
  ];
2996
3674
  }
2997
3675
  });
2998
- });
2999
- return function(_url, options) {
3000
- return _ref.apply(this, arguments);
3001
- };
3002
- }();
3676
+ })();
3677
+ };
3003
3678
  };
3004
3679
  // src/adapters/client/humirisClientAdapter/completions/index.ts
3005
3680
  var completions8 = function(param) {
@@ -3028,8 +3703,8 @@ var humirisClientAdapter = function(param) {
3028
3703
  // src/adapters/client/ollamaClientAdapter/models/get.ts
3029
3704
  var get9 = function(param) {
3030
3705
  var ollama = param.ollama;
3031
- return /*#__PURE__*/ function() {
3032
- var _ref = _async_to_generator(function(_url, _options) {
3706
+ return function(_url, _options) {
3707
+ return _async_to_generator(function() {
3033
3708
  var data, error;
3034
3709
  return _ts_generator(this, function(_state) {
3035
3710
  switch(_state.label){
@@ -3074,11 +3749,8 @@ var get9 = function(param) {
3074
3749
  ];
3075
3750
  }
3076
3751
  });
3077
- });
3078
- return function(_url, _options) {
3079
- return _ref.apply(this, arguments);
3080
- };
3081
- }();
3752
+ })();
3753
+ };
3082
3754
  };
3083
3755
  // src/adapters/client/ollamaClientAdapter/models/index.ts
3084
3756
  var models12 = function(param) {
@@ -3092,8 +3764,8 @@ var models12 = function(param) {
3092
3764
  // src/adapters/client/ollamaClientAdapter/completions/post.ts
3093
3765
  var post9 = function(param) {
3094
3766
  var ollama = param.ollama;
3095
- return /*#__PURE__*/ function() {
3096
- var _ref = _async_to_generator(function(_url, options) {
3767
+ return function(_url, options) {
3768
+ return _async_to_generator(function() {
3097
3769
  var body, response, stream, data, error;
3098
3770
  return _ts_generator(this, function(_state) {
3099
3771
  switch(_state.label){
@@ -3255,11 +3927,8 @@ var post9 = function(param) {
3255
3927
  ];
3256
3928
  }
3257
3929
  });
3258
- });
3259
- return function(_url, options) {
3260
- return _ref.apply(this, arguments);
3261
- };
3262
- }();
3930
+ })();
3931
+ };
3263
3932
  };
3264
3933
  // src/adapters/client/ollamaClientAdapter/completions/index.ts
3265
3934
  var completions9 = function(param) {
@@ -3287,21 +3956,21 @@ var ollamaClientAdapter = function(param) {
3287
3956
  };
3288
3957
  // src/adapters/run/completionsRunAdapter/index.ts
3289
3958
  var import_lodash = __toESM(require("lodash"), 1);
3290
- var import_radash6 = require("radash");
3959
+ var import_radash7 = require("radash");
3291
3960
  var import_dayjs = __toESM(require("dayjs"), 1);
3292
3961
  // src/adapters/run/completionsRunAdapter/messages/index.ts
3293
- var import_radash5 = require("radash");
3962
+ var import_radash6 = require("radash");
3294
3963
  // src/adapters/run/completionsRunAdapter/messages/serializeMessage.ts
3295
- var import_radash4 = require("radash");
3964
+ var import_radash5 = require("radash");
3296
3965
  var validToolCallContentTypes = [
3297
3966
  "image",
3298
3967
  "text"
3299
3968
  ];
3300
3969
  var serializeToolContent = function(param) {
3301
3970
  var toolCall = param.toolCall;
3302
- if ((0, import_radash4.isArray)(toolCall.function.output)) {
3971
+ if ((0, import_radash5.isArray)(toolCall.function.output)) {
3303
3972
  var isEveryToolPartValid = toolCall.function.output.every(function(toolPart) {
3304
- if (!(0, import_radash4.isObject)(toolPart)) return false;
3973
+ if (!(0, import_radash5.isObject)(toolPart)) return false;
3305
3974
  return validToolCallContentTypes.includes(toolPart.type);
3306
3975
  });
3307
3976
  if (isEveryToolPartValid) {
@@ -3376,20 +4045,20 @@ var serializeMessage3 = function(param) {
3376
4045
  return result;
3377
4046
  };
3378
4047
  // src/adapters/run/completionsRunAdapter/messages/index.ts
3379
- var messages = /*#__PURE__*/ function() {
3380
- var _ref = _async_to_generator(function(param) {
3381
- var run3, getMessages2, _, _1, _2;
4048
+ var messages = function(param) {
4049
+ var run3 = param.run, getMessages2 = param.getMessages;
4050
+ return _async_to_generator(function() {
4051
+ var _, _1, _2;
3382
4052
  return _ts_generator(this, function(_state) {
3383
4053
  switch(_state.label){
3384
4054
  case 0:
3385
- run3 = param.run, getMessages2 = param.getMessages;
3386
4055
  _1 = (_ = _to_consumable_array(run3.instructions ? [
3387
4056
  {
3388
4057
  role: "system",
3389
4058
  content: run3.instructions
3390
4059
  }
3391
4060
  ] : [])).concat;
3392
- _2 = (0, import_radash5.flat);
4061
+ _2 = (0, import_radash6.flat);
3393
4062
  return [
3394
4063
  4,
3395
4064
  getMessages2()
@@ -3411,15 +4080,12 @@ var messages = /*#__PURE__*/ function() {
3411
4080
  ];
3412
4081
  }
3413
4082
  });
3414
- });
3415
- return function messages(_) {
3416
- return _ref.apply(this, arguments);
3417
- };
3418
- }();
4083
+ })();
4084
+ };
3419
4085
  // src/adapters/run/completionsRunAdapter/index.ts
3420
4086
  var updatedToolCall = function(param) {
3421
4087
  var toolCall = param.toolCall, delta = param.delta;
3422
- if (!toolCall) return (0, import_radash6.omit)(delta, [
4088
+ if (!toolCall) return (0, import_radash7.omit)(delta, [
3423
4089
  "index"
3424
4090
  ]);
3425
4091
  var result = import_lodash.default.cloneDeep(toolCall);
@@ -3450,10 +4116,11 @@ var toolCallsData = function(param) {
3450
4116
  var prevToolCalls = param.prevToolCalls, delta = param.delta;
3451
4117
  if (!prevToolCalls) {
3452
4118
  return delta.tool_calls.map(function(tc) {
4119
+ var _tc_type;
3453
4120
  return _object_spread({
3454
- id: (0, import_radash6.uid)(24),
3455
- type: "function"
3456
- }, (0, import_radash6.omit)(tc, [
4121
+ id: (0, import_radash7.uid)(24),
4122
+ type: (_tc_type = tc.type) !== null && _tc_type !== void 0 ? _tc_type : "function"
4123
+ }, (0, import_radash7.omit)(tc, [
3457
4124
  "index"
3458
4125
  ]));
3459
4126
  });
@@ -3486,13 +4153,13 @@ var toolCallsData = function(param) {
3486
4153
  };
3487
4154
  var completionsRunAdapter = function() {
3488
4155
  return {
3489
- handleRun: /*#__PURE__*/ function() {
3490
- var _ref = _async_to_generator(function(param) {
3491
- var client, run3, onEvent2, getMessages2, opts, _tmp, providerResponse, e, _e_cause, _e_message, _e_cause_message, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, _delta_content, err;
4156
+ handleRun: function(param) {
4157
+ var client = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
4158
+ return _async_to_generator(function() {
4159
+ var opts, _tmp, providerResponse, e, _e_cause, _e_message, _e_cause_message, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, _delta_content, err, _message_toolCalls, messageToolCalls, functionToolCalls, pendingFunctionToolCalls, requiredToolCalls;
3492
4160
  return _ts_generator(this, function(_state) {
3493
4161
  switch(_state.label){
3494
4162
  case 0:
3495
- client = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
3496
4163
  if (run3.status !== "queued") return [
3497
4164
  2
3498
4165
  ];
@@ -3513,7 +4180,7 @@ var completionsRunAdapter = function() {
3513
4180
  case 1:
3514
4181
  opts = _object_spread.apply(void 0, [
3515
4182
  (_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
3516
- (0, import_radash6.isEmpty)(run3.tools) ? {} : {
4183
+ (0, import_radash7.isEmpty)(run3.tools) ? {} : {
3517
4184
  tools: run3.tools
3518
4185
  }
3519
4186
  ]);
@@ -3695,9 +4362,10 @@ var completionsRunAdapter = function() {
3695
4362
  step_details: {
3696
4363
  type: "tool_calls",
3697
4364
  tool_calls: delta.tool_calls.map(function(tc) {
4365
+ var _tc_type;
3698
4366
  return _object_spread({
3699
- id: (0, import_radash6.uid)(24),
3700
- type: "function"
4367
+ id: (0, import_radash7.uid)(24),
4368
+ type: (_tc_type = tc.type) !== null && _tc_type !== void 0 ? _tc_type : "function"
3701
4369
  }, tc);
3702
4370
  })
3703
4371
  }
@@ -3803,20 +4471,85 @@ var completionsRunAdapter = function() {
3803
4471
  })
3804
4472
  })
3805
4473
  ];
3806
- case 22:
3807
- message = _state.sent();
3808
- if ((0, import_radash6.isEmpty)(message.toolCalls)) {
3809
- return [
3810
- 2,
3811
- onEvent2({
3812
- event: "thread.run.completed",
3813
- data: _object_spread_props(_object_spread({}, run3), {
3814
- status: "completed",
3815
- completed_at: (0, import_dayjs.default)().unix()
3816
- })
3817
- })
3818
- ];
3819
- }
4474
+ case 22:
4475
+ message = _state.sent();
4476
+ messageToolCalls = (_message_toolCalls = message.toolCalls) !== null && _message_toolCalls !== void 0 ? _message_toolCalls : [];
4477
+ functionToolCalls = messageToolCalls.filter(function(toolCall) {
4478
+ return toolCall.type === "function";
4479
+ });
4480
+ pendingFunctionToolCalls = functionToolCalls.filter(function(toolCall) {
4481
+ var _toolCall_function;
4482
+ return !((_toolCall_function = toolCall.function) === null || _toolCall_function === void 0 ? void 0 : _toolCall_function.output);
4483
+ });
4484
+ if (!(0, import_radash7.isEmpty)(pendingFunctionToolCalls)) return [
4485
+ 3,
4486
+ 25
4487
+ ];
4488
+ if (!toolCallsRunStep) return [
4489
+ 3,
4490
+ 24
4491
+ ];
4492
+ return [
4493
+ 4,
4494
+ onEvent2({
4495
+ event: "thread.run.step.completed",
4496
+ data: _object_spread_props(_object_spread({}, toolCallsRunStep), {
4497
+ status: "completed",
4498
+ completed_at: (0, import_dayjs.default)().unix(),
4499
+ step_details: {
4500
+ type: "tool_calls",
4501
+ tool_calls: currentToolCalls !== null && currentToolCalls !== void 0 ? currentToolCalls : []
4502
+ }
4503
+ })
4504
+ })
4505
+ ];
4506
+ case 23:
4507
+ toolCallsRunStep = _state.sent();
4508
+ _state.label = 24;
4509
+ case 24:
4510
+ return [
4511
+ 2,
4512
+ onEvent2({
4513
+ event: "thread.run.completed",
4514
+ data: _object_spread_props(_object_spread({}, run3), {
4515
+ status: "completed",
4516
+ completed_at: (0, import_dayjs.default)().unix()
4517
+ })
4518
+ })
4519
+ ];
4520
+ case 25:
4521
+ requiredToolCalls = pendingFunctionToolCalls.map(function(toolCall) {
4522
+ var _toolCall_function, _toolCall_function1, _toolCall_function2;
4523
+ var _toolCall_function_arguments;
4524
+ var args = (_toolCall_function_arguments = (_toolCall_function = toolCall.function) === null || _toolCall_function === void 0 ? void 0 : _toolCall_function.arguments) !== null && _toolCall_function_arguments !== void 0 ? _toolCall_function_arguments : "";
4525
+ if (((_toolCall_function1 = toolCall.function) === null || _toolCall_function1 === void 0 ? void 0 : _toolCall_function1.name) === "computer_call") {
4526
+ var parsedArguments = {};
4527
+ try {
4528
+ parsedArguments = JSON.parse(args || "{}");
4529
+ } catch (e) {
4530
+ parsedArguments = {};
4531
+ }
4532
+ var _parsedArguments_action, _ref;
4533
+ var computerCall = {
4534
+ action: (_ref = (_parsedArguments_action = parsedArguments === null || parsedArguments === void 0 ? void 0 : parsedArguments.action) !== null && _parsedArguments_action !== void 0 ? _parsedArguments_action : parsedArguments) !== null && _ref !== void 0 ? _ref : {},
4535
+ pending_safety_checks: Array.isArray(parsedArguments === null || parsedArguments === void 0 ? void 0 : parsedArguments.pending_safety_checks) ? parsedArguments.pending_safety_checks : []
4536
+ };
4537
+ return {
4538
+ id: toolCall.id,
4539
+ type: "computer_call",
4540
+ computer_call: computerCall
4541
+ };
4542
+ }
4543
+ var _toolCall_function_name;
4544
+ return {
4545
+ id: toolCall.id,
4546
+ type: "function",
4547
+ function: {
4548
+ name: (_toolCall_function_name = (_toolCall_function2 = toolCall.function) === null || _toolCall_function2 === void 0 ? void 0 : _toolCall_function2.name) !== null && _toolCall_function_name !== void 0 ? _toolCall_function_name : "",
4549
+ arguments: args
4550
+ }
4551
+ };
4552
+ });
3820
4553
  return [
3821
4554
  2,
3822
4555
  onEvent2({
@@ -3826,7 +4559,7 @@ var completionsRunAdapter = function() {
3826
4559
  required_action: {
3827
4560
  type: "submit_tool_outputs",
3828
4561
  submit_tool_outputs: {
3829
- tool_calls: message.toolCalls
4562
+ tool_calls: requiredToolCalls
3830
4563
  }
3831
4564
  }
3832
4565
  })
@@ -3834,11 +4567,8 @@ var completionsRunAdapter = function() {
3834
4567
  ];
3835
4568
  }
3836
4569
  });
3837
- });
3838
- return function(_) {
3839
- return _ref.apply(this, arguments);
3840
- };
3841
- }()
4570
+ })();
4571
+ }
3842
4572
  };
3843
4573
  };
3844
4574
  // src/lib/messages/messagesRegexp.ts
@@ -3869,8 +4599,8 @@ var serializeThread = function(param) {
3869
4599
  // src/adapters/storage/prismaStorageAdapter/threads/post.ts
3870
4600
  var post10 = function(param) {
3871
4601
  var prisma = param.prisma;
3872
- return /*#__PURE__*/ function() {
3873
- var _ref = _async_to_generator(function(_urlString, options) {
4602
+ return function(_urlString, options) {
4603
+ return _async_to_generator(function() {
3874
4604
  var body, messages4, metadataRecord, assistantId, initialCreatedAt, messageData, threadData, thread;
3875
4605
  return _ts_generator(this, function(_state) {
3876
4606
  switch(_state.label){
@@ -3936,11 +4666,8 @@ var post10 = function(param) {
3936
4666
  ];
3937
4667
  }
3938
4668
  });
3939
- });
3940
- return function(_urlString, options) {
3941
- return _ref.apply(this, arguments);
3942
- };
3943
- }();
4669
+ })();
4670
+ };
3944
4671
  };
3945
4672
  // src/adapters/storage/prismaStorageAdapter/threads/index.ts
3946
4673
  var threads = function(param) {
@@ -3952,10 +4679,10 @@ var threads = function(param) {
3952
4679
  };
3953
4680
  };
3954
4681
  // src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
3955
- var import_radash8 = require("radash");
4682
+ var import_radash9 = require("radash");
3956
4683
  // src/adapters/storage/prismaStorageAdapter/threads/messages/serializeMessage.ts
3957
4684
  var import_dayjs4 = __toESM(require("dayjs"), 1);
3958
- var import_radash7 = require("radash");
4685
+ var import_radash8 = require("radash");
3959
4686
  var serializeMessage4 = function(param) {
3960
4687
  var message = param.message;
3961
4688
  var _message_metadata;
@@ -3973,7 +4700,7 @@ var serializeMessage4 = function(param) {
3973
4700
  run_id: message.runId,
3974
4701
  attachments: message.attachments,
3975
4702
  status: message.status.toLowerCase(),
3976
- metadata: (0, import_radash7.assign)((_message_metadata = message.metadata) !== null && _message_metadata !== void 0 ? _message_metadata : {}, message.toolCalls ? {
4703
+ metadata: (0, import_radash8.assign)((_message_metadata = message.metadata) !== null && _message_metadata !== void 0 ? _message_metadata : {}, message.toolCalls ? {
3977
4704
  toolCalls: message.toolCalls
3978
4705
  } : {})
3979
4706
  };
@@ -3981,7 +4708,7 @@ var serializeMessage4 = function(param) {
3981
4708
  // src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
3982
4709
  var messageContentBlocks = function(param) {
3983
4710
  var content = param.content;
3984
- if ((0, import_radash8.isArray)(content)) {
4711
+ if ((0, import_radash9.isArray)(content)) {
3985
4712
  return content.map(function(item) {
3986
4713
  if (item.type === "text") {
3987
4714
  var _item_text;
@@ -4008,8 +4735,8 @@ var messageContentBlocks = function(param) {
4008
4735
  };
4009
4736
  var post11 = function(param) {
4010
4737
  var prisma = param.prisma;
4011
- return /*#__PURE__*/ function() {
4012
- var _ref = _async_to_generator(function(urlString, options) {
4738
+ return function(urlString, options) {
4739
+ return _async_to_generator(function() {
4013
4740
  var url, _url_pathname_match, threadId, body, role, content, metadata, message;
4014
4741
  return _ts_generator(this, function(_state) {
4015
4742
  switch(_state.label){
@@ -4049,25 +4776,22 @@ var post11 = function(param) {
4049
4776
  ];
4050
4777
  }
4051
4778
  });
4052
- });
4053
- return function(urlString, options) {
4054
- return _ref.apply(this, arguments);
4055
- };
4056
- }();
4779
+ })();
4780
+ };
4057
4781
  };
4058
4782
  // src/adapters/storage/prismaStorageAdapter/threads/messages/get.ts
4059
- var import_radash9 = require("radash");
4783
+ var import_radash10 = require("radash");
4060
4784
  var get10 = function(param) {
4061
4785
  var prisma = param.prisma;
4062
- return /*#__PURE__*/ function() {
4063
- var _ref = _async_to_generator(function(urlString) {
4786
+ return function(urlString) {
4787
+ return _async_to_generator(function() {
4064
4788
  var _this, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, messagesPlusOne, messages4, _id;
4065
4789
  return _ts_generator(this, function(_state) {
4066
4790
  switch(_state.label){
4067
4791
  case 0:
4068
4792
  url = new URL(urlString);
4069
4793
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
4070
- _ref = (0, import_radash9.assign)({
4794
+ _ref = (0, import_radash10.assign)({
4071
4795
  limit: "20",
4072
4796
  order: "desc"
4073
4797
  }, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
@@ -4101,7 +4825,7 @@ var get10 = function(param) {
4101
4825
  });
4102
4826
  }),
4103
4827
  has_more: messagesPlusOne.length > pageSize,
4104
- last_id: (_id = (_this = (0, import_radash9.last)(messages4)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
4828
+ last_id: (_id = (_this = (0, import_radash10.last)(messages4)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
4105
4829
  }), {
4106
4830
  status: 200,
4107
4831
  headers: {
@@ -4111,11 +4835,8 @@ var get10 = function(param) {
4111
4835
  ];
4112
4836
  }
4113
4837
  });
4114
- });
4115
- return function(urlString) {
4116
- return _ref.apply(this, arguments);
4117
- };
4118
- }();
4838
+ })();
4839
+ };
4119
4840
  };
4120
4841
  // src/adapters/storage/prismaStorageAdapter/threads/messages/index.ts
4121
4842
  var messages2 = function(param) {
@@ -4130,7 +4851,7 @@ var messages2 = function(param) {
4130
4851
  };
4131
4852
  };
4132
4853
  // src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
4133
- var import_radash10 = require("radash");
4854
+ var import_radash11 = require("radash");
4134
4855
  // src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
4135
4856
  var import_dayjs5 = __toESM(require("dayjs"), 1);
4136
4857
  var serializeRun = function(param) {
@@ -4197,15 +4918,15 @@ var mapPrismaRun = function(run3) {
4197
4918
  // src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
4198
4919
  var get11 = function(param) {
4199
4920
  var prisma = param.prisma;
4200
- return /*#__PURE__*/ function() {
4201
- var _ref = _async_to_generator(function(urlString) {
4921
+ return function(urlString) {
4922
+ return _async_to_generator(function() {
4202
4923
  var _runs3_at, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, runsPlusOne, runs3, _runs3_at_id;
4203
4924
  return _ts_generator(this, function(_state) {
4204
4925
  switch(_state.label){
4205
4926
  case 0:
4206
4927
  url = new URL(urlString);
4207
4928
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
4208
- _ref = (0, import_radash10.assign)({
4929
+ _ref = (0, import_radash11.assign)({
4209
4930
  limit: "20",
4210
4931
  order: "desc"
4211
4932
  }, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
@@ -4249,15 +4970,12 @@ var get11 = function(param) {
4249
4970
  ];
4250
4971
  }
4251
4972
  });
4252
- });
4253
- return function(urlString) {
4254
- return _ref.apply(this, arguments);
4255
- };
4256
- }();
4973
+ })();
4974
+ };
4257
4975
  };
4258
4976
  // src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
4259
4977
  var import_dayjs7 = __toESM(require("dayjs"), 1);
4260
- var import_radash11 = require("radash");
4978
+ var import_radash12 = require("radash");
4261
4979
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunInProgress.ts
4262
4980
  var threadRunInProgress = function(param) {
4263
4981
  var prisma = param.prisma, event = param.event, controller = param.controller;
@@ -4354,13 +5072,13 @@ var status = function(event) {
4354
5072
  if (event.data.status === "expired") return "EXPIRED" /* EXPIRED */ ;
4355
5073
  throw new Error("Unknown status: ".concat(event.data.status));
4356
5074
  };
4357
- var threadRunStepCreated = /*#__PURE__*/ function() {
4358
- var _ref = _async_to_generator(function(param) {
4359
- var prisma, event, controller, runStep, serializedRunStep;
5075
+ var threadRunStepCreated = function(param) {
5076
+ var prisma = param.prisma, event = param.event, controller = param.controller;
5077
+ return _async_to_generator(function() {
5078
+ var runStep, serializedRunStep;
4360
5079
  return _ts_generator(this, function(_state) {
4361
5080
  switch(_state.label){
4362
5081
  case 0:
4363
- prisma = param.prisma, event = param.event, controller = param.controller;
4364
5082
  return [
4365
5083
  4,
4366
5084
  prisma.runStep.create({
@@ -4389,16 +5107,43 @@ var threadRunStepCreated = /*#__PURE__*/ function() {
4389
5107
  ];
4390
5108
  }
4391
5109
  });
4392
- });
4393
- return function threadRunStepCreated(_) {
4394
- return _ref.apply(this, arguments);
4395
- };
4396
- }();
5110
+ })();
5111
+ };
4397
5112
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunStepDelta.ts
4398
5113
  var threadRunStepDelta = function(param) {
4399
5114
  var event = param.event, controller = param.controller;
4400
5115
  return controller.enqueue(event);
4401
5116
  };
5117
+ // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunStepCompleted.ts
5118
+ var threadRunStepCompleted = function(param) {
5119
+ var prisma = param.prisma, event = param.event, controller = param.controller;
5120
+ return _async_to_generator(function() {
5121
+ return _ts_generator(this, function(_state) {
5122
+ switch(_state.label){
5123
+ case 0:
5124
+ controller.enqueue(event);
5125
+ return [
5126
+ 4,
5127
+ prisma.runStep.update({
5128
+ where: {
5129
+ id: event.data.id
5130
+ },
5131
+ data: {
5132
+ status: "COMPLETED" /* COMPLETED */ ,
5133
+ stepDetails: event.data.step_details,
5134
+ completedAt: event.data.completed_at
5135
+ }
5136
+ })
5137
+ ];
5138
+ case 1:
5139
+ _state.sent();
5140
+ return [
5141
+ 2
5142
+ ];
5143
+ }
5144
+ });
5145
+ })();
5146
+ };
4402
5147
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadMessageCreated.ts
4403
5148
  var status2 = function(event) {
4404
5149
  if (event.data.status === "completed") return "COMPLETED" /* COMPLETED */ ;
@@ -4406,13 +5151,13 @@ var status2 = function(event) {
4406
5151
  if (event.data.status === "incomplete") return "INCOMPLETE" /* INCOMPLETE */ ;
4407
5152
  throw new Error("Unknown status: ".concat(event.data.status));
4408
5153
  };
4409
- var threadMessageCreated = /*#__PURE__*/ function() {
4410
- var _ref = _async_to_generator(function(param) {
4411
- var prisma, event, controller, message, serializedMessage;
5154
+ var threadMessageCreated = function(param) {
5155
+ var prisma = param.prisma, event = param.event, controller = param.controller;
5156
+ return _async_to_generator(function() {
5157
+ var message, serializedMessage;
4412
5158
  return _ts_generator(this, function(_state) {
4413
5159
  switch(_state.label){
4414
5160
  case 0:
4415
- prisma = param.prisma, event = param.event, controller = param.controller;
4416
5161
  return [
4417
5162
  4,
4418
5163
  prisma.message.create({
@@ -4440,24 +5185,21 @@ var threadMessageCreated = /*#__PURE__*/ function() {
4440
5185
  ];
4441
5186
  }
4442
5187
  });
4443
- });
4444
- return function threadMessageCreated(_) {
4445
- return _ref.apply(this, arguments);
4446
- };
4447
- }();
5188
+ })();
5189
+ };
4448
5190
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadMessageDelta.ts
4449
5191
  var threadMessageDelta = function(param) {
4450
5192
  var event = param.event, controller = param.controller;
4451
5193
  return controller.enqueue(event);
4452
5194
  };
4453
5195
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadMessageCompleted.ts
4454
- var threadMessageCompleted = /*#__PURE__*/ function() {
4455
- var _ref = _async_to_generator(function(param) {
4456
- var prisma, event, controller, toolCalls, latestRunStep;
5196
+ var threadMessageCompleted = function(param) {
5197
+ var prisma = param.prisma, event = param.event, controller = param.controller;
5198
+ return _async_to_generator(function() {
5199
+ var toolCalls, latestRunStep;
4457
5200
  return _ts_generator(this, function(_state) {
4458
5201
  switch(_state.label){
4459
5202
  case 0:
4460
- prisma = param.prisma, event = param.event, controller = param.controller;
4461
5203
  controller.enqueue(event);
4462
5204
  toolCalls = event.data.tool_calls;
4463
5205
  if (!(toolCalls !== void 0)) return [
@@ -4516,11 +5258,8 @@ var threadMessageCompleted = /*#__PURE__*/ function() {
4516
5258
  ];
4517
5259
  }
4518
5260
  });
4519
- });
4520
- return function threadMessageCompleted(_) {
4521
- return _ref.apply(this, arguments);
4522
- };
4523
- }();
5261
+ })();
5262
+ };
4524
5263
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/index.ts
4525
5264
  var handlers = {
4526
5265
  "thread.run.in_progress": threadRunInProgress,
@@ -4529,6 +5268,7 @@ var handlers = {
4529
5268
  "thread.run.requires_action": threadRunRequiresAction,
4530
5269
  "thread.run.step.created": threadRunStepCreated,
4531
5270
  "thread.run.step.delta": threadRunStepDelta,
5271
+ "thread.run.step.completed": threadRunStepCompleted,
4532
5272
  "thread.message.created": threadMessageCreated,
4533
5273
  "thread.message.delta": threadMessageDelta,
4534
5274
  "thread.message.completed": threadMessageCompleted
@@ -4568,63 +5308,65 @@ var getTake = function(param) {
4568
5308
  };
4569
5309
  var getMessages = function(param) {
4570
5310
  var prisma = param.prisma, run3 = param.run;
4571
- return /*#__PURE__*/ _async_to_generator(function() {
4572
- var take, messages4;
4573
- return _ts_generator(this, function(_state) {
4574
- switch(_state.label){
4575
- case 0:
4576
- take = getTake({
4577
- run: run3
4578
- });
4579
- return [
4580
- 4,
4581
- prisma.message.findMany(_object_spread({
4582
- where: {
4583
- threadId: run3.threadId
4584
- },
4585
- include: {
4586
- run: {
4587
- include: {
4588
- runSteps: true
5311
+ return function() {
5312
+ return _async_to_generator(function() {
5313
+ var take, messages4;
5314
+ return _ts_generator(this, function(_state) {
5315
+ switch(_state.label){
5316
+ case 0:
5317
+ take = getTake({
5318
+ run: run3
5319
+ });
5320
+ return [
5321
+ 4,
5322
+ prisma.message.findMany(_object_spread({
5323
+ where: {
5324
+ threadId: run3.threadId
5325
+ },
5326
+ include: {
5327
+ run: {
5328
+ include: {
5329
+ runSteps: true
5330
+ }
4589
5331
  }
5332
+ },
5333
+ orderBy: {
5334
+ createdAt: "asc"
4590
5335
  }
4591
- },
4592
- orderBy: {
4593
- createdAt: "asc"
4594
- }
4595
- }, take ? {
4596
- take: take
4597
- } : {}))
4598
- ];
4599
- case 1:
4600
- messages4 = _state.sent();
4601
- return [
4602
- 2,
4603
- messages4.map(function(message) {
4604
- return _object_spread_props(_object_spread({}, serializeMessage4({
4605
- message: message
4606
- })), {
4607
- run: message.run ? _object_spread_props(_object_spread({}, serializeRun({
4608
- run: mapPrismaRun(message.run)
5336
+ }, take ? {
5337
+ take: take
5338
+ } : {}))
5339
+ ];
5340
+ case 1:
5341
+ messages4 = _state.sent();
5342
+ return [
5343
+ 2,
5344
+ messages4.map(function(message) {
5345
+ return _object_spread_props(_object_spread({}, serializeMessage4({
5346
+ message: message
4609
5347
  })), {
4610
- runSteps: message.run.runSteps.map(function(runStep) {
4611
- return serializeRunStep({
4612
- runStep: runStep
4613
- });
4614
- })
4615
- }) : null
4616
- });
4617
- })
4618
- ];
4619
- }
4620
- });
4621
- });
5348
+ run: message.run ? _object_spread_props(_object_spread({}, serializeRun({
5349
+ run: mapPrismaRun(message.run)
5350
+ })), {
5351
+ runSteps: message.run.runSteps.map(function(runStep) {
5352
+ return serializeRunStep({
5353
+ runStep: runStep
5354
+ });
5355
+ })
5356
+ }) : null
5357
+ });
5358
+ })
5359
+ ];
5360
+ }
5361
+ });
5362
+ })();
5363
+ };
4622
5364
  };
4623
5365
  // src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
4624
5366
  var post12 = function(param) {
4625
5367
  var prisma = param.prisma, runAdapter = param.runAdapter;
4626
- return /*#__PURE__*/ function() {
4627
- var _ref = _async_to_generator(function(urlString, options) {
5368
+ return function(urlString, options) {
5369
+ return _async_to_generator(function() {
4628
5370
  var url, _url_pathname_match, threadId, body, assistant_id, stream, assistant, _ref, model, instructions, // additional_instructions,
4629
5371
  tools, metadata, response_format, truncation_strategy, run3, data, readableStream;
4630
5372
  return _ts_generator(this, function(_state) {
@@ -4650,7 +5392,7 @@ var post12 = function(param) {
4650
5392
  if (!assistant) {
4651
5393
  throw new Error("Assistant not found");
4652
5394
  }
4653
- _ref = (0, import_radash11.assign)({
5395
+ _ref = (0, import_radash12.assign)({
4654
5396
  model: assistant.modelSlug,
4655
5397
  instructions: "",
4656
5398
  additional_instructions: null,
@@ -4788,11 +5530,8 @@ var post12 = function(param) {
4788
5530
  ];
4789
5531
  }
4790
5532
  });
4791
- });
4792
- return function(urlString, options) {
4793
- return _ref.apply(this, arguments);
4794
- };
4795
- }();
5533
+ })();
5534
+ };
4796
5535
  };
4797
5536
  // src/adapters/storage/prismaStorageAdapter/threads/runs/index.ts
4798
5537
  var runs = function(param) {
@@ -4810,8 +5549,8 @@ var runs = function(param) {
4810
5549
  // src/adapters/storage/prismaStorageAdapter/threads/run/get.ts
4811
5550
  var get12 = function(param) {
4812
5551
  var prisma = param.prisma;
4813
- return /*#__PURE__*/ function() {
4814
- var _ref = _async_to_generator(function(urlString) {
5552
+ return function(urlString) {
5553
+ return _async_to_generator(function() {
4815
5554
  var url, _url_pathname_match, threadId, runId, run3;
4816
5555
  return _ts_generator(this, function(_state) {
4817
5556
  switch(_state.label){
@@ -4856,11 +5595,8 @@ var get12 = function(param) {
4856
5595
  ];
4857
5596
  }
4858
5597
  });
4859
- });
4860
- return function(urlString) {
4861
- return _ref.apply(this, arguments);
4862
- };
4863
- }();
5598
+ })();
5599
+ };
4864
5600
  };
4865
5601
  // src/adapters/storage/prismaStorageAdapter/threads/run/index.ts
4866
5602
  var run = function(param) {
@@ -4872,18 +5608,18 @@ var run = function(param) {
4872
5608
  };
4873
5609
  };
4874
5610
  // src/adapters/storage/prismaStorageAdapter/threads/runs/steps/get.ts
4875
- var import_radash12 = require("radash");
5611
+ var import_radash13 = require("radash");
4876
5612
  var get13 = function(param) {
4877
5613
  var prisma = param.prisma;
4878
- return /*#__PURE__*/ function() {
4879
- var _ref = _async_to_generator(function(urlString) {
5614
+ return function(urlString) {
5615
+ return _async_to_generator(function() {
4880
5616
  var _runSteps_at, url, _url_pathname_match, threadId, runId, _ref, limit, order, after, pageSize, runStepsPlusOne, runSteps, _runSteps_at_id;
4881
5617
  return _ts_generator(this, function(_state) {
4882
5618
  switch(_state.label){
4883
5619
  case 0:
4884
5620
  url = new URL(urlString);
4885
5621
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
4886
- _ref = (0, import_radash12.assign)({
5622
+ _ref = (0, import_radash13.assign)({
4887
5623
  limit: "20",
4888
5624
  order: "desc"
4889
5625
  }, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
@@ -4928,11 +5664,8 @@ var get13 = function(param) {
4928
5664
  ];
4929
5665
  }
4930
5666
  });
4931
- });
4932
- return function(urlString) {
4933
- return _ref.apply(this, arguments);
4934
- };
4935
- }();
5667
+ })();
5668
+ };
4936
5669
  };
4937
5670
  // src/adapters/storage/prismaStorageAdapter/threads/runs/steps/index.ts
4938
5671
  var steps = function(param) {
@@ -4945,16 +5678,15 @@ var steps = function(param) {
4945
5678
  };
4946
5679
  // src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/post/updateRun.ts
4947
5680
  var import_dayjs8 = __toESM(require("dayjs"), 1);
4948
- var updateRun = /*#__PURE__*/ function() {
4949
- var _ref = _async_to_generator(function(param) {
4950
- var prisma, runId, threadId, _param_onThreadRunStepCompleted, onThreadRunStepCompleted, tool_outputs;
5681
+ var updateRun = function(param) {
5682
+ var prisma = param.prisma, runId = param.runId, threadId = param.threadId, _param_onThreadRunStepCompleted = param.onThreadRunStepCompleted, onThreadRunStepCompleted = _param_onThreadRunStepCompleted === void 0 ? function() {} : _param_onThreadRunStepCompleted, tool_outputs = param.tool_outputs;
5683
+ return _async_to_generator(function() {
4951
5684
  return _ts_generator(this, function(_state) {
4952
- prisma = param.prisma, runId = param.runId, threadId = param.threadId, _param_onThreadRunStepCompleted = param.onThreadRunStepCompleted, onThreadRunStepCompleted = _param_onThreadRunStepCompleted === void 0 ? function() {} : _param_onThreadRunStepCompleted, tool_outputs = param.tool_outputs;
4953
- // @ts-expect-error prisma transaction typing is broken
4954
5685
  return [
4955
5686
  2,
4956
- prisma.$transaction(/*#__PURE__*/ function() {
4957
- var _ref = _async_to_generator(function(prisma2) {
5687
+ // @ts-expect-error prisma transaction typing is broken
5688
+ prisma.$transaction(function(prisma2) {
5689
+ return _async_to_generator(function() {
4958
5690
  var runSteps, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err;
4959
5691
  return _ts_generator(this, function(_state) {
4960
5692
  switch(_state.label){
@@ -5100,23 +5832,17 @@ var updateRun = /*#__PURE__*/ function() {
5100
5832
  ];
5101
5833
  }
5102
5834
  });
5103
- });
5104
- return function(prisma2) {
5105
- return _ref.apply(this, arguments);
5106
- };
5107
- }())
5835
+ })();
5836
+ })
5108
5837
  ];
5109
5838
  });
5110
- });
5111
- return function updateRun(_) {
5112
- return _ref.apply(this, arguments);
5113
- };
5114
- }();
5839
+ })();
5840
+ };
5115
5841
  // src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
5116
5842
  var post13 = function(param) {
5117
5843
  var prisma = param.prisma, runAdapter = param.runAdapter;
5118
- return /*#__PURE__*/ function() {
5119
- var _ref = _async_to_generator(function(urlString, options) {
5844
+ return function(urlString, options) {
5845
+ return _async_to_generator(function() {
5120
5846
  var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream, run3;
5121
5847
  return _ts_generator(this, function(_state) {
5122
5848
  switch(_state.label){
@@ -5143,11 +5869,10 @@ var post13 = function(param) {
5143
5869
  runId: runId,
5144
5870
  threadId: threadId,
5145
5871
  tool_outputs: tool_outputs,
5146
- onThreadRunStepCompleted: /*#__PURE__*/ function() {
5147
- var _ref = _async_to_generator(function(param) {
5148
- var runStep;
5872
+ onThreadRunStepCompleted: function(param) {
5873
+ var runStep = param.runStep;
5874
+ return _async_to_generator(function() {
5149
5875
  return _ts_generator(this, function(_state) {
5150
- runStep = param.runStep;
5151
5876
  controller.enqueue("data: ".concat(JSON.stringify({
5152
5877
  event: "thread.run.step.completed",
5153
5878
  data: serializeRunStep({
@@ -5158,11 +5883,8 @@ var post13 = function(param) {
5158
5883
  2
5159
5884
  ];
5160
5885
  });
5161
- });
5162
- return function(_) {
5163
- return _ref.apply(this, arguments);
5164
- };
5165
- }()
5886
+ })();
5887
+ }
5166
5888
  })
5167
5889
  ];
5168
5890
  case 1:
@@ -5278,11 +6000,8 @@ var post13 = function(param) {
5278
6000
  ];
5279
6001
  }
5280
6002
  });
5281
- });
5282
- return function(urlString, options) {
5283
- return _ref.apply(this, arguments);
5284
- };
5285
- }();
6003
+ })();
6004
+ };
5286
6005
  };
5287
6006
  // src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/index.ts
5288
6007
  var submitToolOutputs = function(param) {
@@ -5299,8 +6018,8 @@ var submitToolOutputs = function(param) {
5299
6018
  var import_dayjs9 = __toESM(require("dayjs"), 1);
5300
6019
  var post14 = function(param) {
5301
6020
  var prisma = param.prisma;
5302
- return /*#__PURE__*/ function() {
5303
- var _ref = _async_to_generator(function(_url, options) {
6021
+ return function(_url, options) {
6022
+ return _async_to_generator(function() {
5304
6023
  var body, model, instructions, assistant, data;
5305
6024
  return _ts_generator(this, function(_state) {
5306
6025
  switch(_state.label){
@@ -5343,11 +6062,8 @@ var post14 = function(param) {
5343
6062
  ];
5344
6063
  }
5345
6064
  });
5346
- });
5347
- return function(_url, options) {
5348
- return _ref.apply(this, arguments);
5349
- };
5350
- }();
6065
+ })();
6066
+ };
5351
6067
  };
5352
6068
  // src/adapters/storage/prismaStorageAdapter/assistants/index.ts
5353
6069
  var assistants = function(param) {
@@ -5404,8 +6120,8 @@ var serializeThread2 = function(param) {
5404
6120
  // src/adapters/storage/responsesStorageAdapter/threads/post.ts
5405
6121
  var post15 = function(param) {
5406
6122
  var client = param.client;
5407
- return /*#__PURE__*/ function() {
5408
- var _ref = _async_to_generator(function(_urlString, options) {
6123
+ return function(_urlString, options) {
6124
+ return _async_to_generator(function() {
5409
6125
  var body, messages4, metadata, conversation;
5410
6126
  return _ts_generator(this, function(_state) {
5411
6127
  switch(_state.label){
@@ -5449,11 +6165,8 @@ var post15 = function(param) {
5449
6165
  ];
5450
6166
  }
5451
6167
  });
5452
- });
5453
- return function(_urlString, options) {
5454
- return _ref.apply(this, arguments);
5455
- };
5456
- }();
6168
+ })();
6169
+ };
5457
6170
  };
5458
6171
  // src/adapters/storage/responsesStorageAdapter/threads/index.ts
5459
6172
  var threads2 = function(param) {
@@ -5466,9 +6179,9 @@ var threads2 = function(param) {
5466
6179
  };
5467
6180
  // src/adapters/storage/responsesStorageAdapter/threads/messages/post.ts
5468
6181
  var import_dayjs10 = __toESM(require("dayjs"), 1);
5469
- var import_radash14 = require("radash");
6182
+ var import_radash15 = require("radash");
5470
6183
  // src/lib/items/serializeItemAsMessage.ts
5471
- var import_radash13 = require("radash");
6184
+ var import_radash14 = require("radash");
5472
6185
  var serializeContent2 = function(param) {
5473
6186
  var item = param.item;
5474
6187
  if (item.type === "message") {
@@ -5544,7 +6257,7 @@ var serializeMetadata = function(param) {
5544
6257
  var serializeItemAsMessage = function(param) {
5545
6258
  var item = param.item, threadId = param.threadId, openaiAssistant = param.openaiAssistant, createdAt = param.createdAt, _param_runId = param.runId, runId = _param_runId === void 0 ? null : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp;
5546
6259
  return {
5547
- id: item.id || (0, import_radash13.uid)(24),
6260
+ id: item.id || (0, import_radash14.uid)(24),
5548
6261
  object: "thread.message",
5549
6262
  created_at: createdAt,
5550
6263
  thread_id: threadId,
@@ -5569,7 +6282,7 @@ var serializeItemAsMessage = function(param) {
5569
6282
  // src/adapters/storage/responsesStorageAdapter/threads/messages/post.ts
5570
6283
  var contentBlocksFromContent = function(param) {
5571
6284
  var content = param.content;
5572
- if ((0, import_radash14.isArray)(content)) {
6285
+ if ((0, import_radash15.isArray)(content)) {
5573
6286
  return content.map(function(item) {
5574
6287
  if (item.type === "text") {
5575
6288
  return {
@@ -5625,8 +6338,8 @@ var messageContentBlocks2 = function(param) {
5625
6338
  };
5626
6339
  var post16 = function(param) {
5627
6340
  var runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
5628
- return /*#__PURE__*/ function() {
5629
- var _ref = _async_to_generator(function(urlString, options) {
6341
+ return function(urlString, options) {
6342
+ return _async_to_generator(function() {
5630
6343
  var url, _url_pathname_match, threadId, body, role, content, _body_attachments, attachments, item, openaiAssistant;
5631
6344
  return _ts_generator(this, function(_state) {
5632
6345
  switch(_state.label){
@@ -5673,14 +6386,11 @@ var post16 = function(param) {
5673
6386
  ];
5674
6387
  }
5675
6388
  });
5676
- });
5677
- return function(urlString, options) {
5678
- return _ref.apply(this, arguments);
5679
- };
5680
- }();
6389
+ })();
6390
+ };
5681
6391
  };
5682
6392
  // src/adapters/storage/responsesStorageAdapter/threads/messages/get.ts
5683
- var import_radash15 = require("radash");
6393
+ var import_radash16 = require("radash");
5684
6394
  // src/lib/items/responseId.ts
5685
6395
  function responseId(param) {
5686
6396
  var conversation = param.conversation, itemId = param.itemId;
@@ -5720,15 +6430,15 @@ function responseId(param) {
5720
6430
  // src/adapters/storage/responsesStorageAdapter/threads/messages/get.ts
5721
6431
  var get14 = function(param) {
5722
6432
  var client = param.client, runAdapter = param.runAdapter;
5723
- return /*#__PURE__*/ function() {
5724
- var _ref = _async_to_generator(function(urlString) {
6433
+ return function(urlString) {
6434
+ return _async_to_generator(function() {
5725
6435
  var url, _url_pathname_match, threadId, _ref, limit, order, after, conversation, sortOrder, items, itemsWithRunIds, responseMap, timestampedItems, openaiAssistant;
5726
6436
  return _ts_generator(this, function(_state) {
5727
6437
  switch(_state.label){
5728
6438
  case 0:
5729
6439
  url = new URL(urlString);
5730
6440
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
5731
- _ref = (0, import_radash15.assign)({
6441
+ _ref = (0, import_radash16.assign)({
5732
6442
  limit: "20",
5733
6443
  order: "desc"
5734
6444
  }, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
@@ -5802,11 +6512,8 @@ var get14 = function(param) {
5802
6512
  ];
5803
6513
  }
5804
6514
  });
5805
- });
5806
- return function(urlString) {
5807
- return _ref.apply(this, arguments);
5808
- };
5809
- }();
6515
+ })();
6516
+ };
5810
6517
  };
5811
6518
  var mapItemsWithRunIds = function(param) {
5812
6519
  var conversation = param.conversation, items = param.items;
@@ -5820,13 +6527,13 @@ var mapItemsWithRunIds = function(param) {
5820
6527
  };
5821
6528
  });
5822
6529
  };
5823
- var fetchResponsesForItems = /*#__PURE__*/ function() {
5824
- var _ref = _async_to_generator(function(param) {
5825
- var client, items, responseIds, results, map;
6530
+ var fetchResponsesForItems = function(param) {
6531
+ var client = param.client, items = param.items;
6532
+ return _async_to_generator(function() {
6533
+ var responseIds, results, map;
5826
6534
  return _ts_generator(this, function(_state) {
5827
6535
  switch(_state.label){
5828
6536
  case 0:
5829
- client = param.client, items = param.items;
5830
6537
  responseIds = Array.from(new Set(items.map(function(param) {
5831
6538
  var runId = param.runId;
5832
6539
  return runId;
@@ -5853,11 +6560,8 @@ var fetchResponsesForItems = /*#__PURE__*/ function() {
5853
6560
  ];
5854
6561
  }
5855
6562
  });
5856
- });
5857
- return function fetchResponsesForItems(_) {
5858
- return _ref.apply(this, arguments);
5859
- };
5860
- }();
6563
+ })();
6564
+ };
5861
6565
  var assignTimestamps = function(param) {
5862
6566
  var items = param.items, responseMap = param.responseMap, sortOrder = param.sortOrder, conversationCreatedAt = param.conversationCreatedAt;
5863
6567
  var itemsWithTimestamps = items.map(function(entry) {
@@ -5948,8 +6652,8 @@ var messages3 = function(param) {
5948
6652
  };
5949
6653
  // src/adapters/storage/responsesStorageAdapter/threads/runs/get.ts
5950
6654
  var get15 = function() {
5951
- return /*#__PURE__*/ function() {
5952
- var _ref = _async_to_generator(function(urlString) {
6655
+ return function(urlString) {
6656
+ return _async_to_generator(function() {
5953
6657
  return _ts_generator(this, function(_state) {
5954
6658
  return [
5955
6659
  2,
@@ -5965,16 +6669,13 @@ var get15 = function() {
5965
6669
  })
5966
6670
  ];
5967
6671
  });
5968
- });
5969
- return function(urlString) {
5970
- return _ref.apply(this, arguments);
5971
- };
5972
- }();
6672
+ })();
6673
+ };
5973
6674
  };
5974
6675
  // src/adapters/storage/responsesStorageAdapter/threads/runs/post.ts
5975
- var import_radash16 = require("radash");
5976
- var import_dayjs11 = __toESM(require("dayjs"), 1);
5977
6676
  var import_radash17 = require("radash");
6677
+ var import_dayjs11 = __toESM(require("dayjs"), 1);
6678
+ var import_radash18 = require("radash");
5978
6679
  // src/lib/responses/serializeResponseAsRun.ts
5979
6680
  var serializeStatus = function(param) {
5980
6681
  var response = param.response;
@@ -6376,11 +7077,8 @@ function appendItemIdsToConversationMetadata(param) {
6376
7077
  changed: changed
6377
7078
  };
6378
7079
  }
6379
- function saveResponseItemsToConversationMetadata(_) {
6380
- return _saveResponseItemsToConversationMetadata.apply(this, arguments);
6381
- }
6382
- function _saveResponseItemsToConversationMetadata() {
6383
- _saveResponseItemsToConversationMetadata = _async_to_generator(function(param) {
7080
+ function saveResponseItemsToConversationMetadata(_0) {
7081
+ return _async_to_generator(function(param) {
6384
7082
  var client, threadId, responseId2, itemIds, conversation, _appendItemIdsToConversationMetadata, updated, changed;
6385
7083
  return _ts_generator(this, function(_state) {
6386
7084
  switch(_state.label){
@@ -6413,8 +7111,7 @@ function _saveResponseItemsToConversationMetadata() {
6413
7111
  ];
6414
7112
  }
6415
7113
  });
6416
- });
6417
- return _saveResponseItemsToConversationMetadata.apply(this, arguments);
7114
+ }).apply(this, arguments);
6418
7115
  }
6419
7116
  // src/adapters/storage/responsesStorageAdapter/threads/runs/post.ts
6420
7117
  var serializeTools2 = function(param) {
@@ -6448,8 +7145,8 @@ var defaultAssistant = {
6448
7145
  };
6449
7146
  var post17 = function(param) {
6450
7147
  var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6451
- return /*#__PURE__*/ function() {
6452
- var _ref = _async_to_generator(function(urlString, options) {
7148
+ return function(urlString, options) {
7149
+ return _async_to_generator(function() {
6453
7150
  var url, _url_pathname_match, threadId, body, assistant_id, stream, _ref, model, instructions, // additional_instructions,
6454
7151
  tools, metadata, response_format, truncation_strategy, _, _tmp, response, readableStream, _response_output, itemIds, data;
6455
7152
  return _ts_generator(this, function(_state) {
@@ -6462,7 +7159,7 @@ var post17 = function(param) {
6462
7159
  }
6463
7160
  body = JSON.parse(options.body);
6464
7161
  assistant_id = body.assistant_id, stream = body.stream;
6465
- _ = (0, import_radash17.assign);
7162
+ _ = (0, import_radash18.assign);
6466
7163
  _tmp = [
6467
7164
  {},
6468
7165
  defaultAssistant
@@ -6518,19 +7215,16 @@ var post17 = function(param) {
6518
7215
  runAdapter.handleRun({
6519
7216
  threadId: threadId,
6520
7217
  response: response,
6521
- onEvent: /*#__PURE__*/ function() {
6522
- var _ref = _async_to_generator(function(event) {
7218
+ onEvent: function(event) {
7219
+ return _async_to_generator(function() {
6523
7220
  return _ts_generator(this, function(_state) {
6524
7221
  return [
6525
7222
  2,
6526
7223
  controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"))
6527
7224
  ];
6528
7225
  });
6529
- });
6530
- return function(event) {
6531
- return _ref.apply(this, arguments);
6532
- };
6533
- }()
7226
+ })();
7227
+ }
6534
7228
  })
6535
7229
  ];
6536
7230
  case 1:
@@ -6545,7 +7239,7 @@ var post17 = function(param) {
6545
7239
  event = {
6546
7240
  event: "thread.run.failed",
6547
7241
  data: {
6548
- id: (0, import_radash16.uid)(24),
7242
+ id: (0, import_radash17.uid)(24),
6549
7243
  failed_at: (0, import_dayjs11.default)().unix(),
6550
7244
  last_error: {
6551
7245
  code: "server_error",
@@ -6622,11 +7316,8 @@ var post17 = function(param) {
6622
7316
  ];
6623
7317
  }
6624
7318
  });
6625
- });
6626
- return function(urlString, options) {
6627
- return _ref.apply(this, arguments);
6628
- };
6629
- }();
7319
+ })();
7320
+ };
6630
7321
  };
6631
7322
  // src/adapters/storage/responsesStorageAdapter/threads/runs/index.ts
6632
7323
  var runs2 = function(param) {
@@ -6643,8 +7334,8 @@ var runs2 = function(param) {
6643
7334
  // src/adapters/storage/responsesStorageAdapter/threads/run/get.ts
6644
7335
  var get16 = function(param) {
6645
7336
  var client = param.client, runAdapter = param.runAdapter;
6646
- return /*#__PURE__*/ function() {
6647
- var _ref = _async_to_generator(function(urlString) {
7337
+ return function(urlString) {
7338
+ return _async_to_generator(function() {
6648
7339
  var url, _url_pathname_match, _threadId, runId, response, data, _tmp;
6649
7340
  return _ts_generator(this, function(_state) {
6650
7341
  switch(_state.label){
@@ -6684,11 +7375,8 @@ var get16 = function(param) {
6684
7375
  ];
6685
7376
  }
6686
7377
  });
6687
- });
6688
- return function(urlString) {
6689
- return _ref.apply(this, arguments);
6690
- };
6691
- }();
7378
+ })();
7379
+ };
6692
7380
  };
6693
7381
  // src/adapters/storage/responsesStorageAdapter/threads/run/index.ts
6694
7382
  var run2 = function(param) {
@@ -6701,13 +7389,13 @@ var run2 = function(param) {
6701
7389
  };
6702
7390
  };
6703
7391
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
6704
- var import_radash21 = require("radash");
7392
+ var import_radash22 = require("radash");
6705
7393
  // src/lib/items/serializeItemAsMessageCreationRunStep.ts
6706
7394
  var import_dayjs12 = __toESM(require("dayjs"), 1);
6707
- var import_radash18 = require("radash");
7395
+ var import_radash19 = require("radash");
6708
7396
  function serializeItemAsMessageCreationRunStep(param) {
6709
- var item = param.item, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash18.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs12.default)().unix() : _param_completedAt;
6710
- var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash18.uid)(18));
7397
+ var item = param.item, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash19.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs12.default)().unix() : _param_completedAt;
7398
+ var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash19.uid)(18));
6711
7399
  var base = {
6712
7400
  id: itemId,
6713
7401
  object: "thread.run.step",
@@ -6770,7 +7458,7 @@ function serializeItemAsMessageCreationRunStep(param) {
6770
7458
  }
6771
7459
  // src/lib/items/serializeItemAsFunctionCallRunStep.ts
6772
7460
  var import_dayjs13 = __toESM(require("dayjs"), 1);
6773
- var import_radash19 = require("radash");
7461
+ var import_radash20 = require("radash");
6774
7462
  var serializeFunctionCallOutput = function(param) {
6775
7463
  var functionCallOutput = param.functionCallOutput;
6776
7464
  if (!functionCallOutput) return null;
@@ -6780,8 +7468,8 @@ var serializeFunctionCallOutput = function(param) {
6780
7468
  return JSON.stringify(functionCallOutput.output);
6781
7469
  };
6782
7470
  var serializeItemAsFunctionCallRunStep = function(param) {
6783
- var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash19.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs13.default)().unix() : _param_completedAt;
6784
- var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash19.uid)(18));
7471
+ var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash20.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs13.default)().unix() : _param_completedAt;
7472
+ var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash20.uid)(18));
6785
7473
  var base = {
6786
7474
  id: itemId,
6787
7475
  object: "thread.run.step",
@@ -7111,10 +7799,10 @@ var serializeItemAsCodeInterpreterCallRunStep = function(param) {
7111
7799
  };
7112
7800
  // src/lib/items/serializeItemAsComputerCallRunStep.ts
7113
7801
  var import_dayjs19 = __toESM(require("dayjs"), 1);
7114
- var import_radash20 = require("radash");
7802
+ var import_radash21 = require("radash");
7115
7803
  var serializeItemAsComputerCallRunStep = function(param) {
7116
- var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash20.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs19.default)().unix() : _param_completedAt;
7117
- var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash20.uid)(18));
7804
+ var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash21.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs19.default)().unix() : _param_completedAt;
7805
+ var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash21.uid)(18));
7118
7806
  var base = {
7119
7807
  id: itemId,
7120
7808
  object: "thread.run.step",
@@ -7217,8 +7905,8 @@ var serializeItemAsReasoningRunStep = function(param) {
7217
7905
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
7218
7906
  var get17 = function(param) {
7219
7907
  var client = param.client, runAdapter = param.runAdapter;
7220
- return /*#__PURE__*/ function() {
7221
- var _ref = _async_to_generator(function(urlString) {
7908
+ return function(urlString) {
7909
+ return _async_to_generator(function() {
7222
7910
  var _this, url, _url_pathname_match, threadId, runId, response, latestToolCallItem, functionCallOutputItems, computerCallOutputItems, items, openaiAssistant, data, _id;
7223
7911
  return _ts_generator(this, function(_state) {
7224
7912
  switch(_state.label){
@@ -7367,7 +8055,7 @@ var get17 = function(param) {
7367
8055
  new Response(JSON.stringify({
7368
8056
  data: data,
7369
8057
  has_more: false,
7370
- last_id: (_id = (_this = (0, import_radash21.last)(response.output)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
8058
+ last_id: (_id = (_this = (0, import_radash22.last)(response.output)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
7371
8059
  }), {
7372
8060
  status: 200,
7373
8061
  headers: {
@@ -7377,11 +8065,8 @@ var get17 = function(param) {
7377
8065
  ];
7378
8066
  }
7379
8067
  });
7380
- });
7381
- return function(urlString) {
7382
- return _ref.apply(this, arguments);
7383
- };
7384
- }();
8068
+ })();
8069
+ };
7385
8070
  };
7386
8071
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/index.ts
7387
8072
  var steps2 = function(param) {
@@ -7470,8 +8155,8 @@ var truncation2 = function(param) {
7470
8155
  };
7471
8156
  var post18 = function(param) {
7472
8157
  var client = param.client, runAdapter = param.runAdapter;
7473
- return /*#__PURE__*/ function() {
7474
- var _ref = _async_to_generator(function(urlString, options) {
8158
+ return function(urlString, options) {
8159
+ return _async_to_generator(function() {
7475
8160
  var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, toolCallOutputItems, input, previousResponse, openaiAssistant, response, readableStream;
7476
8161
  return _ts_generator(this, function(_state) {
7477
8162
  switch(_state.label){
@@ -7562,19 +8247,16 @@ var post18 = function(param) {
7562
8247
  runAdapter.handleRun({
7563
8248
  threadId: threadId,
7564
8249
  response: response,
7565
- onEvent: /*#__PURE__*/ function() {
7566
- var _ref = _async_to_generator(function(event) {
8250
+ onEvent: function(event) {
8251
+ return _async_to_generator(function() {
7567
8252
  return _ts_generator(this, function(_state) {
7568
8253
  return [
7569
8254
  2,
7570
8255
  controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"))
7571
8256
  ];
7572
8257
  });
7573
- });
7574
- return function(event) {
7575
- return _ref.apply(this, arguments);
7576
- };
7577
- }()
8258
+ })();
8259
+ }
7578
8260
  })
7579
8261
  ];
7580
8262
  case 1:
@@ -7598,11 +8280,8 @@ var post18 = function(param) {
7598
8280
  ];
7599
8281
  }
7600
8282
  });
7601
- });
7602
- return function(urlString, options) {
7603
- return _ref.apply(this, arguments);
7604
- };
7605
- }();
8283
+ })();
8284
+ };
7606
8285
  };
7607
8286
  // src/adapters/storage/responsesStorageAdapter/threads/runs/submitToolOutputs/index.ts
7608
8287
  var submitToolOutputs2 = function(param) {
@@ -7617,8 +8296,8 @@ var submitToolOutputs2 = function(param) {
7617
8296
  // src/adapters/storage/responsesStorageAdapter/assistants/get.ts
7618
8297
  var get18 = function(param) {
7619
8298
  var runAdapter = param.runAdapter;
7620
- return /*#__PURE__*/ function() {
7621
- var _ref = _async_to_generator(function(_urlString) {
8299
+ return function(_urlString) {
8300
+ return _async_to_generator(function() {
7622
8301
  var _, _1, _tmp;
7623
8302
  return _ts_generator(this, function(_state) {
7624
8303
  switch(_state.label){
@@ -7660,32 +8339,31 @@ var get18 = function(param) {
7660
8339
  ];
7661
8340
  }
7662
8341
  });
7663
- });
7664
- return function(_urlString) {
7665
- return _ref.apply(this, arguments);
7666
- };
7667
- }();
8342
+ })();
8343
+ };
7668
8344
  };
7669
8345
  // src/adapters/storage/responsesStorageAdapter/assistants/post.ts
7670
8346
  var post19 = function() {
7671
- return /*#__PURE__*/ _async_to_generator(function() {
7672
- return _ts_generator(this, function(_state) {
7673
- return [
7674
- 2,
7675
- new Response(JSON.stringify({
7676
- error: {
7677
- message: "Assistant creation is not implemented for the Responses storage adapter.",
7678
- type: "not_implemented"
7679
- }
7680
- }), {
7681
- status: 501,
7682
- headers: {
7683
- "Content-Type": "application/json"
7684
- }
7685
- })
7686
- ];
7687
- });
7688
- });
8347
+ return function() {
8348
+ return _async_to_generator(function() {
8349
+ return _ts_generator(this, function(_state) {
8350
+ return [
8351
+ 2,
8352
+ new Response(JSON.stringify({
8353
+ error: {
8354
+ message: "Assistant creation is not implemented for the Responses storage adapter.",
8355
+ type: "not_implemented"
8356
+ }
8357
+ }), {
8358
+ status: 501,
8359
+ headers: {
8360
+ "Content-Type": "application/json"
8361
+ }
8362
+ })
8363
+ ];
8364
+ });
8365
+ })();
8366
+ };
7689
8367
  };
7690
8368
  // src/adapters/storage/responsesStorageAdapter/assistants/index.ts
7691
8369
  var assistants2 = function(param) {
@@ -7734,7 +8412,7 @@ var responsesStorageAdapter = function() {
7734
8412
  };
7735
8413
  // src/adapters/run/responsesRunAdapter/index.ts
7736
8414
  var import_dayjs21 = __toESM(require("dayjs"), 1);
7737
- var import_radash22 = require("radash");
8415
+ var import_radash23 = require("radash");
7738
8416
  var serializeToolCalls2 = function(param) {
7739
8417
  var toolCalls = param.toolCalls;
7740
8418
  return toolCalls.map(function(toolCall) {
@@ -7764,14 +8442,13 @@ var responsesRunAdapter = function(param) {
7764
8442
  return p.then(function() {});
7765
8443
  } : _param_waitUntil;
7766
8444
  var cachedOpenaiAssistant = null;
7767
- var getOpenaiAssistant = /*#__PURE__*/ function() {
7768
- var _ref = _async_to_generator(function() {
7769
- var _ref, tmp, _ref1, _ref_id, id, args, _tmp;
7770
- var _arguments = arguments;
8445
+ var getOpenaiAssistant = function() {
8446
+ var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, tmp = _ref.select, _ref1 = tmp === void 0 ? {} : tmp, _ref_id = _ref1.id, id = _ref_id === void 0 ? false : _ref_id;
8447
+ return _async_to_generator(function() {
8448
+ var args, _tmp;
7771
8449
  return _ts_generator(this, function(_state) {
7772
8450
  switch(_state.label){
7773
8451
  case 0:
7774
- _ref = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}, tmp = _ref.select, _ref1 = tmp === void 0 ? {} : tmp, _ref_id = _ref1.id, id = _ref_id === void 0 ? false : _ref_id;
7775
8452
  args = {
7776
8453
  select: {
7777
8454
  id: id
@@ -7812,18 +8489,15 @@ var responsesRunAdapter = function(param) {
7812
8489
  ];
7813
8490
  }
7814
8491
  });
7815
- });
7816
- return function getOpenaiAssistant() {
7817
- return _ref.apply(this, arguments);
7818
- };
7819
- }();
7820
- var handleRun = /*#__PURE__*/ function() {
7821
- var _ref = _async_to_generator(function(param) {
7822
- var client, threadId, response, onEvent2, responseCreatedResponse, responseCompletedResponse, toolCalls, mcpCalls, codeInterpreterCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, _tmp, _tmp1, _tmp2, _tmp3, _tmp4, _tmp5, _tmp6, _tmp7, _tmp8, _tmp9, _tmp10, _tmp11, _tmp12, _tmp13, _tmp14, _tmp15, _tmp16, _tmp17, _tmp18, _tmp19, _tmp20, _tmp21, _tmp22, _tmp23, _tmp24, _tmp25, _tmp26, _tmp27, _tmp28, _tmp29, _tmp30, _tmp31, _tmp32, _tmp33, _tmp34, _tmp35, _tmp36, _tmp37, _tmp38, _tmp39, _tmp40, _tmp41, _tmp42, _tmp43, _tmp44, _tmp45, _tmp46, _tmp47, _tmp48, _tmp49, _tmp50, _tmp51, _tmp52, _tmp53, _tmp54, _tmp55, _tmp56, _tmp57, _tmp58, _tmp59, _tmp60, _tmp61, _tmp62, _tmp63, _tmp64, _tmp65, _tmp66, _tmp67, _tmp68, _tmp69, _tmp70, _tmp71, _tmp72, _tmp73, _tmp74, _tmp75, _tmp76, _tmp77, _tmp78, _tmp79, _tmp80, _tmp81, _tmp82, _tmp83, _tmp84, _tmp85, _tmp86, _tmp87, _tmp88, _tmp89, _tmp90, _tmp91, _tmp92, _tmp93, _tmp94, _tmp95, toolCall, mcpCall, _tmp96, _tmp97, _tmp98, _tmp99, err, _responseCompletedResponse_output, toolCalls2, serializedRun, _tmp100, e, _tmp101, _tmp102;
8492
+ })();
8493
+ };
8494
+ var handleRun = function(param) {
8495
+ var client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
8496
+ return _async_to_generator(function() {
8497
+ var responseCreatedResponse, responseCompletedResponse, toolCalls, mcpCalls, codeInterpreterCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, _tmp, _tmp1, _tmp2, _tmp3, _tmp4, _tmp5, _tmp6, _tmp7, _tmp8, _tmp9, _tmp10, _tmp11, _tmp12, _tmp13, _tmp14, _tmp15, _tmp16, _tmp17, _tmp18, _tmp19, _tmp20, _tmp21, _tmp22, _tmp23, _tmp24, _tmp25, _tmp26, _tmp27, _tmp28, _tmp29, _tmp30, _tmp31, _tmp32, _tmp33, _tmp34, _tmp35, _tmp36, _tmp37, _tmp38, _tmp39, _tmp40, _tmp41, _tmp42, _tmp43, _tmp44, _tmp45, _tmp46, _tmp47, _tmp48, _tmp49, _tmp50, _tmp51, _tmp52, _tmp53, _tmp54, _tmp55, _tmp56, _tmp57, _tmp58, _tmp59, _tmp60, _tmp61, _tmp62, _tmp63, _tmp64, _tmp65, _tmp66, _tmp67, _tmp68, _tmp69, _tmp70, _tmp71, _tmp72, _tmp73, _tmp74, _tmp75, _tmp76, _tmp77, _tmp78, _tmp79, _tmp80, _tmp81, _tmp82, _tmp83, _tmp84, _tmp85, _tmp86, _tmp87, _tmp88, _tmp89, _tmp90, _tmp91, _tmp92, _tmp93, _tmp94, _tmp95, toolCall, mcpCall, _tmp96, _tmp97, _tmp98, _tmp99, err, _responseCompletedResponse_output, toolCalls2, serializedRun, _tmp100, e, _tmp101, _tmp102;
7823
8498
  return _ts_generator(this, function(_state) {
7824
8499
  switch(_state.label){
7825
8500
  case 0:
7826
- client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
7827
8501
  responseCreatedResponse = null;
7828
8502
  responseCompletedResponse = null;
7829
8503
  toolCalls = {};
@@ -9675,7 +10349,7 @@ var responsesRunAdapter = function(param) {
9675
10349
  event: "thread.run.failed"
9676
10350
  };
9677
10351
  _tmp102 = {
9678
- id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash22.uid)(18)),
10352
+ id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash23.uid)(18)),
9679
10353
  object: "thread.run",
9680
10354
  thread_id: threadId
9681
10355
  };
@@ -9704,8 +10378,8 @@ var responsesRunAdapter = function(param) {
9704
10378
  155
9705
10379
  ];
9706
10380
  case 154:
9707
- waitUntil(new Promise(/*#__PURE__*/ function() {
9708
- var _ref = _async_to_generator(function(resolve) {
10381
+ waitUntil(new Promise(function(resolve) {
10382
+ return _async_to_generator(function() {
9709
10383
  return _ts_generator(this, function(_state) {
9710
10384
  switch(_state.label){
9711
10385
  case 0:
@@ -9732,11 +10406,8 @@ var responsesRunAdapter = function(param) {
9732
10406
  ];
9733
10407
  }
9734
10408
  });
9735
- });
9736
- return function(resolve) {
9737
- return _ref.apply(this, arguments);
9738
- };
9739
- }()));
10409
+ })();
10410
+ }));
9740
10411
  return [
9741
10412
  7
9742
10413
  ];
@@ -9746,11 +10417,8 @@ var responsesRunAdapter = function(param) {
9746
10417
  ];
9747
10418
  }
9748
10419
  });
9749
- });
9750
- return function handleRun(_) {
9751
- return _ref.apply(this, arguments);
9752
- };
9753
- }();
10420
+ })();
10421
+ };
9754
10422
  return {
9755
10423
  handleRun: handleRun,
9756
10424
  getOpenaiAssistant: getOpenaiAssistant