supercompat 3.17.1 → 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 +576 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +576 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3519,6 +3519,256 @@ var models9 = function(param) {
|
|
|
3519
3519
|
// src/adapters/client/googleClientAdapter/completions/post.ts
|
|
3520
3520
|
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
3521
3521
|
var import_radash5 = require("radash");
|
|
3522
|
+
// src/adapters/client/googleClientAdapter/normalizeGeminiAction.ts
|
|
3523
|
+
var GEMINI_ACTION_NAMES = /* @__PURE__ */ new Set([
|
|
3524
|
+
"click_at",
|
|
3525
|
+
"single_click_at",
|
|
3526
|
+
"right_click_at",
|
|
3527
|
+
"double_click_at",
|
|
3528
|
+
"triple_click_at",
|
|
3529
|
+
"hover_at",
|
|
3530
|
+
"type_text_at",
|
|
3531
|
+
"key_combination",
|
|
3532
|
+
"scroll_at",
|
|
3533
|
+
"scroll_document",
|
|
3534
|
+
"drag_and_drop",
|
|
3535
|
+
"wait_5_seconds",
|
|
3536
|
+
"wait_for_load"
|
|
3537
|
+
]);
|
|
3538
|
+
var isGeminiAction = function(name) {
|
|
3539
|
+
return GEMINI_ACTION_NAMES.has(name);
|
|
3540
|
+
};
|
|
3541
|
+
var act = function(action) {
|
|
3542
|
+
return {
|
|
3543
|
+
action: action,
|
|
3544
|
+
pending_safety_checks: []
|
|
3545
|
+
};
|
|
3546
|
+
};
|
|
3547
|
+
var normalizeGeminiKey = function(key) {
|
|
3548
|
+
var lower = key.toLowerCase();
|
|
3549
|
+
switch(lower){
|
|
3550
|
+
case "control":
|
|
3551
|
+
return "ctrl";
|
|
3552
|
+
case "command":
|
|
3553
|
+
case "cmd":
|
|
3554
|
+
return "meta";
|
|
3555
|
+
case "option":
|
|
3556
|
+
return "alt";
|
|
3557
|
+
default:
|
|
3558
|
+
return lower;
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
var scrollFromDirection = function(direction, amount) {
|
|
3562
|
+
if (!direction) return {
|
|
3563
|
+
scroll_x: 0,
|
|
3564
|
+
scroll_y: 0
|
|
3565
|
+
};
|
|
3566
|
+
switch(direction.toLowerCase()){
|
|
3567
|
+
case "up":
|
|
3568
|
+
return {
|
|
3569
|
+
scroll_x: 0,
|
|
3570
|
+
scroll_y: -amount
|
|
3571
|
+
};
|
|
3572
|
+
case "down":
|
|
3573
|
+
return {
|
|
3574
|
+
scroll_x: 0,
|
|
3575
|
+
scroll_y: amount
|
|
3576
|
+
};
|
|
3577
|
+
case "left":
|
|
3578
|
+
return {
|
|
3579
|
+
scroll_x: -amount,
|
|
3580
|
+
scroll_y: 0
|
|
3581
|
+
};
|
|
3582
|
+
case "right":
|
|
3583
|
+
return {
|
|
3584
|
+
scroll_x: amount,
|
|
3585
|
+
scroll_y: 0
|
|
3586
|
+
};
|
|
3587
|
+
default:
|
|
3588
|
+
return {
|
|
3589
|
+
scroll_x: 0,
|
|
3590
|
+
scroll_y: 0
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
};
|
|
3594
|
+
var normalizeGeminiAction = function(name, args) {
|
|
3595
|
+
var x = typeof args.x === "number" ? args.x : typeof args.coordinate_x === "number" ? args.coordinate_x : 0;
|
|
3596
|
+
var y = typeof args.y === "number" ? args.y : typeof args.coordinate_y === "number" ? args.coordinate_y : 0;
|
|
3597
|
+
switch(name){
|
|
3598
|
+
case "click_at":
|
|
3599
|
+
case "single_click_at":
|
|
3600
|
+
return [
|
|
3601
|
+
act({
|
|
3602
|
+
type: "click",
|
|
3603
|
+
button: "left",
|
|
3604
|
+
x: x,
|
|
3605
|
+
y: y
|
|
3606
|
+
})
|
|
3607
|
+
];
|
|
3608
|
+
case "right_click_at":
|
|
3609
|
+
return [
|
|
3610
|
+
act({
|
|
3611
|
+
type: "click",
|
|
3612
|
+
button: "right",
|
|
3613
|
+
x: x,
|
|
3614
|
+
y: y
|
|
3615
|
+
})
|
|
3616
|
+
];
|
|
3617
|
+
case "double_click_at":
|
|
3618
|
+
return [
|
|
3619
|
+
act({
|
|
3620
|
+
type: "double_click",
|
|
3621
|
+
x: x,
|
|
3622
|
+
y: y
|
|
3623
|
+
})
|
|
3624
|
+
];
|
|
3625
|
+
case "triple_click_at":
|
|
3626
|
+
return [
|
|
3627
|
+
act({
|
|
3628
|
+
type: "double_click",
|
|
3629
|
+
x: x,
|
|
3630
|
+
y: y,
|
|
3631
|
+
repetitions: 3
|
|
3632
|
+
})
|
|
3633
|
+
];
|
|
3634
|
+
case "hover_at":
|
|
3635
|
+
return [
|
|
3636
|
+
act({
|
|
3637
|
+
type: "move",
|
|
3638
|
+
x: x,
|
|
3639
|
+
y: y
|
|
3640
|
+
})
|
|
3641
|
+
];
|
|
3642
|
+
case "type_text_at":
|
|
3643
|
+
{
|
|
3644
|
+
var text = typeof args.text === "string" ? args.text : "";
|
|
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
|
+
})
|
|
3654
|
+
];
|
|
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({
|
|
3676
|
+
type: "keypress",
|
|
3677
|
+
keys: [
|
|
3678
|
+
"Return"
|
|
3679
|
+
]
|
|
3680
|
+
}));
|
|
3681
|
+
}
|
|
3682
|
+
return actions;
|
|
3683
|
+
}
|
|
3684
|
+
case "key_combination":
|
|
3685
|
+
{
|
|
3686
|
+
var rawKeys = args.keys;
|
|
3687
|
+
var keys;
|
|
3688
|
+
if (Array.isArray(rawKeys)) {
|
|
3689
|
+
keys = rawKeys.map(String).map(normalizeGeminiKey);
|
|
3690
|
+
} else if (typeof rawKeys === "string") {
|
|
3691
|
+
keys = rawKeys.split(/[+\s]+/).map(function(k) {
|
|
3692
|
+
return k.trim();
|
|
3693
|
+
}).filter(Boolean).map(normalizeGeminiKey);
|
|
3694
|
+
} else {
|
|
3695
|
+
keys = [];
|
|
3696
|
+
}
|
|
3697
|
+
return [
|
|
3698
|
+
act({
|
|
3699
|
+
type: "keypress",
|
|
3700
|
+
keys: keys
|
|
3701
|
+
})
|
|
3702
|
+
];
|
|
3703
|
+
}
|
|
3704
|
+
case "scroll_at":
|
|
3705
|
+
{
|
|
3706
|
+
var direction = typeof args.direction === "string" ? args.direction : void 0;
|
|
3707
|
+
var amount = typeof args.amount === "number" ? args.amount : 3;
|
|
3708
|
+
var _scrollFromDirection = scrollFromDirection(direction, amount), scroll_x = _scrollFromDirection.scroll_x, scroll_y = _scrollFromDirection.scroll_y;
|
|
3709
|
+
return [
|
|
3710
|
+
act({
|
|
3711
|
+
type: "scroll",
|
|
3712
|
+
x: x,
|
|
3713
|
+
y: y,
|
|
3714
|
+
scroll_x: scroll_x,
|
|
3715
|
+
scroll_y: scroll_y
|
|
3716
|
+
})
|
|
3717
|
+
];
|
|
3718
|
+
}
|
|
3719
|
+
case "scroll_document":
|
|
3720
|
+
{
|
|
3721
|
+
var direction1 = typeof args.direction === "string" ? args.direction : void 0;
|
|
3722
|
+
var amount1 = typeof args.amount === "number" ? args.amount : 3;
|
|
3723
|
+
var _scrollFromDirection1 = scrollFromDirection(direction1, amount1), scroll_x1 = _scrollFromDirection1.scroll_x, scroll_y1 = _scrollFromDirection1.scroll_y;
|
|
3724
|
+
return [
|
|
3725
|
+
act({
|
|
3726
|
+
type: "scroll",
|
|
3727
|
+
x: 640,
|
|
3728
|
+
y: 360,
|
|
3729
|
+
scroll_x: scroll_x1,
|
|
3730
|
+
scroll_y: scroll_y1
|
|
3731
|
+
})
|
|
3732
|
+
];
|
|
3733
|
+
}
|
|
3734
|
+
case "drag_and_drop":
|
|
3735
|
+
{
|
|
3736
|
+
var destX = typeof args.destination_x === "number" ? args.destination_x : 0;
|
|
3737
|
+
var destY = typeof args.destination_y === "number" ? args.destination_y : 0;
|
|
3738
|
+
return [
|
|
3739
|
+
act({
|
|
3740
|
+
type: "drag",
|
|
3741
|
+
path: [
|
|
3742
|
+
{
|
|
3743
|
+
x: x,
|
|
3744
|
+
y: y
|
|
3745
|
+
},
|
|
3746
|
+
{
|
|
3747
|
+
x: destX,
|
|
3748
|
+
y: destY
|
|
3749
|
+
}
|
|
3750
|
+
]
|
|
3751
|
+
})
|
|
3752
|
+
];
|
|
3753
|
+
}
|
|
3754
|
+
case "wait_5_seconds":
|
|
3755
|
+
case "wait_for_load":
|
|
3756
|
+
return [
|
|
3757
|
+
act({
|
|
3758
|
+
type: "wait"
|
|
3759
|
+
})
|
|
3760
|
+
];
|
|
3761
|
+
// navigate, go_back, go_forward, open_web_browser, search are excluded
|
|
3762
|
+
// via excludedPredefinedFunctions in the tool config
|
|
3763
|
+
default:
|
|
3764
|
+
return [
|
|
3765
|
+
act(_object_spread({
|
|
3766
|
+
type: name
|
|
3767
|
+
}, args))
|
|
3768
|
+
];
|
|
3769
|
+
}
|
|
3770
|
+
};
|
|
3771
|
+
// src/adapters/client/googleClientAdapter/completions/post.ts
|
|
3522
3772
|
var stripFunctionPrefix = function(name) {
|
|
3523
3773
|
return name.replace(/^default_api:/, "");
|
|
3524
3774
|
};
|
|
@@ -3559,6 +3809,9 @@ var serializeMessages2 = function(messages5) {
|
|
|
3559
3809
|
var systemParts = [];
|
|
3560
3810
|
var contents = [];
|
|
3561
3811
|
var toolCallIdToName = /* @__PURE__ */ new Map();
|
|
3812
|
+
var geminiCallGroups = /* @__PURE__ */ new Map();
|
|
3813
|
+
var skipToolResultIds = /* @__PURE__ */ new Set();
|
|
3814
|
+
var lastSubActionMap = /* @__PURE__ */ new Map();
|
|
3562
3815
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
3563
3816
|
try {
|
|
3564
3817
|
for(var _iterator = messages5[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
@@ -3653,14 +3906,49 @@ var serializeMessages2 = function(messages5) {
|
|
|
3653
3906
|
var _tc_function1;
|
|
3654
3907
|
args = JSON.parse((_ref1 = (_tc_function1 = tc.function) === null || _tc_function1 === void 0 ? void 0 : _tc_function1.arguments) !== null && _ref1 !== void 0 ? _ref1 : "{}");
|
|
3655
3908
|
} catch (unused) {}
|
|
3656
|
-
var geminiName = name;
|
|
3657
|
-
if (name === "computer_call" && args.action && _type_of(args.action) === "object") {
|
|
3658
|
-
var _args_action_type;
|
|
3659
|
-
geminiName = (_args_action_type = args.action.type) !== null && _args_action_type !== void 0 ? _args_action_type : name;
|
|
3660
|
-
}
|
|
3661
3909
|
var thoughtSignature = args._thoughtSignature;
|
|
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;
|
|
3662
3915
|
var cleanArgs = _object_spread({}, args);
|
|
3663
3916
|
delete cleanArgs._thoughtSignature;
|
|
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
|
+
}
|
|
3947
|
+
var geminiName = name;
|
|
3948
|
+
if (name === "computer_call" && args.action && _type_of(args.action) === "object") {
|
|
3949
|
+
var _ref2;
|
|
3950
|
+
geminiName = (_ref2 = geminiActionName !== null && geminiActionName !== void 0 ? geminiActionName : args.action.type) !== null && _ref2 !== void 0 ? _ref2 : name;
|
|
3951
|
+
}
|
|
3664
3952
|
var geminiArgs = void 0;
|
|
3665
3953
|
if (name === "computer_call" && cleanArgs.action && _type_of(cleanArgs.action) === "object") {
|
|
3666
3954
|
var action = cleanArgs.action;
|
|
@@ -3708,10 +3996,22 @@ var serializeMessages2 = function(messages5) {
|
|
|
3708
3996
|
continue;
|
|
3709
3997
|
}
|
|
3710
3998
|
if (msg.role === "tool") {
|
|
3711
|
-
var _msg_tool_call_id
|
|
3999
|
+
var _msg_tool_call_id;
|
|
3712
4000
|
var _lastContent_parts;
|
|
3713
4001
|
var toolCallId = (_msg_tool_call_id = msg.tool_call_id) !== null && _msg_tool_call_id !== void 0 ? _msg_tool_call_id : "";
|
|
3714
|
-
|
|
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
|
+
}
|
|
3715
4015
|
var parts2 = [];
|
|
3716
4016
|
var imageContent = extractImageFromToolMessage(msg);
|
|
3717
4017
|
if (imageContent) {
|
|
@@ -3725,8 +4025,8 @@ var serializeMessages2 = function(messages5) {
|
|
|
3725
4025
|
];
|
|
3726
4026
|
parts2.push({
|
|
3727
4027
|
functionResponse: {
|
|
3728
|
-
id:
|
|
3729
|
-
name:
|
|
4028
|
+
id: responseId2,
|
|
4029
|
+
name: responseName,
|
|
3730
4030
|
response: {
|
|
3731
4031
|
output: "Screenshot captured."
|
|
3732
4032
|
},
|
|
@@ -3737,8 +4037,8 @@ var serializeMessages2 = function(messages5) {
|
|
|
3737
4037
|
var output = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
3738
4038
|
parts2.push({
|
|
3739
4039
|
functionResponse: {
|
|
3740
|
-
id:
|
|
3741
|
-
name:
|
|
4040
|
+
id: responseId2,
|
|
4041
|
+
name: responseName,
|
|
3742
4042
|
response: {
|
|
3743
4043
|
output: output
|
|
3744
4044
|
}
|
|
@@ -3873,7 +4173,14 @@ var serializeTools2 = function(tools) {
|
|
|
3873
4173
|
if (computerUseEnabled) {
|
|
3874
4174
|
geminiTools.push({
|
|
3875
4175
|
computerUse: {
|
|
3876
|
-
environment: "ENVIRONMENT_BROWSER"
|
|
4176
|
+
environment: "ENVIRONMENT_BROWSER",
|
|
4177
|
+
excludedPredefinedFunctions: [
|
|
4178
|
+
"navigate",
|
|
4179
|
+
"go_back",
|
|
4180
|
+
"go_forward",
|
|
4181
|
+
"search",
|
|
4182
|
+
"open_web_browser"
|
|
4183
|
+
]
|
|
3877
4184
|
}
|
|
3878
4185
|
});
|
|
3879
4186
|
}
|
|
@@ -3922,6 +4229,8 @@ var denormalizeCoords = function(args, tools) {
|
|
|
3922
4229
|
denormY(result.end_coordinate[1])
|
|
3923
4230
|
];
|
|
3924
4231
|
}
|
|
4232
|
+
if (typeof result.destination_x === "number") result.destination_x = denormX(result.destination_x);
|
|
4233
|
+
if (typeof result.destination_y === "number") result.destination_y = denormY(result.destination_y);
|
|
3925
4234
|
return result;
|
|
3926
4235
|
};
|
|
3927
4236
|
var isComputerUseFunction = function(name, tools) {
|
|
@@ -3929,53 +4238,194 @@ var isComputerUseFunction = function(name, tools) {
|
|
|
3929
4238
|
var userFns = getUserDefinedFunctionNames(tools);
|
|
3930
4239
|
return !userFns.has(name);
|
|
3931
4240
|
};
|
|
3932
|
-
var
|
|
4241
|
+
var functionCallToToolCallDeltas = function(fc, startIndex, tools, thoughtSignature) {
|
|
3933
4242
|
var _fc_name, _fc_args, _fc_id;
|
|
3934
4243
|
var rawName = (_fc_name = fc.name) !== null && _fc_name !== void 0 ? _fc_name : "";
|
|
3935
4244
|
var name = stripFunctionPrefix(rawName);
|
|
3936
4245
|
if (isComputerUseFunction(name, tools)) {
|
|
3937
4246
|
var _fc_args1, _fc_id1;
|
|
3938
4247
|
var denormed = denormalizeCoords((_fc_args1 = fc.args) !== null && _fc_args1 !== void 0 ? _fc_args1 : {}, tools);
|
|
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
|
+
}
|
|
3939
4290
|
var normalized = normalizeComputerToolCallPayload(_object_spread_props(_object_spread({}, denormed), {
|
|
3940
4291
|
type: name
|
|
3941
4292
|
}));
|
|
3942
4293
|
var payload = _object_spread({}, normalized);
|
|
3943
|
-
if (thoughtSignature)
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
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
|
+
}
|
|
3953
4304
|
}
|
|
3954
|
-
|
|
4305
|
+
];
|
|
3955
4306
|
}
|
|
3956
4307
|
var args = (_fc_args = fc.args) !== null && _fc_args !== void 0 ? _fc_args : {};
|
|
3957
4308
|
if (thoughtSignature) {
|
|
3958
4309
|
args._thoughtSignature = thoughtSignature;
|
|
3959
4310
|
}
|
|
3960
|
-
return
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
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
|
+
}
|
|
3967
4320
|
}
|
|
3968
|
-
|
|
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
|
+
});
|
|
3969
4411
|
};
|
|
3970
4412
|
var post7 = function(param) {
|
|
3971
4413
|
var google = param.google;
|
|
4414
|
+
var pendingSubActions = [];
|
|
3972
4415
|
return function(_url, options) {
|
|
3973
4416
|
return _async_to_generator(function() {
|
|
3974
|
-
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;
|
|
3975
4418
|
return _ts_generator(this, function(_state) {
|
|
3976
4419
|
switch(_state.label){
|
|
3977
4420
|
case 0:
|
|
3978
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
|
+
}
|
|
3979
4429
|
messages5 = nonEmptyMessages({
|
|
3980
4430
|
messages: body.messages
|
|
3981
4431
|
});
|
|
@@ -4009,7 +4459,7 @@ var post7 = function(param) {
|
|
|
4009
4459
|
stream = new ReadableStream({
|
|
4010
4460
|
start: function start(controller) {
|
|
4011
4461
|
return _async_to_generator(function() {
|
|
4012
|
-
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;
|
|
4013
4463
|
return _ts_generator(this, function(_state) {
|
|
4014
4464
|
switch(_state.label){
|
|
4015
4465
|
case 0:
|
|
@@ -4066,24 +4516,50 @@ var post7 = function(param) {
|
|
|
4066
4516
|
controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
|
|
4067
4517
|
}
|
|
4068
4518
|
if (part.functionCall) {
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
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();
|
|
4082
4555
|
}
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4556
|
+
} finally{
|
|
4557
|
+
if (_didIteratorError2) {
|
|
4558
|
+
throw _iteratorError2;
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
}
|
|
4562
|
+
chunkIndex += emitDeltas.length;
|
|
4087
4563
|
lastThoughtSignature = void 0;
|
|
4088
4564
|
}
|
|
4089
4565
|
}
|
|
@@ -4216,7 +4692,15 @@ var post7 = function(param) {
|
|
|
4216
4692
|
lastSig = p.thoughtSignature;
|
|
4217
4693
|
}
|
|
4218
4694
|
if (p.functionCall) {
|
|
4219
|
-
|
|
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
|
+
}
|
|
4220
4704
|
lastSig = void 0;
|
|
4221
4705
|
}
|
|
4222
4706
|
}
|
|
@@ -4819,6 +5303,12 @@ var MODEL_QUIRKS = {
|
|
|
4819
5303
|
},
|
|
4820
5304
|
"qwen/": {
|
|
4821
5305
|
fuzzyFallback: true
|
|
5306
|
+
},
|
|
5307
|
+
"moonshotai/kimi-k2.5": {
|
|
5308
|
+
relativeCoords: {
|
|
5309
|
+
referenceWidth: 1920,
|
|
5310
|
+
referenceHeight: 1080
|
|
5311
|
+
}
|
|
4822
5312
|
}
|
|
4823
5313
|
};
|
|
4824
5314
|
var getQuirks = function(model) {
|
|
@@ -5047,6 +5537,32 @@ var denormalizeAction = function(action, displayWidth, displayHeight) {
|
|
|
5047
5537
|
}
|
|
5048
5538
|
return result;
|
|
5049
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
|
+
};
|
|
5050
5566
|
var COORD_FIELDS = [
|
|
5051
5567
|
"x",
|
|
5052
5568
|
"y",
|
|
@@ -5159,14 +5675,19 @@ var denormalizeComputerCallArguments = function(param) {
|
|
|
5159
5675
|
action: denormalizeAction(normalized.action, displayWidth, displayHeight)
|
|
5160
5676
|
}));
|
|
5161
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
|
+
}
|
|
5162
5683
|
return JSON.stringify(normalized);
|
|
5163
5684
|
};
|
|
5164
5685
|
// src/adapters/client/openRouterClientAdapter/completions/computerUseTool.ts
|
|
5165
5686
|
var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
|
|
5166
5687
|
var quirks = getQuirks(model);
|
|
5167
|
-
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, ").");
|
|
5168
|
-
var xDesc = quirks.normalizedCoords ? "X coordinate (0-1000 normalized)" : "X coordinate in pixels (0-".concat(displayWidth, ")");
|
|
5169
|
-
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, ")");
|
|
5170
5691
|
return {
|
|
5171
5692
|
name: "computer_call",
|
|
5172
5693
|
description: "Perform a computer action. ".concat(coordDesc),
|