supercompat 4.2.2 → 4.2.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/openai/index.cjs +1121 -77
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.js +1121 -77
- package/dist/openai/index.js.map +1 -1
- package/package.json +1 -1
package/dist/openai/index.js
CHANGED
|
@@ -2678,7 +2678,7 @@ var post5 = function(param) {
|
|
|
2678
2678
|
stream = new ReadableStream({
|
|
2679
2679
|
start: function start(controller) {
|
|
2680
2680
|
return _async_to_generator(function() {
|
|
2681
|
-
var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex,
|
|
2681
|
+
var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex, parseJson4, getOrCreateIndexForToolUseId, assignBlockToToolUse, markComputerToolUse, getToolUseIdFromBlock, emitNormalizedToolCall, getOrCreateIndexForBlock, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, toolUseId, _toolUseIdArgumentBuffer_get, buffered, parsed, normalized, toolCallIndex, chunkIndex, _toolUseIdArgumentBuffer_get1, buffered1, toolCallIndex1, chunkIndex1, messageDelta, delta, toolUseId1, _toolUseIdArgumentBuffer_get2, _chunk_delta_partial_json, existing, updated, parsed1, normalized1, toolCallIndex2, chunkIndex2, _toolUseIdArgumentBuffer_get3, _chunk_delta_partial_json1, existing1, index, messageDelta1, delta1, toolName, normalizedToolName, index1, index2, _chunk_content_block_content, _getToolUseIdFromBlock, outputPayload, toolCallId, index3, _getToolUseIdFromBlock1, _chunk_content_block_content1, toolCallId1, _chunk_content_block, _toolUseId, _type, _id, rest, index4, outputPayload1, messageDelta2, messageDelta3, err;
|
|
2682
2682
|
return _ts_generator(this, function(_state) {
|
|
2683
2683
|
switch(_state.label){
|
|
2684
2684
|
case 0:
|
|
@@ -2688,7 +2688,7 @@ var post5 = function(param) {
|
|
|
2688
2688
|
computerToolUseIds = /* @__PURE__ */ new Set();
|
|
2689
2689
|
normalizedComputerCalls = /* @__PURE__ */ new Set();
|
|
2690
2690
|
nextToolCallIndex = 0;
|
|
2691
|
-
|
|
2691
|
+
parseJson4 = function(value) {
|
|
2692
2692
|
try {
|
|
2693
2693
|
return JSON.parse(value);
|
|
2694
2694
|
} catch (unused) {
|
|
@@ -2785,7 +2785,7 @@ var post5 = function(param) {
|
|
|
2785
2785
|
if (toolUseId && computerToolUseIds.has(toolUseId) && !normalizedComputerCalls.has(toolUseId)) {
|
|
2786
2786
|
;
|
|
2787
2787
|
buffered = (_toolUseIdArgumentBuffer_get = toolUseIdArgumentBuffer.get(toolUseId)) !== null && _toolUseIdArgumentBuffer_get !== void 0 ? _toolUseIdArgumentBuffer_get : "";
|
|
2788
|
-
parsed = buffered ?
|
|
2788
|
+
parsed = buffered ? parseJson4(buffered) : void 0;
|
|
2789
2789
|
if (parsed !== void 0) {
|
|
2790
2790
|
normalized = normalizeComputerToolCallPayload(parsed);
|
|
2791
2791
|
toolCallIndex = getOrCreateIndexForToolUseId(toolUseId);
|
|
@@ -2850,7 +2850,7 @@ var post5 = function(param) {
|
|
|
2850
2850
|
updated = "".concat(existing).concat((_chunk_delta_partial_json = chunk.delta.partial_json) !== null && _chunk_delta_partial_json !== void 0 ? _chunk_delta_partial_json : "");
|
|
2851
2851
|
toolUseIdArgumentBuffer.set(toolUseId1, updated);
|
|
2852
2852
|
if (!normalizedComputerCalls.has(toolUseId1)) {
|
|
2853
|
-
parsed1 =
|
|
2853
|
+
parsed1 = parseJson4(updated);
|
|
2854
2854
|
if (parsed1 !== void 0) {
|
|
2855
2855
|
normalized1 = normalizeComputerToolCallPayload(parsed1);
|
|
2856
2856
|
toolCallIndex2 = getOrCreateIndexForToolUseId(toolUseId1);
|
|
@@ -5074,34 +5074,849 @@ var models12 = function(param) {
|
|
|
5074
5074
|
})
|
|
5075
5075
|
};
|
|
5076
5076
|
};
|
|
5077
|
+
// src/adapters/client/ollamaClientAdapter/completions/normalizeComputerCall.ts
|
|
5078
|
+
var MODEL_QUIRKS = {
|
|
5079
|
+
"gemma4": {
|
|
5080
|
+
normalizedCoords: true,
|
|
5081
|
+
fuzzyFallback: true
|
|
5082
|
+
},
|
|
5083
|
+
"gemma3": {
|
|
5084
|
+
normalizedCoords: true,
|
|
5085
|
+
fuzzyFallback: true
|
|
5086
|
+
},
|
|
5087
|
+
"glm-4.6v": {
|
|
5088
|
+
normalizedCoords: true,
|
|
5089
|
+
cleanArtifacts: true
|
|
5090
|
+
},
|
|
5091
|
+
"glm4.6v": {
|
|
5092
|
+
normalizedCoords: true,
|
|
5093
|
+
cleanArtifacts: true
|
|
5094
|
+
},
|
|
5095
|
+
"qwen": {
|
|
5096
|
+
fuzzyFallback: true
|
|
5097
|
+
},
|
|
5098
|
+
"kimi-k2.5": {
|
|
5099
|
+
relativeCoords: {
|
|
5100
|
+
referenceWidth: 1920,
|
|
5101
|
+
referenceHeight: 1080
|
|
5102
|
+
}
|
|
5103
|
+
},
|
|
5104
|
+
"kimi2.5": {
|
|
5105
|
+
relativeCoords: {
|
|
5106
|
+
referenceWidth: 1920,
|
|
5107
|
+
referenceHeight: 1080
|
|
5108
|
+
}
|
|
5109
|
+
}
|
|
5110
|
+
};
|
|
5111
|
+
var getQuirks = function(model) {
|
|
5112
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5113
|
+
try {
|
|
5114
|
+
for(var _iterator = Object.entries(MODEL_QUIRKS)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5115
|
+
var _step_value = _sliced_to_array(_step.value, 2), prefix = _step_value[0], quirks = _step_value[1];
|
|
5116
|
+
if (model.startsWith(prefix)) return quirks;
|
|
5117
|
+
}
|
|
5118
|
+
} catch (err) {
|
|
5119
|
+
_didIteratorError = true;
|
|
5120
|
+
_iteratorError = err;
|
|
5121
|
+
} finally{
|
|
5122
|
+
try {
|
|
5123
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5124
|
+
_iterator.return();
|
|
5125
|
+
}
|
|
5126
|
+
} finally{
|
|
5127
|
+
if (_didIteratorError) {
|
|
5128
|
+
throw _iteratorError;
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
}
|
|
5132
|
+
return {};
|
|
5133
|
+
};
|
|
5134
|
+
var cleanTextArtifacts = function(text) {
|
|
5135
|
+
return text.replace(/<\|begin_of_box\|>/g, "").replace(/<\|end_of_box\|>/g, "").replace(/<arg_key>[^<]*<\/arg_key>/g, "").replace(/<\/arg_value>/g, "").trim();
|
|
5136
|
+
};
|
|
5137
|
+
var KNOWN_ACTION_TYPES = [
|
|
5138
|
+
"double_click",
|
|
5139
|
+
"screenshot",
|
|
5140
|
+
"keypress",
|
|
5141
|
+
"scroll",
|
|
5142
|
+
"click",
|
|
5143
|
+
"move",
|
|
5144
|
+
"type",
|
|
5145
|
+
"drag",
|
|
5146
|
+
"wait"
|
|
5147
|
+
];
|
|
5148
|
+
var splitCoordDigits = function(numStr) {
|
|
5149
|
+
for(var i = 1; i < numStr.length; i++){
|
|
5150
|
+
var x = parseInt(numStr.slice(0, i));
|
|
5151
|
+
var y = parseInt(numStr.slice(i));
|
|
5152
|
+
if (x >= 0 && x <= 1e3 && y >= 0 && y <= 1e3) {
|
|
5153
|
+
return {
|
|
5154
|
+
x: x,
|
|
5155
|
+
y: y
|
|
5156
|
+
};
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5159
|
+
return null;
|
|
5160
|
+
};
|
|
5161
|
+
var cleanGlmAction = function(action) {
|
|
5162
|
+
var typeVal = action.type;
|
|
5163
|
+
if (typeof typeVal !== "string") return action;
|
|
5164
|
+
var argValueMatch = typeVal.match(/<arg_value>\s*(\{[\s\S]*\})\s*$/);
|
|
5165
|
+
if (argValueMatch) {
|
|
5166
|
+
var inner = parseJson2(argValueMatch[1]);
|
|
5167
|
+
if (inner && (typeof inner === "undefined" ? "undefined" : _type_of(inner)) === "object") {
|
|
5168
|
+
return inner;
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
var cleanedType = typeVal.replace(/<\/?[^>]+>/g, "").replace(/\n/g, "").trim();
|
|
5172
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5173
|
+
try {
|
|
5174
|
+
for(var _iterator = KNOWN_ACTION_TYPES[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5175
|
+
var actionType = _step.value;
|
|
5176
|
+
if (cleanedType.startsWith(actionType) && cleanedType !== actionType) {
|
|
5177
|
+
var rest = cleanedType.slice(actionType.length);
|
|
5178
|
+
var nums = rest.match(/\d+/g);
|
|
5179
|
+
if (nums && nums.length >= 2) {
|
|
5180
|
+
return _object_spread_props(_object_spread({}, action), {
|
|
5181
|
+
type: actionType,
|
|
5182
|
+
x: parseInt(nums[0]),
|
|
5183
|
+
y: parseInt(nums[1])
|
|
5184
|
+
});
|
|
5185
|
+
}
|
|
5186
|
+
if (nums && nums.length === 1 && nums[0].length >= 2) {
|
|
5187
|
+
var coords = splitCoordDigits(nums[0]);
|
|
5188
|
+
if (coords) {
|
|
5189
|
+
return _object_spread(_object_spread_props(_object_spread({}, action), {
|
|
5190
|
+
type: actionType
|
|
5191
|
+
}), coords);
|
|
5192
|
+
}
|
|
5193
|
+
}
|
|
5194
|
+
return _object_spread_props(_object_spread({}, action), {
|
|
5195
|
+
type: actionType
|
|
5196
|
+
});
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
} catch (err) {
|
|
5200
|
+
_didIteratorError = true;
|
|
5201
|
+
_iteratorError = err;
|
|
5202
|
+
} finally{
|
|
5203
|
+
try {
|
|
5204
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5205
|
+
_iterator.return();
|
|
5206
|
+
}
|
|
5207
|
+
} finally{
|
|
5208
|
+
if (_didIteratorError) {
|
|
5209
|
+
throw _iteratorError;
|
|
5210
|
+
}
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
if (cleanedType === typeVal) return action;
|
|
5214
|
+
return _object_spread_props(_object_spread({}, action), {
|
|
5215
|
+
type: cleanedType
|
|
5216
|
+
});
|
|
5217
|
+
};
|
|
5218
|
+
var cleanGlmFields = function(action) {
|
|
5219
|
+
var result = _object_spread({}, action);
|
|
5220
|
+
if (typeof result.x === "string") {
|
|
5221
|
+
var nums = result.x.match(/\d+/g);
|
|
5222
|
+
if (nums && nums.length >= 2) {
|
|
5223
|
+
result.x = parseInt(nums[0]);
|
|
5224
|
+
if (result.y === void 0 || typeof result.y === "string") {
|
|
5225
|
+
result.y = parseInt(nums[1]);
|
|
5226
|
+
}
|
|
5227
|
+
} else if (nums && nums.length === 1) {
|
|
5228
|
+
result.x = parseInt(nums[0]);
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5231
|
+
if (typeof result.y === "string") {
|
|
5232
|
+
var nums1 = result.y.match(/\d+/g);
|
|
5233
|
+
if (nums1 && nums1.length >= 1) {
|
|
5234
|
+
result.y = parseInt(nums1[0]);
|
|
5235
|
+
}
|
|
5236
|
+
}
|
|
5237
|
+
for(var _i = 0, _iter = [
|
|
5238
|
+
"scroll_x",
|
|
5239
|
+
"scroll_y"
|
|
5240
|
+
]; _i < _iter.length; _i++){
|
|
5241
|
+
var key = _iter[_i];
|
|
5242
|
+
if (typeof result[key] === "string") {
|
|
5243
|
+
var nums2 = result[key].match(/\d+/g);
|
|
5244
|
+
if (nums2) result[key] = parseInt(nums2[0]);
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
if (typeof result.type === "string") {
|
|
5248
|
+
result.type = result.type.replace(/<[^>]*>/g, "").replace(/^\{|\}$/g, "").replace(/\n/g, "").trim();
|
|
5249
|
+
}
|
|
5250
|
+
return result;
|
|
5251
|
+
};
|
|
5252
|
+
var applyArtifactCleanup = function(action) {
|
|
5253
|
+
return cleanGlmFields(cleanGlmAction(action));
|
|
5254
|
+
};
|
|
5255
|
+
var parseJson2 = function(text) {
|
|
5256
|
+
try {
|
|
5257
|
+
return JSON.parse(text);
|
|
5258
|
+
} catch (unused) {
|
|
5259
|
+
return void 0;
|
|
5260
|
+
}
|
|
5261
|
+
};
|
|
5262
|
+
var extractJson = function(text) {
|
|
5263
|
+
var direct = parseJson2(text);
|
|
5264
|
+
if (direct) return direct;
|
|
5265
|
+
var codeBlockMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
5266
|
+
if (codeBlockMatch) {
|
|
5267
|
+
var parsed = parseJson2(codeBlockMatch[1].trim());
|
|
5268
|
+
if (parsed) return parsed;
|
|
5269
|
+
}
|
|
5270
|
+
var jsonMatch = text.match(/(\{[\s\S]*\})\s*$/);
|
|
5271
|
+
if (jsonMatch) {
|
|
5272
|
+
var parsed1 = parseJson2(jsonMatch[1].trim());
|
|
5273
|
+
if (parsed1) return parsed1;
|
|
5274
|
+
}
|
|
5275
|
+
return void 0;
|
|
5276
|
+
};
|
|
5277
|
+
var fuzzyExtractJson = function(text) {
|
|
5278
|
+
var clickMatch = text.match(/"action"\s*:\s*"click"\s*,\s*"x"\s*:\s*\[?\s*(\d+)\s*,\s*(\d+)/);
|
|
5279
|
+
if (clickMatch) {
|
|
5280
|
+
return {
|
|
5281
|
+
action: {
|
|
5282
|
+
type: "click",
|
|
5283
|
+
x: parseInt(clickMatch[1]),
|
|
5284
|
+
y: parseInt(clickMatch[2])
|
|
5285
|
+
}
|
|
5286
|
+
};
|
|
5287
|
+
}
|
|
5288
|
+
var actionTypeMatch = text.match(/"type"\s*:\s*"(\w+)"/);
|
|
5289
|
+
if (actionTypeMatch) {
|
|
5290
|
+
var result = {
|
|
5291
|
+
type: actionTypeMatch[1]
|
|
5292
|
+
};
|
|
5293
|
+
var xMatch = text.match(/"x"\s*:\s*\[?\s*(\d+)/);
|
|
5294
|
+
var yMatch = text.match(/"y"\s*:\s*(\d+)/);
|
|
5295
|
+
if (xMatch) result.x = parseInt(xMatch[1]);
|
|
5296
|
+
if (yMatch) {
|
|
5297
|
+
result.y = parseInt(yMatch[1]);
|
|
5298
|
+
} else if (xMatch) {
|
|
5299
|
+
var _xMatch_index;
|
|
5300
|
+
var afterX = text.slice(((_xMatch_index = xMatch.index) !== null && _xMatch_index !== void 0 ? _xMatch_index : 0) + xMatch[0].length);
|
|
5301
|
+
var nextNum = afterX.match(/\s*,?\s*(\d+)/);
|
|
5302
|
+
if (nextNum) result.y = parseInt(nextNum[1]);
|
|
5303
|
+
}
|
|
5304
|
+
var textMatch = text.match(/"text"\s*:\s*"([^"]*)"/);
|
|
5305
|
+
if (textMatch) result.text = textMatch[1];
|
|
5306
|
+
return {
|
|
5307
|
+
action: result
|
|
5308
|
+
};
|
|
5309
|
+
}
|
|
5310
|
+
var boxMatch = text.match(/"box_2d"\s*:\s*\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]/);
|
|
5311
|
+
if (boxMatch) {
|
|
5312
|
+
var y1 = parseInt(boxMatch[1]);
|
|
5313
|
+
var x1 = parseInt(boxMatch[2]);
|
|
5314
|
+
var y2 = parseInt(boxMatch[3]);
|
|
5315
|
+
var x2 = parseInt(boxMatch[4]);
|
|
5316
|
+
return {
|
|
5317
|
+
action: {
|
|
5318
|
+
type: "click",
|
|
5319
|
+
x: Math.round((x1 + x2) / 2),
|
|
5320
|
+
y: Math.round((y1 + y2) / 2)
|
|
5321
|
+
}
|
|
5322
|
+
};
|
|
5323
|
+
}
|
|
5324
|
+
return void 0;
|
|
5325
|
+
};
|
|
5326
|
+
var denormalize = function(value, dimension) {
|
|
5327
|
+
return Math.round(value / 1e3 * dimension);
|
|
5328
|
+
};
|
|
5329
|
+
var denormalizeAction = function(action, displayWidth, displayHeight) {
|
|
5330
|
+
var result = _object_spread({}, action);
|
|
5331
|
+
if (typeof result.x === "number") {
|
|
5332
|
+
result.x = denormalize(result.x, displayWidth);
|
|
5333
|
+
}
|
|
5334
|
+
if (typeof result.y === "number") {
|
|
5335
|
+
result.y = denormalize(result.y, displayHeight);
|
|
5336
|
+
}
|
|
5337
|
+
if (Array.isArray(result.path)) {
|
|
5338
|
+
result.path = result.path.map(function(point) {
|
|
5339
|
+
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5340
|
+
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5341
|
+
x: denormalize(point.x, displayWidth)
|
|
5342
|
+
} : {}, typeof point.y === "number" ? {
|
|
5343
|
+
y: denormalize(point.y, displayHeight)
|
|
5344
|
+
} : {});
|
|
5345
|
+
}
|
|
5346
|
+
return point;
|
|
5347
|
+
});
|
|
5348
|
+
}
|
|
5349
|
+
return result;
|
|
5350
|
+
};
|
|
5351
|
+
var rescaleCoord = function(value, displayDim, referenceDim) {
|
|
5352
|
+
if (value <= 1) return Math.round(value * displayDim);
|
|
5353
|
+
return Math.round(value / referenceDim * displayDim);
|
|
5354
|
+
};
|
|
5355
|
+
var rescaleRelativeAction = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
|
|
5356
|
+
var result = _object_spread({}, action);
|
|
5357
|
+
if (typeof result.x === "number") {
|
|
5358
|
+
result.x = rescaleCoord(result.x, displayWidth, referenceWidth);
|
|
5359
|
+
}
|
|
5360
|
+
if (typeof result.y === "number") {
|
|
5361
|
+
result.y = rescaleCoord(result.y, displayHeight, referenceHeight);
|
|
5362
|
+
}
|
|
5363
|
+
if (Array.isArray(result.path)) {
|
|
5364
|
+
result.path = result.path.map(function(point) {
|
|
5365
|
+
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5366
|
+
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5367
|
+
x: rescaleCoord(point.x, displayWidth, referenceWidth)
|
|
5368
|
+
} : {}, typeof point.y === "number" ? {
|
|
5369
|
+
y: rescaleCoord(point.y, displayHeight, referenceHeight)
|
|
5370
|
+
} : {});
|
|
5371
|
+
}
|
|
5372
|
+
return point;
|
|
5373
|
+
});
|
|
5374
|
+
}
|
|
5375
|
+
return result;
|
|
5376
|
+
};
|
|
5377
|
+
var COORD_FIELDS = [
|
|
5378
|
+
"x",
|
|
5379
|
+
"y",
|
|
5380
|
+
"text",
|
|
5381
|
+
"keys",
|
|
5382
|
+
"button",
|
|
5383
|
+
"direction",
|
|
5384
|
+
"scroll_x",
|
|
5385
|
+
"scroll_y",
|
|
5386
|
+
"path"
|
|
5387
|
+
];
|
|
5388
|
+
var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
5389
|
+
var clean = shouldCleanArtifacts ? function(action) {
|
|
5390
|
+
return applyArtifactCleanup(action);
|
|
5391
|
+
} : function(action) {
|
|
5392
|
+
return action;
|
|
5393
|
+
};
|
|
5394
|
+
if (parsed.action && _type_of(parsed.action) === "object") {
|
|
5395
|
+
return _object_spread_props(_object_spread({}, parsed), {
|
|
5396
|
+
action: clean(parsed.action)
|
|
5397
|
+
});
|
|
5398
|
+
}
|
|
5399
|
+
if (typeof parsed.action === "string") {
|
|
5400
|
+
var actionObj = {
|
|
5401
|
+
type: parsed.action
|
|
5402
|
+
};
|
|
5403
|
+
var rest = {};
|
|
5404
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5405
|
+
try {
|
|
5406
|
+
for(var _iterator = Object.entries(parsed)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5407
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
5408
|
+
if (key === "action") continue;
|
|
5409
|
+
if (COORD_FIELDS.includes(key)) {
|
|
5410
|
+
actionObj[key] = value;
|
|
5411
|
+
} else {
|
|
5412
|
+
rest[key] = value;
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
} catch (err) {
|
|
5416
|
+
_didIteratorError = true;
|
|
5417
|
+
_iteratorError = err;
|
|
5418
|
+
} finally{
|
|
5419
|
+
try {
|
|
5420
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5421
|
+
_iterator.return();
|
|
5422
|
+
}
|
|
5423
|
+
} finally{
|
|
5424
|
+
if (_didIteratorError) {
|
|
5425
|
+
throw _iteratorError;
|
|
5426
|
+
}
|
|
5427
|
+
}
|
|
5428
|
+
}
|
|
5429
|
+
return _object_spread_props(_object_spread({}, rest), {
|
|
5430
|
+
action: clean(actionObj)
|
|
5431
|
+
});
|
|
5432
|
+
}
|
|
5433
|
+
if (typeof parsed.type === "string") {
|
|
5434
|
+
var actionObj1 = {};
|
|
5435
|
+
var rest1 = {};
|
|
5436
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
5437
|
+
try {
|
|
5438
|
+
for(var _iterator1 = Object.entries(parsed)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
5439
|
+
var _step_value1 = _sliced_to_array(_step1.value, 2), key1 = _step_value1[0], value1 = _step_value1[1];
|
|
5440
|
+
if (key1 === "type" || COORD_FIELDS.includes(key1)) {
|
|
5441
|
+
actionObj1[key1] = value1;
|
|
5442
|
+
} else {
|
|
5443
|
+
rest1[key1] = value1;
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
} catch (err) {
|
|
5447
|
+
_didIteratorError1 = true;
|
|
5448
|
+
_iteratorError1 = err;
|
|
5449
|
+
} finally{
|
|
5450
|
+
try {
|
|
5451
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
5452
|
+
_iterator1.return();
|
|
5453
|
+
}
|
|
5454
|
+
} finally{
|
|
5455
|
+
if (_didIteratorError1) {
|
|
5456
|
+
throw _iteratorError1;
|
|
5457
|
+
}
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
return _object_spread_props(_object_spread({}, rest1), {
|
|
5461
|
+
action: clean(actionObj1)
|
|
5462
|
+
});
|
|
5463
|
+
}
|
|
5464
|
+
return parsed;
|
|
5465
|
+
};
|
|
5466
|
+
var denormalizeComputerCallArguments = function(param) {
|
|
5467
|
+
var argumentsText = param.argumentsText, displayWidth = param.displayWidth, displayHeight = param.displayHeight, model = param.model;
|
|
5468
|
+
if ((typeof argumentsText === "undefined" ? "undefined" : _type_of(argumentsText)) === "object" && argumentsText !== null) {
|
|
5469
|
+
argumentsText = JSON.stringify(argumentsText);
|
|
5470
|
+
}
|
|
5471
|
+
var quirks = getQuirks(model);
|
|
5472
|
+
var text = argumentsText;
|
|
5473
|
+
if (quirks.cleanArtifacts) {
|
|
5474
|
+
text = cleanTextArtifacts(text);
|
|
5475
|
+
}
|
|
5476
|
+
var parsed = extractJson(text);
|
|
5477
|
+
if (!parsed && (quirks.cleanArtifacts || quirks.fuzzyFallback)) {
|
|
5478
|
+
parsed = fuzzyExtractJson(text);
|
|
5479
|
+
}
|
|
5480
|
+
if (!parsed || (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) !== "object") {
|
|
5481
|
+
return argumentsText;
|
|
5482
|
+
}
|
|
5483
|
+
var normalized = normalizeStructure(parsed, !!quirks.cleanArtifacts);
|
|
5484
|
+
if (quirks.normalizedCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5485
|
+
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5486
|
+
action: denormalizeAction(normalized.action, displayWidth, displayHeight)
|
|
5487
|
+
}));
|
|
5488
|
+
}
|
|
5489
|
+
if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5490
|
+
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5491
|
+
action: rescaleRelativeAction(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
|
|
5492
|
+
}));
|
|
5493
|
+
}
|
|
5494
|
+
return JSON.stringify(normalized);
|
|
5495
|
+
};
|
|
5496
|
+
// src/adapters/client/ollamaClientAdapter/completions/computerUseTool.ts
|
|
5497
|
+
var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
|
|
5498
|
+
var quirks = getQuirks(model);
|
|
5499
|
+
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, ").");
|
|
5500
|
+
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, ")");
|
|
5501
|
+
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, ")");
|
|
5502
|
+
return {
|
|
5503
|
+
name: "computer_call",
|
|
5504
|
+
description: "Perform a computer action. ".concat(coordDesc),
|
|
5505
|
+
parameters: {
|
|
5506
|
+
type: "object",
|
|
5507
|
+
properties: {
|
|
5508
|
+
action: {
|
|
5509
|
+
type: "object",
|
|
5510
|
+
description: "The action to perform",
|
|
5511
|
+
properties: {
|
|
5512
|
+
type: {
|
|
5513
|
+
type: "string",
|
|
5514
|
+
enum: [
|
|
5515
|
+
"screenshot",
|
|
5516
|
+
"click",
|
|
5517
|
+
"double_click",
|
|
5518
|
+
"type",
|
|
5519
|
+
"keypress",
|
|
5520
|
+
"scroll",
|
|
5521
|
+
"move",
|
|
5522
|
+
"drag",
|
|
5523
|
+
"wait"
|
|
5524
|
+
]
|
|
5525
|
+
},
|
|
5526
|
+
x: {
|
|
5527
|
+
type: "number",
|
|
5528
|
+
description: xDesc
|
|
5529
|
+
},
|
|
5530
|
+
y: {
|
|
5531
|
+
type: "number",
|
|
5532
|
+
description: yDesc
|
|
5533
|
+
},
|
|
5534
|
+
text: {
|
|
5535
|
+
type: "string",
|
|
5536
|
+
description: "Text to type"
|
|
5537
|
+
},
|
|
5538
|
+
keys: {
|
|
5539
|
+
type: "array",
|
|
5540
|
+
items: {
|
|
5541
|
+
type: "string"
|
|
5542
|
+
},
|
|
5543
|
+
description: "Keys to press"
|
|
5544
|
+
},
|
|
5545
|
+
button: {
|
|
5546
|
+
type: "string",
|
|
5547
|
+
enum: [
|
|
5548
|
+
"left",
|
|
5549
|
+
"right",
|
|
5550
|
+
"wheel"
|
|
5551
|
+
]
|
|
5552
|
+
},
|
|
5553
|
+
direction: {
|
|
5554
|
+
type: "string",
|
|
5555
|
+
enum: [
|
|
5556
|
+
"up",
|
|
5557
|
+
"down",
|
|
5558
|
+
"left",
|
|
5559
|
+
"right"
|
|
5560
|
+
]
|
|
5561
|
+
},
|
|
5562
|
+
scroll_x: {
|
|
5563
|
+
type: "number"
|
|
5564
|
+
},
|
|
5565
|
+
scroll_y: {
|
|
5566
|
+
type: "number"
|
|
5567
|
+
},
|
|
5568
|
+
path: {
|
|
5569
|
+
type: "array",
|
|
5570
|
+
items: {
|
|
5571
|
+
type: "object",
|
|
5572
|
+
properties: {
|
|
5573
|
+
x: {
|
|
5574
|
+
type: "number"
|
|
5575
|
+
},
|
|
5576
|
+
y: {
|
|
5577
|
+
type: "number"
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5580
|
+
},
|
|
5581
|
+
description: "Path for drag action"
|
|
5582
|
+
}
|
|
5583
|
+
},
|
|
5584
|
+
required: [
|
|
5585
|
+
"type"
|
|
5586
|
+
]
|
|
5587
|
+
},
|
|
5588
|
+
pending_safety_checks: {
|
|
5589
|
+
type: "array",
|
|
5590
|
+
items: {
|
|
5591
|
+
type: "object"
|
|
5592
|
+
}
|
|
5593
|
+
}
|
|
5594
|
+
},
|
|
5595
|
+
required: [
|
|
5596
|
+
"action"
|
|
5597
|
+
]
|
|
5598
|
+
}
|
|
5599
|
+
};
|
|
5600
|
+
};
|
|
5601
|
+
var transformTools = function(tools, model) {
|
|
5602
|
+
if (!tools || tools.length === 0) {
|
|
5603
|
+
return {
|
|
5604
|
+
tools: tools !== null && tools !== void 0 ? tools : [],
|
|
5605
|
+
computerUseConfig: null
|
|
5606
|
+
};
|
|
5607
|
+
}
|
|
5608
|
+
var computerUseConfig = null;
|
|
5609
|
+
var transformed = tools.map(function(tool) {
|
|
5610
|
+
if (tool.type === "computer_use_preview") {
|
|
5611
|
+
var _tool_computer_use_preview, _ref, _config_display_width, _ref1, _config_display_height;
|
|
5612
|
+
var config = (_tool_computer_use_preview = tool.computer_use_preview) !== null && _tool_computer_use_preview !== void 0 ? _tool_computer_use_preview : tool;
|
|
5613
|
+
computerUseConfig = {
|
|
5614
|
+
displayWidth: (_ref = (_config_display_width = config.display_width) !== null && _config_display_width !== void 0 ? _config_display_width : config.display_width_px) !== null && _ref !== void 0 ? _ref : 1280,
|
|
5615
|
+
displayHeight: (_ref1 = (_config_display_height = config.display_height) !== null && _config_display_height !== void 0 ? _config_display_height : config.display_height_px) !== null && _ref1 !== void 0 ? _ref1 : 720
|
|
5616
|
+
};
|
|
5617
|
+
return {
|
|
5618
|
+
type: "function",
|
|
5619
|
+
function: buildComputerCallFunction(model, computerUseConfig.displayWidth, computerUseConfig.displayHeight)
|
|
5620
|
+
};
|
|
5621
|
+
}
|
|
5622
|
+
return tool;
|
|
5623
|
+
});
|
|
5624
|
+
return {
|
|
5625
|
+
tools: transformed,
|
|
5626
|
+
computerUseConfig: computerUseConfig
|
|
5627
|
+
};
|
|
5628
|
+
};
|
|
5077
5629
|
// src/adapters/client/ollamaClientAdapter/completions/post.ts
|
|
5078
5630
|
var encoder9 = new TextEncoder();
|
|
5631
|
+
var ARTIFACT_TAGS = /<\|begin_of_box\|>|<\|end_of_box\|>/g;
|
|
5632
|
+
var sanitizeContent = function(content) {
|
|
5633
|
+
if (!content) return content;
|
|
5634
|
+
return content.replace(ARTIFACT_TAGS, "").trim();
|
|
5635
|
+
};
|
|
5636
|
+
var convertScreenshotToolMessages = function(messages6) {
|
|
5637
|
+
return messages6.flatMap(function(msg) {
|
|
5638
|
+
if (msg.role !== "tool" || typeof msg.content !== "string") return [
|
|
5639
|
+
msg
|
|
5640
|
+
];
|
|
5641
|
+
try {
|
|
5642
|
+
var parsed = JSON.parse(msg.content);
|
|
5643
|
+
if (parsed.type === "computer_screenshot" && parsed.image_url) {
|
|
5644
|
+
return [
|
|
5645
|
+
_object_spread_props(_object_spread({}, msg), {
|
|
5646
|
+
content: ""
|
|
5647
|
+
}),
|
|
5648
|
+
{
|
|
5649
|
+
role: "user",
|
|
5650
|
+
content: [
|
|
5651
|
+
{
|
|
5652
|
+
type: "image_url",
|
|
5653
|
+
image_url: {
|
|
5654
|
+
url: parsed.image_url
|
|
5655
|
+
}
|
|
5656
|
+
}
|
|
5657
|
+
]
|
|
5658
|
+
}
|
|
5659
|
+
];
|
|
5660
|
+
}
|
|
5661
|
+
} catch (unused) {}
|
|
5662
|
+
return [
|
|
5663
|
+
msg
|
|
5664
|
+
];
|
|
5665
|
+
});
|
|
5666
|
+
};
|
|
5079
5667
|
var post9 = function(param) {
|
|
5080
5668
|
var ollama = param.ollama;
|
|
5081
5669
|
return function(_url, options) {
|
|
5082
5670
|
return _async_to_generator(function() {
|
|
5083
|
-
var body, response, stream, data, error;
|
|
5671
|
+
var body, model, _transformTools, transformedTools, computerUseConfig, resultOptions, response, shouldCleanArtifacts, stream2, stream21, displayWidth, displayHeight, stream, data, _data_choices, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, choice, _ref, message5, toolCalls, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _data_choices1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice1, message51, error;
|
|
5084
5672
|
return _ts_generator(this, function(_state) {
|
|
5085
5673
|
switch(_state.label){
|
|
5086
5674
|
case 0:
|
|
5087
5675
|
body = JSON.parse(options.body);
|
|
5676
|
+
model = body.model;
|
|
5677
|
+
_transformTools = transformTools(body.tools, model), transformedTools = _transformTools.tools, computerUseConfig = _transformTools.computerUseConfig;
|
|
5678
|
+
resultOptions = _object_spread({}, body, computerUseConfig && body.messages ? {
|
|
5679
|
+
messages: convertScreenshotToolMessages(body.messages)
|
|
5680
|
+
} : {}, transformedTools.length > 0 ? {
|
|
5681
|
+
tools: transformedTools
|
|
5682
|
+
} : {});
|
|
5088
5683
|
if (!body.stream) return [
|
|
5089
5684
|
3,
|
|
5090
5685
|
2
|
|
5091
5686
|
];
|
|
5092
5687
|
return [
|
|
5093
5688
|
4,
|
|
5094
|
-
ollama.chat.completions.create(
|
|
5689
|
+
ollama.chat.completions.create(resultOptions)
|
|
5095
5690
|
];
|
|
5096
5691
|
case 1:
|
|
5097
5692
|
response = _state.sent();
|
|
5693
|
+
shouldCleanArtifacts = !!getQuirks(model).cleanArtifacts;
|
|
5694
|
+
if (!computerUseConfig && !shouldCleanArtifacts) {
|
|
5695
|
+
stream2 = new ReadableStream({
|
|
5696
|
+
start: function start(controller) {
|
|
5697
|
+
return _async_to_generator(function() {
|
|
5698
|
+
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, err;
|
|
5699
|
+
return _ts_generator(this, function(_state) {
|
|
5700
|
+
switch(_state.label){
|
|
5701
|
+
case 0:
|
|
5702
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
5703
|
+
_state.label = 1;
|
|
5704
|
+
case 1:
|
|
5705
|
+
_state.trys.push([
|
|
5706
|
+
1,
|
|
5707
|
+
6,
|
|
5708
|
+
7,
|
|
5709
|
+
12
|
|
5710
|
+
]);
|
|
5711
|
+
_iterator = _async_iterator(response);
|
|
5712
|
+
_state.label = 2;
|
|
5713
|
+
case 2:
|
|
5714
|
+
return [
|
|
5715
|
+
4,
|
|
5716
|
+
_iterator.next()
|
|
5717
|
+
];
|
|
5718
|
+
case 3:
|
|
5719
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
5720
|
+
3,
|
|
5721
|
+
5
|
|
5722
|
+
];
|
|
5723
|
+
_value = _step.value;
|
|
5724
|
+
chunk = _value;
|
|
5725
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
5726
|
+
_state.label = 4;
|
|
5727
|
+
case 4:
|
|
5728
|
+
_iteratorAbruptCompletion = false;
|
|
5729
|
+
return [
|
|
5730
|
+
3,
|
|
5731
|
+
2
|
|
5732
|
+
];
|
|
5733
|
+
case 5:
|
|
5734
|
+
return [
|
|
5735
|
+
3,
|
|
5736
|
+
12
|
|
5737
|
+
];
|
|
5738
|
+
case 6:
|
|
5739
|
+
err = _state.sent();
|
|
5740
|
+
_didIteratorError = true;
|
|
5741
|
+
_iteratorError = err;
|
|
5742
|
+
return [
|
|
5743
|
+
3,
|
|
5744
|
+
12
|
|
5745
|
+
];
|
|
5746
|
+
case 7:
|
|
5747
|
+
_state.trys.push([
|
|
5748
|
+
7,
|
|
5749
|
+
,
|
|
5750
|
+
10,
|
|
5751
|
+
11
|
|
5752
|
+
]);
|
|
5753
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
5754
|
+
3,
|
|
5755
|
+
9
|
|
5756
|
+
];
|
|
5757
|
+
return [
|
|
5758
|
+
4,
|
|
5759
|
+
_iterator.return()
|
|
5760
|
+
];
|
|
5761
|
+
case 8:
|
|
5762
|
+
_state.sent();
|
|
5763
|
+
_state.label = 9;
|
|
5764
|
+
case 9:
|
|
5765
|
+
return [
|
|
5766
|
+
3,
|
|
5767
|
+
11
|
|
5768
|
+
];
|
|
5769
|
+
case 10:
|
|
5770
|
+
if (_didIteratorError) {
|
|
5771
|
+
throw _iteratorError;
|
|
5772
|
+
}
|
|
5773
|
+
return [
|
|
5774
|
+
7
|
|
5775
|
+
];
|
|
5776
|
+
case 11:
|
|
5777
|
+
return [
|
|
5778
|
+
7
|
|
5779
|
+
];
|
|
5780
|
+
case 12:
|
|
5781
|
+
controller.close();
|
|
5782
|
+
return [
|
|
5783
|
+
2
|
|
5784
|
+
];
|
|
5785
|
+
}
|
|
5786
|
+
});
|
|
5787
|
+
})();
|
|
5788
|
+
}
|
|
5789
|
+
});
|
|
5790
|
+
return [
|
|
5791
|
+
2,
|
|
5792
|
+
new Response(stream2, {
|
|
5793
|
+
headers: {
|
|
5794
|
+
"Content-Type": "text/event-stream"
|
|
5795
|
+
}
|
|
5796
|
+
})
|
|
5797
|
+
];
|
|
5798
|
+
}
|
|
5799
|
+
if (!computerUseConfig) {
|
|
5800
|
+
stream21 = new ReadableStream({
|
|
5801
|
+
start: function start(controller) {
|
|
5802
|
+
return _async_to_generator(function() {
|
|
5803
|
+
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, _choices_, choices, delta, err;
|
|
5804
|
+
return _ts_generator(this, function(_state) {
|
|
5805
|
+
switch(_state.label){
|
|
5806
|
+
case 0:
|
|
5807
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
5808
|
+
_state.label = 1;
|
|
5809
|
+
case 1:
|
|
5810
|
+
_state.trys.push([
|
|
5811
|
+
1,
|
|
5812
|
+
6,
|
|
5813
|
+
7,
|
|
5814
|
+
12
|
|
5815
|
+
]);
|
|
5816
|
+
_iterator = _async_iterator(response);
|
|
5817
|
+
_state.label = 2;
|
|
5818
|
+
case 2:
|
|
5819
|
+
return [
|
|
5820
|
+
4,
|
|
5821
|
+
_iterator.next()
|
|
5822
|
+
];
|
|
5823
|
+
case 3:
|
|
5824
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
5825
|
+
3,
|
|
5826
|
+
5
|
|
5827
|
+
];
|
|
5828
|
+
_value = _step.value;
|
|
5829
|
+
chunk = _value;
|
|
5830
|
+
choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
|
|
5831
|
+
delta = (_choices_ = choices[0]) === null || _choices_ === void 0 ? void 0 : _choices_.delta;
|
|
5832
|
+
if ((delta === null || delta === void 0 ? void 0 : delta.content) && typeof delta.content === "string") {
|
|
5833
|
+
delta.content = sanitizeContent(delta.content);
|
|
5834
|
+
}
|
|
5835
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
5836
|
+
_state.label = 4;
|
|
5837
|
+
case 4:
|
|
5838
|
+
_iteratorAbruptCompletion = false;
|
|
5839
|
+
return [
|
|
5840
|
+
3,
|
|
5841
|
+
2
|
|
5842
|
+
];
|
|
5843
|
+
case 5:
|
|
5844
|
+
return [
|
|
5845
|
+
3,
|
|
5846
|
+
12
|
|
5847
|
+
];
|
|
5848
|
+
case 6:
|
|
5849
|
+
err = _state.sent();
|
|
5850
|
+
_didIteratorError = true;
|
|
5851
|
+
_iteratorError = err;
|
|
5852
|
+
return [
|
|
5853
|
+
3,
|
|
5854
|
+
12
|
|
5855
|
+
];
|
|
5856
|
+
case 7:
|
|
5857
|
+
_state.trys.push([
|
|
5858
|
+
7,
|
|
5859
|
+
,
|
|
5860
|
+
10,
|
|
5861
|
+
11
|
|
5862
|
+
]);
|
|
5863
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
5864
|
+
3,
|
|
5865
|
+
9
|
|
5866
|
+
];
|
|
5867
|
+
return [
|
|
5868
|
+
4,
|
|
5869
|
+
_iterator.return()
|
|
5870
|
+
];
|
|
5871
|
+
case 8:
|
|
5872
|
+
_state.sent();
|
|
5873
|
+
_state.label = 9;
|
|
5874
|
+
case 9:
|
|
5875
|
+
return [
|
|
5876
|
+
3,
|
|
5877
|
+
11
|
|
5878
|
+
];
|
|
5879
|
+
case 10:
|
|
5880
|
+
if (_didIteratorError) {
|
|
5881
|
+
throw _iteratorError;
|
|
5882
|
+
}
|
|
5883
|
+
return [
|
|
5884
|
+
7
|
|
5885
|
+
];
|
|
5886
|
+
case 11:
|
|
5887
|
+
return [
|
|
5888
|
+
7
|
|
5889
|
+
];
|
|
5890
|
+
case 12:
|
|
5891
|
+
controller.close();
|
|
5892
|
+
return [
|
|
5893
|
+
2
|
|
5894
|
+
];
|
|
5895
|
+
}
|
|
5896
|
+
});
|
|
5897
|
+
})();
|
|
5898
|
+
}
|
|
5899
|
+
});
|
|
5900
|
+
return [
|
|
5901
|
+
2,
|
|
5902
|
+
new Response(stream21, {
|
|
5903
|
+
headers: {
|
|
5904
|
+
"Content-Type": "text/event-stream"
|
|
5905
|
+
}
|
|
5906
|
+
})
|
|
5907
|
+
];
|
|
5908
|
+
}
|
|
5909
|
+
displayWidth = computerUseConfig.displayWidth, displayHeight = computerUseConfig.displayHeight;
|
|
5098
5910
|
stream = new ReadableStream({
|
|
5099
5911
|
start: function start(controller) {
|
|
5100
5912
|
return _async_to_generator(function() {
|
|
5101
|
-
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk,
|
|
5913
|
+
var computerCallIndices, argumentBuffers, emittedIndices, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, toolCalls, passThrough, _iteratorNormalCompletion, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _ref, initialArgs, denormalized, _argumentBuffers_get, _ref1, buf, denormalized1, modifiedChunk, err1, _iteratorNormalCompletion1, _didIteratorError2, _iteratorError2, _iterator2, _step2, _step_value, index, buf1, denormalized2, flushChunk;
|
|
5102
5914
|
return _ts_generator(this, function(_state) {
|
|
5103
5915
|
switch(_state.label){
|
|
5104
5916
|
case 0:
|
|
5917
|
+
computerCallIndices = /* @__PURE__ */ new Set();
|
|
5918
|
+
argumentBuffers = /* @__PURE__ */ new Map();
|
|
5919
|
+
emittedIndices = /* @__PURE__ */ new Set();
|
|
5105
5920
|
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
5106
5921
|
_state.label = 1;
|
|
5107
5922
|
case 1:
|
|
@@ -5125,7 +5940,105 @@ var post9 = function(param) {
|
|
|
5125
5940
|
];
|
|
5126
5941
|
_value = _step.value;
|
|
5127
5942
|
chunk = _value;
|
|
5128
|
-
|
|
5943
|
+
choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
|
|
5944
|
+
choice = choices[0];
|
|
5945
|
+
delta = choice === null || choice === void 0 ? void 0 : choice.delta;
|
|
5946
|
+
toolCalls = delta === null || delta === void 0 ? void 0 : delta.tool_calls;
|
|
5947
|
+
if (!toolCalls) {
|
|
5948
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
5949
|
+
return [
|
|
5950
|
+
3,
|
|
5951
|
+
4
|
|
5952
|
+
];
|
|
5953
|
+
}
|
|
5954
|
+
passThrough = [];
|
|
5955
|
+
_iteratorNormalCompletion = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
5956
|
+
try {
|
|
5957
|
+
for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
|
|
5958
|
+
tc = _step1.value;
|
|
5959
|
+
fn = tc.function;
|
|
5960
|
+
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
5961
|
+
;
|
|
5962
|
+
computerCallIndices.add(tc.index);
|
|
5963
|
+
initialArgs = (_ref = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref !== void 0 ? _ref : "";
|
|
5964
|
+
argumentBuffers.set(tc.index, initialArgs);
|
|
5965
|
+
if (initialArgs) {
|
|
5966
|
+
try {
|
|
5967
|
+
JSON.parse(initialArgs);
|
|
5968
|
+
denormalized = denormalizeComputerCallArguments({
|
|
5969
|
+
argumentsText: initialArgs,
|
|
5970
|
+
displayWidth: displayWidth,
|
|
5971
|
+
displayHeight: displayHeight,
|
|
5972
|
+
model: model
|
|
5973
|
+
});
|
|
5974
|
+
passThrough.push(_object_spread_props(_object_spread({}, tc), {
|
|
5975
|
+
function: _object_spread_props(_object_spread({}, fn), {
|
|
5976
|
+
arguments: denormalized
|
|
5977
|
+
})
|
|
5978
|
+
}));
|
|
5979
|
+
emittedIndices.add(tc.index);
|
|
5980
|
+
continue;
|
|
5981
|
+
} catch (unused) {}
|
|
5982
|
+
}
|
|
5983
|
+
passThrough.push(_object_spread_props(_object_spread({}, tc), {
|
|
5984
|
+
function: _object_spread_props(_object_spread({}, fn), {
|
|
5985
|
+
arguments: ""
|
|
5986
|
+
})
|
|
5987
|
+
}));
|
|
5988
|
+
continue;
|
|
5989
|
+
}
|
|
5990
|
+
if (computerCallIndices.has(tc.index)) {
|
|
5991
|
+
;
|
|
5992
|
+
buf = ((_argumentBuffers_get = argumentBuffers.get(tc.index)) !== null && _argumentBuffers_get !== void 0 ? _argumentBuffers_get : "") + ((_ref1 = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref1 !== void 0 ? _ref1 : "");
|
|
5993
|
+
argumentBuffers.set(tc.index, buf);
|
|
5994
|
+
if (!emittedIndices.has(tc.index)) {
|
|
5995
|
+
try {
|
|
5996
|
+
JSON.parse(buf);
|
|
5997
|
+
denormalized1 = denormalizeComputerCallArguments({
|
|
5998
|
+
argumentsText: buf,
|
|
5999
|
+
displayWidth: displayWidth,
|
|
6000
|
+
displayHeight: displayHeight,
|
|
6001
|
+
model: model
|
|
6002
|
+
});
|
|
6003
|
+
passThrough.push({
|
|
6004
|
+
index: tc.index,
|
|
6005
|
+
function: {
|
|
6006
|
+
arguments: denormalized1
|
|
6007
|
+
}
|
|
6008
|
+
});
|
|
6009
|
+
emittedIndices.add(tc.index);
|
|
6010
|
+
} catch (unused) {}
|
|
6011
|
+
}
|
|
6012
|
+
continue;
|
|
6013
|
+
}
|
|
6014
|
+
passThrough.push(tc);
|
|
6015
|
+
}
|
|
6016
|
+
} catch (err) {
|
|
6017
|
+
_didIteratorError1 = true;
|
|
6018
|
+
_iteratorError1 = err;
|
|
6019
|
+
} finally{
|
|
6020
|
+
try {
|
|
6021
|
+
if (!_iteratorNormalCompletion && _iterator1.return != null) {
|
|
6022
|
+
_iterator1.return();
|
|
6023
|
+
}
|
|
6024
|
+
} finally{
|
|
6025
|
+
if (_didIteratorError1) {
|
|
6026
|
+
throw _iteratorError1;
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
if (passThrough.length > 0) {
|
|
6031
|
+
modifiedChunk = _object_spread_props(_object_spread({}, chunk), {
|
|
6032
|
+
choices: [
|
|
6033
|
+
_object_spread_props(_object_spread({}, choice), {
|
|
6034
|
+
delta: _object_spread_props(_object_spread({}, delta), {
|
|
6035
|
+
tool_calls: passThrough
|
|
6036
|
+
})
|
|
6037
|
+
})
|
|
6038
|
+
]
|
|
6039
|
+
});
|
|
6040
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(modifiedChunk), "\n\n")));
|
|
6041
|
+
}
|
|
5129
6042
|
_state.label = 4;
|
|
5130
6043
|
case 4:
|
|
5131
6044
|
_iteratorAbruptCompletion = false;
|
|
@@ -5139,9 +6052,9 @@ var post9 = function(param) {
|
|
|
5139
6052
|
12
|
|
5140
6053
|
];
|
|
5141
6054
|
case 6:
|
|
5142
|
-
|
|
6055
|
+
err1 = _state.sent();
|
|
5143
6056
|
_didIteratorError = true;
|
|
5144
|
-
_iteratorError =
|
|
6057
|
+
_iteratorError = err1;
|
|
5145
6058
|
return [
|
|
5146
6059
|
3,
|
|
5147
6060
|
12
|
|
@@ -5181,6 +6094,52 @@ var post9 = function(param) {
|
|
|
5181
6094
|
7
|
|
5182
6095
|
];
|
|
5183
6096
|
case 12:
|
|
6097
|
+
_iteratorNormalCompletion1 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
6098
|
+
try {
|
|
6099
|
+
for(_iterator2 = Array.from(argumentBuffers)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
|
|
6100
|
+
_step_value = _sliced_to_array(_step2.value, 2), index = _step_value[0], buf1 = _step_value[1];
|
|
6101
|
+
if (!emittedIndices.has(index) && buf1) {
|
|
6102
|
+
denormalized2 = denormalizeComputerCallArguments({
|
|
6103
|
+
argumentsText: buf1,
|
|
6104
|
+
displayWidth: displayWidth,
|
|
6105
|
+
displayHeight: displayHeight,
|
|
6106
|
+
model: model
|
|
6107
|
+
});
|
|
6108
|
+
flushChunk = {
|
|
6109
|
+
object: "chat.completion.chunk",
|
|
6110
|
+
choices: [
|
|
6111
|
+
{
|
|
6112
|
+
index: 0,
|
|
6113
|
+
delta: {
|
|
6114
|
+
tool_calls: [
|
|
6115
|
+
{
|
|
6116
|
+
index: index,
|
|
6117
|
+
function: {
|
|
6118
|
+
arguments: denormalized2
|
|
6119
|
+
}
|
|
6120
|
+
}
|
|
6121
|
+
]
|
|
6122
|
+
}
|
|
6123
|
+
}
|
|
6124
|
+
]
|
|
6125
|
+
};
|
|
6126
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(flushChunk), "\n\n")));
|
|
6127
|
+
}
|
|
6128
|
+
}
|
|
6129
|
+
} catch (err) {
|
|
6130
|
+
_didIteratorError2 = true;
|
|
6131
|
+
_iteratorError2 = err;
|
|
6132
|
+
} finally{
|
|
6133
|
+
try {
|
|
6134
|
+
if (!_iteratorNormalCompletion1 && _iterator2.return != null) {
|
|
6135
|
+
_iterator2.return();
|
|
6136
|
+
}
|
|
6137
|
+
} finally{
|
|
6138
|
+
if (_didIteratorError2) {
|
|
6139
|
+
throw _iteratorError2;
|
|
6140
|
+
}
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
5184
6143
|
controller.close();
|
|
5185
6144
|
return [
|
|
5186
6145
|
2
|
|
@@ -5207,15 +6166,92 @@ var post9 = function(param) {
|
|
|
5207
6166
|
]);
|
|
5208
6167
|
return [
|
|
5209
6168
|
4,
|
|
5210
|
-
ollama.chat.completions.create(
|
|
6169
|
+
ollama.chat.completions.create(resultOptions)
|
|
5211
6170
|
];
|
|
5212
6171
|
case 3:
|
|
5213
6172
|
data = _state.sent();
|
|
6173
|
+
if (computerUseConfig) {
|
|
6174
|
+
;
|
|
6175
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
6176
|
+
try {
|
|
6177
|
+
for(_iterator = ((_data_choices = data.choices) !== null && _data_choices !== void 0 ? _data_choices : [])[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
6178
|
+
choice = _step.value;
|
|
6179
|
+
;
|
|
6180
|
+
message5 = choice.message;
|
|
6181
|
+
toolCalls = (_ref = message5 === null || message5 === void 0 ? void 0 : message5.tool_calls) !== null && _ref !== void 0 ? _ref : [];
|
|
6182
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
6183
|
+
try {
|
|
6184
|
+
for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
6185
|
+
tc = _step1.value;
|
|
6186
|
+
fn = tc.function;
|
|
6187
|
+
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
6188
|
+
fn.arguments = denormalizeComputerCallArguments({
|
|
6189
|
+
argumentsText: fn.arguments,
|
|
6190
|
+
displayWidth: computerUseConfig.displayWidth,
|
|
6191
|
+
displayHeight: computerUseConfig.displayHeight,
|
|
6192
|
+
model: model
|
|
6193
|
+
});
|
|
6194
|
+
}
|
|
6195
|
+
}
|
|
6196
|
+
} catch (err) {
|
|
6197
|
+
_didIteratorError1 = true;
|
|
6198
|
+
_iteratorError1 = err;
|
|
6199
|
+
} finally{
|
|
6200
|
+
try {
|
|
6201
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
6202
|
+
_iterator1.return();
|
|
6203
|
+
}
|
|
6204
|
+
} finally{
|
|
6205
|
+
if (_didIteratorError1) {
|
|
6206
|
+
throw _iteratorError1;
|
|
6207
|
+
}
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
} catch (err) {
|
|
6212
|
+
_didIteratorError = true;
|
|
6213
|
+
_iteratorError = err;
|
|
6214
|
+
} finally{
|
|
6215
|
+
try {
|
|
6216
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
6217
|
+
_iterator.return();
|
|
6218
|
+
}
|
|
6219
|
+
} finally{
|
|
6220
|
+
if (_didIteratorError) {
|
|
6221
|
+
throw _iteratorError;
|
|
6222
|
+
}
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
}
|
|
6226
|
+
if (getQuirks(model).cleanArtifacts) {
|
|
6227
|
+
;
|
|
6228
|
+
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
6229
|
+
try {
|
|
6230
|
+
for(_iterator2 = ((_data_choices1 = data.choices) !== null && _data_choices1 !== void 0 ? _data_choices1 : [])[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
6231
|
+
choice1 = _step2.value;
|
|
6232
|
+
message51 = choice1.message;
|
|
6233
|
+
if ((message51 === null || message51 === void 0 ? void 0 : message51.content) && typeof message51.content === "string") {
|
|
6234
|
+
message51.content = sanitizeContent(message51.content);
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
} catch (err) {
|
|
6238
|
+
_didIteratorError2 = true;
|
|
6239
|
+
_iteratorError2 = err;
|
|
6240
|
+
} finally{
|
|
6241
|
+
try {
|
|
6242
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
6243
|
+
_iterator2.return();
|
|
6244
|
+
}
|
|
6245
|
+
} finally{
|
|
6246
|
+
if (_didIteratorError2) {
|
|
6247
|
+
throw _iteratorError2;
|
|
6248
|
+
}
|
|
6249
|
+
}
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
5214
6252
|
return [
|
|
5215
6253
|
2,
|
|
5216
|
-
new Response(JSON.stringify({
|
|
5217
|
-
data: data
|
|
5218
|
-
}), {
|
|
6254
|
+
new Response(JSON.stringify(data), {
|
|
5219
6255
|
status: 200,
|
|
5220
6256
|
headers: {
|
|
5221
6257
|
"Content-Type": "application/json"
|
|
@@ -5341,7 +6377,7 @@ var models13 = function(param) {
|
|
|
5341
6377
|
};
|
|
5342
6378
|
};
|
|
5343
6379
|
// src/adapters/client/openRouterClientAdapter/completions/normalizeComputerCall.ts
|
|
5344
|
-
var
|
|
6380
|
+
var MODEL_QUIRKS2 = {
|
|
5345
6381
|
"z-ai/glm-4.6v": {
|
|
5346
6382
|
normalizedCoords: true,
|
|
5347
6383
|
cleanArtifacts: true
|
|
@@ -5354,12 +6390,20 @@ var MODEL_QUIRKS = {
|
|
|
5354
6390
|
referenceWidth: 1920,
|
|
5355
6391
|
referenceHeight: 1080
|
|
5356
6392
|
}
|
|
6393
|
+
},
|
|
6394
|
+
"google/gemma-4": {
|
|
6395
|
+
normalizedCoords: true,
|
|
6396
|
+
fuzzyFallback: true
|
|
6397
|
+
},
|
|
6398
|
+
"google/gemma-3": {
|
|
6399
|
+
normalizedCoords: true,
|
|
6400
|
+
fuzzyFallback: true
|
|
5357
6401
|
}
|
|
5358
6402
|
};
|
|
5359
|
-
var
|
|
6403
|
+
var getQuirks2 = function(model) {
|
|
5360
6404
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5361
6405
|
try {
|
|
5362
|
-
for(var _iterator = Object.entries(
|
|
6406
|
+
for(var _iterator = Object.entries(MODEL_QUIRKS2)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5363
6407
|
var _step_value = _sliced_to_array(_step.value, 2), prefix = _step_value[0], quirks = _step_value[1];
|
|
5364
6408
|
if (model.startsWith(prefix)) return quirks;
|
|
5365
6409
|
}
|
|
@@ -5379,10 +6423,10 @@ var getQuirks = function(model) {
|
|
|
5379
6423
|
}
|
|
5380
6424
|
return {};
|
|
5381
6425
|
};
|
|
5382
|
-
var
|
|
6426
|
+
var cleanTextArtifacts2 = function(text) {
|
|
5383
6427
|
return text.replace(/<\|begin_of_box\|>/g, "").replace(/<\|end_of_box\|>/g, "").replace(/<arg_key>[^<]*<\/arg_key>/g, "").replace(/<\/arg_value>/g, "").trim();
|
|
5384
6428
|
};
|
|
5385
|
-
var
|
|
6429
|
+
var KNOWN_ACTION_TYPES2 = [
|
|
5386
6430
|
"double_click",
|
|
5387
6431
|
"screenshot",
|
|
5388
6432
|
"keypress",
|
|
@@ -5393,7 +6437,7 @@ var KNOWN_ACTION_TYPES = [
|
|
|
5393
6437
|
"drag",
|
|
5394
6438
|
"wait"
|
|
5395
6439
|
];
|
|
5396
|
-
var
|
|
6440
|
+
var splitCoordDigits2 = function(numStr) {
|
|
5397
6441
|
for(var i = 1; i < numStr.length; i++){
|
|
5398
6442
|
var x = parseInt(numStr.slice(0, i));
|
|
5399
6443
|
var y = parseInt(numStr.slice(i));
|
|
@@ -5406,12 +6450,12 @@ var splitCoordDigits = function(numStr) {
|
|
|
5406
6450
|
}
|
|
5407
6451
|
return null;
|
|
5408
6452
|
};
|
|
5409
|
-
var
|
|
6453
|
+
var cleanGlmAction2 = function(action) {
|
|
5410
6454
|
var typeVal = action.type;
|
|
5411
6455
|
if (typeof typeVal !== "string") return action;
|
|
5412
6456
|
var argValueMatch = typeVal.match(/<arg_value>\s*(\{[\s\S]*\})\s*$/);
|
|
5413
6457
|
if (argValueMatch) {
|
|
5414
|
-
var inner =
|
|
6458
|
+
var inner = parseJson3(argValueMatch[1]);
|
|
5415
6459
|
if (inner && (typeof inner === "undefined" ? "undefined" : _type_of(inner)) === "object") {
|
|
5416
6460
|
return inner;
|
|
5417
6461
|
}
|
|
@@ -5419,7 +6463,7 @@ var cleanGlmAction = function(action) {
|
|
|
5419
6463
|
var cleanedType = typeVal.replace(/<\/?[^>]+>/g, "").replace(/\n/g, "").trim();
|
|
5420
6464
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5421
6465
|
try {
|
|
5422
|
-
for(var _iterator =
|
|
6466
|
+
for(var _iterator = KNOWN_ACTION_TYPES2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5423
6467
|
var actionType = _step.value;
|
|
5424
6468
|
if (cleanedType.startsWith(actionType) && cleanedType !== actionType) {
|
|
5425
6469
|
var rest = cleanedType.slice(actionType.length);
|
|
@@ -5432,7 +6476,7 @@ var cleanGlmAction = function(action) {
|
|
|
5432
6476
|
});
|
|
5433
6477
|
}
|
|
5434
6478
|
if (nums && nums.length === 1 && nums[0].length >= 2) {
|
|
5435
|
-
var coords =
|
|
6479
|
+
var coords = splitCoordDigits2(nums[0]);
|
|
5436
6480
|
if (coords) {
|
|
5437
6481
|
return _object_spread(_object_spread_props(_object_spread({}, action), {
|
|
5438
6482
|
type: actionType
|
|
@@ -5463,7 +6507,7 @@ var cleanGlmAction = function(action) {
|
|
|
5463
6507
|
type: cleanedType
|
|
5464
6508
|
});
|
|
5465
6509
|
};
|
|
5466
|
-
var
|
|
6510
|
+
var cleanGlmFields2 = function(action) {
|
|
5467
6511
|
var result = _object_spread({}, action);
|
|
5468
6512
|
if (typeof result.x === "string") {
|
|
5469
6513
|
var nums = result.x.match(/\d+/g);
|
|
@@ -5497,32 +6541,32 @@ var cleanGlmFields = function(action) {
|
|
|
5497
6541
|
}
|
|
5498
6542
|
return result;
|
|
5499
6543
|
};
|
|
5500
|
-
var
|
|
5501
|
-
return
|
|
6544
|
+
var applyArtifactCleanup2 = function(action) {
|
|
6545
|
+
return cleanGlmFields2(cleanGlmAction2(action));
|
|
5502
6546
|
};
|
|
5503
|
-
var
|
|
6547
|
+
var parseJson3 = function(text) {
|
|
5504
6548
|
try {
|
|
5505
6549
|
return JSON.parse(text);
|
|
5506
6550
|
} catch (unused) {
|
|
5507
6551
|
return void 0;
|
|
5508
6552
|
}
|
|
5509
6553
|
};
|
|
5510
|
-
var
|
|
5511
|
-
var direct =
|
|
6554
|
+
var extractJson2 = function(text) {
|
|
6555
|
+
var direct = parseJson3(text);
|
|
5512
6556
|
if (direct) return direct;
|
|
5513
6557
|
var codeBlockMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
5514
6558
|
if (codeBlockMatch) {
|
|
5515
|
-
var parsed =
|
|
6559
|
+
var parsed = parseJson3(codeBlockMatch[1].trim());
|
|
5516
6560
|
if (parsed) return parsed;
|
|
5517
6561
|
}
|
|
5518
6562
|
var jsonMatch = text.match(/(\{[\s\S]*\})\s*$/);
|
|
5519
6563
|
if (jsonMatch) {
|
|
5520
|
-
var parsed1 =
|
|
6564
|
+
var parsed1 = parseJson3(jsonMatch[1].trim());
|
|
5521
6565
|
if (parsed1) return parsed1;
|
|
5522
6566
|
}
|
|
5523
6567
|
return void 0;
|
|
5524
6568
|
};
|
|
5525
|
-
var
|
|
6569
|
+
var fuzzyExtractJson2 = function(text) {
|
|
5526
6570
|
var clickMatch = text.match(/"action"\s*:\s*"click"\s*,\s*"x"\s*:\s*\[?\s*(\d+)\s*,\s*(\d+)/);
|
|
5527
6571
|
if (clickMatch) {
|
|
5528
6572
|
return {
|
|
@@ -5557,24 +6601,24 @@ var fuzzyExtractJson = function(text) {
|
|
|
5557
6601
|
}
|
|
5558
6602
|
return void 0;
|
|
5559
6603
|
};
|
|
5560
|
-
var
|
|
6604
|
+
var denormalize2 = function(value, dimension) {
|
|
5561
6605
|
return Math.round(value / 1e3 * dimension);
|
|
5562
6606
|
};
|
|
5563
|
-
var
|
|
6607
|
+
var denormalizeAction2 = function(action, displayWidth, displayHeight) {
|
|
5564
6608
|
var result = _object_spread({}, action);
|
|
5565
6609
|
if (typeof result.x === "number") {
|
|
5566
|
-
result.x =
|
|
6610
|
+
result.x = denormalize2(result.x, displayWidth);
|
|
5567
6611
|
}
|
|
5568
6612
|
if (typeof result.y === "number") {
|
|
5569
|
-
result.y =
|
|
6613
|
+
result.y = denormalize2(result.y, displayHeight);
|
|
5570
6614
|
}
|
|
5571
6615
|
if (Array.isArray(result.path)) {
|
|
5572
6616
|
result.path = result.path.map(function(point) {
|
|
5573
6617
|
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5574
6618
|
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5575
|
-
x:
|
|
6619
|
+
x: denormalize2(point.x, displayWidth)
|
|
5576
6620
|
} : {}, typeof point.y === "number" ? {
|
|
5577
|
-
y:
|
|
6621
|
+
y: denormalize2(point.y, displayHeight)
|
|
5578
6622
|
} : {});
|
|
5579
6623
|
}
|
|
5580
6624
|
return point;
|
|
@@ -5582,25 +6626,25 @@ var denormalizeAction = function(action, displayWidth, displayHeight) {
|
|
|
5582
6626
|
}
|
|
5583
6627
|
return result;
|
|
5584
6628
|
};
|
|
5585
|
-
var
|
|
6629
|
+
var rescaleCoord2 = function(value, displayDim, referenceDim) {
|
|
5586
6630
|
if (value <= 1) return Math.round(value * displayDim);
|
|
5587
6631
|
return Math.round(value / referenceDim * displayDim);
|
|
5588
6632
|
};
|
|
5589
|
-
var
|
|
6633
|
+
var rescaleRelativeAction2 = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
|
|
5590
6634
|
var result = _object_spread({}, action);
|
|
5591
6635
|
if (typeof result.x === "number") {
|
|
5592
|
-
result.x =
|
|
6636
|
+
result.x = rescaleCoord2(result.x, displayWidth, referenceWidth);
|
|
5593
6637
|
}
|
|
5594
6638
|
if (typeof result.y === "number") {
|
|
5595
|
-
result.y =
|
|
6639
|
+
result.y = rescaleCoord2(result.y, displayHeight, referenceHeight);
|
|
5596
6640
|
}
|
|
5597
6641
|
if (Array.isArray(result.path)) {
|
|
5598
6642
|
result.path = result.path.map(function(point) {
|
|
5599
6643
|
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5600
6644
|
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5601
|
-
x:
|
|
6645
|
+
x: rescaleCoord2(point.x, displayWidth, referenceWidth)
|
|
5602
6646
|
} : {}, typeof point.y === "number" ? {
|
|
5603
|
-
y:
|
|
6647
|
+
y: rescaleCoord2(point.y, displayHeight, referenceHeight)
|
|
5604
6648
|
} : {});
|
|
5605
6649
|
}
|
|
5606
6650
|
return point;
|
|
@@ -5608,7 +6652,7 @@ var rescaleRelativeAction = function(action, displayWidth, displayHeight, refere
|
|
|
5608
6652
|
}
|
|
5609
6653
|
return result;
|
|
5610
6654
|
};
|
|
5611
|
-
var
|
|
6655
|
+
var COORD_FIELDS2 = [
|
|
5612
6656
|
"x",
|
|
5613
6657
|
"y",
|
|
5614
6658
|
"text",
|
|
@@ -5619,9 +6663,9 @@ var COORD_FIELDS = [
|
|
|
5619
6663
|
"scroll_y",
|
|
5620
6664
|
"path"
|
|
5621
6665
|
];
|
|
5622
|
-
var
|
|
6666
|
+
var normalizeStructure2 = function(parsed, shouldCleanArtifacts) {
|
|
5623
6667
|
var clean = shouldCleanArtifacts ? function(action) {
|
|
5624
|
-
return
|
|
6668
|
+
return applyArtifactCleanup2(action);
|
|
5625
6669
|
} : function(action) {
|
|
5626
6670
|
return action;
|
|
5627
6671
|
};
|
|
@@ -5640,7 +6684,7 @@ var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
|
5640
6684
|
for(var _iterator = Object.entries(parsed)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5641
6685
|
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
5642
6686
|
if (key === "action") continue;
|
|
5643
|
-
if (
|
|
6687
|
+
if (COORD_FIELDS2.includes(key)) {
|
|
5644
6688
|
actionObj[key] = value;
|
|
5645
6689
|
} else {
|
|
5646
6690
|
rest[key] = value;
|
|
@@ -5671,7 +6715,7 @@ var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
|
5671
6715
|
try {
|
|
5672
6716
|
for(var _iterator1 = Object.entries(parsed)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
5673
6717
|
var _step_value1 = _sliced_to_array(_step1.value, 2), key1 = _step_value1[0], value1 = _step_value1[1];
|
|
5674
|
-
if (key1 === "type" ||
|
|
6718
|
+
if (key1 === "type" || COORD_FIELDS2.includes(key1)) {
|
|
5675
6719
|
actionObj1[key1] = value1;
|
|
5676
6720
|
} else {
|
|
5677
6721
|
rest1[key1] = value1;
|
|
@@ -5697,39 +6741,39 @@ var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
|
5697
6741
|
}
|
|
5698
6742
|
return parsed;
|
|
5699
6743
|
};
|
|
5700
|
-
var
|
|
6744
|
+
var denormalizeComputerCallArguments2 = function(param) {
|
|
5701
6745
|
var argumentsText = param.argumentsText, displayWidth = param.displayWidth, displayHeight = param.displayHeight, model = param.model;
|
|
5702
6746
|
if ((typeof argumentsText === "undefined" ? "undefined" : _type_of(argumentsText)) === "object" && argumentsText !== null) {
|
|
5703
6747
|
argumentsText = JSON.stringify(argumentsText);
|
|
5704
6748
|
}
|
|
5705
|
-
var quirks =
|
|
6749
|
+
var quirks = getQuirks2(model);
|
|
5706
6750
|
var text = argumentsText;
|
|
5707
6751
|
if (quirks.cleanArtifacts) {
|
|
5708
|
-
text =
|
|
6752
|
+
text = cleanTextArtifacts2(text);
|
|
5709
6753
|
}
|
|
5710
|
-
var parsed =
|
|
6754
|
+
var parsed = extractJson2(text);
|
|
5711
6755
|
if (!parsed && (quirks.cleanArtifacts || quirks.fuzzyFallback)) {
|
|
5712
|
-
parsed =
|
|
6756
|
+
parsed = fuzzyExtractJson2(text);
|
|
5713
6757
|
}
|
|
5714
6758
|
if (!parsed || (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) !== "object") {
|
|
5715
6759
|
return argumentsText;
|
|
5716
6760
|
}
|
|
5717
|
-
var normalized =
|
|
6761
|
+
var normalized = normalizeStructure2(parsed, !!quirks.cleanArtifacts);
|
|
5718
6762
|
if (quirks.normalizedCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5719
6763
|
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5720
|
-
action:
|
|
6764
|
+
action: denormalizeAction2(normalized.action, displayWidth, displayHeight)
|
|
5721
6765
|
}));
|
|
5722
6766
|
}
|
|
5723
6767
|
if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5724
6768
|
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5725
|
-
action:
|
|
6769
|
+
action: rescaleRelativeAction2(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
|
|
5726
6770
|
}));
|
|
5727
6771
|
}
|
|
5728
6772
|
return JSON.stringify(normalized);
|
|
5729
6773
|
};
|
|
5730
6774
|
// src/adapters/client/openRouterClientAdapter/completions/computerUseTool.ts
|
|
5731
|
-
var
|
|
5732
|
-
var quirks =
|
|
6775
|
+
var buildComputerCallFunction2 = function(model, displayWidth, displayHeight) {
|
|
6776
|
+
var quirks = getQuirks2(model);
|
|
5733
6777
|
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, ").");
|
|
5734
6778
|
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, ")");
|
|
5735
6779
|
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, ")");
|
|
@@ -5832,7 +6876,7 @@ var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
|
|
|
5832
6876
|
}
|
|
5833
6877
|
};
|
|
5834
6878
|
};
|
|
5835
|
-
var
|
|
6879
|
+
var transformTools2 = function(tools, model) {
|
|
5836
6880
|
if (!tools || tools.length === 0) {
|
|
5837
6881
|
return {
|
|
5838
6882
|
tools: tools !== null && tools !== void 0 ? tools : [],
|
|
@@ -5850,7 +6894,7 @@ var transformTools = function(tools, model) {
|
|
|
5850
6894
|
};
|
|
5851
6895
|
return {
|
|
5852
6896
|
type: "function",
|
|
5853
|
-
function:
|
|
6897
|
+
function: buildComputerCallFunction2(model, computerUseConfig.displayWidth, computerUseConfig.displayHeight)
|
|
5854
6898
|
};
|
|
5855
6899
|
}
|
|
5856
6900
|
return tool;
|
|
@@ -5862,12 +6906,12 @@ var transformTools = function(tools, model) {
|
|
|
5862
6906
|
};
|
|
5863
6907
|
// src/adapters/client/openRouterClientAdapter/completions/post.ts
|
|
5864
6908
|
var encoder10 = new TextEncoder();
|
|
5865
|
-
var
|
|
5866
|
-
var
|
|
6909
|
+
var ARTIFACT_TAGS2 = /<\|begin_of_box\|>|<\|end_of_box\|>/g;
|
|
6910
|
+
var sanitizeContent2 = function(content) {
|
|
5867
6911
|
if (!content) return content;
|
|
5868
|
-
return content.replace(
|
|
6912
|
+
return content.replace(ARTIFACT_TAGS2, "").trim();
|
|
5869
6913
|
};
|
|
5870
|
-
var
|
|
6914
|
+
var convertScreenshotToolMessages2 = function(messages6) {
|
|
5871
6915
|
return messages6.map(function(msg) {
|
|
5872
6916
|
if (msg.role !== "tool" || typeof msg.content !== "string") return msg;
|
|
5873
6917
|
try {
|
|
@@ -6111,17 +7155,17 @@ var post10 = function(param) {
|
|
|
6111
7155
|
var openRouter = param.openRouter, provider = param.provider;
|
|
6112
7156
|
return function(_url, options) {
|
|
6113
7157
|
return _async_to_generator(function() {
|
|
6114
|
-
var body, model,
|
|
7158
|
+
var body, model, _transformTools2, transformedTools, computerUseConfig, resultOptions, response, _response_headers_get, shouldCleanArtifacts, readableStream2, displayWidth, displayHeight, readableStream, response1, _response_headers_get1, data, _data_choices, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, choice, _ref, message5, toolCalls, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _data_choices1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice1, message51, error;
|
|
6115
7159
|
return _ts_generator(this, function(_state) {
|
|
6116
7160
|
switch(_state.label){
|
|
6117
7161
|
case 0:
|
|
6118
7162
|
body = JSON.parse(options.body);
|
|
6119
7163
|
model = body.model;
|
|
6120
|
-
|
|
7164
|
+
_transformTools2 = transformTools2(body.tools, model), transformedTools = _transformTools2.tools, computerUseConfig = _transformTools2.computerUseConfig;
|
|
6121
7165
|
resultOptions = _object_spread({}, body, provider && !body.provider ? {
|
|
6122
7166
|
provider: provider
|
|
6123
7167
|
} : {}, computerUseConfig && body.messages ? {
|
|
6124
|
-
messages:
|
|
7168
|
+
messages: convertScreenshotToolMessages2(body.messages)
|
|
6125
7169
|
} : {}, transformedTools.length > 0 ? {
|
|
6126
7170
|
tools: transformedTools
|
|
6127
7171
|
} : {});
|
|
@@ -6147,7 +7191,7 @@ var post10 = function(param) {
|
|
|
6147
7191
|
})
|
|
6148
7192
|
];
|
|
6149
7193
|
}
|
|
6150
|
-
shouldCleanArtifacts =
|
|
7194
|
+
shouldCleanArtifacts = getQuirks2(model).cleanArtifacts;
|
|
6151
7195
|
if (!computerUseConfig && !shouldCleanArtifacts) {
|
|
6152
7196
|
return [
|
|
6153
7197
|
2,
|
|
@@ -6193,7 +7237,7 @@ var post10 = function(param) {
|
|
|
6193
7237
|
delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : _chunk_choices[0];
|
|
6194
7238
|
d = delta === null || delta === void 0 ? void 0 : delta.delta;
|
|
6195
7239
|
if ((d === null || d === void 0 ? void 0 : d.content) && typeof d.content === "string") {
|
|
6196
|
-
d.content =
|
|
7240
|
+
d.content = sanitizeContent2(d.content);
|
|
6197
7241
|
}
|
|
6198
7242
|
controller.enqueue(encoder10.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
6199
7243
|
_state.label = 4;
|
|
@@ -6328,7 +7372,7 @@ var post10 = function(param) {
|
|
|
6328
7372
|
if (initialArgs) {
|
|
6329
7373
|
try {
|
|
6330
7374
|
JSON.parse(initialArgs);
|
|
6331
|
-
denormalized =
|
|
7375
|
+
denormalized = denormalizeComputerCallArguments2({
|
|
6332
7376
|
argumentsText: initialArgs,
|
|
6333
7377
|
displayWidth: displayWidth,
|
|
6334
7378
|
displayHeight: displayHeight,
|
|
@@ -6357,7 +7401,7 @@ var post10 = function(param) {
|
|
|
6357
7401
|
if (!emittedIndices.has(tc.index)) {
|
|
6358
7402
|
try {
|
|
6359
7403
|
JSON.parse(buf);
|
|
6360
|
-
denormalized1 =
|
|
7404
|
+
denormalized1 = denormalizeComputerCallArguments2({
|
|
6361
7405
|
argumentsText: buf,
|
|
6362
7406
|
displayWidth: displayWidth,
|
|
6363
7407
|
displayHeight: displayHeight,
|
|
@@ -6462,7 +7506,7 @@ var post10 = function(param) {
|
|
|
6462
7506
|
for(_iterator2 = Array.from(argumentBuffers)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
|
|
6463
7507
|
_step_value = _sliced_to_array(_step2.value, 2), index = _step_value[0], buf1 = _step_value[1];
|
|
6464
7508
|
if (!emittedIndices.has(index) && buf1) {
|
|
6465
|
-
denormalized2 =
|
|
7509
|
+
denormalized2 = denormalizeComputerCallArguments2({
|
|
6466
7510
|
argumentsText: buf1,
|
|
6467
7511
|
displayWidth: displayWidth,
|
|
6468
7512
|
displayHeight: displayHeight,
|
|
@@ -6566,7 +7610,7 @@ var post10 = function(param) {
|
|
|
6566
7610
|
tc = _step1.value;
|
|
6567
7611
|
fn = tc.function;
|
|
6568
7612
|
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
6569
|
-
fn.arguments =
|
|
7613
|
+
fn.arguments = denormalizeComputerCallArguments2({
|
|
6570
7614
|
argumentsText: fn.arguments,
|
|
6571
7615
|
displayWidth: computerUseConfig.displayWidth,
|
|
6572
7616
|
displayHeight: computerUseConfig.displayHeight,
|
|
@@ -6604,7 +7648,7 @@ var post10 = function(param) {
|
|
|
6604
7648
|
}
|
|
6605
7649
|
}
|
|
6606
7650
|
}
|
|
6607
|
-
if (
|
|
7651
|
+
if (getQuirks2(model).cleanArtifacts) {
|
|
6608
7652
|
;
|
|
6609
7653
|
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
6610
7654
|
try {
|
|
@@ -6612,7 +7656,7 @@ var post10 = function(param) {
|
|
|
6612
7656
|
choice1 = _step2.value;
|
|
6613
7657
|
message51 = choice1.message;
|
|
6614
7658
|
if ((message51 === null || message51 === void 0 ? void 0 : message51.content) && typeof message51.content === "string") {
|
|
6615
|
-
message51.content =
|
|
7659
|
+
message51.content = sanitizeContent2(message51.content);
|
|
6616
7660
|
}
|
|
6617
7661
|
}
|
|
6618
7662
|
} catch (err) {
|