supercompat 3.17.2 → 3.17.3

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
@@ -3533,15 +3533,17 @@ var GEMINI_ACTION_NAMES = /* @__PURE__ */ new Set([
3533
3533
  "scroll_document",
3534
3534
  "drag_and_drop",
3535
3535
  "wait_5_seconds",
3536
- "wait_for_load",
3537
- "navigate",
3538
- "go_back",
3539
- "go_forward",
3540
- "open_web_browser"
3536
+ "wait_for_load"
3541
3537
  ]);
3542
3538
  var isGeminiAction = function(name) {
3543
3539
  return GEMINI_ACTION_NAMES.has(name);
3544
3540
  };
3541
+ var act = function(action) {
3542
+ return {
3543
+ action: action,
3544
+ pending_safety_checks: []
3545
+ };
3546
+ };
3545
3547
  var normalizeGeminiKey = function(key) {
3546
3548
  var lower = key.toLowerCase();
3547
3549
  switch(lower){
@@ -3595,80 +3597,89 @@ var normalizeGeminiAction = function(name, args) {
3595
3597
  switch(name){
3596
3598
  case "click_at":
3597
3599
  case "single_click_at":
3598
- return {
3599
- action: {
3600
+ return [
3601
+ act({
3600
3602
  type: "click",
3601
3603
  button: "left",
3602
3604
  x: x,
3603
3605
  y: y
3604
- },
3605
- pending_safety_checks: []
3606
- };
3606
+ })
3607
+ ];
3607
3608
  case "right_click_at":
3608
- return {
3609
- action: {
3609
+ return [
3610
+ act({
3610
3611
  type: "click",
3611
3612
  button: "right",
3612
3613
  x: x,
3613
3614
  y: y
3614
- },
3615
- pending_safety_checks: []
3616
- };
3615
+ })
3616
+ ];
3617
3617
  case "double_click_at":
3618
- return {
3619
- action: {
3618
+ return [
3619
+ act({
3620
3620
  type: "double_click",
3621
3621
  x: x,
3622
3622
  y: y
3623
- },
3624
- pending_safety_checks: []
3625
- };
3623
+ })
3624
+ ];
3626
3625
  case "triple_click_at":
3627
- return {
3628
- action: {
3626
+ return [
3627
+ act({
3629
3628
  type: "double_click",
3630
3629
  x: x,
3631
3630
  y: y,
3632
3631
  repetitions: 3
3633
- },
3634
- pending_safety_checks: []
3635
- };
3632
+ })
3633
+ ];
3636
3634
  case "hover_at":
3637
- return {
3638
- action: {
3635
+ return [
3636
+ act({
3639
3637
  type: "move",
3640
3638
  x: x,
3641
3639
  y: y
3642
- },
3643
- pending_safety_checks: []
3644
- };
3640
+ })
3641
+ ];
3645
3642
  case "type_text_at":
3646
3643
  {
3647
3644
  var text = typeof args.text === "string" ? args.text : "";
3648
- var pendingActions = [
3649
- {
3650
- type: "type",
3651
- text: text
3652
- }
3645
+ var clearBeforeTyping = args.clear_before_typing !== false;
3646
+ var pressEnter = args.press_enter !== false;
3647
+ var actions = [
3648
+ act({
3649
+ type: "click",
3650
+ button: "left",
3651
+ x: x,
3652
+ y: y
3653
+ })
3653
3654
  ];
3654
- if (args.submit_after_type === true) {
3655
- pendingActions.push({
3655
+ if (clearBeforeTyping) {
3656
+ actions.push(act({
3657
+ type: "keypress",
3658
+ keys: [
3659
+ "ctrl",
3660
+ "a"
3661
+ ]
3662
+ }));
3663
+ actions.push(act({
3664
+ type: "keypress",
3665
+ keys: [
3666
+ "Backspace"
3667
+ ]
3668
+ }));
3669
+ }
3670
+ actions.push(act({
3671
+ type: "type",
3672
+ text: text
3673
+ }));
3674
+ if (pressEnter) {
3675
+ actions.push(act({
3656
3676
  type: "keypress",
3657
3677
  keys: [
3658
3678
  "Return"
3659
3679
  ]
3660
- });
3680
+ }));
3661
3681
  }
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
- };
3682
+ return actions;
3672
3683
  }
3673
3684
  case "key_combination":
3674
3685
  {
@@ -3683,52 +3694,49 @@ var normalizeGeminiAction = function(name, args) {
3683
3694
  } else {
3684
3695
  keys = [];
3685
3696
  }
3686
- return {
3687
- action: {
3697
+ return [
3698
+ act({
3688
3699
  type: "keypress",
3689
3700
  keys: keys
3690
- },
3691
- pending_safety_checks: []
3692
- };
3701
+ })
3702
+ ];
3693
3703
  }
3694
3704
  case "scroll_at":
3695
3705
  {
3696
3706
  var direction = typeof args.direction === "string" ? args.direction : void 0;
3697
3707
  var amount = typeof args.amount === "number" ? args.amount : 3;
3698
3708
  var _scrollFromDirection = scrollFromDirection(direction, amount), scroll_x = _scrollFromDirection.scroll_x, scroll_y = _scrollFromDirection.scroll_y;
3699
- return {
3700
- action: {
3709
+ return [
3710
+ act({
3701
3711
  type: "scroll",
3702
3712
  x: x,
3703
3713
  y: y,
3704
3714
  scroll_x: scroll_x,
3705
3715
  scroll_y: scroll_y
3706
- },
3707
- pending_safety_checks: []
3708
- };
3716
+ })
3717
+ ];
3709
3718
  }
3710
3719
  case "scroll_document":
3711
3720
  {
3712
3721
  var direction1 = typeof args.direction === "string" ? args.direction : void 0;
3713
3722
  var amount1 = typeof args.amount === "number" ? args.amount : 3;
3714
3723
  var _scrollFromDirection1 = scrollFromDirection(direction1, amount1), scroll_x1 = _scrollFromDirection1.scroll_x, scroll_y1 = _scrollFromDirection1.scroll_y;
3715
- return {
3716
- action: {
3724
+ return [
3725
+ act({
3717
3726
  type: "scroll",
3718
3727
  x: 640,
3719
3728
  y: 360,
3720
3729
  scroll_x: scroll_x1,
3721
3730
  scroll_y: scroll_y1
3722
- },
3723
- pending_safety_checks: []
3724
- };
3731
+ })
3732
+ ];
3725
3733
  }
3726
3734
  case "drag_and_drop":
3727
3735
  {
3728
3736
  var destX = typeof args.destination_x === "number" ? args.destination_x : 0;
3729
3737
  var destY = typeof args.destination_y === "number" ? args.destination_y : 0;
3730
- return {
3731
- action: {
3738
+ return [
3739
+ act({
3732
3740
  type: "drag",
3733
3741
  path: [
3734
3742
  {
@@ -3740,86 +3748,24 @@ var normalizeGeminiAction = function(name, args) {
3740
3748
  y: destY
3741
3749
  }
3742
3750
  ]
3743
- },
3744
- pending_safety_checks: []
3745
- };
3751
+ })
3752
+ ];
3746
3753
  }
3747
3754
  case "wait_5_seconds":
3748
3755
  case "wait_for_load":
3749
- return {
3750
- action: {
3756
+ return [
3757
+ act({
3751
3758
  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
- };
3759
+ })
3760
+ ];
3761
+ // navigate, go_back, go_forward, open_web_browser, search are excluded
3762
+ // via excludedPredefinedFunctions in the tool config
3816
3763
  default:
3817
- return {
3818
- action: _object_spread({
3764
+ return [
3765
+ act(_object_spread({
3819
3766
  type: name
3820
- }, args),
3821
- pending_safety_checks: []
3822
- };
3767
+ }, args))
3768
+ ];
3823
3769
  }
3824
3770
  };
3825
3771
  // src/adapters/client/googleClientAdapter/completions/post.ts
@@ -3863,6 +3809,9 @@ var serializeMessages2 = function(messages5) {
3863
3809
  var systemParts = [];
3864
3810
  var contents = [];
3865
3811
  var toolCallIdToName = /* @__PURE__ */ new Map();
3812
+ var geminiCallGroups = /* @__PURE__ */ new Map();
3813
+ var skipToolResultIds = /* @__PURE__ */ new Set();
3814
+ var lastSubActionMap = /* @__PURE__ */ new Map();
3866
3815
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3867
3816
  try {
3868
3817
  for(var _iterator = messages5[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -3959,9 +3908,42 @@ var serializeMessages2 = function(messages5) {
3959
3908
  } catch (unused) {}
3960
3909
  var thoughtSignature = args._thoughtSignature;
3961
3910
  var geminiActionName = args._geminiAction;
3911
+ var geminiCallId = args._geminiCallId;
3912
+ var subActionIndex = args._subActionIndex;
3913
+ var subActionTotal = args._subActionTotal;
3914
+ var geminiOrigArgs = args._geminiArgs;
3962
3915
  var cleanArgs = _object_spread({}, args);
3963
3916
  delete cleanArgs._thoughtSignature;
3964
3917
  delete cleanArgs._geminiAction;
3918
+ delete cleanArgs._geminiCallId;
3919
+ delete cleanArgs._subActionIndex;
3920
+ delete cleanArgs._subActionTotal;
3921
+ delete cleanArgs._geminiArgs;
3922
+ if (geminiCallId && typeof subActionIndex === "number" && typeof subActionTotal === "number") {
3923
+ if (subActionIndex === 0) {
3924
+ var fcName = geminiActionName !== null && geminiActionName !== void 0 ? geminiActionName : name;
3925
+ geminiCallGroups.set(geminiCallId, {
3926
+ name: fcName,
3927
+ primaryId: id
3928
+ });
3929
+ toolCallIdToName.set(id, fcName);
3930
+ if (subActionTotal > 1) skipToolResultIds.add(id);
3931
+ var fcPart2 = {
3932
+ functionCall: {
3933
+ name: fcName,
3934
+ args: geminiOrigArgs !== null && geminiOrigArgs !== void 0 ? geminiOrigArgs : {},
3935
+ id: id
3936
+ }
3937
+ };
3938
+ if (thoughtSignature) fcPart2.thoughtSignature = thoughtSignature;
3939
+ parts1.push(fcPart2);
3940
+ } else if (subActionIndex === subActionTotal - 1) {
3941
+ lastSubActionMap.set(id, geminiCallId);
3942
+ } else {
3943
+ skipToolResultIds.add(id);
3944
+ }
3945
+ continue;
3946
+ }
3965
3947
  var geminiName = name;
3966
3948
  if (name === "computer_call" && args.action && _type_of(args.action) === "object") {
3967
3949
  var _ref2;
@@ -3970,9 +3952,8 @@ var serializeMessages2 = function(messages5) {
3970
3952
  var geminiArgs = void 0;
3971
3953
  if (name === "computer_call" && cleanArgs.action && _type_of(cleanArgs.action) === "object") {
3972
3954
  var action = cleanArgs.action;
3973
- var _type = action.type, _pa = action.pending_actions, rest = _object_without_properties(action, [
3974
- "type",
3975
- "pending_actions"
3955
+ var _type = action.type, rest = _object_without_properties(action, [
3956
+ "type"
3976
3957
  ]);
3977
3958
  geminiArgs = rest;
3978
3959
  } else {
@@ -4015,10 +3996,22 @@ var serializeMessages2 = function(messages5) {
4015
3996
  continue;
4016
3997
  }
4017
3998
  if (msg.role === "tool") {
4018
- var _msg_tool_call_id, _toolCallIdToName_get;
3999
+ var _msg_tool_call_id;
4019
4000
  var _lastContent_parts;
4020
4001
  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 : "";
4002
+ if (skipToolResultIds.has(toolCallId)) continue;
4003
+ var responseName = void 0;
4004
+ var responseId2 = void 0;
4005
+ if (lastSubActionMap.has(toolCallId)) {
4006
+ var gcId = lastSubActionMap.get(toolCallId);
4007
+ var group = geminiCallGroups.get(gcId);
4008
+ responseName = group.name;
4009
+ responseId2 = group.primaryId;
4010
+ } else {
4011
+ var _toolCallIdToName_get;
4012
+ responseName = (_toolCallIdToName_get = toolCallIdToName.get(toolCallId)) !== null && _toolCallIdToName_get !== void 0 ? _toolCallIdToName_get : "";
4013
+ responseId2 = toolCallId;
4014
+ }
4022
4015
  var parts2 = [];
4023
4016
  var imageContent = extractImageFromToolMessage(msg);
4024
4017
  if (imageContent) {
@@ -4032,8 +4025,8 @@ var serializeMessages2 = function(messages5) {
4032
4025
  ];
4033
4026
  parts2.push({
4034
4027
  functionResponse: {
4035
- id: toolCallId,
4036
- name: name1,
4028
+ id: responseId2,
4029
+ name: responseName,
4037
4030
  response: {
4038
4031
  output: "Screenshot captured."
4039
4032
  },
@@ -4044,8 +4037,8 @@ var serializeMessages2 = function(messages5) {
4044
4037
  var output = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
4045
4038
  parts2.push({
4046
4039
  functionResponse: {
4047
- id: toolCallId,
4048
- name: name1,
4040
+ id: responseId2,
4041
+ name: responseName,
4049
4042
  response: {
4050
4043
  output: output
4051
4044
  }
@@ -4180,7 +4173,14 @@ var serializeTools2 = function(tools) {
4180
4173
  if (computerUseEnabled) {
4181
4174
  geminiTools.push({
4182
4175
  computerUse: {
4183
- environment: "ENVIRONMENT_BROWSER"
4176
+ environment: "ENVIRONMENT_BROWSER",
4177
+ excludedPredefinedFunctions: [
4178
+ "navigate",
4179
+ "go_back",
4180
+ "go_forward",
4181
+ "search",
4182
+ "open_web_browser"
4183
+ ]
4184
4184
  }
4185
4185
  });
4186
4186
  }
@@ -4238,56 +4238,194 @@ var isComputerUseFunction = function(name, tools) {
4238
4238
  var userFns = getUserDefinedFunctionNames(tools);
4239
4239
  return !userFns.has(name);
4240
4240
  };
4241
- var functionCallToToolCallDelta = function(fc, index, tools, thoughtSignature) {
4241
+ var functionCallToToolCallDeltas = function(fc, startIndex, tools, thoughtSignature) {
4242
4242
  var _fc_name, _fc_args, _fc_id;
4243
4243
  var rawName = (_fc_name = fc.name) !== null && _fc_name !== void 0 ? _fc_name : "";
4244
4244
  var name = stripFunctionPrefix(rawName);
4245
4245
  if (isComputerUseFunction(name, tools)) {
4246
4246
  var _fc_args1, _fc_id1;
4247
4247
  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), {
4248
+ if (isGeminiAction(name)) {
4249
+ var normalizedActions = normalizeGeminiAction(name, denormed);
4250
+ if (normalizedActions.length === 1) {
4251
+ var _fc_id2;
4252
+ var payload2 = _object_spread({}, normalizedActions[0]);
4253
+ payload2._geminiAction = name;
4254
+ if (thoughtSignature) payload2._thoughtSignature = thoughtSignature;
4255
+ return [
4256
+ {
4257
+ index: startIndex,
4258
+ id: (_fc_id2 = fc.id) !== null && _fc_id2 !== void 0 ? _fc_id2 : "call_".concat((0, import_cuid2.createId)()),
4259
+ type: "function",
4260
+ function: {
4261
+ name: "computer_call",
4262
+ arguments: JSON.stringify(payload2)
4263
+ }
4264
+ }
4265
+ ];
4266
+ }
4267
+ var geminiCallId = "gcall_".concat((0, import_cuid2.createId)());
4268
+ return normalizedActions.map(function(normalized2, i) {
4269
+ var _fc_id;
4270
+ var payload2 = _object_spread({}, normalized2);
4271
+ payload2._geminiCallId = geminiCallId;
4272
+ payload2._geminiAction = name;
4273
+ payload2._subActionIndex = i;
4274
+ payload2._subActionTotal = normalizedActions.length;
4275
+ if (i === 0) {
4276
+ payload2._geminiArgs = denormed;
4277
+ if (thoughtSignature) payload2._thoughtSignature = thoughtSignature;
4278
+ }
4279
+ return {
4280
+ index: startIndex + i,
4281
+ 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)()),
4282
+ type: "function",
4283
+ function: {
4284
+ name: "computer_call",
4285
+ arguments: JSON.stringify(payload2)
4286
+ }
4287
+ };
4288
+ });
4289
+ }
4290
+ var normalized = normalizeComputerToolCallPayload(_object_spread_props(_object_spread({}, denormed), {
4249
4291
  type: name
4250
4292
  }));
4251
4293
  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)
4294
+ if (thoughtSignature) payload._thoughtSignature = thoughtSignature;
4295
+ return [
4296
+ {
4297
+ index: startIndex,
4298
+ id: (_fc_id1 = fc.id) !== null && _fc_id1 !== void 0 ? _fc_id1 : "call_".concat((0, import_cuid2.createId)()),
4299
+ type: "function",
4300
+ function: {
4301
+ name: "computer_call",
4302
+ arguments: JSON.stringify(payload)
4303
+ }
4265
4304
  }
4266
- };
4305
+ ];
4267
4306
  }
4268
4307
  var args = (_fc_args = fc.args) !== null && _fc_args !== void 0 ? _fc_args : {};
4269
4308
  if (thoughtSignature) {
4270
4309
  args._thoughtSignature = thoughtSignature;
4271
4310
  }
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)
4311
+ return [
4312
+ {
4313
+ index: startIndex,
4314
+ id: (_fc_id = fc.id) !== null && _fc_id !== void 0 ? _fc_id : "call_".concat((0, import_cuid2.createId)()),
4315
+ type: "function",
4316
+ function: {
4317
+ name: name,
4318
+ arguments: JSON.stringify(args)
4319
+ }
4279
4320
  }
4280
- };
4321
+ ];
4322
+ };
4323
+ var syntheticToolCallResponse = function(toolCallDelta, stream) {
4324
+ var delta = _object_spread_props(_object_spread({}, toolCallDelta), {
4325
+ index: 0
4326
+ });
4327
+ var encoder = new TextEncoder();
4328
+ if (stream) {
4329
+ var chunks = [
4330
+ "data: ".concat(JSON.stringify({
4331
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4332
+ object: "chat.completion.chunk",
4333
+ choices: [
4334
+ {
4335
+ index: 0,
4336
+ delta: {
4337
+ content: null,
4338
+ tool_calls: [
4339
+ delta
4340
+ ]
4341
+ }
4342
+ }
4343
+ ]
4344
+ }), "\n\n"),
4345
+ "data: ".concat(JSON.stringify({
4346
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4347
+ object: "chat.completion.chunk",
4348
+ choices: [
4349
+ {
4350
+ index: 0,
4351
+ delta: {},
4352
+ finish_reason: "stop"
4353
+ }
4354
+ ]
4355
+ }), "\n\n")
4356
+ ];
4357
+ return new Response(new ReadableStream({
4358
+ start: function start(controller) {
4359
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4360
+ try {
4361
+ for(var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4362
+ var chunk = _step.value;
4363
+ controller.enqueue(encoder.encode(chunk));
4364
+ }
4365
+ } catch (err) {
4366
+ _didIteratorError = true;
4367
+ _iteratorError = err;
4368
+ } finally{
4369
+ try {
4370
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
4371
+ _iterator.return();
4372
+ }
4373
+ } finally{
4374
+ if (_didIteratorError) {
4375
+ throw _iteratorError;
4376
+ }
4377
+ }
4378
+ }
4379
+ controller.close();
4380
+ }
4381
+ }), {
4382
+ headers: {
4383
+ "Content-Type": "text/event-stream"
4384
+ }
4385
+ });
4386
+ }
4387
+ return new Response(JSON.stringify({
4388
+ data: {
4389
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4390
+ object: "chat.completion",
4391
+ choices: [
4392
+ {
4393
+ index: 0,
4394
+ message: {
4395
+ role: "assistant",
4396
+ content: null,
4397
+ tool_calls: [
4398
+ delta
4399
+ ]
4400
+ },
4401
+ finish_reason: "stop"
4402
+ }
4403
+ ]
4404
+ }
4405
+ }), {
4406
+ status: 200,
4407
+ headers: {
4408
+ "Content-Type": "application/json"
4409
+ }
4410
+ });
4281
4411
  };
4282
4412
  var post7 = function(param) {
4283
4413
  var google = param.google;
4414
+ var pendingSubActions = [];
4284
4415
  return function(_url, options) {
4285
4416
  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;
4417
+ 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
4418
  return _ts_generator(this, function(_state) {
4288
4419
  switch(_state.label){
4289
4420
  case 0:
4290
4421
  body = JSON.parse(options.body);
4422
+ if (pendingSubActions.length > 0) {
4423
+ next = pendingSubActions.shift();
4424
+ return [
4425
+ 2,
4426
+ syntheticToolCallResponse(next, !!body.stream)
4427
+ ];
4428
+ }
4291
4429
  messages5 = nonEmptyMessages({
4292
4430
  messages: body.messages
4293
4431
  });
@@ -4321,7 +4459,7 @@ var post7 = function(param) {
4321
4459
  stream = new ReadableStream({
4322
4460
  start: function start(controller) {
4323
4461
  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;
4462
+ 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
4463
  return _ts_generator(this, function(_state) {
4326
4464
  switch(_state.label){
4327
4465
  case 0:
@@ -4378,24 +4516,50 @@ var post7 = function(param) {
4378
4516
  controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
4379
4517
  }
4380
4518
  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
- }
4519
+ deltas = functionCallToToolCallDeltas(part.functionCall, chunkIndex, body.tools, lastThoughtSignature);
4520
+ emitDeltas = deltas.length > 1 ? [
4521
+ deltas[0]
4522
+ ] : deltas;
4523
+ if (deltas.length > 1) {
4524
+ ;
4525
+ (_pendingSubActions = pendingSubActions).push.apply(_pendingSubActions, _to_consumable_array(deltas.slice(1)));
4526
+ }
4527
+ _iteratorNormalCompletion1 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
4528
+ try {
4529
+ for(_iterator2 = emitDeltas[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
4530
+ toolCallDelta = _step2.value;
4531
+ messageDelta1 = {
4532
+ id: "chatcmpl-".concat((0, import_radash5.uid)(29)),
4533
+ object: "chat.completion.chunk",
4534
+ choices: [
4535
+ {
4536
+ index: 0,
4537
+ delta: {
4538
+ content: null,
4539
+ tool_calls: [
4540
+ toolCallDelta
4541
+ ]
4542
+ }
4543
+ }
4544
+ ]
4545
+ };
4546
+ controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
4547
+ }
4548
+ } catch (err) {
4549
+ _didIteratorError2 = true;
4550
+ _iteratorError2 = err;
4551
+ } finally{
4552
+ try {
4553
+ if (!_iteratorNormalCompletion1 && _iterator2.return != null) {
4554
+ _iterator2.return();
4394
4555
  }
4395
- ]
4396
- };
4397
- controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
4398
- chunkIndex++;
4556
+ } finally{
4557
+ if (_didIteratorError2) {
4558
+ throw _iteratorError2;
4559
+ }
4560
+ }
4561
+ }
4562
+ chunkIndex += emitDeltas.length;
4399
4563
  lastThoughtSignature = void 0;
4400
4564
  }
4401
4565
  }
@@ -4528,7 +4692,15 @@ var post7 = function(param) {
4528
4692
  lastSig = p.thoughtSignature;
4529
4693
  }
4530
4694
  if (p.functionCall) {
4531
- toolCalls.push(functionCallToToolCallDelta(p.functionCall, toolCalls.length, body.tools, lastSig));
4695
+ deltas = functionCallToToolCallDeltas(p.functionCall, toolCalls.length, body.tools, lastSig);
4696
+ if (deltas.length > 1) {
4697
+ ;
4698
+ toolCalls.push(deltas[0]);
4699
+ (_pendingSubActions = pendingSubActions).push.apply(_pendingSubActions, _to_consumable_array(deltas.slice(1)));
4700
+ } else {
4701
+ ;
4702
+ (_toolCalls = toolCalls).push.apply(_toolCalls, _to_consumable_array(deltas));
4703
+ }
4532
4704
  lastSig = void 0;
4533
4705
  }
4534
4706
  }
@@ -5131,6 +5303,12 @@ var MODEL_QUIRKS = {
5131
5303
  },
5132
5304
  "qwen/": {
5133
5305
  fuzzyFallback: true
5306
+ },
5307
+ "moonshotai/kimi-k2.5": {
5308
+ relativeCoords: {
5309
+ referenceWidth: 1920,
5310
+ referenceHeight: 1080
5311
+ }
5134
5312
  }
5135
5313
  };
5136
5314
  var getQuirks = function(model) {
@@ -5359,6 +5537,32 @@ var denormalizeAction = function(action, displayWidth, displayHeight) {
5359
5537
  }
5360
5538
  return result;
5361
5539
  };
5540
+ var rescaleCoord = function(value, displayDim, referenceDim) {
5541
+ if (value <= 1) return Math.round(value * displayDim);
5542
+ return Math.round(value / referenceDim * displayDim);
5543
+ };
5544
+ var rescaleRelativeAction = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
5545
+ var result = _object_spread({}, action);
5546
+ if (typeof result.x === "number") {
5547
+ result.x = rescaleCoord(result.x, displayWidth, referenceWidth);
5548
+ }
5549
+ if (typeof result.y === "number") {
5550
+ result.y = rescaleCoord(result.y, displayHeight, referenceHeight);
5551
+ }
5552
+ if (Array.isArray(result.path)) {
5553
+ result.path = result.path.map(function(point) {
5554
+ if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
5555
+ return _object_spread({}, point, typeof point.x === "number" ? {
5556
+ x: rescaleCoord(point.x, displayWidth, referenceWidth)
5557
+ } : {}, typeof point.y === "number" ? {
5558
+ y: rescaleCoord(point.y, displayHeight, referenceHeight)
5559
+ } : {});
5560
+ }
5561
+ return point;
5562
+ });
5563
+ }
5564
+ return result;
5565
+ };
5362
5566
  var COORD_FIELDS = [
5363
5567
  "x",
5364
5568
  "y",
@@ -5471,14 +5675,19 @@ var denormalizeComputerCallArguments = function(param) {
5471
5675
  action: denormalizeAction(normalized.action, displayWidth, displayHeight)
5472
5676
  }));
5473
5677
  }
5678
+ if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
5679
+ return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
5680
+ action: rescaleRelativeAction(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
5681
+ }));
5682
+ }
5474
5683
  return JSON.stringify(normalized);
5475
5684
  };
5476
5685
  // src/adapters/client/openRouterClientAdapter/completions/computerUseTool.ts
5477
5686
  var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
5478
5687
  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, ")");
5688
+ 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, ").");
5689
+ 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, ")");
5690
+ 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
5691
  return {
5483
5692
  name: "computer_call",
5484
5693
  description: "Perform a computer action. ".concat(coordDesc),