supercompat 3.1.0 → 3.4.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 CHANGED
@@ -435,10 +435,16 @@ var storageRequestHandlers = function(param) {
435
435
  var storage = param.storage, runAdapter = param.runAdapter, client = param.client;
436
436
  if (!storage) return {};
437
437
  if (!runAdapter) return {};
438
+ var wrappedClient = supercompat({
439
+ client: client
440
+ });
438
441
  var result = storage({
439
- runAdapter: (0, import_radash.partob)(runAdapter, {
440
- client: client
441
- })
442
+ runAdapter: _object_spread_props(_object_spread({}, runAdapter), {
443
+ handleRun: (0, import_radash.partob)(runAdapter.handleRun, {
444
+ client: wrappedClient
445
+ })
446
+ }),
447
+ client: wrappedClient
442
448
  });
443
449
  return result.requestHandlers;
444
450
  };
@@ -3452,179 +3458,106 @@ var toolCallsData = function(param) {
3452
3458
  return newToolCalls;
3453
3459
  };
3454
3460
  var completionsRunAdapter = function() {
3455
- return /*#__PURE__*/ function() {
3456
- var _ref = _async_to_generator(function(param) {
3457
- var clientAdapter, run3, onEvent2, getMessages2, client, opts, _tmp, providerResponse, e, _e_cause, _e_message, _e_cause_message, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, _delta_content, err;
3458
- return _ts_generator(this, function(_state) {
3459
- switch(_state.label){
3460
- case 0:
3461
- clientAdapter = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
3462
- if (run3.status !== "queued") return [
3463
- 2
3464
- ];
3465
- client = supercompat({
3466
- client: clientAdapter
3467
- });
3468
- onEvent2({
3469
- event: "thread.run.in_progress",
3470
- data: _object_spread_props(_object_spread({}, run3), {
3471
- status: "in_progress"
3472
- })
3473
- });
3474
- _tmp = {};
3475
- return [
3476
- 4,
3477
- messages({
3478
- run: run3,
3479
- getMessages: getMessages2
3480
- })
3481
- ];
3482
- case 1:
3483
- opts = _object_spread.apply(void 0, [
3484
- (_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
3485
- (0, import_radash6.isEmpty)(run3.tools) ? {} : {
3486
- tools: run3.tools
3487
- }
3488
- ]);
3489
- _state.label = 2;
3490
- case 2:
3491
- _state.trys.push([
3492
- 2,
3493
- 4,
3494
- ,
3495
- 5
3496
- ]);
3497
- return [
3498
- 4,
3499
- client.chat.completions.create(opts)
3500
- ];
3501
- case 3:
3502
- providerResponse = _state.sent();
3503
- return [
3504
- 3,
3505
- 5
3506
- ];
3507
- case 4:
3508
- e = _state.sent();
3509
- console.error(e);
3510
- return [
3511
- 2,
3461
+ return {
3462
+ handleRun: /*#__PURE__*/ function() {
3463
+ var _ref = _async_to_generator(function(param) {
3464
+ var client, run3, onEvent2, getMessages2, opts, _tmp, providerResponse, e, _e_cause, _e_message, _e_cause_message, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, _delta_content, err;
3465
+ return _ts_generator(this, function(_state) {
3466
+ switch(_state.label){
3467
+ case 0:
3468
+ client = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
3469
+ if (run3.status !== "queued") return [
3470
+ 2
3471
+ ];
3512
3472
  onEvent2({
3513
- event: "thread.run.failed",
3473
+ event: "thread.run.in_progress",
3514
3474
  data: _object_spread_props(_object_spread({}, run3), {
3515
- failed_at: (0, import_dayjs.default)().unix(),
3516
- status: "in_progress",
3517
- last_error: {
3518
- code: "server_error",
3519
- message: "".concat((_e_message = e === null || e === void 0 ? void 0 : e.message) !== null && _e_message !== void 0 ? _e_message : "", " ").concat((_e_cause_message = e === null || e === void 0 ? void 0 : (_e_cause = e.cause) === null || _e_cause === void 0 ? void 0 : _e_cause.message) !== null && _e_cause_message !== void 0 ? _e_cause_message : "")
3520
- }
3521
- })
3522
- })
3523
- ];
3524
- case 5:
3525
- return [
3526
- 4,
3527
- onEvent2({
3528
- event: "thread.message.created",
3529
- data: {
3530
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3531
- object: "thread.message",
3532
- completed_at: null,
3533
- run_id: run3.id,
3534
- created_at: (0, import_dayjs.default)().unix(),
3535
- assistant_id: run3.assistant_id,
3536
- incomplete_at: null,
3537
- incomplete_details: null,
3538
- metadata: {},
3539
- attachments: [],
3540
- thread_id: run3.thread_id,
3541
- content: [
3542
- {
3543
- text: {
3544
- value: "",
3545
- annotations: []
3546
- },
3547
- type: "text"
3548
- }
3549
- ],
3550
- role: "assistant",
3551
3475
  status: "in_progress"
3476
+ })
3477
+ });
3478
+ _tmp = {};
3479
+ return [
3480
+ 4,
3481
+ messages({
3482
+ run: run3,
3483
+ getMessages: getMessages2
3484
+ })
3485
+ ];
3486
+ case 1:
3487
+ opts = _object_spread.apply(void 0, [
3488
+ (_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
3489
+ (0, import_radash6.isEmpty)(run3.tools) ? {} : {
3490
+ tools: run3.tools
3552
3491
  }
3553
- })
3554
- ];
3555
- case 6:
3556
- message = _state.sent();
3557
- onEvent2({
3558
- event: "thread.run.step.created",
3559
- data: {
3560
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3561
- object: "thread.run.step",
3562
- run_id: run3.id,
3563
- assistant_id: run3.assistant_id,
3564
- thread_id: run3.thread_id,
3565
- type: "message_creation",
3566
- status: "completed",
3567
- completed_at: (0, import_dayjs.default)().unix(),
3568
- created_at: (0, import_dayjs.default)().unix(),
3569
- expired_at: null,
3570
- last_error: null,
3571
- metadata: {},
3572
- failed_at: null,
3573
- cancelled_at: null,
3574
- usage: null,
3575
- step_details: {
3576
- type: "message_creation",
3577
- message_creation: {
3578
- message_id: message.id
3492
+ ]);
3493
+ _state.label = 2;
3494
+ case 2:
3495
+ _state.trys.push([
3496
+ 2,
3497
+ 4,
3498
+ ,
3499
+ 5
3500
+ ]);
3501
+ return [
3502
+ 4,
3503
+ client.chat.completions.create(opts)
3504
+ ];
3505
+ case 3:
3506
+ providerResponse = _state.sent();
3507
+ return [
3508
+ 3,
3509
+ 5
3510
+ ];
3511
+ case 4:
3512
+ e = _state.sent();
3513
+ console.error(e);
3514
+ return [
3515
+ 2,
3516
+ onEvent2({
3517
+ event: "thread.run.failed",
3518
+ data: _object_spread_props(_object_spread({}, run3), {
3519
+ failed_at: (0, import_dayjs.default)().unix(),
3520
+ status: "in_progress",
3521
+ last_error: {
3522
+ code: "server_error",
3523
+ message: "".concat((_e_message = e === null || e === void 0 ? void 0 : e.message) !== null && _e_message !== void 0 ? _e_message : "", " ").concat((_e_cause_message = e === null || e === void 0 ? void 0 : (_e_cause = e.cause) === null || _e_cause === void 0 ? void 0 : _e_cause.message) !== null && _e_cause_message !== void 0 ? _e_cause_message : "")
3524
+ }
3525
+ })
3526
+ })
3527
+ ];
3528
+ case 5:
3529
+ return [
3530
+ 4,
3531
+ onEvent2({
3532
+ event: "thread.message.created",
3533
+ data: {
3534
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3535
+ object: "thread.message",
3536
+ completed_at: null,
3537
+ run_id: run3.id,
3538
+ created_at: (0, import_dayjs.default)().unix(),
3539
+ assistant_id: run3.assistant_id,
3540
+ incomplete_at: null,
3541
+ incomplete_details: null,
3542
+ metadata: {},
3543
+ attachments: [],
3544
+ thread_id: run3.thread_id,
3545
+ content: [
3546
+ {
3547
+ text: {
3548
+ value: "",
3549
+ annotations: []
3550
+ },
3551
+ type: "text"
3552
+ }
3553
+ ],
3554
+ role: "assistant",
3555
+ status: "in_progress"
3579
3556
  }
3580
- }
3581
- }
3582
- });
3583
- currentContent = "";
3584
- _iteratorAbruptCompletion = false, _didIteratorError = false;
3585
- _state.label = 7;
3586
- case 7:
3587
- _state.trys.push([
3588
- 7,
3589
- 15,
3590
- 16,
3591
- 21
3592
- ]);
3593
- _iterator = _async_iterator(providerResponse);
3594
- _state.label = 8;
3595
- case 8:
3596
- return [
3597
- 4,
3598
- _iterator.next()
3599
- ];
3600
- case 9:
3601
- if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
3602
- 3,
3603
- 14
3604
- ];
3605
- _value = _step.value;
3606
- chunk = _value;
3607
- choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
3608
- choice = choices[0];
3609
- if (!choice) return [
3610
- 3,
3611
- 13
3612
- ];
3613
- delta = choice.delta;
3614
- if (delta.content) {
3615
- ;
3616
- currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
3617
- }
3618
- if (!delta.tool_calls) return [
3619
- 3,
3620
- 12
3621
- ];
3622
- if (!!toolCallsRunStep) return [
3623
- 3,
3624
- 11
3625
- ];
3626
- return [
3627
- 4,
3557
+ })
3558
+ ];
3559
+ case 6:
3560
+ message = _state.sent();
3628
3561
  onEvent2({
3629
3562
  event: "thread.run.step.created",
3630
3563
  data: {
@@ -3633,9 +3566,9 @@ var completionsRunAdapter = function() {
3633
3566
  run_id: run3.id,
3634
3567
  assistant_id: run3.assistant_id,
3635
3568
  thread_id: run3.thread_id,
3636
- type: "tool_calls",
3637
- status: "in_progress",
3638
- completed_at: null,
3569
+ type: "message_creation",
3570
+ status: "completed",
3571
+ completed_at: (0, import_dayjs.default)().unix(),
3639
3572
  created_at: (0, import_dayjs.default)().unix(),
3640
3573
  expired_at: null,
3641
3574
  last_error: null,
@@ -3644,170 +3577,242 @@ var completionsRunAdapter = function() {
3644
3577
  cancelled_at: null,
3645
3578
  usage: null,
3646
3579
  step_details: {
3647
- type: "tool_calls",
3648
- tool_calls: []
3580
+ type: "message_creation",
3581
+ message_creation: {
3582
+ message_id: message.id
3583
+ }
3649
3584
  }
3650
3585
  }
3651
- })
3652
- ];
3653
- case 10:
3654
- toolCallsRunStep = _state.sent();
3655
- _state.label = 11;
3656
- case 11:
3657
- onEvent2({
3658
- event: "thread.run.step.delta",
3659
- data: {
3660
- object: "thread.run.step.delta",
3661
- run_id: run3.id,
3662
- id: toolCallsRunStep.id,
3663
- delta: {
3664
- step_details: {
3586
+ });
3587
+ currentContent = "";
3588
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
3589
+ _state.label = 7;
3590
+ case 7:
3591
+ _state.trys.push([
3592
+ 7,
3593
+ 15,
3594
+ 16,
3595
+ 21
3596
+ ]);
3597
+ _iterator = _async_iterator(providerResponse);
3598
+ _state.label = 8;
3599
+ case 8:
3600
+ return [
3601
+ 4,
3602
+ _iterator.next()
3603
+ ];
3604
+ case 9:
3605
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
3606
+ 3,
3607
+ 14
3608
+ ];
3609
+ _value = _step.value;
3610
+ chunk = _value;
3611
+ choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
3612
+ choice = choices[0];
3613
+ if (!choice) return [
3614
+ 3,
3615
+ 13
3616
+ ];
3617
+ delta = choice.delta;
3618
+ if (delta.content) {
3619
+ ;
3620
+ currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
3621
+ }
3622
+ if (!delta.tool_calls) return [
3623
+ 3,
3624
+ 12
3625
+ ];
3626
+ if (!!toolCallsRunStep) return [
3627
+ 3,
3628
+ 11
3629
+ ];
3630
+ return [
3631
+ 4,
3632
+ onEvent2({
3633
+ event: "thread.run.step.created",
3634
+ data: {
3635
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3636
+ object: "thread.run.step",
3637
+ run_id: run3.id,
3638
+ assistant_id: run3.assistant_id,
3639
+ thread_id: run3.thread_id,
3665
3640
  type: "tool_calls",
3666
- tool_calls: delta.tool_calls.map(function(tc) {
3667
- return _object_spread({
3668
- id: (0, import_radash6.uid)(24),
3669
- type: "function"
3670
- }, tc);
3671
- })
3641
+ status: "in_progress",
3642
+ completed_at: null,
3643
+ created_at: (0, import_dayjs.default)().unix(),
3644
+ expired_at: null,
3645
+ last_error: null,
3646
+ metadata: {},
3647
+ failed_at: null,
3648
+ cancelled_at: null,
3649
+ usage: null,
3650
+ step_details: {
3651
+ type: "tool_calls",
3652
+ tool_calls: []
3653
+ }
3672
3654
  }
3673
- }
3674
- }
3675
- });
3676
- currentToolCalls = toolCallsData({
3677
- prevToolCalls: currentToolCalls,
3678
- delta: delta
3679
- });
3680
- _state.label = 12;
3681
- case 12:
3682
- if (delta.content) {
3655
+ })
3656
+ ];
3657
+ case 10:
3658
+ toolCallsRunStep = _state.sent();
3659
+ _state.label = 11;
3660
+ case 11:
3683
3661
  onEvent2({
3684
- event: "thread.message.delta",
3662
+ event: "thread.run.step.delta",
3685
3663
  data: {
3686
- id: message.id,
3664
+ object: "thread.run.step.delta",
3665
+ run_id: run3.id,
3666
+ id: toolCallsRunStep.id,
3687
3667
  delta: {
3688
- content: [
3689
- {
3690
- type: "text",
3691
- index: 0,
3692
- text: {
3693
- value: delta.content
3694
- }
3695
- }
3696
- ]
3668
+ step_details: {
3669
+ type: "tool_calls",
3670
+ tool_calls: delta.tool_calls.map(function(tc) {
3671
+ return _object_spread({
3672
+ id: (0, import_radash6.uid)(24),
3673
+ type: "function"
3674
+ }, tc);
3675
+ })
3676
+ }
3697
3677
  }
3698
3678
  }
3699
3679
  });
3700
- }
3701
- _state.label = 13;
3702
- case 13:
3703
- _iteratorAbruptCompletion = false;
3704
- return [
3705
- 3,
3706
- 8
3707
- ];
3708
- case 14:
3709
- return [
3710
- 3,
3711
- 21
3712
- ];
3713
- case 15:
3714
- err = _state.sent();
3715
- _didIteratorError = true;
3716
- _iteratorError = err;
3717
- return [
3718
- 3,
3719
- 21
3720
- ];
3721
- case 16:
3722
- _state.trys.push([
3723
- 16,
3724
- ,
3725
- 19,
3726
- 20
3727
- ]);
3728
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
3729
- 3,
3730
- 18
3731
- ];
3732
- return [
3733
- 4,
3734
- _iterator.return()
3735
- ];
3736
- case 17:
3737
- _state.sent();
3738
- _state.label = 18;
3739
- case 18:
3740
- return [
3741
- 3,
3742
- 20
3743
- ];
3744
- case 19:
3745
- if (_didIteratorError) {
3746
- throw _iteratorError;
3747
- }
3748
- return [
3749
- 7
3750
- ];
3751
- case 20:
3752
- return [
3753
- 7
3754
- ];
3755
- case 21:
3756
- return [
3757
- 4,
3758
- onEvent2({
3759
- event: "thread.message.completed",
3760
- data: _object_spread_props(_object_spread({}, message), {
3761
- status: "completed",
3762
- content: [
3763
- {
3764
- text: {
3765
- value: currentContent,
3766
- annotations: []
3767
- },
3768
- type: "text"
3680
+ currentToolCalls = toolCallsData({
3681
+ prevToolCalls: currentToolCalls,
3682
+ delta: delta
3683
+ });
3684
+ _state.label = 12;
3685
+ case 12:
3686
+ if (delta.content) {
3687
+ onEvent2({
3688
+ event: "thread.message.delta",
3689
+ data: {
3690
+ id: message.id,
3691
+ delta: {
3692
+ content: [
3693
+ {
3694
+ type: "text",
3695
+ index: 0,
3696
+ text: {
3697
+ value: delta.content
3698
+ }
3699
+ }
3700
+ ]
3769
3701
  }
3770
- ],
3771
- tool_calls: currentToolCalls
3772
- })
3773
- })
3774
- ];
3775
- case 22:
3776
- message = _state.sent();
3777
- if ((0, import_radash6.isEmpty)(message.toolCalls)) {
3702
+ }
3703
+ });
3704
+ }
3705
+ _state.label = 13;
3706
+ case 13:
3707
+ _iteratorAbruptCompletion = false;
3778
3708
  return [
3779
- 2,
3709
+ 3,
3710
+ 8
3711
+ ];
3712
+ case 14:
3713
+ return [
3714
+ 3,
3715
+ 21
3716
+ ];
3717
+ case 15:
3718
+ err = _state.sent();
3719
+ _didIteratorError = true;
3720
+ _iteratorError = err;
3721
+ return [
3722
+ 3,
3723
+ 21
3724
+ ];
3725
+ case 16:
3726
+ _state.trys.push([
3727
+ 16,
3728
+ ,
3729
+ 19,
3730
+ 20
3731
+ ]);
3732
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
3733
+ 3,
3734
+ 18
3735
+ ];
3736
+ return [
3737
+ 4,
3738
+ _iterator.return()
3739
+ ];
3740
+ case 17:
3741
+ _state.sent();
3742
+ _state.label = 18;
3743
+ case 18:
3744
+ return [
3745
+ 3,
3746
+ 20
3747
+ ];
3748
+ case 19:
3749
+ if (_didIteratorError) {
3750
+ throw _iteratorError;
3751
+ }
3752
+ return [
3753
+ 7
3754
+ ];
3755
+ case 20:
3756
+ return [
3757
+ 7
3758
+ ];
3759
+ case 21:
3760
+ return [
3761
+ 4,
3780
3762
  onEvent2({
3781
- event: "thread.run.completed",
3782
- data: _object_spread_props(_object_spread({}, run3), {
3763
+ event: "thread.message.completed",
3764
+ data: _object_spread_props(_object_spread({}, message), {
3783
3765
  status: "completed",
3784
- completed_at: (0, import_dayjs.default)().unix()
3766
+ content: [
3767
+ {
3768
+ text: {
3769
+ value: currentContent,
3770
+ annotations: []
3771
+ },
3772
+ type: "text"
3773
+ }
3774
+ ],
3775
+ tool_calls: currentToolCalls
3785
3776
  })
3786
3777
  })
3787
3778
  ];
3788
- }
3789
- return [
3790
- 2,
3791
- onEvent2({
3792
- event: "thread.run.requires_action",
3793
- data: _object_spread_props(_object_spread({}, run3), {
3794
- status: "requires_action",
3795
- required_action: {
3796
- type: "submit_tool_outputs",
3797
- submit_tool_outputs: {
3798
- tool_calls: message.toolCalls
3779
+ case 22:
3780
+ message = _state.sent();
3781
+ if ((0, import_radash6.isEmpty)(message.toolCalls)) {
3782
+ return [
3783
+ 2,
3784
+ onEvent2({
3785
+ event: "thread.run.completed",
3786
+ data: _object_spread_props(_object_spread({}, run3), {
3787
+ status: "completed",
3788
+ completed_at: (0, import_dayjs.default)().unix()
3789
+ })
3790
+ })
3791
+ ];
3792
+ }
3793
+ return [
3794
+ 2,
3795
+ onEvent2({
3796
+ event: "thread.run.requires_action",
3797
+ data: _object_spread_props(_object_spread({}, run3), {
3798
+ status: "requires_action",
3799
+ required_action: {
3800
+ type: "submit_tool_outputs",
3801
+ submit_tool_outputs: {
3802
+ tool_calls: message.toolCalls
3803
+ }
3799
3804
  }
3800
- }
3805
+ })
3801
3806
  })
3802
- })
3803
- ];
3804
- }
3807
+ ];
3808
+ }
3809
+ });
3805
3810
  });
3806
- });
3807
- return function(_) {
3808
- return _ref.apply(this, arguments);
3809
- };
3810
- }();
3811
+ return function(_) {
3812
+ return _ref.apply(this, arguments);
3813
+ };
3814
+ }()
3815
+ };
3811
3816
  };
3812
3817
  // src/lib/messages/messagesRegexp.ts
3813
3818
  var messagesRegexp = "^/(?:v1|/?openai)/threads/([^/]+)/messages$";
@@ -4628,7 +4633,7 @@ var post12 = function(param) {
4628
4633
  ]);
4629
4634
  return [
4630
4635
  4,
4631
- runAdapter({
4636
+ runAdapter.handleRun({
4632
4637
  run: data,
4633
4638
  onEvent: onEvent({
4634
4639
  controller: _object_spread_props(_object_spread({}, controller), {
@@ -5077,7 +5082,7 @@ var post13 = function(param) {
5077
5082
  run3 = _state.sent();
5078
5083
  return [
5079
5084
  4,
5080
- runAdapter({
5085
+ runAdapter.handleRun({
5081
5086
  run: serializeRun({
5082
5087
  run: run3
5083
5088
  }),
@@ -5137,7 +5142,7 @@ var post13 = function(param) {
5137
5142
  case 0:
5138
5143
  return [
5139
5144
  4,
5140
- runAdapter({
5145
+ runAdapter.handleRun({
5141
5146
  run: serializeRun({
5142
5147
  run: run3
5143
5148
  }),
@@ -5308,7 +5313,7 @@ var serializeThread2 = function(param) {
5308
5313
  };
5309
5314
  // src/adapters/storage/responsesStorageAdapter/threads/post.ts
5310
5315
  var post15 = function(param) {
5311
- var openai = param.openai;
5316
+ var client = param.client;
5312
5317
  return /*#__PURE__*/ function() {
5313
5318
  var _ref = _async_to_generator(function(urlString, options) {
5314
5319
  var body, messages4, metadata, conversation;
@@ -5320,7 +5325,7 @@ var post15 = function(param) {
5320
5325
  metadata = body.metadata || {};
5321
5326
  return [
5322
5327
  4,
5323
- openai.conversations.create({
5328
+ client.conversations.create({
5324
5329
  metadata: metadata,
5325
5330
  items: messages4.map(function(message) {
5326
5331
  return {
@@ -5359,10 +5364,10 @@ var post15 = function(param) {
5359
5364
  };
5360
5365
  // src/adapters/storage/responsesStorageAdapter/threads/index.ts
5361
5366
  var threads2 = function(param) {
5362
- var openai = param.openai;
5367
+ var client = param.client;
5363
5368
  return {
5364
5369
  post: post15({
5365
- openai: openai
5370
+ client: client
5366
5371
  })
5367
5372
  };
5368
5373
  };
@@ -5373,34 +5378,71 @@ var import_radash14 = require("radash");
5373
5378
  var import_radash13 = require("radash");
5374
5379
  var serializeContent2 = function(param) {
5375
5380
  var item = param.item;
5376
- if (item.type !== "message") return [];
5377
- return item.content.map(function(contentBlock) {
5378
- if (contentBlock.type === "input_text") {
5379
- return {
5380
- type: "text",
5381
- text: {
5382
- value: contentBlock.text,
5383
- annotations: []
5384
- }
5385
- };
5386
- } else if (contentBlock.type === "output_text") {
5387
- return {
5388
- type: "text",
5389
- text: {
5390
- value: contentBlock.text,
5391
- annotations: []
5381
+ if (item.type === "message") {
5382
+ return item.content.map(function(contentBlock) {
5383
+ if (contentBlock.type === "input_text") {
5384
+ return {
5385
+ type: "text",
5386
+ text: {
5387
+ value: contentBlock.text,
5388
+ annotations: []
5389
+ }
5390
+ };
5391
+ } else if (contentBlock.type === "output_text") {
5392
+ return {
5393
+ type: "text",
5394
+ text: {
5395
+ value: contentBlock.text,
5396
+ annotations: []
5397
+ }
5398
+ };
5399
+ } else if (contentBlock.type === "input_image") {
5400
+ return {
5401
+ type: "image_file",
5402
+ image_file: {
5403
+ file_id: contentBlock.file_id,
5404
+ detail: "auto"
5405
+ }
5406
+ };
5407
+ }
5408
+ return null;
5409
+ }).filter(Boolean);
5410
+ } else if (item.type === "image_generation_call") {
5411
+ if (!item.result) return [];
5412
+ return [
5413
+ {
5414
+ type: "image_url",
5415
+ image_url: {
5416
+ url: "data:image/".concat(item.output_format, ";base64,").concat(item.result),
5417
+ detail: "auto"
5392
5418
  }
5393
- };
5394
- }
5395
- return null;
5396
- }).filter(Boolean);
5419
+ }
5420
+ ];
5421
+ } else {
5422
+ return [];
5423
+ }
5397
5424
  };
5398
5425
  var serializeAttachments = function(param) {
5399
5426
  var item = param.item;
5400
- return [];
5427
+ if (item.type !== "message") return [];
5428
+ var inputFiles = item.content.filter(function(contentBlock) {
5429
+ return contentBlock.type === "input_file" && contentBlock.file_id;
5430
+ });
5431
+ return inputFiles.map(function(inputFile) {
5432
+ return {
5433
+ file_id: inputFile.file_id
5434
+ };
5435
+ });
5401
5436
  };
5402
5437
  var serializeMetadata = function(param) {
5403
5438
  var item = param.item;
5439
+ if (item.type === "image_generation_call") {
5440
+ return {
5441
+ item: JSON.stringify(_object_spread_props(_object_spread({}, item), {
5442
+ result: "truncated"
5443
+ }))
5444
+ };
5445
+ }
5404
5446
  return {
5405
5447
  item: JSON.stringify(item)
5406
5448
  };
@@ -5431,8 +5473,7 @@ var serializeItemAsMessage = function(param) {
5431
5473
  };
5432
5474
  };
5433
5475
  // src/adapters/storage/responsesStorageAdapter/threads/messages/post.ts
5434
- var import_radash15 = require("radash");
5435
- var messageContentBlocks2 = function(param) {
5476
+ var contentBlocksFromContent = function(param) {
5436
5477
  var content = param.content;
5437
5478
  if ((0, import_radash14.isArray)(content)) {
5438
5479
  return content.map(function(item) {
@@ -5471,40 +5512,65 @@ var messageContentBlocks2 = function(param) {
5471
5512
  }
5472
5513
  ];
5473
5514
  };
5515
+ var contentBlocksFromAttachments = function(param) {
5516
+ var attachments = param.attachments;
5517
+ return attachments.map(function(attachment) {
5518
+ return {
5519
+ type: "input_file",
5520
+ file_id: attachment.file_id
5521
+ };
5522
+ });
5523
+ };
5524
+ var messageContentBlocks2 = function(param) {
5525
+ var content = param.content, attachments = param.attachments;
5526
+ return _to_consumable_array(contentBlocksFromContent({
5527
+ content: content
5528
+ })).concat(_to_consumable_array(contentBlocksFromAttachments({
5529
+ attachments: attachments
5530
+ })));
5531
+ };
5474
5532
  var post16 = function(param) {
5475
- var openai = param.openai, openaiAssistant = param.openaiAssistant, createResponseItems = param.createResponseItems;
5533
+ var runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
5476
5534
  return /*#__PURE__*/ function() {
5477
5535
  var _ref = _async_to_generator(function(urlString, options) {
5478
- var url, _url_pathname_match, threadId, body, role, content, metadata, item;
5536
+ var url, _url_pathname_match, threadId, body, role, content, _body_attachments, attachments, item, openaiAssistant;
5479
5537
  return _ts_generator(this, function(_state) {
5480
- url = new URL(urlString);
5481
- _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
5482
- body = JSON.parse(options.body);
5483
- role = body.role, content = body.content, metadata = body.metadata;
5484
- item = {
5485
- id: "msg_".concat((0, import_radash15.uid)(24)),
5486
- status: "in_progress",
5487
- type: "message",
5488
- role: role,
5489
- content: messageContentBlocks2({
5490
- content: content
5491
- })
5492
- };
5493
- createResponseItems.push(item);
5494
- return [
5495
- 2,
5496
- new Response(JSON.stringify(serializeItemAsMessage({
5497
- item: item,
5498
- threadId: threadId,
5499
- openaiAssistant: openaiAssistant,
5500
- createdAt: (0, import_dayjs10.default)().unix()
5501
- })), {
5502
- status: 200,
5503
- headers: {
5504
- "Content-Type": "application/json"
5505
- }
5506
- })
5507
- ];
5538
+ switch(_state.label){
5539
+ case 0:
5540
+ url = new URL(urlString);
5541
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
5542
+ body = JSON.parse(options.body);
5543
+ role = body.role, content = body.content, _body_attachments = body.attachments, attachments = _body_attachments === void 0 ? [] : _body_attachments;
5544
+ item = {
5545
+ type: "message",
5546
+ role: role,
5547
+ content: messageContentBlocks2({
5548
+ content: content,
5549
+ attachments: attachments
5550
+ })
5551
+ };
5552
+ createResponseItems.push(item);
5553
+ return [
5554
+ 4,
5555
+ runAdapter.getOpenaiAssistant()
5556
+ ];
5557
+ case 1:
5558
+ openaiAssistant = _state.sent();
5559
+ return [
5560
+ 2,
5561
+ new Response(JSON.stringify(serializeItemAsMessage({
5562
+ item: item,
5563
+ threadId: threadId,
5564
+ openaiAssistant: openaiAssistant,
5565
+ createdAt: (0, import_dayjs10.default)().unix()
5566
+ })), {
5567
+ status: 200,
5568
+ headers: {
5569
+ "Content-Type": "application/json"
5570
+ }
5571
+ })
5572
+ ];
5573
+ }
5508
5574
  });
5509
5575
  });
5510
5576
  return function(urlString, options) {
@@ -5513,7 +5579,7 @@ var post16 = function(param) {
5513
5579
  }();
5514
5580
  };
5515
5581
  // src/adapters/storage/responsesStorageAdapter/threads/messages/get.ts
5516
- var import_radash16 = require("radash");
5582
+ var import_radash15 = require("radash");
5517
5583
  // src/lib/items/responseId.ts
5518
5584
  function responseId(param) {
5519
5585
  var conversation = param.conversation, itemId = param.itemId;
@@ -5552,29 +5618,29 @@ function responseId(param) {
5552
5618
  }
5553
5619
  // src/adapters/storage/responsesStorageAdapter/threads/messages/get.ts
5554
5620
  var get14 = function(param) {
5555
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
5621
+ var client = param.client, runAdapter = param.runAdapter;
5556
5622
  return /*#__PURE__*/ function() {
5557
5623
  var _ref = _async_to_generator(function(urlString) {
5558
- var url, _url_pathname_match, threadId, _ref, limit, order, after, conversation, sortOrder, items, itemsWithRunIds, responseMap, timestampedItems;
5624
+ var url, _url_pathname_match, threadId, _ref, limit, order, after, conversation, sortOrder, items, itemsWithRunIds, responseMap, timestampedItems, openaiAssistant;
5559
5625
  return _ts_generator(this, function(_state) {
5560
5626
  switch(_state.label){
5561
5627
  case 0:
5562
5628
  url = new URL(urlString);
5563
5629
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
5564
- _ref = (0, import_radash16.assign)({
5630
+ _ref = (0, import_radash15.assign)({
5565
5631
  limit: "20",
5566
5632
  order: "desc"
5567
5633
  }, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
5568
5634
  return [
5569
5635
  4,
5570
- openai.conversations.retrieve(threadId)
5636
+ client.conversations.retrieve(threadId)
5571
5637
  ];
5572
5638
  case 1:
5573
5639
  conversation = _state.sent();
5574
5640
  sortOrder = order === "asc" ? "asc" : "desc";
5575
5641
  return [
5576
5642
  4,
5577
- openai.conversations.items.list(threadId, {
5643
+ client.conversations.items.list(threadId, {
5578
5644
  limit: parseInt(limit, 10),
5579
5645
  after: after,
5580
5646
  order: sortOrder
@@ -5589,7 +5655,7 @@ var get14 = function(param) {
5589
5655
  return [
5590
5656
  4,
5591
5657
  fetchResponsesForItems({
5592
- openai: openai,
5658
+ client: client,
5593
5659
  items: itemsWithRunIds
5594
5660
  })
5595
5661
  ];
@@ -5601,6 +5667,12 @@ var get14 = function(param) {
5601
5667
  sortOrder: sortOrder,
5602
5668
  conversationCreatedAt: conversation.created_at
5603
5669
  });
5670
+ return [
5671
+ 4,
5672
+ runAdapter.getOpenaiAssistant()
5673
+ ];
5674
+ case 4:
5675
+ openaiAssistant = _state.sent();
5604
5676
  return [
5605
5677
  2,
5606
5678
  new Response(JSON.stringify({
@@ -5645,11 +5717,11 @@ var mapItemsWithRunIds = function(param) {
5645
5717
  };
5646
5718
  var fetchResponsesForItems = /*#__PURE__*/ function() {
5647
5719
  var _ref = _async_to_generator(function(param) {
5648
- var openai, items, responseIds, results, map;
5720
+ var client, items, responseIds, results, map;
5649
5721
  return _ts_generator(this, function(_state) {
5650
5722
  switch(_state.label){
5651
5723
  case 0:
5652
- openai = param.openai, items = param.items;
5724
+ client = param.client, items = param.items;
5653
5725
  responseIds = Array.from(new Set(items.map(function(param) {
5654
5726
  var runId = param.runId;
5655
5727
  return runId;
@@ -5659,7 +5731,7 @@ var fetchResponsesForItems = /*#__PURE__*/ function() {
5659
5731
  return [
5660
5732
  4,
5661
5733
  Promise.allSettled(responseIds.map(function(id) {
5662
- return openai.responses.retrieve(id);
5734
+ return client.responses.retrieve(id);
5663
5735
  }))
5664
5736
  ];
5665
5737
  case 1:
@@ -5757,34 +5829,23 @@ var assignTimestamps = function(param) {
5757
5829
  };
5758
5830
  // src/adapters/storage/responsesStorageAdapter/threads/messages/index.ts
5759
5831
  var messages3 = function(param) {
5760
- var openai = param.openai, openaiAssistant = param.openaiAssistant, createResponseItems = param.createResponseItems;
5832
+ var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
5761
5833
  return {
5762
5834
  post: post16({
5763
- openai: openai,
5764
- openaiAssistant: openaiAssistant,
5835
+ runAdapter: runAdapter,
5765
5836
  createResponseItems: createResponseItems
5766
5837
  }),
5767
5838
  get: get14({
5768
- openai: openai,
5769
- openaiAssistant: openaiAssistant
5839
+ client: client,
5840
+ runAdapter: runAdapter
5770
5841
  })
5771
5842
  };
5772
5843
  };
5773
5844
  // src/adapters/storage/responsesStorageAdapter/threads/runs/get.ts
5774
- var import_radash17 = require("radash");
5775
- var get15 = function(param) {
5776
- var prisma = param.prisma;
5845
+ var get15 = function() {
5777
5846
  return /*#__PURE__*/ function() {
5778
5847
  var _ref = _async_to_generator(function(urlString) {
5779
- var url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize;
5780
5848
  return _ts_generator(this, function(_state) {
5781
- url = new URL(urlString);
5782
- _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
5783
- _ref = (0, import_radash17.assign)({
5784
- limit: "20",
5785
- order: "desc"
5786
- }, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
5787
- pageSize = parseInt(limit, 10);
5788
5849
  return [
5789
5850
  2,
5790
5851
  new Response(JSON.stringify({
@@ -5806,9 +5867,9 @@ var get15 = function(param) {
5806
5867
  }();
5807
5868
  };
5808
5869
  // src/adapters/storage/responsesStorageAdapter/threads/runs/post.ts
5809
- var import_radash18 = require("radash");
5870
+ var import_radash16 = require("radash");
5810
5871
  var import_dayjs11 = __toESM(require("dayjs"), 1);
5811
- var import_radash19 = require("radash");
5872
+ var import_radash17 = require("radash");
5812
5873
  // src/lib/responses/serializeResponseAsRun.ts
5813
5874
  var serializeStatus = function(param) {
5814
5875
  var response = param.response;
@@ -6036,9 +6097,9 @@ function tryPackPairs(param) {
6036
6097
  itemIds: _to_consumable_array(e.itemIds)
6037
6098
  };
6038
6099
  });
6039
- var last6 = next[next.length - 1];
6040
- if (last6 && last6.responseId === responseId2) {
6041
- last6.itemIds.push(itemId);
6100
+ var last5 = next[next.length - 1];
6101
+ if (last5 && last5.responseId === responseId2) {
6102
+ last5.itemIds.push(itemId);
6042
6103
  } else {
6043
6104
  next.push({
6044
6105
  responseId: responseId2,
@@ -6146,14 +6207,14 @@ function saveResponseItemsToConversationMetadata(_) {
6146
6207
  }
6147
6208
  function _saveResponseItemsToConversationMetadata() {
6148
6209
  _saveResponseItemsToConversationMetadata = _async_to_generator(function(param) {
6149
- var openai, threadId, responseId2, itemIds, conversation, updated;
6210
+ var client, threadId, responseId2, itemIds, conversation, updated;
6150
6211
  return _ts_generator(this, function(_state) {
6151
6212
  switch(_state.label){
6152
6213
  case 0:
6153
- openai = param.openai, threadId = param.threadId, responseId2 = param.responseId, itemIds = param.itemIds;
6214
+ client = param.client, threadId = param.threadId, responseId2 = param.responseId, itemIds = param.itemIds;
6154
6215
  return [
6155
6216
  4,
6156
- openai.conversations.retrieve(threadId)
6217
+ client.conversations.retrieve(threadId)
6157
6218
  ];
6158
6219
  case 1:
6159
6220
  conversation = _state.sent();
@@ -6164,7 +6225,7 @@ function _saveResponseItemsToConversationMetadata() {
6164
6225
  });
6165
6226
  return [
6166
6227
  4,
6167
- openai.conversations.update(threadId, {
6228
+ client.conversations.update(threadId, {
6168
6229
  metadata: updated
6169
6230
  })
6170
6231
  ];
@@ -6202,11 +6263,11 @@ var defaultAssistant = {
6202
6263
  }
6203
6264
  };
6204
6265
  var post17 = function(param) {
6205
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6266
+ var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6206
6267
  return /*#__PURE__*/ function() {
6207
6268
  var _ref = _async_to_generator(function(urlString, options) {
6208
6269
  var url, _url_pathname_match, threadId, body, assistant_id, stream, _ref, model, instructions, // additional_instructions,
6209
- tools, metadata, response_format, truncation_strategy, response, readableStream, _response_output, itemIds, data;
6270
+ tools, metadata, response_format, truncation_strategy, _, _tmp, response, readableStream, _response_output, itemIds, data;
6210
6271
  return _ts_generator(this, function(_state) {
6211
6272
  switch(_state.label){
6212
6273
  case 0:
@@ -6214,10 +6275,25 @@ var post17 = function(param) {
6214
6275
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
6215
6276
  body = JSON.parse(options.body);
6216
6277
  assistant_id = body.assistant_id, stream = body.stream;
6217
- _ref = (0, import_radash19.assign)(_object_spread({}, defaultAssistant, openaiAssistant), body), model = _ref.model, instructions = _ref.instructions, tools = _ref.tools, metadata = _ref.metadata, response_format = _ref.response_format, truncation_strategy = _ref.truncation_strategy;
6278
+ _ = (0, import_radash17.assign);
6279
+ _tmp = [
6280
+ {},
6281
+ defaultAssistant
6282
+ ];
6283
+ return [
6284
+ 4,
6285
+ runAdapter.getOpenaiAssistant()
6286
+ ];
6287
+ case 1:
6288
+ _ref = _.apply(void 0, [
6289
+ _object_spread.apply(void 0, _tmp.concat([
6290
+ _state.sent()
6291
+ ])),
6292
+ body
6293
+ ]), model = _ref.model, instructions = _ref.instructions, tools = _ref.tools, metadata = _ref.metadata, response_format = _ref.response_format, truncation_strategy = _ref.truncation_strategy;
6218
6294
  return [
6219
6295
  4,
6220
- openai.responses.create(_object_spread_props(_object_spread({
6296
+ client.responses.create(_object_spread_props(_object_spread({
6221
6297
  conversation: threadId,
6222
6298
  instructions: instructions,
6223
6299
  model: model,
@@ -6233,7 +6309,7 @@ var post17 = function(param) {
6233
6309
  input: createResponseItems
6234
6310
  }))
6235
6311
  ];
6236
- case 1:
6312
+ case 2:
6237
6313
  response = _state.sent();
6238
6314
  readableStream = new ReadableStream({
6239
6315
  start: function start(controller) {
@@ -6250,7 +6326,7 @@ var post17 = function(param) {
6250
6326
  ]);
6251
6327
  return [
6252
6328
  4,
6253
- runAdapter({
6329
+ runAdapter.handleRun({
6254
6330
  threadId: threadId,
6255
6331
  response: response,
6256
6332
  onEvent: /*#__PURE__*/ function() {
@@ -6280,7 +6356,7 @@ var post17 = function(param) {
6280
6356
  event = {
6281
6357
  event: "thread.run.failed",
6282
6358
  data: {
6283
- id: (0, import_radash18.uid)(24),
6359
+ id: (0, import_radash16.uid)(24),
6284
6360
  failed_at: (0, import_dayjs11.default)().unix(),
6285
6361
  last_error: {
6286
6362
  code: "server_error",
@@ -6305,7 +6381,7 @@ var post17 = function(param) {
6305
6381
  });
6306
6382
  if (!stream) return [
6307
6383
  3,
6308
- 2
6384
+ 3
6309
6385
  ];
6310
6386
  return [
6311
6387
  2,
@@ -6315,7 +6391,7 @@ var post17 = function(param) {
6315
6391
  }
6316
6392
  })
6317
6393
  ];
6318
- case 2:
6394
+ case 3:
6319
6395
  itemIds = ((_response_output = response.output) !== null && _response_output !== void 0 ? _response_output : []).filter(function(o) {
6320
6396
  return o.id;
6321
6397
  }).map(function(o) {
@@ -6323,21 +6399,21 @@ var post17 = function(param) {
6323
6399
  });
6324
6400
  if (!(itemIds.length > 0)) return [
6325
6401
  3,
6326
- 4
6402
+ 5
6327
6403
  ];
6328
6404
  return [
6329
6405
  4,
6330
6406
  saveResponseItemsToConversationMetadata({
6331
- openai: openai,
6407
+ client: client,
6332
6408
  threadId: threadId,
6333
6409
  responseId: response.id,
6334
6410
  itemIds: itemIds
6335
6411
  })
6336
6412
  ];
6337
- case 3:
6338
- _state.sent();
6339
- _state.label = 4;
6340
6413
  case 4:
6414
+ _state.sent();
6415
+ _state.label = 5;
6416
+ case 5:
6341
6417
  data = serializeResponseAsRun({
6342
6418
  response: response,
6343
6419
  assistantId: assistant_id
@@ -6351,7 +6427,7 @@ var post17 = function(param) {
6351
6427
  }
6352
6428
  })
6353
6429
  ];
6354
- case 5:
6430
+ case 6:
6355
6431
  return [
6356
6432
  2
6357
6433
  ];
@@ -6365,14 +6441,11 @@ var post17 = function(param) {
6365
6441
  };
6366
6442
  // src/adapters/storage/responsesStorageAdapter/threads/runs/index.ts
6367
6443
  var runs2 = function(param) {
6368
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6444
+ var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6369
6445
  return {
6370
- get: get15({
6371
- openai: openai
6372
- }),
6446
+ get: get15(),
6373
6447
  post: post17({
6374
- openai: openai,
6375
- openaiAssistant: openaiAssistant,
6448
+ client: client,
6376
6449
  createResponseItems: createResponseItems,
6377
6450
  runAdapter: runAdapter
6378
6451
  })
@@ -6380,10 +6453,10 @@ var runs2 = function(param) {
6380
6453
  };
6381
6454
  // src/adapters/storage/responsesStorageAdapter/threads/run/get.ts
6382
6455
  var get16 = function(param) {
6383
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
6456
+ var client = param.client, runAdapter = param.runAdapter;
6384
6457
  return /*#__PURE__*/ function() {
6385
6458
  var _ref = _async_to_generator(function(urlString) {
6386
- var url, _url_pathname_match, _threadId, runId, response, data;
6459
+ var url, _url_pathname_match, _threadId, runId, response, data, _tmp;
6387
6460
  return _ts_generator(this, function(_state) {
6388
6461
  switch(_state.label){
6389
6462
  case 0:
@@ -6391,14 +6464,21 @@ var get16 = function(param) {
6391
6464
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runRegexp)), 3), _threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
6392
6465
  return [
6393
6466
  4,
6394
- openai.responses.retrieve(runId)
6467
+ client.responses.retrieve(runId)
6395
6468
  ];
6396
6469
  case 1:
6397
6470
  response = _state.sent();
6398
- data = serializeResponseAsRun({
6399
- response: response,
6400
- assistantId: openaiAssistant.id
6401
- });
6471
+ _tmp = {
6472
+ response: response
6473
+ };
6474
+ return [
6475
+ 4,
6476
+ runAdapter.getOpenaiAssistant()
6477
+ ];
6478
+ case 2:
6479
+ data = serializeResponseAsRun.apply(void 0, [
6480
+ (_tmp.assistantId = _state.sent().id, _tmp)
6481
+ ]);
6402
6482
  return [
6403
6483
  2,
6404
6484
  new Response(JSON.stringify(data), {
@@ -6419,11 +6499,11 @@ var get16 = function(param) {
6419
6499
  };
6420
6500
  // src/adapters/storage/responsesStorageAdapter/threads/run/index.ts
6421
6501
  var run2 = function(param) {
6422
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter;
6502
+ var client = param.client, runAdapter = param.runAdapter;
6423
6503
  return {
6424
6504
  get: get16({
6425
- openai: openai,
6426
- openaiAssistant: openaiAssistant
6505
+ client: client,
6506
+ runAdapter: runAdapter
6427
6507
  })
6428
6508
  };
6429
6509
  };
@@ -6718,13 +6798,13 @@ function _pMap() {
6718
6798
  }
6719
6799
  var pMapSkip = Symbol("skip");
6720
6800
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
6721
- var import_radash21 = require("radash");
6801
+ var import_radash19 = require("radash");
6722
6802
  // src/lib/items/serializeItemAsRunStep.ts
6723
6803
  var import_dayjs12 = __toESM(require("dayjs"), 1);
6724
- var import_radash20 = require("radash");
6804
+ var import_radash18 = require("radash");
6725
6805
  function serializeItemAsRunStep(param) {
6726
- var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash20.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs12.default)().unix() : _param_completedAt;
6727
- var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash20.uid)(18));
6806
+ var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash18.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs12.default)().unix() : _param_completedAt;
6807
+ var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash18.uid)(18));
6728
6808
  var base = {
6729
6809
  id: itemId,
6730
6810
  object: "thread.run.step",
@@ -6780,6 +6860,22 @@ function serializeItemAsRunStep(param) {
6780
6860
  }
6781
6861
  });
6782
6862
  }
6863
+ if (item.type === "image_generation_call") {
6864
+ return _object_spread_props(_object_spread({}, base), {
6865
+ type: "message_creation",
6866
+ step_details: {
6867
+ type: "message_creation",
6868
+ message_creation: {
6869
+ message_id: itemId
6870
+ }
6871
+ },
6872
+ metadata: {
6873
+ item: JSON.stringify(_object_spread_props(_object_spread({}, item), {
6874
+ result: "truncated"
6875
+ }))
6876
+ }
6877
+ });
6878
+ }
6783
6879
  return _object_spread_props(_object_spread({}, base), {
6784
6880
  type: "message_creation",
6785
6881
  step_details: {
@@ -6793,88 +6889,418 @@ function serializeItemAsRunStep(param) {
6793
6889
  }
6794
6890
  });
6795
6891
  }
6796
- // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
6797
- var get17 = function(param) {
6798
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
6799
- return /*#__PURE__*/ function() {
6800
- var _ref = _async_to_generator(function(urlString) {
6801
- var _this, url, _url_pathname_match, threadId, runId, response, functionCalls, functionCallOutputsResponses, functionCallOutputs, nonFcItems, data, _id;
6802
- return _ts_generator(this, function(_state) {
6803
- switch(_state.label){
6804
- case 0:
6805
- url = new URL(urlString);
6806
- _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
6807
- return [
6808
- 4,
6809
- openai.responses.retrieve(runId)
6810
- ];
6811
- case 1:
6812
- response = _state.sent();
6813
- functionCalls = response.output.filter(function(item) {
6814
- return item.type === "function_call";
6815
- });
6816
- return [
6817
- 4,
6818
- pMap(functionCalls, /*#__PURE__*/ function() {
6819
- var _ref = _async_to_generator(function(functionCall) {
6820
- var items;
6821
- return _ts_generator(this, function(_state) {
6822
- switch(_state.label){
6823
- case 0:
6824
- return [
6825
- 4,
6826
- openai.conversations.items.list(threadId, {
6827
- after: functionCall.id,
6828
- order: "asc"
6829
- })
6830
- ];
6831
- case 1:
6832
- items = _state.sent();
6833
- return [
6834
- 2,
6835
- items.data.find(function(item) {
6836
- return item.type === "function_call_output" && item.call_id === functionCall.call_id;
6837
- })
6838
- ];
6839
- }
6840
- });
6841
- });
6842
- return function(functionCall) {
6843
- return _ref.apply(this, arguments);
6844
- };
6845
- }())
6846
- ];
6847
- case 2:
6848
- functionCallOutputsResponses = _state.sent();
6849
- functionCallOutputs = functionCallOutputsResponses.filter(Boolean);
6850
- nonFcItems = response.output.filter(function(item) {
6851
- return item.type !== "function_call";
6852
- });
6853
- data = response.output.flatMap(function(item) {
6854
- var step = serializeItemAsRunStep({
6855
- item: item,
6856
- items: functionCallOutputs,
6857
- threadId: threadId,
6858
- openaiAssistant: openaiAssistant,
6859
- runId: response.id
6860
- });
6861
- if (item.type === "function_call") {
6862
- var synthCreation = {
6863
- id: "mc".concat(item.id),
6864
- run_id: response.id,
6865
- status: "completed",
6866
- completed_at: step.created_at,
6867
- step_details: {
6868
- type: "message_creation",
6869
- message_creation: {
6870
- message_id: item.id
6871
- }
6872
- }
6873
- };
6874
- return [
6875
- synthCreation,
6876
- step
6877
- ];
6892
+ // src/lib/items/serializeItemAsImageGenerationRunStep.ts
6893
+ var import_dayjs13 = __toESM(require("dayjs"), 1);
6894
+ var serializeStatus2 = function(param) {
6895
+ var item = param.item;
6896
+ if (item.status === "generating") {
6897
+ return "in_progress";
6898
+ }
6899
+ return item.status;
6900
+ };
6901
+ var serializeItemAsImageGenerationRunStep = function(param) {
6902
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs13.default)().unix() : _param_completedAt;
6903
+ var toolCall = {
6904
+ id: "ftc".concat(item.id),
6905
+ type: "function",
6906
+ function: {
6907
+ name: "image_generation",
6908
+ arguments: "{}",
6909
+ output: JSON.stringify({
6910
+ status: item.status,
6911
+ background: item.background,
6912
+ output_format: item.output_format,
6913
+ quality: item.quality,
6914
+ result: item.result,
6915
+ size: item.size,
6916
+ revised_prompt: item.revised_prompt
6917
+ })
6918
+ }
6919
+ };
6920
+ return {
6921
+ id: "fc".concat(item.id),
6922
+ object: "thread.run.step",
6923
+ created_at: (0, import_dayjs13.default)().unix(),
6924
+ assistant_id: openaiAssistant.id,
6925
+ thread_id: threadId,
6926
+ run_id: runId,
6927
+ status: serializeStatus2({
6928
+ item: item
6929
+ }),
6930
+ last_error: null,
6931
+ expired_at: null,
6932
+ cancelled_at: null,
6933
+ failed_at: null,
6934
+ completed_at: completedAt,
6935
+ metadata: {},
6936
+ usage: null,
6937
+ type: "tool_calls",
6938
+ step_details: {
6939
+ type: "tool_calls",
6940
+ tool_calls: [
6941
+ toolCall
6942
+ ]
6943
+ }
6944
+ };
6945
+ };
6946
+ // src/lib/items/serializeItemAsWebSearchRunStep.ts
6947
+ var import_dayjs14 = __toESM(require("dayjs"), 1);
6948
+ var serializeStatus3 = function(param) {
6949
+ var item = param.item;
6950
+ if (item.status === "searching") {
6951
+ return "in_progress";
6952
+ }
6953
+ return item.status;
6954
+ };
6955
+ var serializeItemAsWebSearchRunStep = function(param) {
6956
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs14.default)().unix() : _param_completedAt;
6957
+ var toolCall = {
6958
+ id: "ftc".concat(item.id),
6959
+ type: "function",
6960
+ function: {
6961
+ name: "web_search",
6962
+ arguments: JSON.stringify({
6963
+ action: item.action
6964
+ }),
6965
+ output: JSON.stringify({
6966
+ status: item.status
6967
+ })
6968
+ }
6969
+ };
6970
+ return {
6971
+ id: "fc".concat(item.id),
6972
+ object: "thread.run.step",
6973
+ created_at: (0, import_dayjs14.default)().unix(),
6974
+ assistant_id: openaiAssistant.id,
6975
+ thread_id: threadId,
6976
+ run_id: runId,
6977
+ status: serializeStatus3({
6978
+ item: item
6979
+ }),
6980
+ last_error: null,
6981
+ expired_at: null,
6982
+ cancelled_at: null,
6983
+ failed_at: null,
6984
+ completed_at: completedAt,
6985
+ metadata: {},
6986
+ usage: null,
6987
+ type: "tool_calls",
6988
+ step_details: {
6989
+ type: "tool_calls",
6990
+ tool_calls: [
6991
+ toolCall
6992
+ ]
6993
+ }
6994
+ };
6995
+ };
6996
+ // src/lib/items/serializeItemAsMcpListToolsRunStep.ts
6997
+ var import_dayjs15 = __toESM(require("dayjs"), 1);
6998
+ var serializeStatus4 = function(param) {
6999
+ var item = param.item;
7000
+ if (item.error) {
7001
+ return "failed";
7002
+ }
7003
+ return "completed";
7004
+ };
7005
+ var serializeItemAsMcpListToolsRunStep = function(param) {
7006
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs15.default)().unix() : _param_completedAt;
7007
+ var toolCall = {
7008
+ id: "ftc".concat(item.id),
7009
+ type: "function",
7010
+ function: {
7011
+ name: "mcp_list_tools",
7012
+ arguments: JSON.stringify({
7013
+ server_label: item.server_label
7014
+ }),
7015
+ output: JSON.stringify(_object_spread({
7016
+ tools: item.tools
7017
+ }, item.error && {
7018
+ error: item.error
7019
+ }))
7020
+ }
7021
+ };
7022
+ return {
7023
+ id: "fc".concat(item.id),
7024
+ object: "thread.run.step",
7025
+ created_at: (0, import_dayjs15.default)().unix(),
7026
+ assistant_id: openaiAssistant.id,
7027
+ thread_id: threadId,
7028
+ run_id: runId,
7029
+ status: serializeStatus4({
7030
+ item: item
7031
+ }),
7032
+ last_error: null,
7033
+ expired_at: null,
7034
+ cancelled_at: null,
7035
+ failed_at: null,
7036
+ completed_at: completedAt,
7037
+ metadata: {},
7038
+ usage: null,
7039
+ type: "tool_calls",
7040
+ step_details: {
7041
+ type: "tool_calls",
7042
+ tool_calls: [
7043
+ toolCall
7044
+ ]
7045
+ }
7046
+ };
7047
+ };
7048
+ // src/lib/items/serializeItemAsMcpCallRunStep.ts
7049
+ var import_dayjs16 = __toESM(require("dayjs"), 1);
7050
+ var serializeStatus5 = function(param) {
7051
+ var item = param.item;
7052
+ if (item.error) {
7053
+ return "failed";
7054
+ }
7055
+ return "completed";
7056
+ };
7057
+ var serializeItemAsMcpCallRunStep = function(param) {
7058
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs16.default)().unix() : _param_completedAt;
7059
+ var _item_output, _ref;
7060
+ var toolCall = {
7061
+ id: "ftc".concat(item.id),
7062
+ type: "function",
7063
+ function: {
7064
+ name: item.name,
7065
+ arguments: item.arguments,
7066
+ server_label: item.server_label,
7067
+ output: (_ref = (_item_output = item.output) !== null && _item_output !== void 0 ? _item_output : item.error) !== null && _ref !== void 0 ? _ref : null
7068
+ }
7069
+ };
7070
+ return {
7071
+ id: "fc".concat(item.id),
7072
+ object: "thread.run.step",
7073
+ created_at: (0, import_dayjs16.default)().unix(),
7074
+ assistant_id: openaiAssistant.id,
7075
+ thread_id: threadId,
7076
+ run_id: runId,
7077
+ status: serializeStatus5({
7078
+ item: item
7079
+ }),
7080
+ last_error: item.error ? {
7081
+ code: "server_error",
7082
+ message: item.error
7083
+ } : null,
7084
+ expired_at: null,
7085
+ cancelled_at: null,
7086
+ failed_at: item.error ? (0, import_dayjs16.default)().unix() : null,
7087
+ completed_at: item.error ? null : completedAt,
7088
+ metadata: {},
7089
+ usage: null,
7090
+ type: "tool_calls",
7091
+ step_details: {
7092
+ type: "tool_calls",
7093
+ tool_calls: [
7094
+ toolCall
7095
+ ]
7096
+ }
7097
+ };
7098
+ };
7099
+ // src/lib/items/serializeItemAsCodeInterpreterCallRunStep.ts
7100
+ var import_dayjs17 = __toESM(require("dayjs"), 1);
7101
+ var serializeStatus6 = function(param) {
7102
+ var item = param.item;
7103
+ if (item.status === "incomplete") {
7104
+ return "in_progress";
7105
+ } else if (item.status === "interpreting") {
7106
+ return "in_progress";
7107
+ }
7108
+ return item.status;
7109
+ };
7110
+ var serializeOutput = function(param) {
7111
+ var output = param.output;
7112
+ return {
7113
+ type: output.type,
7114
+ logs: output.logs
7115
+ };
7116
+ };
7117
+ var serializeOutputs = function(param) {
7118
+ var item = param.item;
7119
+ if (!item.outputs) return [];
7120
+ return item.outputs.filter(function(o) {
7121
+ return o.type === "logs";
7122
+ }).map(function(output) {
7123
+ return serializeOutput({
7124
+ output: output
7125
+ });
7126
+ });
7127
+ };
7128
+ var serializeItemAsCodeInterpreterCallRunStep = function(param) {
7129
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs17.default)().unix() : _param_completedAt;
7130
+ var _item_code;
7131
+ var toolCall = {
7132
+ id: "citc".concat(item.id),
7133
+ type: "code_interpreter",
7134
+ code_interpreter: {
7135
+ input: (_item_code = item.code) !== null && _item_code !== void 0 ? _item_code : "",
7136
+ outputs: serializeOutputs({
7137
+ item: item
7138
+ })
7139
+ }
7140
+ };
7141
+ return {
7142
+ id: "fc".concat(item.id),
7143
+ object: "thread.run.step",
7144
+ created_at: (0, import_dayjs17.default)().unix(),
7145
+ assistant_id: openaiAssistant.id,
7146
+ thread_id: threadId,
7147
+ run_id: runId,
7148
+ status: serializeStatus6({
7149
+ item: item
7150
+ }),
7151
+ last_error: null,
7152
+ expired_at: null,
7153
+ cancelled_at: null,
7154
+ failed_at: null,
7155
+ completed_at: completedAt,
7156
+ metadata: {
7157
+ item: JSON.stringify(item)
7158
+ },
7159
+ usage: null,
7160
+ type: "tool_calls",
7161
+ step_details: {
7162
+ type: "tool_calls",
7163
+ tool_calls: [
7164
+ toolCall
7165
+ ]
7166
+ }
7167
+ };
7168
+ };
7169
+ // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
7170
+ var get17 = function(param) {
7171
+ var client = param.client, runAdapter = param.runAdapter;
7172
+ return /*#__PURE__*/ function() {
7173
+ var _ref = _async_to_generator(function(urlString) {
7174
+ var _this, url, _url_pathname_match, threadId, runId, response, functionCalls, functionCallOutputsResponses, functionCallOutputs, openaiAssistant, data, _id;
7175
+ return _ts_generator(this, function(_state) {
7176
+ switch(_state.label){
7177
+ case 0:
7178
+ url = new URL(urlString);
7179
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
7180
+ return [
7181
+ 4,
7182
+ client.responses.retrieve(runId)
7183
+ ];
7184
+ case 1:
7185
+ response = _state.sent();
7186
+ functionCalls = response.output.filter(function(item) {
7187
+ return item.type === "function_call";
7188
+ });
7189
+ return [
7190
+ 4,
7191
+ pMap(functionCalls, /*#__PURE__*/ function() {
7192
+ var _ref = _async_to_generator(function(functionCall) {
7193
+ var items;
7194
+ return _ts_generator(this, function(_state) {
7195
+ switch(_state.label){
7196
+ case 0:
7197
+ return [
7198
+ 4,
7199
+ client.conversations.items.list(threadId, {
7200
+ after: functionCall.id,
7201
+ order: "asc"
7202
+ })
7203
+ ];
7204
+ case 1:
7205
+ items = _state.sent();
7206
+ return [
7207
+ 2,
7208
+ items.data.find(function(item) {
7209
+ return item.type === "function_call_output" && item.call_id === functionCall.call_id;
7210
+ })
7211
+ ];
7212
+ }
7213
+ });
7214
+ });
7215
+ return function(functionCall) {
7216
+ return _ref.apply(this, arguments);
7217
+ };
7218
+ }())
7219
+ ];
7220
+ case 2:
7221
+ functionCallOutputsResponses = _state.sent();
7222
+ functionCallOutputs = functionCallOutputsResponses.filter(Boolean);
7223
+ return [
7224
+ 4,
7225
+ runAdapter.getOpenaiAssistant()
7226
+ ];
7227
+ case 3:
7228
+ openaiAssistant = _state.sent();
7229
+ data = response.output.flatMap(function(item) {
7230
+ var step = serializeItemAsRunStep({
7231
+ item: item,
7232
+ items: functionCallOutputs,
7233
+ threadId: threadId,
7234
+ openaiAssistant: openaiAssistant,
7235
+ runId: response.id
7236
+ });
7237
+ if (item.type === "function_call") {
7238
+ var synthCreation = {
7239
+ id: "mc".concat(item.id),
7240
+ run_id: response.id,
7241
+ status: "completed",
7242
+ completed_at: step.created_at,
7243
+ step_details: {
7244
+ type: "message_creation",
7245
+ message_creation: {
7246
+ message_id: item.id
7247
+ }
7248
+ }
7249
+ };
7250
+ return [
7251
+ synthCreation,
7252
+ step
7253
+ ];
7254
+ } else if (item.type === "image_generation_call") {
7255
+ return [
7256
+ serializeItemAsImageGenerationRunStep({
7257
+ item: item,
7258
+ openaiAssistant: openaiAssistant,
7259
+ threadId: threadId,
7260
+ runId: response.id
7261
+ }),
7262
+ step
7263
+ ];
7264
+ } else if (item.type === "web_search_call") {
7265
+ return [
7266
+ serializeItemAsWebSearchRunStep({
7267
+ item: item,
7268
+ openaiAssistant: openaiAssistant,
7269
+ threadId: threadId,
7270
+ runId: response.id
7271
+ }),
7272
+ step
7273
+ ];
7274
+ } else if (item.type === "mcp_list_tools") {
7275
+ return [
7276
+ serializeItemAsMcpListToolsRunStep({
7277
+ item: item,
7278
+ openaiAssistant: openaiAssistant,
7279
+ threadId: threadId,
7280
+ runId: response.id
7281
+ }),
7282
+ step
7283
+ ];
7284
+ } else if (item.type === "mcp_call") {
7285
+ return [
7286
+ serializeItemAsMcpCallRunStep({
7287
+ item: item,
7288
+ openaiAssistant: openaiAssistant,
7289
+ threadId: threadId,
7290
+ runId: response.id
7291
+ }),
7292
+ step
7293
+ ];
7294
+ } else if (item.type === "code_interpreter_call") {
7295
+ return [
7296
+ serializeItemAsCodeInterpreterCallRunStep({
7297
+ item: item,
7298
+ openaiAssistant: openaiAssistant,
7299
+ threadId: threadId,
7300
+ runId: response.id
7301
+ }),
7302
+ step
7303
+ ];
6878
7304
  }
6879
7305
  return [
6880
7306
  step
@@ -6885,7 +7311,7 @@ var get17 = function(param) {
6885
7311
  new Response(JSON.stringify({
6886
7312
  data: data,
6887
7313
  has_more: false,
6888
- last_id: (_id = (_this = (0, import_radash21.last)(response.output)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
7314
+ last_id: (_id = (_this = (0, import_radash19.last)(response.output)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
6889
7315
  }), {
6890
7316
  status: 200,
6891
7317
  headers: {
@@ -6903,11 +7329,11 @@ var get17 = function(param) {
6903
7329
  };
6904
7330
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/index.ts
6905
7331
  var steps2 = function(param) {
6906
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7332
+ var client = param.client, runAdapter = param.runAdapter;
6907
7333
  return {
6908
7334
  get: get17({
6909
- openai: openai,
6910
- openaiAssistant: openaiAssistant
7335
+ client: client,
7336
+ runAdapter: runAdapter
6911
7337
  })
6912
7338
  };
6913
7339
  };
@@ -6934,10 +7360,10 @@ var getFunctionCallOutputItems = function(param) {
6934
7360
  });
6935
7361
  };
6936
7362
  var post18 = function(param) {
6937
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter;
7363
+ var client = param.client, runAdapter = param.runAdapter;
6938
7364
  return /*#__PURE__*/ function() {
6939
7365
  var _ref = _async_to_generator(function(urlString, options) {
6940
- var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, functionCallOutputItems, previousResponse, response, readableStream;
7366
+ var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, functionCallOutputItems, previousResponse, openaiAssistant, response, readableStream;
6941
7367
  return _ts_generator(this, function(_state) {
6942
7368
  switch(_state.label){
6943
7369
  case 0:
@@ -6950,13 +7376,19 @@ var post18 = function(param) {
6950
7376
  });
6951
7377
  return [
6952
7378
  4,
6953
- openai.responses.retrieve(runId)
7379
+ client.responses.retrieve(runId)
6954
7380
  ];
6955
7381
  case 1:
6956
7382
  previousResponse = _state.sent();
6957
7383
  return [
6958
7384
  4,
6959
- openai.responses.create(_object_spread({
7385
+ runAdapter.getOpenaiAssistant()
7386
+ ];
7387
+ case 2:
7388
+ openaiAssistant = _state.sent();
7389
+ return [
7390
+ 4,
7391
+ client.responses.create(_object_spread({
6960
7392
  conversation: threadId,
6961
7393
  input: functionCallOutputItems,
6962
7394
  instructions: openaiAssistant.instructions,
@@ -6967,7 +7399,7 @@ var post18 = function(param) {
6967
7399
  tools: openaiAssistant.tools
6968
7400
  })))
6969
7401
  ];
6970
- case 2:
7402
+ case 3:
6971
7403
  response = _state.sent();
6972
7404
  readableStream = new ReadableStream({
6973
7405
  start: function start(controller) {
@@ -6995,7 +7427,7 @@ var post18 = function(param) {
6995
7427
  });
6996
7428
  return [
6997
7429
  4,
6998
- runAdapter({
7430
+ runAdapter.handleRun({
6999
7431
  threadId: threadId,
7000
7432
  response: response,
7001
7433
  onEvent: /*#__PURE__*/ function() {
@@ -7042,37 +7474,55 @@ var post18 = function(param) {
7042
7474
  };
7043
7475
  // src/adapters/storage/responsesStorageAdapter/threads/runs/submitToolOutputs/index.ts
7044
7476
  var submitToolOutputs2 = function(param) {
7045
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter;
7477
+ var client = param.client, runAdapter = param.runAdapter;
7046
7478
  return {
7047
7479
  post: post18({
7048
- openai: openai,
7049
- openaiAssistant: openaiAssistant,
7050
- // @ts-ignore-next-line
7480
+ client: client,
7051
7481
  runAdapter: runAdapter
7052
7482
  })
7053
7483
  };
7054
7484
  };
7055
7485
  // src/adapters/storage/responsesStorageAdapter/assistants/get.ts
7056
7486
  var get18 = function(param) {
7057
- var openaiAssistant = param.openaiAssistant;
7487
+ var runAdapter = param.runAdapter;
7058
7488
  return /*#__PURE__*/ function() {
7059
7489
  var _ref = _async_to_generator(function(urlString) {
7490
+ var _, _1, _tmp;
7060
7491
  return _ts_generator(this, function(_state) {
7061
- return [
7062
- 2,
7063
- new Response(JSON.stringify({
7064
- data: [
7065
- openaiAssistant
7066
- ],
7067
- has_more: false,
7068
- last_id: openaiAssistant.id
7069
- }), {
7070
- status: 200,
7071
- headers: {
7072
- "Content-Type": "application/json"
7073
- }
7074
- })
7075
- ];
7492
+ switch(_state.label){
7493
+ case 0:
7494
+ _ = Response.bind;
7495
+ _1 = JSON.stringify;
7496
+ _tmp = {};
7497
+ return [
7498
+ 4,
7499
+ runAdapter.getOpenaiAssistant()
7500
+ ];
7501
+ case 1:
7502
+ _tmp.data = [
7503
+ _state.sent()
7504
+ ], _tmp.has_more = false;
7505
+ return [
7506
+ 4,
7507
+ runAdapter.getOpenaiAssistant()
7508
+ ];
7509
+ case 2:
7510
+ return [
7511
+ 2,
7512
+ new (_.apply(Response, [
7513
+ void 0,
7514
+ _1.apply(JSON, [
7515
+ (_tmp.last_id = _state.sent().id, _tmp)
7516
+ ]),
7517
+ {
7518
+ status: 200,
7519
+ headers: {
7520
+ "Content-Type": "application/json"
7521
+ }
7522
+ }
7523
+ ]))
7524
+ ];
7525
+ }
7076
7526
  });
7077
7527
  });
7078
7528
  return function(urlString) {
@@ -7081,8 +7531,7 @@ var get18 = function(param) {
7081
7531
  }();
7082
7532
  };
7083
7533
  // src/adapters/storage/responsesStorageAdapter/assistants/post.ts
7084
- var post19 = function(param) {
7085
- var _openaiAssistant = param.openaiAssistant;
7534
+ var post19 = function() {
7086
7535
  return /*#__PURE__*/ _async_to_generator(function() {
7087
7536
  return _ts_generator(this, function(_state) {
7088
7537
  return [
@@ -7104,59 +7553,52 @@ var post19 = function(param) {
7104
7553
  };
7105
7554
  // src/adapters/storage/responsesStorageAdapter/assistants/index.ts
7106
7555
  var assistants2 = function(param) {
7107
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7556
+ var runAdapter = param.runAdapter;
7108
7557
  return {
7109
7558
  get: get18({
7110
- openaiAssistant: openaiAssistant
7559
+ runAdapter: runAdapter
7111
7560
  }),
7112
- post: post19({
7113
- openaiAssistant: openaiAssistant
7114
- })
7561
+ post: post19()
7115
7562
  };
7116
7563
  };
7117
7564
  // src/adapters/storage/responsesStorageAdapter/index.ts
7118
- var responsesStorageAdapter = function(param) {
7119
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7565
+ var responsesStorageAdapter = function() {
7120
7566
  var createResponseItems = [];
7121
7567
  return function(param) {
7122
- var runAdapter = param.runAdapter;
7568
+ var runAdapter = param.runAdapter, client = param.client;
7123
7569
  var _obj;
7124
7570
  return {
7125
7571
  requestHandlers: (_obj = {
7126
7572
  "^/(?:v1|/?openai)/assistants$": assistants2({
7127
- openai: openai,
7128
- openaiAssistant: openaiAssistant
7573
+ runAdapter: runAdapter
7129
7574
  }),
7130
7575
  "^/(?:v1|/?openai)/threads$": threads2({
7131
- openai: openai
7576
+ client: client
7132
7577
  })
7133
7578
  }, _define_property(_obj, messagesRegexp, messages3({
7134
- openai: openai,
7135
- openaiAssistant: openaiAssistant,
7579
+ client: client,
7580
+ runAdapter: runAdapter,
7136
7581
  createResponseItems: createResponseItems
7137
7582
  })), _define_property(_obj, runsRegexp, runs2({
7138
- openai: openai,
7139
- openaiAssistant: openaiAssistant,
7583
+ client: client,
7140
7584
  runAdapter: runAdapter,
7141
7585
  createResponseItems: createResponseItems
7142
7586
  })), _define_property(_obj, runRegexp, run2({
7143
- openai: openai,
7144
- openaiAssistant: openaiAssistant,
7587
+ client: client,
7145
7588
  runAdapter: runAdapter
7146
7589
  })), _define_property(_obj, stepsRegexp, steps2({
7147
- openai: openai,
7148
- openaiAssistant: openaiAssistant
7590
+ client: client,
7591
+ runAdapter: runAdapter
7149
7592
  })), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs2({
7150
- openai: openai,
7151
- openaiAssistant: openaiAssistant,
7593
+ client: client,
7152
7594
  runAdapter: runAdapter
7153
7595
  })), _obj)
7154
7596
  };
7155
7597
  };
7156
7598
  };
7157
7599
  // src/adapters/run/responsesRunAdapter/index.ts
7158
- var import_dayjs13 = __toESM(require("dayjs"), 1);
7159
- var import_radash22 = require("radash");
7600
+ var import_dayjs18 = __toESM(require("dayjs"), 1);
7601
+ var import_radash20 = require("radash");
7160
7602
  var serializeToolCalls2 = function(param) {
7161
7603
  var toolCalls = param.toolCalls;
7162
7604
  return toolCalls.map(function(toolCall) {
@@ -7171,33 +7613,62 @@ var serializeToolCalls2 = function(param) {
7171
7613
  });
7172
7614
  };
7173
7615
  var responsesRunAdapter = function(param) {
7174
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7175
- return /*#__PURE__*/ function() {
7616
+ var getDirectOpenaiAssistant = param.getOpenaiAssistant;
7617
+ var cachedOpenaiAssistant = null;
7618
+ var getOpenaiAssistant = /*#__PURE__*/ function() {
7619
+ var _ref = _async_to_generator(function() {
7620
+ return _ts_generator(this, function(_state) {
7621
+ switch(_state.label){
7622
+ case 0:
7623
+ if (cachedOpenaiAssistant) return [
7624
+ 2,
7625
+ cachedOpenaiAssistant
7626
+ ];
7627
+ return [
7628
+ 4,
7629
+ getDirectOpenaiAssistant()
7630
+ ];
7631
+ case 1:
7632
+ cachedOpenaiAssistant = _state.sent();
7633
+ return [
7634
+ 2,
7635
+ cachedOpenaiAssistant
7636
+ ];
7637
+ }
7638
+ });
7639
+ });
7640
+ return function getOpenaiAssistant() {
7641
+ return _ref.apply(this, arguments);
7642
+ };
7643
+ }();
7644
+ var handleRun = /*#__PURE__*/ function() {
7176
7645
  var _ref = _async_to_generator(function(param) {
7177
- var threadId, response, onEvent2, responseCreatedResponse, toolCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, toolCalls2, toolCall, err, e;
7646
+ var client, threadId, response, onEvent2, responseCreatedResponse, toolCalls, mcpCalls, codeInterpreterCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, _tmp, _tmp1, _tmp2, _tmp3, toolCalls2, _tmp4, _tmp5, _tmp6, _tmp7, _tmp8, _tmp9, _tmp10, _tmp11, _tmp12, _tmp13, _tmp14, _tmp15, _tmp16, _tmp17, _tmp18, _tmp19, _tmp20, _tmp21, _tmp22, _tmp23, _tmp24, _tmp25, _tmp26, _tmp27, _tmp28, _tmp29, _tmp30, _tmp31, _tmp32, _tmp33, _tmp34, _tmp35, _tmp36, _tmp37, _tmp38, _tmp39, _tmp40, _tmp41, _tmp42, _tmp43, _tmp44, _tmp45, _tmp46, _tmp47, _tmp48, _tmp49, _tmp50, _tmp51, _tmp52, _tmp53, _tmp54, _tmp55, _tmp56, _tmp57, _tmp58, _tmp59, _tmp60, _tmp61, _tmp62, _tmp63, _tmp64, _tmp65, _tmp66, _tmp67, _tmp68, _tmp69, _tmp70, _tmp71, _tmp72, _tmp73, _tmp74, _tmp75, _tmp76, _tmp77, _tmp78, _tmp79, _tmp80, _tmp81, _tmp82, toolCall, mcpCall, _tmp83, _tmp84, _tmp85, _tmp86, err, e, _tmp87, _tmp88;
7178
7647
  return _ts_generator(this, function(_state) {
7179
7648
  switch(_state.label){
7180
7649
  case 0:
7181
- threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
7650
+ client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
7182
7651
  responseCreatedResponse = null;
7183
7652
  toolCalls = {};
7653
+ mcpCalls = {};
7654
+ codeInterpreterCalls = {};
7184
7655
  itemIds = [];
7185
7656
  _state.label = 1;
7186
7657
  case 1:
7187
7658
  _state.trys.push([
7188
7659
  1,
7189
- 42,
7190
- 44,
7191
- 47
7660
+ 131,
7661
+ 134,
7662
+ 137
7192
7663
  ]);
7193
7664
  _iteratorAbruptCompletion = false, _didIteratorError = false;
7194
7665
  _state.label = 2;
7195
7666
  case 2:
7196
7667
  _state.trys.push([
7197
7668
  2,
7198
- 35,
7199
- 36,
7200
- 41
7669
+ 124,
7670
+ 125,
7671
+ 130
7201
7672
  ]);
7202
7673
  _iterator = _async_iterator(response);
7203
7674
  _state.label = 3;
@@ -7209,7 +7680,7 @@ var responsesRunAdapter = function(param) {
7209
7680
  case 4:
7210
7681
  if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
7211
7682
  3,
7212
- 34
7683
+ 123
7213
7684
  ];
7214
7685
  _value = _step.value;
7215
7686
  event = _value;
@@ -7223,339 +7694,1244 @@ var responsesRunAdapter = function(param) {
7223
7694
  case "response.in_progress":
7224
7695
  return [
7225
7696
  3,
7226
- 7
7697
+ 8
7227
7698
  ];
7228
7699
  case "response.completed":
7229
7700
  return [
7230
7701
  3,
7231
- 9
7702
+ 11
7232
7703
  ];
7233
7704
  case "response.failed":
7234
7705
  return [
7235
7706
  3,
7236
- 14
7707
+ 18
7237
7708
  ];
7238
7709
  case "response.output_text.delta":
7239
7710
  return [
7240
7711
  3,
7241
- 16
7712
+ 21
7242
7713
  ];
7243
7714
  case "response.output_item.added":
7244
7715
  return [
7245
7716
  3,
7246
- 18
7717
+ 23
7247
7718
  ];
7248
7719
  case "response.output_item.done":
7249
7720
  return [
7250
7721
  3,
7251
- 24
7722
+ 67
7252
7723
  ];
7253
7724
  case "response.function_call_arguments.delta":
7254
7725
  return [
7255
7726
  3,
7256
- 30
7727
+ 111
7728
+ ];
7729
+ case "response.mcp_call_arguments.delta":
7730
+ return [
7731
+ 3,
7732
+ 113
7733
+ ];
7734
+ case "response.image_generation_call.in_progress":
7735
+ return [
7736
+ 3,
7737
+ 115
7738
+ ];
7739
+ case "response.image_generation_call.generating":
7740
+ return [
7741
+ 3,
7742
+ 115
7743
+ ];
7744
+ case "response.image_generation_call.partial_image":
7745
+ return [
7746
+ 3,
7747
+ 118
7257
7748
  ];
7258
7749
  }
7259
7750
  return [
7260
- 3,
7261
- 32
7751
+ 3,
7752
+ 121
7753
+ ];
7754
+ case 5:
7755
+ responseCreatedResponse = event.response;
7756
+ _tmp = {
7757
+ event: "thread.run.created"
7758
+ };
7759
+ _tmp1 = {
7760
+ response: event.response
7761
+ };
7762
+ return [
7763
+ 4,
7764
+ getOpenaiAssistant()
7765
+ ];
7766
+ case 6:
7767
+ return [
7768
+ 4,
7769
+ onEvent2.apply(void 0, [
7770
+ (_tmp.data = serializeResponseAsRun.apply(void 0, [
7771
+ (_tmp1.assistantId = _state.sent().id, _tmp1)
7772
+ ]), _tmp)
7773
+ ])
7774
+ ];
7775
+ case 7:
7776
+ _state.sent();
7777
+ return [
7778
+ 3,
7779
+ 122
7780
+ ];
7781
+ case 8:
7782
+ _tmp2 = {
7783
+ event: "thread.run.in_progress"
7784
+ };
7785
+ _tmp3 = {
7786
+ response: event.response
7787
+ };
7788
+ return [
7789
+ 4,
7790
+ getOpenaiAssistant()
7791
+ ];
7792
+ case 9:
7793
+ return [
7794
+ 4,
7795
+ onEvent2.apply(void 0, [
7796
+ (_tmp2.data = serializeResponseAsRun.apply(void 0, [
7797
+ (_tmp3.assistantId = _state.sent().id, _tmp3)
7798
+ ]), _tmp2)
7799
+ ])
7800
+ ];
7801
+ case 10:
7802
+ _state.sent();
7803
+ return [
7804
+ 3,
7805
+ 122
7806
+ ];
7807
+ case 11:
7808
+ itemIds = event.response.output.filter(function(o) {
7809
+ return o.id;
7810
+ }).map(function(o) {
7811
+ return o.id;
7812
+ });
7813
+ toolCalls2 = event.response.output.filter(function(o) {
7814
+ return o.type === "function_call";
7815
+ });
7816
+ if (!(toolCalls2.length > 0)) return [
7817
+ 3,
7818
+ 14
7819
+ ];
7820
+ _tmp4 = {
7821
+ event: "thread.run.requires_action"
7822
+ };
7823
+ _tmp5 = [
7824
+ {}
7825
+ ];
7826
+ _tmp6 = {
7827
+ response: event.response
7828
+ };
7829
+ return [
7830
+ 4,
7831
+ getOpenaiAssistant()
7832
+ ];
7833
+ case 12:
7834
+ return [
7835
+ 4,
7836
+ onEvent2.apply(void 0, [
7837
+ (_tmp4.data = _object_spread.apply(void 0, _tmp5.concat([
7838
+ serializeResponseAsRun.apply(void 0, [
7839
+ (_tmp6.assistantId = _state.sent().id, _tmp6)
7840
+ ]),
7841
+ {
7842
+ status: "requires_action",
7843
+ required_action: {
7844
+ type: "submit_tool_outputs",
7845
+ submit_tool_outputs: {
7846
+ tool_calls: serializeToolCalls2({
7847
+ toolCalls: toolCalls2
7848
+ })
7849
+ }
7850
+ }
7851
+ }
7852
+ ])), _tmp4)
7853
+ ])
7854
+ ];
7855
+ case 13:
7856
+ _state.sent();
7857
+ return [
7858
+ 3,
7859
+ 17
7860
+ ];
7861
+ case 14:
7862
+ _tmp7 = {
7863
+ event: "thread.run.completed"
7864
+ };
7865
+ _tmp8 = {
7866
+ response: event.response
7867
+ };
7868
+ return [
7869
+ 4,
7870
+ getOpenaiAssistant()
7871
+ ];
7872
+ case 15:
7873
+ return [
7874
+ 4,
7875
+ onEvent2.apply(void 0, [
7876
+ (_tmp7.data = serializeResponseAsRun.apply(void 0, [
7877
+ (_tmp8.assistantId = _state.sent().id, _tmp8)
7878
+ ]), _tmp7)
7879
+ ])
7880
+ ];
7881
+ case 16:
7882
+ _state.sent();
7883
+ _state.label = 17;
7884
+ case 17:
7885
+ return [
7886
+ 3,
7887
+ 122
7888
+ ];
7889
+ case 18:
7890
+ _tmp9 = {
7891
+ event: "thread.run.failed"
7892
+ };
7893
+ _tmp10 = {
7894
+ response: event.response
7895
+ };
7896
+ return [
7897
+ 4,
7898
+ getOpenaiAssistant()
7899
+ ];
7900
+ case 19:
7901
+ return [
7902
+ 4,
7903
+ onEvent2.apply(void 0, [
7904
+ (_tmp9.data = serializeResponseAsRun.apply(void 0, [
7905
+ (_tmp10.assistantId = _state.sent().id, _tmp10)
7906
+ ]), _tmp9)
7907
+ ])
7908
+ ];
7909
+ case 20:
7910
+ _state.sent();
7911
+ return [
7912
+ 3,
7913
+ 122
7914
+ ];
7915
+ case 21:
7916
+ return [
7917
+ 4,
7918
+ onEvent2({
7919
+ event: "thread.message.delta",
7920
+ data: {
7921
+ id: event.item_id,
7922
+ delta: {
7923
+ content: [
7924
+ {
7925
+ type: "text",
7926
+ index: event.content_index,
7927
+ text: {
7928
+ value: event.delta
7929
+ }
7930
+ }
7931
+ ]
7932
+ }
7933
+ }
7934
+ })
7935
+ ];
7936
+ case 22:
7937
+ _state.sent();
7938
+ return [
7939
+ 3,
7940
+ 122
7941
+ ];
7942
+ case 23:
7943
+ if (!(event.item.type === "message")) return [
7944
+ 3,
7945
+ 28
7946
+ ];
7947
+ _tmp11 = {
7948
+ event: "thread.message.created"
7949
+ };
7950
+ _tmp12 = {
7951
+ item: event.item,
7952
+ threadId: threadId
7953
+ };
7954
+ return [
7955
+ 4,
7956
+ getOpenaiAssistant()
7957
+ ];
7958
+ case 24:
7959
+ return [
7960
+ 4,
7961
+ onEvent2.apply(void 0, [
7962
+ (_tmp11.data = serializeItemAsMessage.apply(void 0, [
7963
+ (_tmp12.openaiAssistant = _state.sent(), _tmp12.createdAt = (0, import_dayjs18.default)().unix(), _tmp12.runId = responseCreatedResponse.id, _tmp12.status = "in_progress", _tmp12)
7964
+ ]), _tmp11)
7965
+ ])
7966
+ ];
7967
+ case 25:
7968
+ _state.sent();
7969
+ _tmp13 = {
7970
+ event: "thread.run.step.created"
7971
+ };
7972
+ _tmp14 = {
7973
+ item: event.item,
7974
+ items: [],
7975
+ threadId: threadId
7976
+ };
7977
+ return [
7978
+ 4,
7979
+ getOpenaiAssistant()
7980
+ ];
7981
+ case 26:
7982
+ return [
7983
+ 4,
7984
+ onEvent2.apply(void 0, [
7985
+ (_tmp13.data = serializeItemAsRunStep.apply(void 0, [
7986
+ (_tmp14.openaiAssistant = _state.sent(), _tmp14.runId = responseCreatedResponse.id, _tmp14.status = "in_progress", _tmp14.completedAt = null, _tmp14)
7987
+ ]), _tmp13)
7988
+ ])
7989
+ ];
7990
+ case 27:
7991
+ _state.sent();
7992
+ return [
7993
+ 3,
7994
+ 66
7995
+ ];
7996
+ case 28:
7997
+ if (!(event.item.type === "function_call")) return [
7998
+ 3,
7999
+ 31
8000
+ ];
8001
+ toolCalls[event.item.id] = event.item;
8002
+ _tmp15 = {
8003
+ event: "thread.run.step.created"
8004
+ };
8005
+ _tmp16 = {
8006
+ item: event.item,
8007
+ items: [],
8008
+ threadId: threadId
8009
+ };
8010
+ return [
8011
+ 4,
8012
+ getOpenaiAssistant()
8013
+ ];
8014
+ case 29:
8015
+ return [
8016
+ 4,
8017
+ onEvent2.apply(void 0, [
8018
+ (_tmp15.data = serializeItemAsRunStep.apply(void 0, [
8019
+ (_tmp16.openaiAssistant = _state.sent(), _tmp16.runId = responseCreatedResponse.id, _tmp16)
8020
+ ]), _tmp15)
8021
+ ])
8022
+ ];
8023
+ case 30:
8024
+ _state.sent();
8025
+ return [
8026
+ 3,
8027
+ 66
8028
+ ];
8029
+ case 31:
8030
+ if (!(event.item.type === "image_generation_call")) return [
8031
+ 3,
8032
+ 38
8033
+ ];
8034
+ _tmp17 = {
8035
+ event: "thread.message.created"
8036
+ };
8037
+ _tmp18 = {
8038
+ item: event.item,
8039
+ threadId: threadId
8040
+ };
8041
+ return [
8042
+ 4,
8043
+ getOpenaiAssistant()
8044
+ ];
8045
+ case 32:
8046
+ return [
8047
+ 4,
8048
+ onEvent2.apply(void 0, [
8049
+ (_tmp17.data = serializeItemAsMessage.apply(void 0, [
8050
+ (_tmp18.openaiAssistant = _state.sent(), _tmp18.createdAt = (0, import_dayjs18.default)().unix(), _tmp18.runId = responseCreatedResponse.id, _tmp18.status = "in_progress", _tmp18)
8051
+ ]), _tmp17)
8052
+ ])
8053
+ ];
8054
+ case 33:
8055
+ _state.sent();
8056
+ _tmp19 = {
8057
+ event: "thread.run.step.created"
8058
+ };
8059
+ _tmp20 = {
8060
+ item: event.item,
8061
+ items: [],
8062
+ threadId: threadId
8063
+ };
8064
+ return [
8065
+ 4,
8066
+ getOpenaiAssistant()
8067
+ ];
8068
+ case 34:
8069
+ return [
8070
+ 4,
8071
+ onEvent2.apply(void 0, [
8072
+ (_tmp19.data = serializeItemAsRunStep.apply(void 0, [
8073
+ (_tmp20.openaiAssistant = _state.sent(), _tmp20.runId = responseCreatedResponse.id, _tmp20.status = "in_progress", _tmp20.completedAt = null, _tmp20)
8074
+ ]), _tmp19)
8075
+ ])
8076
+ ];
8077
+ case 35:
8078
+ _state.sent();
8079
+ _tmp21 = {
8080
+ event: "thread.run.step.created"
8081
+ };
8082
+ _tmp22 = {
8083
+ item: event.item
8084
+ };
8085
+ return [
8086
+ 4,
8087
+ getOpenaiAssistant()
8088
+ ];
8089
+ case 36:
8090
+ return [
8091
+ 4,
8092
+ onEvent2.apply(void 0, [
8093
+ (_tmp21.data = serializeItemAsImageGenerationRunStep.apply(void 0, [
8094
+ (_tmp22.openaiAssistant = _state.sent(), _tmp22.threadId = threadId, _tmp22.runId = responseCreatedResponse.id, _tmp22.completedAt = null, _tmp22)
8095
+ ]), _tmp21)
8096
+ ])
8097
+ ];
8098
+ case 37:
8099
+ _state.sent();
8100
+ return [
8101
+ 3,
8102
+ 66
8103
+ ];
8104
+ case 38:
8105
+ if (!(event.item.type === "web_search_call")) return [
8106
+ 3,
8107
+ 45
8108
+ ];
8109
+ _tmp23 = {
8110
+ event: "thread.message.created"
8111
+ };
8112
+ _tmp24 = {
8113
+ item: event.item,
8114
+ threadId: threadId
8115
+ };
8116
+ return [
8117
+ 4,
8118
+ getOpenaiAssistant()
8119
+ ];
8120
+ case 39:
8121
+ return [
8122
+ 4,
8123
+ onEvent2.apply(void 0, [
8124
+ (_tmp23.data = serializeItemAsMessage.apply(void 0, [
8125
+ (_tmp24.openaiAssistant = _state.sent(), _tmp24.createdAt = (0, import_dayjs18.default)().unix(), _tmp24.runId = responseCreatedResponse.id, _tmp24.status = "in_progress", _tmp24)
8126
+ ]), _tmp23)
8127
+ ])
8128
+ ];
8129
+ case 40:
8130
+ _state.sent();
8131
+ _tmp25 = {
8132
+ event: "thread.run.step.created"
8133
+ };
8134
+ _tmp26 = {
8135
+ item: event.item,
8136
+ items: [],
8137
+ threadId: threadId
8138
+ };
8139
+ return [
8140
+ 4,
8141
+ getOpenaiAssistant()
8142
+ ];
8143
+ case 41:
8144
+ return [
8145
+ 4,
8146
+ onEvent2.apply(void 0, [
8147
+ (_tmp25.data = serializeItemAsRunStep.apply(void 0, [
8148
+ (_tmp26.openaiAssistant = _state.sent(), _tmp26.runId = responseCreatedResponse.id, _tmp26.status = "in_progress", _tmp26.completedAt = null, _tmp26)
8149
+ ]), _tmp25)
8150
+ ])
8151
+ ];
8152
+ case 42:
8153
+ _state.sent();
8154
+ _tmp27 = {
8155
+ event: "thread.run.step.created"
8156
+ };
8157
+ _tmp28 = {
8158
+ item: event.item
8159
+ };
8160
+ return [
8161
+ 4,
8162
+ getOpenaiAssistant()
8163
+ ];
8164
+ case 43:
8165
+ return [
8166
+ 4,
8167
+ onEvent2.apply(void 0, [
8168
+ (_tmp27.data = serializeItemAsWebSearchRunStep.apply(void 0, [
8169
+ (_tmp28.openaiAssistant = _state.sent(), _tmp28.threadId = threadId, _tmp28.runId = responseCreatedResponse.id, _tmp28.completedAt = null, _tmp28)
8170
+ ]), _tmp27)
8171
+ ])
8172
+ ];
8173
+ case 44:
8174
+ _state.sent();
8175
+ return [
8176
+ 3,
8177
+ 66
8178
+ ];
8179
+ case 45:
8180
+ if (!(event.item.type === "mcp_list_tools")) return [
8181
+ 3,
8182
+ 52
8183
+ ];
8184
+ _tmp29 = {
8185
+ event: "thread.message.created"
8186
+ };
8187
+ _tmp30 = {
8188
+ item: event.item,
8189
+ threadId: threadId
8190
+ };
8191
+ return [
8192
+ 4,
8193
+ getOpenaiAssistant()
8194
+ ];
8195
+ case 46:
8196
+ return [
8197
+ 4,
8198
+ onEvent2.apply(void 0, [
8199
+ (_tmp29.data = serializeItemAsMessage.apply(void 0, [
8200
+ (_tmp30.openaiAssistant = _state.sent(), _tmp30.createdAt = (0, import_dayjs18.default)().unix(), _tmp30.runId = responseCreatedResponse.id, _tmp30.status = "in_progress", _tmp30)
8201
+ ]), _tmp29)
8202
+ ])
8203
+ ];
8204
+ case 47:
8205
+ _state.sent();
8206
+ _tmp31 = {
8207
+ event: "thread.run.step.created"
8208
+ };
8209
+ _tmp32 = {
8210
+ item: event.item,
8211
+ items: [],
8212
+ threadId: threadId
8213
+ };
8214
+ return [
8215
+ 4,
8216
+ getOpenaiAssistant()
8217
+ ];
8218
+ case 48:
8219
+ return [
8220
+ 4,
8221
+ onEvent2.apply(void 0, [
8222
+ (_tmp31.data = serializeItemAsRunStep.apply(void 0, [
8223
+ (_tmp32.openaiAssistant = _state.sent(), _tmp32.runId = responseCreatedResponse.id, _tmp32.status = "in_progress", _tmp32.completedAt = null, _tmp32)
8224
+ ]), _tmp31)
8225
+ ])
8226
+ ];
8227
+ case 49:
8228
+ _state.sent();
8229
+ _tmp33 = {
8230
+ event: "thread.run.step.created"
8231
+ };
8232
+ _tmp34 = {
8233
+ item: event.item
8234
+ };
8235
+ return [
8236
+ 4,
8237
+ getOpenaiAssistant()
8238
+ ];
8239
+ case 50:
8240
+ return [
8241
+ 4,
8242
+ onEvent2.apply(void 0, [
8243
+ (_tmp33.data = serializeItemAsMcpListToolsRunStep.apply(void 0, [
8244
+ (_tmp34.openaiAssistant = _state.sent(), _tmp34.threadId = threadId, _tmp34.runId = responseCreatedResponse.id, _tmp34.completedAt = null, _tmp34)
8245
+ ]), _tmp33)
8246
+ ])
8247
+ ];
8248
+ case 51:
8249
+ _state.sent();
8250
+ return [
8251
+ 3,
8252
+ 66
8253
+ ];
8254
+ case 52:
8255
+ if (!(event.item.type === "mcp_call")) return [
8256
+ 3,
8257
+ 59
8258
+ ];
8259
+ mcpCalls[event.item.id] = event.item;
8260
+ _tmp35 = {
8261
+ event: "thread.message.created"
8262
+ };
8263
+ _tmp36 = {
8264
+ item: event.item,
8265
+ threadId: threadId
8266
+ };
8267
+ return [
8268
+ 4,
8269
+ getOpenaiAssistant()
8270
+ ];
8271
+ case 53:
8272
+ return [
8273
+ 4,
8274
+ onEvent2.apply(void 0, [
8275
+ (_tmp35.data = serializeItemAsMessage.apply(void 0, [
8276
+ (_tmp36.openaiAssistant = _state.sent(), _tmp36.createdAt = (0, import_dayjs18.default)().unix(), _tmp36.runId = responseCreatedResponse.id, _tmp36.status = "in_progress", _tmp36)
8277
+ ]), _tmp35)
8278
+ ])
8279
+ ];
8280
+ case 54:
8281
+ _state.sent();
8282
+ _tmp37 = {
8283
+ event: "thread.run.step.created"
8284
+ };
8285
+ _tmp38 = {
8286
+ item: event.item,
8287
+ items: [],
8288
+ threadId: threadId
8289
+ };
8290
+ return [
8291
+ 4,
8292
+ getOpenaiAssistant()
8293
+ ];
8294
+ case 55:
8295
+ return [
8296
+ 4,
8297
+ onEvent2.apply(void 0, [
8298
+ (_tmp37.data = serializeItemAsRunStep.apply(void 0, [
8299
+ (_tmp38.openaiAssistant = _state.sent(), _tmp38.runId = responseCreatedResponse.id, _tmp38.status = "in_progress", _tmp38.completedAt = null, _tmp38)
8300
+ ]), _tmp37)
8301
+ ])
8302
+ ];
8303
+ case 56:
8304
+ _state.sent();
8305
+ _tmp39 = {
8306
+ event: "thread.run.step.created"
8307
+ };
8308
+ _tmp40 = {
8309
+ item: event.item
8310
+ };
8311
+ return [
8312
+ 4,
8313
+ getOpenaiAssistant()
8314
+ ];
8315
+ case 57:
8316
+ return [
8317
+ 4,
8318
+ onEvent2.apply(void 0, [
8319
+ (_tmp39.data = serializeItemAsMcpCallRunStep.apply(void 0, [
8320
+ (_tmp40.openaiAssistant = _state.sent(), _tmp40.threadId = threadId, _tmp40.runId = responseCreatedResponse.id, _tmp40.completedAt = null, _tmp40)
8321
+ ]), _tmp39)
8322
+ ])
8323
+ ];
8324
+ case 58:
8325
+ _state.sent();
8326
+ return [
8327
+ 3,
8328
+ 66
8329
+ ];
8330
+ case 59:
8331
+ if (!(event.item.type === "code_interpreter_call")) return [
8332
+ 3,
8333
+ 66
8334
+ ];
8335
+ codeInterpreterCalls[event.item.id] = event.item;
8336
+ _tmp41 = {
8337
+ event: "thread.message.created"
8338
+ };
8339
+ _tmp42 = {
8340
+ item: event.item,
8341
+ threadId: threadId
8342
+ };
8343
+ return [
8344
+ 4,
8345
+ getOpenaiAssistant()
8346
+ ];
8347
+ case 60:
8348
+ return [
8349
+ 4,
8350
+ onEvent2.apply(void 0, [
8351
+ (_tmp41.data = serializeItemAsMessage.apply(void 0, [
8352
+ (_tmp42.openaiAssistant = _state.sent(), _tmp42.createdAt = (0, import_dayjs18.default)().unix(), _tmp42.runId = responseCreatedResponse.id, _tmp42.status = "in_progress", _tmp42)
8353
+ ]), _tmp41)
8354
+ ])
8355
+ ];
8356
+ case 61:
8357
+ _state.sent();
8358
+ _tmp43 = {
8359
+ event: "thread.run.step.created"
8360
+ };
8361
+ _tmp44 = {
8362
+ item: event.item,
8363
+ items: [],
8364
+ threadId: threadId
8365
+ };
8366
+ return [
8367
+ 4,
8368
+ getOpenaiAssistant()
8369
+ ];
8370
+ case 62:
8371
+ return [
8372
+ 4,
8373
+ onEvent2.apply(void 0, [
8374
+ (_tmp43.data = serializeItemAsRunStep.apply(void 0, [
8375
+ (_tmp44.openaiAssistant = _state.sent(), _tmp44.runId = responseCreatedResponse.id, _tmp44.status = "in_progress", _tmp44.completedAt = null, _tmp44)
8376
+ ]), _tmp43)
8377
+ ])
8378
+ ];
8379
+ case 63:
8380
+ _state.sent();
8381
+ _tmp45 = {
8382
+ event: "thread.run.step.created"
8383
+ };
8384
+ _tmp46 = {
8385
+ item: event.item
8386
+ };
8387
+ return [
8388
+ 4,
8389
+ getOpenaiAssistant()
8390
+ ];
8391
+ case 64:
8392
+ return [
8393
+ 4,
8394
+ onEvent2.apply(void 0, [
8395
+ (_tmp45.data = serializeItemAsCodeInterpreterCallRunStep.apply(void 0, [
8396
+ (_tmp46.openaiAssistant = _state.sent(), _tmp46.threadId = threadId, _tmp46.runId = responseCreatedResponse.id, _tmp46.completedAt = null, _tmp46)
8397
+ ]), _tmp45)
8398
+ ])
8399
+ ];
8400
+ case 65:
8401
+ _state.sent();
8402
+ _state.label = 66;
8403
+ case 66:
8404
+ if (event.item.id) itemIds.push(event.item.id);
8405
+ return [
8406
+ 3,
8407
+ 122
8408
+ ];
8409
+ case 67:
8410
+ if (!(event.item.type === "message")) return [
8411
+ 3,
8412
+ 72
8413
+ ];
8414
+ _tmp47 = {
8415
+ event: "thread.run.step.completed"
8416
+ };
8417
+ _tmp48 = {
8418
+ item: event.item,
8419
+ items: [],
8420
+ threadId: threadId
8421
+ };
8422
+ return [
8423
+ 4,
8424
+ getOpenaiAssistant()
8425
+ ];
8426
+ case 68:
8427
+ return [
8428
+ 4,
8429
+ onEvent2.apply(void 0, [
8430
+ (_tmp47.data = serializeItemAsRunStep.apply(void 0, [
8431
+ (_tmp48.openaiAssistant = _state.sent(), _tmp48.runId = responseCreatedResponse.id, _tmp48)
8432
+ ]), _tmp47)
8433
+ ])
8434
+ ];
8435
+ case 69:
8436
+ _state.sent();
8437
+ _tmp49 = {
8438
+ event: "thread.message.completed"
8439
+ };
8440
+ _tmp50 = {
8441
+ item: event.item,
8442
+ threadId: threadId
8443
+ };
8444
+ return [
8445
+ 4,
8446
+ getOpenaiAssistant()
8447
+ ];
8448
+ case 70:
8449
+ return [
8450
+ 4,
8451
+ onEvent2.apply(void 0, [
8452
+ (_tmp49.data = serializeItemAsMessage.apply(void 0, [
8453
+ (_tmp50.openaiAssistant = _state.sent(), _tmp50.createdAt = (0, import_dayjs18.default)().unix(), _tmp50.runId = responseCreatedResponse.id, _tmp50)
8454
+ ]), _tmp49)
8455
+ ])
8456
+ ];
8457
+ case 71:
8458
+ _state.sent();
8459
+ return [
8460
+ 3,
8461
+ 110
8462
+ ];
8463
+ case 72:
8464
+ if (!(event.item.type === "function_call")) return [
8465
+ 3,
8466
+ 75
8467
+ ];
8468
+ toolCalls[event.item.id] = event.item;
8469
+ _tmp51 = {
8470
+ event: "thread.run.step.in_progress"
8471
+ };
8472
+ _tmp52 = {
8473
+ item: event.item,
8474
+ items: [],
8475
+ threadId: threadId
8476
+ };
8477
+ return [
8478
+ 4,
8479
+ getOpenaiAssistant()
8480
+ ];
8481
+ case 73:
8482
+ return [
8483
+ 4,
8484
+ onEvent2.apply(void 0, [
8485
+ (_tmp51.data = serializeItemAsRunStep.apply(void 0, [
8486
+ (_tmp52.openaiAssistant = _state.sent(), _tmp52.runId = responseCreatedResponse.id, _tmp52)
8487
+ ]), _tmp51)
8488
+ ])
8489
+ ];
8490
+ case 74:
8491
+ _state.sent();
8492
+ return [
8493
+ 3,
8494
+ 110
8495
+ ];
8496
+ case 75:
8497
+ if (!(event.item.type === "image_generation_call")) return [
8498
+ 3,
8499
+ 82
8500
+ ];
8501
+ _tmp53 = {
8502
+ event: "thread.run.step.completed"
8503
+ };
8504
+ _tmp54 = {
8505
+ item: event.item
8506
+ };
8507
+ return [
8508
+ 4,
8509
+ getOpenaiAssistant()
8510
+ ];
8511
+ case 76:
8512
+ return [
8513
+ 4,
8514
+ onEvent2.apply(void 0, [
8515
+ (_tmp53.data = serializeItemAsImageGenerationRunStep.apply(void 0, [
8516
+ (_tmp54.openaiAssistant = _state.sent(), _tmp54.threadId = threadId, _tmp54.runId = responseCreatedResponse.id, _tmp54)
8517
+ ]), _tmp53)
8518
+ ])
8519
+ ];
8520
+ case 77:
8521
+ _state.sent();
8522
+ _tmp55 = {
8523
+ event: "thread.run.step.completed"
8524
+ };
8525
+ _tmp56 = {
8526
+ item: event.item,
8527
+ items: [],
8528
+ threadId: threadId
8529
+ };
8530
+ return [
8531
+ 4,
8532
+ getOpenaiAssistant()
8533
+ ];
8534
+ case 78:
8535
+ return [
8536
+ 4,
8537
+ onEvent2.apply(void 0, [
8538
+ (_tmp55.data = serializeItemAsRunStep.apply(void 0, [
8539
+ (_tmp56.openaiAssistant = _state.sent(), _tmp56.runId = responseCreatedResponse.id, _tmp56)
8540
+ ]), _tmp55)
8541
+ ])
8542
+ ];
8543
+ case 79:
8544
+ _state.sent();
8545
+ _tmp57 = {
8546
+ event: "thread.message.completed"
8547
+ };
8548
+ _tmp58 = {
8549
+ item: event.item,
8550
+ threadId: threadId
8551
+ };
8552
+ return [
8553
+ 4,
8554
+ getOpenaiAssistant()
8555
+ ];
8556
+ case 80:
8557
+ return [
8558
+ 4,
8559
+ onEvent2.apply(void 0, [
8560
+ (_tmp57.data = serializeItemAsMessage.apply(void 0, [
8561
+ (_tmp58.openaiAssistant = _state.sent(), _tmp58.createdAt = (0, import_dayjs18.default)().unix(), _tmp58.runId = responseCreatedResponse.id, _tmp58)
8562
+ ]), _tmp57)
8563
+ ])
8564
+ ];
8565
+ case 81:
8566
+ _state.sent();
8567
+ return [
8568
+ 3,
8569
+ 110
8570
+ ];
8571
+ case 82:
8572
+ if (!(event.item.type === "web_search_call")) return [
8573
+ 3,
8574
+ 89
8575
+ ];
8576
+ _tmp59 = {
8577
+ event: "thread.run.step.completed"
8578
+ };
8579
+ _tmp60 = {
8580
+ item: event.item
8581
+ };
8582
+ return [
8583
+ 4,
8584
+ getOpenaiAssistant()
8585
+ ];
8586
+ case 83:
8587
+ return [
8588
+ 4,
8589
+ onEvent2.apply(void 0, [
8590
+ (_tmp59.data = serializeItemAsWebSearchRunStep.apply(void 0, [
8591
+ (_tmp60.openaiAssistant = _state.sent(), _tmp60.threadId = threadId, _tmp60.runId = responseCreatedResponse.id, _tmp60)
8592
+ ]), _tmp59)
8593
+ ])
8594
+ ];
8595
+ case 84:
8596
+ _state.sent();
8597
+ _tmp61 = {
8598
+ event: "thread.run.step.completed"
8599
+ };
8600
+ _tmp62 = {
8601
+ item: event.item,
8602
+ items: [],
8603
+ threadId: threadId
8604
+ };
8605
+ return [
8606
+ 4,
8607
+ getOpenaiAssistant()
7262
8608
  ];
7263
- case 5:
7264
- responseCreatedResponse = event.response;
8609
+ case 85:
7265
8610
  return [
7266
8611
  4,
7267
- onEvent2({
7268
- event: "thread.run.created",
7269
- data: serializeResponseAsRun({
7270
- response: event.response,
7271
- assistantId: openaiAssistant.id
7272
- })
7273
- })
8612
+ onEvent2.apply(void 0, [
8613
+ (_tmp61.data = serializeItemAsRunStep.apply(void 0, [
8614
+ (_tmp62.openaiAssistant = _state.sent(), _tmp62.runId = responseCreatedResponse.id, _tmp62)
8615
+ ]), _tmp61)
8616
+ ])
7274
8617
  ];
7275
- case 6:
8618
+ case 86:
7276
8619
  _state.sent();
8620
+ _tmp63 = {
8621
+ event: "thread.message.completed"
8622
+ };
8623
+ _tmp64 = {
8624
+ item: event.item,
8625
+ threadId: threadId
8626
+ };
7277
8627
  return [
7278
- 3,
7279
- 33
8628
+ 4,
8629
+ getOpenaiAssistant()
7280
8630
  ];
7281
- case 7:
8631
+ case 87:
7282
8632
  return [
7283
8633
  4,
7284
- onEvent2({
7285
- event: "thread.run.in_progress",
7286
- data: serializeResponseAsRun({
7287
- response: event.response,
7288
- assistantId: openaiAssistant.id
7289
- })
7290
- })
8634
+ onEvent2.apply(void 0, [
8635
+ (_tmp63.data = serializeItemAsMessage.apply(void 0, [
8636
+ (_tmp64.openaiAssistant = _state.sent(), _tmp64.createdAt = (0, import_dayjs18.default)().unix(), _tmp64.runId = responseCreatedResponse.id, _tmp64)
8637
+ ]), _tmp63)
8638
+ ])
7291
8639
  ];
7292
- case 8:
8640
+ case 88:
7293
8641
  _state.sent();
7294
8642
  return [
7295
8643
  3,
7296
- 33
8644
+ 110
7297
8645
  ];
7298
- case 9:
7299
- itemIds = event.response.output.filter(function(o) {
7300
- return o.id;
7301
- }).map(function(o) {
7302
- return o.id;
7303
- });
7304
- toolCalls2 = event.response.output.filter(function(o) {
7305
- return o.type === "function_call";
7306
- });
7307
- if (!(toolCalls2.length > 0)) return [
8646
+ case 89:
8647
+ if (!(event.item.type === "mcp_list_tools")) return [
7308
8648
  3,
7309
- 11
8649
+ 96
8650
+ ];
8651
+ _tmp65 = {
8652
+ event: "thread.run.step.completed"
8653
+ };
8654
+ _tmp66 = {
8655
+ item: event.item
8656
+ };
8657
+ return [
8658
+ 4,
8659
+ getOpenaiAssistant()
7310
8660
  ];
8661
+ case 90:
7311
8662
  return [
7312
8663
  4,
7313
- onEvent2({
7314
- event: "thread.run.requires_action",
7315
- data: _object_spread({}, serializeResponseAsRun({
7316
- response: event.response,
7317
- assistantId: openaiAssistant.id
7318
- }), {
7319
- status: "requires_action",
7320
- required_action: {
7321
- type: "submit_tool_outputs",
7322
- submit_tool_outputs: {
7323
- tool_calls: serializeToolCalls2({
7324
- toolCalls: toolCalls2
7325
- })
7326
- }
7327
- }
7328
- })
7329
- })
8664
+ onEvent2.apply(void 0, [
8665
+ (_tmp65.data = serializeItemAsMcpListToolsRunStep.apply(void 0, [
8666
+ (_tmp66.openaiAssistant = _state.sent(), _tmp66.threadId = threadId, _tmp66.runId = responseCreatedResponse.id, _tmp66)
8667
+ ]), _tmp65)
8668
+ ])
7330
8669
  ];
7331
- case 10:
8670
+ case 91:
7332
8671
  _state.sent();
8672
+ _tmp67 = {
8673
+ event: "thread.run.step.completed"
8674
+ };
8675
+ _tmp68 = {
8676
+ item: event.item,
8677
+ items: [],
8678
+ threadId: threadId
8679
+ };
7333
8680
  return [
7334
- 3,
7335
- 13
8681
+ 4,
8682
+ getOpenaiAssistant()
7336
8683
  ];
7337
- case 11:
8684
+ case 92:
7338
8685
  return [
7339
8686
  4,
7340
- onEvent2({
7341
- event: "thread.run.completed",
7342
- data: serializeResponseAsRun({
7343
- response: event.response,
7344
- assistantId: openaiAssistant.id
7345
- })
7346
- })
8687
+ onEvent2.apply(void 0, [
8688
+ (_tmp67.data = serializeItemAsRunStep.apply(void 0, [
8689
+ (_tmp68.openaiAssistant = _state.sent(), _tmp68.runId = responseCreatedResponse.id, _tmp68)
8690
+ ]), _tmp67)
8691
+ ])
7347
8692
  ];
7348
- case 12:
8693
+ case 93:
7349
8694
  _state.sent();
7350
- _state.label = 13;
7351
- case 13:
8695
+ _tmp69 = {
8696
+ event: "thread.message.completed"
8697
+ };
8698
+ _tmp70 = {
8699
+ item: event.item,
8700
+ threadId: threadId
8701
+ };
7352
8702
  return [
7353
- 3,
7354
- 33
8703
+ 4,
8704
+ getOpenaiAssistant()
7355
8705
  ];
7356
- case 14:
8706
+ case 94:
7357
8707
  return [
7358
8708
  4,
7359
- onEvent2({
7360
- event: "thread.run.failed",
7361
- data: serializeResponseAsRun({
7362
- response: event.response,
7363
- assistantId: openaiAssistant.id
7364
- })
7365
- })
8709
+ onEvent2.apply(void 0, [
8710
+ (_tmp69.data = serializeItemAsMessage.apply(void 0, [
8711
+ (_tmp70.openaiAssistant = _state.sent(), _tmp70.createdAt = (0, import_dayjs18.default)().unix(), _tmp70.runId = responseCreatedResponse.id, _tmp70)
8712
+ ]), _tmp69)
8713
+ ])
7366
8714
  ];
7367
- case 15:
8715
+ case 95:
7368
8716
  _state.sent();
7369
8717
  return [
7370
8718
  3,
7371
- 33
8719
+ 110
7372
8720
  ];
7373
- case 16:
8721
+ case 96:
8722
+ if (!(event.item.type === "mcp_call")) return [
8723
+ 3,
8724
+ 103
8725
+ ];
8726
+ _tmp71 = {
8727
+ event: "thread.run.step.completed"
8728
+ };
8729
+ _tmp72 = {
8730
+ item: event.item
8731
+ };
7374
8732
  return [
7375
8733
  4,
7376
- onEvent2({
7377
- event: "thread.message.delta",
7378
- data: {
7379
- id: event.item_id,
7380
- delta: {
7381
- content: [
7382
- {
7383
- type: "text",
7384
- index: event.output_index - 1,
7385
- text: {
7386
- value: event.delta
7387
- }
7388
- }
7389
- ]
7390
- }
7391
- }
7392
- })
8734
+ getOpenaiAssistant()
7393
8735
  ];
7394
- case 17:
7395
- _state.sent();
8736
+ case 97:
7396
8737
  return [
7397
- 3,
7398
- 33
8738
+ 4,
8739
+ onEvent2.apply(void 0, [
8740
+ (_tmp71.data = serializeItemAsMcpCallRunStep.apply(void 0, [
8741
+ (_tmp72.openaiAssistant = _state.sent(), _tmp72.threadId = threadId, _tmp72.runId = responseCreatedResponse.id, _tmp72)
8742
+ ]), _tmp71)
8743
+ ])
7399
8744
  ];
7400
- case 18:
7401
- if (!(event.item.type === "message")) return [
7402
- 3,
7403
- 21
8745
+ case 98:
8746
+ _state.sent();
8747
+ _tmp73 = {
8748
+ event: "thread.run.step.completed"
8749
+ };
8750
+ _tmp74 = {
8751
+ item: event.item,
8752
+ items: [],
8753
+ threadId: threadId
8754
+ };
8755
+ return [
8756
+ 4,
8757
+ getOpenaiAssistant()
7404
8758
  ];
8759
+ case 99:
7405
8760
  return [
7406
8761
  4,
7407
- onEvent2({
7408
- event: "thread.run.step.created",
7409
- data: serializeItemAsRunStep({
7410
- item: event.item,
7411
- items: [],
7412
- threadId: threadId,
7413
- openaiAssistant: openaiAssistant,
7414
- runId: responseCreatedResponse.id,
7415
- status: "in_progress",
7416
- completedAt: null
7417
- })
7418
- })
8762
+ onEvent2.apply(void 0, [
8763
+ (_tmp73.data = serializeItemAsRunStep.apply(void 0, [
8764
+ (_tmp74.openaiAssistant = _state.sent(), _tmp74.runId = responseCreatedResponse.id, _tmp74)
8765
+ ]), _tmp73)
8766
+ ])
7419
8767
  ];
7420
- case 19:
8768
+ case 100:
7421
8769
  _state.sent();
8770
+ _tmp75 = {
8771
+ event: "thread.message.completed"
8772
+ };
8773
+ _tmp76 = {
8774
+ item: event.item,
8775
+ threadId: threadId
8776
+ };
7422
8777
  return [
7423
8778
  4,
7424
- onEvent2({
7425
- event: "thread.message.created",
7426
- data: serializeItemAsMessage({
7427
- item: event.item,
7428
- threadId: threadId,
7429
- openaiAssistant: openaiAssistant,
7430
- createdAt: (0, import_dayjs13.default)().unix(),
7431
- runId: responseCreatedResponse.id,
7432
- status: "in_progress"
7433
- })
7434
- })
8779
+ getOpenaiAssistant()
7435
8780
  ];
7436
- case 20:
8781
+ case 101:
8782
+ return [
8783
+ 4,
8784
+ onEvent2.apply(void 0, [
8785
+ (_tmp75.data = serializeItemAsMessage.apply(void 0, [
8786
+ (_tmp76.openaiAssistant = _state.sent(), _tmp76.createdAt = (0, import_dayjs18.default)().unix(), _tmp76.runId = responseCreatedResponse.id, _tmp76)
8787
+ ]), _tmp75)
8788
+ ])
8789
+ ];
8790
+ case 102:
7437
8791
  _state.sent();
7438
8792
  return [
7439
8793
  3,
7440
- 23
8794
+ 110
7441
8795
  ];
7442
- case 21:
7443
- if (!(event.item.type === "function_call")) return [
8796
+ case 103:
8797
+ if (!(event.item.type === "code_interpreter_call")) return [
7444
8798
  3,
7445
- 23
8799
+ 110
7446
8800
  ];
7447
- toolCalls[event.item.id] = event.item;
8801
+ _tmp77 = {
8802
+ event: "thread.run.step.completed"
8803
+ };
8804
+ _tmp78 = {
8805
+ item: event.item
8806
+ };
7448
8807
  return [
7449
8808
  4,
7450
- onEvent2({
7451
- event: "thread.run.step.created",
7452
- data: serializeItemAsRunStep({
7453
- item: event.item,
7454
- items: [],
7455
- threadId: threadId,
7456
- openaiAssistant: openaiAssistant,
7457
- runId: responseCreatedResponse.id
7458
- })
7459
- })
8809
+ getOpenaiAssistant()
7460
8810
  ];
7461
- case 22:
7462
- _state.sent();
7463
- _state.label = 23;
7464
- case 23:
7465
- if (event.item.id) itemIds.push(event.item.id);
8811
+ case 104:
7466
8812
  return [
7467
- 3,
7468
- 33
8813
+ 4,
8814
+ onEvent2.apply(void 0, [
8815
+ (_tmp77.data = serializeItemAsCodeInterpreterCallRunStep.apply(void 0, [
8816
+ (_tmp78.openaiAssistant = _state.sent(), _tmp78.threadId = threadId, _tmp78.runId = responseCreatedResponse.id, _tmp78)
8817
+ ]), _tmp77)
8818
+ ])
7469
8819
  ];
7470
- case 24:
7471
- if (!(event.item.type === "message")) return [
7472
- 3,
7473
- 27
8820
+ case 105:
8821
+ _state.sent();
8822
+ _tmp79 = {
8823
+ event: "thread.run.step.completed"
8824
+ };
8825
+ _tmp80 = {
8826
+ item: event.item,
8827
+ items: [],
8828
+ threadId: threadId
8829
+ };
8830
+ return [
8831
+ 4,
8832
+ getOpenaiAssistant()
7474
8833
  ];
8834
+ case 106:
7475
8835
  return [
7476
8836
  4,
7477
- onEvent2({
7478
- event: "thread.run.step.completed",
7479
- data: serializeItemAsRunStep({
7480
- item: event.item,
7481
- items: [],
7482
- threadId: threadId,
7483
- openaiAssistant: openaiAssistant,
7484
- runId: responseCreatedResponse.id
7485
- })
7486
- })
8837
+ onEvent2.apply(void 0, [
8838
+ (_tmp79.data = serializeItemAsRunStep.apply(void 0, [
8839
+ (_tmp80.openaiAssistant = _state.sent(), _tmp80.runId = responseCreatedResponse.id, _tmp80)
8840
+ ]), _tmp79)
8841
+ ])
7487
8842
  ];
7488
- case 25:
8843
+ case 107:
7489
8844
  _state.sent();
8845
+ _tmp81 = {
8846
+ event: "thread.message.completed"
8847
+ };
8848
+ _tmp82 = {
8849
+ item: event.item,
8850
+ threadId: threadId
8851
+ };
7490
8852
  return [
7491
8853
  4,
7492
- onEvent2({
7493
- event: "thread.message.completed",
7494
- data: serializeItemAsMessage({
7495
- item: event.item,
7496
- threadId: threadId,
7497
- openaiAssistant: openaiAssistant,
7498
- createdAt: (0, import_dayjs13.default)().unix(),
7499
- runId: responseCreatedResponse.id
7500
- })
7501
- })
8854
+ getOpenaiAssistant()
7502
8855
  ];
7503
- case 26:
8856
+ case 108:
8857
+ return [
8858
+ 4,
8859
+ onEvent2.apply(void 0, [
8860
+ (_tmp81.data = serializeItemAsMessage.apply(void 0, [
8861
+ (_tmp82.openaiAssistant = _state.sent(), _tmp82.createdAt = (0, import_dayjs18.default)().unix(), _tmp82.runId = responseCreatedResponse.id, _tmp82)
8862
+ ]), _tmp81)
8863
+ ])
8864
+ ];
8865
+ case 109:
7504
8866
  _state.sent();
8867
+ _state.label = 110;
8868
+ case 110:
7505
8869
  return [
7506
8870
  3,
7507
- 29
8871
+ 122
7508
8872
  ];
7509
- case 27:
7510
- if (!(event.item.type === "function_call")) return [
8873
+ case 111:
8874
+ toolCall = toolCalls[event.item_id];
8875
+ if (!toolCall) return [
7511
8876
  3,
7512
- 29
8877
+ 122
7513
8878
  ];
7514
- toolCalls[event.item.id] = event.item;
7515
8879
  return [
7516
8880
  4,
7517
8881
  onEvent2({
7518
- event: "thread.run.step.in_progress",
7519
- data: serializeItemAsRunStep({
7520
- item: event.item,
7521
- items: [],
7522
- threadId: threadId,
7523
- openaiAssistant: openaiAssistant,
7524
- runId: responseCreatedResponse.id
7525
- })
8882
+ event: "thread.run.step.delta",
8883
+ data: {
8884
+ id: event.item_id,
8885
+ object: "thread.run.step.delta",
8886
+ delta: {
8887
+ step_details: {
8888
+ type: "tool_calls",
8889
+ tool_calls: [
8890
+ {
8891
+ id: toolCall.call_id,
8892
+ type: "function",
8893
+ index: event.output_index,
8894
+ function: {
8895
+ name: toolCall.name,
8896
+ arguments: event.delta,
8897
+ output: null
8898
+ }
8899
+ }
8900
+ ]
8901
+ }
8902
+ }
8903
+ }
7526
8904
  })
7527
8905
  ];
7528
- case 28:
8906
+ case 112:
7529
8907
  _state.sent();
7530
- _state.label = 29;
7531
- case 29:
7532
8908
  return [
7533
8909
  3,
7534
- 33
8910
+ 122
7535
8911
  ];
7536
- case 30:
7537
- toolCall = toolCalls[event.item_id];
7538
- if (!toolCall) return [
8912
+ case 113:
8913
+ mcpCall = mcpCalls[event.item_id];
8914
+ if (!mcpCall) return [
7539
8915
  3,
7540
- 33
8916
+ 122
7541
8917
  ];
7542
8918
  return [
7543
8919
  4,
7544
8920
  onEvent2({
7545
8921
  event: "thread.run.step.delta",
7546
8922
  data: {
7547
- id: event.item_id,
8923
+ id: "fc".concat(event.item_id),
7548
8924
  object: "thread.run.step.delta",
7549
8925
  delta: {
7550
8926
  step_details: {
7551
8927
  type: "tool_calls",
7552
8928
  tool_calls: [
7553
8929
  {
7554
- id: toolCall.call_id,
8930
+ id: "ftc".concat(mcpCall.id),
7555
8931
  type: "function",
7556
8932
  index: event.output_index,
7557
8933
  function: {
7558
- name: toolCall.name,
8934
+ name: mcpCall.name,
7559
8935
  arguments: event.delta,
7560
8936
  output: null
7561
8937
  }
@@ -7566,133 +8942,220 @@ var responsesRunAdapter = function(param) {
7566
8942
  }
7567
8943
  })
7568
8944
  ];
7569
- case 31:
8945
+ case 114:
7570
8946
  _state.sent();
7571
8947
  return [
7572
8948
  3,
7573
- 33
8949
+ 122
7574
8950
  ];
7575
- case 32:
8951
+ case 115:
8952
+ _tmp83 = {
8953
+ event: "thread.message.in_progress"
8954
+ };
8955
+ _tmp84 = {
8956
+ id: event.item_id,
8957
+ object: "thread.message",
8958
+ created_at: (0, import_dayjs18.default)().unix(),
8959
+ thread_id: threadId,
8960
+ completed_at: null,
8961
+ incomplete_at: null,
8962
+ incomplete_details: null,
8963
+ role: "assistant",
8964
+ content: []
8965
+ };
8966
+ return [
8967
+ 4,
8968
+ getOpenaiAssistant()
8969
+ ];
8970
+ case 116:
8971
+ return [
8972
+ 4,
8973
+ onEvent2.apply(void 0, [
8974
+ (_tmp83.data = (_tmp84.assistant_id = _state.sent().id, _tmp84.run_id = responseCreatedResponse.id, _tmp84.attachments = [], _tmp84.status = "in_progress", _tmp84.metadata = {
8975
+ event: JSON.stringify(event)
8976
+ }, _tmp84), _tmp83)
8977
+ ])
8978
+ ];
8979
+ case 117:
8980
+ _state.sent();
7576
8981
  return [
7577
8982
  3,
7578
- 33
8983
+ 122
7579
8984
  ];
7580
- case 33:
8985
+ case 118:
8986
+ _tmp85 = {
8987
+ event: "thread.message.in_progress"
8988
+ };
8989
+ _tmp86 = {
8990
+ id: event.item_id,
8991
+ object: "thread.message",
8992
+ created_at: (0, import_dayjs18.default)().unix(),
8993
+ thread_id: threadId,
8994
+ completed_at: null,
8995
+ incomplete_at: null,
8996
+ incomplete_details: null,
8997
+ role: "assistant",
8998
+ content: [
8999
+ {
9000
+ type: "image_url",
9001
+ image_url: {
9002
+ url: "data:image/png;base64,".concat(event.partial_image_b64),
9003
+ // url: `data:image/png;base64,truncated`,
9004
+ detail: "auto"
9005
+ }
9006
+ }
9007
+ ]
9008
+ };
9009
+ return [
9010
+ 4,
9011
+ getOpenaiAssistant()
9012
+ ];
9013
+ case 119:
9014
+ return [
9015
+ 4,
9016
+ onEvent2.apply(void 0, [
9017
+ (_tmp85.data = (_tmp86.assistant_id = _state.sent().id, _tmp86.run_id = responseCreatedResponse.id, _tmp86.attachments = [], _tmp86.status = "in_progress", _tmp86.metadata = {
9018
+ event: JSON.stringify(_object_spread_props(_object_spread({}, event), {
9019
+ partial_image_b64: "truncated"
9020
+ }))
9021
+ }, _tmp86), _tmp85)
9022
+ ])
9023
+ ];
9024
+ case 120:
9025
+ _state.sent();
9026
+ return [
9027
+ 3,
9028
+ 122
9029
+ ];
9030
+ case 121:
9031
+ return [
9032
+ 3,
9033
+ 122
9034
+ ];
9035
+ case 122:
7581
9036
  _iteratorAbruptCompletion = false;
7582
9037
  return [
7583
9038
  3,
7584
9039
  3
7585
9040
  ];
7586
- case 34:
9041
+ case 123:
7587
9042
  return [
7588
9043
  3,
7589
- 41
9044
+ 130
7590
9045
  ];
7591
- case 35:
9046
+ case 124:
7592
9047
  err = _state.sent();
7593
9048
  _didIteratorError = true;
7594
9049
  _iteratorError = err;
7595
9050
  return [
7596
9051
  3,
7597
- 41
9052
+ 130
7598
9053
  ];
7599
- case 36:
9054
+ case 125:
7600
9055
  _state.trys.push([
7601
- 36,
9056
+ 125,
7602
9057
  ,
7603
- 39,
7604
- 40
9058
+ 128,
9059
+ 129
7605
9060
  ]);
7606
9061
  if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
7607
9062
  3,
7608
- 38
9063
+ 127
7609
9064
  ];
7610
9065
  return [
7611
9066
  4,
7612
9067
  _iterator.return()
7613
9068
  ];
7614
- case 37:
9069
+ case 126:
7615
9070
  _state.sent();
7616
- _state.label = 38;
7617
- case 38:
9071
+ _state.label = 127;
9072
+ case 127:
7618
9073
  return [
7619
9074
  3,
7620
- 40
9075
+ 129
7621
9076
  ];
7622
- case 39:
9077
+ case 128:
7623
9078
  if (_didIteratorError) {
7624
9079
  throw _iteratorError;
7625
9080
  }
7626
9081
  return [
7627
9082
  7
7628
9083
  ];
7629
- case 40:
9084
+ case 129:
7630
9085
  return [
7631
9086
  7
7632
9087
  ];
7633
- case 41:
9088
+ case 130:
7634
9089
  return [
7635
9090
  3,
7636
- 47
9091
+ 137
7637
9092
  ];
7638
- case 42:
9093
+ case 131:
7639
9094
  e = _state.sent();
9095
+ _tmp87 = {
9096
+ event: "thread.run.failed"
9097
+ };
9098
+ _tmp88 = {
9099
+ id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash20.uid)(18)),
9100
+ object: "thread.run",
9101
+ thread_id: threadId
9102
+ };
7640
9103
  return [
7641
9104
  4,
7642
- onEvent2({
7643
- event: "thread.run.failed",
7644
- data: {
7645
- id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash22.uid)(18)),
7646
- object: "thread.run",
7647
- thread_id: threadId,
7648
- assistant_id: openaiAssistant.id,
7649
- status: "failed",
7650
- failed_at: (0, import_dayjs13.default)().unix(),
7651
- last_error: {
7652
- code: "server_error",
7653
- message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
7654
- }
7655
- }
7656
- })
9105
+ getOpenaiAssistant()
7657
9106
  ];
7658
- case 43:
9107
+ case 132:
9108
+ return [
9109
+ 4,
9110
+ onEvent2.apply(void 0, [
9111
+ (_tmp87.data = (_tmp88.assistant_id = _state.sent().id, _tmp88.status = "failed", _tmp88.failed_at = (0, import_dayjs18.default)().unix(), _tmp88.last_error = {
9112
+ code: "server_error",
9113
+ message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
9114
+ }, _tmp88), _tmp87)
9115
+ ])
9116
+ ];
9117
+ case 133:
7659
9118
  _state.sent();
7660
9119
  return [
7661
9120
  3,
7662
- 47
9121
+ 137
7663
9122
  ];
7664
- case 44:
9123
+ case 134:
7665
9124
  if (!((responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) && itemIds.length > 0)) return [
7666
9125
  3,
7667
- 46
9126
+ 136
7668
9127
  ];
7669
9128
  return [
7670
9129
  4,
7671
9130
  saveResponseItemsToConversationMetadata({
7672
- openai: openai,
9131
+ client: client,
7673
9132
  threadId: threadId,
7674
9133
  responseId: responseCreatedResponse.id,
7675
9134
  itemIds: itemIds
7676
9135
  })
7677
9136
  ];
7678
- case 45:
9137
+ case 135:
7679
9138
  _state.sent();
7680
- _state.label = 46;
7681
- case 46:
9139
+ _state.label = 136;
9140
+ case 136:
7682
9141
  return [
7683
9142
  7
7684
9143
  ];
7685
- case 47:
9144
+ case 137:
7686
9145
  return [
7687
9146
  2
7688
9147
  ];
7689
9148
  }
7690
9149
  });
7691
9150
  });
7692
- return function(_) {
9151
+ return function handleRun(_) {
7693
9152
  return _ref.apply(this, arguments);
7694
9153
  };
7695
9154
  }();
9155
+ return {
9156
+ handleRun: handleRun,
9157
+ getOpenaiAssistant: getOpenaiAssistant
9158
+ };
7696
9159
  };
7697
9160
  // Annotate the CommonJS export names for ESM import in node:
7698
9161
  0 && (module.exports = {