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.cjs
CHANGED
|
@@ -2832,7 +2832,7 @@ var post5 = function(param) {
|
|
|
2832
2832
|
stream = new ReadableStream({
|
|
2833
2833
|
start: function start(controller) {
|
|
2834
2834
|
return _async_to_generator(function() {
|
|
2835
|
-
var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex,
|
|
2835
|
+
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;
|
|
2836
2836
|
return _ts_generator(this, function(_state) {
|
|
2837
2837
|
switch(_state.label){
|
|
2838
2838
|
case 0:
|
|
@@ -2842,7 +2842,7 @@ var post5 = function(param) {
|
|
|
2842
2842
|
computerToolUseIds = /* @__PURE__ */ new Set();
|
|
2843
2843
|
normalizedComputerCalls = /* @__PURE__ */ new Set();
|
|
2844
2844
|
nextToolCallIndex = 0;
|
|
2845
|
-
|
|
2845
|
+
parseJson4 = function(value) {
|
|
2846
2846
|
try {
|
|
2847
2847
|
return JSON.parse(value);
|
|
2848
2848
|
} catch (unused) {
|
|
@@ -2939,7 +2939,7 @@ var post5 = function(param) {
|
|
|
2939
2939
|
if (toolUseId && computerToolUseIds.has(toolUseId) && !normalizedComputerCalls.has(toolUseId)) {
|
|
2940
2940
|
;
|
|
2941
2941
|
buffered = (_toolUseIdArgumentBuffer_get = toolUseIdArgumentBuffer.get(toolUseId)) !== null && _toolUseIdArgumentBuffer_get !== void 0 ? _toolUseIdArgumentBuffer_get : "";
|
|
2942
|
-
parsed = buffered ?
|
|
2942
|
+
parsed = buffered ? parseJson4(buffered) : void 0;
|
|
2943
2943
|
if (parsed !== void 0) {
|
|
2944
2944
|
normalized = normalizeComputerToolCallPayload(parsed);
|
|
2945
2945
|
toolCallIndex = getOrCreateIndexForToolUseId(toolUseId);
|
|
@@ -3004,7 +3004,7 @@ var post5 = function(param) {
|
|
|
3004
3004
|
updated = "".concat(existing).concat((_chunk_delta_partial_json = chunk.delta.partial_json) !== null && _chunk_delta_partial_json !== void 0 ? _chunk_delta_partial_json : "");
|
|
3005
3005
|
toolUseIdArgumentBuffer.set(toolUseId1, updated);
|
|
3006
3006
|
if (!normalizedComputerCalls.has(toolUseId1)) {
|
|
3007
|
-
parsed1 =
|
|
3007
|
+
parsed1 = parseJson4(updated);
|
|
3008
3008
|
if (parsed1 !== void 0) {
|
|
3009
3009
|
normalized1 = normalizeComputerToolCallPayload(parsed1);
|
|
3010
3010
|
toolCallIndex2 = getOrCreateIndexForToolUseId(toolUseId1);
|
|
@@ -5228,34 +5228,849 @@ var models12 = function(param) {
|
|
|
5228
5228
|
})
|
|
5229
5229
|
};
|
|
5230
5230
|
};
|
|
5231
|
+
// src/adapters/client/ollamaClientAdapter/completions/normalizeComputerCall.ts
|
|
5232
|
+
var MODEL_QUIRKS = {
|
|
5233
|
+
"gemma4": {
|
|
5234
|
+
normalizedCoords: true,
|
|
5235
|
+
fuzzyFallback: true
|
|
5236
|
+
},
|
|
5237
|
+
"gemma3": {
|
|
5238
|
+
normalizedCoords: true,
|
|
5239
|
+
fuzzyFallback: true
|
|
5240
|
+
},
|
|
5241
|
+
"glm-4.6v": {
|
|
5242
|
+
normalizedCoords: true,
|
|
5243
|
+
cleanArtifacts: true
|
|
5244
|
+
},
|
|
5245
|
+
"glm4.6v": {
|
|
5246
|
+
normalizedCoords: true,
|
|
5247
|
+
cleanArtifacts: true
|
|
5248
|
+
},
|
|
5249
|
+
"qwen": {
|
|
5250
|
+
fuzzyFallback: true
|
|
5251
|
+
},
|
|
5252
|
+
"kimi-k2.5": {
|
|
5253
|
+
relativeCoords: {
|
|
5254
|
+
referenceWidth: 1920,
|
|
5255
|
+
referenceHeight: 1080
|
|
5256
|
+
}
|
|
5257
|
+
},
|
|
5258
|
+
"kimi2.5": {
|
|
5259
|
+
relativeCoords: {
|
|
5260
|
+
referenceWidth: 1920,
|
|
5261
|
+
referenceHeight: 1080
|
|
5262
|
+
}
|
|
5263
|
+
}
|
|
5264
|
+
};
|
|
5265
|
+
var getQuirks = function(model) {
|
|
5266
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5267
|
+
try {
|
|
5268
|
+
for(var _iterator = Object.entries(MODEL_QUIRKS)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5269
|
+
var _step_value = _sliced_to_array(_step.value, 2), prefix = _step_value[0], quirks = _step_value[1];
|
|
5270
|
+
if (model.startsWith(prefix)) return quirks;
|
|
5271
|
+
}
|
|
5272
|
+
} catch (err) {
|
|
5273
|
+
_didIteratorError = true;
|
|
5274
|
+
_iteratorError = err;
|
|
5275
|
+
} finally{
|
|
5276
|
+
try {
|
|
5277
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5278
|
+
_iterator.return();
|
|
5279
|
+
}
|
|
5280
|
+
} finally{
|
|
5281
|
+
if (_didIteratorError) {
|
|
5282
|
+
throw _iteratorError;
|
|
5283
|
+
}
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
return {};
|
|
5287
|
+
};
|
|
5288
|
+
var cleanTextArtifacts = function(text) {
|
|
5289
|
+
return text.replace(/<\|begin_of_box\|>/g, "").replace(/<\|end_of_box\|>/g, "").replace(/<arg_key>[^<]*<\/arg_key>/g, "").replace(/<\/arg_value>/g, "").trim();
|
|
5290
|
+
};
|
|
5291
|
+
var KNOWN_ACTION_TYPES = [
|
|
5292
|
+
"double_click",
|
|
5293
|
+
"screenshot",
|
|
5294
|
+
"keypress",
|
|
5295
|
+
"scroll",
|
|
5296
|
+
"click",
|
|
5297
|
+
"move",
|
|
5298
|
+
"type",
|
|
5299
|
+
"drag",
|
|
5300
|
+
"wait"
|
|
5301
|
+
];
|
|
5302
|
+
var splitCoordDigits = function(numStr) {
|
|
5303
|
+
for(var i = 1; i < numStr.length; i++){
|
|
5304
|
+
var x = parseInt(numStr.slice(0, i));
|
|
5305
|
+
var y = parseInt(numStr.slice(i));
|
|
5306
|
+
if (x >= 0 && x <= 1e3 && y >= 0 && y <= 1e3) {
|
|
5307
|
+
return {
|
|
5308
|
+
x: x,
|
|
5309
|
+
y: y
|
|
5310
|
+
};
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
return null;
|
|
5314
|
+
};
|
|
5315
|
+
var cleanGlmAction = function(action) {
|
|
5316
|
+
var typeVal = action.type;
|
|
5317
|
+
if (typeof typeVal !== "string") return action;
|
|
5318
|
+
var argValueMatch = typeVal.match(/<arg_value>\s*(\{[\s\S]*\})\s*$/);
|
|
5319
|
+
if (argValueMatch) {
|
|
5320
|
+
var inner = parseJson2(argValueMatch[1]);
|
|
5321
|
+
if (inner && (typeof inner === "undefined" ? "undefined" : _type_of(inner)) === "object") {
|
|
5322
|
+
return inner;
|
|
5323
|
+
}
|
|
5324
|
+
}
|
|
5325
|
+
var cleanedType = typeVal.replace(/<\/?[^>]+>/g, "").replace(/\n/g, "").trim();
|
|
5326
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5327
|
+
try {
|
|
5328
|
+
for(var _iterator = KNOWN_ACTION_TYPES[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5329
|
+
var actionType = _step.value;
|
|
5330
|
+
if (cleanedType.startsWith(actionType) && cleanedType !== actionType) {
|
|
5331
|
+
var rest = cleanedType.slice(actionType.length);
|
|
5332
|
+
var nums = rest.match(/\d+/g);
|
|
5333
|
+
if (nums && nums.length >= 2) {
|
|
5334
|
+
return _object_spread_props(_object_spread({}, action), {
|
|
5335
|
+
type: actionType,
|
|
5336
|
+
x: parseInt(nums[0]),
|
|
5337
|
+
y: parseInt(nums[1])
|
|
5338
|
+
});
|
|
5339
|
+
}
|
|
5340
|
+
if (nums && nums.length === 1 && nums[0].length >= 2) {
|
|
5341
|
+
var coords = splitCoordDigits(nums[0]);
|
|
5342
|
+
if (coords) {
|
|
5343
|
+
return _object_spread(_object_spread_props(_object_spread({}, action), {
|
|
5344
|
+
type: actionType
|
|
5345
|
+
}), coords);
|
|
5346
|
+
}
|
|
5347
|
+
}
|
|
5348
|
+
return _object_spread_props(_object_spread({}, action), {
|
|
5349
|
+
type: actionType
|
|
5350
|
+
});
|
|
5351
|
+
}
|
|
5352
|
+
}
|
|
5353
|
+
} catch (err) {
|
|
5354
|
+
_didIteratorError = true;
|
|
5355
|
+
_iteratorError = err;
|
|
5356
|
+
} finally{
|
|
5357
|
+
try {
|
|
5358
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5359
|
+
_iterator.return();
|
|
5360
|
+
}
|
|
5361
|
+
} finally{
|
|
5362
|
+
if (_didIteratorError) {
|
|
5363
|
+
throw _iteratorError;
|
|
5364
|
+
}
|
|
5365
|
+
}
|
|
5366
|
+
}
|
|
5367
|
+
if (cleanedType === typeVal) return action;
|
|
5368
|
+
return _object_spread_props(_object_spread({}, action), {
|
|
5369
|
+
type: cleanedType
|
|
5370
|
+
});
|
|
5371
|
+
};
|
|
5372
|
+
var cleanGlmFields = function(action) {
|
|
5373
|
+
var result = _object_spread({}, action);
|
|
5374
|
+
if (typeof result.x === "string") {
|
|
5375
|
+
var nums = result.x.match(/\d+/g);
|
|
5376
|
+
if (nums && nums.length >= 2) {
|
|
5377
|
+
result.x = parseInt(nums[0]);
|
|
5378
|
+
if (result.y === void 0 || typeof result.y === "string") {
|
|
5379
|
+
result.y = parseInt(nums[1]);
|
|
5380
|
+
}
|
|
5381
|
+
} else if (nums && nums.length === 1) {
|
|
5382
|
+
result.x = parseInt(nums[0]);
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
if (typeof result.y === "string") {
|
|
5386
|
+
var nums1 = result.y.match(/\d+/g);
|
|
5387
|
+
if (nums1 && nums1.length >= 1) {
|
|
5388
|
+
result.y = parseInt(nums1[0]);
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
for(var _i = 0, _iter = [
|
|
5392
|
+
"scroll_x",
|
|
5393
|
+
"scroll_y"
|
|
5394
|
+
]; _i < _iter.length; _i++){
|
|
5395
|
+
var key = _iter[_i];
|
|
5396
|
+
if (typeof result[key] === "string") {
|
|
5397
|
+
var nums2 = result[key].match(/\d+/g);
|
|
5398
|
+
if (nums2) result[key] = parseInt(nums2[0]);
|
|
5399
|
+
}
|
|
5400
|
+
}
|
|
5401
|
+
if (typeof result.type === "string") {
|
|
5402
|
+
result.type = result.type.replace(/<[^>]*>/g, "").replace(/^\{|\}$/g, "").replace(/\n/g, "").trim();
|
|
5403
|
+
}
|
|
5404
|
+
return result;
|
|
5405
|
+
};
|
|
5406
|
+
var applyArtifactCleanup = function(action) {
|
|
5407
|
+
return cleanGlmFields(cleanGlmAction(action));
|
|
5408
|
+
};
|
|
5409
|
+
var parseJson2 = function(text) {
|
|
5410
|
+
try {
|
|
5411
|
+
return JSON.parse(text);
|
|
5412
|
+
} catch (unused) {
|
|
5413
|
+
return void 0;
|
|
5414
|
+
}
|
|
5415
|
+
};
|
|
5416
|
+
var extractJson = function(text) {
|
|
5417
|
+
var direct = parseJson2(text);
|
|
5418
|
+
if (direct) return direct;
|
|
5419
|
+
var codeBlockMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
5420
|
+
if (codeBlockMatch) {
|
|
5421
|
+
var parsed = parseJson2(codeBlockMatch[1].trim());
|
|
5422
|
+
if (parsed) return parsed;
|
|
5423
|
+
}
|
|
5424
|
+
var jsonMatch = text.match(/(\{[\s\S]*\})\s*$/);
|
|
5425
|
+
if (jsonMatch) {
|
|
5426
|
+
var parsed1 = parseJson2(jsonMatch[1].trim());
|
|
5427
|
+
if (parsed1) return parsed1;
|
|
5428
|
+
}
|
|
5429
|
+
return void 0;
|
|
5430
|
+
};
|
|
5431
|
+
var fuzzyExtractJson = function(text) {
|
|
5432
|
+
var clickMatch = text.match(/"action"\s*:\s*"click"\s*,\s*"x"\s*:\s*\[?\s*(\d+)\s*,\s*(\d+)/);
|
|
5433
|
+
if (clickMatch) {
|
|
5434
|
+
return {
|
|
5435
|
+
action: {
|
|
5436
|
+
type: "click",
|
|
5437
|
+
x: parseInt(clickMatch[1]),
|
|
5438
|
+
y: parseInt(clickMatch[2])
|
|
5439
|
+
}
|
|
5440
|
+
};
|
|
5441
|
+
}
|
|
5442
|
+
var actionTypeMatch = text.match(/"type"\s*:\s*"(\w+)"/);
|
|
5443
|
+
if (actionTypeMatch) {
|
|
5444
|
+
var result = {
|
|
5445
|
+
type: actionTypeMatch[1]
|
|
5446
|
+
};
|
|
5447
|
+
var xMatch = text.match(/"x"\s*:\s*\[?\s*(\d+)/);
|
|
5448
|
+
var yMatch = text.match(/"y"\s*:\s*(\d+)/);
|
|
5449
|
+
if (xMatch) result.x = parseInt(xMatch[1]);
|
|
5450
|
+
if (yMatch) {
|
|
5451
|
+
result.y = parseInt(yMatch[1]);
|
|
5452
|
+
} else if (xMatch) {
|
|
5453
|
+
var _xMatch_index;
|
|
5454
|
+
var afterX = text.slice(((_xMatch_index = xMatch.index) !== null && _xMatch_index !== void 0 ? _xMatch_index : 0) + xMatch[0].length);
|
|
5455
|
+
var nextNum = afterX.match(/\s*,?\s*(\d+)/);
|
|
5456
|
+
if (nextNum) result.y = parseInt(nextNum[1]);
|
|
5457
|
+
}
|
|
5458
|
+
var textMatch = text.match(/"text"\s*:\s*"([^"]*)"/);
|
|
5459
|
+
if (textMatch) result.text = textMatch[1];
|
|
5460
|
+
return {
|
|
5461
|
+
action: result
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
var boxMatch = text.match(/"box_2d"\s*:\s*\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]/);
|
|
5465
|
+
if (boxMatch) {
|
|
5466
|
+
var y1 = parseInt(boxMatch[1]);
|
|
5467
|
+
var x1 = parseInt(boxMatch[2]);
|
|
5468
|
+
var y2 = parseInt(boxMatch[3]);
|
|
5469
|
+
var x2 = parseInt(boxMatch[4]);
|
|
5470
|
+
return {
|
|
5471
|
+
action: {
|
|
5472
|
+
type: "click",
|
|
5473
|
+
x: Math.round((x1 + x2) / 2),
|
|
5474
|
+
y: Math.round((y1 + y2) / 2)
|
|
5475
|
+
}
|
|
5476
|
+
};
|
|
5477
|
+
}
|
|
5478
|
+
return void 0;
|
|
5479
|
+
};
|
|
5480
|
+
var denormalize = function(value, dimension) {
|
|
5481
|
+
return Math.round(value / 1e3 * dimension);
|
|
5482
|
+
};
|
|
5483
|
+
var denormalizeAction = function(action, displayWidth, displayHeight) {
|
|
5484
|
+
var result = _object_spread({}, action);
|
|
5485
|
+
if (typeof result.x === "number") {
|
|
5486
|
+
result.x = denormalize(result.x, displayWidth);
|
|
5487
|
+
}
|
|
5488
|
+
if (typeof result.y === "number") {
|
|
5489
|
+
result.y = denormalize(result.y, displayHeight);
|
|
5490
|
+
}
|
|
5491
|
+
if (Array.isArray(result.path)) {
|
|
5492
|
+
result.path = result.path.map(function(point) {
|
|
5493
|
+
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5494
|
+
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5495
|
+
x: denormalize(point.x, displayWidth)
|
|
5496
|
+
} : {}, typeof point.y === "number" ? {
|
|
5497
|
+
y: denormalize(point.y, displayHeight)
|
|
5498
|
+
} : {});
|
|
5499
|
+
}
|
|
5500
|
+
return point;
|
|
5501
|
+
});
|
|
5502
|
+
}
|
|
5503
|
+
return result;
|
|
5504
|
+
};
|
|
5505
|
+
var rescaleCoord = function(value, displayDim, referenceDim) {
|
|
5506
|
+
if (value <= 1) return Math.round(value * displayDim);
|
|
5507
|
+
return Math.round(value / referenceDim * displayDim);
|
|
5508
|
+
};
|
|
5509
|
+
var rescaleRelativeAction = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
|
|
5510
|
+
var result = _object_spread({}, action);
|
|
5511
|
+
if (typeof result.x === "number") {
|
|
5512
|
+
result.x = rescaleCoord(result.x, displayWidth, referenceWidth);
|
|
5513
|
+
}
|
|
5514
|
+
if (typeof result.y === "number") {
|
|
5515
|
+
result.y = rescaleCoord(result.y, displayHeight, referenceHeight);
|
|
5516
|
+
}
|
|
5517
|
+
if (Array.isArray(result.path)) {
|
|
5518
|
+
result.path = result.path.map(function(point) {
|
|
5519
|
+
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5520
|
+
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5521
|
+
x: rescaleCoord(point.x, displayWidth, referenceWidth)
|
|
5522
|
+
} : {}, typeof point.y === "number" ? {
|
|
5523
|
+
y: rescaleCoord(point.y, displayHeight, referenceHeight)
|
|
5524
|
+
} : {});
|
|
5525
|
+
}
|
|
5526
|
+
return point;
|
|
5527
|
+
});
|
|
5528
|
+
}
|
|
5529
|
+
return result;
|
|
5530
|
+
};
|
|
5531
|
+
var COORD_FIELDS = [
|
|
5532
|
+
"x",
|
|
5533
|
+
"y",
|
|
5534
|
+
"text",
|
|
5535
|
+
"keys",
|
|
5536
|
+
"button",
|
|
5537
|
+
"direction",
|
|
5538
|
+
"scroll_x",
|
|
5539
|
+
"scroll_y",
|
|
5540
|
+
"path"
|
|
5541
|
+
];
|
|
5542
|
+
var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
5543
|
+
var clean = shouldCleanArtifacts ? function(action) {
|
|
5544
|
+
return applyArtifactCleanup(action);
|
|
5545
|
+
} : function(action) {
|
|
5546
|
+
return action;
|
|
5547
|
+
};
|
|
5548
|
+
if (parsed.action && _type_of(parsed.action) === "object") {
|
|
5549
|
+
return _object_spread_props(_object_spread({}, parsed), {
|
|
5550
|
+
action: clean(parsed.action)
|
|
5551
|
+
});
|
|
5552
|
+
}
|
|
5553
|
+
if (typeof parsed.action === "string") {
|
|
5554
|
+
var actionObj = {
|
|
5555
|
+
type: parsed.action
|
|
5556
|
+
};
|
|
5557
|
+
var rest = {};
|
|
5558
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5559
|
+
try {
|
|
5560
|
+
for(var _iterator = Object.entries(parsed)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5561
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
5562
|
+
if (key === "action") continue;
|
|
5563
|
+
if (COORD_FIELDS.includes(key)) {
|
|
5564
|
+
actionObj[key] = value;
|
|
5565
|
+
} else {
|
|
5566
|
+
rest[key] = value;
|
|
5567
|
+
}
|
|
5568
|
+
}
|
|
5569
|
+
} catch (err) {
|
|
5570
|
+
_didIteratorError = true;
|
|
5571
|
+
_iteratorError = err;
|
|
5572
|
+
} finally{
|
|
5573
|
+
try {
|
|
5574
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5575
|
+
_iterator.return();
|
|
5576
|
+
}
|
|
5577
|
+
} finally{
|
|
5578
|
+
if (_didIteratorError) {
|
|
5579
|
+
throw _iteratorError;
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
}
|
|
5583
|
+
return _object_spread_props(_object_spread({}, rest), {
|
|
5584
|
+
action: clean(actionObj)
|
|
5585
|
+
});
|
|
5586
|
+
}
|
|
5587
|
+
if (typeof parsed.type === "string") {
|
|
5588
|
+
var actionObj1 = {};
|
|
5589
|
+
var rest1 = {};
|
|
5590
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
5591
|
+
try {
|
|
5592
|
+
for(var _iterator1 = Object.entries(parsed)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
5593
|
+
var _step_value1 = _sliced_to_array(_step1.value, 2), key1 = _step_value1[0], value1 = _step_value1[1];
|
|
5594
|
+
if (key1 === "type" || COORD_FIELDS.includes(key1)) {
|
|
5595
|
+
actionObj1[key1] = value1;
|
|
5596
|
+
} else {
|
|
5597
|
+
rest1[key1] = value1;
|
|
5598
|
+
}
|
|
5599
|
+
}
|
|
5600
|
+
} catch (err) {
|
|
5601
|
+
_didIteratorError1 = true;
|
|
5602
|
+
_iteratorError1 = err;
|
|
5603
|
+
} finally{
|
|
5604
|
+
try {
|
|
5605
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
5606
|
+
_iterator1.return();
|
|
5607
|
+
}
|
|
5608
|
+
} finally{
|
|
5609
|
+
if (_didIteratorError1) {
|
|
5610
|
+
throw _iteratorError1;
|
|
5611
|
+
}
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
return _object_spread_props(_object_spread({}, rest1), {
|
|
5615
|
+
action: clean(actionObj1)
|
|
5616
|
+
});
|
|
5617
|
+
}
|
|
5618
|
+
return parsed;
|
|
5619
|
+
};
|
|
5620
|
+
var denormalizeComputerCallArguments = function(param) {
|
|
5621
|
+
var argumentsText = param.argumentsText, displayWidth = param.displayWidth, displayHeight = param.displayHeight, model = param.model;
|
|
5622
|
+
if ((typeof argumentsText === "undefined" ? "undefined" : _type_of(argumentsText)) === "object" && argumentsText !== null) {
|
|
5623
|
+
argumentsText = JSON.stringify(argumentsText);
|
|
5624
|
+
}
|
|
5625
|
+
var quirks = getQuirks(model);
|
|
5626
|
+
var text = argumentsText;
|
|
5627
|
+
if (quirks.cleanArtifacts) {
|
|
5628
|
+
text = cleanTextArtifacts(text);
|
|
5629
|
+
}
|
|
5630
|
+
var parsed = extractJson(text);
|
|
5631
|
+
if (!parsed && (quirks.cleanArtifacts || quirks.fuzzyFallback)) {
|
|
5632
|
+
parsed = fuzzyExtractJson(text);
|
|
5633
|
+
}
|
|
5634
|
+
if (!parsed || (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) !== "object") {
|
|
5635
|
+
return argumentsText;
|
|
5636
|
+
}
|
|
5637
|
+
var normalized = normalizeStructure(parsed, !!quirks.cleanArtifacts);
|
|
5638
|
+
if (quirks.normalizedCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5639
|
+
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5640
|
+
action: denormalizeAction(normalized.action, displayWidth, displayHeight)
|
|
5641
|
+
}));
|
|
5642
|
+
}
|
|
5643
|
+
if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5644
|
+
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5645
|
+
action: rescaleRelativeAction(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
|
|
5646
|
+
}));
|
|
5647
|
+
}
|
|
5648
|
+
return JSON.stringify(normalized);
|
|
5649
|
+
};
|
|
5650
|
+
// src/adapters/client/ollamaClientAdapter/completions/computerUseTool.ts
|
|
5651
|
+
var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
|
|
5652
|
+
var quirks = getQuirks(model);
|
|
5653
|
+
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, ").");
|
|
5654
|
+
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, ")");
|
|
5655
|
+
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, ")");
|
|
5656
|
+
return {
|
|
5657
|
+
name: "computer_call",
|
|
5658
|
+
description: "Perform a computer action. ".concat(coordDesc),
|
|
5659
|
+
parameters: {
|
|
5660
|
+
type: "object",
|
|
5661
|
+
properties: {
|
|
5662
|
+
action: {
|
|
5663
|
+
type: "object",
|
|
5664
|
+
description: "The action to perform",
|
|
5665
|
+
properties: {
|
|
5666
|
+
type: {
|
|
5667
|
+
type: "string",
|
|
5668
|
+
enum: [
|
|
5669
|
+
"screenshot",
|
|
5670
|
+
"click",
|
|
5671
|
+
"double_click",
|
|
5672
|
+
"type",
|
|
5673
|
+
"keypress",
|
|
5674
|
+
"scroll",
|
|
5675
|
+
"move",
|
|
5676
|
+
"drag",
|
|
5677
|
+
"wait"
|
|
5678
|
+
]
|
|
5679
|
+
},
|
|
5680
|
+
x: {
|
|
5681
|
+
type: "number",
|
|
5682
|
+
description: xDesc
|
|
5683
|
+
},
|
|
5684
|
+
y: {
|
|
5685
|
+
type: "number",
|
|
5686
|
+
description: yDesc
|
|
5687
|
+
},
|
|
5688
|
+
text: {
|
|
5689
|
+
type: "string",
|
|
5690
|
+
description: "Text to type"
|
|
5691
|
+
},
|
|
5692
|
+
keys: {
|
|
5693
|
+
type: "array",
|
|
5694
|
+
items: {
|
|
5695
|
+
type: "string"
|
|
5696
|
+
},
|
|
5697
|
+
description: "Keys to press"
|
|
5698
|
+
},
|
|
5699
|
+
button: {
|
|
5700
|
+
type: "string",
|
|
5701
|
+
enum: [
|
|
5702
|
+
"left",
|
|
5703
|
+
"right",
|
|
5704
|
+
"wheel"
|
|
5705
|
+
]
|
|
5706
|
+
},
|
|
5707
|
+
direction: {
|
|
5708
|
+
type: "string",
|
|
5709
|
+
enum: [
|
|
5710
|
+
"up",
|
|
5711
|
+
"down",
|
|
5712
|
+
"left",
|
|
5713
|
+
"right"
|
|
5714
|
+
]
|
|
5715
|
+
},
|
|
5716
|
+
scroll_x: {
|
|
5717
|
+
type: "number"
|
|
5718
|
+
},
|
|
5719
|
+
scroll_y: {
|
|
5720
|
+
type: "number"
|
|
5721
|
+
},
|
|
5722
|
+
path: {
|
|
5723
|
+
type: "array",
|
|
5724
|
+
items: {
|
|
5725
|
+
type: "object",
|
|
5726
|
+
properties: {
|
|
5727
|
+
x: {
|
|
5728
|
+
type: "number"
|
|
5729
|
+
},
|
|
5730
|
+
y: {
|
|
5731
|
+
type: "number"
|
|
5732
|
+
}
|
|
5733
|
+
}
|
|
5734
|
+
},
|
|
5735
|
+
description: "Path for drag action"
|
|
5736
|
+
}
|
|
5737
|
+
},
|
|
5738
|
+
required: [
|
|
5739
|
+
"type"
|
|
5740
|
+
]
|
|
5741
|
+
},
|
|
5742
|
+
pending_safety_checks: {
|
|
5743
|
+
type: "array",
|
|
5744
|
+
items: {
|
|
5745
|
+
type: "object"
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
},
|
|
5749
|
+
required: [
|
|
5750
|
+
"action"
|
|
5751
|
+
]
|
|
5752
|
+
}
|
|
5753
|
+
};
|
|
5754
|
+
};
|
|
5755
|
+
var transformTools = function(tools, model) {
|
|
5756
|
+
if (!tools || tools.length === 0) {
|
|
5757
|
+
return {
|
|
5758
|
+
tools: tools !== null && tools !== void 0 ? tools : [],
|
|
5759
|
+
computerUseConfig: null
|
|
5760
|
+
};
|
|
5761
|
+
}
|
|
5762
|
+
var computerUseConfig = null;
|
|
5763
|
+
var transformed = tools.map(function(tool) {
|
|
5764
|
+
if (tool.type === "computer_use_preview") {
|
|
5765
|
+
var _tool_computer_use_preview, _ref, _config_display_width, _ref1, _config_display_height;
|
|
5766
|
+
var config = (_tool_computer_use_preview = tool.computer_use_preview) !== null && _tool_computer_use_preview !== void 0 ? _tool_computer_use_preview : tool;
|
|
5767
|
+
computerUseConfig = {
|
|
5768
|
+
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,
|
|
5769
|
+
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
|
|
5770
|
+
};
|
|
5771
|
+
return {
|
|
5772
|
+
type: "function",
|
|
5773
|
+
function: buildComputerCallFunction(model, computerUseConfig.displayWidth, computerUseConfig.displayHeight)
|
|
5774
|
+
};
|
|
5775
|
+
}
|
|
5776
|
+
return tool;
|
|
5777
|
+
});
|
|
5778
|
+
return {
|
|
5779
|
+
tools: transformed,
|
|
5780
|
+
computerUseConfig: computerUseConfig
|
|
5781
|
+
};
|
|
5782
|
+
};
|
|
5231
5783
|
// src/adapters/client/ollamaClientAdapter/completions/post.ts
|
|
5232
5784
|
var encoder9 = new TextEncoder();
|
|
5785
|
+
var ARTIFACT_TAGS = /<\|begin_of_box\|>|<\|end_of_box\|>/g;
|
|
5786
|
+
var sanitizeContent = function(content) {
|
|
5787
|
+
if (!content) return content;
|
|
5788
|
+
return content.replace(ARTIFACT_TAGS, "").trim();
|
|
5789
|
+
};
|
|
5790
|
+
var convertScreenshotToolMessages = function(messages6) {
|
|
5791
|
+
return messages6.flatMap(function(msg) {
|
|
5792
|
+
if (msg.role !== "tool" || typeof msg.content !== "string") return [
|
|
5793
|
+
msg
|
|
5794
|
+
];
|
|
5795
|
+
try {
|
|
5796
|
+
var parsed = JSON.parse(msg.content);
|
|
5797
|
+
if (parsed.type === "computer_screenshot" && parsed.image_url) {
|
|
5798
|
+
return [
|
|
5799
|
+
_object_spread_props(_object_spread({}, msg), {
|
|
5800
|
+
content: ""
|
|
5801
|
+
}),
|
|
5802
|
+
{
|
|
5803
|
+
role: "user",
|
|
5804
|
+
content: [
|
|
5805
|
+
{
|
|
5806
|
+
type: "image_url",
|
|
5807
|
+
image_url: {
|
|
5808
|
+
url: parsed.image_url
|
|
5809
|
+
}
|
|
5810
|
+
}
|
|
5811
|
+
]
|
|
5812
|
+
}
|
|
5813
|
+
];
|
|
5814
|
+
}
|
|
5815
|
+
} catch (unused) {}
|
|
5816
|
+
return [
|
|
5817
|
+
msg
|
|
5818
|
+
];
|
|
5819
|
+
});
|
|
5820
|
+
};
|
|
5233
5821
|
var post9 = function(param) {
|
|
5234
5822
|
var ollama = param.ollama;
|
|
5235
5823
|
return function(_url, options) {
|
|
5236
5824
|
return _async_to_generator(function() {
|
|
5237
|
-
var body, response, stream, data, error;
|
|
5825
|
+
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;
|
|
5238
5826
|
return _ts_generator(this, function(_state) {
|
|
5239
5827
|
switch(_state.label){
|
|
5240
5828
|
case 0:
|
|
5241
5829
|
body = JSON.parse(options.body);
|
|
5830
|
+
model = body.model;
|
|
5831
|
+
_transformTools = transformTools(body.tools, model), transformedTools = _transformTools.tools, computerUseConfig = _transformTools.computerUseConfig;
|
|
5832
|
+
resultOptions = _object_spread({}, body, computerUseConfig && body.messages ? {
|
|
5833
|
+
messages: convertScreenshotToolMessages(body.messages)
|
|
5834
|
+
} : {}, transformedTools.length > 0 ? {
|
|
5835
|
+
tools: transformedTools
|
|
5836
|
+
} : {});
|
|
5242
5837
|
if (!body.stream) return [
|
|
5243
5838
|
3,
|
|
5244
5839
|
2
|
|
5245
5840
|
];
|
|
5246
5841
|
return [
|
|
5247
5842
|
4,
|
|
5248
|
-
ollama.chat.completions.create(
|
|
5843
|
+
ollama.chat.completions.create(resultOptions)
|
|
5249
5844
|
];
|
|
5250
5845
|
case 1:
|
|
5251
5846
|
response = _state.sent();
|
|
5847
|
+
shouldCleanArtifacts = !!getQuirks(model).cleanArtifacts;
|
|
5848
|
+
if (!computerUseConfig && !shouldCleanArtifacts) {
|
|
5849
|
+
stream2 = new ReadableStream({
|
|
5850
|
+
start: function start(controller) {
|
|
5851
|
+
return _async_to_generator(function() {
|
|
5852
|
+
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, err;
|
|
5853
|
+
return _ts_generator(this, function(_state) {
|
|
5854
|
+
switch(_state.label){
|
|
5855
|
+
case 0:
|
|
5856
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
5857
|
+
_state.label = 1;
|
|
5858
|
+
case 1:
|
|
5859
|
+
_state.trys.push([
|
|
5860
|
+
1,
|
|
5861
|
+
6,
|
|
5862
|
+
7,
|
|
5863
|
+
12
|
|
5864
|
+
]);
|
|
5865
|
+
_iterator = _async_iterator(response);
|
|
5866
|
+
_state.label = 2;
|
|
5867
|
+
case 2:
|
|
5868
|
+
return [
|
|
5869
|
+
4,
|
|
5870
|
+
_iterator.next()
|
|
5871
|
+
];
|
|
5872
|
+
case 3:
|
|
5873
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
5874
|
+
3,
|
|
5875
|
+
5
|
|
5876
|
+
];
|
|
5877
|
+
_value = _step.value;
|
|
5878
|
+
chunk = _value;
|
|
5879
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
5880
|
+
_state.label = 4;
|
|
5881
|
+
case 4:
|
|
5882
|
+
_iteratorAbruptCompletion = false;
|
|
5883
|
+
return [
|
|
5884
|
+
3,
|
|
5885
|
+
2
|
|
5886
|
+
];
|
|
5887
|
+
case 5:
|
|
5888
|
+
return [
|
|
5889
|
+
3,
|
|
5890
|
+
12
|
|
5891
|
+
];
|
|
5892
|
+
case 6:
|
|
5893
|
+
err = _state.sent();
|
|
5894
|
+
_didIteratorError = true;
|
|
5895
|
+
_iteratorError = err;
|
|
5896
|
+
return [
|
|
5897
|
+
3,
|
|
5898
|
+
12
|
|
5899
|
+
];
|
|
5900
|
+
case 7:
|
|
5901
|
+
_state.trys.push([
|
|
5902
|
+
7,
|
|
5903
|
+
,
|
|
5904
|
+
10,
|
|
5905
|
+
11
|
|
5906
|
+
]);
|
|
5907
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
5908
|
+
3,
|
|
5909
|
+
9
|
|
5910
|
+
];
|
|
5911
|
+
return [
|
|
5912
|
+
4,
|
|
5913
|
+
_iterator.return()
|
|
5914
|
+
];
|
|
5915
|
+
case 8:
|
|
5916
|
+
_state.sent();
|
|
5917
|
+
_state.label = 9;
|
|
5918
|
+
case 9:
|
|
5919
|
+
return [
|
|
5920
|
+
3,
|
|
5921
|
+
11
|
|
5922
|
+
];
|
|
5923
|
+
case 10:
|
|
5924
|
+
if (_didIteratorError) {
|
|
5925
|
+
throw _iteratorError;
|
|
5926
|
+
}
|
|
5927
|
+
return [
|
|
5928
|
+
7
|
|
5929
|
+
];
|
|
5930
|
+
case 11:
|
|
5931
|
+
return [
|
|
5932
|
+
7
|
|
5933
|
+
];
|
|
5934
|
+
case 12:
|
|
5935
|
+
controller.close();
|
|
5936
|
+
return [
|
|
5937
|
+
2
|
|
5938
|
+
];
|
|
5939
|
+
}
|
|
5940
|
+
});
|
|
5941
|
+
})();
|
|
5942
|
+
}
|
|
5943
|
+
});
|
|
5944
|
+
return [
|
|
5945
|
+
2,
|
|
5946
|
+
new Response(stream2, {
|
|
5947
|
+
headers: {
|
|
5948
|
+
"Content-Type": "text/event-stream"
|
|
5949
|
+
}
|
|
5950
|
+
})
|
|
5951
|
+
];
|
|
5952
|
+
}
|
|
5953
|
+
if (!computerUseConfig) {
|
|
5954
|
+
stream21 = new ReadableStream({
|
|
5955
|
+
start: function start(controller) {
|
|
5956
|
+
return _async_to_generator(function() {
|
|
5957
|
+
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, _choices_, choices, delta, err;
|
|
5958
|
+
return _ts_generator(this, function(_state) {
|
|
5959
|
+
switch(_state.label){
|
|
5960
|
+
case 0:
|
|
5961
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
5962
|
+
_state.label = 1;
|
|
5963
|
+
case 1:
|
|
5964
|
+
_state.trys.push([
|
|
5965
|
+
1,
|
|
5966
|
+
6,
|
|
5967
|
+
7,
|
|
5968
|
+
12
|
|
5969
|
+
]);
|
|
5970
|
+
_iterator = _async_iterator(response);
|
|
5971
|
+
_state.label = 2;
|
|
5972
|
+
case 2:
|
|
5973
|
+
return [
|
|
5974
|
+
4,
|
|
5975
|
+
_iterator.next()
|
|
5976
|
+
];
|
|
5977
|
+
case 3:
|
|
5978
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
5979
|
+
3,
|
|
5980
|
+
5
|
|
5981
|
+
];
|
|
5982
|
+
_value = _step.value;
|
|
5983
|
+
chunk = _value;
|
|
5984
|
+
choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
|
|
5985
|
+
delta = (_choices_ = choices[0]) === null || _choices_ === void 0 ? void 0 : _choices_.delta;
|
|
5986
|
+
if ((delta === null || delta === void 0 ? void 0 : delta.content) && typeof delta.content === "string") {
|
|
5987
|
+
delta.content = sanitizeContent(delta.content);
|
|
5988
|
+
}
|
|
5989
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
5990
|
+
_state.label = 4;
|
|
5991
|
+
case 4:
|
|
5992
|
+
_iteratorAbruptCompletion = false;
|
|
5993
|
+
return [
|
|
5994
|
+
3,
|
|
5995
|
+
2
|
|
5996
|
+
];
|
|
5997
|
+
case 5:
|
|
5998
|
+
return [
|
|
5999
|
+
3,
|
|
6000
|
+
12
|
|
6001
|
+
];
|
|
6002
|
+
case 6:
|
|
6003
|
+
err = _state.sent();
|
|
6004
|
+
_didIteratorError = true;
|
|
6005
|
+
_iteratorError = err;
|
|
6006
|
+
return [
|
|
6007
|
+
3,
|
|
6008
|
+
12
|
|
6009
|
+
];
|
|
6010
|
+
case 7:
|
|
6011
|
+
_state.trys.push([
|
|
6012
|
+
7,
|
|
6013
|
+
,
|
|
6014
|
+
10,
|
|
6015
|
+
11
|
|
6016
|
+
]);
|
|
6017
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
6018
|
+
3,
|
|
6019
|
+
9
|
|
6020
|
+
];
|
|
6021
|
+
return [
|
|
6022
|
+
4,
|
|
6023
|
+
_iterator.return()
|
|
6024
|
+
];
|
|
6025
|
+
case 8:
|
|
6026
|
+
_state.sent();
|
|
6027
|
+
_state.label = 9;
|
|
6028
|
+
case 9:
|
|
6029
|
+
return [
|
|
6030
|
+
3,
|
|
6031
|
+
11
|
|
6032
|
+
];
|
|
6033
|
+
case 10:
|
|
6034
|
+
if (_didIteratorError) {
|
|
6035
|
+
throw _iteratorError;
|
|
6036
|
+
}
|
|
6037
|
+
return [
|
|
6038
|
+
7
|
|
6039
|
+
];
|
|
6040
|
+
case 11:
|
|
6041
|
+
return [
|
|
6042
|
+
7
|
|
6043
|
+
];
|
|
6044
|
+
case 12:
|
|
6045
|
+
controller.close();
|
|
6046
|
+
return [
|
|
6047
|
+
2
|
|
6048
|
+
];
|
|
6049
|
+
}
|
|
6050
|
+
});
|
|
6051
|
+
})();
|
|
6052
|
+
}
|
|
6053
|
+
});
|
|
6054
|
+
return [
|
|
6055
|
+
2,
|
|
6056
|
+
new Response(stream21, {
|
|
6057
|
+
headers: {
|
|
6058
|
+
"Content-Type": "text/event-stream"
|
|
6059
|
+
}
|
|
6060
|
+
})
|
|
6061
|
+
];
|
|
6062
|
+
}
|
|
6063
|
+
displayWidth = computerUseConfig.displayWidth, displayHeight = computerUseConfig.displayHeight;
|
|
5252
6064
|
stream = new ReadableStream({
|
|
5253
6065
|
start: function start(controller) {
|
|
5254
6066
|
return _async_to_generator(function() {
|
|
5255
|
-
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk,
|
|
6067
|
+
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;
|
|
5256
6068
|
return _ts_generator(this, function(_state) {
|
|
5257
6069
|
switch(_state.label){
|
|
5258
6070
|
case 0:
|
|
6071
|
+
computerCallIndices = /* @__PURE__ */ new Set();
|
|
6072
|
+
argumentBuffers = /* @__PURE__ */ new Map();
|
|
6073
|
+
emittedIndices = /* @__PURE__ */ new Set();
|
|
5259
6074
|
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
5260
6075
|
_state.label = 1;
|
|
5261
6076
|
case 1:
|
|
@@ -5279,7 +6094,105 @@ var post9 = function(param) {
|
|
|
5279
6094
|
];
|
|
5280
6095
|
_value = _step.value;
|
|
5281
6096
|
chunk = _value;
|
|
5282
|
-
|
|
6097
|
+
choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
|
|
6098
|
+
choice = choices[0];
|
|
6099
|
+
delta = choice === null || choice === void 0 ? void 0 : choice.delta;
|
|
6100
|
+
toolCalls = delta === null || delta === void 0 ? void 0 : delta.tool_calls;
|
|
6101
|
+
if (!toolCalls) {
|
|
6102
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
6103
|
+
return [
|
|
6104
|
+
3,
|
|
6105
|
+
4
|
|
6106
|
+
];
|
|
6107
|
+
}
|
|
6108
|
+
passThrough = [];
|
|
6109
|
+
_iteratorNormalCompletion = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
6110
|
+
try {
|
|
6111
|
+
for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
|
|
6112
|
+
tc = _step1.value;
|
|
6113
|
+
fn = tc.function;
|
|
6114
|
+
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
6115
|
+
;
|
|
6116
|
+
computerCallIndices.add(tc.index);
|
|
6117
|
+
initialArgs = (_ref = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref !== void 0 ? _ref : "";
|
|
6118
|
+
argumentBuffers.set(tc.index, initialArgs);
|
|
6119
|
+
if (initialArgs) {
|
|
6120
|
+
try {
|
|
6121
|
+
JSON.parse(initialArgs);
|
|
6122
|
+
denormalized = denormalizeComputerCallArguments({
|
|
6123
|
+
argumentsText: initialArgs,
|
|
6124
|
+
displayWidth: displayWidth,
|
|
6125
|
+
displayHeight: displayHeight,
|
|
6126
|
+
model: model
|
|
6127
|
+
});
|
|
6128
|
+
passThrough.push(_object_spread_props(_object_spread({}, tc), {
|
|
6129
|
+
function: _object_spread_props(_object_spread({}, fn), {
|
|
6130
|
+
arguments: denormalized
|
|
6131
|
+
})
|
|
6132
|
+
}));
|
|
6133
|
+
emittedIndices.add(tc.index);
|
|
6134
|
+
continue;
|
|
6135
|
+
} catch (unused) {}
|
|
6136
|
+
}
|
|
6137
|
+
passThrough.push(_object_spread_props(_object_spread({}, tc), {
|
|
6138
|
+
function: _object_spread_props(_object_spread({}, fn), {
|
|
6139
|
+
arguments: ""
|
|
6140
|
+
})
|
|
6141
|
+
}));
|
|
6142
|
+
continue;
|
|
6143
|
+
}
|
|
6144
|
+
if (computerCallIndices.has(tc.index)) {
|
|
6145
|
+
;
|
|
6146
|
+
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 : "");
|
|
6147
|
+
argumentBuffers.set(tc.index, buf);
|
|
6148
|
+
if (!emittedIndices.has(tc.index)) {
|
|
6149
|
+
try {
|
|
6150
|
+
JSON.parse(buf);
|
|
6151
|
+
denormalized1 = denormalizeComputerCallArguments({
|
|
6152
|
+
argumentsText: buf,
|
|
6153
|
+
displayWidth: displayWidth,
|
|
6154
|
+
displayHeight: displayHeight,
|
|
6155
|
+
model: model
|
|
6156
|
+
});
|
|
6157
|
+
passThrough.push({
|
|
6158
|
+
index: tc.index,
|
|
6159
|
+
function: {
|
|
6160
|
+
arguments: denormalized1
|
|
6161
|
+
}
|
|
6162
|
+
});
|
|
6163
|
+
emittedIndices.add(tc.index);
|
|
6164
|
+
} catch (unused) {}
|
|
6165
|
+
}
|
|
6166
|
+
continue;
|
|
6167
|
+
}
|
|
6168
|
+
passThrough.push(tc);
|
|
6169
|
+
}
|
|
6170
|
+
} catch (err) {
|
|
6171
|
+
_didIteratorError1 = true;
|
|
6172
|
+
_iteratorError1 = err;
|
|
6173
|
+
} finally{
|
|
6174
|
+
try {
|
|
6175
|
+
if (!_iteratorNormalCompletion && _iterator1.return != null) {
|
|
6176
|
+
_iterator1.return();
|
|
6177
|
+
}
|
|
6178
|
+
} finally{
|
|
6179
|
+
if (_didIteratorError1) {
|
|
6180
|
+
throw _iteratorError1;
|
|
6181
|
+
}
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6184
|
+
if (passThrough.length > 0) {
|
|
6185
|
+
modifiedChunk = _object_spread_props(_object_spread({}, chunk), {
|
|
6186
|
+
choices: [
|
|
6187
|
+
_object_spread_props(_object_spread({}, choice), {
|
|
6188
|
+
delta: _object_spread_props(_object_spread({}, delta), {
|
|
6189
|
+
tool_calls: passThrough
|
|
6190
|
+
})
|
|
6191
|
+
})
|
|
6192
|
+
]
|
|
6193
|
+
});
|
|
6194
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(modifiedChunk), "\n\n")));
|
|
6195
|
+
}
|
|
5283
6196
|
_state.label = 4;
|
|
5284
6197
|
case 4:
|
|
5285
6198
|
_iteratorAbruptCompletion = false;
|
|
@@ -5293,9 +6206,9 @@ var post9 = function(param) {
|
|
|
5293
6206
|
12
|
|
5294
6207
|
];
|
|
5295
6208
|
case 6:
|
|
5296
|
-
|
|
6209
|
+
err1 = _state.sent();
|
|
5297
6210
|
_didIteratorError = true;
|
|
5298
|
-
_iteratorError =
|
|
6211
|
+
_iteratorError = err1;
|
|
5299
6212
|
return [
|
|
5300
6213
|
3,
|
|
5301
6214
|
12
|
|
@@ -5335,6 +6248,52 @@ var post9 = function(param) {
|
|
|
5335
6248
|
7
|
|
5336
6249
|
];
|
|
5337
6250
|
case 12:
|
|
6251
|
+
_iteratorNormalCompletion1 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
6252
|
+
try {
|
|
6253
|
+
for(_iterator2 = Array.from(argumentBuffers)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
|
|
6254
|
+
_step_value = _sliced_to_array(_step2.value, 2), index = _step_value[0], buf1 = _step_value[1];
|
|
6255
|
+
if (!emittedIndices.has(index) && buf1) {
|
|
6256
|
+
denormalized2 = denormalizeComputerCallArguments({
|
|
6257
|
+
argumentsText: buf1,
|
|
6258
|
+
displayWidth: displayWidth,
|
|
6259
|
+
displayHeight: displayHeight,
|
|
6260
|
+
model: model
|
|
6261
|
+
});
|
|
6262
|
+
flushChunk = {
|
|
6263
|
+
object: "chat.completion.chunk",
|
|
6264
|
+
choices: [
|
|
6265
|
+
{
|
|
6266
|
+
index: 0,
|
|
6267
|
+
delta: {
|
|
6268
|
+
tool_calls: [
|
|
6269
|
+
{
|
|
6270
|
+
index: index,
|
|
6271
|
+
function: {
|
|
6272
|
+
arguments: denormalized2
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
]
|
|
6276
|
+
}
|
|
6277
|
+
}
|
|
6278
|
+
]
|
|
6279
|
+
};
|
|
6280
|
+
controller.enqueue(encoder9.encode("data: ".concat(JSON.stringify(flushChunk), "\n\n")));
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6283
|
+
} catch (err) {
|
|
6284
|
+
_didIteratorError2 = true;
|
|
6285
|
+
_iteratorError2 = err;
|
|
6286
|
+
} finally{
|
|
6287
|
+
try {
|
|
6288
|
+
if (!_iteratorNormalCompletion1 && _iterator2.return != null) {
|
|
6289
|
+
_iterator2.return();
|
|
6290
|
+
}
|
|
6291
|
+
} finally{
|
|
6292
|
+
if (_didIteratorError2) {
|
|
6293
|
+
throw _iteratorError2;
|
|
6294
|
+
}
|
|
6295
|
+
}
|
|
6296
|
+
}
|
|
5338
6297
|
controller.close();
|
|
5339
6298
|
return [
|
|
5340
6299
|
2
|
|
@@ -5361,15 +6320,92 @@ var post9 = function(param) {
|
|
|
5361
6320
|
]);
|
|
5362
6321
|
return [
|
|
5363
6322
|
4,
|
|
5364
|
-
ollama.chat.completions.create(
|
|
6323
|
+
ollama.chat.completions.create(resultOptions)
|
|
5365
6324
|
];
|
|
5366
6325
|
case 3:
|
|
5367
6326
|
data = _state.sent();
|
|
6327
|
+
if (computerUseConfig) {
|
|
6328
|
+
;
|
|
6329
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
6330
|
+
try {
|
|
6331
|
+
for(_iterator = ((_data_choices = data.choices) !== null && _data_choices !== void 0 ? _data_choices : [])[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
6332
|
+
choice = _step.value;
|
|
6333
|
+
;
|
|
6334
|
+
message5 = choice.message;
|
|
6335
|
+
toolCalls = (_ref = message5 === null || message5 === void 0 ? void 0 : message5.tool_calls) !== null && _ref !== void 0 ? _ref : [];
|
|
6336
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
6337
|
+
try {
|
|
6338
|
+
for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
6339
|
+
tc = _step1.value;
|
|
6340
|
+
fn = tc.function;
|
|
6341
|
+
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
6342
|
+
fn.arguments = denormalizeComputerCallArguments({
|
|
6343
|
+
argumentsText: fn.arguments,
|
|
6344
|
+
displayWidth: computerUseConfig.displayWidth,
|
|
6345
|
+
displayHeight: computerUseConfig.displayHeight,
|
|
6346
|
+
model: model
|
|
6347
|
+
});
|
|
6348
|
+
}
|
|
6349
|
+
}
|
|
6350
|
+
} catch (err) {
|
|
6351
|
+
_didIteratorError1 = true;
|
|
6352
|
+
_iteratorError1 = err;
|
|
6353
|
+
} finally{
|
|
6354
|
+
try {
|
|
6355
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
6356
|
+
_iterator1.return();
|
|
6357
|
+
}
|
|
6358
|
+
} finally{
|
|
6359
|
+
if (_didIteratorError1) {
|
|
6360
|
+
throw _iteratorError1;
|
|
6361
|
+
}
|
|
6362
|
+
}
|
|
6363
|
+
}
|
|
6364
|
+
}
|
|
6365
|
+
} catch (err) {
|
|
6366
|
+
_didIteratorError = true;
|
|
6367
|
+
_iteratorError = err;
|
|
6368
|
+
} finally{
|
|
6369
|
+
try {
|
|
6370
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
6371
|
+
_iterator.return();
|
|
6372
|
+
}
|
|
6373
|
+
} finally{
|
|
6374
|
+
if (_didIteratorError) {
|
|
6375
|
+
throw _iteratorError;
|
|
6376
|
+
}
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
if (getQuirks(model).cleanArtifacts) {
|
|
6381
|
+
;
|
|
6382
|
+
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
6383
|
+
try {
|
|
6384
|
+
for(_iterator2 = ((_data_choices1 = data.choices) !== null && _data_choices1 !== void 0 ? _data_choices1 : [])[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
6385
|
+
choice1 = _step2.value;
|
|
6386
|
+
message51 = choice1.message;
|
|
6387
|
+
if ((message51 === null || message51 === void 0 ? void 0 : message51.content) && typeof message51.content === "string") {
|
|
6388
|
+
message51.content = sanitizeContent(message51.content);
|
|
6389
|
+
}
|
|
6390
|
+
}
|
|
6391
|
+
} catch (err) {
|
|
6392
|
+
_didIteratorError2 = true;
|
|
6393
|
+
_iteratorError2 = err;
|
|
6394
|
+
} finally{
|
|
6395
|
+
try {
|
|
6396
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
6397
|
+
_iterator2.return();
|
|
6398
|
+
}
|
|
6399
|
+
} finally{
|
|
6400
|
+
if (_didIteratorError2) {
|
|
6401
|
+
throw _iteratorError2;
|
|
6402
|
+
}
|
|
6403
|
+
}
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
5368
6406
|
return [
|
|
5369
6407
|
2,
|
|
5370
|
-
new Response(JSON.stringify({
|
|
5371
|
-
data: data
|
|
5372
|
-
}), {
|
|
6408
|
+
new Response(JSON.stringify(data), {
|
|
5373
6409
|
status: 200,
|
|
5374
6410
|
headers: {
|
|
5375
6411
|
"Content-Type": "application/json"
|
|
@@ -5495,7 +6531,7 @@ var models13 = function(param) {
|
|
|
5495
6531
|
};
|
|
5496
6532
|
};
|
|
5497
6533
|
// src/adapters/client/openRouterClientAdapter/completions/normalizeComputerCall.ts
|
|
5498
|
-
var
|
|
6534
|
+
var MODEL_QUIRKS2 = {
|
|
5499
6535
|
"z-ai/glm-4.6v": {
|
|
5500
6536
|
normalizedCoords: true,
|
|
5501
6537
|
cleanArtifacts: true
|
|
@@ -5508,12 +6544,20 @@ var MODEL_QUIRKS = {
|
|
|
5508
6544
|
referenceWidth: 1920,
|
|
5509
6545
|
referenceHeight: 1080
|
|
5510
6546
|
}
|
|
6547
|
+
},
|
|
6548
|
+
"google/gemma-4": {
|
|
6549
|
+
normalizedCoords: true,
|
|
6550
|
+
fuzzyFallback: true
|
|
6551
|
+
},
|
|
6552
|
+
"google/gemma-3": {
|
|
6553
|
+
normalizedCoords: true,
|
|
6554
|
+
fuzzyFallback: true
|
|
5511
6555
|
}
|
|
5512
6556
|
};
|
|
5513
|
-
var
|
|
6557
|
+
var getQuirks2 = function(model) {
|
|
5514
6558
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5515
6559
|
try {
|
|
5516
|
-
for(var _iterator = Object.entries(
|
|
6560
|
+
for(var _iterator = Object.entries(MODEL_QUIRKS2)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5517
6561
|
var _step_value = _sliced_to_array(_step.value, 2), prefix = _step_value[0], quirks = _step_value[1];
|
|
5518
6562
|
if (model.startsWith(prefix)) return quirks;
|
|
5519
6563
|
}
|
|
@@ -5533,10 +6577,10 @@ var getQuirks = function(model) {
|
|
|
5533
6577
|
}
|
|
5534
6578
|
return {};
|
|
5535
6579
|
};
|
|
5536
|
-
var
|
|
6580
|
+
var cleanTextArtifacts2 = function(text) {
|
|
5537
6581
|
return text.replace(/<\|begin_of_box\|>/g, "").replace(/<\|end_of_box\|>/g, "").replace(/<arg_key>[^<]*<\/arg_key>/g, "").replace(/<\/arg_value>/g, "").trim();
|
|
5538
6582
|
};
|
|
5539
|
-
var
|
|
6583
|
+
var KNOWN_ACTION_TYPES2 = [
|
|
5540
6584
|
"double_click",
|
|
5541
6585
|
"screenshot",
|
|
5542
6586
|
"keypress",
|
|
@@ -5547,7 +6591,7 @@ var KNOWN_ACTION_TYPES = [
|
|
|
5547
6591
|
"drag",
|
|
5548
6592
|
"wait"
|
|
5549
6593
|
];
|
|
5550
|
-
var
|
|
6594
|
+
var splitCoordDigits2 = function(numStr) {
|
|
5551
6595
|
for(var i = 1; i < numStr.length; i++){
|
|
5552
6596
|
var x = parseInt(numStr.slice(0, i));
|
|
5553
6597
|
var y = parseInt(numStr.slice(i));
|
|
@@ -5560,12 +6604,12 @@ var splitCoordDigits = function(numStr) {
|
|
|
5560
6604
|
}
|
|
5561
6605
|
return null;
|
|
5562
6606
|
};
|
|
5563
|
-
var
|
|
6607
|
+
var cleanGlmAction2 = function(action) {
|
|
5564
6608
|
var typeVal = action.type;
|
|
5565
6609
|
if (typeof typeVal !== "string") return action;
|
|
5566
6610
|
var argValueMatch = typeVal.match(/<arg_value>\s*(\{[\s\S]*\})\s*$/);
|
|
5567
6611
|
if (argValueMatch) {
|
|
5568
|
-
var inner =
|
|
6612
|
+
var inner = parseJson3(argValueMatch[1]);
|
|
5569
6613
|
if (inner && (typeof inner === "undefined" ? "undefined" : _type_of(inner)) === "object") {
|
|
5570
6614
|
return inner;
|
|
5571
6615
|
}
|
|
@@ -5573,7 +6617,7 @@ var cleanGlmAction = function(action) {
|
|
|
5573
6617
|
var cleanedType = typeVal.replace(/<\/?[^>]+>/g, "").replace(/\n/g, "").trim();
|
|
5574
6618
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5575
6619
|
try {
|
|
5576
|
-
for(var _iterator =
|
|
6620
|
+
for(var _iterator = KNOWN_ACTION_TYPES2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5577
6621
|
var actionType = _step.value;
|
|
5578
6622
|
if (cleanedType.startsWith(actionType) && cleanedType !== actionType) {
|
|
5579
6623
|
var rest = cleanedType.slice(actionType.length);
|
|
@@ -5586,7 +6630,7 @@ var cleanGlmAction = function(action) {
|
|
|
5586
6630
|
});
|
|
5587
6631
|
}
|
|
5588
6632
|
if (nums && nums.length === 1 && nums[0].length >= 2) {
|
|
5589
|
-
var coords =
|
|
6633
|
+
var coords = splitCoordDigits2(nums[0]);
|
|
5590
6634
|
if (coords) {
|
|
5591
6635
|
return _object_spread(_object_spread_props(_object_spread({}, action), {
|
|
5592
6636
|
type: actionType
|
|
@@ -5617,7 +6661,7 @@ var cleanGlmAction = function(action) {
|
|
|
5617
6661
|
type: cleanedType
|
|
5618
6662
|
});
|
|
5619
6663
|
};
|
|
5620
|
-
var
|
|
6664
|
+
var cleanGlmFields2 = function(action) {
|
|
5621
6665
|
var result = _object_spread({}, action);
|
|
5622
6666
|
if (typeof result.x === "string") {
|
|
5623
6667
|
var nums = result.x.match(/\d+/g);
|
|
@@ -5651,32 +6695,32 @@ var cleanGlmFields = function(action) {
|
|
|
5651
6695
|
}
|
|
5652
6696
|
return result;
|
|
5653
6697
|
};
|
|
5654
|
-
var
|
|
5655
|
-
return
|
|
6698
|
+
var applyArtifactCleanup2 = function(action) {
|
|
6699
|
+
return cleanGlmFields2(cleanGlmAction2(action));
|
|
5656
6700
|
};
|
|
5657
|
-
var
|
|
6701
|
+
var parseJson3 = function(text) {
|
|
5658
6702
|
try {
|
|
5659
6703
|
return JSON.parse(text);
|
|
5660
6704
|
} catch (unused) {
|
|
5661
6705
|
return void 0;
|
|
5662
6706
|
}
|
|
5663
6707
|
};
|
|
5664
|
-
var
|
|
5665
|
-
var direct =
|
|
6708
|
+
var extractJson2 = function(text) {
|
|
6709
|
+
var direct = parseJson3(text);
|
|
5666
6710
|
if (direct) return direct;
|
|
5667
6711
|
var codeBlockMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
5668
6712
|
if (codeBlockMatch) {
|
|
5669
|
-
var parsed =
|
|
6713
|
+
var parsed = parseJson3(codeBlockMatch[1].trim());
|
|
5670
6714
|
if (parsed) return parsed;
|
|
5671
6715
|
}
|
|
5672
6716
|
var jsonMatch = text.match(/(\{[\s\S]*\})\s*$/);
|
|
5673
6717
|
if (jsonMatch) {
|
|
5674
|
-
var parsed1 =
|
|
6718
|
+
var parsed1 = parseJson3(jsonMatch[1].trim());
|
|
5675
6719
|
if (parsed1) return parsed1;
|
|
5676
6720
|
}
|
|
5677
6721
|
return void 0;
|
|
5678
6722
|
};
|
|
5679
|
-
var
|
|
6723
|
+
var fuzzyExtractJson2 = function(text) {
|
|
5680
6724
|
var clickMatch = text.match(/"action"\s*:\s*"click"\s*,\s*"x"\s*:\s*\[?\s*(\d+)\s*,\s*(\d+)/);
|
|
5681
6725
|
if (clickMatch) {
|
|
5682
6726
|
return {
|
|
@@ -5711,24 +6755,24 @@ var fuzzyExtractJson = function(text) {
|
|
|
5711
6755
|
}
|
|
5712
6756
|
return void 0;
|
|
5713
6757
|
};
|
|
5714
|
-
var
|
|
6758
|
+
var denormalize2 = function(value, dimension) {
|
|
5715
6759
|
return Math.round(value / 1e3 * dimension);
|
|
5716
6760
|
};
|
|
5717
|
-
var
|
|
6761
|
+
var denormalizeAction2 = function(action, displayWidth, displayHeight) {
|
|
5718
6762
|
var result = _object_spread({}, action);
|
|
5719
6763
|
if (typeof result.x === "number") {
|
|
5720
|
-
result.x =
|
|
6764
|
+
result.x = denormalize2(result.x, displayWidth);
|
|
5721
6765
|
}
|
|
5722
6766
|
if (typeof result.y === "number") {
|
|
5723
|
-
result.y =
|
|
6767
|
+
result.y = denormalize2(result.y, displayHeight);
|
|
5724
6768
|
}
|
|
5725
6769
|
if (Array.isArray(result.path)) {
|
|
5726
6770
|
result.path = result.path.map(function(point) {
|
|
5727
6771
|
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5728
6772
|
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5729
|
-
x:
|
|
6773
|
+
x: denormalize2(point.x, displayWidth)
|
|
5730
6774
|
} : {}, typeof point.y === "number" ? {
|
|
5731
|
-
y:
|
|
6775
|
+
y: denormalize2(point.y, displayHeight)
|
|
5732
6776
|
} : {});
|
|
5733
6777
|
}
|
|
5734
6778
|
return point;
|
|
@@ -5736,25 +6780,25 @@ var denormalizeAction = function(action, displayWidth, displayHeight) {
|
|
|
5736
6780
|
}
|
|
5737
6781
|
return result;
|
|
5738
6782
|
};
|
|
5739
|
-
var
|
|
6783
|
+
var rescaleCoord2 = function(value, displayDim, referenceDim) {
|
|
5740
6784
|
if (value <= 1) return Math.round(value * displayDim);
|
|
5741
6785
|
return Math.round(value / referenceDim * displayDim);
|
|
5742
6786
|
};
|
|
5743
|
-
var
|
|
6787
|
+
var rescaleRelativeAction2 = function(action, displayWidth, displayHeight, referenceWidth, referenceHeight) {
|
|
5744
6788
|
var result = _object_spread({}, action);
|
|
5745
6789
|
if (typeof result.x === "number") {
|
|
5746
|
-
result.x =
|
|
6790
|
+
result.x = rescaleCoord2(result.x, displayWidth, referenceWidth);
|
|
5747
6791
|
}
|
|
5748
6792
|
if (typeof result.y === "number") {
|
|
5749
|
-
result.y =
|
|
6793
|
+
result.y = rescaleCoord2(result.y, displayHeight, referenceHeight);
|
|
5750
6794
|
}
|
|
5751
6795
|
if (Array.isArray(result.path)) {
|
|
5752
6796
|
result.path = result.path.map(function(point) {
|
|
5753
6797
|
if (point && (typeof point === "undefined" ? "undefined" : _type_of(point)) === "object") {
|
|
5754
6798
|
return _object_spread({}, point, typeof point.x === "number" ? {
|
|
5755
|
-
x:
|
|
6799
|
+
x: rescaleCoord2(point.x, displayWidth, referenceWidth)
|
|
5756
6800
|
} : {}, typeof point.y === "number" ? {
|
|
5757
|
-
y:
|
|
6801
|
+
y: rescaleCoord2(point.y, displayHeight, referenceHeight)
|
|
5758
6802
|
} : {});
|
|
5759
6803
|
}
|
|
5760
6804
|
return point;
|
|
@@ -5762,7 +6806,7 @@ var rescaleRelativeAction = function(action, displayWidth, displayHeight, refere
|
|
|
5762
6806
|
}
|
|
5763
6807
|
return result;
|
|
5764
6808
|
};
|
|
5765
|
-
var
|
|
6809
|
+
var COORD_FIELDS2 = [
|
|
5766
6810
|
"x",
|
|
5767
6811
|
"y",
|
|
5768
6812
|
"text",
|
|
@@ -5773,9 +6817,9 @@ var COORD_FIELDS = [
|
|
|
5773
6817
|
"scroll_y",
|
|
5774
6818
|
"path"
|
|
5775
6819
|
];
|
|
5776
|
-
var
|
|
6820
|
+
var normalizeStructure2 = function(parsed, shouldCleanArtifacts) {
|
|
5777
6821
|
var clean = shouldCleanArtifacts ? function(action) {
|
|
5778
|
-
return
|
|
6822
|
+
return applyArtifactCleanup2(action);
|
|
5779
6823
|
} : function(action) {
|
|
5780
6824
|
return action;
|
|
5781
6825
|
};
|
|
@@ -5794,7 +6838,7 @@ var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
|
5794
6838
|
for(var _iterator = Object.entries(parsed)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5795
6839
|
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
5796
6840
|
if (key === "action") continue;
|
|
5797
|
-
if (
|
|
6841
|
+
if (COORD_FIELDS2.includes(key)) {
|
|
5798
6842
|
actionObj[key] = value;
|
|
5799
6843
|
} else {
|
|
5800
6844
|
rest[key] = value;
|
|
@@ -5825,7 +6869,7 @@ var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
|
5825
6869
|
try {
|
|
5826
6870
|
for(var _iterator1 = Object.entries(parsed)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
5827
6871
|
var _step_value1 = _sliced_to_array(_step1.value, 2), key1 = _step_value1[0], value1 = _step_value1[1];
|
|
5828
|
-
if (key1 === "type" ||
|
|
6872
|
+
if (key1 === "type" || COORD_FIELDS2.includes(key1)) {
|
|
5829
6873
|
actionObj1[key1] = value1;
|
|
5830
6874
|
} else {
|
|
5831
6875
|
rest1[key1] = value1;
|
|
@@ -5851,39 +6895,39 @@ var normalizeStructure = function(parsed, shouldCleanArtifacts) {
|
|
|
5851
6895
|
}
|
|
5852
6896
|
return parsed;
|
|
5853
6897
|
};
|
|
5854
|
-
var
|
|
6898
|
+
var denormalizeComputerCallArguments2 = function(param) {
|
|
5855
6899
|
var argumentsText = param.argumentsText, displayWidth = param.displayWidth, displayHeight = param.displayHeight, model = param.model;
|
|
5856
6900
|
if ((typeof argumentsText === "undefined" ? "undefined" : _type_of(argumentsText)) === "object" && argumentsText !== null) {
|
|
5857
6901
|
argumentsText = JSON.stringify(argumentsText);
|
|
5858
6902
|
}
|
|
5859
|
-
var quirks =
|
|
6903
|
+
var quirks = getQuirks2(model);
|
|
5860
6904
|
var text = argumentsText;
|
|
5861
6905
|
if (quirks.cleanArtifacts) {
|
|
5862
|
-
text =
|
|
6906
|
+
text = cleanTextArtifacts2(text);
|
|
5863
6907
|
}
|
|
5864
|
-
var parsed =
|
|
6908
|
+
var parsed = extractJson2(text);
|
|
5865
6909
|
if (!parsed && (quirks.cleanArtifacts || quirks.fuzzyFallback)) {
|
|
5866
|
-
parsed =
|
|
6910
|
+
parsed = fuzzyExtractJson2(text);
|
|
5867
6911
|
}
|
|
5868
6912
|
if (!parsed || (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) !== "object") {
|
|
5869
6913
|
return argumentsText;
|
|
5870
6914
|
}
|
|
5871
|
-
var normalized =
|
|
6915
|
+
var normalized = normalizeStructure2(parsed, !!quirks.cleanArtifacts);
|
|
5872
6916
|
if (quirks.normalizedCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5873
6917
|
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5874
|
-
action:
|
|
6918
|
+
action: denormalizeAction2(normalized.action, displayWidth, displayHeight)
|
|
5875
6919
|
}));
|
|
5876
6920
|
}
|
|
5877
6921
|
if (quirks.relativeCoords && normalized.action && _type_of(normalized.action) === "object") {
|
|
5878
6922
|
return JSON.stringify(_object_spread_props(_object_spread({}, normalized), {
|
|
5879
|
-
action:
|
|
6923
|
+
action: rescaleRelativeAction2(normalized.action, displayWidth, displayHeight, quirks.relativeCoords.referenceWidth, quirks.relativeCoords.referenceHeight)
|
|
5880
6924
|
}));
|
|
5881
6925
|
}
|
|
5882
6926
|
return JSON.stringify(normalized);
|
|
5883
6927
|
};
|
|
5884
6928
|
// src/adapters/client/openRouterClientAdapter/completions/computerUseTool.ts
|
|
5885
|
-
var
|
|
5886
|
-
var quirks =
|
|
6929
|
+
var buildComputerCallFunction2 = function(model, displayWidth, displayHeight) {
|
|
6930
|
+
var quirks = getQuirks2(model);
|
|
5887
6931
|
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, ").");
|
|
5888
6932
|
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, ")");
|
|
5889
6933
|
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, ")");
|
|
@@ -5986,7 +7030,7 @@ var buildComputerCallFunction = function(model, displayWidth, displayHeight) {
|
|
|
5986
7030
|
}
|
|
5987
7031
|
};
|
|
5988
7032
|
};
|
|
5989
|
-
var
|
|
7033
|
+
var transformTools2 = function(tools, model) {
|
|
5990
7034
|
if (!tools || tools.length === 0) {
|
|
5991
7035
|
return {
|
|
5992
7036
|
tools: tools !== null && tools !== void 0 ? tools : [],
|
|
@@ -6004,7 +7048,7 @@ var transformTools = function(tools, model) {
|
|
|
6004
7048
|
};
|
|
6005
7049
|
return {
|
|
6006
7050
|
type: "function",
|
|
6007
|
-
function:
|
|
7051
|
+
function: buildComputerCallFunction2(model, computerUseConfig.displayWidth, computerUseConfig.displayHeight)
|
|
6008
7052
|
};
|
|
6009
7053
|
}
|
|
6010
7054
|
return tool;
|
|
@@ -6016,12 +7060,12 @@ var transformTools = function(tools, model) {
|
|
|
6016
7060
|
};
|
|
6017
7061
|
// src/adapters/client/openRouterClientAdapter/completions/post.ts
|
|
6018
7062
|
var encoder10 = new TextEncoder();
|
|
6019
|
-
var
|
|
6020
|
-
var
|
|
7063
|
+
var ARTIFACT_TAGS2 = /<\|begin_of_box\|>|<\|end_of_box\|>/g;
|
|
7064
|
+
var sanitizeContent2 = function(content) {
|
|
6021
7065
|
if (!content) return content;
|
|
6022
|
-
return content.replace(
|
|
7066
|
+
return content.replace(ARTIFACT_TAGS2, "").trim();
|
|
6023
7067
|
};
|
|
6024
|
-
var
|
|
7068
|
+
var convertScreenshotToolMessages2 = function(messages6) {
|
|
6025
7069
|
return messages6.map(function(msg) {
|
|
6026
7070
|
if (msg.role !== "tool" || typeof msg.content !== "string") return msg;
|
|
6027
7071
|
try {
|
|
@@ -6265,17 +7309,17 @@ var post10 = function(param) {
|
|
|
6265
7309
|
var openRouter = param.openRouter, provider = param.provider;
|
|
6266
7310
|
return function(_url, options) {
|
|
6267
7311
|
return _async_to_generator(function() {
|
|
6268
|
-
var body, model,
|
|
7312
|
+
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;
|
|
6269
7313
|
return _ts_generator(this, function(_state) {
|
|
6270
7314
|
switch(_state.label){
|
|
6271
7315
|
case 0:
|
|
6272
7316
|
body = JSON.parse(options.body);
|
|
6273
7317
|
model = body.model;
|
|
6274
|
-
|
|
7318
|
+
_transformTools2 = transformTools2(body.tools, model), transformedTools = _transformTools2.tools, computerUseConfig = _transformTools2.computerUseConfig;
|
|
6275
7319
|
resultOptions = _object_spread({}, body, provider && !body.provider ? {
|
|
6276
7320
|
provider: provider
|
|
6277
7321
|
} : {}, computerUseConfig && body.messages ? {
|
|
6278
|
-
messages:
|
|
7322
|
+
messages: convertScreenshotToolMessages2(body.messages)
|
|
6279
7323
|
} : {}, transformedTools.length > 0 ? {
|
|
6280
7324
|
tools: transformedTools
|
|
6281
7325
|
} : {});
|
|
@@ -6301,7 +7345,7 @@ var post10 = function(param) {
|
|
|
6301
7345
|
})
|
|
6302
7346
|
];
|
|
6303
7347
|
}
|
|
6304
|
-
shouldCleanArtifacts =
|
|
7348
|
+
shouldCleanArtifacts = getQuirks2(model).cleanArtifacts;
|
|
6305
7349
|
if (!computerUseConfig && !shouldCleanArtifacts) {
|
|
6306
7350
|
return [
|
|
6307
7351
|
2,
|
|
@@ -6347,7 +7391,7 @@ var post10 = function(param) {
|
|
|
6347
7391
|
delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : _chunk_choices[0];
|
|
6348
7392
|
d = delta === null || delta === void 0 ? void 0 : delta.delta;
|
|
6349
7393
|
if ((d === null || d === void 0 ? void 0 : d.content) && typeof d.content === "string") {
|
|
6350
|
-
d.content =
|
|
7394
|
+
d.content = sanitizeContent2(d.content);
|
|
6351
7395
|
}
|
|
6352
7396
|
controller.enqueue(encoder10.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
6353
7397
|
_state.label = 4;
|
|
@@ -6482,7 +7526,7 @@ var post10 = function(param) {
|
|
|
6482
7526
|
if (initialArgs) {
|
|
6483
7527
|
try {
|
|
6484
7528
|
JSON.parse(initialArgs);
|
|
6485
|
-
denormalized =
|
|
7529
|
+
denormalized = denormalizeComputerCallArguments2({
|
|
6486
7530
|
argumentsText: initialArgs,
|
|
6487
7531
|
displayWidth: displayWidth,
|
|
6488
7532
|
displayHeight: displayHeight,
|
|
@@ -6511,7 +7555,7 @@ var post10 = function(param) {
|
|
|
6511
7555
|
if (!emittedIndices.has(tc.index)) {
|
|
6512
7556
|
try {
|
|
6513
7557
|
JSON.parse(buf);
|
|
6514
|
-
denormalized1 =
|
|
7558
|
+
denormalized1 = denormalizeComputerCallArguments2({
|
|
6515
7559
|
argumentsText: buf,
|
|
6516
7560
|
displayWidth: displayWidth,
|
|
6517
7561
|
displayHeight: displayHeight,
|
|
@@ -6616,7 +7660,7 @@ var post10 = function(param) {
|
|
|
6616
7660
|
for(_iterator2 = Array.from(argumentBuffers)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
|
|
6617
7661
|
_step_value = _sliced_to_array(_step2.value, 2), index = _step_value[0], buf1 = _step_value[1];
|
|
6618
7662
|
if (!emittedIndices.has(index) && buf1) {
|
|
6619
|
-
denormalized2 =
|
|
7663
|
+
denormalized2 = denormalizeComputerCallArguments2({
|
|
6620
7664
|
argumentsText: buf1,
|
|
6621
7665
|
displayWidth: displayWidth,
|
|
6622
7666
|
displayHeight: displayHeight,
|
|
@@ -6720,7 +7764,7 @@ var post10 = function(param) {
|
|
|
6720
7764
|
tc = _step1.value;
|
|
6721
7765
|
fn = tc.function;
|
|
6722
7766
|
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
6723
|
-
fn.arguments =
|
|
7767
|
+
fn.arguments = denormalizeComputerCallArguments2({
|
|
6724
7768
|
argumentsText: fn.arguments,
|
|
6725
7769
|
displayWidth: computerUseConfig.displayWidth,
|
|
6726
7770
|
displayHeight: computerUseConfig.displayHeight,
|
|
@@ -6758,7 +7802,7 @@ var post10 = function(param) {
|
|
|
6758
7802
|
}
|
|
6759
7803
|
}
|
|
6760
7804
|
}
|
|
6761
|
-
if (
|
|
7805
|
+
if (getQuirks2(model).cleanArtifacts) {
|
|
6762
7806
|
;
|
|
6763
7807
|
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
6764
7808
|
try {
|
|
@@ -6766,7 +7810,7 @@ var post10 = function(param) {
|
|
|
6766
7810
|
choice1 = _step2.value;
|
|
6767
7811
|
message51 = choice1.message;
|
|
6768
7812
|
if ((message51 === null || message51 === void 0 ? void 0 : message51.content) && typeof message51.content === "string") {
|
|
6769
|
-
message51.content =
|
|
7813
|
+
message51.content = sanitizeContent2(message51.content);
|
|
6770
7814
|
}
|
|
6771
7815
|
}
|
|
6772
7816
|
} catch (err) {
|