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.js
CHANGED
|
@@ -3395,6 +3395,256 @@ var models9 = function(param) {
|
|
|
3395
3395
|
// src/adapters/client/googleClientAdapter/completions/post.ts
|
|
3396
3396
|
import { createId } from "@paralleldrive/cuid2";
|
|
3397
3397
|
import { uid as uid2 } from "radash";
|
|
3398
|
+
// src/adapters/client/googleClientAdapter/normalizeGeminiAction.ts
|
|
3399
|
+
var GEMINI_ACTION_NAMES = /* @__PURE__ */ new Set([
|
|
3400
|
+
"click_at",
|
|
3401
|
+
"single_click_at",
|
|
3402
|
+
"right_click_at",
|
|
3403
|
+
"double_click_at",
|
|
3404
|
+
"triple_click_at",
|
|
3405
|
+
"hover_at",
|
|
3406
|
+
"type_text_at",
|
|
3407
|
+
"key_combination",
|
|
3408
|
+
"scroll_at",
|
|
3409
|
+
"scroll_document",
|
|
3410
|
+
"drag_and_drop",
|
|
3411
|
+
"wait_5_seconds",
|
|
3412
|
+
"wait_for_load"
|
|
3413
|
+
]);
|
|
3414
|
+
var isGeminiAction = function(name) {
|
|
3415
|
+
return GEMINI_ACTION_NAMES.has(name);
|
|
3416
|
+
};
|
|
3417
|
+
var act = function(action) {
|
|
3418
|
+
return {
|
|
3419
|
+
action: action,
|
|
3420
|
+
pending_safety_checks: []
|
|
3421
|
+
};
|
|
3422
|
+
};
|
|
3423
|
+
var normalizeGeminiKey = function(key) {
|
|
3424
|
+
var lower = key.toLowerCase();
|
|
3425
|
+
switch(lower){
|
|
3426
|
+
case "control":
|
|
3427
|
+
return "ctrl";
|
|
3428
|
+
case "command":
|
|
3429
|
+
case "cmd":
|
|
3430
|
+
return "meta";
|
|
3431
|
+
case "option":
|
|
3432
|
+
return "alt";
|
|
3433
|
+
default:
|
|
3434
|
+
return lower;
|
|
3435
|
+
}
|
|
3436
|
+
};
|
|
3437
|
+
var scrollFromDirection = function(direction, amount) {
|
|
3438
|
+
if (!direction) return {
|
|
3439
|
+
scroll_x: 0,
|
|
3440
|
+
scroll_y: 0
|
|
3441
|
+
};
|
|
3442
|
+
switch(direction.toLowerCase()){
|
|
3443
|
+
case "up":
|
|
3444
|
+
return {
|
|
3445
|
+
scroll_x: 0,
|
|
3446
|
+
scroll_y: -amount
|
|
3447
|
+
};
|
|
3448
|
+
case "down":
|
|
3449
|
+
return {
|
|
3450
|
+
scroll_x: 0,
|
|
3451
|
+
scroll_y: amount
|
|
3452
|
+
};
|
|
3453
|
+
case "left":
|
|
3454
|
+
return {
|
|
3455
|
+
scroll_x: -amount,
|
|
3456
|
+
scroll_y: 0
|
|
3457
|
+
};
|
|
3458
|
+
case "right":
|
|
3459
|
+
return {
|
|
3460
|
+
scroll_x: amount,
|
|
3461
|
+
scroll_y: 0
|
|
3462
|
+
};
|
|
3463
|
+
default:
|
|
3464
|
+
return {
|
|
3465
|
+
scroll_x: 0,
|
|
3466
|
+
scroll_y: 0
|
|
3467
|
+
};
|
|
3468
|
+
}
|
|
3469
|
+
};
|
|
3470
|
+
var normalizeGeminiAction = function(name, args) {
|
|
3471
|
+
var x = typeof args.x === "number" ? args.x : typeof args.coordinate_x === "number" ? args.coordinate_x : 0;
|
|
3472
|
+
var y = typeof args.y === "number" ? args.y : typeof args.coordinate_y === "number" ? args.coordinate_y : 0;
|
|
3473
|
+
switch(name){
|
|
3474
|
+
case "click_at":
|
|
3475
|
+
case "single_click_at":
|
|
3476
|
+
return [
|
|
3477
|
+
act({
|
|
3478
|
+
type: "click",
|
|
3479
|
+
button: "left",
|
|
3480
|
+
x: x,
|
|
3481
|
+
y: y
|
|
3482
|
+
})
|
|
3483
|
+
];
|
|
3484
|
+
case "right_click_at":
|
|
3485
|
+
return [
|
|
3486
|
+
act({
|
|
3487
|
+
type: "click",
|
|
3488
|
+
button: "right",
|
|
3489
|
+
x: x,
|
|
3490
|
+
y: y
|
|
3491
|
+
})
|
|
3492
|
+
];
|
|
3493
|
+
case "double_click_at":
|
|
3494
|
+
return [
|
|
3495
|
+
act({
|
|
3496
|
+
type: "double_click",
|
|
3497
|
+
x: x,
|
|
3498
|
+
y: y
|
|
3499
|
+
})
|
|
3500
|
+
];
|
|
3501
|
+
case "triple_click_at":
|
|
3502
|
+
return [
|
|
3503
|
+
act({
|
|
3504
|
+
type: "double_click",
|
|
3505
|
+
x: x,
|
|
3506
|
+
y: y,
|
|
3507
|
+
repetitions: 3
|
|
3508
|
+
})
|
|
3509
|
+
];
|
|
3510
|
+
case "hover_at":
|
|
3511
|
+
return [
|
|
3512
|
+
act({
|
|
3513
|
+
type: "move",
|
|
3514
|
+
x: x,
|
|
3515
|
+
y: y
|
|
3516
|
+
})
|
|
3517
|
+
];
|
|
3518
|
+
case "type_text_at":
|
|
3519
|
+
{
|
|
3520
|
+
var text = typeof args.text === "string" ? args.text : "";
|
|
3521
|
+
var clearBeforeTyping = args.clear_before_typing !== false;
|
|
3522
|
+
var pressEnter = args.press_enter !== false;
|
|
3523
|
+
var actions = [
|
|
3524
|
+
act({
|
|
3525
|
+
type: "click",
|
|
3526
|
+
button: "left",
|
|
3527
|
+
x: x,
|
|
3528
|
+
y: y
|
|
3529
|
+
})
|
|
3530
|
+
];
|
|
3531
|
+
if (clearBeforeTyping) {
|
|
3532
|
+
actions.push(act({
|
|
3533
|
+
type: "keypress",
|
|
3534
|
+
keys: [
|
|
3535
|
+
"ctrl",
|
|
3536
|
+
"a"
|
|
3537
|
+
]
|
|
3538
|
+
}));
|
|
3539
|
+
actions.push(act({
|
|
3540
|
+
type: "keypress",
|
|
3541
|
+
keys: [
|
|
3542
|
+
"Backspace"
|
|
3543
|
+
]
|
|
3544
|
+
}));
|
|
3545
|
+
}
|
|
3546
|
+
actions.push(act({
|
|
3547
|
+
type: "type",
|
|
3548
|
+
text: text
|
|
3549
|
+
}));
|
|
3550
|
+
if (pressEnter) {
|
|
3551
|
+
actions.push(act({
|
|
3552
|
+
type: "keypress",
|
|
3553
|
+
keys: [
|
|
3554
|
+
"Return"
|
|
3555
|
+
]
|
|
3556
|
+
}));
|
|
3557
|
+
}
|
|
3558
|
+
return actions;
|
|
3559
|
+
}
|
|
3560
|
+
case "key_combination":
|
|
3561
|
+
{
|
|
3562
|
+
var rawKeys = args.keys;
|
|
3563
|
+
var keys;
|
|
3564
|
+
if (Array.isArray(rawKeys)) {
|
|
3565
|
+
keys = rawKeys.map(String).map(normalizeGeminiKey);
|
|
3566
|
+
} else if (typeof rawKeys === "string") {
|
|
3567
|
+
keys = rawKeys.split(/[+\s]+/).map(function(k) {
|
|
3568
|
+
return k.trim();
|
|
3569
|
+
}).filter(Boolean).map(normalizeGeminiKey);
|
|
3570
|
+
} else {
|
|
3571
|
+
keys = [];
|
|
3572
|
+
}
|
|
3573
|
+
return [
|
|
3574
|
+
act({
|
|
3575
|
+
type: "keypress",
|
|
3576
|
+
keys: keys
|
|
3577
|
+
})
|
|
3578
|
+
];
|
|
3579
|
+
}
|
|
3580
|
+
case "scroll_at":
|
|
3581
|
+
{
|
|
3582
|
+
var direction = typeof args.direction === "string" ? args.direction : void 0;
|
|
3583
|
+
var amount = typeof args.amount === "number" ? args.amount : 3;
|
|
3584
|
+
var _scrollFromDirection = scrollFromDirection(direction, amount), scroll_x = _scrollFromDirection.scroll_x, scroll_y = _scrollFromDirection.scroll_y;
|
|
3585
|
+
return [
|
|
3586
|
+
act({
|
|
3587
|
+
type: "scroll",
|
|
3588
|
+
x: x,
|
|
3589
|
+
y: y,
|
|
3590
|
+
scroll_x: scroll_x,
|
|
3591
|
+
scroll_y: scroll_y
|
|
3592
|
+
})
|
|
3593
|
+
];
|
|
3594
|
+
}
|
|
3595
|
+
case "scroll_document":
|
|
3596
|
+
{
|
|
3597
|
+
var direction1 = typeof args.direction === "string" ? args.direction : void 0;
|
|
3598
|
+
var amount1 = typeof args.amount === "number" ? args.amount : 3;
|
|
3599
|
+
var _scrollFromDirection1 = scrollFromDirection(direction1, amount1), scroll_x1 = _scrollFromDirection1.scroll_x, scroll_y1 = _scrollFromDirection1.scroll_y;
|
|
3600
|
+
return [
|
|
3601
|
+
act({
|
|
3602
|
+
type: "scroll",
|
|
3603
|
+
x: 640,
|
|
3604
|
+
y: 360,
|
|
3605
|
+
scroll_x: scroll_x1,
|
|
3606
|
+
scroll_y: scroll_y1
|
|
3607
|
+
})
|
|
3608
|
+
];
|
|
3609
|
+
}
|
|
3610
|
+
case "drag_and_drop":
|
|
3611
|
+
{
|
|
3612
|
+
var destX = typeof args.destination_x === "number" ? args.destination_x : 0;
|
|
3613
|
+
var destY = typeof args.destination_y === "number" ? args.destination_y : 0;
|
|
3614
|
+
return [
|
|
3615
|
+
act({
|
|
3616
|
+
type: "drag",
|
|
3617
|
+
path: [
|
|
3618
|
+
{
|
|
3619
|
+
x: x,
|
|
3620
|
+
y: y
|
|
3621
|
+
},
|
|
3622
|
+
{
|
|
3623
|
+
x: destX,
|
|
3624
|
+
y: destY
|
|
3625
|
+
}
|
|
3626
|
+
]
|
|
3627
|
+
})
|
|
3628
|
+
];
|
|
3629
|
+
}
|
|
3630
|
+
case "wait_5_seconds":
|
|
3631
|
+
case "wait_for_load":
|
|
3632
|
+
return [
|
|
3633
|
+
act({
|
|
3634
|
+
type: "wait"
|
|
3635
|
+
})
|
|
3636
|
+
];
|
|
3637
|
+
// navigate, go_back, go_forward, open_web_browser, search are excluded
|
|
3638
|
+
// via excludedPredefinedFunctions in the tool config
|
|
3639
|
+
default:
|
|
3640
|
+
return [
|
|
3641
|
+
act(_object_spread({
|
|
3642
|
+
type: name
|
|
3643
|
+
}, args))
|
|
3644
|
+
];
|
|
3645
|
+
}
|
|
3646
|
+
};
|
|
3647
|
+
// src/adapters/client/googleClientAdapter/completions/post.ts
|
|
3398
3648
|
var stripFunctionPrefix = function(name) {
|
|
3399
3649
|
return name.replace(/^default_api:/, "");
|
|
3400
3650
|
};
|
|
@@ -3435,6 +3685,9 @@ var serializeMessages2 = function(messages5) {
|
|
|
3435
3685
|
var systemParts = [];
|
|
3436
3686
|
var contents = [];
|
|
3437
3687
|
var toolCallIdToName = /* @__PURE__ */ new Map();
|
|
3688
|
+
var geminiCallGroups = /* @__PURE__ */ new Map();
|
|
3689
|
+
var skipToolResultIds = /* @__PURE__ */ new Set();
|
|
3690
|
+
var lastSubActionMap = /* @__PURE__ */ new Map();
|
|
3438
3691
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
3439
3692
|
try {
|
|
3440
3693
|
for(var _iterator = messages5[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
@@ -3529,14 +3782,49 @@ var serializeMessages2 = function(messages5) {
|
|
|
3529
3782
|
var _tc_function1;
|
|
3530
3783
|
args = JSON.parse((_ref1 = (_tc_function1 = tc.function) === null || _tc_function1 === void 0 ? void 0 : _tc_function1.arguments) !== null && _ref1 !== void 0 ? _ref1 : "{}");
|
|
3531
3784
|
} catch (unused) {}
|
|
3532
|
-
var geminiName = name;
|
|
3533
|
-
if (name === "computer_call" && args.action && _type_of(args.action) === "object") {
|
|
3534
|
-
var _args_action_type;
|
|
3535
|
-
geminiName = (_args_action_type = args.action.type) !== null && _args_action_type !== void 0 ? _args_action_type : name;
|
|
3536
|
-
}
|
|
3537
3785
|
var thoughtSignature = args._thoughtSignature;
|
|
3786
|
+
var geminiActionName = args._geminiAction;
|
|
3787
|
+
var geminiCallId = args._geminiCallId;
|
|
3788
|
+
var subActionIndex = args._subActionIndex;
|
|
3789
|
+
var subActionTotal = args._subActionTotal;
|
|
3790
|
+
var geminiOrigArgs = args._geminiArgs;
|
|
3538
3791
|
var cleanArgs = _object_spread({}, args);
|
|
3539
3792
|
delete cleanArgs._thoughtSignature;
|
|
3793
|
+
delete cleanArgs._geminiAction;
|
|
3794
|
+
delete cleanArgs._geminiCallId;
|
|
3795
|
+
delete cleanArgs._subActionIndex;
|
|
3796
|
+
delete cleanArgs._subActionTotal;
|
|
3797
|
+
delete cleanArgs._geminiArgs;
|
|
3798
|
+
if (geminiCallId && typeof subActionIndex === "number" && typeof subActionTotal === "number") {
|
|
3799
|
+
if (subActionIndex === 0) {
|
|
3800
|
+
var fcName = geminiActionName !== null && geminiActionName !== void 0 ? geminiActionName : name;
|
|
3801
|
+
geminiCallGroups.set(geminiCallId, {
|
|
3802
|
+
name: fcName,
|
|
3803
|
+
primaryId: id
|
|
3804
|
+
});
|
|
3805
|
+
toolCallIdToName.set(id, fcName);
|
|
3806
|
+
if (subActionTotal > 1) skipToolResultIds.add(id);
|
|
3807
|
+
var fcPart2 = {
|
|
3808
|
+
functionCall: {
|
|
3809
|
+
name: fcName,
|
|
3810
|
+
args: geminiOrigArgs !== null && geminiOrigArgs !== void 0 ? geminiOrigArgs : {},
|
|
3811
|
+
id: id
|
|
3812
|
+
}
|
|
3813
|
+
};
|
|
3814
|
+
if (thoughtSignature) fcPart2.thoughtSignature = thoughtSignature;
|
|
3815
|
+
parts1.push(fcPart2);
|
|
3816
|
+
} else if (subActionIndex === subActionTotal - 1) {
|
|
3817
|
+
lastSubActionMap.set(id, geminiCallId);
|
|
3818
|
+
} else {
|
|
3819
|
+
skipToolResultIds.add(id);
|
|
3820
|
+
}
|
|
3821
|
+
continue;
|
|
3822
|
+
}
|
|
3823
|
+
var geminiName = name;
|
|
3824
|
+
if (name === "computer_call" && args.action && _type_of(args.action) === "object") {
|
|
3825
|
+
var _ref2;
|
|
3826
|
+
geminiName = (_ref2 = geminiActionName !== null && geminiActionName !== void 0 ? geminiActionName : args.action.type) !== null && _ref2 !== void 0 ? _ref2 : name;
|
|
3827
|
+
}
|
|
3540
3828
|
var geminiArgs = void 0;
|
|
3541
3829
|
if (name === "computer_call" && cleanArgs.action && _type_of(cleanArgs.action) === "object") {
|
|
3542
3830
|
var action = cleanArgs.action;
|
|
@@ -3584,10 +3872,22 @@ var serializeMessages2 = function(messages5) {
|
|
|
3584
3872
|
continue;
|
|
3585
3873
|
}
|
|
3586
3874
|
if (msg.role === "tool") {
|
|
3587
|
-
var _msg_tool_call_id
|
|
3875
|
+
var _msg_tool_call_id;
|
|
3588
3876
|
var _lastContent_parts;
|
|
3589
3877
|
var toolCallId = (_msg_tool_call_id = msg.tool_call_id) !== null && _msg_tool_call_id !== void 0 ? _msg_tool_call_id : "";
|
|
3590
|
-
|
|
3878
|
+
if (skipToolResultIds.has(toolCallId)) continue;
|
|
3879
|
+
var responseName = void 0;
|
|
3880
|
+
var responseId2 = void 0;
|
|
3881
|
+
if (lastSubActionMap.has(toolCallId)) {
|
|
3882
|
+
var gcId = lastSubActionMap.get(toolCallId);
|
|
3883
|
+
var group = geminiCallGroups.get(gcId);
|
|
3884
|
+
responseName = group.name;
|
|
3885
|
+
responseId2 = group.primaryId;
|
|
3886
|
+
} else {
|
|
3887
|
+
var _toolCallIdToName_get;
|
|
3888
|
+
responseName = (_toolCallIdToName_get = toolCallIdToName.get(toolCallId)) !== null && _toolCallIdToName_get !== void 0 ? _toolCallIdToName_get : "";
|
|
3889
|
+
responseId2 = toolCallId;
|
|
3890
|
+
}
|
|
3591
3891
|
var parts2 = [];
|
|
3592
3892
|
var imageContent = extractImageFromToolMessage(msg);
|
|
3593
3893
|
if (imageContent) {
|
|
@@ -3601,8 +3901,8 @@ var serializeMessages2 = function(messages5) {
|
|
|
3601
3901
|
];
|
|
3602
3902
|
parts2.push({
|
|
3603
3903
|
functionResponse: {
|
|
3604
|
-
id:
|
|
3605
|
-
name:
|
|
3904
|
+
id: responseId2,
|
|
3905
|
+
name: responseName,
|
|
3606
3906
|
response: {
|
|
3607
3907
|
output: "Screenshot captured."
|
|
3608
3908
|
},
|
|
@@ -3613,8 +3913,8 @@ var serializeMessages2 = function(messages5) {
|
|
|
3613
3913
|
var output = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
3614
3914
|
parts2.push({
|
|
3615
3915
|
functionResponse: {
|
|
3616
|
-
id:
|
|
3617
|
-
name:
|
|
3916
|
+
id: responseId2,
|
|
3917
|
+
name: responseName,
|
|
3618
3918
|
response: {
|
|
3619
3919
|
output: output
|
|
3620
3920
|
}
|
|
@@ -3749,7 +4049,14 @@ var serializeTools2 = function(tools) {
|
|
|
3749
4049
|
if (computerUseEnabled) {
|
|
3750
4050
|
geminiTools.push({
|
|
3751
4051
|
computerUse: {
|
|
3752
|
-
environment: "ENVIRONMENT_BROWSER"
|
|
4052
|
+
environment: "ENVIRONMENT_BROWSER",
|
|
4053
|
+
excludedPredefinedFunctions: [
|
|
4054
|
+
"navigate",
|
|
4055
|
+
"go_back",
|
|
4056
|
+
"go_forward",
|
|
4057
|
+
"search",
|
|
4058
|
+
"open_web_browser"
|
|
4059
|
+
]
|
|
3753
4060
|
}
|
|
3754
4061
|
});
|
|
3755
4062
|
}
|
|
@@ -3798,6 +4105,8 @@ var denormalizeCoords = function(args, tools) {
|
|
|
3798
4105
|
denormY(result.end_coordinate[1])
|
|
3799
4106
|
];
|
|
3800
4107
|
}
|
|
4108
|
+
if (typeof result.destination_x === "number") result.destination_x = denormX(result.destination_x);
|
|
4109
|
+
if (typeof result.destination_y === "number") result.destination_y = denormY(result.destination_y);
|
|
3801
4110
|
return result;
|
|
3802
4111
|
};
|
|
3803
4112
|
var isComputerUseFunction = function(name, tools) {
|
|
@@ -3805,53 +4114,194 @@ var isComputerUseFunction = function(name, tools) {
|
|
|
3805
4114
|
var userFns = getUserDefinedFunctionNames(tools);
|
|
3806
4115
|
return !userFns.has(name);
|
|
3807
4116
|
};
|
|
3808
|
-
var
|
|
4117
|
+
var functionCallToToolCallDeltas = function(fc, startIndex, tools, thoughtSignature) {
|
|
3809
4118
|
var _fc_name, _fc_args, _fc_id;
|
|
3810
4119
|
var rawName = (_fc_name = fc.name) !== null && _fc_name !== void 0 ? _fc_name : "";
|
|
3811
4120
|
var name = stripFunctionPrefix(rawName);
|
|
3812
4121
|
if (isComputerUseFunction(name, tools)) {
|
|
3813
4122
|
var _fc_args1, _fc_id1;
|
|
3814
4123
|
var denormed = denormalizeCoords((_fc_args1 = fc.args) !== null && _fc_args1 !== void 0 ? _fc_args1 : {}, tools);
|
|
4124
|
+
if (isGeminiAction(name)) {
|
|
4125
|
+
var normalizedActions = normalizeGeminiAction(name, denormed);
|
|
4126
|
+
if (normalizedActions.length === 1) {
|
|
4127
|
+
var _fc_id2;
|
|
4128
|
+
var payload2 = _object_spread({}, normalizedActions[0]);
|
|
4129
|
+
payload2._geminiAction = name;
|
|
4130
|
+
if (thoughtSignature) payload2._thoughtSignature = thoughtSignature;
|
|
4131
|
+
return [
|
|
4132
|
+
{
|
|
4133
|
+
index: startIndex,
|
|
4134
|
+
id: (_fc_id2 = fc.id) !== null && _fc_id2 !== void 0 ? _fc_id2 : "call_".concat(createId()),
|
|
4135
|
+
type: "function",
|
|
4136
|
+
function: {
|
|
4137
|
+
name: "computer_call",
|
|
4138
|
+
arguments: JSON.stringify(payload2)
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
];
|
|
4142
|
+
}
|
|
4143
|
+
var geminiCallId = "gcall_".concat(createId());
|
|
4144
|
+
return normalizedActions.map(function(normalized2, i) {
|
|
4145
|
+
var _fc_id;
|
|
4146
|
+
var payload2 = _object_spread({}, normalized2);
|
|
4147
|
+
payload2._geminiCallId = geminiCallId;
|
|
4148
|
+
payload2._geminiAction = name;
|
|
4149
|
+
payload2._subActionIndex = i;
|
|
4150
|
+
payload2._subActionTotal = normalizedActions.length;
|
|
4151
|
+
if (i === 0) {
|
|
4152
|
+
payload2._geminiArgs = denormed;
|
|
4153
|
+
if (thoughtSignature) payload2._thoughtSignature = thoughtSignature;
|
|
4154
|
+
}
|
|
4155
|
+
return {
|
|
4156
|
+
index: startIndex + i,
|
|
4157
|
+
id: i === 0 ? (_fc_id = fc.id) !== null && _fc_id !== void 0 ? _fc_id : "call_".concat(createId()) : "call_".concat(createId()),
|
|
4158
|
+
type: "function",
|
|
4159
|
+
function: {
|
|
4160
|
+
name: "computer_call",
|
|
4161
|
+
arguments: JSON.stringify(payload2)
|
|
4162
|
+
}
|
|
4163
|
+
};
|
|
4164
|
+
});
|
|
4165
|
+
}
|
|
3815
4166
|
var normalized = normalizeComputerToolCallPayload(_object_spread_props(_object_spread({}, denormed), {
|
|
3816
4167
|
type: name
|
|
3817
4168
|
}));
|
|
3818
4169
|
var payload = _object_spread({}, normalized);
|
|
3819
|
-
if (thoughtSignature)
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
4170
|
+
if (thoughtSignature) payload._thoughtSignature = thoughtSignature;
|
|
4171
|
+
return [
|
|
4172
|
+
{
|
|
4173
|
+
index: startIndex,
|
|
4174
|
+
id: (_fc_id1 = fc.id) !== null && _fc_id1 !== void 0 ? _fc_id1 : "call_".concat(createId()),
|
|
4175
|
+
type: "function",
|
|
4176
|
+
function: {
|
|
4177
|
+
name: "computer_call",
|
|
4178
|
+
arguments: JSON.stringify(payload)
|
|
4179
|
+
}
|
|
3829
4180
|
}
|
|
3830
|
-
|
|
4181
|
+
];
|
|
3831
4182
|
}
|
|
3832
4183
|
var args = (_fc_args = fc.args) !== null && _fc_args !== void 0 ? _fc_args : {};
|
|
3833
4184
|
if (thoughtSignature) {
|
|
3834
4185
|
args._thoughtSignature = thoughtSignature;
|
|
3835
4186
|
}
|
|
3836
|
-
return
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
4187
|
+
return [
|
|
4188
|
+
{
|
|
4189
|
+
index: startIndex,
|
|
4190
|
+
id: (_fc_id = fc.id) !== null && _fc_id !== void 0 ? _fc_id : "call_".concat(createId()),
|
|
4191
|
+
type: "function",
|
|
4192
|
+
function: {
|
|
4193
|
+
name: name,
|
|
4194
|
+
arguments: JSON.stringify(args)
|
|
4195
|
+
}
|
|
3843
4196
|
}
|
|
3844
|
-
|
|
4197
|
+
];
|
|
4198
|
+
};
|
|
4199
|
+
var syntheticToolCallResponse = function(toolCallDelta, stream) {
|
|
4200
|
+
var delta = _object_spread_props(_object_spread({}, toolCallDelta), {
|
|
4201
|
+
index: 0
|
|
4202
|
+
});
|
|
4203
|
+
var encoder = new TextEncoder();
|
|
4204
|
+
if (stream) {
|
|
4205
|
+
var chunks = [
|
|
4206
|
+
"data: ".concat(JSON.stringify({
|
|
4207
|
+
id: "chatcmpl-".concat(uid2(29)),
|
|
4208
|
+
object: "chat.completion.chunk",
|
|
4209
|
+
choices: [
|
|
4210
|
+
{
|
|
4211
|
+
index: 0,
|
|
4212
|
+
delta: {
|
|
4213
|
+
content: null,
|
|
4214
|
+
tool_calls: [
|
|
4215
|
+
delta
|
|
4216
|
+
]
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
]
|
|
4220
|
+
}), "\n\n"),
|
|
4221
|
+
"data: ".concat(JSON.stringify({
|
|
4222
|
+
id: "chatcmpl-".concat(uid2(29)),
|
|
4223
|
+
object: "chat.completion.chunk",
|
|
4224
|
+
choices: [
|
|
4225
|
+
{
|
|
4226
|
+
index: 0,
|
|
4227
|
+
delta: {},
|
|
4228
|
+
finish_reason: "stop"
|
|
4229
|
+
}
|
|
4230
|
+
]
|
|
4231
|
+
}), "\n\n")
|
|
4232
|
+
];
|
|
4233
|
+
return new Response(new ReadableStream({
|
|
4234
|
+
start: function start(controller) {
|
|
4235
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
4236
|
+
try {
|
|
4237
|
+
for(var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
4238
|
+
var chunk = _step.value;
|
|
4239
|
+
controller.enqueue(encoder.encode(chunk));
|
|
4240
|
+
}
|
|
4241
|
+
} catch (err) {
|
|
4242
|
+
_didIteratorError = true;
|
|
4243
|
+
_iteratorError = err;
|
|
4244
|
+
} finally{
|
|
4245
|
+
try {
|
|
4246
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
4247
|
+
_iterator.return();
|
|
4248
|
+
}
|
|
4249
|
+
} finally{
|
|
4250
|
+
if (_didIteratorError) {
|
|
4251
|
+
throw _iteratorError;
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4255
|
+
controller.close();
|
|
4256
|
+
}
|
|
4257
|
+
}), {
|
|
4258
|
+
headers: {
|
|
4259
|
+
"Content-Type": "text/event-stream"
|
|
4260
|
+
}
|
|
4261
|
+
});
|
|
4262
|
+
}
|
|
4263
|
+
return new Response(JSON.stringify({
|
|
4264
|
+
data: {
|
|
4265
|
+
id: "chatcmpl-".concat(uid2(29)),
|
|
4266
|
+
object: "chat.completion",
|
|
4267
|
+
choices: [
|
|
4268
|
+
{
|
|
4269
|
+
index: 0,
|
|
4270
|
+
message: {
|
|
4271
|
+
role: "assistant",
|
|
4272
|
+
content: null,
|
|
4273
|
+
tool_calls: [
|
|
4274
|
+
delta
|
|
4275
|
+
]
|
|
4276
|
+
},
|
|
4277
|
+
finish_reason: "stop"
|
|
4278
|
+
}
|
|
4279
|
+
]
|
|
4280
|
+
}
|
|
4281
|
+
}), {
|
|
4282
|
+
status: 200,
|
|
4283
|
+
headers: {
|
|
4284
|
+
"Content-Type": "application/json"
|
|
4285
|
+
}
|
|
4286
|
+
});
|
|
3845
4287
|
};
|
|
3846
4288
|
var post7 = function(param) {
|
|
3847
4289
|
var google = param.google;
|
|
4290
|
+
var pendingSubActions = [];
|
|
3848
4291
|
return function(_url, options) {
|
|
3849
4292
|
return _async_to_generator(function() {
|
|
3850
|
-
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;
|
|
4293
|
+
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;
|
|
3851
4294
|
return _ts_generator(this, function(_state) {
|
|
3852
4295
|
switch(_state.label){
|
|
3853
4296
|
case 0:
|
|
3854
4297
|
body = JSON.parse(options.body);
|
|
4298
|
+
if (pendingSubActions.length > 0) {
|
|
4299
|
+
next = pendingSubActions.shift();
|
|
4300
|
+
return [
|
|
4301
|
+
2,
|
|
4302
|
+
syntheticToolCallResponse(next, !!body.stream)
|
|
4303
|
+
];
|
|
4304
|
+
}
|
|
3855
4305
|
messages5 = nonEmptyMessages({
|
|
3856
4306
|
messages: body.messages
|
|
3857
4307
|
});
|
|
@@ -3885,7 +4335,7 @@ var post7 = function(param) {
|
|
|
3885
4335
|
stream = new ReadableStream({
|
|
3886
4336
|
start: function start(controller) {
|
|
3887
4337
|
return _async_to_generator(function() {
|
|
3888
|
-
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;
|
|
4338
|
+
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;
|
|
3889
4339
|
return _ts_generator(this, function(_state) {
|
|
3890
4340
|
switch(_state.label){
|
|
3891
4341
|
case 0:
|
|
@@ -3942,24 +4392,50 @@ var post7 = function(param) {
|
|
|
3942
4392
|
controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
|
|
3943
4393
|
}
|
|
3944
4394
|
if (part.functionCall) {
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
4395
|
+
deltas = functionCallToToolCallDeltas(part.functionCall, chunkIndex, body.tools, lastThoughtSignature);
|
|
4396
|
+
emitDeltas = deltas.length > 1 ? [
|
|
4397
|
+
deltas[0]
|
|
4398
|
+
] : deltas;
|
|
4399
|
+
if (deltas.length > 1) {
|
|
4400
|
+
;
|
|
4401
|
+
(_pendingSubActions = pendingSubActions).push.apply(_pendingSubActions, _to_consumable_array(deltas.slice(1)));
|
|
4402
|
+
}
|
|
4403
|
+
_iteratorNormalCompletion1 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
4404
|
+
try {
|
|
4405
|
+
for(_iterator2 = emitDeltas[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
|
|
4406
|
+
toolCallDelta = _step2.value;
|
|
4407
|
+
messageDelta1 = {
|
|
4408
|
+
id: "chatcmpl-".concat(uid2(29)),
|
|
4409
|
+
object: "chat.completion.chunk",
|
|
4410
|
+
choices: [
|
|
4411
|
+
{
|
|
4412
|
+
index: 0,
|
|
4413
|
+
delta: {
|
|
4414
|
+
content: null,
|
|
4415
|
+
tool_calls: [
|
|
4416
|
+
toolCallDelta
|
|
4417
|
+
]
|
|
4418
|
+
}
|
|
4419
|
+
}
|
|
4420
|
+
]
|
|
4421
|
+
};
|
|
4422
|
+
controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
|
|
4423
|
+
}
|
|
4424
|
+
} catch (err) {
|
|
4425
|
+
_didIteratorError2 = true;
|
|
4426
|
+
_iteratorError2 = err;
|
|
4427
|
+
} finally{
|
|
4428
|
+
try {
|
|
4429
|
+
if (!_iteratorNormalCompletion1 && _iterator2.return != null) {
|
|
4430
|
+
_iterator2.return();
|
|
3958
4431
|
}
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
4432
|
+
} finally{
|
|
4433
|
+
if (_didIteratorError2) {
|
|
4434
|
+
throw _iteratorError2;
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
chunkIndex += emitDeltas.length;
|
|
3963
4439
|
lastThoughtSignature = void 0;
|
|
3964
4440
|
}
|
|
3965
4441
|
}
|
|
@@ -4092,7 +4568,15 @@ var post7 = function(param) {
|
|
|
4092
4568
|
lastSig = p.thoughtSignature;
|
|
4093
4569
|
}
|
|
4094
4570
|
if (p.functionCall) {
|
|
4095
|
-
|
|
4571
|
+
deltas = functionCallToToolCallDeltas(p.functionCall, toolCalls.length, body.tools, lastSig);
|
|
4572
|
+
if (deltas.length > 1) {
|
|
4573
|
+
;
|
|
4574
|
+
toolCalls.push(deltas[0]);
|
|
4575
|
+
(_pendingSubActions = pendingSubActions).push.apply(_pendingSubActions, _to_consumable_array(deltas.slice(1)));
|
|
4576
|
+
} else {
|
|
4577
|
+
;
|
|
4578
|
+
(_toolCalls = toolCalls).push.apply(_toolCalls, _to_consumable_array(deltas));
|
|
4579
|
+
}
|
|
4096
4580
|
lastSig = void 0;
|
|
4097
4581
|
}
|
|
4098
4582
|
}
|
|
@@ -4695,6 +5179,12 @@ var MODEL_QUIRKS = {
|
|
|
4695
5179
|
},
|
|
4696
5180
|
"qwen/": {
|
|
4697
5181
|
fuzzyFallback: true
|
|
5182
|
+
},
|
|
5183
|
+
"moonshotai/kimi-k2.5": {
|
|
5184
|
+
relativeCoords: {
|
|
5185
|
+
referenceWidth: 1920,
|
|
5186
|
+
referenceHeight: 1080
|
|
5187
|
+
}
|
|
4698
5188
|
}
|
|
4699
5189
|
};
|
|
4700
5190
|
var getQuirks = function(model) {
|
|
@@ -4923,6 +5413,32 @@ var denormalizeAction = function(action, displayWidth, displayHeight) {
|
|
|
4923
5413
|
}
|
|
4924
5414
|
return result;
|
|
4925
5415
|
};
|
|
5416
|
+
var rescaleCoord = function(value, displayDim, referenceDim) {
|
|
5417
|
+
if (value <= 1) return Math.round(value * displayDim);
|
|
5418
|
+
return Math.round(value / referenceDim * displayDim);
|
|
5419
|
+
};
|
|
5420
|
+
var rescaleRelativeAction = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
|
|
5421
|
+
var result = _object_spread({}, action);
|
|
5422
|
+
if (typeof result.x === "number") {
|
|
5423
|
+
result.x = rescaleCoord(result.x, displayWidth, referenceWidth);
|
|
5424
|
+
}
|
|
5425
|
+
if (typeof result.y === "number") {
|
|
5426
|
+
result.y = rescaleCoord(result.y, displayHeight, referenceHeight);
|
|
5427
|
+
}
|
|
5428
|
+
if (Array.isArray(result.path)) {
|
|
5429
|
+
result.path = result.path.map(function(point) {
|
|
5430
|
+
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5431
|
+
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5432
|
+
x: rescaleCoord(point.x, displayWidth, referenceWidth)
|
|
5433
|
+
} : {}, typeof point.y === "number" ? {
|
|
5434
|
+
y: rescaleCoord(point.y, displayHeight, referenceHeight)
|
|
5435
|
+
} : {});
|
|
5436
|
+
}
|
|
5437
|
+
return point;
|
|
5438
|
+
});
|
|
5439
|
+
}
|
|
5440
|
+
return result;
|
|
5441
|
+
};
|
|
4926
5442
|
var COORD_FIELDS = [
|
|
4927
5443
|
"x",
|
|
4928
5444
|
"y",
|
|
@@ -5035,14 +5551,19 @@ var denormalizeComputerCallArguments = function(param) {
|
|
|
5035
5551
|
action: denormalizeAction(normalized.action, displayWidth, displayHeight)
|
|
5036
5552
|
}));
|
|
5037
5553
|
}
|
|
5554
|
+
if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5555
|
+
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5556
|
+
action: rescaleRelativeAction(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
|
|
5557
|
+
}));
|
|
5558
|
+
}
|
|
5038
5559
|
return JSON.stringify(normalized);
|
|
5039
5560
|
};
|
|
5040
5561
|
// src/adapters/client/openRouterClientAdapter/completions/computerUseTool.ts
|
|
5041
5562
|
var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
|
|
5042
5563
|
var quirks = getQuirks(model);
|
|
5043
|
-
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, ").");
|
|
5044
|
-
var xDesc = quirks.normalizedCoords ? "X coordinate (0-1000 normalized)" : "X coordinate in pixels (0-".concat(displayWidth, ")");
|
|
5045
|
-
var yDesc = quirks.normalizedCoords ? "Y coordinate (0-1000 normalized)" : "Y coordinate in pixels (0-".concat(displayHeight, ")");
|
|
5564
|
+
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, ").");
|
|
5565
|
+
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, ")");
|
|
5566
|
+
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, ")");
|
|
5046
5567
|
return {
|
|
5047
5568
|
name: "computer_call",
|
|
5048
5569
|
description: "Perform a computer action. ".concat(coordDesc),
|