supercompat 2.0.0 → 2.1.0

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.js CHANGED
@@ -168,9 +168,6 @@ function _object_spread_props(target, source) {
168
168
  function _sliced_to_array(arr, i) {
169
169
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
170
170
  }
171
- function _to_array(arr) {
172
- return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
173
- }
174
171
  function _to_consumable_array(arr) {
175
172
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
176
173
  }
@@ -291,7 +288,6 @@ function _ts_values(o) {
291
288
  };
292
289
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
293
290
  }
294
- var _mistral, _mistral1;
295
291
  import OpenAI from "openai";
296
292
  // src/supercompatFetch/requestHandlers.ts
297
293
  import { assign, partob } from "radash";
@@ -502,11 +498,6 @@ var post = function(param) {
502
498
  ];
503
499
  case 4:
504
500
  error = _state.sent();
505
- console.dir({
506
- error: error
507
- }, {
508
- depth: null
509
- });
510
501
  return [
511
502
  2,
512
503
  new Response(JSON.stringify({
@@ -697,11 +688,6 @@ var post2 = function(param) {
697
688
  ];
698
689
  case 4:
699
690
  error = _state.sent();
700
- console.dir({
701
- error: error
702
- }, {
703
- depth: null
704
- });
705
691
  return [
706
692
  2,
707
693
  new Response(JSON.stringify({
@@ -743,690 +729,783 @@ var openaiClientAdapter = function(param) {
743
729
  })
744
730
  };
745
731
  };
732
+ // src/adapters/client/mistralClientAdapter/completions/post.ts
733
+ var post3 = function(param) {
734
+ var mistral = param.mistral;
735
+ return function() {
736
+ var _ref = _async_to_generator(function(_url, options) {
737
+ var body, response, stream, data, error;
738
+ return _ts_generator(this, function(_state) {
739
+ switch(_state.label){
740
+ case 0:
741
+ body = JSON.parse(options.body);
742
+ if (!body.stream) return [
743
+ 3,
744
+ 2
745
+ ];
746
+ return [
747
+ 4,
748
+ mistral.chatStream(body)
749
+ ];
750
+ case 1:
751
+ response = _state.sent();
752
+ stream = new ReadableStream({
753
+ start: function start(controller) {
754
+ return _async_to_generator(function() {
755
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, err;
756
+ return _ts_generator(this, function(_state) {
757
+ switch(_state.label){
758
+ case 0:
759
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
760
+ _state.label = 1;
761
+ case 1:
762
+ _state.trys.push([
763
+ 1,
764
+ 6,
765
+ 7,
766
+ 12
767
+ ]);
768
+ _iterator = _async_iterator(response);
769
+ _state.label = 2;
770
+ case 2:
771
+ return [
772
+ 4,
773
+ _iterator.next()
774
+ ];
775
+ case 3:
776
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
777
+ 3,
778
+ 5
779
+ ];
780
+ _value = _step.value;
781
+ chunk = _value;
782
+ controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
783
+ _state.label = 4;
784
+ case 4:
785
+ _iteratorAbruptCompletion = false;
786
+ return [
787
+ 3,
788
+ 2
789
+ ];
790
+ case 5:
791
+ return [
792
+ 3,
793
+ 12
794
+ ];
795
+ case 6:
796
+ err = _state.sent();
797
+ _didIteratorError = true;
798
+ _iteratorError = err;
799
+ return [
800
+ 3,
801
+ 12
802
+ ];
803
+ case 7:
804
+ _state.trys.push([
805
+ 7,
806
+ ,
807
+ 10,
808
+ 11
809
+ ]);
810
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
811
+ 3,
812
+ 9
813
+ ];
814
+ return [
815
+ 4,
816
+ _iterator.return()
817
+ ];
818
+ case 8:
819
+ _state.sent();
820
+ _state.label = 9;
821
+ case 9:
822
+ return [
823
+ 3,
824
+ 11
825
+ ];
826
+ case 10:
827
+ if (_didIteratorError) {
828
+ throw _iteratorError;
829
+ }
830
+ return [
831
+ 7
832
+ ];
833
+ case 11:
834
+ return [
835
+ 7
836
+ ];
837
+ case 12:
838
+ controller.close();
839
+ return [
840
+ 2
841
+ ];
842
+ }
843
+ });
844
+ })();
845
+ }
846
+ });
847
+ return [
848
+ 2,
849
+ new Response(stream, {
850
+ headers: {
851
+ "Content-Type": "text/event-stream"
852
+ }
853
+ })
854
+ ];
855
+ case 2:
856
+ _state.trys.push([
857
+ 2,
858
+ 4,
859
+ ,
860
+ 5
861
+ ]);
862
+ return [
863
+ 4,
864
+ mistral.chat(body)
865
+ ];
866
+ case 3:
867
+ data = _state.sent();
868
+ return [
869
+ 2,
870
+ new Response(JSON.stringify({
871
+ data: data
872
+ }), {
873
+ status: 200,
874
+ headers: {
875
+ "Content-Type": "application/json"
876
+ }
877
+ })
878
+ ];
879
+ case 4:
880
+ error = _state.sent();
881
+ return [
882
+ 2,
883
+ new Response(JSON.stringify({
884
+ error: error
885
+ }), {
886
+ status: 500,
887
+ headers: {
888
+ "Content-Type": "application/json"
889
+ }
890
+ })
891
+ ];
892
+ case 5:
893
+ return [
894
+ 2
895
+ ];
896
+ }
897
+ });
898
+ });
899
+ return function(_url, options) {
900
+ return _ref.apply(this, arguments);
901
+ };
902
+ }();
903
+ };
904
+ // src/adapters/client/mistralClientAdapter/completions/index.ts
905
+ var completions3 = function(param) {
906
+ var mistral = param.mistral;
907
+ return {
908
+ post: post3({
909
+ mistral: mistral
910
+ })
911
+ };
912
+ };
746
913
  // src/adapters/client/mistralClientAdapter/index.ts
747
914
  var mistralClientAdapter = function(param) {
748
915
  var mistral = param.mistral;
749
916
  return {
750
- chat: {
751
- completions: {
752
- // @ts-ignore-next-line
753
- create: function() {
754
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
755
- args[_key] = arguments[_key];
756
- }
757
- return(// @ts-ignore-next-line
758
- args[0].stream ? (_mistral = mistral).chatStream.apply(_mistral, _to_consumable_array(args)) : (_mistral1 = mistral).chat.apply(_mistral1, _to_consumable_array(args)));
759
- }
760
- }
761
- }
917
+ "^/v1/chat/completions$": completions3({
918
+ mistral: mistral
919
+ })
762
920
  };
763
921
  };
764
- // src/adapters/client/perplexityClientAdapter/index.ts
922
+ // src/adapters/client/perplexityClientAdapter/completions/post.ts
765
923
  var agentSideRoles = [
766
924
  "assistant",
767
925
  "system"
768
926
  ];
769
- var perplexityClientAdapter = function(param) {
927
+ var post4 = function(param) {
770
928
  var perplexity = param.perplexity;
771
- return {
772
- chat: {
773
- completions: {
774
- create: function() {
775
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
776
- args[_key] = arguments[_key];
777
- }
778
- var _perplexity_chat_completions;
779
- var _args = _to_array(args), firstArg = _args[0], restArgs = _args.slice(1);
780
- var messages4 = [];
781
- firstArg.messages.forEach(function(message, index) {
782
- messages4.push(message);
783
- var nextMessage = firstArg.messages[index + 1];
784
- if (!nextMessage) return;
785
- if (message.role === "user" && nextMessage.role === "user") {
786
- messages4.push({
787
- role: "assistant",
788
- content: ""
789
- });
790
- } else if (agentSideRoles.includes(message.role) && agentSideRoles.includes(nextMessage.role)) {
791
- messages4.push({
792
- role: "user",
793
- content: ""
794
- });
795
- }
796
- });
797
- return (_perplexity_chat_completions = perplexity.chat.completions).create.apply(_perplexity_chat_completions, [
798
- _object_spread_props(_object_spread({}, firstArg), {
799
- messages: messages4
800
- })
801
- ].concat(_to_consumable_array(restArgs)));
802
- }
803
- }
804
- }
805
- };
806
- };
807
- // src/adapters/client/anthropicClientAdapter/index.ts
808
- var anthropicClientAdapter = function(param) {
809
- var anthropic = param.anthropic;
810
- return {
811
- chat: {
812
- completions: {
813
- create: function() {
814
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
815
- args[_key] = arguments[_key];
816
- }
817
- var _args = _to_array(args), firstArg = _args[0], secondArg = _args[1], restArgs = _args.slice(2);
818
- var messages4 = firstArg.messages;
819
- if (firstArg.messages[0].role != "user") {
820
- messages4.unshift({
821
- role: "user",
822
- content: "-"
929
+ return function() {
930
+ var _ref = _async_to_generator(function(_url, options) {
931
+ var body, messages3, response, stream, data, error;
932
+ return _ts_generator(this, function(_state) {
933
+ switch(_state.label){
934
+ case 0:
935
+ body = JSON.parse(options.body);
936
+ messages3 = [];
937
+ body.messages.forEach(function(message, index) {
938
+ messages3.push(message);
939
+ var nextMessage = body.messages[index + 1];
940
+ if (!nextMessage) return;
941
+ if (message.role === "user" && nextMessage.role === "user") {
942
+ messages3.push({
943
+ role: "assistant",
944
+ content: ""
945
+ });
946
+ } else if (agentSideRoles.includes(message.role) && agentSideRoles.includes(nextMessage.role)) {
947
+ messages3.push({
948
+ role: "user",
949
+ content: ""
950
+ });
951
+ }
823
952
  });
824
- }
825
- var resultFirstArg = _object_spread_props(_object_spread({}, firstArg), {
826
- messages: messages4
827
- });
828
- var _secondArg_headers;
829
- var resultSecondArg = _object_spread_props(_object_spread({}, secondArg), {
830
- headers: _object_spread_props(_object_spread({}, (_secondArg_headers = secondArg === null || secondArg === void 0 ? void 0 : secondArg.headers) !== null && _secondArg_headers !== void 0 ? _secondArg_headers : {}), {
831
- "anthropic-beta": "tools-2024-04-04"
832
- })
833
- });
834
- if (args[0].stream) {
835
- var _anthropic_messages;
836
- return (_anthropic_messages = anthropic.messages).stream.apply(_anthropic_messages, [
837
- resultFirstArg,
838
- resultSecondArg
839
- ].concat(_to_consumable_array(restArgs)));
840
- } else {
841
- var _anthropic_messages1;
842
- return (_anthropic_messages1 = anthropic.messages).create.apply(_anthropic_messages1, [
843
- resultFirstArg,
844
- resultSecondArg
845
- ].concat(_to_consumable_array(restArgs)));
846
- }
847
- }
848
- }
849
- }
850
- };
851
- };
852
- // src/adapters/run/completionsRunAdapter/index.ts
853
- import _ from "lodash";
854
- import { uid, omit, isEmpty } from "radash";
855
- import dayjs from "dayjs";
856
- // src/adapters/run/completionsRunAdapter/messages/index.ts
857
- import { flat } from "radash";
858
- // src/adapters/run/completionsRunAdapter/messages/serializeMessage.ts
859
- var serializeToolCall = function(param) {
860
- var toolCall = param.toolCall;
861
- var _toolCall_function_output;
862
- return {
863
- tool_call_id: toolCall.id,
864
- role: "tool",
865
- name: toolCall.function.name,
866
- content: (_toolCall_function_output = toolCall.function.output) !== null && _toolCall_function_output !== void 0 ? _toolCall_function_output : ""
867
- };
868
- };
869
- var serializeMessageWithContent = function(param) {
870
- var message = param.message;
871
- var _message_metadata;
872
- return _object_spread({
873
- role: message.role,
874
- content: serializeContent({
875
- content: message.content
876
- })
877
- }, (message === null || message === void 0 ? void 0 : (_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) ? {
878
- tool_calls: message.metadata.toolCalls
879
- } : {});
880
- };
881
- var serializeContent = function(param) {
882
- var content = param.content;
883
- return content.map(function(content2) {
884
- return content2.text.value;
885
- }).join("\n");
886
- };
887
- var serializeMessage = function(param) {
888
- var message = param.message;
889
- var _message_metadata;
890
- var result = [
891
- serializeMessageWithContent({
892
- message: message
893
- })
894
- ];
895
- var run2 = message.run;
896
- if (!run2) return result;
897
- var messageToolCalls = ((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) || [];
898
- messageToolCalls.forEach(function(tc) {
899
- var runStep = run2.runSteps.find(function(rs) {
900
- if (rs.type !== "tool_calls") return false;
901
- return rs.step_details.tool_calls.some(function(rsTc) {
902
- if (rsTc.type !== "function") return false;
903
- return rsTc.id === tc.id;
904
- });
905
- });
906
- if (!runStep) return;
907
- var toolCall = runStep.step_details.tool_calls.find(function(rsTc) {
908
- if (rsTc.type !== "function") return false;
909
- return rsTc.id === tc.id;
910
- });
911
- result.push(serializeToolCall({
912
- toolCall: toolCall
913
- }));
914
- });
915
- return result;
916
- };
917
- // src/adapters/run/completionsRunAdapter/messages/index.ts
918
- var messages = function() {
919
- var _ref = _async_to_generator(function(param) {
920
- var run2, getMessages2, _, _1;
921
- return _ts_generator(this, function(_state) {
922
- switch(_state.label){
923
- case 0:
924
- run2 = param.run, getMessages2 = param.getMessages;
925
- _1 = (_ = _to_consumable_array(run2.instructions ? [
926
- {
927
- role: "system",
928
- content: run2.instructions
929
- }
930
- ] : [])).concat;
931
- return [
932
- 4,
933
- getMessages2()
934
- ];
935
- case 1:
936
- return [
937
- 2,
938
- _1.apply(_, [
939
- _to_consumable_array.apply(void 0, [
940
- flat.apply(void 0, [
941
- _state.sent().map(function(message) {
942
- return serializeMessage({
943
- message: message
944
- });
945
- })
946
- ])
947
- ])
948
- ])
949
- ];
950
- }
951
- });
952
- });
953
- return function messages(_) {
954
- return _ref.apply(this, arguments);
955
- };
956
- }();
957
- // src/adapters/run/completionsRunAdapter/index.ts
958
- var updatedToolCall = function(param) {
959
- var toolCall = param.toolCall, delta = param.delta;
960
- if (!toolCall) return omit(delta, [
961
- "index"
962
- ]);
963
- var result = _.cloneDeep(toolCall);
964
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
965
- try {
966
- for(var _iterator = Object.entries(delta.function)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
967
- var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
968
- var _result_function_key;
969
- result.function[key] = "".concat((_result_function_key = result.function[key]) !== null && _result_function_key !== void 0 ? _result_function_key : "").concat(value);
970
- }
971
- } catch (err) {
972
- _didIteratorError = true;
973
- _iteratorError = err;
974
- } finally{
975
- try {
976
- if (!_iteratorNormalCompletion && _iterator.return != null) {
977
- _iterator.return();
978
- }
979
- } finally{
980
- if (_didIteratorError) {
981
- throw _iteratorError;
982
- }
983
- }
984
- }
985
- return result;
986
- };
987
- var toolCallsData = function(param) {
988
- var prevToolCalls = param.prevToolCalls, delta = param.delta;
989
- if (!prevToolCalls) {
990
- return delta.tool_calls.map(function(tc) {
991
- return _object_spread({
992
- id: uid(24),
993
- type: "function"
994
- }, omit(tc, [
995
- "index"
996
- ]));
997
- });
998
- }
999
- var newToolCalls = _.cloneDeep(prevToolCalls);
1000
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1001
- try {
1002
- for(var _iterator = delta.tool_calls[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1003
- var runStepDelta = _step.value;
1004
- newToolCalls[runStepDelta.index] = updatedToolCall({
1005
- toolCall: newToolCalls[runStepDelta.index],
1006
- delta: runStepDelta
1007
- });
1008
- }
1009
- } catch (err) {
1010
- _didIteratorError = true;
1011
- _iteratorError = err;
1012
- } finally{
1013
- try {
1014
- if (!_iteratorNormalCompletion && _iterator.return != null) {
1015
- _iterator.return();
1016
- }
1017
- } finally{
1018
- if (_didIteratorError) {
1019
- throw _iteratorError;
1020
- }
1021
- }
1022
- }
1023
- return newToolCalls;
1024
- };
1025
- var completionsRunAdapter = function() {
1026
- return function() {
1027
- var _ref = _async_to_generator(function(param) {
1028
- var clientAdapter, run2, onEvent2, getMessages2, client, opts, _tmp, providerResponse, e, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, _delta_content, err;
1029
- return _ts_generator(this, function(_state) {
1030
- switch(_state.label){
1031
- case 0:
1032
- clientAdapter = param.client, run2 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
1033
- if (run2.status !== "queued") return [
953
+ if (!body.stream) return [
954
+ 3,
1034
955
  2
1035
956
  ];
1036
- client = supercompat({
1037
- client: clientAdapter,
1038
- storage: function() {},
1039
- // @ts-ignore-next-line
1040
- runAdapter: {}
1041
- });
1042
- onEvent2({
1043
- event: "thread.run.in_progress",
1044
- data: _object_spread_props(_object_spread({}, run2), {
1045
- status: "in_progress"
1046
- })
1047
- });
1048
- _tmp = {};
1049
957
  return [
1050
958
  4,
1051
- messages({
1052
- run: run2,
1053
- getMessages: getMessages2
1054
- })
959
+ perplexity.chat.completions.create(body)
1055
960
  ];
1056
961
  case 1:
1057
- opts = _object_spread.apply(void 0, [
1058
- (_tmp.messages = _state.sent(), _tmp.model = run2.model, _tmp.stream = true, _tmp.response_format = run2.response_format, _tmp),
1059
- isEmpty(run2.tools) ? {} : {
1060
- tools: run2.tools
962
+ response = _state.sent();
963
+ stream = new ReadableStream({
964
+ start: function start(controller) {
965
+ return _async_to_generator(function() {
966
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, err;
967
+ return _ts_generator(this, function(_state) {
968
+ switch(_state.label){
969
+ case 0:
970
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
971
+ _state.label = 1;
972
+ case 1:
973
+ _state.trys.push([
974
+ 1,
975
+ 6,
976
+ 7,
977
+ 12
978
+ ]);
979
+ _iterator = _async_iterator(response);
980
+ _state.label = 2;
981
+ case 2:
982
+ return [
983
+ 4,
984
+ _iterator.next()
985
+ ];
986
+ case 3:
987
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
988
+ 3,
989
+ 5
990
+ ];
991
+ _value = _step.value;
992
+ chunk = _value;
993
+ controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
994
+ _state.label = 4;
995
+ case 4:
996
+ _iteratorAbruptCompletion = false;
997
+ return [
998
+ 3,
999
+ 2
1000
+ ];
1001
+ case 5:
1002
+ return [
1003
+ 3,
1004
+ 12
1005
+ ];
1006
+ case 6:
1007
+ err = _state.sent();
1008
+ _didIteratorError = true;
1009
+ _iteratorError = err;
1010
+ return [
1011
+ 3,
1012
+ 12
1013
+ ];
1014
+ case 7:
1015
+ _state.trys.push([
1016
+ 7,
1017
+ ,
1018
+ 10,
1019
+ 11
1020
+ ]);
1021
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
1022
+ 3,
1023
+ 9
1024
+ ];
1025
+ return [
1026
+ 4,
1027
+ _iterator.return()
1028
+ ];
1029
+ case 8:
1030
+ _state.sent();
1031
+ _state.label = 9;
1032
+ case 9:
1033
+ return [
1034
+ 3,
1035
+ 11
1036
+ ];
1037
+ case 10:
1038
+ if (_didIteratorError) {
1039
+ throw _iteratorError;
1040
+ }
1041
+ return [
1042
+ 7
1043
+ ];
1044
+ case 11:
1045
+ return [
1046
+ 7
1047
+ ];
1048
+ case 12:
1049
+ controller.close();
1050
+ return [
1051
+ 2
1052
+ ];
1053
+ }
1054
+ });
1055
+ })();
1061
1056
  }
1062
- ]);
1063
- _state.label = 2;
1064
- case 2:
1065
- _state.trys.push([
1066
- 2,
1067
- 4,
1068
- ,
1069
- 5
1070
- ]);
1071
- return [
1072
- 4,
1073
- client.chat.completions.create(opts)
1074
- ];
1075
- case 3:
1076
- providerResponse = _state.sent();
1077
- return [
1078
- 3,
1079
- 5
1080
- ];
1081
- case 4:
1082
- e = _state.sent();
1083
- console.log("error", e);
1084
- console.error(e);
1057
+ });
1085
1058
  return [
1086
1059
  2,
1087
- onEvent2({
1088
- event: "thread.run.failed",
1089
- data: _object_spread_props(_object_spread({}, run2), {
1090
- failed_at: dayjs().unix(),
1091
- status: "in_progress",
1092
- last_error: e.message
1093
- })
1094
- })
1095
- ];
1096
- case 5:
1097
- return [
1098
- 4,
1099
- onEvent2({
1100
- event: "thread.message.created",
1101
- data: {
1102
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
1103
- object: "thread.message",
1104
- completed_at: null,
1105
- run_id: run2.id,
1106
- created_at: dayjs().unix(),
1107
- assistant_id: run2.assistant_id,
1108
- incomplete_at: null,
1109
- incomplete_details: null,
1110
- metadata: {},
1111
- attachments: [],
1112
- thread_id: run2.thread_id,
1113
- content: [
1114
- {
1115
- text: {
1116
- value: "",
1117
- annotations: []
1118
- },
1119
- type: "text"
1120
- }
1121
- ],
1122
- role: "assistant",
1123
- status: "in_progress"
1060
+ new Response(stream, {
1061
+ headers: {
1062
+ "Content-Type": "text/event-stream"
1124
1063
  }
1125
1064
  })
1126
1065
  ];
1127
- case 6:
1128
- message = _state.sent();
1129
- onEvent2({
1130
- event: "thread.run.step.created",
1131
- data: {
1132
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
1133
- object: "thread.run.step",
1134
- run_id: run2.id,
1135
- assistant_id: run2.assistant_id,
1136
- thread_id: run2.thread_id,
1137
- type: "message_creation",
1138
- status: "completed",
1139
- completed_at: dayjs().unix(),
1140
- created_at: dayjs().unix(),
1141
- expired_at: null,
1142
- last_error: null,
1143
- metadata: {},
1144
- failed_at: null,
1145
- cancelled_at: null,
1146
- usage: null,
1147
- step_details: {
1148
- type: "message_creation",
1149
- message_creation: {
1150
- message_id: message.id
1151
- }
1152
- }
1153
- }
1154
- });
1155
- currentContent = "";
1156
- _iteratorAbruptCompletion = false, _didIteratorError = false;
1157
- _state.label = 7;
1158
- case 7:
1066
+ case 2:
1159
1067
  _state.trys.push([
1160
- 7,
1161
- 15,
1162
- 16,
1163
- 21
1164
- ]);
1165
- _iterator = _async_iterator(providerResponse);
1166
- _state.label = 8;
1167
- case 8:
1068
+ 2,
1069
+ 4,
1070
+ ,
1071
+ 5
1072
+ ]);
1168
1073
  return [
1169
1074
  4,
1170
- _iterator.next()
1075
+ perplexity.chat.completions.create(body)
1171
1076
  ];
1172
- case 9:
1173
- if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
1174
- 3,
1175
- 14
1077
+ case 3:
1078
+ data = _state.sent();
1079
+ return [
1080
+ 2,
1081
+ new Response(JSON.stringify({
1082
+ data: data
1083
+ }), {
1084
+ status: 200,
1085
+ headers: {
1086
+ "Content-Type": "application/json"
1087
+ }
1088
+ })
1176
1089
  ];
1177
- _value = _step.value;
1178
- chunk = _value;
1179
- delta = chunk.choices[0].delta;
1180
- if (delta.content) {
1181
- ;
1182
- currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
1183
- }
1184
- if (!delta.tool_calls) return [
1185
- 3,
1186
- 12
1090
+ case 4:
1091
+ error = _state.sent();
1092
+ return [
1093
+ 2,
1094
+ new Response(JSON.stringify({
1095
+ error: error
1096
+ }), {
1097
+ status: 500,
1098
+ headers: {
1099
+ "Content-Type": "application/json"
1100
+ }
1101
+ })
1187
1102
  ];
1188
- if (!!toolCallsRunStep) return [
1103
+ case 5:
1104
+ return [
1105
+ 2
1106
+ ];
1107
+ }
1108
+ });
1109
+ });
1110
+ return function(_url, options) {
1111
+ return _ref.apply(this, arguments);
1112
+ };
1113
+ }();
1114
+ };
1115
+ // src/adapters/client/perplexityClientAdapter/completions/index.ts
1116
+ var completions4 = function(param) {
1117
+ var perplexity = param.perplexity;
1118
+ return {
1119
+ post: post4({
1120
+ perplexity: perplexity
1121
+ })
1122
+ };
1123
+ };
1124
+ // src/adapters/client/perplexityClientAdapter/index.ts
1125
+ var perplexityClientAdapter = function(param) {
1126
+ var perplexity = param.perplexity;
1127
+ return {
1128
+ "^/v1/chat/completions$": completions4({
1129
+ perplexity: perplexity
1130
+ })
1131
+ };
1132
+ };
1133
+ // src/adapters/client/anthropicClientAdapter/completions/post.ts
1134
+ import { uid, fork, omit, isEmpty } from "radash";
1135
+ // src/adapters/client/anthropicClientAdapter/completions/serializeTools.ts
1136
+ var serializeTools = function(param) {
1137
+ var tools = param.tools;
1138
+ return tools.map(function(tool) {
1139
+ if (tool.type === "function") {
1140
+ return {
1141
+ name: tool.function.name,
1142
+ description: tool.function.description,
1143
+ input_schema: tool.function.parameters
1144
+ };
1145
+ }
1146
+ return tool;
1147
+ });
1148
+ };
1149
+ // src/adapters/client/anthropicClientAdapter/completions/serializeMessages/serializeMessage.ts
1150
+ var serializeMessage = function(param) {
1151
+ var message = param.message;
1152
+ if (message.role === "user") {
1153
+ return {
1154
+ role: "user",
1155
+ content: message.content
1156
+ };
1157
+ } else if (message.role === "assistant") {
1158
+ var _message_tool_calls;
1159
+ return {
1160
+ role: "assistant",
1161
+ content: [
1162
+ {
1163
+ type: "text",
1164
+ text: message.content
1165
+ }
1166
+ ].concat(_to_consumable_array(((_message_tool_calls = message.tool_calls) !== null && _message_tool_calls !== void 0 ? _message_tool_calls : []).map(function(toolCall) {
1167
+ return {
1168
+ type: "tool_use",
1169
+ id: toolCall.id,
1170
+ name: toolCall.function.name,
1171
+ input: JSON.parse(toolCall.function.arguments)
1172
+ };
1173
+ })))
1174
+ };
1175
+ } else if (message.role === "tool") {
1176
+ return {
1177
+ role: "user",
1178
+ content: [
1179
+ {
1180
+ type: "tool_result",
1181
+ tool_use_id: message.tool_call_id,
1182
+ content: message.content
1183
+ }
1184
+ ]
1185
+ };
1186
+ }
1187
+ };
1188
+ // src/adapters/client/anthropicClientAdapter/completions/serializeMessages/index.ts
1189
+ var serializeMessages = function(param) {
1190
+ var messages3 = param.messages;
1191
+ return messages3.map(function(message) {
1192
+ return serializeMessage({
1193
+ message: message
1194
+ });
1195
+ });
1196
+ };
1197
+ // src/adapters/client/anthropicClientAdapter/completions/post.ts
1198
+ var post5 = function(param) {
1199
+ var anthropic = param.anthropic;
1200
+ return function() {
1201
+ var _ref = _async_to_generator(function(_url, options) {
1202
+ var body, messages3, _fork, systemMessages, otherMessages, system, resultOptions, response, stream, data, error;
1203
+ return _ts_generator(this, function(_state) {
1204
+ switch(_state.label){
1205
+ case 0:
1206
+ body = JSON.parse(options.body);
1207
+ messages3 = body.messages;
1208
+ _fork = _sliced_to_array(fork(messages3, function(message) {
1209
+ return message.role === "system";
1210
+ }), 2), systemMessages = _fork[0], otherMessages = _fork[1];
1211
+ system = systemMessages.map(function(message) {
1212
+ return message.content;
1213
+ }).join("\n");
1214
+ if (otherMessages[0] && otherMessages[0].role != "user") {
1215
+ otherMessages.unshift({
1216
+ role: "user",
1217
+ content: "-"
1218
+ });
1219
+ }
1220
+ resultOptions = _object_spread_props(_object_spread({}, omit(body, [
1221
+ "response_format"
1222
+ ])), {
1223
+ stream: body.stream ? isEmpty(body.tools) : false,
1224
+ system: system,
1225
+ messages: serializeMessages({
1226
+ messages: otherMessages
1227
+ }),
1228
+ max_tokens: 4096,
1229
+ tools: serializeTools({
1230
+ tools: body.tools
1231
+ })
1232
+ });
1233
+ if (!body.stream) return [
1189
1234
  3,
1190
- 11
1235
+ 2
1191
1236
  ];
1192
1237
  return [
1193
1238
  4,
1194
- onEvent2({
1195
- event: "thread.run.step.created",
1196
- data: {
1197
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
1198
- object: "thread.run.step",
1199
- run_id: run2.id,
1200
- assistant_id: run2.assistant_id,
1201
- thread_id: run2.thread_id,
1202
- type: "tool_calls",
1203
- status: "in_progress",
1204
- completed_at: null,
1205
- created_at: dayjs().unix(),
1206
- expired_at: null,
1207
- last_error: null,
1208
- metadata: {},
1209
- failed_at: null,
1210
- cancelled_at: null,
1211
- usage: null,
1212
- step_details: {
1213
- type: "tool_calls",
1214
- tool_calls: []
1215
- }
1216
- }
1217
- })
1239
+ anthropic.messages.stream(resultOptions)
1218
1240
  ];
1219
- case 10:
1220
- toolCallsRunStep = _state.sent();
1221
- _state.label = 11;
1222
- case 11:
1223
- onEvent2({
1224
- event: "thread.run.step.delta",
1225
- data: {
1226
- object: "thread.run.step.delta",
1227
- run_id: run2.id,
1228
- id: toolCallsRunStep.id,
1229
- delta: {
1230
- step_details: {
1231
- type: "tool_calls",
1232
- tool_calls: delta.tool_calls.map(function(tc) {
1233
- return _object_spread({
1234
- id: uid(24),
1235
- type: "function"
1236
- }, tc);
1237
- })
1238
- }
1239
- }
1241
+ case 1:
1242
+ response = _state.sent();
1243
+ stream = new ReadableStream({
1244
+ start: function start(controller) {
1245
+ return _async_to_generator(function() {
1246
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, messageDelta, delta1, messageDelta1, messageDelta2, err;
1247
+ return _ts_generator(this, function(_state) {
1248
+ switch(_state.label){
1249
+ case 0:
1250
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
1251
+ _state.label = 1;
1252
+ case 1:
1253
+ _state.trys.push([
1254
+ 1,
1255
+ 6,
1256
+ 7,
1257
+ 12
1258
+ ]);
1259
+ _iterator = _async_iterator(response);
1260
+ _state.label = 2;
1261
+ case 2:
1262
+ return [
1263
+ 4,
1264
+ _iterator.next()
1265
+ ];
1266
+ case 3:
1267
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
1268
+ 3,
1269
+ 5
1270
+ ];
1271
+ _value = _step.value;
1272
+ chunk = _value;
1273
+ if (chunk.type === "content_block_delta") {
1274
+ delta = chunk.delta.type === "input_json_delta" ? {
1275
+ tool_calls: [
1276
+ {
1277
+ index: 0,
1278
+ function: {
1279
+ arguments: chunk.delta.partial_json
1280
+ }
1281
+ }
1282
+ ]
1283
+ } : {
1284
+ content: chunk.delta.text
1285
+ };
1286
+ messageDelta = {
1287
+ id: "chatcmpl-".concat(uid(29)),
1288
+ object: "chat.completion.chunk",
1289
+ choices: [
1290
+ {
1291
+ index: chunk.index,
1292
+ delta: delta
1293
+ }
1294
+ ]
1295
+ };
1296
+ controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
1297
+ } else if (chunk.type === "content_block_start") {
1298
+ delta1 = chunk.content_block.type === "tool_use" ? {
1299
+ content: null,
1300
+ tool_calls: [
1301
+ {
1302
+ index: 0,
1303
+ id: chunk.content_block.id,
1304
+ type: "function",
1305
+ function: {
1306
+ name: chunk.content_block.name,
1307
+ arguments: ""
1308
+ }
1309
+ }
1310
+ ]
1311
+ } : {
1312
+ content: chunk.content_block.text
1313
+ };
1314
+ messageDelta1 = {
1315
+ id: "chatcmpl-".concat(uid(29)),
1316
+ object: "chat.completion.chunk",
1317
+ choices: [
1318
+ {
1319
+ index: chunk.index,
1320
+ delta: delta1
1321
+ }
1322
+ ]
1323
+ };
1324
+ controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
1325
+ } else if (chunk.type === "message_start") {
1326
+ messageDelta2 = {
1327
+ id: "chatcmpl-".concat(uid(29)),
1328
+ object: "chat.completion.chunk",
1329
+ choices: [
1330
+ {
1331
+ index: 0,
1332
+ delta: {
1333
+ content: ""
1334
+ }
1335
+ }
1336
+ ]
1337
+ };
1338
+ controller.enqueue("data: ".concat(JSON.stringify(messageDelta2), "\n\n"));
1339
+ }
1340
+ _state.label = 4;
1341
+ case 4:
1342
+ _iteratorAbruptCompletion = false;
1343
+ return [
1344
+ 3,
1345
+ 2
1346
+ ];
1347
+ case 5:
1348
+ return [
1349
+ 3,
1350
+ 12
1351
+ ];
1352
+ case 6:
1353
+ err = _state.sent();
1354
+ _didIteratorError = true;
1355
+ _iteratorError = err;
1356
+ return [
1357
+ 3,
1358
+ 12
1359
+ ];
1360
+ case 7:
1361
+ _state.trys.push([
1362
+ 7,
1363
+ ,
1364
+ 10,
1365
+ 11
1366
+ ]);
1367
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
1368
+ 3,
1369
+ 9
1370
+ ];
1371
+ return [
1372
+ 4,
1373
+ _iterator.return()
1374
+ ];
1375
+ case 8:
1376
+ _state.sent();
1377
+ _state.label = 9;
1378
+ case 9:
1379
+ return [
1380
+ 3,
1381
+ 11
1382
+ ];
1383
+ case 10:
1384
+ if (_didIteratorError) {
1385
+ throw _iteratorError;
1386
+ }
1387
+ return [
1388
+ 7
1389
+ ];
1390
+ case 11:
1391
+ return [
1392
+ 7
1393
+ ];
1394
+ case 12:
1395
+ controller.close();
1396
+ return [
1397
+ 2
1398
+ ];
1399
+ }
1400
+ });
1401
+ })();
1240
1402
  }
1241
1403
  });
1242
- currentToolCalls = toolCallsData({
1243
- prevToolCalls: currentToolCalls,
1244
- delta: delta
1245
- });
1246
- _state.label = 12;
1247
- case 12:
1248
- if (delta.content) {
1249
- onEvent2({
1250
- event: "thread.message.delta",
1251
- data: {
1252
- id: message.id,
1253
- delta: {
1254
- content: [
1255
- {
1256
- type: "text",
1257
- index: 0,
1258
- text: {
1259
- value: delta.content
1260
- }
1261
- }
1262
- ]
1263
- }
1264
- }
1265
- });
1266
- }
1267
- _state.label = 13;
1268
- case 13:
1269
- _iteratorAbruptCompletion = false;
1270
- return [
1271
- 3,
1272
- 8
1273
- ];
1274
- case 14:
1275
- return [
1276
- 3,
1277
- 21
1278
- ];
1279
- case 15:
1280
- err = _state.sent();
1281
- _didIteratorError = true;
1282
- _iteratorError = err;
1283
1404
  return [
1284
- 3,
1285
- 21
1405
+ 2,
1406
+ new Response(stream, {
1407
+ headers: {
1408
+ "Content-Type": "text/event-stream"
1409
+ }
1410
+ })
1286
1411
  ];
1287
- case 16:
1412
+ case 2:
1288
1413
  _state.trys.push([
1289
- 16,
1414
+ 2,
1415
+ 4,
1290
1416
  ,
1291
- 19,
1292
- 20
1417
+ 5
1293
1418
  ]);
1294
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
1295
- 3,
1296
- 18
1297
- ];
1298
1419
  return [
1299
1420
  4,
1300
- _iterator.return()
1421
+ anthropic.messages.create(resultOptions)
1301
1422
  ];
1302
- case 17:
1303
- _state.sent();
1304
- _state.label = 18;
1305
- case 18:
1306
- return [
1307
- 3,
1308
- 20
1309
- ];
1310
- case 19:
1311
- if (_didIteratorError) {
1312
- throw _iteratorError;
1313
- }
1314
- return [
1315
- 7
1316
- ];
1317
- case 20:
1318
- return [
1319
- 7
1320
- ];
1321
- case 21:
1423
+ case 3:
1424
+ data = _state.sent();
1322
1425
  return [
1323
- 4,
1324
- onEvent2({
1325
- event: "thread.message.completed",
1326
- data: _object_spread_props(_object_spread({}, message), {
1327
- status: "completed",
1328
- content: [
1329
- {
1330
- text: {
1331
- value: currentContent,
1332
- annotations: []
1333
- },
1334
- type: "text"
1335
- }
1336
- ],
1337
- tool_calls: currentToolCalls
1338
- })
1426
+ 2,
1427
+ new Response(JSON.stringify({
1428
+ data: data
1429
+ }), {
1430
+ status: 200,
1431
+ headers: {
1432
+ "Content-Type": "application/json"
1433
+ }
1339
1434
  })
1340
1435
  ];
1341
- case 22:
1342
- message = _state.sent();
1343
- if (isEmpty(message.toolCalls)) {
1344
- return [
1345
- 2,
1346
- onEvent2({
1347
- event: "thread.run.completed",
1348
- data: _object_spread_props(_object_spread({}, run2), {
1349
- status: "completed",
1350
- completed_at: dayjs().unix()
1351
- })
1352
- })
1353
- ];
1354
- }
1436
+ case 4:
1437
+ error = _state.sent();
1355
1438
  return [
1356
1439
  2,
1357
- onEvent2({
1358
- event: "thread.run.requires_action",
1359
- data: _object_spread_props(_object_spread({}, run2), {
1360
- status: "requires_action",
1361
- required_action: {
1362
- type: "submit_tool_outputs",
1363
- submit_tool_outputs: {
1364
- tool_calls: message.toolCalls
1365
- }
1366
- }
1367
- })
1440
+ new Response(JSON.stringify({
1441
+ error: error
1442
+ }), {
1443
+ status: 500,
1444
+ headers: {
1445
+ "Content-Type": "application/json"
1446
+ }
1368
1447
  })
1369
1448
  ];
1449
+ case 5:
1450
+ return [
1451
+ 2
1452
+ ];
1370
1453
  }
1371
1454
  });
1372
1455
  });
1373
- return function(_) {
1456
+ return function(_url, options) {
1374
1457
  return _ref.apply(this, arguments);
1375
1458
  };
1376
1459
  }();
1377
1460
  };
1378
- // src/adapters/run/anthropicRunAdapter/index.ts
1379
- import _2 from "lodash";
1380
- import { uid as uid2, omit as omit2, isEmpty as isEmpty2 } from "radash";
1381
- import dayjs2 from "dayjs";
1382
- // src/adapters/run/anthropicRunAdapter/messages/index.ts
1383
- import { flat as flat2 } from "radash";
1384
- // src/adapters/run/anthropicRunAdapter/messages/serializeMessage.ts
1385
- var serializeToolCall2 = function(param) {
1386
- var toolCall = param.toolCall;
1387
- var _toolCall_function_output;
1461
+ // src/adapters/client/anthropicClientAdapter/completions/index.ts
1462
+ var completions5 = function(param) {
1463
+ var anthropic = param.anthropic;
1388
1464
  return {
1389
- role: "user",
1390
- content: [
1391
- {
1392
- type: "tool_result",
1393
- tool_use_id: toolCall.id,
1394
- content: (_toolCall_function_output = toolCall.function.output) !== null && _toolCall_function_output !== void 0 ? _toolCall_function_output : ""
1395
- }
1396
- ]
1465
+ post: post5({
1466
+ anthropic: anthropic
1467
+ })
1468
+ };
1469
+ };
1470
+ // src/adapters/client/anthropicClientAdapter/index.ts
1471
+ var anthropicClientAdapter = function(param) {
1472
+ var anthropic = param.anthropic;
1473
+ return {
1474
+ "^/v1/chat/completions$": completions5({
1475
+ anthropic: anthropic
1476
+ })
1397
1477
  };
1398
1478
  };
1399
- var serializeInputToolCall = function(param) {
1479
+ // src/adapters/run/completionsRunAdapter/index.ts
1480
+ import _ from "lodash";
1481
+ import { uid as uid2, omit as omit2, isEmpty as isEmpty2 } from "radash";
1482
+ import dayjs from "dayjs";
1483
+ // src/adapters/run/completionsRunAdapter/messages/index.ts
1484
+ import { flat } from "radash";
1485
+ // src/adapters/run/completionsRunAdapter/messages/serializeMessage.ts
1486
+ var serializeToolCall = function(param) {
1400
1487
  var toolCall = param.toolCall;
1488
+ var _toolCall_function_output;
1401
1489
  return {
1402
- type: "tool_use",
1403
- id: toolCall.id,
1490
+ tool_call_id: toolCall.id,
1491
+ role: "tool",
1404
1492
  name: toolCall.function.name,
1405
- input: JSON.parse(toolCall.function.arguments)
1493
+ content: (_toolCall_function_output = toolCall.function.output) !== null && _toolCall_function_output !== void 0 ? _toolCall_function_output : ""
1406
1494
  };
1407
1495
  };
1408
- var serializeMessageWithContent2 = function(param) {
1496
+ var serializeMessageWithContent = function(param) {
1409
1497
  var message = param.message;
1410
1498
  var _message_metadata;
1411
- var _message_metadata_toolCalls;
1412
- return {
1499
+ return _object_spread({
1413
1500
  role: message.role,
1414
- content: [
1415
- {
1416
- type: "text",
1417
- text: serializeContent2({
1418
- content: message.content
1419
- })
1420
- }
1421
- ].concat(// @ts-ignore-next-line
1422
- _to_consumable_array(((_message_metadata_toolCalls = message === null || message === void 0 ? void 0 : (_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) !== null && _message_metadata_toolCalls !== void 0 ? _message_metadata_toolCalls : []).map(function(toolCall) {
1423
- return serializeInputToolCall({
1424
- toolCall: toolCall
1425
- });
1426
- })))
1427
- };
1501
+ content: serializeContent({
1502
+ content: message.content
1503
+ })
1504
+ }, (message === null || message === void 0 ? void 0 : (_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) ? {
1505
+ tool_calls: message.metadata.toolCalls
1506
+ } : {});
1428
1507
  };
1429
- var serializeContent2 = function(param) {
1508
+ var serializeContent = function(param) {
1430
1509
  var content = param.content;
1431
1510
  return content.map(function(content2) {
1432
1511
  return content2.text.value;
@@ -1436,7 +1515,7 @@ var serializeMessage2 = function(param) {
1436
1515
  var message = param.message;
1437
1516
  var _message_metadata;
1438
1517
  var result = [
1439
- serializeMessageWithContent2({
1518
+ serializeMessageWithContent({
1440
1519
  message: message
1441
1520
  })
1442
1521
  ];
@@ -1456,90 +1535,156 @@ var serializeMessage2 = function(param) {
1456
1535
  if (rsTc.type !== "function") return false;
1457
1536
  return rsTc.id === tc.id;
1458
1537
  });
1459
- result.push(serializeToolCall2({
1538
+ result.push(serializeToolCall({
1460
1539
  toolCall: toolCall
1461
1540
  }));
1462
1541
  });
1463
1542
  return result;
1464
1543
  };
1465
- // src/adapters/run/anthropicRunAdapter/messages/index.ts
1466
- var messages2 = function() {
1467
- var _ref = _async_to_generator(function(param) {
1468
- var run2, getMessages2;
1469
- return _ts_generator(this, function(_state) {
1470
- switch(_state.label){
1471
- case 0:
1472
- run2 = param.run, getMessages2 = param.getMessages;
1473
- return [
1474
- 4,
1475
- getMessages2()
1476
- ];
1477
- case 1:
1478
- return [
1479
- 2,
1480
- flat2.apply(void 0, [
1481
- _state.sent().map(function(message) {
1482
- return serializeMessage2({
1483
- message: message
1484
- });
1485
- })
1486
- ])
1487
- ];
1488
- }
1544
+ // src/adapters/run/completionsRunAdapter/messages/index.ts
1545
+ var messages = function() {
1546
+ var _ref = _async_to_generator(function(param) {
1547
+ var run2, getMessages2, _, _1;
1548
+ return _ts_generator(this, function(_state) {
1549
+ switch(_state.label){
1550
+ case 0:
1551
+ run2 = param.run, getMessages2 = param.getMessages;
1552
+ _1 = (_ = _to_consumable_array(run2.instructions ? [
1553
+ {
1554
+ role: "system",
1555
+ content: run2.instructions
1556
+ }
1557
+ ] : [])).concat;
1558
+ return [
1559
+ 4,
1560
+ getMessages2()
1561
+ ];
1562
+ case 1:
1563
+ return [
1564
+ 2,
1565
+ _1.apply(_, [
1566
+ _to_consumable_array.apply(void 0, [
1567
+ flat.apply(void 0, [
1568
+ _state.sent().map(function(message) {
1569
+ return serializeMessage2({
1570
+ message: message
1571
+ });
1572
+ })
1573
+ ])
1574
+ ])
1575
+ ])
1576
+ ];
1577
+ }
1578
+ });
1579
+ });
1580
+ return function messages(_) {
1581
+ return _ref.apply(this, arguments);
1582
+ };
1583
+ }();
1584
+ // src/adapters/run/completionsRunAdapter/index.ts
1585
+ var updatedToolCall = function(param) {
1586
+ var toolCall = param.toolCall, delta = param.delta;
1587
+ if (!toolCall) return omit2(delta, [
1588
+ "index"
1589
+ ]);
1590
+ var result = _.cloneDeep(toolCall);
1591
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1592
+ try {
1593
+ for(var _iterator = Object.entries(delta.function)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1594
+ var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
1595
+ var _result_function_key;
1596
+ result.function[key] = "".concat((_result_function_key = result.function[key]) !== null && _result_function_key !== void 0 ? _result_function_key : "").concat(value);
1597
+ }
1598
+ } catch (err) {
1599
+ _didIteratorError = true;
1600
+ _iteratorError = err;
1601
+ } finally{
1602
+ try {
1603
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1604
+ _iterator.return();
1605
+ }
1606
+ } finally{
1607
+ if (_didIteratorError) {
1608
+ throw _iteratorError;
1609
+ }
1610
+ }
1611
+ }
1612
+ return result;
1613
+ };
1614
+ var toolCallsData = function(param) {
1615
+ var prevToolCalls = param.prevToolCalls, delta = param.delta;
1616
+ if (!prevToolCalls) {
1617
+ return delta.tool_calls.map(function(tc) {
1618
+ return _object_spread({
1619
+ id: uid2(24),
1620
+ type: "function"
1621
+ }, omit2(tc, [
1622
+ "index"
1623
+ ]));
1489
1624
  });
1490
- });
1491
- return function messages2(_) {
1492
- return _ref.apply(this, arguments);
1493
- };
1494
- }();
1495
- // src/adapters/run/anthropicRunAdapter/serializeTools.ts
1496
- var serializeTools = function(param) {
1497
- var run2 = param.run;
1498
- return run2.tools.map(function(tool) {
1499
- if (tool.type === "function") {
1500
- return {
1501
- name: tool.function.name,
1502
- description: tool.function.description,
1503
- input_schema: tool.function.parameters
1504
- };
1625
+ }
1626
+ var newToolCalls = _.cloneDeep(prevToolCalls);
1627
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1628
+ try {
1629
+ for(var _iterator = delta.tool_calls[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1630
+ var runStepDelta = _step.value;
1631
+ newToolCalls[runStepDelta.index] = updatedToolCall({
1632
+ toolCall: newToolCalls[runStepDelta.index],
1633
+ delta: runStepDelta
1634
+ });
1505
1635
  }
1506
- return tool;
1507
- });
1636
+ } catch (err) {
1637
+ _didIteratorError = true;
1638
+ _iteratorError = err;
1639
+ } finally{
1640
+ try {
1641
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1642
+ _iterator.return();
1643
+ }
1644
+ } finally{
1645
+ if (_didIteratorError) {
1646
+ throw _iteratorError;
1647
+ }
1648
+ }
1649
+ }
1650
+ return newToolCalls;
1508
1651
  };
1509
- // src/adapters/run/anthropicRunAdapter/index.ts
1510
- var anthropicRunAdapter = function() {
1652
+ var completionsRunAdapter = function() {
1511
1653
  return function() {
1512
1654
  var _ref = _async_to_generator(function(param) {
1513
- var client, run2, onEvent2, getMessages2, isStream, opts, _tmp, providerResponse, e, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, messageStreamEvent, _messageStreamEvent_delta_text, err, textContentBlock, toolUseBlocks;
1655
+ var clientAdapter, run2, onEvent2, getMessages2, client, opts, _tmp, providerResponse, e, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, _delta_content, err;
1514
1656
  return _ts_generator(this, function(_state) {
1515
1657
  switch(_state.label){
1516
1658
  case 0:
1517
- client = param.client, run2 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
1659
+ clientAdapter = param.client, run2 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
1518
1660
  if (run2.status !== "queued") return [
1519
1661
  2
1520
1662
  ];
1663
+ client = supercompat({
1664
+ client: clientAdapter,
1665
+ storage: function() {},
1666
+ // @ts-ignore-next-line
1667
+ runAdapter: {}
1668
+ });
1521
1669
  onEvent2({
1522
1670
  event: "thread.run.in_progress",
1523
1671
  data: _object_spread_props(_object_spread({}, run2), {
1524
1672
  status: "in_progress"
1525
1673
  })
1526
1674
  });
1527
- isStream = isEmpty2(run2.tools);
1528
1675
  _tmp = {};
1529
1676
  return [
1530
1677
  4,
1531
- messages2({
1678
+ messages({
1532
1679
  run: run2,
1533
1680
  getMessages: getMessages2
1534
1681
  })
1535
1682
  ];
1536
1683
  case 1:
1537
1684
  opts = _object_spread.apply(void 0, [
1538
- (_tmp.messages = _state.sent(), _tmp.stream = isStream, _tmp.model = run2.model, _tmp),
1685
+ (_tmp.messages = _state.sent(), _tmp.model = run2.model, _tmp.stream = true, _tmp.response_format = run2.response_format, _tmp),
1539
1686
  isEmpty2(run2.tools) ? {} : {
1540
- tools: serializeTools({
1541
- run: run2
1542
- })
1687
+ tools: run2.tools
1543
1688
  }
1544
1689
  ]);
1545
1690
  _state.label = 2;
@@ -1562,13 +1707,14 @@ var anthropicRunAdapter = function() {
1562
1707
  ];
1563
1708
  case 4:
1564
1709
  e = _state.sent();
1710
+ console.log("error", e);
1565
1711
  console.error(e);
1566
1712
  return [
1567
1713
  2,
1568
1714
  onEvent2({
1569
1715
  event: "thread.run.failed",
1570
1716
  data: _object_spread_props(_object_spread({}, run2), {
1571
- failed_at: dayjs2().unix(),
1717
+ failed_at: dayjs().unix(),
1572
1718
  status: "in_progress",
1573
1719
  last_error: e.message
1574
1720
  })
@@ -1584,7 +1730,7 @@ var anthropicRunAdapter = function() {
1584
1730
  object: "thread.message",
1585
1731
  completed_at: null,
1586
1732
  run_id: run2.id,
1587
- created_at: dayjs2().unix(),
1733
+ created_at: dayjs().unix(),
1588
1734
  assistant_id: run2.assistant_id,
1589
1735
  incomplete_at: null,
1590
1736
  incomplete_details: null,
@@ -1617,8 +1763,8 @@ var anthropicRunAdapter = function() {
1617
1763
  thread_id: run2.thread_id,
1618
1764
  type: "message_creation",
1619
1765
  status: "completed",
1620
- completed_at: dayjs2().unix(),
1621
- created_at: dayjs2().unix(),
1766
+ completed_at: dayjs().unix(),
1767
+ created_at: dayjs().unix(),
1622
1768
  expired_at: null,
1623
1769
  last_error: null,
1624
1770
  metadata: {},
@@ -1634,18 +1780,14 @@ var anthropicRunAdapter = function() {
1634
1780
  }
1635
1781
  });
1636
1782
  currentContent = "";
1637
- if (!isStream) return [
1638
- 3,
1639
- 19
1640
- ];
1641
1783
  _iteratorAbruptCompletion = false, _didIteratorError = false;
1642
1784
  _state.label = 7;
1643
1785
  case 7:
1644
1786
  _state.trys.push([
1645
1787
  7,
1646
- 12,
1647
- 13,
1648
- 18
1788
+ 15,
1789
+ 16,
1790
+ 21
1649
1791
  ]);
1650
1792
  _iterator = _async_iterator(providerResponse);
1651
1793
  _state.label = 8;
@@ -1657,13 +1799,80 @@ var anthropicRunAdapter = function() {
1657
1799
  case 9:
1658
1800
  if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
1659
1801
  3,
1660
- 11
1802
+ 14
1661
1803
  ];
1662
1804
  _value = _step.value;
1663
- messageStreamEvent = _value;
1664
- if (messageStreamEvent.type === "content_block_delta") {
1805
+ chunk = _value;
1806
+ delta = chunk.choices[0].delta;
1807
+ if (delta.content) {
1665
1808
  ;
1666
- currentContent = "".concat(currentContent).concat((_messageStreamEvent_delta_text = messageStreamEvent.delta.text) !== null && _messageStreamEvent_delta_text !== void 0 ? _messageStreamEvent_delta_text : "");
1809
+ currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
1810
+ }
1811
+ if (!delta.tool_calls) return [
1812
+ 3,
1813
+ 12
1814
+ ];
1815
+ if (!!toolCallsRunStep) return [
1816
+ 3,
1817
+ 11
1818
+ ];
1819
+ return [
1820
+ 4,
1821
+ onEvent2({
1822
+ event: "thread.run.step.created",
1823
+ data: {
1824
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
1825
+ object: "thread.run.step",
1826
+ run_id: run2.id,
1827
+ assistant_id: run2.assistant_id,
1828
+ thread_id: run2.thread_id,
1829
+ type: "tool_calls",
1830
+ status: "in_progress",
1831
+ completed_at: null,
1832
+ created_at: dayjs().unix(),
1833
+ expired_at: null,
1834
+ last_error: null,
1835
+ metadata: {},
1836
+ failed_at: null,
1837
+ cancelled_at: null,
1838
+ usage: null,
1839
+ step_details: {
1840
+ type: "tool_calls",
1841
+ tool_calls: []
1842
+ }
1843
+ }
1844
+ })
1845
+ ];
1846
+ case 10:
1847
+ toolCallsRunStep = _state.sent();
1848
+ _state.label = 11;
1849
+ case 11:
1850
+ onEvent2({
1851
+ event: "thread.run.step.delta",
1852
+ data: {
1853
+ object: "thread.run.step.delta",
1854
+ run_id: run2.id,
1855
+ id: toolCallsRunStep.id,
1856
+ delta: {
1857
+ step_details: {
1858
+ type: "tool_calls",
1859
+ tool_calls: delta.tool_calls.map(function(tc) {
1860
+ return _object_spread({
1861
+ id: uid2(24),
1862
+ type: "function"
1863
+ }, tc);
1864
+ })
1865
+ }
1866
+ }
1867
+ }
1868
+ });
1869
+ currentToolCalls = toolCallsData({
1870
+ prevToolCalls: currentToolCalls,
1871
+ delta: delta
1872
+ });
1873
+ _state.label = 12;
1874
+ case 12:
1875
+ if (delta.content) {
1667
1876
  onEvent2({
1668
1877
  event: "thread.message.delta",
1669
1878
  data: {
@@ -1674,8 +1883,7 @@ var anthropicRunAdapter = function() {
1674
1883
  type: "text",
1675
1884
  index: 0,
1676
1885
  text: {
1677
- // @ts-ignore-next-line
1678
- value: messageStreamEvent.delta.text
1886
+ value: delta.content
1679
1887
  }
1680
1888
  }
1681
1889
  ]
@@ -1683,119 +1891,60 @@ var anthropicRunAdapter = function() {
1683
1891
  }
1684
1892
  });
1685
1893
  }
1686
- _state.label = 10;
1687
- case 10:
1894
+ _state.label = 13;
1895
+ case 13:
1688
1896
  _iteratorAbruptCompletion = false;
1689
1897
  return [
1690
1898
  3,
1691
1899
  8
1692
1900
  ];
1693
- case 11:
1901
+ case 14:
1694
1902
  return [
1695
1903
  3,
1696
- 18
1904
+ 21
1697
1905
  ];
1698
- case 12:
1906
+ case 15:
1699
1907
  err = _state.sent();
1700
1908
  _didIteratorError = true;
1701
1909
  _iteratorError = err;
1702
1910
  return [
1703
1911
  3,
1704
- 18
1912
+ 21
1705
1913
  ];
1706
- case 13:
1914
+ case 16:
1707
1915
  _state.trys.push([
1708
- 13,
1709
- ,
1710
1916
  16,
1711
- 17
1917
+ ,
1918
+ 19,
1919
+ 20
1712
1920
  ]);
1713
1921
  if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
1714
1922
  3,
1715
- 15
1923
+ 18
1716
1924
  ];
1717
1925
  return [
1718
1926
  4,
1719
1927
  _iterator.return()
1720
1928
  ];
1721
- case 14:
1929
+ case 17:
1722
1930
  _state.sent();
1723
- _state.label = 15;
1724
- case 15:
1931
+ _state.label = 18;
1932
+ case 18:
1725
1933
  return [
1726
1934
  3,
1727
- 17
1935
+ 20
1728
1936
  ];
1729
- case 16:
1937
+ case 19:
1730
1938
  if (_didIteratorError) {
1731
1939
  throw _iteratorError;
1732
1940
  }
1733
1941
  return [
1734
1942
  7
1735
1943
  ];
1736
- case 17:
1944
+ case 20:
1737
1945
  return [
1738
1946
  7
1739
1947
  ];
1740
- case 18:
1741
- return [
1742
- 3,
1743
- 21
1744
- ];
1745
- case 19:
1746
- textContentBlock = providerResponse.content.filter(function(c) {
1747
- return c.type === "text";
1748
- })[0];
1749
- if (textContentBlock) {
1750
- currentContent = textContentBlock.text;
1751
- }
1752
- toolUseBlocks = providerResponse.content.filter(function(c) {
1753
- return c.type === "tool_use";
1754
- });
1755
- if (!!isEmpty2(toolUseBlocks)) return [
1756
- 3,
1757
- 21
1758
- ];
1759
- currentToolCalls = toolUseBlocks.map(function(tc) {
1760
- return {
1761
- id: tc.id,
1762
- type: "function",
1763
- function: {
1764
- name: tc.name,
1765
- arguments: JSON.stringify(tc.input)
1766
- }
1767
- };
1768
- });
1769
- return [
1770
- 4,
1771
- onEvent2({
1772
- event: "thread.run.step.created",
1773
- data: {
1774
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
1775
- object: "thread.run.step",
1776
- run_id: run2.id,
1777
- assistant_id: run2.assistant_id,
1778
- thread_id: run2.thread_id,
1779
- type: "tool_calls",
1780
- status: "in_progress",
1781
- completed_at: null,
1782
- created_at: dayjs2().unix(),
1783
- expired_at: null,
1784
- last_error: null,
1785
- metadata: {},
1786
- failed_at: null,
1787
- cancelled_at: null,
1788
- usage: null,
1789
- step_details: {
1790
- type: "tool_calls",
1791
- tool_calls: currentToolCalls
1792
- }
1793
- }
1794
- })
1795
- ];
1796
- case 20:
1797
- toolCallsRunStep = _state.sent();
1798
- _state.label = 21;
1799
1948
  case 21:
1800
1949
  return [
1801
1950
  4,
@@ -1825,7 +1974,7 @@ var anthropicRunAdapter = function() {
1825
1974
  event: "thread.run.completed",
1826
1975
  data: _object_spread_props(_object_spread({}, run2), {
1827
1976
  status: "completed",
1828
- completed_at: dayjs2().unix()
1977
+ completed_at: dayjs().unix()
1829
1978
  })
1830
1979
  })
1831
1980
  ];
@@ -1854,25 +2003,25 @@ var anthropicRunAdapter = function() {
1854
2003
  }();
1855
2004
  };
1856
2005
  // src/adapters/storage/prismaStorageAdapter/threads/post.ts
1857
- import dayjs4 from "dayjs";
1858
- // src/adapters/storage/prismaStorageAdapter/threads/serializeThread.ts
1859
2006
  import dayjs3 from "dayjs";
2007
+ // src/adapters/storage/prismaStorageAdapter/threads/serializeThread.ts
2008
+ import dayjs2 from "dayjs";
1860
2009
  var serializeThread = function(param) {
1861
2010
  var thread = param.thread;
1862
2011
  return {
1863
2012
  id: thread.id,
1864
2013
  object: "thread",
1865
- created_at: dayjs3(thread.createdAt).unix(),
2014
+ created_at: dayjs2(thread.createdAt).unix(),
1866
2015
  metadata: thread.metadata,
1867
2016
  // TODO
1868
2017
  tool_resources: null
1869
2018
  };
1870
2019
  };
1871
2020
  // src/adapters/storage/prismaStorageAdapter/threads/post.ts
1872
- var post3 = function(param) {
2021
+ var post6 = function(param) {
1873
2022
  var prisma = param.prisma;
1874
2023
  return /*#__PURE__*/ _async_to_generator(function() {
1875
- var _len, args, _key, body, messages4, metadata, initialCreatedAt, thread;
2024
+ var _len, args, _key, body, messages3, metadata, initialCreatedAt, thread;
1876
2025
  var _arguments = arguments;
1877
2026
  return _ts_generator(this, function(_state) {
1878
2027
  switch(_state.label){
@@ -1881,9 +2030,9 @@ var post3 = function(param) {
1881
2030
  args[_key] = _arguments[_key];
1882
2031
  }
1883
2032
  body = JSON.parse(args[1].body);
1884
- messages4 = body.messages || [];
2033
+ messages3 = body.messages || [];
1885
2034
  metadata = body.metadata || {};
1886
- initialCreatedAt = dayjs4().subtract(messages4.length, "seconds").format();
2035
+ initialCreatedAt = dayjs3().subtract(messages3.length, "seconds").format();
1887
2036
  return [
1888
2037
  4,
1889
2038
  prisma.thread.create({
@@ -1897,7 +2046,7 @@ var post3 = function(param) {
1897
2046
  }
1898
2047
  } : {}), {
1899
2048
  messages: {
1900
- create: messages4.map(function(message, index) {
2049
+ create: messages3.map(function(message, index) {
1901
2050
  return {
1902
2051
  role: message.role === "user" ? "USER" : "ASSISTANT",
1903
2052
  content: [
@@ -1911,7 +2060,7 @@ var post3 = function(param) {
1911
2060
  ],
1912
2061
  attachments: message.attachments,
1913
2062
  metadata: message.metadata,
1914
- createdAt: dayjs4(initialCreatedAt).add(index, "seconds").toDate()
2063
+ createdAt: dayjs3(initialCreatedAt).add(index, "seconds").toDate()
1915
2064
  };
1916
2065
  })
1917
2066
  }
@@ -1939,13 +2088,13 @@ var post3 = function(param) {
1939
2088
  var threads = function(param) {
1940
2089
  var prisma = param.prisma;
1941
2090
  return {
1942
- post: post3({
2091
+ post: post6({
1943
2092
  prisma: prisma
1944
2093
  })
1945
2094
  };
1946
2095
  };
1947
2096
  // src/adapters/storage/prismaStorageAdapter/threads/messages/serializeMessage.ts
1948
- import dayjs5 from "dayjs";
2097
+ import dayjs4 from "dayjs";
1949
2098
  import { assign as assign2 } from "radash";
1950
2099
  var serializeMessage3 = function(param) {
1951
2100
  var message = param.message;
@@ -1953,10 +2102,10 @@ var serializeMessage3 = function(param) {
1953
2102
  return {
1954
2103
  id: message.id,
1955
2104
  object: "thread.message",
1956
- created_at: dayjs5(message.createdAt).unix(),
2105
+ created_at: dayjs4(message.createdAt).unix(),
1957
2106
  thread_id: message.threadId,
1958
- completed_at: message.completedAt ? dayjs5(message.completedAt).unix() : null,
1959
- incomplete_at: message.incompleteAt ? dayjs5(message.incompleteAt).unix() : null,
2107
+ completed_at: message.completedAt ? dayjs4(message.completedAt).unix() : null,
2108
+ incomplete_at: message.incompleteAt ? dayjs4(message.incompleteAt).unix() : null,
1960
2109
  incomplete_details: message.incompleteDetails,
1961
2110
  role: message.role.toLowerCase(),
1962
2111
  content: message.content,
@@ -1982,7 +2131,7 @@ var messageContentBlocks = function(param) {
1982
2131
  }
1983
2132
  ];
1984
2133
  };
1985
- var post4 = function(param) {
2134
+ var post7 = function(param) {
1986
2135
  var prisma = param.prisma;
1987
2136
  return function() {
1988
2137
  var _ref = _async_to_generator(function(urlString, options) {
@@ -2033,7 +2182,7 @@ var get = function(param) {
2033
2182
  var prisma = param.prisma;
2034
2183
  return function() {
2035
2184
  var _ref = _async_to_generator(function(urlString) {
2036
- var _last, url, _url_pathname_match, threadId, _assign3, limit, order, after, messages4, _last_id;
2185
+ var _last, url, _url_pathname_match, threadId, _assign3, limit, order, after, messages3, _last_id;
2037
2186
  return _ts_generator(this, function(_state) {
2038
2187
  switch(_state.label){
2039
2188
  case 0:
@@ -2061,20 +2210,20 @@ var get = function(param) {
2061
2210
  } : {}))
2062
2211
  ];
2063
2212
  case 1:
2064
- messages4 = _state.sent();
2213
+ messages3 = _state.sent();
2065
2214
  return [
2066
2215
  2,
2067
2216
  new Response(JSON.stringify({
2068
- data: messages4.map(function(message) {
2217
+ data: messages3.map(function(message) {
2069
2218
  return serializeMessage3({
2070
2219
  message: message
2071
2220
  });
2072
2221
  }),
2073
2222
  hasNextPage: function() {
2074
- return messages4.length === parseInt(limit);
2223
+ return messages3.length === parseInt(limit);
2075
2224
  },
2076
2225
  body: {
2077
- last_id: (_last_id = (_last = last(messages4)) === null || _last === void 0 ? void 0 : _last.id) !== null && _last_id !== void 0 ? _last_id : null
2226
+ last_id: (_last_id = (_last = last(messages3)) === null || _last === void 0 ? void 0 : _last.id) !== null && _last_id !== void 0 ? _last_id : null
2078
2227
  }
2079
2228
  }), {
2080
2229
  status: 200,
@@ -2092,10 +2241,10 @@ var get = function(param) {
2092
2241
  }();
2093
2242
  };
2094
2243
  // src/adapters/storage/prismaStorageAdapter/threads/messages/index.ts
2095
- var messages3 = function(param) {
2244
+ var messages2 = function(param) {
2096
2245
  var prisma = param.prisma;
2097
2246
  return {
2098
- post: post4({
2247
+ post: post7({
2099
2248
  prisma: prisma
2100
2249
  }),
2101
2250
  get: get({
@@ -2106,23 +2255,23 @@ var messages3 = function(param) {
2106
2255
  // src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
2107
2256
  import { assign as assign4, last as last2 } from "radash";
2108
2257
  // src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
2109
- import dayjs6 from "dayjs";
2258
+ import dayjs5 from "dayjs";
2110
2259
  var serializeRun = function(param) {
2111
2260
  var run2 = param.run;
2112
2261
  return {
2113
2262
  id: run2.id,
2114
2263
  object: "thread.run",
2115
- created_at: dayjs6(run2.createdAt).unix(),
2264
+ created_at: dayjs5(run2.createdAt).unix(),
2116
2265
  thread_id: run2.threadId,
2117
2266
  assistant_id: run2.assistantId,
2118
2267
  status: run2.status.toLowerCase(),
2119
2268
  required_action: run2.requiredAction,
2120
2269
  last_error: run2.lastError,
2121
- expires_at: dayjs6(run2.expiresAt).unix(),
2122
- started_at: run2.startedAt ? dayjs6(run2.startedAt).unix() : null,
2123
- cancelled_at: run2.cancelledAt ? dayjs6(run2.cancelledAt).unix() : null,
2124
- failed_at: run2.failedAt ? dayjs6(run2.failedAt).unix() : null,
2125
- completed_at: run2.completedAt ? dayjs6(run2.completedAt).unix() : null,
2270
+ expires_at: dayjs5(run2.expiresAt).unix(),
2271
+ started_at: run2.startedAt ? dayjs5(run2.startedAt).unix() : null,
2272
+ cancelled_at: run2.cancelledAt ? dayjs5(run2.cancelledAt).unix() : null,
2273
+ failed_at: run2.failedAt ? dayjs5(run2.failedAt).unix() : null,
2274
+ completed_at: run2.completedAt ? dayjs5(run2.completedAt).unix() : null,
2126
2275
  model: run2.model,
2127
2276
  instructions: run2.instructions,
2128
2277
  tools: run2.tools,
@@ -2207,7 +2356,7 @@ var get2 = function(param) {
2207
2356
  }();
2208
2357
  };
2209
2358
  // src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
2210
- import dayjs8 from "dayjs";
2359
+ import dayjs7 from "dayjs";
2211
2360
  import { assign as assign5 } from "radash";
2212
2361
  // src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunInProgress.ts
2213
2362
  var threadRunInProgress = function(param) {
@@ -2266,13 +2415,13 @@ var threadRunRequiresAction = function(param) {
2266
2415
  });
2267
2416
  };
2268
2417
  // src/adapters/storage/prismaStorageAdapter/threads/runs/steps/serializeRunStep.ts
2269
- import dayjs7 from "dayjs";
2418
+ import dayjs6 from "dayjs";
2270
2419
  var serializeRunStep = function(param) {
2271
2420
  var runStep = param.runStep;
2272
2421
  return {
2273
2422
  id: runStep.id,
2274
2423
  object: "thread.run.step",
2275
- created_at: dayjs7(runStep.createdAt).unix(),
2424
+ created_at: dayjs6(runStep.createdAt).unix(),
2276
2425
  assistant_id: runStep.assistantId,
2277
2426
  thread_id: runStep.threadId,
2278
2427
  run_id: runStep.runId,
@@ -2281,10 +2430,10 @@ var serializeRunStep = function(param) {
2281
2430
  // @ts-ignore-next-line
2282
2431
  step_details: runStep.stepDetails,
2283
2432
  last_error: runStep.lastError,
2284
- expired_at: runStep.expiredAt ? dayjs7(runStep.expiredAt).unix() : null,
2285
- cancelled_at: runStep.cancelledAt ? dayjs7(runStep.cancelledAt).unix() : null,
2286
- failed_at: runStep.failedAt ? dayjs7(runStep.failedAt).unix() : null,
2287
- completed_at: runStep.completedAt ? dayjs7(runStep.completedAt).unix() : null,
2433
+ expired_at: runStep.expiredAt ? dayjs6(runStep.expiredAt).unix() : null,
2434
+ cancelled_at: runStep.cancelledAt ? dayjs6(runStep.cancelledAt).unix() : null,
2435
+ failed_at: runStep.failedAt ? dayjs6(runStep.failedAt).unix() : null,
2436
+ completed_at: runStep.completedAt ? dayjs6(runStep.completedAt).unix() : null,
2288
2437
  metadata: runStep.metadata,
2289
2438
  usage: runStep.usage
2290
2439
  };
@@ -2514,7 +2663,7 @@ var getTake = function(param) {
2514
2663
  var getMessages = function(param) {
2515
2664
  var prisma = param.prisma, run2 = param.run;
2516
2665
  return /*#__PURE__*/ _async_to_generator(function() {
2517
- var take, messages4;
2666
+ var take, messages3;
2518
2667
  return _ts_generator(this, function(_state) {
2519
2668
  switch(_state.label){
2520
2669
  case 0:
@@ -2542,10 +2691,10 @@ var getMessages = function(param) {
2542
2691
  } : {}))
2543
2692
  ];
2544
2693
  case 1:
2545
- messages4 = _state.sent();
2694
+ messages3 = _state.sent();
2546
2695
  return [
2547
2696
  2,
2548
- messages4.map(function(message) {
2697
+ messages3.map(function(message) {
2549
2698
  return _object_spread_props(_object_spread({}, serializeMessage3({
2550
2699
  message: message
2551
2700
  })), {
@@ -2566,7 +2715,7 @@ var getMessages = function(param) {
2566
2715
  });
2567
2716
  };
2568
2717
  // src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
2569
- var post5 = function(param) {
2718
+ var post8 = function(param) {
2570
2719
  var prisma = param.prisma, runAdapter = param.runAdapter;
2571
2720
  return function() {
2572
2721
  var _ref = _async_to_generator(function(urlString, options) {
@@ -2608,7 +2757,7 @@ var post5 = function(param) {
2608
2757
  prisma.run.create({
2609
2758
  data: {
2610
2759
  status: "QUEUED",
2611
- expiresAt: dayjs8().add(1, "hour").unix(),
2760
+ expiresAt: dayjs7().add(1, "hour").unix(),
2612
2761
  model: model,
2613
2762
  instructions: instructions,
2614
2763
  tools: tools,
@@ -2706,7 +2855,7 @@ var runs = function(param) {
2706
2855
  get: get2({
2707
2856
  prisma: prisma
2708
2857
  }),
2709
- post: post5({
2858
+ post: post8({
2710
2859
  prisma: prisma,
2711
2860
  runAdapter: runAdapter
2712
2861
  })
@@ -2839,7 +2988,7 @@ var steps = function(param) {
2839
2988
  };
2840
2989
  };
2841
2990
  // src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/post/updateRun.ts
2842
- import dayjs9 from "dayjs";
2991
+ import dayjs8 from "dayjs";
2843
2992
  var updateRun = function() {
2844
2993
  var _ref = _async_to_generator(function(param) {
2845
2994
  var prisma, runId, threadId, _param_onThreadRunStepCompleted, onThreadRunStepCompleted, tool_outputs;
@@ -2892,7 +3041,7 @@ var updateRun = function() {
2892
3041
  },
2893
3042
  data: {
2894
3043
  status: "COMPLETED",
2895
- completedAt: dayjs9().unix(),
3044
+ completedAt: dayjs8().unix(),
2896
3045
  stepDetails: {
2897
3046
  type: "tool_calls",
2898
3047
  // @ts-ignore-next-line
@@ -3007,7 +3156,7 @@ var updateRun = function() {
3007
3156
  };
3008
3157
  }();
3009
3158
  // src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
3010
- var post6 = function(param) {
3159
+ var post9 = function(param) {
3011
3160
  var prisma = param.prisma, runAdapter = param.runAdapter;
3012
3161
  return function() {
3013
3162
  var _ref = _async_to_generator(function(urlString, options) {
@@ -3182,7 +3331,7 @@ var post6 = function(param) {
3182
3331
  var submitToolOutputs = function(param) {
3183
3332
  var prisma = param.prisma, runAdapter = param.runAdapter;
3184
3333
  return {
3185
- post: post6({
3334
+ post: post9({
3186
3335
  prisma: prisma,
3187
3336
  // @ts-ignore-next-line
3188
3337
  runAdapter: runAdapter
@@ -3198,7 +3347,7 @@ var prismaStorageAdapter = function(param) {
3198
3347
  "^/v1/threads$": threads({
3199
3348
  prisma: prisma
3200
3349
  }),
3201
- "^/v1/threads/([^/]+)/messages$": messages3({
3350
+ "^/v1/threads/([^/]+)/messages$": messages2({
3202
3351
  prisma: prisma
3203
3352
  }),
3204
3353
  "^/v1/threads/([^/]+)/runs$": runs({
@@ -3219,5 +3368,5 @@ var prismaStorageAdapter = function(param) {
3219
3368
  };
3220
3369
  };
3221
3370
  };
3222
- export { anthropicClientAdapter, anthropicRunAdapter, completionsRunAdapter, groqClientAdapter, mistralClientAdapter, openaiClientAdapter, perplexityClientAdapter, prismaStorageAdapter, supercompat };
3371
+ export { anthropicClientAdapter, completionsRunAdapter, groqClientAdapter, mistralClientAdapter, openaiClientAdapter, perplexityClientAdapter, prismaStorageAdapter, supercompat };
3223
3372
  //# sourceMappingURL=index.js.map