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