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.js CHANGED
@@ -326,10 +326,16 @@ var storageRequestHandlers = function(param) {
326
326
  var storage = param.storage, runAdapter = param.runAdapter, client = param.client;
327
327
  if (!storage) return {};
328
328
  if (!runAdapter) return {};
329
+ var wrappedClient = supercompat({
330
+ client: client
331
+ });
329
332
  var result = storage({
330
- runAdapter: partob(runAdapter, {
331
- client: client
332
- })
333
+ runAdapter: _object_spread_props(_object_spread({}, runAdapter), {
334
+ handleRun: partob(runAdapter.handleRun, {
335
+ client: wrappedClient
336
+ })
337
+ }),
338
+ client: wrappedClient
333
339
  });
334
340
  return result.requestHandlers;
335
341
  };
@@ -3342,179 +3348,106 @@ var toolCallsData = function(param) {
3342
3348
  return newToolCalls;
3343
3349
  };
3344
3350
  var completionsRunAdapter = function() {
3345
- return /*#__PURE__*/ function() {
3346
- var _ref = _async_to_generator(function(param) {
3347
- 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;
3348
- return _ts_generator(this, function(_state) {
3349
- switch(_state.label){
3350
- case 0:
3351
- clientAdapter = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
3352
- if (run3.status !== "queued") return [
3353
- 2
3354
- ];
3355
- client = supercompat({
3356
- client: clientAdapter
3357
- });
3358
- onEvent2({
3359
- event: "thread.run.in_progress",
3360
- data: _object_spread_props(_object_spread({}, run3), {
3361
- status: "in_progress"
3362
- })
3363
- });
3364
- _tmp = {};
3365
- return [
3366
- 4,
3367
- messages({
3368
- run: run3,
3369
- getMessages: getMessages2
3370
- })
3371
- ];
3372
- case 1:
3373
- opts = _object_spread.apply(void 0, [
3374
- (_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
3375
- isEmpty2(run3.tools) ? {} : {
3376
- tools: run3.tools
3377
- }
3378
- ]);
3379
- _state.label = 2;
3380
- case 2:
3381
- _state.trys.push([
3382
- 2,
3383
- 4,
3384
- ,
3385
- 5
3386
- ]);
3387
- return [
3388
- 4,
3389
- client.chat.completions.create(opts)
3390
- ];
3391
- case 3:
3392
- providerResponse = _state.sent();
3393
- return [
3394
- 3,
3395
- 5
3396
- ];
3397
- case 4:
3398
- e = _state.sent();
3399
- console.error(e);
3400
- return [
3401
- 2,
3351
+ return {
3352
+ handleRun: /*#__PURE__*/ function() {
3353
+ var _ref = _async_to_generator(function(param) {
3354
+ 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;
3355
+ return _ts_generator(this, function(_state) {
3356
+ switch(_state.label){
3357
+ case 0:
3358
+ client = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
3359
+ if (run3.status !== "queued") return [
3360
+ 2
3361
+ ];
3402
3362
  onEvent2({
3403
- event: "thread.run.failed",
3363
+ event: "thread.run.in_progress",
3404
3364
  data: _object_spread_props(_object_spread({}, run3), {
3405
- failed_at: dayjs().unix(),
3406
- status: "in_progress",
3407
- last_error: {
3408
- code: "server_error",
3409
- 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 : "")
3410
- }
3411
- })
3412
- })
3413
- ];
3414
- case 5:
3415
- return [
3416
- 4,
3417
- onEvent2({
3418
- event: "thread.message.created",
3419
- data: {
3420
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3421
- object: "thread.message",
3422
- completed_at: null,
3423
- run_id: run3.id,
3424
- created_at: dayjs().unix(),
3425
- assistant_id: run3.assistant_id,
3426
- incomplete_at: null,
3427
- incomplete_details: null,
3428
- metadata: {},
3429
- attachments: [],
3430
- thread_id: run3.thread_id,
3431
- content: [
3432
- {
3433
- text: {
3434
- value: "",
3435
- annotations: []
3436
- },
3437
- type: "text"
3438
- }
3439
- ],
3440
- role: "assistant",
3441
3365
  status: "in_progress"
3366
+ })
3367
+ });
3368
+ _tmp = {};
3369
+ return [
3370
+ 4,
3371
+ messages({
3372
+ run: run3,
3373
+ getMessages: getMessages2
3374
+ })
3375
+ ];
3376
+ case 1:
3377
+ opts = _object_spread.apply(void 0, [
3378
+ (_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
3379
+ isEmpty2(run3.tools) ? {} : {
3380
+ tools: run3.tools
3442
3381
  }
3443
- })
3444
- ];
3445
- case 6:
3446
- message = _state.sent();
3447
- onEvent2({
3448
- event: "thread.run.step.created",
3449
- data: {
3450
- id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3451
- object: "thread.run.step",
3452
- run_id: run3.id,
3453
- assistant_id: run3.assistant_id,
3454
- thread_id: run3.thread_id,
3455
- type: "message_creation",
3456
- status: "completed",
3457
- completed_at: dayjs().unix(),
3458
- created_at: dayjs().unix(),
3459
- expired_at: null,
3460
- last_error: null,
3461
- metadata: {},
3462
- failed_at: null,
3463
- cancelled_at: null,
3464
- usage: null,
3465
- step_details: {
3466
- type: "message_creation",
3467
- message_creation: {
3468
- message_id: message.id
3382
+ ]);
3383
+ _state.label = 2;
3384
+ case 2:
3385
+ _state.trys.push([
3386
+ 2,
3387
+ 4,
3388
+ ,
3389
+ 5
3390
+ ]);
3391
+ return [
3392
+ 4,
3393
+ client.chat.completions.create(opts)
3394
+ ];
3395
+ case 3:
3396
+ providerResponse = _state.sent();
3397
+ return [
3398
+ 3,
3399
+ 5
3400
+ ];
3401
+ case 4:
3402
+ e = _state.sent();
3403
+ console.error(e);
3404
+ return [
3405
+ 2,
3406
+ onEvent2({
3407
+ event: "thread.run.failed",
3408
+ data: _object_spread_props(_object_spread({}, run3), {
3409
+ failed_at: dayjs().unix(),
3410
+ status: "in_progress",
3411
+ last_error: {
3412
+ code: "server_error",
3413
+ 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 : "")
3414
+ }
3415
+ })
3416
+ })
3417
+ ];
3418
+ case 5:
3419
+ return [
3420
+ 4,
3421
+ onEvent2({
3422
+ event: "thread.message.created",
3423
+ data: {
3424
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3425
+ object: "thread.message",
3426
+ completed_at: null,
3427
+ run_id: run3.id,
3428
+ created_at: dayjs().unix(),
3429
+ assistant_id: run3.assistant_id,
3430
+ incomplete_at: null,
3431
+ incomplete_details: null,
3432
+ metadata: {},
3433
+ attachments: [],
3434
+ thread_id: run3.thread_id,
3435
+ content: [
3436
+ {
3437
+ text: {
3438
+ value: "",
3439
+ annotations: []
3440
+ },
3441
+ type: "text"
3442
+ }
3443
+ ],
3444
+ role: "assistant",
3445
+ status: "in_progress"
3469
3446
  }
3470
- }
3471
- }
3472
- });
3473
- currentContent = "";
3474
- _iteratorAbruptCompletion = false, _didIteratorError = false;
3475
- _state.label = 7;
3476
- case 7:
3477
- _state.trys.push([
3478
- 7,
3479
- 15,
3480
- 16,
3481
- 21
3482
- ]);
3483
- _iterator = _async_iterator(providerResponse);
3484
- _state.label = 8;
3485
- case 8:
3486
- return [
3487
- 4,
3488
- _iterator.next()
3489
- ];
3490
- case 9:
3491
- if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
3492
- 3,
3493
- 14
3494
- ];
3495
- _value = _step.value;
3496
- chunk = _value;
3497
- choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
3498
- choice = choices[0];
3499
- if (!choice) return [
3500
- 3,
3501
- 13
3502
- ];
3503
- delta = choice.delta;
3504
- if (delta.content) {
3505
- ;
3506
- currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
3507
- }
3508
- if (!delta.tool_calls) return [
3509
- 3,
3510
- 12
3511
- ];
3512
- if (!!toolCallsRunStep) return [
3513
- 3,
3514
- 11
3515
- ];
3516
- return [
3517
- 4,
3447
+ })
3448
+ ];
3449
+ case 6:
3450
+ message = _state.sent();
3518
3451
  onEvent2({
3519
3452
  event: "thread.run.step.created",
3520
3453
  data: {
@@ -3523,9 +3456,9 @@ var completionsRunAdapter = function() {
3523
3456
  run_id: run3.id,
3524
3457
  assistant_id: run3.assistant_id,
3525
3458
  thread_id: run3.thread_id,
3526
- type: "tool_calls",
3527
- status: "in_progress",
3528
- completed_at: null,
3459
+ type: "message_creation",
3460
+ status: "completed",
3461
+ completed_at: dayjs().unix(),
3529
3462
  created_at: dayjs().unix(),
3530
3463
  expired_at: null,
3531
3464
  last_error: null,
@@ -3534,170 +3467,242 @@ var completionsRunAdapter = function() {
3534
3467
  cancelled_at: null,
3535
3468
  usage: null,
3536
3469
  step_details: {
3537
- type: "tool_calls",
3538
- tool_calls: []
3470
+ type: "message_creation",
3471
+ message_creation: {
3472
+ message_id: message.id
3473
+ }
3539
3474
  }
3540
3475
  }
3541
- })
3542
- ];
3543
- case 10:
3544
- toolCallsRunStep = _state.sent();
3545
- _state.label = 11;
3546
- case 11:
3547
- onEvent2({
3548
- event: "thread.run.step.delta",
3549
- data: {
3550
- object: "thread.run.step.delta",
3551
- run_id: run3.id,
3552
- id: toolCallsRunStep.id,
3553
- delta: {
3554
- step_details: {
3476
+ });
3477
+ currentContent = "";
3478
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
3479
+ _state.label = 7;
3480
+ case 7:
3481
+ _state.trys.push([
3482
+ 7,
3483
+ 15,
3484
+ 16,
3485
+ 21
3486
+ ]);
3487
+ _iterator = _async_iterator(providerResponse);
3488
+ _state.label = 8;
3489
+ case 8:
3490
+ return [
3491
+ 4,
3492
+ _iterator.next()
3493
+ ];
3494
+ case 9:
3495
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
3496
+ 3,
3497
+ 14
3498
+ ];
3499
+ _value = _step.value;
3500
+ chunk = _value;
3501
+ choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
3502
+ choice = choices[0];
3503
+ if (!choice) return [
3504
+ 3,
3505
+ 13
3506
+ ];
3507
+ delta = choice.delta;
3508
+ if (delta.content) {
3509
+ ;
3510
+ currentContent = "".concat(currentContent).concat((_delta_content = delta.content) !== null && _delta_content !== void 0 ? _delta_content : "");
3511
+ }
3512
+ if (!delta.tool_calls) return [
3513
+ 3,
3514
+ 12
3515
+ ];
3516
+ if (!!toolCallsRunStep) return [
3517
+ 3,
3518
+ 11
3519
+ ];
3520
+ return [
3521
+ 4,
3522
+ onEvent2({
3523
+ event: "thread.run.step.created",
3524
+ data: {
3525
+ id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
3526
+ object: "thread.run.step",
3527
+ run_id: run3.id,
3528
+ assistant_id: run3.assistant_id,
3529
+ thread_id: run3.thread_id,
3555
3530
  type: "tool_calls",
3556
- tool_calls: delta.tool_calls.map(function(tc) {
3557
- return _object_spread({
3558
- id: uid2(24),
3559
- type: "function"
3560
- }, tc);
3561
- })
3531
+ status: "in_progress",
3532
+ completed_at: null,
3533
+ created_at: dayjs().unix(),
3534
+ expired_at: null,
3535
+ last_error: null,
3536
+ metadata: {},
3537
+ failed_at: null,
3538
+ cancelled_at: null,
3539
+ usage: null,
3540
+ step_details: {
3541
+ type: "tool_calls",
3542
+ tool_calls: []
3543
+ }
3562
3544
  }
3563
- }
3564
- }
3565
- });
3566
- currentToolCalls = toolCallsData({
3567
- prevToolCalls: currentToolCalls,
3568
- delta: delta
3569
- });
3570
- _state.label = 12;
3571
- case 12:
3572
- if (delta.content) {
3545
+ })
3546
+ ];
3547
+ case 10:
3548
+ toolCallsRunStep = _state.sent();
3549
+ _state.label = 11;
3550
+ case 11:
3573
3551
  onEvent2({
3574
- event: "thread.message.delta",
3552
+ event: "thread.run.step.delta",
3575
3553
  data: {
3576
- id: message.id,
3554
+ object: "thread.run.step.delta",
3555
+ run_id: run3.id,
3556
+ id: toolCallsRunStep.id,
3577
3557
  delta: {
3578
- content: [
3579
- {
3580
- type: "text",
3581
- index: 0,
3582
- text: {
3583
- value: delta.content
3584
- }
3585
- }
3586
- ]
3558
+ step_details: {
3559
+ type: "tool_calls",
3560
+ tool_calls: delta.tool_calls.map(function(tc) {
3561
+ return _object_spread({
3562
+ id: uid2(24),
3563
+ type: "function"
3564
+ }, tc);
3565
+ })
3566
+ }
3587
3567
  }
3588
3568
  }
3589
3569
  });
3590
- }
3591
- _state.label = 13;
3592
- case 13:
3593
- _iteratorAbruptCompletion = false;
3594
- return [
3595
- 3,
3596
- 8
3597
- ];
3598
- case 14:
3599
- return [
3600
- 3,
3601
- 21
3602
- ];
3603
- case 15:
3604
- err = _state.sent();
3605
- _didIteratorError = true;
3606
- _iteratorError = err;
3607
- return [
3608
- 3,
3609
- 21
3610
- ];
3611
- case 16:
3612
- _state.trys.push([
3613
- 16,
3614
- ,
3615
- 19,
3616
- 20
3617
- ]);
3618
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
3619
- 3,
3620
- 18
3621
- ];
3622
- return [
3623
- 4,
3624
- _iterator.return()
3625
- ];
3626
- case 17:
3627
- _state.sent();
3628
- _state.label = 18;
3629
- case 18:
3630
- return [
3631
- 3,
3632
- 20
3633
- ];
3634
- case 19:
3635
- if (_didIteratorError) {
3636
- throw _iteratorError;
3637
- }
3638
- return [
3639
- 7
3640
- ];
3641
- case 20:
3642
- return [
3643
- 7
3644
- ];
3645
- case 21:
3646
- return [
3647
- 4,
3648
- onEvent2({
3649
- event: "thread.message.completed",
3650
- data: _object_spread_props(_object_spread({}, message), {
3651
- status: "completed",
3652
- content: [
3653
- {
3654
- text: {
3655
- value: currentContent,
3656
- annotations: []
3657
- },
3658
- type: "text"
3570
+ currentToolCalls = toolCallsData({
3571
+ prevToolCalls: currentToolCalls,
3572
+ delta: delta
3573
+ });
3574
+ _state.label = 12;
3575
+ case 12:
3576
+ if (delta.content) {
3577
+ onEvent2({
3578
+ event: "thread.message.delta",
3579
+ data: {
3580
+ id: message.id,
3581
+ delta: {
3582
+ content: [
3583
+ {
3584
+ type: "text",
3585
+ index: 0,
3586
+ text: {
3587
+ value: delta.content
3588
+ }
3589
+ }
3590
+ ]
3659
3591
  }
3660
- ],
3661
- tool_calls: currentToolCalls
3662
- })
3663
- })
3664
- ];
3665
- case 22:
3666
- message = _state.sent();
3667
- if (isEmpty2(message.toolCalls)) {
3592
+ }
3593
+ });
3594
+ }
3595
+ _state.label = 13;
3596
+ case 13:
3597
+ _iteratorAbruptCompletion = false;
3668
3598
  return [
3669
- 2,
3599
+ 3,
3600
+ 8
3601
+ ];
3602
+ case 14:
3603
+ return [
3604
+ 3,
3605
+ 21
3606
+ ];
3607
+ case 15:
3608
+ err = _state.sent();
3609
+ _didIteratorError = true;
3610
+ _iteratorError = err;
3611
+ return [
3612
+ 3,
3613
+ 21
3614
+ ];
3615
+ case 16:
3616
+ _state.trys.push([
3617
+ 16,
3618
+ ,
3619
+ 19,
3620
+ 20
3621
+ ]);
3622
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
3623
+ 3,
3624
+ 18
3625
+ ];
3626
+ return [
3627
+ 4,
3628
+ _iterator.return()
3629
+ ];
3630
+ case 17:
3631
+ _state.sent();
3632
+ _state.label = 18;
3633
+ case 18:
3634
+ return [
3635
+ 3,
3636
+ 20
3637
+ ];
3638
+ case 19:
3639
+ if (_didIteratorError) {
3640
+ throw _iteratorError;
3641
+ }
3642
+ return [
3643
+ 7
3644
+ ];
3645
+ case 20:
3646
+ return [
3647
+ 7
3648
+ ];
3649
+ case 21:
3650
+ return [
3651
+ 4,
3670
3652
  onEvent2({
3671
- event: "thread.run.completed",
3672
- data: _object_spread_props(_object_spread({}, run3), {
3653
+ event: "thread.message.completed",
3654
+ data: _object_spread_props(_object_spread({}, message), {
3673
3655
  status: "completed",
3674
- completed_at: dayjs().unix()
3656
+ content: [
3657
+ {
3658
+ text: {
3659
+ value: currentContent,
3660
+ annotations: []
3661
+ },
3662
+ type: "text"
3663
+ }
3664
+ ],
3665
+ tool_calls: currentToolCalls
3675
3666
  })
3676
3667
  })
3677
3668
  ];
3678
- }
3679
- return [
3680
- 2,
3681
- onEvent2({
3682
- event: "thread.run.requires_action",
3683
- data: _object_spread_props(_object_spread({}, run3), {
3684
- status: "requires_action",
3685
- required_action: {
3686
- type: "submit_tool_outputs",
3687
- submit_tool_outputs: {
3688
- tool_calls: message.toolCalls
3669
+ case 22:
3670
+ message = _state.sent();
3671
+ if (isEmpty2(message.toolCalls)) {
3672
+ return [
3673
+ 2,
3674
+ onEvent2({
3675
+ event: "thread.run.completed",
3676
+ data: _object_spread_props(_object_spread({}, run3), {
3677
+ status: "completed",
3678
+ completed_at: dayjs().unix()
3679
+ })
3680
+ })
3681
+ ];
3682
+ }
3683
+ return [
3684
+ 2,
3685
+ onEvent2({
3686
+ event: "thread.run.requires_action",
3687
+ data: _object_spread_props(_object_spread({}, run3), {
3688
+ status: "requires_action",
3689
+ required_action: {
3690
+ type: "submit_tool_outputs",
3691
+ submit_tool_outputs: {
3692
+ tool_calls: message.toolCalls
3693
+ }
3689
3694
  }
3690
- }
3695
+ })
3691
3696
  })
3692
- })
3693
- ];
3694
- }
3697
+ ];
3698
+ }
3699
+ });
3695
3700
  });
3696
- });
3697
- return function(_) {
3698
- return _ref.apply(this, arguments);
3699
- };
3700
- }();
3701
+ return function(_) {
3702
+ return _ref.apply(this, arguments);
3703
+ };
3704
+ }()
3705
+ };
3701
3706
  };
3702
3707
  // src/lib/messages/messagesRegexp.ts
3703
3708
  var messagesRegexp = "^/(?:v1|/?openai)/threads/([^/]+)/messages$";
@@ -4518,7 +4523,7 @@ var post12 = function(param) {
4518
4523
  ]);
4519
4524
  return [
4520
4525
  4,
4521
- runAdapter({
4526
+ runAdapter.handleRun({
4522
4527
  run: data,
4523
4528
  onEvent: onEvent({
4524
4529
  controller: _object_spread_props(_object_spread({}, controller), {
@@ -4967,7 +4972,7 @@ var post13 = function(param) {
4967
4972
  run3 = _state.sent();
4968
4973
  return [
4969
4974
  4,
4970
- runAdapter({
4975
+ runAdapter.handleRun({
4971
4976
  run: serializeRun({
4972
4977
  run: run3
4973
4978
  }),
@@ -5027,7 +5032,7 @@ var post13 = function(param) {
5027
5032
  case 0:
5028
5033
  return [
5029
5034
  4,
5030
- runAdapter({
5035
+ runAdapter.handleRun({
5031
5036
  run: serializeRun({
5032
5037
  run: run3
5033
5038
  }),
@@ -5198,7 +5203,7 @@ var serializeThread2 = function(param) {
5198
5203
  };
5199
5204
  // src/adapters/storage/responsesStorageAdapter/threads/post.ts
5200
5205
  var post15 = function(param) {
5201
- var openai = param.openai;
5206
+ var client = param.client;
5202
5207
  return /*#__PURE__*/ function() {
5203
5208
  var _ref = _async_to_generator(function(urlString, options) {
5204
5209
  var body, messages4, metadata, conversation;
@@ -5210,7 +5215,7 @@ var post15 = function(param) {
5210
5215
  metadata = body.metadata || {};
5211
5216
  return [
5212
5217
  4,
5213
- openai.conversations.create({
5218
+ client.conversations.create({
5214
5219
  metadata: metadata,
5215
5220
  items: messages4.map(function(message) {
5216
5221
  return {
@@ -5249,10 +5254,10 @@ var post15 = function(param) {
5249
5254
  };
5250
5255
  // src/adapters/storage/responsesStorageAdapter/threads/index.ts
5251
5256
  var threads2 = function(param) {
5252
- var openai = param.openai;
5257
+ var client = param.client;
5253
5258
  return {
5254
5259
  post: post15({
5255
- openai: openai
5260
+ client: client
5256
5261
  })
5257
5262
  };
5258
5263
  };
@@ -5263,34 +5268,71 @@ import { isArray as isArray3 } from "radash";
5263
5268
  import { uid as uid3 } from "radash";
5264
5269
  var serializeContent2 = function(param) {
5265
5270
  var item = param.item;
5266
- if (item.type !== "message") return [];
5267
- return item.content.map(function(contentBlock) {
5268
- if (contentBlock.type === "input_text") {
5269
- return {
5270
- type: "text",
5271
- text: {
5272
- value: contentBlock.text,
5273
- annotations: []
5274
- }
5275
- };
5276
- } else if (contentBlock.type === "output_text") {
5277
- return {
5278
- type: "text",
5279
- text: {
5280
- value: contentBlock.text,
5281
- annotations: []
5271
+ if (item.type === "message") {
5272
+ return item.content.map(function(contentBlock) {
5273
+ if (contentBlock.type === "input_text") {
5274
+ return {
5275
+ type: "text",
5276
+ text: {
5277
+ value: contentBlock.text,
5278
+ annotations: []
5279
+ }
5280
+ };
5281
+ } else if (contentBlock.type === "output_text") {
5282
+ return {
5283
+ type: "text",
5284
+ text: {
5285
+ value: contentBlock.text,
5286
+ annotations: []
5287
+ }
5288
+ };
5289
+ } else if (contentBlock.type === "input_image") {
5290
+ return {
5291
+ type: "image_file",
5292
+ image_file: {
5293
+ file_id: contentBlock.file_id,
5294
+ detail: "auto"
5295
+ }
5296
+ };
5297
+ }
5298
+ return null;
5299
+ }).filter(Boolean);
5300
+ } else if (item.type === "image_generation_call") {
5301
+ if (!item.result) return [];
5302
+ return [
5303
+ {
5304
+ type: "image_url",
5305
+ image_url: {
5306
+ url: "data:image/".concat(item.output_format, ";base64,").concat(item.result),
5307
+ detail: "auto"
5282
5308
  }
5283
- };
5284
- }
5285
- return null;
5286
- }).filter(Boolean);
5309
+ }
5310
+ ];
5311
+ } else {
5312
+ return [];
5313
+ }
5287
5314
  };
5288
5315
  var serializeAttachments = function(param) {
5289
5316
  var item = param.item;
5290
- return [];
5317
+ if (item.type !== "message") return [];
5318
+ var inputFiles = item.content.filter(function(contentBlock) {
5319
+ return contentBlock.type === "input_file" && contentBlock.file_id;
5320
+ });
5321
+ return inputFiles.map(function(inputFile) {
5322
+ return {
5323
+ file_id: inputFile.file_id
5324
+ };
5325
+ });
5291
5326
  };
5292
5327
  var serializeMetadata = function(param) {
5293
5328
  var item = param.item;
5329
+ if (item.type === "image_generation_call") {
5330
+ return {
5331
+ item: JSON.stringify(_object_spread_props(_object_spread({}, item), {
5332
+ result: "truncated"
5333
+ }))
5334
+ };
5335
+ }
5294
5336
  return {
5295
5337
  item: JSON.stringify(item)
5296
5338
  };
@@ -5321,8 +5363,7 @@ var serializeItemAsMessage = function(param) {
5321
5363
  };
5322
5364
  };
5323
5365
  // src/adapters/storage/responsesStorageAdapter/threads/messages/post.ts
5324
- import { uid as uid4 } from "radash";
5325
- var messageContentBlocks2 = function(param) {
5366
+ var contentBlocksFromContent = function(param) {
5326
5367
  var content = param.content;
5327
5368
  if (isArray3(content)) {
5328
5369
  return content.map(function(item) {
@@ -5361,40 +5402,65 @@ var messageContentBlocks2 = function(param) {
5361
5402
  }
5362
5403
  ];
5363
5404
  };
5405
+ var contentBlocksFromAttachments = function(param) {
5406
+ var attachments = param.attachments;
5407
+ return attachments.map(function(attachment) {
5408
+ return {
5409
+ type: "input_file",
5410
+ file_id: attachment.file_id
5411
+ };
5412
+ });
5413
+ };
5414
+ var messageContentBlocks2 = function(param) {
5415
+ var content = param.content, attachments = param.attachments;
5416
+ return _to_consumable_array(contentBlocksFromContent({
5417
+ content: content
5418
+ })).concat(_to_consumable_array(contentBlocksFromAttachments({
5419
+ attachments: attachments
5420
+ })));
5421
+ };
5364
5422
  var post16 = function(param) {
5365
- var openai = param.openai, openaiAssistant = param.openaiAssistant, createResponseItems = param.createResponseItems;
5423
+ var runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
5366
5424
  return /*#__PURE__*/ function() {
5367
5425
  var _ref = _async_to_generator(function(urlString, options) {
5368
- var url, _url_pathname_match, threadId, body, role, content, metadata, item;
5426
+ var url, _url_pathname_match, threadId, body, role, content, _body_attachments, attachments, item, openaiAssistant;
5369
5427
  return _ts_generator(this, function(_state) {
5370
- url = new URL(urlString);
5371
- _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
5372
- body = JSON.parse(options.body);
5373
- role = body.role, content = body.content, metadata = body.metadata;
5374
- item = {
5375
- id: "msg_".concat(uid4(24)),
5376
- status: "in_progress",
5377
- type: "message",
5378
- role: role,
5379
- content: messageContentBlocks2({
5380
- content: content
5381
- })
5382
- };
5383
- createResponseItems.push(item);
5384
- return [
5385
- 2,
5386
- new Response(JSON.stringify(serializeItemAsMessage({
5387
- item: item,
5388
- threadId: threadId,
5389
- openaiAssistant: openaiAssistant,
5390
- createdAt: dayjs10().unix()
5391
- })), {
5392
- status: 200,
5393
- headers: {
5394
- "Content-Type": "application/json"
5395
- }
5396
- })
5397
- ];
5428
+ switch(_state.label){
5429
+ case 0:
5430
+ url = new URL(urlString);
5431
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
5432
+ body = JSON.parse(options.body);
5433
+ role = body.role, content = body.content, _body_attachments = body.attachments, attachments = _body_attachments === void 0 ? [] : _body_attachments;
5434
+ item = {
5435
+ type: "message",
5436
+ role: role,
5437
+ content: messageContentBlocks2({
5438
+ content: content,
5439
+ attachments: attachments
5440
+ })
5441
+ };
5442
+ createResponseItems.push(item);
5443
+ return [
5444
+ 4,
5445
+ runAdapter.getOpenaiAssistant()
5446
+ ];
5447
+ case 1:
5448
+ openaiAssistant = _state.sent();
5449
+ return [
5450
+ 2,
5451
+ new Response(JSON.stringify(serializeItemAsMessage({
5452
+ item: item,
5453
+ threadId: threadId,
5454
+ openaiAssistant: openaiAssistant,
5455
+ createdAt: dayjs10().unix()
5456
+ })), {
5457
+ status: 200,
5458
+ headers: {
5459
+ "Content-Type": "application/json"
5460
+ }
5461
+ })
5462
+ ];
5463
+ }
5398
5464
  });
5399
5465
  });
5400
5466
  return function(urlString, options) {
@@ -5442,10 +5508,10 @@ function responseId(param) {
5442
5508
  }
5443
5509
  // src/adapters/storage/responsesStorageAdapter/threads/messages/get.ts
5444
5510
  var get14 = function(param) {
5445
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
5511
+ var client = param.client, runAdapter = param.runAdapter;
5446
5512
  return /*#__PURE__*/ function() {
5447
5513
  var _ref = _async_to_generator(function(urlString) {
5448
- var url, _url_pathname_match, threadId, _assign7, limit, order, after, conversation, sortOrder, items, itemsWithRunIds, responseMap, timestampedItems;
5514
+ var url, _url_pathname_match, threadId, _assign7, limit, order, after, conversation, sortOrder, items, itemsWithRunIds, responseMap, timestampedItems, openaiAssistant;
5449
5515
  return _ts_generator(this, function(_state) {
5450
5516
  switch(_state.label){
5451
5517
  case 0:
@@ -5457,14 +5523,14 @@ var get14 = function(param) {
5457
5523
  }, Object.fromEntries(url.searchParams)), limit = _assign7.limit, order = _assign7.order, after = _assign7.after;
5458
5524
  return [
5459
5525
  4,
5460
- openai.conversations.retrieve(threadId)
5526
+ client.conversations.retrieve(threadId)
5461
5527
  ];
5462
5528
  case 1:
5463
5529
  conversation = _state.sent();
5464
5530
  sortOrder = order === "asc" ? "asc" : "desc";
5465
5531
  return [
5466
5532
  4,
5467
- openai.conversations.items.list(threadId, {
5533
+ client.conversations.items.list(threadId, {
5468
5534
  limit: parseInt(limit, 10),
5469
5535
  after: after,
5470
5536
  order: sortOrder
@@ -5479,7 +5545,7 @@ var get14 = function(param) {
5479
5545
  return [
5480
5546
  4,
5481
5547
  fetchResponsesForItems({
5482
- openai: openai,
5548
+ client: client,
5483
5549
  items: itemsWithRunIds
5484
5550
  })
5485
5551
  ];
@@ -5491,6 +5557,12 @@ var get14 = function(param) {
5491
5557
  sortOrder: sortOrder,
5492
5558
  conversationCreatedAt: conversation.created_at
5493
5559
  });
5560
+ return [
5561
+ 4,
5562
+ runAdapter.getOpenaiAssistant()
5563
+ ];
5564
+ case 4:
5565
+ openaiAssistant = _state.sent();
5494
5566
  return [
5495
5567
  2,
5496
5568
  new Response(JSON.stringify({
@@ -5535,11 +5607,11 @@ var mapItemsWithRunIds = function(param) {
5535
5607
  };
5536
5608
  var fetchResponsesForItems = /*#__PURE__*/ function() {
5537
5609
  var _ref = _async_to_generator(function(param) {
5538
- var openai, items, responseIds, results, map;
5610
+ var client, items, responseIds, results, map;
5539
5611
  return _ts_generator(this, function(_state) {
5540
5612
  switch(_state.label){
5541
5613
  case 0:
5542
- openai = param.openai, items = param.items;
5614
+ client = param.client, items = param.items;
5543
5615
  responseIds = Array.from(new Set(items.map(function(param) {
5544
5616
  var runId = param.runId;
5545
5617
  return runId;
@@ -5549,7 +5621,7 @@ var fetchResponsesForItems = /*#__PURE__*/ function() {
5549
5621
  return [
5550
5622
  4,
5551
5623
  Promise.allSettled(responseIds.map(function(id) {
5552
- return openai.responses.retrieve(id);
5624
+ return client.responses.retrieve(id);
5553
5625
  }))
5554
5626
  ];
5555
5627
  case 1:
@@ -5647,34 +5719,23 @@ var assignTimestamps = function(param) {
5647
5719
  };
5648
5720
  // src/adapters/storage/responsesStorageAdapter/threads/messages/index.ts
5649
5721
  var messages3 = function(param) {
5650
- var openai = param.openai, openaiAssistant = param.openaiAssistant, createResponseItems = param.createResponseItems;
5722
+ var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
5651
5723
  return {
5652
5724
  post: post16({
5653
- openai: openai,
5654
- openaiAssistant: openaiAssistant,
5725
+ runAdapter: runAdapter,
5655
5726
  createResponseItems: createResponseItems
5656
5727
  }),
5657
5728
  get: get14({
5658
- openai: openai,
5659
- openaiAssistant: openaiAssistant
5729
+ client: client,
5730
+ runAdapter: runAdapter
5660
5731
  })
5661
5732
  };
5662
5733
  };
5663
5734
  // src/adapters/storage/responsesStorageAdapter/threads/runs/get.ts
5664
- import { assign as assign8 } from "radash";
5665
- var get15 = function(param) {
5666
- var prisma = param.prisma;
5735
+ var get15 = function() {
5667
5736
  return /*#__PURE__*/ function() {
5668
5737
  var _ref = _async_to_generator(function(urlString) {
5669
- var url, _url_pathname_match, threadId, _assign8, limit, order, after, pageSize;
5670
5738
  return _ts_generator(this, function(_state) {
5671
- url = new URL(urlString);
5672
- _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
5673
- _assign8 = assign8({
5674
- limit: "20",
5675
- order: "desc"
5676
- }, Object.fromEntries(url.searchParams)), limit = _assign8.limit, order = _assign8.order, after = _assign8.after;
5677
- pageSize = parseInt(limit, 10);
5678
5739
  return [
5679
5740
  2,
5680
5741
  new Response(JSON.stringify({
@@ -5696,9 +5757,9 @@ var get15 = function(param) {
5696
5757
  }();
5697
5758
  };
5698
5759
  // src/adapters/storage/responsesStorageAdapter/threads/runs/post.ts
5699
- import { uid as uid5 } from "radash";
5760
+ import { uid as uid4 } from "radash";
5700
5761
  import dayjs11 from "dayjs";
5701
- import { assign as assign9 } from "radash";
5762
+ import { assign as assign8 } from "radash";
5702
5763
  // src/lib/responses/serializeResponseAsRun.ts
5703
5764
  var serializeStatus = function(param) {
5704
5765
  var response = param.response;
@@ -5926,9 +5987,9 @@ function tryPackPairs(param) {
5926
5987
  itemIds: _to_consumable_array(e.itemIds)
5927
5988
  };
5928
5989
  });
5929
- var last6 = next[next.length - 1];
5930
- if (last6 && last6.responseId === responseId2) {
5931
- last6.itemIds.push(itemId);
5990
+ var last5 = next[next.length - 1];
5991
+ if (last5 && last5.responseId === responseId2) {
5992
+ last5.itemIds.push(itemId);
5932
5993
  } else {
5933
5994
  next.push({
5934
5995
  responseId: responseId2,
@@ -6036,14 +6097,14 @@ function saveResponseItemsToConversationMetadata(_) {
6036
6097
  }
6037
6098
  function _saveResponseItemsToConversationMetadata() {
6038
6099
  _saveResponseItemsToConversationMetadata = _async_to_generator(function(param) {
6039
- var openai, threadId, responseId2, itemIds, conversation, updated;
6100
+ var client, threadId, responseId2, itemIds, conversation, updated;
6040
6101
  return _ts_generator(this, function(_state) {
6041
6102
  switch(_state.label){
6042
6103
  case 0:
6043
- openai = param.openai, threadId = param.threadId, responseId2 = param.responseId, itemIds = param.itemIds;
6104
+ client = param.client, threadId = param.threadId, responseId2 = param.responseId, itemIds = param.itemIds;
6044
6105
  return [
6045
6106
  4,
6046
- openai.conversations.retrieve(threadId)
6107
+ client.conversations.retrieve(threadId)
6047
6108
  ];
6048
6109
  case 1:
6049
6110
  conversation = _state.sent();
@@ -6054,7 +6115,7 @@ function _saveResponseItemsToConversationMetadata() {
6054
6115
  });
6055
6116
  return [
6056
6117
  4,
6057
- openai.conversations.update(threadId, {
6118
+ client.conversations.update(threadId, {
6058
6119
  metadata: updated
6059
6120
  })
6060
6121
  ];
@@ -6092,11 +6153,11 @@ var defaultAssistant = {
6092
6153
  }
6093
6154
  };
6094
6155
  var post17 = function(param) {
6095
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6156
+ var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6096
6157
  return /*#__PURE__*/ function() {
6097
6158
  var _ref = _async_to_generator(function(urlString, options) {
6098
- var url, _url_pathname_match, threadId, body, assistant_id, stream, _assign9, model, instructions, // additional_instructions,
6099
- tools, metadata, response_format, truncation_strategy, response, readableStream, _response_output, itemIds, data;
6159
+ var url, _url_pathname_match, threadId, body, assistant_id, stream, _assign8, model, instructions, // additional_instructions,
6160
+ tools, metadata, response_format, truncation_strategy, _tmp, response, readableStream, _response_output, itemIds, data;
6100
6161
  return _ts_generator(this, function(_state) {
6101
6162
  switch(_state.label){
6102
6163
  case 0:
@@ -6104,10 +6165,24 @@ var post17 = function(param) {
6104
6165
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
6105
6166
  body = JSON.parse(options.body);
6106
6167
  assistant_id = body.assistant_id, stream = body.stream;
6107
- _assign9 = assign9(_object_spread({}, defaultAssistant, openaiAssistant), body), model = _assign9.model, instructions = _assign9.instructions, tools = _assign9.tools, metadata = _assign9.metadata, response_format = _assign9.response_format, truncation_strategy = _assign9.truncation_strategy;
6168
+ _tmp = [
6169
+ {},
6170
+ defaultAssistant
6171
+ ];
6172
+ return [
6173
+ 4,
6174
+ runAdapter.getOpenaiAssistant()
6175
+ ];
6176
+ case 1:
6177
+ _assign8 = assign8.apply(void 0, [
6178
+ _object_spread.apply(void 0, _tmp.concat([
6179
+ _state.sent()
6180
+ ])),
6181
+ body
6182
+ ]), model = _assign8.model, instructions = _assign8.instructions, tools = _assign8.tools, metadata = _assign8.metadata, response_format = _assign8.response_format, truncation_strategy = _assign8.truncation_strategy;
6108
6183
  return [
6109
6184
  4,
6110
- openai.responses.create(_object_spread_props(_object_spread({
6185
+ client.responses.create(_object_spread_props(_object_spread({
6111
6186
  conversation: threadId,
6112
6187
  instructions: instructions,
6113
6188
  model: model,
@@ -6123,7 +6198,7 @@ var post17 = function(param) {
6123
6198
  input: createResponseItems
6124
6199
  }))
6125
6200
  ];
6126
- case 1:
6201
+ case 2:
6127
6202
  response = _state.sent();
6128
6203
  readableStream = new ReadableStream({
6129
6204
  start: function start(controller) {
@@ -6140,7 +6215,7 @@ var post17 = function(param) {
6140
6215
  ]);
6141
6216
  return [
6142
6217
  4,
6143
- runAdapter({
6218
+ runAdapter.handleRun({
6144
6219
  threadId: threadId,
6145
6220
  response: response,
6146
6221
  onEvent: /*#__PURE__*/ function() {
@@ -6170,7 +6245,7 @@ var post17 = function(param) {
6170
6245
  event = {
6171
6246
  event: "thread.run.failed",
6172
6247
  data: {
6173
- id: uid5(24),
6248
+ id: uid4(24),
6174
6249
  failed_at: dayjs11().unix(),
6175
6250
  last_error: {
6176
6251
  code: "server_error",
@@ -6195,7 +6270,7 @@ var post17 = function(param) {
6195
6270
  });
6196
6271
  if (!stream) return [
6197
6272
  3,
6198
- 2
6273
+ 3
6199
6274
  ];
6200
6275
  return [
6201
6276
  2,
@@ -6205,7 +6280,7 @@ var post17 = function(param) {
6205
6280
  }
6206
6281
  })
6207
6282
  ];
6208
- case 2:
6283
+ case 3:
6209
6284
  itemIds = ((_response_output = response.output) !== null && _response_output !== void 0 ? _response_output : []).filter(function(o) {
6210
6285
  return o.id;
6211
6286
  }).map(function(o) {
@@ -6213,21 +6288,21 @@ var post17 = function(param) {
6213
6288
  });
6214
6289
  if (!(itemIds.length > 0)) return [
6215
6290
  3,
6216
- 4
6291
+ 5
6217
6292
  ];
6218
6293
  return [
6219
6294
  4,
6220
6295
  saveResponseItemsToConversationMetadata({
6221
- openai: openai,
6296
+ client: client,
6222
6297
  threadId: threadId,
6223
6298
  responseId: response.id,
6224
6299
  itemIds: itemIds
6225
6300
  })
6226
6301
  ];
6227
- case 3:
6228
- _state.sent();
6229
- _state.label = 4;
6230
6302
  case 4:
6303
+ _state.sent();
6304
+ _state.label = 5;
6305
+ case 5:
6231
6306
  data = serializeResponseAsRun({
6232
6307
  response: response,
6233
6308
  assistantId: assistant_id
@@ -6241,7 +6316,7 @@ var post17 = function(param) {
6241
6316
  }
6242
6317
  })
6243
6318
  ];
6244
- case 5:
6319
+ case 6:
6245
6320
  return [
6246
6321
  2
6247
6322
  ];
@@ -6255,14 +6330,11 @@ var post17 = function(param) {
6255
6330
  };
6256
6331
  // src/adapters/storage/responsesStorageAdapter/threads/runs/index.ts
6257
6332
  var runs2 = function(param) {
6258
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6333
+ var client = param.client, runAdapter = param.runAdapter, createResponseItems = param.createResponseItems;
6259
6334
  return {
6260
- get: get15({
6261
- openai: openai
6262
- }),
6335
+ get: get15(),
6263
6336
  post: post17({
6264
- openai: openai,
6265
- openaiAssistant: openaiAssistant,
6337
+ client: client,
6266
6338
  createResponseItems: createResponseItems,
6267
6339
  runAdapter: runAdapter
6268
6340
  })
@@ -6270,10 +6342,10 @@ var runs2 = function(param) {
6270
6342
  };
6271
6343
  // src/adapters/storage/responsesStorageAdapter/threads/run/get.ts
6272
6344
  var get16 = function(param) {
6273
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
6345
+ var client = param.client, runAdapter = param.runAdapter;
6274
6346
  return /*#__PURE__*/ function() {
6275
6347
  var _ref = _async_to_generator(function(urlString) {
6276
- var url, _url_pathname_match, _threadId, runId, response, data;
6348
+ var url, _url_pathname_match, _threadId, runId, response, data, _tmp;
6277
6349
  return _ts_generator(this, function(_state) {
6278
6350
  switch(_state.label){
6279
6351
  case 0:
@@ -6281,14 +6353,21 @@ var get16 = function(param) {
6281
6353
  _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runRegexp)), 3), _threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
6282
6354
  return [
6283
6355
  4,
6284
- openai.responses.retrieve(runId)
6356
+ client.responses.retrieve(runId)
6285
6357
  ];
6286
6358
  case 1:
6287
6359
  response = _state.sent();
6288
- data = serializeResponseAsRun({
6289
- response: response,
6290
- assistantId: openaiAssistant.id
6291
- });
6360
+ _tmp = {
6361
+ response: response
6362
+ };
6363
+ return [
6364
+ 4,
6365
+ runAdapter.getOpenaiAssistant()
6366
+ ];
6367
+ case 2:
6368
+ data = serializeResponseAsRun.apply(void 0, [
6369
+ (_tmp.assistantId = _state.sent().id, _tmp)
6370
+ ]);
6292
6371
  return [
6293
6372
  2,
6294
6373
  new Response(JSON.stringify(data), {
@@ -6309,11 +6388,11 @@ var get16 = function(param) {
6309
6388
  };
6310
6389
  // src/adapters/storage/responsesStorageAdapter/threads/run/index.ts
6311
6390
  var run2 = function(param) {
6312
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter;
6391
+ var client = param.client, runAdapter = param.runAdapter;
6313
6392
  return {
6314
6393
  get: get16({
6315
- openai: openai,
6316
- openaiAssistant: openaiAssistant
6394
+ client: client,
6395
+ runAdapter: runAdapter
6317
6396
  })
6318
6397
  };
6319
6398
  };
@@ -6608,13 +6687,13 @@ function _pMap() {
6608
6687
  }
6609
6688
  var pMapSkip = Symbol("skip");
6610
6689
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
6611
- import { last as last5 } from "radash";
6690
+ import { last as last4 } from "radash";
6612
6691
  // src/lib/items/serializeItemAsRunStep.ts
6613
6692
  import dayjs12 from "dayjs";
6614
- import { uid as uid6 } from "radash";
6693
+ import { uid as uid5 } from "radash";
6615
6694
  function serializeItemAsRunStep(param) {
6616
- var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat(uid6(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs12().unix() : _param_completedAt;
6617
- var itemId = typeof item.id === "string" ? item.id : "item_".concat(uid6(18));
6695
+ var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat(uid5(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs12().unix() : _param_completedAt;
6696
+ var itemId = typeof item.id === "string" ? item.id : "item_".concat(uid5(18));
6618
6697
  var base = {
6619
6698
  id: itemId,
6620
6699
  object: "thread.run.step",
@@ -6670,6 +6749,22 @@ function serializeItemAsRunStep(param) {
6670
6749
  }
6671
6750
  });
6672
6751
  }
6752
+ if (item.type === "image_generation_call") {
6753
+ return _object_spread_props(_object_spread({}, base), {
6754
+ type: "message_creation",
6755
+ step_details: {
6756
+ type: "message_creation",
6757
+ message_creation: {
6758
+ message_id: itemId
6759
+ }
6760
+ },
6761
+ metadata: {
6762
+ item: JSON.stringify(_object_spread_props(_object_spread({}, item), {
6763
+ result: "truncated"
6764
+ }))
6765
+ }
6766
+ });
6767
+ }
6673
6768
  return _object_spread_props(_object_spread({}, base), {
6674
6769
  type: "message_creation",
6675
6770
  step_details: {
@@ -6683,99 +6778,429 @@ function serializeItemAsRunStep(param) {
6683
6778
  }
6684
6779
  });
6685
6780
  }
6686
- // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
6687
- var get17 = function(param) {
6688
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
6689
- return /*#__PURE__*/ function() {
6690
- var _ref = _async_to_generator(function(urlString) {
6691
- var _last5, url, _url_pathname_match, threadId, runId, response, functionCalls, functionCallOutputsResponses, functionCallOutputs, nonFcItems, data, _last5_id;
6692
- return _ts_generator(this, function(_state) {
6693
- switch(_state.label){
6694
- case 0:
6695
- url = new URL(urlString);
6696
- _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
6697
- return [
6698
- 4,
6699
- openai.responses.retrieve(runId)
6700
- ];
6701
- case 1:
6702
- response = _state.sent();
6703
- functionCalls = response.output.filter(function(item) {
6704
- return item.type === "function_call";
6705
- });
6706
- return [
6707
- 4,
6708
- pMap(functionCalls, /*#__PURE__*/ function() {
6709
- var _ref = _async_to_generator(function(functionCall) {
6710
- var items;
6711
- return _ts_generator(this, function(_state) {
6712
- switch(_state.label){
6713
- case 0:
6714
- return [
6715
- 4,
6716
- openai.conversations.items.list(threadId, {
6717
- after: functionCall.id,
6718
- order: "asc"
6719
- })
6720
- ];
6721
- case 1:
6722
- items = _state.sent();
6723
- return [
6724
- 2,
6725
- items.data.find(function(item) {
6726
- return item.type === "function_call_output" && item.call_id === functionCall.call_id;
6727
- })
6728
- ];
6729
- }
6730
- });
6731
- });
6732
- return function(functionCall) {
6733
- return _ref.apply(this, arguments);
6734
- };
6735
- }())
6736
- ];
6737
- case 2:
6738
- functionCallOutputsResponses = _state.sent();
6739
- functionCallOutputs = functionCallOutputsResponses.filter(Boolean);
6740
- nonFcItems = response.output.filter(function(item) {
6741
- return item.type !== "function_call";
6742
- });
6743
- data = response.output.flatMap(function(item) {
6744
- var step = serializeItemAsRunStep({
6745
- item: item,
6746
- items: functionCallOutputs,
6747
- threadId: threadId,
6748
- openaiAssistant: openaiAssistant,
6749
- runId: response.id
6750
- });
6751
- if (item.type === "function_call") {
6752
- var synthCreation = {
6753
- id: "mc".concat(item.id),
6754
- run_id: response.id,
6755
- status: "completed",
6756
- completed_at: step.created_at,
6757
- step_details: {
6758
- type: "message_creation",
6759
- message_creation: {
6760
- message_id: item.id
6761
- }
6762
- }
6763
- };
6764
- return [
6765
- synthCreation,
6766
- step
6767
- ];
6768
- }
6769
- return [
6770
- step
6771
- ];
6781
+ // src/lib/items/serializeItemAsImageGenerationRunStep.ts
6782
+ import dayjs13 from "dayjs";
6783
+ var serializeStatus2 = function(param) {
6784
+ var item = param.item;
6785
+ if (item.status === "generating") {
6786
+ return "in_progress";
6787
+ }
6788
+ return item.status;
6789
+ };
6790
+ var serializeItemAsImageGenerationRunStep = function(param) {
6791
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs13().unix() : _param_completedAt;
6792
+ var toolCall = {
6793
+ id: "ftc".concat(item.id),
6794
+ type: "function",
6795
+ function: {
6796
+ name: "image_generation",
6797
+ arguments: "{}",
6798
+ output: JSON.stringify({
6799
+ status: item.status,
6800
+ background: item.background,
6801
+ output_format: item.output_format,
6802
+ quality: item.quality,
6803
+ result: item.result,
6804
+ size: item.size,
6805
+ revised_prompt: item.revised_prompt
6806
+ })
6807
+ }
6808
+ };
6809
+ return {
6810
+ id: "fc".concat(item.id),
6811
+ object: "thread.run.step",
6812
+ created_at: dayjs13().unix(),
6813
+ assistant_id: openaiAssistant.id,
6814
+ thread_id: threadId,
6815
+ run_id: runId,
6816
+ status: serializeStatus2({
6817
+ item: item
6818
+ }),
6819
+ last_error: null,
6820
+ expired_at: null,
6821
+ cancelled_at: null,
6822
+ failed_at: null,
6823
+ completed_at: completedAt,
6824
+ metadata: {},
6825
+ usage: null,
6826
+ type: "tool_calls",
6827
+ step_details: {
6828
+ type: "tool_calls",
6829
+ tool_calls: [
6830
+ toolCall
6831
+ ]
6832
+ }
6833
+ };
6834
+ };
6835
+ // src/lib/items/serializeItemAsWebSearchRunStep.ts
6836
+ import dayjs14 from "dayjs";
6837
+ var serializeStatus3 = function(param) {
6838
+ var item = param.item;
6839
+ if (item.status === "searching") {
6840
+ return "in_progress";
6841
+ }
6842
+ return item.status;
6843
+ };
6844
+ var serializeItemAsWebSearchRunStep = function(param) {
6845
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs14().unix() : _param_completedAt;
6846
+ var toolCall = {
6847
+ id: "ftc".concat(item.id),
6848
+ type: "function",
6849
+ function: {
6850
+ name: "web_search",
6851
+ arguments: JSON.stringify({
6852
+ action: item.action
6853
+ }),
6854
+ output: JSON.stringify({
6855
+ status: item.status
6856
+ })
6857
+ }
6858
+ };
6859
+ return {
6860
+ id: "fc".concat(item.id),
6861
+ object: "thread.run.step",
6862
+ created_at: dayjs14().unix(),
6863
+ assistant_id: openaiAssistant.id,
6864
+ thread_id: threadId,
6865
+ run_id: runId,
6866
+ status: serializeStatus3({
6867
+ item: item
6868
+ }),
6869
+ last_error: null,
6870
+ expired_at: null,
6871
+ cancelled_at: null,
6872
+ failed_at: null,
6873
+ completed_at: completedAt,
6874
+ metadata: {},
6875
+ usage: null,
6876
+ type: "tool_calls",
6877
+ step_details: {
6878
+ type: "tool_calls",
6879
+ tool_calls: [
6880
+ toolCall
6881
+ ]
6882
+ }
6883
+ };
6884
+ };
6885
+ // src/lib/items/serializeItemAsMcpListToolsRunStep.ts
6886
+ import dayjs15 from "dayjs";
6887
+ var serializeStatus4 = function(param) {
6888
+ var item = param.item;
6889
+ if (item.error) {
6890
+ return "failed";
6891
+ }
6892
+ return "completed";
6893
+ };
6894
+ var serializeItemAsMcpListToolsRunStep = function(param) {
6895
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs15().unix() : _param_completedAt;
6896
+ var toolCall = {
6897
+ id: "ftc".concat(item.id),
6898
+ type: "function",
6899
+ function: {
6900
+ name: "mcp_list_tools",
6901
+ arguments: JSON.stringify({
6902
+ server_label: item.server_label
6903
+ }),
6904
+ output: JSON.stringify(_object_spread({
6905
+ tools: item.tools
6906
+ }, item.error && {
6907
+ error: item.error
6908
+ }))
6909
+ }
6910
+ };
6911
+ return {
6912
+ id: "fc".concat(item.id),
6913
+ object: "thread.run.step",
6914
+ created_at: dayjs15().unix(),
6915
+ assistant_id: openaiAssistant.id,
6916
+ thread_id: threadId,
6917
+ run_id: runId,
6918
+ status: serializeStatus4({
6919
+ item: item
6920
+ }),
6921
+ last_error: null,
6922
+ expired_at: null,
6923
+ cancelled_at: null,
6924
+ failed_at: null,
6925
+ completed_at: completedAt,
6926
+ metadata: {},
6927
+ usage: null,
6928
+ type: "tool_calls",
6929
+ step_details: {
6930
+ type: "tool_calls",
6931
+ tool_calls: [
6932
+ toolCall
6933
+ ]
6934
+ }
6935
+ };
6936
+ };
6937
+ // src/lib/items/serializeItemAsMcpCallRunStep.ts
6938
+ import dayjs16 from "dayjs";
6939
+ var serializeStatus5 = function(param) {
6940
+ var item = param.item;
6941
+ if (item.error) {
6942
+ return "failed";
6943
+ }
6944
+ return "completed";
6945
+ };
6946
+ var serializeItemAsMcpCallRunStep = function(param) {
6947
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs16().unix() : _param_completedAt;
6948
+ var _item_output, _ref;
6949
+ var toolCall = {
6950
+ id: "ftc".concat(item.id),
6951
+ type: "function",
6952
+ function: {
6953
+ name: item.name,
6954
+ arguments: item.arguments,
6955
+ server_label: item.server_label,
6956
+ output: (_ref = (_item_output = item.output) !== null && _item_output !== void 0 ? _item_output : item.error) !== null && _ref !== void 0 ? _ref : null
6957
+ }
6958
+ };
6959
+ return {
6960
+ id: "fc".concat(item.id),
6961
+ object: "thread.run.step",
6962
+ created_at: dayjs16().unix(),
6963
+ assistant_id: openaiAssistant.id,
6964
+ thread_id: threadId,
6965
+ run_id: runId,
6966
+ status: serializeStatus5({
6967
+ item: item
6968
+ }),
6969
+ last_error: item.error ? {
6970
+ code: "server_error",
6971
+ message: item.error
6972
+ } : null,
6973
+ expired_at: null,
6974
+ cancelled_at: null,
6975
+ failed_at: item.error ? dayjs16().unix() : null,
6976
+ completed_at: item.error ? null : completedAt,
6977
+ metadata: {},
6978
+ usage: null,
6979
+ type: "tool_calls",
6980
+ step_details: {
6981
+ type: "tool_calls",
6982
+ tool_calls: [
6983
+ toolCall
6984
+ ]
6985
+ }
6986
+ };
6987
+ };
6988
+ // src/lib/items/serializeItemAsCodeInterpreterCallRunStep.ts
6989
+ import dayjs17 from "dayjs";
6990
+ var serializeStatus6 = function(param) {
6991
+ var item = param.item;
6992
+ if (item.status === "incomplete") {
6993
+ return "in_progress";
6994
+ } else if (item.status === "interpreting") {
6995
+ return "in_progress";
6996
+ }
6997
+ return item.status;
6998
+ };
6999
+ var serializeOutput = function(param) {
7000
+ var output = param.output;
7001
+ return {
7002
+ type: output.type,
7003
+ logs: output.logs
7004
+ };
7005
+ };
7006
+ var serializeOutputs = function(param) {
7007
+ var item = param.item;
7008
+ if (!item.outputs) return [];
7009
+ return item.outputs.filter(function(o) {
7010
+ return o.type === "logs";
7011
+ }).map(function(output) {
7012
+ return serializeOutput({
7013
+ output: output
7014
+ });
7015
+ });
7016
+ };
7017
+ var serializeItemAsCodeInterpreterCallRunStep = function(param) {
7018
+ var item = param.item, openaiAssistant = param.openaiAssistant, threadId = param.threadId, runId = param.runId, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? dayjs17().unix() : _param_completedAt;
7019
+ var _item_code;
7020
+ var toolCall = {
7021
+ id: "citc".concat(item.id),
7022
+ type: "code_interpreter",
7023
+ code_interpreter: {
7024
+ input: (_item_code = item.code) !== null && _item_code !== void 0 ? _item_code : "",
7025
+ outputs: serializeOutputs({
7026
+ item: item
7027
+ })
7028
+ }
7029
+ };
7030
+ return {
7031
+ id: "fc".concat(item.id),
7032
+ object: "thread.run.step",
7033
+ created_at: dayjs17().unix(),
7034
+ assistant_id: openaiAssistant.id,
7035
+ thread_id: threadId,
7036
+ run_id: runId,
7037
+ status: serializeStatus6({
7038
+ item: item
7039
+ }),
7040
+ last_error: null,
7041
+ expired_at: null,
7042
+ cancelled_at: null,
7043
+ failed_at: null,
7044
+ completed_at: completedAt,
7045
+ metadata: {
7046
+ item: JSON.stringify(item)
7047
+ },
7048
+ usage: null,
7049
+ type: "tool_calls",
7050
+ step_details: {
7051
+ type: "tool_calls",
7052
+ tool_calls: [
7053
+ toolCall
7054
+ ]
7055
+ }
7056
+ };
7057
+ };
7058
+ // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
7059
+ var get17 = function(param) {
7060
+ var client = param.client, runAdapter = param.runAdapter;
7061
+ return /*#__PURE__*/ function() {
7062
+ var _ref = _async_to_generator(function(urlString) {
7063
+ var _last4, url, _url_pathname_match, threadId, runId, response, functionCalls, functionCallOutputsResponses, functionCallOutputs, openaiAssistant, data, _last4_id;
7064
+ return _ts_generator(this, function(_state) {
7065
+ switch(_state.label){
7066
+ case 0:
7067
+ url = new URL(urlString);
7068
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
7069
+ return [
7070
+ 4,
7071
+ client.responses.retrieve(runId)
7072
+ ];
7073
+ case 1:
7074
+ response = _state.sent();
7075
+ functionCalls = response.output.filter(function(item) {
7076
+ return item.type === "function_call";
7077
+ });
7078
+ return [
7079
+ 4,
7080
+ pMap(functionCalls, /*#__PURE__*/ function() {
7081
+ var _ref = _async_to_generator(function(functionCall) {
7082
+ var items;
7083
+ return _ts_generator(this, function(_state) {
7084
+ switch(_state.label){
7085
+ case 0:
7086
+ return [
7087
+ 4,
7088
+ client.conversations.items.list(threadId, {
7089
+ after: functionCall.id,
7090
+ order: "asc"
7091
+ })
7092
+ ];
7093
+ case 1:
7094
+ items = _state.sent();
7095
+ return [
7096
+ 2,
7097
+ items.data.find(function(item) {
7098
+ return item.type === "function_call_output" && item.call_id === functionCall.call_id;
7099
+ })
7100
+ ];
7101
+ }
7102
+ });
7103
+ });
7104
+ return function(functionCall) {
7105
+ return _ref.apply(this, arguments);
7106
+ };
7107
+ }())
7108
+ ];
7109
+ case 2:
7110
+ functionCallOutputsResponses = _state.sent();
7111
+ functionCallOutputs = functionCallOutputsResponses.filter(Boolean);
7112
+ return [
7113
+ 4,
7114
+ runAdapter.getOpenaiAssistant()
7115
+ ];
7116
+ case 3:
7117
+ openaiAssistant = _state.sent();
7118
+ data = response.output.flatMap(function(item) {
7119
+ var step = serializeItemAsRunStep({
7120
+ item: item,
7121
+ items: functionCallOutputs,
7122
+ threadId: threadId,
7123
+ openaiAssistant: openaiAssistant,
7124
+ runId: response.id
7125
+ });
7126
+ if (item.type === "function_call") {
7127
+ var synthCreation = {
7128
+ id: "mc".concat(item.id),
7129
+ run_id: response.id,
7130
+ status: "completed",
7131
+ completed_at: step.created_at,
7132
+ step_details: {
7133
+ type: "message_creation",
7134
+ message_creation: {
7135
+ message_id: item.id
7136
+ }
7137
+ }
7138
+ };
7139
+ return [
7140
+ synthCreation,
7141
+ step
7142
+ ];
7143
+ } else if (item.type === "image_generation_call") {
7144
+ return [
7145
+ serializeItemAsImageGenerationRunStep({
7146
+ item: item,
7147
+ openaiAssistant: openaiAssistant,
7148
+ threadId: threadId,
7149
+ runId: response.id
7150
+ }),
7151
+ step
7152
+ ];
7153
+ } else if (item.type === "web_search_call") {
7154
+ return [
7155
+ serializeItemAsWebSearchRunStep({
7156
+ item: item,
7157
+ openaiAssistant: openaiAssistant,
7158
+ threadId: threadId,
7159
+ runId: response.id
7160
+ }),
7161
+ step
7162
+ ];
7163
+ } else if (item.type === "mcp_list_tools") {
7164
+ return [
7165
+ serializeItemAsMcpListToolsRunStep({
7166
+ item: item,
7167
+ openaiAssistant: openaiAssistant,
7168
+ threadId: threadId,
7169
+ runId: response.id
7170
+ }),
7171
+ step
7172
+ ];
7173
+ } else if (item.type === "mcp_call") {
7174
+ return [
7175
+ serializeItemAsMcpCallRunStep({
7176
+ item: item,
7177
+ openaiAssistant: openaiAssistant,
7178
+ threadId: threadId,
7179
+ runId: response.id
7180
+ }),
7181
+ step
7182
+ ];
7183
+ } else if (item.type === "code_interpreter_call") {
7184
+ return [
7185
+ serializeItemAsCodeInterpreterCallRunStep({
7186
+ item: item,
7187
+ openaiAssistant: openaiAssistant,
7188
+ threadId: threadId,
7189
+ runId: response.id
7190
+ }),
7191
+ step
7192
+ ];
7193
+ }
7194
+ return [
7195
+ step
7196
+ ];
6772
7197
  });
6773
7198
  return [
6774
7199
  2,
6775
7200
  new Response(JSON.stringify({
6776
7201
  data: data,
6777
7202
  has_more: false,
6778
- last_id: (_last5_id = (_last5 = last5(response.output)) === null || _last5 === void 0 ? void 0 : _last5.id) !== null && _last5_id !== void 0 ? _last5_id : null
7203
+ last_id: (_last4_id = (_last4 = last4(response.output)) === null || _last4 === void 0 ? void 0 : _last4.id) !== null && _last4_id !== void 0 ? _last4_id : null
6779
7204
  }), {
6780
7205
  status: 200,
6781
7206
  headers: {
@@ -6793,11 +7218,11 @@ var get17 = function(param) {
6793
7218
  };
6794
7219
  // src/adapters/storage/responsesStorageAdapter/threads/runs/steps/index.ts
6795
7220
  var steps2 = function(param) {
6796
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7221
+ var client = param.client, runAdapter = param.runAdapter;
6797
7222
  return {
6798
7223
  get: get17({
6799
- openai: openai,
6800
- openaiAssistant: openaiAssistant
7224
+ client: client,
7225
+ runAdapter: runAdapter
6801
7226
  })
6802
7227
  };
6803
7228
  };
@@ -6824,10 +7249,10 @@ var getFunctionCallOutputItems = function(param) {
6824
7249
  });
6825
7250
  };
6826
7251
  var post18 = function(param) {
6827
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter;
7252
+ var client = param.client, runAdapter = param.runAdapter;
6828
7253
  return /*#__PURE__*/ function() {
6829
7254
  var _ref = _async_to_generator(function(urlString, options) {
6830
- var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, functionCallOutputItems, previousResponse, response, readableStream;
7255
+ var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, functionCallOutputItems, previousResponse, openaiAssistant, response, readableStream;
6831
7256
  return _ts_generator(this, function(_state) {
6832
7257
  switch(_state.label){
6833
7258
  case 0:
@@ -6840,13 +7265,19 @@ var post18 = function(param) {
6840
7265
  });
6841
7266
  return [
6842
7267
  4,
6843
- openai.responses.retrieve(runId)
7268
+ client.responses.retrieve(runId)
6844
7269
  ];
6845
7270
  case 1:
6846
7271
  previousResponse = _state.sent();
6847
7272
  return [
6848
7273
  4,
6849
- openai.responses.create(_object_spread({
7274
+ runAdapter.getOpenaiAssistant()
7275
+ ];
7276
+ case 2:
7277
+ openaiAssistant = _state.sent();
7278
+ return [
7279
+ 4,
7280
+ client.responses.create(_object_spread({
6850
7281
  conversation: threadId,
6851
7282
  input: functionCallOutputItems,
6852
7283
  instructions: openaiAssistant.instructions,
@@ -6857,7 +7288,7 @@ var post18 = function(param) {
6857
7288
  tools: openaiAssistant.tools
6858
7289
  })))
6859
7290
  ];
6860
- case 2:
7291
+ case 3:
6861
7292
  response = _state.sent();
6862
7293
  readableStream = new ReadableStream({
6863
7294
  start: function start(controller) {
@@ -6885,7 +7316,7 @@ var post18 = function(param) {
6885
7316
  });
6886
7317
  return [
6887
7318
  4,
6888
- runAdapter({
7319
+ runAdapter.handleRun({
6889
7320
  threadId: threadId,
6890
7321
  response: response,
6891
7322
  onEvent: /*#__PURE__*/ function() {
@@ -6932,37 +7363,55 @@ var post18 = function(param) {
6932
7363
  };
6933
7364
  // src/adapters/storage/responsesStorageAdapter/threads/runs/submitToolOutputs/index.ts
6934
7365
  var submitToolOutputs2 = function(param) {
6935
- var openai = param.openai, openaiAssistant = param.openaiAssistant, runAdapter = param.runAdapter;
7366
+ var client = param.client, runAdapter = param.runAdapter;
6936
7367
  return {
6937
7368
  post: post18({
6938
- openai: openai,
6939
- openaiAssistant: openaiAssistant,
6940
- // @ts-ignore-next-line
7369
+ client: client,
6941
7370
  runAdapter: runAdapter
6942
7371
  })
6943
7372
  };
6944
7373
  };
6945
7374
  // src/adapters/storage/responsesStorageAdapter/assistants/get.ts
6946
7375
  var get18 = function(param) {
6947
- var openaiAssistant = param.openaiAssistant;
7376
+ var runAdapter = param.runAdapter;
6948
7377
  return /*#__PURE__*/ function() {
6949
7378
  var _ref = _async_to_generator(function(urlString) {
7379
+ var _, _1, _tmp;
6950
7380
  return _ts_generator(this, function(_state) {
6951
- return [
6952
- 2,
6953
- new Response(JSON.stringify({
6954
- data: [
6955
- openaiAssistant
6956
- ],
6957
- has_more: false,
6958
- last_id: openaiAssistant.id
6959
- }), {
6960
- status: 200,
6961
- headers: {
6962
- "Content-Type": "application/json"
6963
- }
6964
- })
6965
- ];
7381
+ switch(_state.label){
7382
+ case 0:
7383
+ _ = Response.bind;
7384
+ _1 = JSON.stringify;
7385
+ _tmp = {};
7386
+ return [
7387
+ 4,
7388
+ runAdapter.getOpenaiAssistant()
7389
+ ];
7390
+ case 1:
7391
+ _tmp.data = [
7392
+ _state.sent()
7393
+ ], _tmp.has_more = false;
7394
+ return [
7395
+ 4,
7396
+ runAdapter.getOpenaiAssistant()
7397
+ ];
7398
+ case 2:
7399
+ return [
7400
+ 2,
7401
+ new (_.apply(Response, [
7402
+ void 0,
7403
+ _1.apply(JSON, [
7404
+ (_tmp.last_id = _state.sent().id, _tmp)
7405
+ ]),
7406
+ {
7407
+ status: 200,
7408
+ headers: {
7409
+ "Content-Type": "application/json"
7410
+ }
7411
+ }
7412
+ ]))
7413
+ ];
7414
+ }
6966
7415
  });
6967
7416
  });
6968
7417
  return function(urlString) {
@@ -6971,8 +7420,7 @@ var get18 = function(param) {
6971
7420
  }();
6972
7421
  };
6973
7422
  // src/adapters/storage/responsesStorageAdapter/assistants/post.ts
6974
- var post19 = function(param) {
6975
- var _openaiAssistant = param.openaiAssistant;
7423
+ var post19 = function() {
6976
7424
  return /*#__PURE__*/ _async_to_generator(function() {
6977
7425
  return _ts_generator(this, function(_state) {
6978
7426
  return [
@@ -6994,59 +7442,52 @@ var post19 = function(param) {
6994
7442
  };
6995
7443
  // src/adapters/storage/responsesStorageAdapter/assistants/index.ts
6996
7444
  var assistants2 = function(param) {
6997
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7445
+ var runAdapter = param.runAdapter;
6998
7446
  return {
6999
7447
  get: get18({
7000
- openaiAssistant: openaiAssistant
7448
+ runAdapter: runAdapter
7001
7449
  }),
7002
- post: post19({
7003
- openaiAssistant: openaiAssistant
7004
- })
7450
+ post: post19()
7005
7451
  };
7006
7452
  };
7007
7453
  // src/adapters/storage/responsesStorageAdapter/index.ts
7008
- var responsesStorageAdapter = function(param) {
7009
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7454
+ var responsesStorageAdapter = function() {
7010
7455
  var createResponseItems = [];
7011
7456
  return function(param) {
7012
- var runAdapter = param.runAdapter;
7457
+ var runAdapter = param.runAdapter, client = param.client;
7013
7458
  var _obj;
7014
7459
  return {
7015
7460
  requestHandlers: (_obj = {
7016
7461
  "^/(?:v1|/?openai)/assistants$": assistants2({
7017
- openai: openai,
7018
- openaiAssistant: openaiAssistant
7462
+ runAdapter: runAdapter
7019
7463
  }),
7020
7464
  "^/(?:v1|/?openai)/threads$": threads2({
7021
- openai: openai
7465
+ client: client
7022
7466
  })
7023
7467
  }, _define_property(_obj, messagesRegexp, messages3({
7024
- openai: openai,
7025
- openaiAssistant: openaiAssistant,
7468
+ client: client,
7469
+ runAdapter: runAdapter,
7026
7470
  createResponseItems: createResponseItems
7027
7471
  })), _define_property(_obj, runsRegexp, runs2({
7028
- openai: openai,
7029
- openaiAssistant: openaiAssistant,
7472
+ client: client,
7030
7473
  runAdapter: runAdapter,
7031
7474
  createResponseItems: createResponseItems
7032
7475
  })), _define_property(_obj, runRegexp, run2({
7033
- openai: openai,
7034
- openaiAssistant: openaiAssistant,
7476
+ client: client,
7035
7477
  runAdapter: runAdapter
7036
7478
  })), _define_property(_obj, stepsRegexp, steps2({
7037
- openai: openai,
7038
- openaiAssistant: openaiAssistant
7479
+ client: client,
7480
+ runAdapter: runAdapter
7039
7481
  })), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs2({
7040
- openai: openai,
7041
- openaiAssistant: openaiAssistant,
7482
+ client: client,
7042
7483
  runAdapter: runAdapter
7043
7484
  })), _obj)
7044
7485
  };
7045
7486
  };
7046
7487
  };
7047
7488
  // src/adapters/run/responsesRunAdapter/index.ts
7048
- import dayjs13 from "dayjs";
7049
- import { uid as uid7 } from "radash";
7489
+ import dayjs18 from "dayjs";
7490
+ import { uid as uid6 } from "radash";
7050
7491
  var serializeToolCalls2 = function(param) {
7051
7492
  var toolCalls = param.toolCalls;
7052
7493
  return toolCalls.map(function(toolCall) {
@@ -7061,33 +7502,62 @@ var serializeToolCalls2 = function(param) {
7061
7502
  });
7062
7503
  };
7063
7504
  var responsesRunAdapter = function(param) {
7064
- var openai = param.openai, openaiAssistant = param.openaiAssistant;
7065
- return /*#__PURE__*/ function() {
7505
+ var getDirectOpenaiAssistant = param.getOpenaiAssistant;
7506
+ var cachedOpenaiAssistant = null;
7507
+ var getOpenaiAssistant = /*#__PURE__*/ function() {
7508
+ var _ref = _async_to_generator(function() {
7509
+ return _ts_generator(this, function(_state) {
7510
+ switch(_state.label){
7511
+ case 0:
7512
+ if (cachedOpenaiAssistant) return [
7513
+ 2,
7514
+ cachedOpenaiAssistant
7515
+ ];
7516
+ return [
7517
+ 4,
7518
+ getDirectOpenaiAssistant()
7519
+ ];
7520
+ case 1:
7521
+ cachedOpenaiAssistant = _state.sent();
7522
+ return [
7523
+ 2,
7524
+ cachedOpenaiAssistant
7525
+ ];
7526
+ }
7527
+ });
7528
+ });
7529
+ return function getOpenaiAssistant() {
7530
+ return _ref.apply(this, arguments);
7531
+ };
7532
+ }();
7533
+ var handleRun = /*#__PURE__*/ function() {
7066
7534
  var _ref = _async_to_generator(function(param) {
7067
- var threadId, response, onEvent2, responseCreatedResponse, toolCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, toolCalls2, toolCall, err, e;
7535
+ 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;
7068
7536
  return _ts_generator(this, function(_state) {
7069
7537
  switch(_state.label){
7070
7538
  case 0:
7071
- threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
7539
+ client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
7072
7540
  responseCreatedResponse = null;
7073
7541
  toolCalls = {};
7542
+ mcpCalls = {};
7543
+ codeInterpreterCalls = {};
7074
7544
  itemIds = [];
7075
7545
  _state.label = 1;
7076
7546
  case 1:
7077
7547
  _state.trys.push([
7078
7548
  1,
7079
- 42,
7080
- 44,
7081
- 47
7549
+ 131,
7550
+ 134,
7551
+ 137
7082
7552
  ]);
7083
7553
  _iteratorAbruptCompletion = false, _didIteratorError = false;
7084
7554
  _state.label = 2;
7085
7555
  case 2:
7086
7556
  _state.trys.push([
7087
7557
  2,
7088
- 35,
7089
- 36,
7090
- 41
7558
+ 124,
7559
+ 125,
7560
+ 130
7091
7561
  ]);
7092
7562
  _iterator = _async_iterator(response);
7093
7563
  _state.label = 3;
@@ -7099,7 +7569,7 @@ var responsesRunAdapter = function(param) {
7099
7569
  case 4:
7100
7570
  if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
7101
7571
  3,
7102
- 34
7572
+ 123
7103
7573
  ];
7104
7574
  _value = _step.value;
7105
7575
  event = _value;
@@ -7113,339 +7583,1244 @@ var responsesRunAdapter = function(param) {
7113
7583
  case "response.in_progress":
7114
7584
  return [
7115
7585
  3,
7116
- 7
7586
+ 8
7117
7587
  ];
7118
7588
  case "response.completed":
7119
7589
  return [
7120
7590
  3,
7121
- 9
7591
+ 11
7122
7592
  ];
7123
7593
  case "response.failed":
7124
7594
  return [
7125
7595
  3,
7126
- 14
7596
+ 18
7127
7597
  ];
7128
7598
  case "response.output_text.delta":
7129
7599
  return [
7130
7600
  3,
7131
- 16
7601
+ 21
7132
7602
  ];
7133
7603
  case "response.output_item.added":
7134
7604
  return [
7135
7605
  3,
7136
- 18
7606
+ 23
7137
7607
  ];
7138
7608
  case "response.output_item.done":
7139
7609
  return [
7140
7610
  3,
7141
- 24
7611
+ 67
7142
7612
  ];
7143
7613
  case "response.function_call_arguments.delta":
7144
7614
  return [
7145
7615
  3,
7146
- 30
7616
+ 111
7617
+ ];
7618
+ case "response.mcp_call_arguments.delta":
7619
+ return [
7620
+ 3,
7621
+ 113
7622
+ ];
7623
+ case "response.image_generation_call.in_progress":
7624
+ return [
7625
+ 3,
7626
+ 115
7627
+ ];
7628
+ case "response.image_generation_call.generating":
7629
+ return [
7630
+ 3,
7631
+ 115
7632
+ ];
7633
+ case "response.image_generation_call.partial_image":
7634
+ return [
7635
+ 3,
7636
+ 118
7147
7637
  ];
7148
7638
  }
7149
7639
  return [
7150
- 3,
7151
- 32
7640
+ 3,
7641
+ 121
7642
+ ];
7643
+ case 5:
7644
+ responseCreatedResponse = event.response;
7645
+ _tmp = {
7646
+ event: "thread.run.created"
7647
+ };
7648
+ _tmp1 = {
7649
+ response: event.response
7650
+ };
7651
+ return [
7652
+ 4,
7653
+ getOpenaiAssistant()
7654
+ ];
7655
+ case 6:
7656
+ return [
7657
+ 4,
7658
+ onEvent2.apply(void 0, [
7659
+ (_tmp.data = serializeResponseAsRun.apply(void 0, [
7660
+ (_tmp1.assistantId = _state.sent().id, _tmp1)
7661
+ ]), _tmp)
7662
+ ])
7663
+ ];
7664
+ case 7:
7665
+ _state.sent();
7666
+ return [
7667
+ 3,
7668
+ 122
7669
+ ];
7670
+ case 8:
7671
+ _tmp2 = {
7672
+ event: "thread.run.in_progress"
7673
+ };
7674
+ _tmp3 = {
7675
+ response: event.response
7676
+ };
7677
+ return [
7678
+ 4,
7679
+ getOpenaiAssistant()
7680
+ ];
7681
+ case 9:
7682
+ return [
7683
+ 4,
7684
+ onEvent2.apply(void 0, [
7685
+ (_tmp2.data = serializeResponseAsRun.apply(void 0, [
7686
+ (_tmp3.assistantId = _state.sent().id, _tmp3)
7687
+ ]), _tmp2)
7688
+ ])
7689
+ ];
7690
+ case 10:
7691
+ _state.sent();
7692
+ return [
7693
+ 3,
7694
+ 122
7695
+ ];
7696
+ case 11:
7697
+ itemIds = event.response.output.filter(function(o) {
7698
+ return o.id;
7699
+ }).map(function(o) {
7700
+ return o.id;
7701
+ });
7702
+ toolCalls2 = event.response.output.filter(function(o) {
7703
+ return o.type === "function_call";
7704
+ });
7705
+ if (!(toolCalls2.length > 0)) return [
7706
+ 3,
7707
+ 14
7708
+ ];
7709
+ _tmp4 = {
7710
+ event: "thread.run.requires_action"
7711
+ };
7712
+ _tmp5 = [
7713
+ {}
7714
+ ];
7715
+ _tmp6 = {
7716
+ response: event.response
7717
+ };
7718
+ return [
7719
+ 4,
7720
+ getOpenaiAssistant()
7721
+ ];
7722
+ case 12:
7723
+ return [
7724
+ 4,
7725
+ onEvent2.apply(void 0, [
7726
+ (_tmp4.data = _object_spread.apply(void 0, _tmp5.concat([
7727
+ serializeResponseAsRun.apply(void 0, [
7728
+ (_tmp6.assistantId = _state.sent().id, _tmp6)
7729
+ ]),
7730
+ {
7731
+ status: "requires_action",
7732
+ required_action: {
7733
+ type: "submit_tool_outputs",
7734
+ submit_tool_outputs: {
7735
+ tool_calls: serializeToolCalls2({
7736
+ toolCalls: toolCalls2
7737
+ })
7738
+ }
7739
+ }
7740
+ }
7741
+ ])), _tmp4)
7742
+ ])
7743
+ ];
7744
+ case 13:
7745
+ _state.sent();
7746
+ return [
7747
+ 3,
7748
+ 17
7749
+ ];
7750
+ case 14:
7751
+ _tmp7 = {
7752
+ event: "thread.run.completed"
7753
+ };
7754
+ _tmp8 = {
7755
+ response: event.response
7756
+ };
7757
+ return [
7758
+ 4,
7759
+ getOpenaiAssistant()
7760
+ ];
7761
+ case 15:
7762
+ return [
7763
+ 4,
7764
+ onEvent2.apply(void 0, [
7765
+ (_tmp7.data = serializeResponseAsRun.apply(void 0, [
7766
+ (_tmp8.assistantId = _state.sent().id, _tmp8)
7767
+ ]), _tmp7)
7768
+ ])
7769
+ ];
7770
+ case 16:
7771
+ _state.sent();
7772
+ _state.label = 17;
7773
+ case 17:
7774
+ return [
7775
+ 3,
7776
+ 122
7777
+ ];
7778
+ case 18:
7779
+ _tmp9 = {
7780
+ event: "thread.run.failed"
7781
+ };
7782
+ _tmp10 = {
7783
+ response: event.response
7784
+ };
7785
+ return [
7786
+ 4,
7787
+ getOpenaiAssistant()
7788
+ ];
7789
+ case 19:
7790
+ return [
7791
+ 4,
7792
+ onEvent2.apply(void 0, [
7793
+ (_tmp9.data = serializeResponseAsRun.apply(void 0, [
7794
+ (_tmp10.assistantId = _state.sent().id, _tmp10)
7795
+ ]), _tmp9)
7796
+ ])
7797
+ ];
7798
+ case 20:
7799
+ _state.sent();
7800
+ return [
7801
+ 3,
7802
+ 122
7803
+ ];
7804
+ case 21:
7805
+ return [
7806
+ 4,
7807
+ onEvent2({
7808
+ event: "thread.message.delta",
7809
+ data: {
7810
+ id: event.item_id,
7811
+ delta: {
7812
+ content: [
7813
+ {
7814
+ type: "text",
7815
+ index: event.content_index,
7816
+ text: {
7817
+ value: event.delta
7818
+ }
7819
+ }
7820
+ ]
7821
+ }
7822
+ }
7823
+ })
7824
+ ];
7825
+ case 22:
7826
+ _state.sent();
7827
+ return [
7828
+ 3,
7829
+ 122
7830
+ ];
7831
+ case 23:
7832
+ if (!(event.item.type === "message")) return [
7833
+ 3,
7834
+ 28
7835
+ ];
7836
+ _tmp11 = {
7837
+ event: "thread.message.created"
7838
+ };
7839
+ _tmp12 = {
7840
+ item: event.item,
7841
+ threadId: threadId
7842
+ };
7843
+ return [
7844
+ 4,
7845
+ getOpenaiAssistant()
7846
+ ];
7847
+ case 24:
7848
+ return [
7849
+ 4,
7850
+ onEvent2.apply(void 0, [
7851
+ (_tmp11.data = serializeItemAsMessage.apply(void 0, [
7852
+ (_tmp12.openaiAssistant = _state.sent(), _tmp12.createdAt = dayjs18().unix(), _tmp12.runId = responseCreatedResponse.id, _tmp12.status = "in_progress", _tmp12)
7853
+ ]), _tmp11)
7854
+ ])
7855
+ ];
7856
+ case 25:
7857
+ _state.sent();
7858
+ _tmp13 = {
7859
+ event: "thread.run.step.created"
7860
+ };
7861
+ _tmp14 = {
7862
+ item: event.item,
7863
+ items: [],
7864
+ threadId: threadId
7865
+ };
7866
+ return [
7867
+ 4,
7868
+ getOpenaiAssistant()
7869
+ ];
7870
+ case 26:
7871
+ return [
7872
+ 4,
7873
+ onEvent2.apply(void 0, [
7874
+ (_tmp13.data = serializeItemAsRunStep.apply(void 0, [
7875
+ (_tmp14.openaiAssistant = _state.sent(), _tmp14.runId = responseCreatedResponse.id, _tmp14.status = "in_progress", _tmp14.completedAt = null, _tmp14)
7876
+ ]), _tmp13)
7877
+ ])
7878
+ ];
7879
+ case 27:
7880
+ _state.sent();
7881
+ return [
7882
+ 3,
7883
+ 66
7884
+ ];
7885
+ case 28:
7886
+ if (!(event.item.type === "function_call")) return [
7887
+ 3,
7888
+ 31
7889
+ ];
7890
+ toolCalls[event.item.id] = event.item;
7891
+ _tmp15 = {
7892
+ event: "thread.run.step.created"
7893
+ };
7894
+ _tmp16 = {
7895
+ item: event.item,
7896
+ items: [],
7897
+ threadId: threadId
7898
+ };
7899
+ return [
7900
+ 4,
7901
+ getOpenaiAssistant()
7902
+ ];
7903
+ case 29:
7904
+ return [
7905
+ 4,
7906
+ onEvent2.apply(void 0, [
7907
+ (_tmp15.data = serializeItemAsRunStep.apply(void 0, [
7908
+ (_tmp16.openaiAssistant = _state.sent(), _tmp16.runId = responseCreatedResponse.id, _tmp16)
7909
+ ]), _tmp15)
7910
+ ])
7911
+ ];
7912
+ case 30:
7913
+ _state.sent();
7914
+ return [
7915
+ 3,
7916
+ 66
7917
+ ];
7918
+ case 31:
7919
+ if (!(event.item.type === "image_generation_call")) return [
7920
+ 3,
7921
+ 38
7922
+ ];
7923
+ _tmp17 = {
7924
+ event: "thread.message.created"
7925
+ };
7926
+ _tmp18 = {
7927
+ item: event.item,
7928
+ threadId: threadId
7929
+ };
7930
+ return [
7931
+ 4,
7932
+ getOpenaiAssistant()
7933
+ ];
7934
+ case 32:
7935
+ return [
7936
+ 4,
7937
+ onEvent2.apply(void 0, [
7938
+ (_tmp17.data = serializeItemAsMessage.apply(void 0, [
7939
+ (_tmp18.openaiAssistant = _state.sent(), _tmp18.createdAt = dayjs18().unix(), _tmp18.runId = responseCreatedResponse.id, _tmp18.status = "in_progress", _tmp18)
7940
+ ]), _tmp17)
7941
+ ])
7942
+ ];
7943
+ case 33:
7944
+ _state.sent();
7945
+ _tmp19 = {
7946
+ event: "thread.run.step.created"
7947
+ };
7948
+ _tmp20 = {
7949
+ item: event.item,
7950
+ items: [],
7951
+ threadId: threadId
7952
+ };
7953
+ return [
7954
+ 4,
7955
+ getOpenaiAssistant()
7956
+ ];
7957
+ case 34:
7958
+ return [
7959
+ 4,
7960
+ onEvent2.apply(void 0, [
7961
+ (_tmp19.data = serializeItemAsRunStep.apply(void 0, [
7962
+ (_tmp20.openaiAssistant = _state.sent(), _tmp20.runId = responseCreatedResponse.id, _tmp20.status = "in_progress", _tmp20.completedAt = null, _tmp20)
7963
+ ]), _tmp19)
7964
+ ])
7965
+ ];
7966
+ case 35:
7967
+ _state.sent();
7968
+ _tmp21 = {
7969
+ event: "thread.run.step.created"
7970
+ };
7971
+ _tmp22 = {
7972
+ item: event.item
7973
+ };
7974
+ return [
7975
+ 4,
7976
+ getOpenaiAssistant()
7977
+ ];
7978
+ case 36:
7979
+ return [
7980
+ 4,
7981
+ onEvent2.apply(void 0, [
7982
+ (_tmp21.data = serializeItemAsImageGenerationRunStep.apply(void 0, [
7983
+ (_tmp22.openaiAssistant = _state.sent(), _tmp22.threadId = threadId, _tmp22.runId = responseCreatedResponse.id, _tmp22.completedAt = null, _tmp22)
7984
+ ]), _tmp21)
7985
+ ])
7986
+ ];
7987
+ case 37:
7988
+ _state.sent();
7989
+ return [
7990
+ 3,
7991
+ 66
7992
+ ];
7993
+ case 38:
7994
+ if (!(event.item.type === "web_search_call")) return [
7995
+ 3,
7996
+ 45
7997
+ ];
7998
+ _tmp23 = {
7999
+ event: "thread.message.created"
8000
+ };
8001
+ _tmp24 = {
8002
+ item: event.item,
8003
+ threadId: threadId
8004
+ };
8005
+ return [
8006
+ 4,
8007
+ getOpenaiAssistant()
8008
+ ];
8009
+ case 39:
8010
+ return [
8011
+ 4,
8012
+ onEvent2.apply(void 0, [
8013
+ (_tmp23.data = serializeItemAsMessage.apply(void 0, [
8014
+ (_tmp24.openaiAssistant = _state.sent(), _tmp24.createdAt = dayjs18().unix(), _tmp24.runId = responseCreatedResponse.id, _tmp24.status = "in_progress", _tmp24)
8015
+ ]), _tmp23)
8016
+ ])
8017
+ ];
8018
+ case 40:
8019
+ _state.sent();
8020
+ _tmp25 = {
8021
+ event: "thread.run.step.created"
8022
+ };
8023
+ _tmp26 = {
8024
+ item: event.item,
8025
+ items: [],
8026
+ threadId: threadId
8027
+ };
8028
+ return [
8029
+ 4,
8030
+ getOpenaiAssistant()
8031
+ ];
8032
+ case 41:
8033
+ return [
8034
+ 4,
8035
+ onEvent2.apply(void 0, [
8036
+ (_tmp25.data = serializeItemAsRunStep.apply(void 0, [
8037
+ (_tmp26.openaiAssistant = _state.sent(), _tmp26.runId = responseCreatedResponse.id, _tmp26.status = "in_progress", _tmp26.completedAt = null, _tmp26)
8038
+ ]), _tmp25)
8039
+ ])
8040
+ ];
8041
+ case 42:
8042
+ _state.sent();
8043
+ _tmp27 = {
8044
+ event: "thread.run.step.created"
8045
+ };
8046
+ _tmp28 = {
8047
+ item: event.item
8048
+ };
8049
+ return [
8050
+ 4,
8051
+ getOpenaiAssistant()
8052
+ ];
8053
+ case 43:
8054
+ return [
8055
+ 4,
8056
+ onEvent2.apply(void 0, [
8057
+ (_tmp27.data = serializeItemAsWebSearchRunStep.apply(void 0, [
8058
+ (_tmp28.openaiAssistant = _state.sent(), _tmp28.threadId = threadId, _tmp28.runId = responseCreatedResponse.id, _tmp28.completedAt = null, _tmp28)
8059
+ ]), _tmp27)
8060
+ ])
8061
+ ];
8062
+ case 44:
8063
+ _state.sent();
8064
+ return [
8065
+ 3,
8066
+ 66
8067
+ ];
8068
+ case 45:
8069
+ if (!(event.item.type === "mcp_list_tools")) return [
8070
+ 3,
8071
+ 52
8072
+ ];
8073
+ _tmp29 = {
8074
+ event: "thread.message.created"
8075
+ };
8076
+ _tmp30 = {
8077
+ item: event.item,
8078
+ threadId: threadId
8079
+ };
8080
+ return [
8081
+ 4,
8082
+ getOpenaiAssistant()
8083
+ ];
8084
+ case 46:
8085
+ return [
8086
+ 4,
8087
+ onEvent2.apply(void 0, [
8088
+ (_tmp29.data = serializeItemAsMessage.apply(void 0, [
8089
+ (_tmp30.openaiAssistant = _state.sent(), _tmp30.createdAt = dayjs18().unix(), _tmp30.runId = responseCreatedResponse.id, _tmp30.status = "in_progress", _tmp30)
8090
+ ]), _tmp29)
8091
+ ])
8092
+ ];
8093
+ case 47:
8094
+ _state.sent();
8095
+ _tmp31 = {
8096
+ event: "thread.run.step.created"
8097
+ };
8098
+ _tmp32 = {
8099
+ item: event.item,
8100
+ items: [],
8101
+ threadId: threadId
8102
+ };
8103
+ return [
8104
+ 4,
8105
+ getOpenaiAssistant()
8106
+ ];
8107
+ case 48:
8108
+ return [
8109
+ 4,
8110
+ onEvent2.apply(void 0, [
8111
+ (_tmp31.data = serializeItemAsRunStep.apply(void 0, [
8112
+ (_tmp32.openaiAssistant = _state.sent(), _tmp32.runId = responseCreatedResponse.id, _tmp32.status = "in_progress", _tmp32.completedAt = null, _tmp32)
8113
+ ]), _tmp31)
8114
+ ])
8115
+ ];
8116
+ case 49:
8117
+ _state.sent();
8118
+ _tmp33 = {
8119
+ event: "thread.run.step.created"
8120
+ };
8121
+ _tmp34 = {
8122
+ item: event.item
8123
+ };
8124
+ return [
8125
+ 4,
8126
+ getOpenaiAssistant()
8127
+ ];
8128
+ case 50:
8129
+ return [
8130
+ 4,
8131
+ onEvent2.apply(void 0, [
8132
+ (_tmp33.data = serializeItemAsMcpListToolsRunStep.apply(void 0, [
8133
+ (_tmp34.openaiAssistant = _state.sent(), _tmp34.threadId = threadId, _tmp34.runId = responseCreatedResponse.id, _tmp34.completedAt = null, _tmp34)
8134
+ ]), _tmp33)
8135
+ ])
8136
+ ];
8137
+ case 51:
8138
+ _state.sent();
8139
+ return [
8140
+ 3,
8141
+ 66
8142
+ ];
8143
+ case 52:
8144
+ if (!(event.item.type === "mcp_call")) return [
8145
+ 3,
8146
+ 59
8147
+ ];
8148
+ mcpCalls[event.item.id] = event.item;
8149
+ _tmp35 = {
8150
+ event: "thread.message.created"
8151
+ };
8152
+ _tmp36 = {
8153
+ item: event.item,
8154
+ threadId: threadId
8155
+ };
8156
+ return [
8157
+ 4,
8158
+ getOpenaiAssistant()
8159
+ ];
8160
+ case 53:
8161
+ return [
8162
+ 4,
8163
+ onEvent2.apply(void 0, [
8164
+ (_tmp35.data = serializeItemAsMessage.apply(void 0, [
8165
+ (_tmp36.openaiAssistant = _state.sent(), _tmp36.createdAt = dayjs18().unix(), _tmp36.runId = responseCreatedResponse.id, _tmp36.status = "in_progress", _tmp36)
8166
+ ]), _tmp35)
8167
+ ])
8168
+ ];
8169
+ case 54:
8170
+ _state.sent();
8171
+ _tmp37 = {
8172
+ event: "thread.run.step.created"
8173
+ };
8174
+ _tmp38 = {
8175
+ item: event.item,
8176
+ items: [],
8177
+ threadId: threadId
8178
+ };
8179
+ return [
8180
+ 4,
8181
+ getOpenaiAssistant()
8182
+ ];
8183
+ case 55:
8184
+ return [
8185
+ 4,
8186
+ onEvent2.apply(void 0, [
8187
+ (_tmp37.data = serializeItemAsRunStep.apply(void 0, [
8188
+ (_tmp38.openaiAssistant = _state.sent(), _tmp38.runId = responseCreatedResponse.id, _tmp38.status = "in_progress", _tmp38.completedAt = null, _tmp38)
8189
+ ]), _tmp37)
8190
+ ])
8191
+ ];
8192
+ case 56:
8193
+ _state.sent();
8194
+ _tmp39 = {
8195
+ event: "thread.run.step.created"
8196
+ };
8197
+ _tmp40 = {
8198
+ item: event.item
8199
+ };
8200
+ return [
8201
+ 4,
8202
+ getOpenaiAssistant()
8203
+ ];
8204
+ case 57:
8205
+ return [
8206
+ 4,
8207
+ onEvent2.apply(void 0, [
8208
+ (_tmp39.data = serializeItemAsMcpCallRunStep.apply(void 0, [
8209
+ (_tmp40.openaiAssistant = _state.sent(), _tmp40.threadId = threadId, _tmp40.runId = responseCreatedResponse.id, _tmp40.completedAt = null, _tmp40)
8210
+ ]), _tmp39)
8211
+ ])
8212
+ ];
8213
+ case 58:
8214
+ _state.sent();
8215
+ return [
8216
+ 3,
8217
+ 66
8218
+ ];
8219
+ case 59:
8220
+ if (!(event.item.type === "code_interpreter_call")) return [
8221
+ 3,
8222
+ 66
8223
+ ];
8224
+ codeInterpreterCalls[event.item.id] = event.item;
8225
+ _tmp41 = {
8226
+ event: "thread.message.created"
8227
+ };
8228
+ _tmp42 = {
8229
+ item: event.item,
8230
+ threadId: threadId
8231
+ };
8232
+ return [
8233
+ 4,
8234
+ getOpenaiAssistant()
8235
+ ];
8236
+ case 60:
8237
+ return [
8238
+ 4,
8239
+ onEvent2.apply(void 0, [
8240
+ (_tmp41.data = serializeItemAsMessage.apply(void 0, [
8241
+ (_tmp42.openaiAssistant = _state.sent(), _tmp42.createdAt = dayjs18().unix(), _tmp42.runId = responseCreatedResponse.id, _tmp42.status = "in_progress", _tmp42)
8242
+ ]), _tmp41)
8243
+ ])
8244
+ ];
8245
+ case 61:
8246
+ _state.sent();
8247
+ _tmp43 = {
8248
+ event: "thread.run.step.created"
8249
+ };
8250
+ _tmp44 = {
8251
+ item: event.item,
8252
+ items: [],
8253
+ threadId: threadId
8254
+ };
8255
+ return [
8256
+ 4,
8257
+ getOpenaiAssistant()
8258
+ ];
8259
+ case 62:
8260
+ return [
8261
+ 4,
8262
+ onEvent2.apply(void 0, [
8263
+ (_tmp43.data = serializeItemAsRunStep.apply(void 0, [
8264
+ (_tmp44.openaiAssistant = _state.sent(), _tmp44.runId = responseCreatedResponse.id, _tmp44.status = "in_progress", _tmp44.completedAt = null, _tmp44)
8265
+ ]), _tmp43)
8266
+ ])
8267
+ ];
8268
+ case 63:
8269
+ _state.sent();
8270
+ _tmp45 = {
8271
+ event: "thread.run.step.created"
8272
+ };
8273
+ _tmp46 = {
8274
+ item: event.item
8275
+ };
8276
+ return [
8277
+ 4,
8278
+ getOpenaiAssistant()
8279
+ ];
8280
+ case 64:
8281
+ return [
8282
+ 4,
8283
+ onEvent2.apply(void 0, [
8284
+ (_tmp45.data = serializeItemAsCodeInterpreterCallRunStep.apply(void 0, [
8285
+ (_tmp46.openaiAssistant = _state.sent(), _tmp46.threadId = threadId, _tmp46.runId = responseCreatedResponse.id, _tmp46.completedAt = null, _tmp46)
8286
+ ]), _tmp45)
8287
+ ])
8288
+ ];
8289
+ case 65:
8290
+ _state.sent();
8291
+ _state.label = 66;
8292
+ case 66:
8293
+ if (event.item.id) itemIds.push(event.item.id);
8294
+ return [
8295
+ 3,
8296
+ 122
8297
+ ];
8298
+ case 67:
8299
+ if (!(event.item.type === "message")) return [
8300
+ 3,
8301
+ 72
8302
+ ];
8303
+ _tmp47 = {
8304
+ event: "thread.run.step.completed"
8305
+ };
8306
+ _tmp48 = {
8307
+ item: event.item,
8308
+ items: [],
8309
+ threadId: threadId
8310
+ };
8311
+ return [
8312
+ 4,
8313
+ getOpenaiAssistant()
8314
+ ];
8315
+ case 68:
8316
+ return [
8317
+ 4,
8318
+ onEvent2.apply(void 0, [
8319
+ (_tmp47.data = serializeItemAsRunStep.apply(void 0, [
8320
+ (_tmp48.openaiAssistant = _state.sent(), _tmp48.runId = responseCreatedResponse.id, _tmp48)
8321
+ ]), _tmp47)
8322
+ ])
8323
+ ];
8324
+ case 69:
8325
+ _state.sent();
8326
+ _tmp49 = {
8327
+ event: "thread.message.completed"
8328
+ };
8329
+ _tmp50 = {
8330
+ item: event.item,
8331
+ threadId: threadId
8332
+ };
8333
+ return [
8334
+ 4,
8335
+ getOpenaiAssistant()
8336
+ ];
8337
+ case 70:
8338
+ return [
8339
+ 4,
8340
+ onEvent2.apply(void 0, [
8341
+ (_tmp49.data = serializeItemAsMessage.apply(void 0, [
8342
+ (_tmp50.openaiAssistant = _state.sent(), _tmp50.createdAt = dayjs18().unix(), _tmp50.runId = responseCreatedResponse.id, _tmp50)
8343
+ ]), _tmp49)
8344
+ ])
8345
+ ];
8346
+ case 71:
8347
+ _state.sent();
8348
+ return [
8349
+ 3,
8350
+ 110
8351
+ ];
8352
+ case 72:
8353
+ if (!(event.item.type === "function_call")) return [
8354
+ 3,
8355
+ 75
8356
+ ];
8357
+ toolCalls[event.item.id] = event.item;
8358
+ _tmp51 = {
8359
+ event: "thread.run.step.in_progress"
8360
+ };
8361
+ _tmp52 = {
8362
+ item: event.item,
8363
+ items: [],
8364
+ threadId: threadId
8365
+ };
8366
+ return [
8367
+ 4,
8368
+ getOpenaiAssistant()
8369
+ ];
8370
+ case 73:
8371
+ return [
8372
+ 4,
8373
+ onEvent2.apply(void 0, [
8374
+ (_tmp51.data = serializeItemAsRunStep.apply(void 0, [
8375
+ (_tmp52.openaiAssistant = _state.sent(), _tmp52.runId = responseCreatedResponse.id, _tmp52)
8376
+ ]), _tmp51)
8377
+ ])
8378
+ ];
8379
+ case 74:
8380
+ _state.sent();
8381
+ return [
8382
+ 3,
8383
+ 110
8384
+ ];
8385
+ case 75:
8386
+ if (!(event.item.type === "image_generation_call")) return [
8387
+ 3,
8388
+ 82
8389
+ ];
8390
+ _tmp53 = {
8391
+ event: "thread.run.step.completed"
8392
+ };
8393
+ _tmp54 = {
8394
+ item: event.item
8395
+ };
8396
+ return [
8397
+ 4,
8398
+ getOpenaiAssistant()
8399
+ ];
8400
+ case 76:
8401
+ return [
8402
+ 4,
8403
+ onEvent2.apply(void 0, [
8404
+ (_tmp53.data = serializeItemAsImageGenerationRunStep.apply(void 0, [
8405
+ (_tmp54.openaiAssistant = _state.sent(), _tmp54.threadId = threadId, _tmp54.runId = responseCreatedResponse.id, _tmp54)
8406
+ ]), _tmp53)
8407
+ ])
8408
+ ];
8409
+ case 77:
8410
+ _state.sent();
8411
+ _tmp55 = {
8412
+ event: "thread.run.step.completed"
8413
+ };
8414
+ _tmp56 = {
8415
+ item: event.item,
8416
+ items: [],
8417
+ threadId: threadId
8418
+ };
8419
+ return [
8420
+ 4,
8421
+ getOpenaiAssistant()
8422
+ ];
8423
+ case 78:
8424
+ return [
8425
+ 4,
8426
+ onEvent2.apply(void 0, [
8427
+ (_tmp55.data = serializeItemAsRunStep.apply(void 0, [
8428
+ (_tmp56.openaiAssistant = _state.sent(), _tmp56.runId = responseCreatedResponse.id, _tmp56)
8429
+ ]), _tmp55)
8430
+ ])
8431
+ ];
8432
+ case 79:
8433
+ _state.sent();
8434
+ _tmp57 = {
8435
+ event: "thread.message.completed"
8436
+ };
8437
+ _tmp58 = {
8438
+ item: event.item,
8439
+ threadId: threadId
8440
+ };
8441
+ return [
8442
+ 4,
8443
+ getOpenaiAssistant()
8444
+ ];
8445
+ case 80:
8446
+ return [
8447
+ 4,
8448
+ onEvent2.apply(void 0, [
8449
+ (_tmp57.data = serializeItemAsMessage.apply(void 0, [
8450
+ (_tmp58.openaiAssistant = _state.sent(), _tmp58.createdAt = dayjs18().unix(), _tmp58.runId = responseCreatedResponse.id, _tmp58)
8451
+ ]), _tmp57)
8452
+ ])
8453
+ ];
8454
+ case 81:
8455
+ _state.sent();
8456
+ return [
8457
+ 3,
8458
+ 110
8459
+ ];
8460
+ case 82:
8461
+ if (!(event.item.type === "web_search_call")) return [
8462
+ 3,
8463
+ 89
8464
+ ];
8465
+ _tmp59 = {
8466
+ event: "thread.run.step.completed"
8467
+ };
8468
+ _tmp60 = {
8469
+ item: event.item
8470
+ };
8471
+ return [
8472
+ 4,
8473
+ getOpenaiAssistant()
8474
+ ];
8475
+ case 83:
8476
+ return [
8477
+ 4,
8478
+ onEvent2.apply(void 0, [
8479
+ (_tmp59.data = serializeItemAsWebSearchRunStep.apply(void 0, [
8480
+ (_tmp60.openaiAssistant = _state.sent(), _tmp60.threadId = threadId, _tmp60.runId = responseCreatedResponse.id, _tmp60)
8481
+ ]), _tmp59)
8482
+ ])
8483
+ ];
8484
+ case 84:
8485
+ _state.sent();
8486
+ _tmp61 = {
8487
+ event: "thread.run.step.completed"
8488
+ };
8489
+ _tmp62 = {
8490
+ item: event.item,
8491
+ items: [],
8492
+ threadId: threadId
8493
+ };
8494
+ return [
8495
+ 4,
8496
+ getOpenaiAssistant()
7152
8497
  ];
7153
- case 5:
7154
- responseCreatedResponse = event.response;
8498
+ case 85:
7155
8499
  return [
7156
8500
  4,
7157
- onEvent2({
7158
- event: "thread.run.created",
7159
- data: serializeResponseAsRun({
7160
- response: event.response,
7161
- assistantId: openaiAssistant.id
7162
- })
7163
- })
8501
+ onEvent2.apply(void 0, [
8502
+ (_tmp61.data = serializeItemAsRunStep.apply(void 0, [
8503
+ (_tmp62.openaiAssistant = _state.sent(), _tmp62.runId = responseCreatedResponse.id, _tmp62)
8504
+ ]), _tmp61)
8505
+ ])
7164
8506
  ];
7165
- case 6:
8507
+ case 86:
7166
8508
  _state.sent();
8509
+ _tmp63 = {
8510
+ event: "thread.message.completed"
8511
+ };
8512
+ _tmp64 = {
8513
+ item: event.item,
8514
+ threadId: threadId
8515
+ };
7167
8516
  return [
7168
- 3,
7169
- 33
8517
+ 4,
8518
+ getOpenaiAssistant()
7170
8519
  ];
7171
- case 7:
8520
+ case 87:
7172
8521
  return [
7173
8522
  4,
7174
- onEvent2({
7175
- event: "thread.run.in_progress",
7176
- data: serializeResponseAsRun({
7177
- response: event.response,
7178
- assistantId: openaiAssistant.id
7179
- })
7180
- })
8523
+ onEvent2.apply(void 0, [
8524
+ (_tmp63.data = serializeItemAsMessage.apply(void 0, [
8525
+ (_tmp64.openaiAssistant = _state.sent(), _tmp64.createdAt = dayjs18().unix(), _tmp64.runId = responseCreatedResponse.id, _tmp64)
8526
+ ]), _tmp63)
8527
+ ])
7181
8528
  ];
7182
- case 8:
8529
+ case 88:
7183
8530
  _state.sent();
7184
8531
  return [
7185
8532
  3,
7186
- 33
8533
+ 110
7187
8534
  ];
7188
- case 9:
7189
- itemIds = event.response.output.filter(function(o) {
7190
- return o.id;
7191
- }).map(function(o) {
7192
- return o.id;
7193
- });
7194
- toolCalls2 = event.response.output.filter(function(o) {
7195
- return o.type === "function_call";
7196
- });
7197
- if (!(toolCalls2.length > 0)) return [
8535
+ case 89:
8536
+ if (!(event.item.type === "mcp_list_tools")) return [
7198
8537
  3,
7199
- 11
8538
+ 96
8539
+ ];
8540
+ _tmp65 = {
8541
+ event: "thread.run.step.completed"
8542
+ };
8543
+ _tmp66 = {
8544
+ item: event.item
8545
+ };
8546
+ return [
8547
+ 4,
8548
+ getOpenaiAssistant()
7200
8549
  ];
8550
+ case 90:
7201
8551
  return [
7202
8552
  4,
7203
- onEvent2({
7204
- event: "thread.run.requires_action",
7205
- data: _object_spread({}, serializeResponseAsRun({
7206
- response: event.response,
7207
- assistantId: openaiAssistant.id
7208
- }), {
7209
- status: "requires_action",
7210
- required_action: {
7211
- type: "submit_tool_outputs",
7212
- submit_tool_outputs: {
7213
- tool_calls: serializeToolCalls2({
7214
- toolCalls: toolCalls2
7215
- })
7216
- }
7217
- }
7218
- })
7219
- })
8553
+ onEvent2.apply(void 0, [
8554
+ (_tmp65.data = serializeItemAsMcpListToolsRunStep.apply(void 0, [
8555
+ (_tmp66.openaiAssistant = _state.sent(), _tmp66.threadId = threadId, _tmp66.runId = responseCreatedResponse.id, _tmp66)
8556
+ ]), _tmp65)
8557
+ ])
7220
8558
  ];
7221
- case 10:
8559
+ case 91:
7222
8560
  _state.sent();
8561
+ _tmp67 = {
8562
+ event: "thread.run.step.completed"
8563
+ };
8564
+ _tmp68 = {
8565
+ item: event.item,
8566
+ items: [],
8567
+ threadId: threadId
8568
+ };
7223
8569
  return [
7224
- 3,
7225
- 13
8570
+ 4,
8571
+ getOpenaiAssistant()
7226
8572
  ];
7227
- case 11:
8573
+ case 92:
7228
8574
  return [
7229
8575
  4,
7230
- onEvent2({
7231
- event: "thread.run.completed",
7232
- data: serializeResponseAsRun({
7233
- response: event.response,
7234
- assistantId: openaiAssistant.id
7235
- })
7236
- })
8576
+ onEvent2.apply(void 0, [
8577
+ (_tmp67.data = serializeItemAsRunStep.apply(void 0, [
8578
+ (_tmp68.openaiAssistant = _state.sent(), _tmp68.runId = responseCreatedResponse.id, _tmp68)
8579
+ ]), _tmp67)
8580
+ ])
7237
8581
  ];
7238
- case 12:
8582
+ case 93:
7239
8583
  _state.sent();
7240
- _state.label = 13;
7241
- case 13:
8584
+ _tmp69 = {
8585
+ event: "thread.message.completed"
8586
+ };
8587
+ _tmp70 = {
8588
+ item: event.item,
8589
+ threadId: threadId
8590
+ };
7242
8591
  return [
7243
- 3,
7244
- 33
8592
+ 4,
8593
+ getOpenaiAssistant()
7245
8594
  ];
7246
- case 14:
8595
+ case 94:
7247
8596
  return [
7248
8597
  4,
7249
- onEvent2({
7250
- event: "thread.run.failed",
7251
- data: serializeResponseAsRun({
7252
- response: event.response,
7253
- assistantId: openaiAssistant.id
7254
- })
7255
- })
8598
+ onEvent2.apply(void 0, [
8599
+ (_tmp69.data = serializeItemAsMessage.apply(void 0, [
8600
+ (_tmp70.openaiAssistant = _state.sent(), _tmp70.createdAt = dayjs18().unix(), _tmp70.runId = responseCreatedResponse.id, _tmp70)
8601
+ ]), _tmp69)
8602
+ ])
7256
8603
  ];
7257
- case 15:
8604
+ case 95:
7258
8605
  _state.sent();
7259
8606
  return [
7260
8607
  3,
7261
- 33
8608
+ 110
7262
8609
  ];
7263
- case 16:
8610
+ case 96:
8611
+ if (!(event.item.type === "mcp_call")) return [
8612
+ 3,
8613
+ 103
8614
+ ];
8615
+ _tmp71 = {
8616
+ event: "thread.run.step.completed"
8617
+ };
8618
+ _tmp72 = {
8619
+ item: event.item
8620
+ };
7264
8621
  return [
7265
8622
  4,
7266
- onEvent2({
7267
- event: "thread.message.delta",
7268
- data: {
7269
- id: event.item_id,
7270
- delta: {
7271
- content: [
7272
- {
7273
- type: "text",
7274
- index: event.output_index - 1,
7275
- text: {
7276
- value: event.delta
7277
- }
7278
- }
7279
- ]
7280
- }
7281
- }
7282
- })
8623
+ getOpenaiAssistant()
7283
8624
  ];
7284
- case 17:
7285
- _state.sent();
8625
+ case 97:
7286
8626
  return [
7287
- 3,
7288
- 33
8627
+ 4,
8628
+ onEvent2.apply(void 0, [
8629
+ (_tmp71.data = serializeItemAsMcpCallRunStep.apply(void 0, [
8630
+ (_tmp72.openaiAssistant = _state.sent(), _tmp72.threadId = threadId, _tmp72.runId = responseCreatedResponse.id, _tmp72)
8631
+ ]), _tmp71)
8632
+ ])
7289
8633
  ];
7290
- case 18:
7291
- if (!(event.item.type === "message")) return [
7292
- 3,
7293
- 21
8634
+ case 98:
8635
+ _state.sent();
8636
+ _tmp73 = {
8637
+ event: "thread.run.step.completed"
8638
+ };
8639
+ _tmp74 = {
8640
+ item: event.item,
8641
+ items: [],
8642
+ threadId: threadId
8643
+ };
8644
+ return [
8645
+ 4,
8646
+ getOpenaiAssistant()
7294
8647
  ];
8648
+ case 99:
7295
8649
  return [
7296
8650
  4,
7297
- onEvent2({
7298
- event: "thread.run.step.created",
7299
- data: serializeItemAsRunStep({
7300
- item: event.item,
7301
- items: [],
7302
- threadId: threadId,
7303
- openaiAssistant: openaiAssistant,
7304
- runId: responseCreatedResponse.id,
7305
- status: "in_progress",
7306
- completedAt: null
7307
- })
7308
- })
8651
+ onEvent2.apply(void 0, [
8652
+ (_tmp73.data = serializeItemAsRunStep.apply(void 0, [
8653
+ (_tmp74.openaiAssistant = _state.sent(), _tmp74.runId = responseCreatedResponse.id, _tmp74)
8654
+ ]), _tmp73)
8655
+ ])
7309
8656
  ];
7310
- case 19:
8657
+ case 100:
7311
8658
  _state.sent();
8659
+ _tmp75 = {
8660
+ event: "thread.message.completed"
8661
+ };
8662
+ _tmp76 = {
8663
+ item: event.item,
8664
+ threadId: threadId
8665
+ };
7312
8666
  return [
7313
8667
  4,
7314
- onEvent2({
7315
- event: "thread.message.created",
7316
- data: serializeItemAsMessage({
7317
- item: event.item,
7318
- threadId: threadId,
7319
- openaiAssistant: openaiAssistant,
7320
- createdAt: dayjs13().unix(),
7321
- runId: responseCreatedResponse.id,
7322
- status: "in_progress"
7323
- })
7324
- })
8668
+ getOpenaiAssistant()
7325
8669
  ];
7326
- case 20:
8670
+ case 101:
8671
+ return [
8672
+ 4,
8673
+ onEvent2.apply(void 0, [
8674
+ (_tmp75.data = serializeItemAsMessage.apply(void 0, [
8675
+ (_tmp76.openaiAssistant = _state.sent(), _tmp76.createdAt = dayjs18().unix(), _tmp76.runId = responseCreatedResponse.id, _tmp76)
8676
+ ]), _tmp75)
8677
+ ])
8678
+ ];
8679
+ case 102:
7327
8680
  _state.sent();
7328
8681
  return [
7329
8682
  3,
7330
- 23
8683
+ 110
7331
8684
  ];
7332
- case 21:
7333
- if (!(event.item.type === "function_call")) return [
8685
+ case 103:
8686
+ if (!(event.item.type === "code_interpreter_call")) return [
7334
8687
  3,
7335
- 23
8688
+ 110
7336
8689
  ];
7337
- toolCalls[event.item.id] = event.item;
8690
+ _tmp77 = {
8691
+ event: "thread.run.step.completed"
8692
+ };
8693
+ _tmp78 = {
8694
+ item: event.item
8695
+ };
7338
8696
  return [
7339
8697
  4,
7340
- onEvent2({
7341
- event: "thread.run.step.created",
7342
- data: serializeItemAsRunStep({
7343
- item: event.item,
7344
- items: [],
7345
- threadId: threadId,
7346
- openaiAssistant: openaiAssistant,
7347
- runId: responseCreatedResponse.id
7348
- })
7349
- })
8698
+ getOpenaiAssistant()
7350
8699
  ];
7351
- case 22:
7352
- _state.sent();
7353
- _state.label = 23;
7354
- case 23:
7355
- if (event.item.id) itemIds.push(event.item.id);
8700
+ case 104:
7356
8701
  return [
7357
- 3,
7358
- 33
8702
+ 4,
8703
+ onEvent2.apply(void 0, [
8704
+ (_tmp77.data = serializeItemAsCodeInterpreterCallRunStep.apply(void 0, [
8705
+ (_tmp78.openaiAssistant = _state.sent(), _tmp78.threadId = threadId, _tmp78.runId = responseCreatedResponse.id, _tmp78)
8706
+ ]), _tmp77)
8707
+ ])
7359
8708
  ];
7360
- case 24:
7361
- if (!(event.item.type === "message")) return [
7362
- 3,
7363
- 27
8709
+ case 105:
8710
+ _state.sent();
8711
+ _tmp79 = {
8712
+ event: "thread.run.step.completed"
8713
+ };
8714
+ _tmp80 = {
8715
+ item: event.item,
8716
+ items: [],
8717
+ threadId: threadId
8718
+ };
8719
+ return [
8720
+ 4,
8721
+ getOpenaiAssistant()
7364
8722
  ];
8723
+ case 106:
7365
8724
  return [
7366
8725
  4,
7367
- onEvent2({
7368
- event: "thread.run.step.completed",
7369
- data: serializeItemAsRunStep({
7370
- item: event.item,
7371
- items: [],
7372
- threadId: threadId,
7373
- openaiAssistant: openaiAssistant,
7374
- runId: responseCreatedResponse.id
7375
- })
7376
- })
8726
+ onEvent2.apply(void 0, [
8727
+ (_tmp79.data = serializeItemAsRunStep.apply(void 0, [
8728
+ (_tmp80.openaiAssistant = _state.sent(), _tmp80.runId = responseCreatedResponse.id, _tmp80)
8729
+ ]), _tmp79)
8730
+ ])
7377
8731
  ];
7378
- case 25:
8732
+ case 107:
7379
8733
  _state.sent();
8734
+ _tmp81 = {
8735
+ event: "thread.message.completed"
8736
+ };
8737
+ _tmp82 = {
8738
+ item: event.item,
8739
+ threadId: threadId
8740
+ };
7380
8741
  return [
7381
8742
  4,
7382
- onEvent2({
7383
- event: "thread.message.completed",
7384
- data: serializeItemAsMessage({
7385
- item: event.item,
7386
- threadId: threadId,
7387
- openaiAssistant: openaiAssistant,
7388
- createdAt: dayjs13().unix(),
7389
- runId: responseCreatedResponse.id
7390
- })
7391
- })
8743
+ getOpenaiAssistant()
7392
8744
  ];
7393
- case 26:
8745
+ case 108:
8746
+ return [
8747
+ 4,
8748
+ onEvent2.apply(void 0, [
8749
+ (_tmp81.data = serializeItemAsMessage.apply(void 0, [
8750
+ (_tmp82.openaiAssistant = _state.sent(), _tmp82.createdAt = dayjs18().unix(), _tmp82.runId = responseCreatedResponse.id, _tmp82)
8751
+ ]), _tmp81)
8752
+ ])
8753
+ ];
8754
+ case 109:
7394
8755
  _state.sent();
8756
+ _state.label = 110;
8757
+ case 110:
7395
8758
  return [
7396
8759
  3,
7397
- 29
8760
+ 122
7398
8761
  ];
7399
- case 27:
7400
- if (!(event.item.type === "function_call")) return [
8762
+ case 111:
8763
+ toolCall = toolCalls[event.item_id];
8764
+ if (!toolCall) return [
7401
8765
  3,
7402
- 29
8766
+ 122
7403
8767
  ];
7404
- toolCalls[event.item.id] = event.item;
7405
8768
  return [
7406
8769
  4,
7407
8770
  onEvent2({
7408
- event: "thread.run.step.in_progress",
7409
- data: serializeItemAsRunStep({
7410
- item: event.item,
7411
- items: [],
7412
- threadId: threadId,
7413
- openaiAssistant: openaiAssistant,
7414
- runId: responseCreatedResponse.id
7415
- })
8771
+ event: "thread.run.step.delta",
8772
+ data: {
8773
+ id: event.item_id,
8774
+ object: "thread.run.step.delta",
8775
+ delta: {
8776
+ step_details: {
8777
+ type: "tool_calls",
8778
+ tool_calls: [
8779
+ {
8780
+ id: toolCall.call_id,
8781
+ type: "function",
8782
+ index: event.output_index,
8783
+ function: {
8784
+ name: toolCall.name,
8785
+ arguments: event.delta,
8786
+ output: null
8787
+ }
8788
+ }
8789
+ ]
8790
+ }
8791
+ }
8792
+ }
7416
8793
  })
7417
8794
  ];
7418
- case 28:
8795
+ case 112:
7419
8796
  _state.sent();
7420
- _state.label = 29;
7421
- case 29:
7422
8797
  return [
7423
8798
  3,
7424
- 33
8799
+ 122
7425
8800
  ];
7426
- case 30:
7427
- toolCall = toolCalls[event.item_id];
7428
- if (!toolCall) return [
8801
+ case 113:
8802
+ mcpCall = mcpCalls[event.item_id];
8803
+ if (!mcpCall) return [
7429
8804
  3,
7430
- 33
8805
+ 122
7431
8806
  ];
7432
8807
  return [
7433
8808
  4,
7434
8809
  onEvent2({
7435
8810
  event: "thread.run.step.delta",
7436
8811
  data: {
7437
- id: event.item_id,
8812
+ id: "fc".concat(event.item_id),
7438
8813
  object: "thread.run.step.delta",
7439
8814
  delta: {
7440
8815
  step_details: {
7441
8816
  type: "tool_calls",
7442
8817
  tool_calls: [
7443
8818
  {
7444
- id: toolCall.call_id,
8819
+ id: "ftc".concat(mcpCall.id),
7445
8820
  type: "function",
7446
8821
  index: event.output_index,
7447
8822
  function: {
7448
- name: toolCall.name,
8823
+ name: mcpCall.name,
7449
8824
  arguments: event.delta,
7450
8825
  output: null
7451
8826
  }
@@ -7456,133 +8831,220 @@ var responsesRunAdapter = function(param) {
7456
8831
  }
7457
8832
  })
7458
8833
  ];
7459
- case 31:
8834
+ case 114:
7460
8835
  _state.sent();
7461
8836
  return [
7462
8837
  3,
7463
- 33
8838
+ 122
7464
8839
  ];
7465
- case 32:
8840
+ case 115:
8841
+ _tmp83 = {
8842
+ event: "thread.message.in_progress"
8843
+ };
8844
+ _tmp84 = {
8845
+ id: event.item_id,
8846
+ object: "thread.message",
8847
+ created_at: dayjs18().unix(),
8848
+ thread_id: threadId,
8849
+ completed_at: null,
8850
+ incomplete_at: null,
8851
+ incomplete_details: null,
8852
+ role: "assistant",
8853
+ content: []
8854
+ };
8855
+ return [
8856
+ 4,
8857
+ getOpenaiAssistant()
8858
+ ];
8859
+ case 116:
8860
+ return [
8861
+ 4,
8862
+ onEvent2.apply(void 0, [
8863
+ (_tmp83.data = (_tmp84.assistant_id = _state.sent().id, _tmp84.run_id = responseCreatedResponse.id, _tmp84.attachments = [], _tmp84.status = "in_progress", _tmp84.metadata = {
8864
+ event: JSON.stringify(event)
8865
+ }, _tmp84), _tmp83)
8866
+ ])
8867
+ ];
8868
+ case 117:
8869
+ _state.sent();
7466
8870
  return [
7467
8871
  3,
7468
- 33
8872
+ 122
7469
8873
  ];
7470
- case 33:
8874
+ case 118:
8875
+ _tmp85 = {
8876
+ event: "thread.message.in_progress"
8877
+ };
8878
+ _tmp86 = {
8879
+ id: event.item_id,
8880
+ object: "thread.message",
8881
+ created_at: dayjs18().unix(),
8882
+ thread_id: threadId,
8883
+ completed_at: null,
8884
+ incomplete_at: null,
8885
+ incomplete_details: null,
8886
+ role: "assistant",
8887
+ content: [
8888
+ {
8889
+ type: "image_url",
8890
+ image_url: {
8891
+ url: "data:image/png;base64,".concat(event.partial_image_b64),
8892
+ // url: `data:image/png;base64,truncated`,
8893
+ detail: "auto"
8894
+ }
8895
+ }
8896
+ ]
8897
+ };
8898
+ return [
8899
+ 4,
8900
+ getOpenaiAssistant()
8901
+ ];
8902
+ case 119:
8903
+ return [
8904
+ 4,
8905
+ onEvent2.apply(void 0, [
8906
+ (_tmp85.data = (_tmp86.assistant_id = _state.sent().id, _tmp86.run_id = responseCreatedResponse.id, _tmp86.attachments = [], _tmp86.status = "in_progress", _tmp86.metadata = {
8907
+ event: JSON.stringify(_object_spread_props(_object_spread({}, event), {
8908
+ partial_image_b64: "truncated"
8909
+ }))
8910
+ }, _tmp86), _tmp85)
8911
+ ])
8912
+ ];
8913
+ case 120:
8914
+ _state.sent();
8915
+ return [
8916
+ 3,
8917
+ 122
8918
+ ];
8919
+ case 121:
8920
+ return [
8921
+ 3,
8922
+ 122
8923
+ ];
8924
+ case 122:
7471
8925
  _iteratorAbruptCompletion = false;
7472
8926
  return [
7473
8927
  3,
7474
8928
  3
7475
8929
  ];
7476
- case 34:
8930
+ case 123:
7477
8931
  return [
7478
8932
  3,
7479
- 41
8933
+ 130
7480
8934
  ];
7481
- case 35:
8935
+ case 124:
7482
8936
  err = _state.sent();
7483
8937
  _didIteratorError = true;
7484
8938
  _iteratorError = err;
7485
8939
  return [
7486
8940
  3,
7487
- 41
8941
+ 130
7488
8942
  ];
7489
- case 36:
8943
+ case 125:
7490
8944
  _state.trys.push([
7491
- 36,
8945
+ 125,
7492
8946
  ,
7493
- 39,
7494
- 40
8947
+ 128,
8948
+ 129
7495
8949
  ]);
7496
8950
  if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
7497
8951
  3,
7498
- 38
8952
+ 127
7499
8953
  ];
7500
8954
  return [
7501
8955
  4,
7502
8956
  _iterator.return()
7503
8957
  ];
7504
- case 37:
8958
+ case 126:
7505
8959
  _state.sent();
7506
- _state.label = 38;
7507
- case 38:
8960
+ _state.label = 127;
8961
+ case 127:
7508
8962
  return [
7509
8963
  3,
7510
- 40
8964
+ 129
7511
8965
  ];
7512
- case 39:
8966
+ case 128:
7513
8967
  if (_didIteratorError) {
7514
8968
  throw _iteratorError;
7515
8969
  }
7516
8970
  return [
7517
8971
  7
7518
8972
  ];
7519
- case 40:
8973
+ case 129:
7520
8974
  return [
7521
8975
  7
7522
8976
  ];
7523
- case 41:
8977
+ case 130:
7524
8978
  return [
7525
8979
  3,
7526
- 47
8980
+ 137
7527
8981
  ];
7528
- case 42:
8982
+ case 131:
7529
8983
  e = _state.sent();
8984
+ _tmp87 = {
8985
+ event: "thread.run.failed"
8986
+ };
8987
+ _tmp88 = {
8988
+ id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat(uid6(18)),
8989
+ object: "thread.run",
8990
+ thread_id: threadId
8991
+ };
7530
8992
  return [
7531
8993
  4,
7532
- onEvent2({
7533
- event: "thread.run.failed",
7534
- data: {
7535
- id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat(uid7(18)),
7536
- object: "thread.run",
7537
- thread_id: threadId,
7538
- assistant_id: openaiAssistant.id,
7539
- status: "failed",
7540
- failed_at: dayjs13().unix(),
7541
- last_error: {
7542
- code: "server_error",
7543
- message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
7544
- }
7545
- }
7546
- })
8994
+ getOpenaiAssistant()
7547
8995
  ];
7548
- case 43:
8996
+ case 132:
8997
+ return [
8998
+ 4,
8999
+ onEvent2.apply(void 0, [
9000
+ (_tmp87.data = (_tmp88.assistant_id = _state.sent().id, _tmp88.status = "failed", _tmp88.failed_at = dayjs18().unix(), _tmp88.last_error = {
9001
+ code: "server_error",
9002
+ message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
9003
+ }, _tmp88), _tmp87)
9004
+ ])
9005
+ ];
9006
+ case 133:
7549
9007
  _state.sent();
7550
9008
  return [
7551
9009
  3,
7552
- 47
9010
+ 137
7553
9011
  ];
7554
- case 44:
9012
+ case 134:
7555
9013
  if (!((responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) && itemIds.length > 0)) return [
7556
9014
  3,
7557
- 46
9015
+ 136
7558
9016
  ];
7559
9017
  return [
7560
9018
  4,
7561
9019
  saveResponseItemsToConversationMetadata({
7562
- openai: openai,
9020
+ client: client,
7563
9021
  threadId: threadId,
7564
9022
  responseId: responseCreatedResponse.id,
7565
9023
  itemIds: itemIds
7566
9024
  })
7567
9025
  ];
7568
- case 45:
9026
+ case 135:
7569
9027
  _state.sent();
7570
- _state.label = 46;
7571
- case 46:
9028
+ _state.label = 136;
9029
+ case 136:
7572
9030
  return [
7573
9031
  7
7574
9032
  ];
7575
- case 47:
9033
+ case 137:
7576
9034
  return [
7577
9035
  2
7578
9036
  ];
7579
9037
  }
7580
9038
  });
7581
9039
  });
7582
- return function(_) {
9040
+ return function handleRun(_) {
7583
9041
  return _ref.apply(this, arguments);
7584
9042
  };
7585
9043
  }();
9044
+ return {
9045
+ handleRun: handleRun,
9046
+ getOpenaiAssistant: getOpenaiAssistant
9047
+ };
7586
9048
  };
7587
9049
  export { anthropicClientAdapter, azureOpenaiClientAdapter, completionsRunAdapter, googleClientAdapter, groqClientAdapter, humirisClientAdapter, mistralClientAdapter, ollamaClientAdapter, openaiClientAdapter, perplexityClientAdapter, prismaStorageAdapter, responsesRunAdapter, responsesStorageAdapter, supercompat, togetherClientAdapter };
7588
9050
  //# sourceMappingURL=index.js.map