supercompat 3.17.2 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -10,6 +10,80 @@ function _array_with_holes(arr) {
10
10
  function _array_without_holes(arr) {
11
11
  if (Array.isArray(arr)) return _array_like_to_array(arr);
12
12
  }
13
+ function _async_generator(gen) {
14
+ var front, back;
15
+ function send(key, arg) {
16
+ return new Promise(function(resolve, reject) {
17
+ var request = {
18
+ key: key,
19
+ arg: arg,
20
+ resolve: resolve,
21
+ reject: reject,
22
+ next: null
23
+ };
24
+ if (back) back = back.next = request;
25
+ else {
26
+ front = back = request;
27
+ resume(key, arg);
28
+ }
29
+ });
30
+ }
31
+ function resume(key, arg) {
32
+ try {
33
+ var result = gen[key](arg);
34
+ var value = result.value;
35
+ var overloaded = value instanceof _overload_yield;
36
+ Promise.resolve(overloaded ? value.v : value).then(function(arg) {
37
+ if (overloaded) {
38
+ var nextKey = key === "return" ? "return" : "next";
39
+ if (!value.k || arg.done) return resume(nextKey, arg);
40
+ else arg = gen[nextKey](arg).value;
41
+ }
42
+ settle(result.done ? "return" : "normal", arg);
43
+ }, function(err) {
44
+ resume("throw", err);
45
+ });
46
+ } catch (err) {
47
+ settle("throw", err);
48
+ }
49
+ }
50
+ function settle(type, value) {
51
+ switch(type){
52
+ case "return":
53
+ front.resolve({
54
+ value: value,
55
+ done: true
56
+ });
57
+ break;
58
+ case "throw":
59
+ front.reject(value);
60
+ break;
61
+ default:
62
+ front.resolve({
63
+ value: value,
64
+ done: false
65
+ });
66
+ break;
67
+ }
68
+ front = front.next;
69
+ if (front) resume(front.key, front.arg);
70
+ else back = null;
71
+ }
72
+ this._invoke = send;
73
+ if (typeof gen.return !== "function") this.return = undefined;
74
+ }
75
+ _async_generator.prototype[typeof Symbol === "function" && Symbol.asyncIterator || "@@asyncIterator"] = function() {
76
+ return this;
77
+ };
78
+ _async_generator.prototype.next = function(arg) {
79
+ return this._invoke("next", arg);
80
+ };
81
+ _async_generator.prototype.throw = function(arg) {
82
+ return this._invoke("throw", arg);
83
+ };
84
+ _async_generator.prototype.return = function(arg) {
85
+ return this._invoke("return", arg);
86
+ };
13
87
  function _async_iterator(iterable) {
14
88
  var method, async, sync, retry = 2;
15
89
  for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
@@ -80,6 +154,9 @@ function _async_to_generator(fn) {
80
154
  });
81
155
  };
82
156
  }
157
+ function _await_async_generator(value) {
158
+ return new _overload_yield(value, 0);
159
+ }
83
160
  function _define_property(obj, key, value) {
84
161
  if (key in obj) {
85
162
  Object.defineProperty(obj, key, {
@@ -208,6 +285,10 @@ function _object_without_properties_loose(source, excluded) {
208
285
  }
209
286
  return target;
210
287
  }
288
+ function _overload_yield(value, kind) {
289
+ this.v = value;
290
+ this.k = kind;
291
+ }
211
292
  function _sliced_to_array(arr, i) {
212
293
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
213
294
  }
@@ -226,6 +307,11 @@ function _unsupported_iterable_to_array(o, minLen) {
226
307
  if (n === "Map" || n === "Set") return Array.from(n);
227
308
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
228
309
  }
310
+ function _wrap_async_generator(fn) {
311
+ return function() {
312
+ return new _async_generator(fn.apply(this, arguments));
313
+ };
314
+ }
229
315
  function _ts_generator(thisArg, body) {
230
316
  var f, y, t, _ = {
231
317
  label: 0,
@@ -3533,15 +3619,17 @@ var GEMINI_ACTION_NAMES = /* @__PURE__ */ new Set([
3533
3619
  "scroll_document",
3534
3620
  "drag_and_drop",
3535
3621
  "wait_5_seconds",
3536
- "wait_for_load",
3537
- "navigate",
3538
- "go_back",
3539
- "go_forward",
3540
- "open_web_browser"
3622
+ "wait_for_load"
3541
3623
  ]);
3542
3624
  var isGeminiAction = function(name) {
3543
3625
  return GEMINI_ACTION_NAMES.has(name);
3544
3626
  };
3627
+ var act = function(action) {
3628
+ return {
3629
+ action: action,
3630
+ pending_safety_checks: []
3631
+ };
3632
+ };
3545
3633
  var normalizeGeminiKey = function(key) {
3546
3634
  var lower = key.toLowerCase();
3547
3635
  switch(lower){
@@ -3595,80 +3683,89 @@ var normalizeGeminiAction = function(name, args) {
3595
3683
  switch(name){
3596
3684
  case "click_at":
3597
3685
  case "single_click_at":
3598
- return {
3599
- action: {
3686
+ return [
3687
+ act({
3600
3688
  type: "click",
3601
3689
  button: "left",
3602
3690
  x: x,
3603
3691
  y: y
3604
- },
3605
- pending_safety_checks: []
3606
- };
3692
+ })
3693
+ ];
3607
3694
  case "right_click_at":
3608
- return {
3609
- action: {
3695
+ return [
3696
+ act({
3610
3697
  type: "click",
3611
3698
  button: "right",
3612
3699
  x: x,
3613
3700
  y: y
3614
- },
3615
- pending_safety_checks: []
3616
- };
3701
+ })
3702
+ ];
3617
3703
  case "double_click_at":
3618
- return {
3619
- action: {
3704
+ return [
3705
+ act({
3620
3706
  type: "double_click",
3621
3707
  x: x,
3622
3708
  y: y
3623
- },
3624
- pending_safety_checks: []
3625
- };
3709
+ })
3710
+ ];
3626
3711
  case "triple_click_at":
3627
- return {
3628
- action: {
3712
+ return [
3713
+ act({
3629
3714
  type: "double_click",
3630
3715
  x: x,
3631
3716
  y: y,
3632
3717
  repetitions: 3
3633
- },
3634
- pending_safety_checks: []
3635
- };
3718
+ })
3719
+ ];
3636
3720
  case "hover_at":
3637
- return {
3638
- action: {
3721
+ return [
3722
+ act({
3639
3723
  type: "move",
3640
3724
  x: x,
3641
3725
  y: y
3642
- },
3643
- pending_safety_checks: []
3644
- };
3726
+ })
3727
+ ];
3645
3728
  case "type_text_at":
3646
3729
  {
3647
3730
  var text = typeof args.text === "string" ? args.text : "";
3648
- var pendingActions = [
3649
- {
3650
- type: "type",
3651
- text: text
3652
- }
3731
+ var clearBeforeTyping = args.clear_before_typing !== false;
3732
+ var pressEnter = args.press_enter !== false;
3733
+ var actions = [
3734
+ act({
3735
+ type: "click",
3736
+ button: "left",
3737
+ x: x,
3738
+ y: y
3739
+ })
3653
3740
  ];
3654
- if (args.submit_after_type === true) {
3655
- pendingActions.push({
3741
+ if (clearBeforeTyping) {
3742
+ actions.push(act({
3743
+ type: "keypress",
3744
+ keys: [
3745
+ "ctrl",
3746
+ "a"
3747
+ ]
3748
+ }));
3749
+ actions.push(act({
3750
+ type: "keypress",
3751
+ keys: [
3752
+ "Backspace"
3753
+ ]
3754
+ }));
3755
+ }
3756
+ actions.push(act({
3757
+ type: "type",
3758
+ text: text
3759
+ }));
3760
+ if (pressEnter) {
3761
+ actions.push(act({
3656
3762
  type: "keypress",
3657
3763
  keys: [
3658
3764
  "Return"
3659
3765
  ]
3660
- });
3766
+ }));
3661
3767
  }
3662
- return {
3663
- action: {
3664
- type: "click",
3665
- button: "left",
3666
- x: x,
3667
- y: y,
3668
- pending_actions: pendingActions
3669
- },
3670
- pending_safety_checks: []
3671
- };
3768
+ return actions;
3672
3769
  }
3673
3770
  case "key_combination":
3674
3771
  {
@@ -3683,52 +3780,49 @@ var normalizeGeminiAction = function(name, args) {
3683
3780
  } else {
3684
3781
  keys = [];
3685
3782
  }
3686
- return {
3687
- action: {
3783
+ return [
3784
+ act({
3688
3785
  type: "keypress",
3689
3786
  keys: keys
3690
- },
3691
- pending_safety_checks: []
3692
- };
3787
+ })
3788
+ ];
3693
3789
  }
3694
3790
  case "scroll_at":
3695
3791
  {
3696
3792
  var direction = typeof args.direction === "string" ? args.direction : void 0;
3697
3793
  var amount = typeof args.amount === "number" ? args.amount : 3;
3698
3794
  var _scrollFromDirection = scrollFromDirection(direction, amount), scroll_x = _scrollFromDirection.scroll_x, scroll_y = _scrollFromDirection.scroll_y;
3699
- return {
3700
- action: {
3795
+ return [
3796
+ act({
3701
3797
  type: "scroll",
3702
3798
  x: x,
3703
3799
  y: y,
3704
3800
  scroll_x: scroll_x,
3705
3801
  scroll_y: scroll_y
3706
- },
3707
- pending_safety_checks: []
3708
- };
3802
+ })
3803
+ ];
3709
3804
  }
3710
3805
  case "scroll_document":
3711
3806
  {
3712
3807
  var direction1 = typeof args.direction === "string" ? args.direction : void 0;
3713
3808
  var amount1 = typeof args.amount === "number" ? args.amount : 3;
3714
3809
  var _scrollFromDirection1 = scrollFromDirection(direction1, amount1), scroll_x1 = _scrollFromDirection1.scroll_x, scroll_y1 = _scrollFromDirection1.scroll_y;
3715
- return {
3716
- action: {
3810
+ return [
3811
+ act({
3717
3812
  type: "scroll",
3718
3813
  x: 640,
3719
3814
  y: 360,
3720
3815
  scroll_x: scroll_x1,
3721
3816
  scroll_y: scroll_y1
3722
- },
3723
- pending_safety_checks: []
3724
- };
3817
+ })
3818
+ ];
3725
3819
  }
3726
3820
  case "drag_and_drop":
3727
3821
  {
3728
3822
  var destX = typeof args.destination_x === "number" ? args.destination_x : 0;
3729
3823
  var destY = typeof args.destination_y === "number" ? args.destination_y : 0;
3730
- return {
3731
- action: {
3824
+ return [
3825
+ act({
3732
3826
  type: "drag",
3733
3827
  path: [
3734
3828
  {
@@ -3740,86 +3834,24 @@ var normalizeGeminiAction = function(name, args) {
3740
3834
  y: destY
3741
3835
  }
3742
3836
  ]
3743
- },
3744
- pending_safety_checks: []
3745
- };
3837
+ })
3838
+ ];
3746
3839
  }
3747
3840
  case "wait_5_seconds":
3748
3841
  case "wait_for_load":
3749
- return {
3750
- action: {
3842
+ return [
3843
+ act({
3751
3844
  type: "wait"
3752
- },
3753
- pending_safety_checks: []
3754
- };
3755
- case "navigate":
3756
- {
3757
- var url = typeof args.url === "string" ? args.url : "";
3758
- return {
3759
- action: {
3760
- type: "keypress",
3761
- keys: [
3762
- "ctrl",
3763
- "l"
3764
- ],
3765
- pending_actions: [
3766
- {
3767
- type: "wait"
3768
- },
3769
- {
3770
- type: "type",
3771
- text: url
3772
- },
3773
- {
3774
- type: "keypress",
3775
- keys: [
3776
- "Return"
3777
- ]
3778
- },
3779
- {
3780
- type: "wait"
3781
- }
3782
- ]
3783
- },
3784
- pending_safety_checks: []
3785
- };
3786
- }
3787
- case "go_back":
3788
- return {
3789
- action: {
3790
- type: "keypress",
3791
- keys: [
3792
- "alt",
3793
- "left"
3794
- ]
3795
- },
3796
- pending_safety_checks: []
3797
- };
3798
- case "go_forward":
3799
- return {
3800
- action: {
3801
- type: "keypress",
3802
- keys: [
3803
- "alt",
3804
- "right"
3805
- ]
3806
- },
3807
- pending_safety_checks: []
3808
- };
3809
- case "open_web_browser":
3810
- return {
3811
- action: {
3812
- type: "screenshot"
3813
- },
3814
- pending_safety_checks: []
3815
- };
3845
+ })
3846
+ ];
3847
+ // navigate, go_back, go_forward, open_web_browser, search are excluded
3848
+ // via excludedPredefinedFunctions in the tool config
3816
3849
  default:
3817
- return {
3818
- action: _object_spread({
3850
+ return [
3851
+ act(_object_spread({
3819
3852
  type: name
3820
- }, args),
3821
- pending_safety_checks: []
3822
- };
3853
+ }, args))
3854
+ ];
3823
3855
  }
3824
3856
  };
3825
3857
  // src/adapters/client/googleClientAdapter/completions/post.ts
@@ -3863,6 +3895,9 @@ var serializeMessages2 = function(messages5) {
3863
3895
  var systemParts = [];
3864
3896
  var contents = [];
3865
3897
  var toolCallIdToName = /* @__PURE__ */ new Map();
3898
+ var geminiCallGroups = /* @__PURE__ */ new Map();
3899
+ var skipToolResultIds = /* @__PURE__ */ new Set();
3900
+ var lastSubActionMap = /* @__PURE__ */ new Map();
3866
3901
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3867
3902
  try {
3868
3903
  for(var _iterator = messages5[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -3959,9 +3994,42 @@ var serializeMessages2 = function(messages5) {
3959
3994
  } catch (unused) {}
3960
3995
  var thoughtSignature = args._thoughtSignature;
3961
3996
  var geminiActionName = args._geminiAction;
3997
+ var geminiCallId = args._geminiCallId;
3998
+ var subActionIndex = args._subActionIndex;
3999
+ var subActionTotal = args._subActionTotal;
4000
+ var geminiOrigArgs = args._geminiArgs;
3962
4001
  var cleanArgs = _object_spread({}, args);
3963
4002
  delete cleanArgs._thoughtSignature;
3964
4003
  delete cleanArgs._geminiAction;
4004
+ delete cleanArgs._geminiCallId;
4005
+ delete cleanArgs._subActionIndex;
4006
+ delete cleanArgs._subActionTotal;
4007
+ delete cleanArgs._geminiArgs;
4008
+ if (geminiCallId && typeof subActionIndex === "number" && typeof subActionTotal === "number") {
4009
+ if (subActionIndex === 0) {
4010
+ var fcName = geminiActionName !== null && geminiActionName !== void 0 ? geminiActionName : name;
4011
+ geminiCallGroups.set(geminiCallId, {
4012
+ name: fcName,
4013
+ primaryId: id
4014
+ });
4015
+ toolCallIdToName.set(id, fcName);
4016
+ if (subActionTotal > 1) skipToolResultIds.add(id);
4017
+ var fcPart2 = {
4018
+ functionCall: {
4019
+ name: fcName,
4020
+ args: geminiOrigArgs !== null && geminiOrigArgs !== void 0 ? geminiOrigArgs : {},
4021
+ id: id
4022
+ }
4023
+ };
4024
+ if (thoughtSignature) fcPart2.thoughtSignature = thoughtSignature;
4025
+ parts1.push(fcPart2);
4026
+ } else if (subActionIndex === subActionTotal - 1) {
4027
+ lastSubActionMap.set(id, geminiCallId);
4028
+ } else {
4029
+ skipToolResultIds.add(id);
4030
+ }
4031
+ continue;
4032
+ }
3965
4033
  var geminiName = name;
3966
4034
  if (name === "computer_call" && args.action && _type_of(args.action) === "object") {
3967
4035
  var _ref2;
@@ -3970,9 +4038,8 @@ var serializeMessages2 = function(messages5) {
3970
4038
  var geminiArgs = void 0;
3971
4039
  if (name === "computer_call" && cleanArgs.action && _type_of(cleanArgs.action) === "object") {
3972
4040
  var action = cleanArgs.action;
3973
- var _type = action.type, _pa = action.pending_actions, rest = _object_without_properties(action, [
3974
- "type",
3975
- "pending_actions"
4041
+ var _type = action.type, rest = _object_without_properties(action, [
4042
+ "type"
3976
4043
  ]);
3977
4044
  geminiArgs = rest;
3978
4045
  } else {
@@ -4015,10 +4082,22 @@ var serializeMessages2 = function(messages5) {
4015
4082
  continue;
4016
4083
  }
4017
4084
  if (msg.role === "tool") {
4018
- var _msg_tool_call_id, _toolCallIdToName_get;
4085
+ var _msg_tool_call_id;
4019
4086
  var _lastContent_parts;
4020
4087
  var toolCallId = (_msg_tool_call_id = msg.tool_call_id) !== null && _msg_tool_call_id !== void 0 ? _msg_tool_call_id : "";
4021
- var name1 = (_toolCallIdToName_get = toolCallIdToName.get(toolCallId)) !== null && _toolCallIdToName_get !== void 0 ? _toolCallIdToName_get : "";
4088
+ if (skipToolResultIds.has(toolCallId)) continue;
4089
+ var responseName = void 0;
4090
+ var responseId2 = void 0;
4091
+ if (lastSubActionMap.has(toolCallId)) {
4092
+ var gcId = lastSubActionMap.get(toolCallId);
4093
+ var group = geminiCallGroups.get(gcId);
4094
+ responseName = group.name;
4095
+ responseId2 = group.primaryId;
4096
+ } else {
4097
+ var _toolCallIdToName_get;
4098
+ responseName = (_toolCallIdToName_get = toolCallIdToName.get(toolCallId)) !== null && _toolCallIdToName_get !== void 0 ? _toolCallIdToName_get : "";
4099
+ responseId2 = toolCallId;
4100
+ }
4022
4101
  var parts2 = [];
4023
4102
  var imageContent = extractImageFromToolMessage(msg);
4024
4103
  if (imageContent) {
@@ -4032,8 +4111,8 @@ var serializeMessages2 = function(messages5) {
4032
4111
  ];
4033
4112
  parts2.push({
4034
4113
  functionResponse: {
4035
- id: toolCallId,
4036
- name: name1,
4114
+ id: responseId2,
4115
+ name: responseName,
4037
4116
  response: {
4038
4117
  output: "Screenshot captured."
4039
4118
  },
@@ -4044,8 +4123,8 @@ var serializeMessages2 = function(messages5) {
4044
4123
  var output = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
4045
4124
  parts2.push({
4046
4125
  functionResponse: {
4047
- id: toolCallId,
4048
- name: name1,
4126
+ id: responseId2,
4127
+ name: responseName,
4049
4128
  response: {
4050
4129
  output: output
4051
4130
  }
@@ -4180,7 +4259,14 @@ var serializeTools2 = function(tools) {
4180
4259
  if (computerUseEnabled) {
4181
4260
  geminiTools.push({
4182
4261
  computerUse: {
4183
- environment: "ENVIRONMENT_BROWSER"
4262
+ environment: "ENVIRONMENT_BROWSER",
4263
+ excludedPredefinedFunctions: [
4264
+ "navigate",
4265
+ "go_back",
4266
+ "go_forward",
4267
+ "search",
4268
+ "open_web_browser"
4269
+ ]
4184
4270
  }
4185
4271
  });
4186
4272
  }
@@ -4238,56 +4324,194 @@ var isComputerUseFunction = function(name, tools) {
4238
4324
  var userFns = getUserDefinedFunctionNames(tools);
4239
4325
  return !userFns.has(name);
4240
4326
  };
4241
- var functionCallToToolCallDelta = function(fc, index, tools, thoughtSignature) {
4327
+ var functionCallToToolCallDeltas = function(fc, startIndex, tools, thoughtSignature) {
4242
4328
  var _fc_name, _fc_args, _fc_id;
4243
4329
  var rawName = (_fc_name = fc.name) !== null && _fc_name !== void 0 ? _fc_name : "";
4244
4330
  var name = stripFunctionPrefix(rawName);
4245
4331
  if (isComputerUseFunction(name, tools)) {
4246
4332
  var _fc_args1, _fc_id1;
4247
4333
  var denormed = denormalizeCoords((_fc_args1 = fc.args) !== null && _fc_args1 !== void 0 ? _fc_args1 : {}, tools);
4248
- var normalized = isGeminiAction(name) ? normalizeGeminiAction(name, denormed) : normalizeComputerToolCallPayload(_object_spread_props(_object_spread({}, denormed), {
4334
+ if (isGeminiAction(name)) {
4335
+ var normalizedActions = normalizeGeminiAction(name, denormed);
4336
+ if (normalizedActions.length === 1) {
4337
+ var _fc_id2;
4338
+ var payload2 = _object_spread({}, normalizedActions[0]);
4339
+ payload2._geminiAction = name;
4340
+ if (thoughtSignature) payload2._thoughtSignature = thoughtSignature;
4341
+ return [
4342
+ {
4343
+ index: startIndex,
4344
+ id: (_fc_id2 = fc.id) !== null && _fc_id2 !== void 0 ? _fc_id2 : "call_".concat((0, import_cuid2.createId)()),
4345
+ type: "function",
4346
+ function: {
4347
+ name: "computer_call",
4348
+ arguments: JSON.stringify(payload2)
4349
+ }
4350
+ }
4351
+ ];
4352
+ }
4353
+ var geminiCallId = "gcall_".concat((0, import_cuid2.createId)());
4354
+ return normalizedActions.map(function(normalized2, i) {
4355
+ var _fc_id;
4356
+ var payload2 = _object_spread({}, normalized2);
4357
+ payload2._geminiCallId = geminiCallId;
4358
+ payload2._geminiAction = name;
4359
+ payload2._subActionIndex = i;
4360
+ payload2._subActionTotal = normalizedActions.length;
4361
+ if (i === 0) {
4362
+ payload2._geminiArgs = denormed;
4363
+ if (thoughtSignature) payload2._thoughtSignature = thoughtSignature;
4364
+ }
4365
+ return {
4366
+ index: startIndex + i,
4367
+ id: i === 0 ? (_fc_id = fc.id) !== null && _fc_id !== void 0 ? _fc_id : "call_".concat((0, import_cuid2.createId)()) : "call_".concat((0, import_cuid2.createId)()),
4368
+ type: "function",
4369
+ function: {
4370
+ name: "computer_call",
4371
+ arguments: JSON.stringify(payload2)
4372
+ }
4373
+ };
4374
+ });
4375
+ }
4376
+ var normalized = normalizeComputerToolCallPayload(_object_spread_props(_object_spread({}, denormed), {
4249
4377
  type: name
4250
4378
  }));
4251
4379
  var payload = _object_spread({}, normalized);
4252
- if (thoughtSignature) {
4253
- payload._thoughtSignature = thoughtSignature;
4254
- }
4255
- if (isGeminiAction(name)) {
4256
- payload._geminiAction = name;
4257
- }
4258
- return {
4259
- index: index,
4260
- id: (_fc_id1 = fc.id) !== null && _fc_id1 !== void 0 ? _fc_id1 : "call_".concat((0, import_cuid2.createId)()),
4261
- type: "function",
4262
- function: {
4263
- name: "computer_call",
4264
- arguments: JSON.stringify(payload)
4380
+ if (thoughtSignature) payload._thoughtSignature = thoughtSignature;
4381
+ return [
4382
+ {
4383
+ index: startIndex,
4384
+ id: (_fc_id1 = fc.id) !== null && _fc_id1 !== void 0 ? _fc_id1 : "call_".concat((0, import_cuid2.createId)()),
4385
+ type: "function",
4386
+ function: {
4387
+ name: "computer_call",
4388
+ arguments: JSON.stringify(payload)
4389
+ }
4265
4390
  }
4266
- };
4391
+ ];
4267
4392
  }
4268
4393
  var args = (_fc_args = fc.args) !== null && _fc_args !== void 0 ? _fc_args : {};
4269
4394
  if (thoughtSignature) {
4270
4395
  args._thoughtSignature = thoughtSignature;
4271
4396
  }
4272
- return {
4273
- index: index,
4274
- id: (_fc_id = fc.id) !== null && _fc_id !== void 0 ? _fc_id : "call_".concat((0, import_cuid2.createId)()),
4275
- type: "function",
4276
- function: {
4277
- name: name,
4278
- arguments: JSON.stringify(args)
4397
+ return [
4398
+ {
4399
+ index: startIndex,
4400
+ id: (_fc_id = fc.id) !== null && _fc_id !== void 0 ? _fc_id : "call_".concat((0, import_cuid2.createId)()),
4401
+ type: "function",
4402
+ function: {
4403
+ name: name,
4404
+ arguments: JSON.stringify(args)
4405
+ }
4279
4406
  }
4280
- };
4407
+ ];
4408
+ };
4409
+ var syntheticToolCallResponse = function(toolCallDelta, stream) {
4410
+ var delta = _object_spread_props(_object_spread({}, toolCallDelta), {
4411
+ index: 0
4412
+ });
4413
+ var encoder = new TextEncoder();
4414
+ if (stream) {
4415
+ var chunks = [
4416
+ "data: ".concat(JSON.stringify({
4417
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4418
+ object: "chat.completion.chunk",
4419
+ choices: [
4420
+ {
4421
+ index: 0,
4422
+ delta: {
4423
+ content: null,
4424
+ tool_calls: [
4425
+ delta
4426
+ ]
4427
+ }
4428
+ }
4429
+ ]
4430
+ }), "\n\n"),
4431
+ "data: ".concat(JSON.stringify({
4432
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4433
+ object: "chat.completion.chunk",
4434
+ choices: [
4435
+ {
4436
+ index: 0,
4437
+ delta: {},
4438
+ finish_reason: "stop"
4439
+ }
4440
+ ]
4441
+ }), "\n\n")
4442
+ ];
4443
+ return new Response(new ReadableStream({
4444
+ start: function start(controller) {
4445
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4446
+ try {
4447
+ for(var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4448
+ var chunk = _step.value;
4449
+ controller.enqueue(encoder.encode(chunk));
4450
+ }
4451
+ } catch (err) {
4452
+ _didIteratorError = true;
4453
+ _iteratorError = err;
4454
+ } finally{
4455
+ try {
4456
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
4457
+ _iterator.return();
4458
+ }
4459
+ } finally{
4460
+ if (_didIteratorError) {
4461
+ throw _iteratorError;
4462
+ }
4463
+ }
4464
+ }
4465
+ controller.close();
4466
+ }
4467
+ }), {
4468
+ headers: {
4469
+ "Content-Type": "text/event-stream"
4470
+ }
4471
+ });
4472
+ }
4473
+ return new Response(JSON.stringify({
4474
+ data: {
4475
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4476
+ object: "chat.completion",
4477
+ choices: [
4478
+ {
4479
+ index: 0,
4480
+ message: {
4481
+ role: "assistant",
4482
+ content: null,
4483
+ tool_calls: [
4484
+ delta
4485
+ ]
4486
+ },
4487
+ finish_reason: "stop"
4488
+ }
4489
+ ]
4490
+ }
4491
+ }), {
4492
+ status: 200,
4493
+ headers: {
4494
+ "Content-Type": "application/json"
4495
+ }
4496
+ });
4281
4497
  };
4282
4498
  var post7 = function(param) {
4283
4499
  var google = param.google;
4500
+ var pendingSubActions = [];
4284
4501
  return function(_url, options) {
4285
4502
  return _async_to_generator(function() {
4286
- var body, messages5, _serializeMessages2, contents, systemInstruction, geminiTools, params, response, stream, _ref, _data_candidates, _candidate_content, data, candidate, parts, textParts, lastSig, toolCalls, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, p, message, result, error;
4503
+ var body, next, messages5, _serializeMessages2, contents, systemInstruction, geminiTools, params, response, stream, _ref, _data_candidates, _candidate_content, data, candidate, parts, textParts, lastSig, toolCalls, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, p, deltas, _pendingSubActions, _toolCalls, message, result, error;
4287
4504
  return _ts_generator(this, function(_state) {
4288
4505
  switch(_state.label){
4289
4506
  case 0:
4290
4507
  body = JSON.parse(options.body);
4508
+ if (pendingSubActions.length > 0) {
4509
+ next = pendingSubActions.shift();
4510
+ return [
4511
+ 2,
4512
+ syntheticToolCallResponse(next, !!body.stream)
4513
+ ];
4514
+ }
4291
4515
  messages5 = nonEmptyMessages({
4292
4516
  messages: body.messages
4293
4517
  });
@@ -4321,7 +4545,7 @@ var post7 = function(param) {
4321
4545
  stream = new ReadableStream({
4322
4546
  start: function start(controller) {
4323
4547
  return _async_to_generator(function() {
4324
- var chunkIndex, lastThoughtSignature, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_candidates, _candidate_content, candidate, _iteratorNormalCompletion, _didIteratorError1, _iteratorError1, _iterator1, _step1, part, messageDelta, toolCallDelta, messageDelta1, messageDelta2, err1;
4548
+ var chunkIndex, lastThoughtSignature, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_candidates, _candidate_content, candidate, _iteratorNormalCompletion, _didIteratorError1, _iteratorError1, _iterator1, _step1, part, messageDelta, deltas, emitDeltas, _pendingSubActions, _iteratorNormalCompletion1, _didIteratorError2, _iteratorError2, _iterator2, _step2, toolCallDelta, messageDelta1, messageDelta2, err1;
4325
4549
  return _ts_generator(this, function(_state) {
4326
4550
  switch(_state.label){
4327
4551
  case 0:
@@ -4378,24 +4602,50 @@ var post7 = function(param) {
4378
4602
  controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
4379
4603
  }
4380
4604
  if (part.functionCall) {
4381
- toolCallDelta = functionCallToToolCallDelta(part.functionCall, chunkIndex, body.tools, lastThoughtSignature);
4382
- messageDelta1 = {
4383
- id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4384
- object: "chat.completion.chunk",
4385
- choices: [
4386
- {
4387
- index: 0,
4388
- delta: {
4389
- content: null,
4390
- tool_calls: [
4391
- toolCallDelta
4392
- ]
4393
- }
4605
+ deltas = functionCallToToolCallDeltas(part.functionCall, chunkIndex, body.tools, lastThoughtSignature);
4606
+ emitDeltas = deltas.length > 1 ? [
4607
+ deltas[0]
4608
+ ] : deltas;
4609
+ if (deltas.length > 1) {
4610
+ ;
4611
+ (_pendingSubActions = pendingSubActions).push.apply(_pendingSubActions, _to_consumable_array(deltas.slice(1)));
4612
+ }
4613
+ _iteratorNormalCompletion1 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
4614
+ try {
4615
+ for(_iterator2 = emitDeltas[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
4616
+ toolCallDelta = _step2.value;
4617
+ messageDelta1 = {
4618
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4619
+ object: "chat.completion.chunk",
4620
+ choices: [
4621
+ {
4622
+ index: 0,
4623
+ delta: {
4624
+ content: null,
4625
+ tool_calls: [
4626
+ toolCallDelta
4627
+ ]
4628
+ }
4629
+ }
4630
+ ]
4631
+ };
4632
+ controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
4633
+ }
4634
+ } catch (err) {
4635
+ _didIteratorError2 = true;
4636
+ _iteratorError2 = err;
4637
+ } finally{
4638
+ try {
4639
+ if (!_iteratorNormalCompletion1 && _iterator2.return != null) {
4640
+ _iterator2.return();
4394
4641
  }
4395
- ]
4396
- };
4397
- controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
4398
- chunkIndex++;
4642
+ } finally{
4643
+ if (_didIteratorError2) {
4644
+ throw _iteratorError2;
4645
+ }
4646
+ }
4647
+ }
4648
+ chunkIndex += emitDeltas.length;
4399
4649
  lastThoughtSignature = void 0;
4400
4650
  }
4401
4651
  }
@@ -4528,7 +4778,15 @@ var post7 = function(param) {
4528
4778
  lastSig = p.thoughtSignature;
4529
4779
  }
4530
4780
  if (p.functionCall) {
4531
- toolCalls.push(functionCallToToolCallDelta(p.functionCall, toolCalls.length, body.tools, lastSig));
4781
+ deltas = functionCallToToolCallDeltas(p.functionCall, toolCalls.length, body.tools, lastSig);
4782
+ if (deltas.length > 1) {
4783
+ ;
4784
+ toolCalls.push(deltas[0]);
4785
+ (_pendingSubActions = pendingSubActions).push.apply(_pendingSubActions, _to_consumable_array(deltas.slice(1)));
4786
+ } else {
4787
+ ;
4788
+ (_toolCalls = toolCalls).push.apply(_toolCalls, _to_consumable_array(deltas));
4789
+ }
4532
4790
  lastSig = void 0;
4533
4791
  }
4534
4792
  }
@@ -5067,7 +5325,7 @@ var get11 = function(param) {
5067
5325
  var openRouter = param.openRouter;
5068
5326
  return function(_url, _options) {
5069
5327
  return _async_to_generator(function() {
5070
- var data, error;
5328
+ var data, openaiModels, error;
5071
5329
  return _ts_generator(this, function(_state) {
5072
5330
  switch(_state.label){
5073
5331
  case 0:
@@ -5083,9 +5341,20 @@ var get11 = function(param) {
5083
5341
  ];
5084
5342
  case 1:
5085
5343
  data = _state.sent();
5344
+ openaiModels = {
5345
+ object: "list",
5346
+ data: data.data.map(function(m) {
5347
+ return {
5348
+ id: m.id,
5349
+ object: "model",
5350
+ created: m.created,
5351
+ owned_by: m.id.split("/")[0] || "openrouter"
5352
+ };
5353
+ })
5354
+ };
5086
5355
  return [
5087
5356
  2,
5088
- new Response(JSON.stringify(data), {
5357
+ new Response(JSON.stringify(openaiModels), {
5089
5358
  status: 200,
5090
5359
  headers: {
5091
5360
  "Content-Type": "application/json"
@@ -5131,6 +5400,12 @@ var MODEL_QUIRKS = {
5131
5400
  },
5132
5401
  "qwen/": {
5133
5402
  fuzzyFallback: true
5403
+ },
5404
+ "moonshotai/kimi-k2.5": {
5405
+ relativeCoords: {
5406
+ referenceWidth: 1920,
5407
+ referenceHeight: 1080
5408
+ }
5134
5409
  }
5135
5410
  };
5136
5411
  var getQuirks = function(model) {
@@ -5359,6 +5634,32 @@ var denormalizeAction = function(action, displayWidth, displayHeight) {
5359
5634
  }
5360
5635
  return result;
5361
5636
  };
5637
+ var rescaleCoord = function(value, displayDim, referenceDim) {
5638
+ if (value <= 1) return Math.round(value * displayDim);
5639
+ return Math.round(value / referenceDim * displayDim);
5640
+ };
5641
+ var rescaleRelativeAction = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
5642
+ var result = _object_spread({}, action);
5643
+ if (typeof result.x === "number") {
5644
+ result.x = rescaleCoord(result.x, displayWidth, referenceWidth);
5645
+ }
5646
+ if (typeof result.y === "number") {
5647
+ result.y = rescaleCoord(result.y, displayHeight, referenceHeight);
5648
+ }
5649
+ if (Array.isArray(result.path)) {
5650
+ result.path = result.path.map(function(point) {
5651
+ if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
5652
+ return _object_spread({}, point, typeof point.x === "number" ? {
5653
+ x: rescaleCoord(point.x, displayWidth, referenceWidth)
5654
+ } : {}, typeof point.y === "number" ? {
5655
+ y: rescaleCoord(point.y, displayHeight, referenceHeight)
5656
+ } : {});
5657
+ }
5658
+ return point;
5659
+ });
5660
+ }
5661
+ return result;
5662
+ };
5362
5663
  var COORD_FIELDS = [
5363
5664
  "x",
5364
5665
  "y",
@@ -5471,14 +5772,19 @@ var denormalizeComputerCallArguments = function(param) {
5471
5772
  action: denormalizeAction(normalized.action, displayWidth, displayHeight)
5472
5773
  }));
5473
5774
  }
5775
+ if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
5776
+ return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
5777
+ action: rescaleRelativeAction(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
5778
+ }));
5779
+ }
5474
5780
  return JSON.stringify(normalized);
5475
5781
  };
5476
5782
  // src/adapters/client/openRouterClientAdapter/completions/computerUseTool.ts
5477
5783
  var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
5478
5784
  var quirks = getQuirks(model);
5479
- var coordDesc = quirks.normalizedCoords ? "Coordinates use 0-1000 normalized scale (0,0=top-left, 1000,1000=bottom-right)." : "Coordinates are in pixels (screen is ".concat(displayWidth, "x").concat(displayHeight, ").");
5480
- var xDesc = quirks.normalizedCoords ? "X coordinate (0-1000 normalized)" : "X coordinate in pixels (0-".concat(displayWidth, ")");
5481
- var yDesc = quirks.normalizedCoords ? "Y coordinate (0-1000 normalized)" : "Y coordinate in pixels (0-".concat(displayHeight, ")");
5785
+ var coordDesc = quirks.normalizedCoords ? "Coordinates use 0-1000 normalized scale (0,0=top-left, 1000,1000=bottom-right)." : quirks.relativeCoords ? "Coordinates are relative (0.0-1.0) where 0.0,0.0 is top-left and 1.0,1.0 is bottom-right. Screen is ".concat(displayWidth, "x").concat(displayHeight, ".") : "Coordinates are in pixels (screen is ".concat(displayWidth, "x").concat(displayHeight, ").");
5786
+ var xDesc = quirks.normalizedCoords ? "X coordinate (0-1000 normalized)" : quirks.relativeCoords ? "X coordinate (0.0-1.0 relative, where 0.0=left edge, 1.0=right edge)" : "X coordinate in pixels (0-".concat(displayWidth, ")");
5787
+ var yDesc = quirks.normalizedCoords ? "Y coordinate (0-1000 normalized)" : quirks.relativeCoords ? "Y coordinate (0.0-1.0 relative, where 0.0=top edge, 1.0=bottom edge)" : "Y coordinate in pixels (0-".concat(displayHeight, ")");
5482
5788
  return {
5483
5789
  name: "computer_call",
5484
5790
  description: "Perform a computer action. ".concat(coordDesc),
@@ -5633,11 +5939,230 @@ var convertScreenshotToolMessages = function(messages5) {
5633
5939
  return msg;
5634
5940
  });
5635
5941
  };
5942
+ var resolveApiKey = function(apiKey) {
5943
+ return _async_to_generator(function() {
5944
+ var _tmp;
5945
+ return _ts_generator(this, function(_state) {
5946
+ switch(_state.label){
5947
+ case 0:
5948
+ if (!apiKey) return [
5949
+ 2,
5950
+ ""
5951
+ ];
5952
+ if (!(typeof apiKey === "function")) return [
5953
+ 3,
5954
+ 2
5955
+ ];
5956
+ return [
5957
+ 4,
5958
+ apiKey()
5959
+ ];
5960
+ case 1:
5961
+ _tmp = _state.sent();
5962
+ return [
5963
+ 3,
5964
+ 3
5965
+ ];
5966
+ case 2:
5967
+ _tmp = apiKey;
5968
+ _state.label = 3;
5969
+ case 3:
5970
+ return [
5971
+ 2,
5972
+ _tmp
5973
+ ];
5974
+ }
5975
+ });
5976
+ })();
5977
+ };
5978
+ function parseSSE(response) {
5979
+ return _wrap_async_generator(function() {
5980
+ var reader, decoder, buffer, _lines_pop, _ref, done, value, lines, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, line, trimmed, data, unused, err;
5981
+ return _ts_generator(this, function(_state) {
5982
+ switch(_state.label){
5983
+ case 0:
5984
+ reader = response.body.getReader();
5985
+ decoder = new TextDecoder();
5986
+ buffer = "";
5987
+ _state.label = 1;
5988
+ case 1:
5989
+ _state.trys.push([
5990
+ 1,
5991
+ ,
5992
+ 15,
5993
+ 16
5994
+ ]);
5995
+ _state.label = 2;
5996
+ case 2:
5997
+ if (!true) return [
5998
+ 3,
5999
+ 14
6000
+ ];
6001
+ return [
6002
+ 4,
6003
+ _await_async_generator(reader.read())
6004
+ ];
6005
+ case 3:
6006
+ _ref = _state.sent(), done = _ref.done, value = _ref.value;
6007
+ if (done) return [
6008
+ 3,
6009
+ 14
6010
+ ];
6011
+ buffer += decoder.decode(value, {
6012
+ stream: true
6013
+ });
6014
+ lines = buffer.split("\n");
6015
+ buffer = (_lines_pop = lines.pop()) !== null && _lines_pop !== void 0 ? _lines_pop : "";
6016
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6017
+ _state.label = 4;
6018
+ case 4:
6019
+ _state.trys.push([
6020
+ 4,
6021
+ 11,
6022
+ 12,
6023
+ 13
6024
+ ]);
6025
+ _iterator = lines[Symbol.iterator]();
6026
+ _state.label = 5;
6027
+ case 5:
6028
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
6029
+ 3,
6030
+ 10
6031
+ ];
6032
+ line = _step.value;
6033
+ trimmed = line.trim();
6034
+ if (!trimmed.startsWith("data: ")) return [
6035
+ 3,
6036
+ 9
6037
+ ];
6038
+ data = trimmed.slice(6);
6039
+ if (data === "[DONE]") return [
6040
+ 2
6041
+ ];
6042
+ _state.label = 6;
6043
+ case 6:
6044
+ _state.trys.push([
6045
+ 6,
6046
+ 8,
6047
+ ,
6048
+ 9
6049
+ ]);
6050
+ return [
6051
+ 4,
6052
+ JSON.parse(data)
6053
+ ];
6054
+ case 7:
6055
+ _state.sent();
6056
+ return [
6057
+ 3,
6058
+ 9
6059
+ ];
6060
+ case 8:
6061
+ unused = _state.sent();
6062
+ return [
6063
+ 3,
6064
+ 9
6065
+ ];
6066
+ case 9:
6067
+ _iteratorNormalCompletion = true;
6068
+ return [
6069
+ 3,
6070
+ 5
6071
+ ];
6072
+ case 10:
6073
+ return [
6074
+ 3,
6075
+ 13
6076
+ ];
6077
+ case 11:
6078
+ err = _state.sent();
6079
+ _didIteratorError = true;
6080
+ _iteratorError = err;
6081
+ return [
6082
+ 3,
6083
+ 13
6084
+ ];
6085
+ case 12:
6086
+ try {
6087
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
6088
+ _iterator.return();
6089
+ }
6090
+ } finally{
6091
+ if (_didIteratorError) {
6092
+ throw _iteratorError;
6093
+ }
6094
+ }
6095
+ return [
6096
+ 7
6097
+ ];
6098
+ case 13:
6099
+ return [
6100
+ 3,
6101
+ 2
6102
+ ];
6103
+ case 14:
6104
+ return [
6105
+ 3,
6106
+ 16
6107
+ ];
6108
+ case 15:
6109
+ reader.releaseLock();
6110
+ return [
6111
+ 7
6112
+ ];
6113
+ case 16:
6114
+ return [
6115
+ 2
6116
+ ];
6117
+ }
6118
+ });
6119
+ })();
6120
+ }
6121
+ var rawFetch = function(openRouter, body) {
6122
+ return _async_to_generator(function() {
6123
+ var _ref, _openRouter__baseURL, apiKey, baseURL, headers, request, httpClient;
6124
+ return _ts_generator(this, function(_state) {
6125
+ switch(_state.label){
6126
+ case 0:
6127
+ return [
6128
+ 4,
6129
+ resolveApiKey(openRouter._options.apiKey)
6130
+ ];
6131
+ case 1:
6132
+ apiKey = _state.sent();
6133
+ baseURL = ((_ref = (_openRouter__baseURL = openRouter._baseURL) === null || _openRouter__baseURL === void 0 ? void 0 : _openRouter__baseURL.toString()) !== null && _ref !== void 0 ? _ref : "https://openrouter.ai/api/v1").replace(/\/+$/, "");
6134
+ headers = {
6135
+ "Content-Type": "application/json",
6136
+ "Authorization": "Bearer ".concat(apiKey)
6137
+ };
6138
+ if (body.stream) {
6139
+ headers["Accept"] = "text/event-stream";
6140
+ }
6141
+ if (openRouter._options.httpReferer) {
6142
+ headers["HTTP-Referer"] = openRouter._options.httpReferer;
6143
+ }
6144
+ if (openRouter._options.xTitle) {
6145
+ headers["X-Title"] = openRouter._options.xTitle;
6146
+ }
6147
+ request = new Request("".concat(baseURL, "/chat/completions"), {
6148
+ method: "POST",
6149
+ headers: headers,
6150
+ body: JSON.stringify(body)
6151
+ });
6152
+ httpClient = openRouter._options.httpClient;
6153
+ return [
6154
+ 2,
6155
+ httpClient ? httpClient.request(request) : fetch(request)
6156
+ ];
6157
+ }
6158
+ });
6159
+ })();
6160
+ };
5636
6161
  var post10 = function(param) {
5637
6162
  var openRouter = param.openRouter;
5638
6163
  return function(_url, options) {
5639
6164
  return _async_to_generator(function() {
5640
- var body, model, _transformTools, transformedTools, computerUseConfig, resultOptions, response, shouldCleanArtifacts, stream2, displayWidth, displayHeight, stream, data, _data_choices, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, choice, _ref, _choice_message, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _data_choices1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice1, _choice_message1, error;
6165
+ var body, model, _transformTools, transformedTools, computerUseConfig, resultOptions, response, _response_headers_get, shouldCleanArtifacts, readableStream2, displayWidth, displayHeight, readableStream, response1, _response_headers_get1, data, _data_choices, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, choice, _ref, message, toolCalls, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _data_choices1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice1, message1, error;
5641
6166
  return _ts_generator(this, function(_state) {
5642
6167
  switch(_state.label){
5643
6168
  case 0:
@@ -5655,16 +6180,39 @@ var post10 = function(param) {
5655
6180
  ];
5656
6181
  return [
5657
6182
  4,
5658
- openRouter.chat.completions.create(resultOptions)
6183
+ rawFetch(openRouter, resultOptions)
5659
6184
  ];
5660
6185
  case 1:
5661
6186
  response = _state.sent();
6187
+ if (!response.ok) {
6188
+ ;
6189
+ return [
6190
+ 2,
6191
+ new Response(response.body, {
6192
+ status: response.status,
6193
+ headers: {
6194
+ "Content-Type": (_response_headers_get = response.headers.get("Content-Type")) !== null && _response_headers_get !== void 0 ? _response_headers_get : "application/json"
6195
+ }
6196
+ })
6197
+ ];
6198
+ }
5662
6199
  shouldCleanArtifacts = getQuirks(model).cleanArtifacts;
6200
+ if (!computerUseConfig && !shouldCleanArtifacts) {
6201
+ return [
6202
+ 2,
6203
+ new Response(response.body, {
6204
+ status: response.status,
6205
+ headers: {
6206
+ "Content-Type": "text/event-stream"
6207
+ }
6208
+ })
6209
+ ];
6210
+ }
5663
6211
  if (!computerUseConfig) {
5664
- stream2 = new ReadableStream({
6212
+ readableStream2 = new ReadableStream({
5665
6213
  start: function start(controller) {
5666
6214
  return _async_to_generator(function() {
5667
- var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices_, _chunk_choices, delta, err;
6215
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, delta, d, err;
5668
6216
  return _ts_generator(this, function(_state) {
5669
6217
  switch(_state.label){
5670
6218
  case 0:
@@ -5677,7 +6225,7 @@ var post10 = function(param) {
5677
6225
  7,
5678
6226
  12
5679
6227
  ]);
5680
- _iterator = _async_iterator(response);
6228
+ _iterator = _async_iterator(parseSSE(response));
5681
6229
  _state.label = 2;
5682
6230
  case 2:
5683
6231
  return [
@@ -5691,12 +6239,10 @@ var post10 = function(param) {
5691
6239
  ];
5692
6240
  _value = _step.value;
5693
6241
  chunk = _value;
5694
- if (shouldCleanArtifacts) {
5695
- ;
5696
- delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : (_chunk_choices_ = _chunk_choices[0]) === null || _chunk_choices_ === void 0 ? void 0 : _chunk_choices_.delta;
5697
- if (delta === null || delta === void 0 ? void 0 : delta.content) {
5698
- delta.content = sanitizeContent(delta.content);
5699
- }
6242
+ delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : _chunk_choices[0];
6243
+ d = delta === null || delta === void 0 ? void 0 : delta.delta;
6244
+ if ((d === null || d === void 0 ? void 0 : d.content) && typeof d.content === "string") {
6245
+ d.content = sanitizeContent(d.content);
5700
6246
  }
5701
6247
  controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
5702
6248
  _state.label = 4;
@@ -5765,7 +6311,7 @@ var post10 = function(param) {
5765
6311
  });
5766
6312
  return [
5767
6313
  2,
5768
- new Response(stream2, {
6314
+ new Response(readableStream2, {
5769
6315
  headers: {
5770
6316
  "Content-Type": "text/event-stream"
5771
6317
  }
@@ -5773,10 +6319,10 @@ var post10 = function(param) {
5773
6319
  ];
5774
6320
  }
5775
6321
  displayWidth = computerUseConfig.displayWidth, displayHeight = computerUseConfig.displayHeight;
5776
- stream = new ReadableStream({
6322
+ readableStream = new ReadableStream({
5777
6323
  start: function start(controller) {
5778
6324
  return _async_to_generator(function() {
5779
- var computerCallIndices, argumentBuffers, emittedIndices, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, _choice_delta, choices, choice, passThrough, _iteratorNormalCompletion, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, _tc_function, _ref, _tc_function1, initialArgs, denormalized, _argumentBuffers_get, _ref1, _tc_function2, buf, denormalized1, modifiedChunk, err1, _iteratorNormalCompletion1, _didIteratorError2, _iteratorError2, _iterator2, _step2, _step_value, index, buf1, denormalized2, flushChunk;
6325
+ var computerCallIndices, argumentBuffers, emittedIndices, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, toolCalls, passThrough, _iteratorNormalCompletion, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _ref, initialArgs, denormalized, _argumentBuffers_get, _ref1, buf, denormalized1, modifiedChunk, err1, _iteratorNormalCompletion1, _didIteratorError2, _iteratorError2, _iterator2, _step2, _step_value, index, buf1, denormalized2, flushChunk;
5780
6326
  return _ts_generator(this, function(_state) {
5781
6327
  switch(_state.label){
5782
6328
  case 0:
@@ -5792,7 +6338,7 @@ var post10 = function(param) {
5792
6338
  7,
5793
6339
  12
5794
6340
  ]);
5795
- _iterator = _async_iterator(response);
6341
+ _iterator = _async_iterator(parseSSE(response));
5796
6342
  _state.label = 2;
5797
6343
  case 2:
5798
6344
  return [
@@ -5808,7 +6354,9 @@ var post10 = function(param) {
5808
6354
  chunk = _value;
5809
6355
  choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
5810
6356
  choice = choices[0];
5811
- if (!(choice === null || choice === void 0 ? void 0 : (_choice_delta = choice.delta) === null || _choice_delta === void 0 ? void 0 : _choice_delta.tool_calls)) {
6357
+ delta = choice === null || choice === void 0 ? void 0 : choice.delta;
6358
+ toolCalls = delta === null || delta === void 0 ? void 0 : delta.tool_calls;
6359
+ if (!toolCalls) {
5812
6360
  controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
5813
6361
  return [
5814
6362
  3,
@@ -5818,14 +6366,13 @@ var post10 = function(param) {
5818
6366
  passThrough = [];
5819
6367
  _iteratorNormalCompletion = true, _didIteratorError1 = false, _iteratorError1 = undefined;
5820
6368
  try {
5821
- for(_iterator1 = choice.delta.tool_calls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
6369
+ for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
5822
6370
  tc = _step1.value;
5823
- ;
5824
- if (((_tc_function = tc.function) === null || _tc_function === void 0 ? void 0 : _tc_function.name) === "computer_call") {
5825
- ;
6371
+ fn = tc.function;
6372
+ if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
5826
6373
  ;
5827
6374
  computerCallIndices.add(tc.index);
5828
- initialArgs = (_ref = (_tc_function1 = tc.function) === null || _tc_function1 === void 0 ? void 0 : _tc_function1.arguments) !== null && _ref !== void 0 ? _ref : "";
6375
+ initialArgs = (_ref = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref !== void 0 ? _ref : "";
5829
6376
  argumentBuffers.set(tc.index, initialArgs);
5830
6377
  if (initialArgs) {
5831
6378
  try {
@@ -5837,7 +6384,7 @@ var post10 = function(param) {
5837
6384
  model: model
5838
6385
  });
5839
6386
  passThrough.push(_object_spread_props(_object_spread({}, tc), {
5840
- function: _object_spread_props(_object_spread({}, tc.function), {
6387
+ function: _object_spread_props(_object_spread({}, fn), {
5841
6388
  arguments: denormalized
5842
6389
  })
5843
6390
  }));
@@ -5846,7 +6393,7 @@ var post10 = function(param) {
5846
6393
  } catch (unused) {}
5847
6394
  }
5848
6395
  passThrough.push(_object_spread_props(_object_spread({}, tc), {
5849
- function: _object_spread_props(_object_spread({}, tc.function), {
6396
+ function: _object_spread_props(_object_spread({}, fn), {
5850
6397
  arguments: ""
5851
6398
  })
5852
6399
  }));
@@ -5854,8 +6401,7 @@ var post10 = function(param) {
5854
6401
  }
5855
6402
  if (computerCallIndices.has(tc.index)) {
5856
6403
  ;
5857
- ;
5858
- buf = ((_argumentBuffers_get = argumentBuffers.get(tc.index)) !== null && _argumentBuffers_get !== void 0 ? _argumentBuffers_get : "") + ((_ref1 = (_tc_function2 = tc.function) === null || _tc_function2 === void 0 ? void 0 : _tc_function2.arguments) !== null && _ref1 !== void 0 ? _ref1 : "");
6404
+ buf = ((_argumentBuffers_get = argumentBuffers.get(tc.index)) !== null && _argumentBuffers_get !== void 0 ? _argumentBuffers_get : "") + ((_ref1 = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref1 !== void 0 ? _ref1 : "");
5859
6405
  argumentBuffers.set(tc.index, buf);
5860
6406
  if (!emittedIndices.has(tc.index)) {
5861
6407
  try {
@@ -5897,7 +6443,7 @@ var post10 = function(param) {
5897
6443
  modifiedChunk = _object_spread_props(_object_spread({}, chunk), {
5898
6444
  choices: [
5899
6445
  _object_spread_props(_object_spread({}, choice), {
5900
- delta: _object_spread_props(_object_spread({}, choice.delta), {
6446
+ delta: _object_spread_props(_object_spread({}, delta), {
5901
6447
  tool_calls: passThrough
5902
6448
  })
5903
6449
  })
@@ -6017,7 +6563,7 @@ var post10 = function(param) {
6017
6563
  });
6018
6564
  return [
6019
6565
  2,
6020
- new Response(stream, {
6566
+ new Response(readableStream, {
6021
6567
  headers: {
6022
6568
  "Content-Type": "text/event-stream"
6023
6569
  }
@@ -6026,15 +6572,33 @@ var post10 = function(param) {
6026
6572
  case 2:
6027
6573
  _state.trys.push([
6028
6574
  2,
6029
- 4,
6575
+ 5,
6030
6576
  ,
6031
- 5
6577
+ 6
6032
6578
  ]);
6033
6579
  return [
6034
6580
  4,
6035
- openRouter.chat.completions.create(resultOptions)
6581
+ rawFetch(openRouter, resultOptions)
6036
6582
  ];
6037
6583
  case 3:
6584
+ response1 = _state.sent();
6585
+ if (!response1.ok) {
6586
+ ;
6587
+ return [
6588
+ 2,
6589
+ new Response(response1.body, {
6590
+ status: response1.status,
6591
+ headers: {
6592
+ "Content-Type": (_response_headers_get1 = response1.headers.get("Content-Type")) !== null && _response_headers_get1 !== void 0 ? _response_headers_get1 : "application/json"
6593
+ }
6594
+ })
6595
+ ];
6596
+ }
6597
+ return [
6598
+ 4,
6599
+ response1.json()
6600
+ ];
6601
+ case 4:
6038
6602
  data = _state.sent();
6039
6603
  if (computerUseConfig) {
6040
6604
  ;
@@ -6043,10 +6607,11 @@ var post10 = function(param) {
6043
6607
  for(_iterator = ((_data_choices = data.choices) !== null && _data_choices !== void 0 ? _data_choices : [])[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6044
6608
  choice = _step.value;
6045
6609
  ;
6046
- ;
6610
+ message = choice.message;
6611
+ toolCalls = (_ref = message === null || message === void 0 ? void 0 : message.tool_calls) !== null && _ref !== void 0 ? _ref : [];
6047
6612
  _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
6048
6613
  try {
6049
- for(_iterator1 = ((_ref = (_choice_message = choice.message) === null || _choice_message === void 0 ? void 0 : _choice_message.tool_calls) !== null && _ref !== void 0 ? _ref : [])[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
6614
+ for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
6050
6615
  tc = _step1.value;
6051
6616
  fn = tc.function;
6052
6617
  if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
@@ -6094,9 +6659,9 @@ var post10 = function(param) {
6094
6659
  try {
6095
6660
  for(_iterator2 = ((_data_choices1 = data.choices) !== null && _data_choices1 !== void 0 ? _data_choices1 : [])[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
6096
6661
  choice1 = _step2.value;
6097
- ;
6098
- if ((_choice_message1 = choice1.message) === null || _choice_message1 === void 0 ? void 0 : _choice_message1.content) {
6099
- choice1.message.content = sanitizeContent(choice1.message.content);
6662
+ message1 = choice1.message;
6663
+ if ((message1 === null || message1 === void 0 ? void 0 : message1.content) && typeof message1.content === "string") {
6664
+ message1.content = sanitizeContent(message1.content);
6100
6665
  }
6101
6666
  }
6102
6667
  } catch (err) {
@@ -6123,7 +6688,7 @@ var post10 = function(param) {
6123
6688
  }
6124
6689
  })
6125
6690
  ];
6126
- case 4:
6691
+ case 5:
6127
6692
  error = _state.sent();
6128
6693
  return [
6129
6694
  2,
@@ -6136,7 +6701,7 @@ var post10 = function(param) {
6136
6701
  }
6137
6702
  })
6138
6703
  ];
6139
- case 5:
6704
+ case 6:
6140
6705
  return [
6141
6706
  2
6142
6707
  ];