supercompat 1.0.5 → 1.1.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.js CHANGED
@@ -429,11 +429,11 @@ var serializeMessage = function(param) {
429
429
  // src/adapters/run/completionsRunAdapter/messages.ts
430
430
  var messages = function() {
431
431
  var _ref = _async_to_generator(function(param) {
432
- var run, getMessages2, _, _1;
432
+ var run, getMessages2, messagesHistoryLength, _, _1;
433
433
  return _ts_generator(this, function(_state) {
434
434
  switch(_state.label){
435
435
  case 0:
436
- run = param.run, getMessages2 = param.getMessages;
436
+ run = param.run, getMessages2 = param.getMessages, messagesHistoryLength = param.messagesHistoryLength;
437
437
  _1 = (_ = _to_consumable_array(run.instructions ? [
438
438
  {
439
439
  role: "system",
@@ -442,7 +442,9 @@ var messages = function() {
442
442
  ] : [])).concat;
443
443
  return [
444
444
  4,
445
- getMessages2()
445
+ getMessages2({
446
+ messagesHistoryLength: messagesHistoryLength
447
+ })
446
448
  ];
447
449
  case 1:
448
450
  return [
@@ -534,177 +536,110 @@ var toolCallsData = function(param) {
534
536
  }
535
537
  return newToolCalls;
536
538
  };
537
- var completionsRunAdapter = function() {
538
- var _ref = _async_to_generator(function(param) {
539
- var client, run, onEvent2, getMessages2, opts, _tmp, providerResponse, e, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, _delta_content, err;
540
- return _ts_generator(this, function(_state) {
541
- switch(_state.label){
542
- case 0:
543
- client = param.client, run = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
544
- if (run.status !== "queued") return [
545
- 2
546
- ];
547
- onEvent2({
548
- event: "thread.run.in_progress",
549
- data: _object_spread_props(_object_spread({}, run), {
550
- status: "in_progress"
551
- })
552
- });
553
- _tmp = {};
554
- return [
555
- 4,
556
- messages({
557
- run: run,
558
- getMessages: getMessages2
559
- })
560
- ];
561
- case 1:
562
- opts = _object_spread.apply(void 0, [
563
- (_tmp.messages = _state.sent(), _tmp.model = run.model, _tmp.stream = true, _tmp),
564
- isEmpty(run.tools) ? {} : {
565
- tools: run.tools
566
- }
567
- ]);
568
- console.dir({
569
- opts: opts
570
- }, {
571
- depth: null
572
- });
573
- _state.label = 2;
574
- case 2:
575
- _state.trys.push([
576
- 2,
577
- 4,
578
- ,
579
- 5
580
- ]);
581
- return [
582
- 4,
583
- client.chat.completions.create(opts)
584
- ];
585
- case 3:
586
- providerResponse = _state.sent();
587
- return [
588
- 3,
589
- 5
590
- ];
591
- case 4:
592
- e = _state.sent();
593
- console.error(e);
594
- return [
595
- 2,
539
+ var completionsRunAdapter = function(param) {
540
+ var _param_messagesHistoryLength = param.messagesHistoryLength, messagesHistoryLength = _param_messagesHistoryLength === void 0 ? 10 : _param_messagesHistoryLength;
541
+ return function() {
542
+ var _ref = _async_to_generator(function(param) {
543
+ var client, run, onEvent2, getMessages2, opts, _tmp, providerResponse, e, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, _delta_content, err;
544
+ return _ts_generator(this, function(_state) {
545
+ switch(_state.label){
546
+ case 0:
547
+ client = param.client, run = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
548
+ if (run.status !== "queued") return [
549
+ 2
550
+ ];
596
551
  onEvent2({
597
- event: "thread.run.failed",
552
+ event: "thread.run.in_progress",
598
553
  data: _object_spread_props(_object_spread({}, run), {
599
- failed_at: dayjs().unix(),
600
- status: "in_progress",
601
- last_error: e.message
602
- })
603
- })
604
- ];
605
- case 5:
606
- return [
607
- 4,
608
- onEvent2({
609
- event: "thread.message.created",
610
- data: {
611
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
612
- object: "thread.message",
613
- completed_at: null,
614
- run_id: run.id,
615
- created_at: dayjs().unix(),
616
- assistant_id: run.assistant_id,
617
- incomplete_at: null,
618
- incomplete_details: null,
619
- metadata: {},
620
- file_ids: [],
621
- thread_id: run.thread_id,
622
- content: [
623
- {
624
- text: {
625
- value: "",
626
- annotations: []
627
- },
628
- type: "text"
629
- }
630
- ],
631
- role: "assistant",
632
554
  status: "in_progress"
555
+ })
556
+ });
557
+ _tmp = {};
558
+ return [
559
+ 4,
560
+ messages({
561
+ run: run,
562
+ getMessages: getMessages2,
563
+ messagesHistoryLength: messagesHistoryLength
564
+ })
565
+ ];
566
+ case 1:
567
+ opts = _object_spread.apply(void 0, [
568
+ (_tmp.messages = _state.sent(), _tmp.model = run.model, _tmp.stream = true, _tmp),
569
+ isEmpty(run.tools) ? {} : {
570
+ tools: run.tools
633
571
  }
634
- })
635
- ];
636
- case 6:
637
- message = _state.sent();
638
- onEvent2({
639
- event: "thread.run.step.created",
640
- data: {
641
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
642
- object: "thread.run.step",
643
- run_id: run.id,
644
- assistant_id: run.assistant_id,
645
- thread_id: run.thread_id,
646
- type: "message_creation",
647
- status: "completed",
648
- completed_at: dayjs().unix(),
649
- created_at: dayjs().unix(),
650
- expired_at: null,
651
- last_error: null,
652
- metadata: {},
653
- failed_at: null,
654
- cancelled_at: null,
655
- usage: null,
656
- step_details: {
657
- type: "message_creation",
658
- message_creation: {
659
- message_id: message.id
572
+ ]);
573
+ console.dir({
574
+ opts: opts
575
+ }, {
576
+ depth: null
577
+ });
578
+ _state.label = 2;
579
+ case 2:
580
+ _state.trys.push([
581
+ 2,
582
+ 4,
583
+ ,
584
+ 5
585
+ ]);
586
+ return [
587
+ 4,
588
+ client.chat.completions.create(opts)
589
+ ];
590
+ case 3:
591
+ providerResponse = _state.sent();
592
+ return [
593
+ 3,
594
+ 5
595
+ ];
596
+ case 4:
597
+ e = _state.sent();
598
+ console.error(e);
599
+ return [
600
+ 2,
601
+ onEvent2({
602
+ event: "thread.run.failed",
603
+ data: _object_spread_props(_object_spread({}, run), {
604
+ failed_at: dayjs().unix(),
605
+ status: "in_progress",
606
+ last_error: e.message
607
+ })
608
+ })
609
+ ];
610
+ case 5:
611
+ return [
612
+ 4,
613
+ onEvent2({
614
+ event: "thread.message.created",
615
+ data: {
616
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
617
+ object: "thread.message",
618
+ completed_at: null,
619
+ run_id: run.id,
620
+ created_at: dayjs().unix(),
621
+ assistant_id: run.assistant_id,
622
+ incomplete_at: null,
623
+ incomplete_details: null,
624
+ metadata: {},
625
+ file_ids: [],
626
+ thread_id: run.thread_id,
627
+ content: [
628
+ {
629
+ text: {
630
+ value: "",
631
+ annotations: []
632
+ },
633
+ type: "text"
634
+ }
635
+ ],
636
+ role: "assistant",
637
+ status: "in_progress"
660
638
  }
661
- }
662
- }
663
- });
664
- currentContent = "";
665
- console.dir({
666
- providerResponse: providerResponse
667
- }, {
668
- depth: null
669
- });
670
- _iteratorAbruptCompletion = false, _didIteratorError = false;
671
- _state.label = 7;
672
- case 7:
673
- _state.trys.push([
674
- 7,
675
- 15,
676
- 16,
677
- 21
678
- ]);
679
- _iterator = _async_iterator(providerResponse);
680
- _state.label = 8;
681
- case 8:
682
- return [
683
- 4,
684
- _iterator.next()
685
- ];
686
- case 9:
687
- if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
688
- 3,
689
- 14
690
- ];
691
- _value = _step.value;
692
- chunk = _value;
693
- delta = chunk.choices[0].delta;
694
- if (delta.content) {
695
- ;
696
- currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
697
- }
698
- if (!delta.tool_calls) return [
699
- 3,
700
- 12
701
- ];
702
- if (!!toolCallsRunStep) return [
703
- 3,
704
- 11
705
- ];
706
- return [
707
- 4,
639
+ })
640
+ ];
641
+ case 6:
642
+ message = _state.sent();
708
643
  onEvent2({
709
644
  event: "thread.run.step.created",
710
645
  data: {
@@ -713,9 +648,9 @@ var completionsRunAdapter = function() {
713
648
  run_id: run.id,
714
649
  assistant_id: run.assistant_id,
715
650
  thread_id: run.thread_id,
716
- type: "tool_calls",
717
- status: "in_progress",
718
- completed_at: null,
651
+ type: "message_creation",
652
+ status: "completed",
653
+ completed_at: dayjs().unix(),
719
654
  created_at: dayjs().unix(),
720
655
  expired_at: null,
721
656
  last_error: null,
@@ -724,170 +659,241 @@ var completionsRunAdapter = function() {
724
659
  cancelled_at: null,
725
660
  usage: null,
726
661
  step_details: {
727
- type: "tool_calls",
728
- tool_calls: []
662
+ type: "message_creation",
663
+ message_creation: {
664
+ message_id: message.id
665
+ }
729
666
  }
730
667
  }
731
- })
732
- ];
733
- case 10:
734
- toolCallsRunStep = _state.sent();
735
- _state.label = 11;
736
- case 11:
737
- onEvent2({
738
- event: "thread.run.step.delta",
739
- data: {
740
- object: "thread.run.step.delta",
741
- run_id: run.id,
742
- id: toolCallsRunStep.id,
743
- delta: {
744
- step_details: {
668
+ });
669
+ currentContent = "";
670
+ console.dir({
671
+ providerResponse: providerResponse
672
+ }, {
673
+ depth: null
674
+ });
675
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
676
+ _state.label = 7;
677
+ case 7:
678
+ _state.trys.push([
679
+ 7,
680
+ 15,
681
+ 16,
682
+ 21
683
+ ]);
684
+ _iterator = _async_iterator(providerResponse);
685
+ _state.label = 8;
686
+ case 8:
687
+ return [
688
+ 4,
689
+ _iterator.next()
690
+ ];
691
+ case 9:
692
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
693
+ 3,
694
+ 14
695
+ ];
696
+ _value = _step.value;
697
+ chunk = _value;
698
+ delta = chunk.choices[0].delta;
699
+ if (delta.content) {
700
+ ;
701
+ currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
702
+ }
703
+ if (!delta.tool_calls) return [
704
+ 3,
705
+ 12
706
+ ];
707
+ if (!!toolCallsRunStep) return [
708
+ 3,
709
+ 11
710
+ ];
711
+ return [
712
+ 4,
713
+ onEvent2({
714
+ event: "thread.run.step.created",
715
+ data: {
716
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
717
+ object: "thread.run.step",
718
+ run_id: run.id,
719
+ assistant_id: run.assistant_id,
720
+ thread_id: run.thread_id,
745
721
  type: "tool_calls",
746
- tool_calls: delta.tool_calls.map(function(tc) {
747
- return _object_spread({
748
- id: uid(24),
749
- type: "function"
750
- }, tc);
751
- })
722
+ status: "in_progress",
723
+ completed_at: null,
724
+ created_at: dayjs().unix(),
725
+ expired_at: null,
726
+ last_error: null,
727
+ metadata: {},
728
+ failed_at: null,
729
+ cancelled_at: null,
730
+ usage: null,
731
+ step_details: {
732
+ type: "tool_calls",
733
+ tool_calls: []
734
+ }
752
735
  }
753
- }
754
- }
755
- });
756
- currentToolCalls = toolCallsData({
757
- prevToolCalls: currentToolCalls,
758
- delta: delta
759
- });
760
- _state.label = 12;
761
- case 12:
762
- if (delta.content) {
736
+ })
737
+ ];
738
+ case 10:
739
+ toolCallsRunStep = _state.sent();
740
+ _state.label = 11;
741
+ case 11:
763
742
  onEvent2({
764
- event: "thread.message.delta",
743
+ event: "thread.run.step.delta",
765
744
  data: {
766
- id: message.id,
745
+ object: "thread.run.step.delta",
746
+ run_id: run.id,
747
+ id: toolCallsRunStep.id,
767
748
  delta: {
768
- content: [
769
- {
770
- type: "text",
771
- index: 0,
772
- text: {
773
- value: delta.content
774
- }
775
- }
776
- ]
749
+ step_details: {
750
+ type: "tool_calls",
751
+ tool_calls: delta.tool_calls.map(function(tc) {
752
+ return _object_spread({
753
+ id: uid(24),
754
+ type: "function"
755
+ }, tc);
756
+ })
757
+ }
777
758
  }
778
759
  }
779
760
  });
780
- }
781
- _state.label = 13;
782
- case 13:
783
- _iteratorAbruptCompletion = false;
784
- return [
785
- 3,
786
- 8
787
- ];
788
- case 14:
789
- return [
790
- 3,
791
- 21
792
- ];
793
- case 15:
794
- err = _state.sent();
795
- _didIteratorError = true;
796
- _iteratorError = err;
797
- return [
798
- 3,
799
- 21
800
- ];
801
- case 16:
802
- _state.trys.push([
803
- 16,
804
- ,
805
- 19,
806
- 20
807
- ]);
808
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
809
- 3,
810
- 18
811
- ];
812
- return [
813
- 4,
814
- _iterator.return()
815
- ];
816
- case 17:
817
- _state.sent();
818
- _state.label = 18;
819
- case 18:
820
- return [
821
- 3,
822
- 20
823
- ];
824
- case 19:
825
- if (_didIteratorError) {
826
- throw _iteratorError;
827
- }
828
- return [
829
- 7
830
- ];
831
- case 20:
832
- return [
833
- 7
834
- ];
835
- case 21:
836
- return [
837
- 4,
838
- onEvent2({
839
- event: "thread.message.completed",
840
- data: _object_spread_props(_object_spread({}, message), {
841
- status: "completed",
842
- content: [
843
- {
844
- text: {
845
- value: currentContent,
846
- annotations: []
847
- },
848
- type: "text"
761
+ currentToolCalls = toolCallsData({
762
+ prevToolCalls: currentToolCalls,
763
+ delta: delta
764
+ });
765
+ _state.label = 12;
766
+ case 12:
767
+ if (delta.content) {
768
+ onEvent2({
769
+ event: "thread.message.delta",
770
+ data: {
771
+ id: message.id,
772
+ delta: {
773
+ content: [
774
+ {
775
+ type: "text",
776
+ index: 0,
777
+ text: {
778
+ value: delta.content
779
+ }
780
+ }
781
+ ]
849
782
  }
850
- ],
851
- tool_calls: currentToolCalls
852
- })
853
- })
854
- ];
855
- case 22:
856
- message = _state.sent();
857
- if (isEmpty(message.toolCalls)) {
783
+ }
784
+ });
785
+ }
786
+ _state.label = 13;
787
+ case 13:
788
+ _iteratorAbruptCompletion = false;
858
789
  return [
859
- 2,
790
+ 3,
791
+ 8
792
+ ];
793
+ case 14:
794
+ return [
795
+ 3,
796
+ 21
797
+ ];
798
+ case 15:
799
+ err = _state.sent();
800
+ _didIteratorError = true;
801
+ _iteratorError = err;
802
+ return [
803
+ 3,
804
+ 21
805
+ ];
806
+ case 16:
807
+ _state.trys.push([
808
+ 16,
809
+ ,
810
+ 19,
811
+ 20
812
+ ]);
813
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
814
+ 3,
815
+ 18
816
+ ];
817
+ return [
818
+ 4,
819
+ _iterator.return()
820
+ ];
821
+ case 17:
822
+ _state.sent();
823
+ _state.label = 18;
824
+ case 18:
825
+ return [
826
+ 3,
827
+ 20
828
+ ];
829
+ case 19:
830
+ if (_didIteratorError) {
831
+ throw _iteratorError;
832
+ }
833
+ return [
834
+ 7
835
+ ];
836
+ case 20:
837
+ return [
838
+ 7
839
+ ];
840
+ case 21:
841
+ return [
842
+ 4,
860
843
  onEvent2({
861
- event: "thread.run.completed",
862
- data: _object_spread_props(_object_spread({}, run), {
844
+ event: "thread.message.completed",
845
+ data: _object_spread_props(_object_spread({}, message), {
863
846
  status: "completed",
864
- completed_at: dayjs().unix()
847
+ content: [
848
+ {
849
+ text: {
850
+ value: currentContent,
851
+ annotations: []
852
+ },
853
+ type: "text"
854
+ }
855
+ ],
856
+ tool_calls: currentToolCalls
865
857
  })
866
858
  })
867
859
  ];
868
- }
869
- return [
870
- 2,
871
- onEvent2({
872
- event: "thread.run.requires_action",
873
- data: _object_spread_props(_object_spread({}, run), {
874
- status: "requires_action",
875
- required_action: {
876
- type: "submit_tool_outputs",
877
- submit_tool_outputs: {
878
- tool_calls: message.toolCalls
860
+ case 22:
861
+ message = _state.sent();
862
+ if (isEmpty(message.toolCalls)) {
863
+ return [
864
+ 2,
865
+ onEvent2({
866
+ event: "thread.run.completed",
867
+ data: _object_spread_props(_object_spread({}, run), {
868
+ status: "completed",
869
+ completed_at: dayjs().unix()
870
+ })
871
+ })
872
+ ];
873
+ }
874
+ return [
875
+ 2,
876
+ onEvent2({
877
+ event: "thread.run.requires_action",
878
+ data: _object_spread_props(_object_spread({}, run), {
879
+ status: "requires_action",
880
+ required_action: {
881
+ type: "submit_tool_outputs",
882
+ submit_tool_outputs: {
883
+ tool_calls: message.toolCalls
884
+ }
879
885
  }
880
- }
886
+ })
881
887
  })
882
- })
883
- ];
884
- }
888
+ ];
889
+ }
890
+ });
885
891
  });
886
- });
887
- return function completionsRunAdapter(_) {
888
- return _ref.apply(this, arguments);
889
- };
890
- }();
892
+ return function(_) {
893
+ return _ref.apply(this, arguments);
894
+ };
895
+ }();
896
+ };
891
897
  // src/adapters/storage/prismaStorageAdapter/beta/threads/create.ts
892
898
  import dayjs3 from "dayjs";
893
899
  // src/adapters/storage/prismaStorageAdapter/beta/threads/serializeThread.ts
@@ -1554,53 +1560,59 @@ var onEvent = function(param) {
1554
1560
  // src/adapters/storage/prismaStorageAdapter/beta/threads/runs/getMessages.ts
1555
1561
  var getMessages = function(param) {
1556
1562
  var prisma = param.prisma, run = param.run;
1557
- return /*#__PURE__*/ _async_to_generator(function() {
1558
- var messages3;
1559
- return _ts_generator(this, function(_state) {
1560
- switch(_state.label){
1561
- case 0:
1562
- return [
1563
- 4,
1564
- prisma.message.findMany({
1565
- where: {
1566
- threadId: run.threadId
1567
- },
1568
- include: {
1569
- run: {
1570
- include: {
1571
- runSteps: true
1563
+ return function() {
1564
+ var _ref = _async_to_generator(function(param) {
1565
+ var messagesHistoryLength, messages3;
1566
+ return _ts_generator(this, function(_state) {
1567
+ switch(_state.label){
1568
+ case 0:
1569
+ messagesHistoryLength = param.messagesHistoryLength;
1570
+ return [
1571
+ 4,
1572
+ prisma.message.findMany({
1573
+ where: {
1574
+ threadId: run.threadId
1575
+ },
1576
+ include: {
1577
+ run: {
1578
+ include: {
1579
+ runSteps: true
1580
+ }
1572
1581
  }
1582
+ },
1583
+ take: -messagesHistoryLength,
1584
+ orderBy: {
1585
+ createdAt: "asc"
1573
1586
  }
1574
- },
1575
- take: -10,
1576
- orderBy: {
1577
- createdAt: "asc"
1578
- }
1579
- })
1580
- ];
1581
- case 1:
1582
- messages3 = _state.sent();
1583
- return [
1584
- 2,
1585
- messages3.map(function(message) {
1586
- return _object_spread_props(_object_spread({}, serializeMessage2({
1587
- message: message
1588
- })), {
1589
- run: message.run ? _object_spread_props(_object_spread({}, serializeRun({
1590
- run: message.run
1587
+ })
1588
+ ];
1589
+ case 1:
1590
+ messages3 = _state.sent();
1591
+ return [
1592
+ 2,
1593
+ messages3.map(function(message) {
1594
+ return _object_spread_props(_object_spread({}, serializeMessage2({
1595
+ message: message
1591
1596
  })), {
1592
- runSteps: message.run.runSteps.map(function(runStep) {
1593
- return serializeRunStep({
1594
- runStep: runStep
1595
- });
1596
- })
1597
- }) : null
1598
- });
1599
- })
1600
- ];
1601
- }
1597
+ run: message.run ? _object_spread_props(_object_spread({}, serializeRun({
1598
+ run: message.run
1599
+ })), {
1600
+ runSteps: message.run.runSteps.map(function(runStep) {
1601
+ return serializeRunStep({
1602
+ runStep: runStep
1603
+ });
1604
+ })
1605
+ }) : null
1606
+ });
1607
+ })
1608
+ ];
1609
+ }
1610
+ });
1602
1611
  });
1603
- });
1612
+ return function(_) {
1613
+ return _ref.apply(this, arguments);
1614
+ };
1615
+ }();
1604
1616
  };
1605
1617
  // src/adapters/storage/prismaStorageAdapter/beta/threads/runs/createAndStream.ts
1606
1618
  var createAndStream = function(param) {