supercompat 3.17.3 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +395 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +395 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,80 @@ function _array_with_holes(arr) {
|
|
|
10
10
|
function _array_without_holes(arr) {
|
|
11
11
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
12
|
}
|
|
13
|
+
function _async_generator(gen) {
|
|
14
|
+
var front, back;
|
|
15
|
+
function send(key, arg) {
|
|
16
|
+
return new Promise(function(resolve, reject) {
|
|
17
|
+
var request = {
|
|
18
|
+
key: key,
|
|
19
|
+
arg: arg,
|
|
20
|
+
resolve: resolve,
|
|
21
|
+
reject: reject,
|
|
22
|
+
next: null
|
|
23
|
+
};
|
|
24
|
+
if (back) back = back.next = request;
|
|
25
|
+
else {
|
|
26
|
+
front = back = request;
|
|
27
|
+
resume(key, arg);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function resume(key, arg) {
|
|
32
|
+
try {
|
|
33
|
+
var result = gen[key](arg);
|
|
34
|
+
var value = result.value;
|
|
35
|
+
var overloaded = value instanceof _overload_yield;
|
|
36
|
+
Promise.resolve(overloaded ? value.v : value).then(function(arg) {
|
|
37
|
+
if (overloaded) {
|
|
38
|
+
var nextKey = key === "return" ? "return" : "next";
|
|
39
|
+
if (!value.k || arg.done) return resume(nextKey, arg);
|
|
40
|
+
else arg = gen[nextKey](arg).value;
|
|
41
|
+
}
|
|
42
|
+
settle(result.done ? "return" : "normal", arg);
|
|
43
|
+
}, function(err) {
|
|
44
|
+
resume("throw", err);
|
|
45
|
+
});
|
|
46
|
+
} catch (err) {
|
|
47
|
+
settle("throw", err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function settle(type, value) {
|
|
51
|
+
switch(type){
|
|
52
|
+
case "return":
|
|
53
|
+
front.resolve({
|
|
54
|
+
value: value,
|
|
55
|
+
done: true
|
|
56
|
+
});
|
|
57
|
+
break;
|
|
58
|
+
case "throw":
|
|
59
|
+
front.reject(value);
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
front.resolve({
|
|
63
|
+
value: value,
|
|
64
|
+
done: false
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
front = front.next;
|
|
69
|
+
if (front) resume(front.key, front.arg);
|
|
70
|
+
else back = null;
|
|
71
|
+
}
|
|
72
|
+
this._invoke = send;
|
|
73
|
+
if (typeof gen.return !== "function") this.return = undefined;
|
|
74
|
+
}
|
|
75
|
+
_async_generator.prototype[typeof Symbol === "function" && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
76
|
+
return this;
|
|
77
|
+
};
|
|
78
|
+
_async_generator.prototype.next = function(arg) {
|
|
79
|
+
return this._invoke("next", arg);
|
|
80
|
+
};
|
|
81
|
+
_async_generator.prototype.throw = function(arg) {
|
|
82
|
+
return this._invoke("throw", arg);
|
|
83
|
+
};
|
|
84
|
+
_async_generator.prototype.return = function(arg) {
|
|
85
|
+
return this._invoke("return", arg);
|
|
86
|
+
};
|
|
13
87
|
function _async_iterator(iterable) {
|
|
14
88
|
var method, async, sync, retry = 2;
|
|
15
89
|
for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
|
|
@@ -80,6 +154,9 @@ function _async_to_generator(fn) {
|
|
|
80
154
|
});
|
|
81
155
|
};
|
|
82
156
|
}
|
|
157
|
+
function _await_async_generator(value) {
|
|
158
|
+
return new _overload_yield(value, 0);
|
|
159
|
+
}
|
|
83
160
|
function _define_property(obj, key, value) {
|
|
84
161
|
if (key in obj) {
|
|
85
162
|
Object.defineProperty(obj, key, {
|
|
@@ -208,6 +285,10 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
208
285
|
}
|
|
209
286
|
return target;
|
|
210
287
|
}
|
|
288
|
+
function _overload_yield(value, kind) {
|
|
289
|
+
this.v = value;
|
|
290
|
+
this.k = kind;
|
|
291
|
+
}
|
|
211
292
|
function _sliced_to_array(arr, i) {
|
|
212
293
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
213
294
|
}
|
|
@@ -226,6 +307,11 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
226
307
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
227
308
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
228
309
|
}
|
|
310
|
+
function _wrap_async_generator(fn) {
|
|
311
|
+
return function() {
|
|
312
|
+
return new _async_generator(fn.apply(this, arguments));
|
|
313
|
+
};
|
|
314
|
+
}
|
|
229
315
|
function _ts_generator(thisArg, body) {
|
|
230
316
|
var f, y, t, _ = {
|
|
231
317
|
label: 0,
|
|
@@ -5239,7 +5325,7 @@ var get11 = function(param) {
|
|
|
5239
5325
|
var openRouter = param.openRouter;
|
|
5240
5326
|
return function(_url, _options) {
|
|
5241
5327
|
return _async_to_generator(function() {
|
|
5242
|
-
var data, error;
|
|
5328
|
+
var data, openaiModels, error;
|
|
5243
5329
|
return _ts_generator(this, function(_state) {
|
|
5244
5330
|
switch(_state.label){
|
|
5245
5331
|
case 0:
|
|
@@ -5255,9 +5341,20 @@ var get11 = function(param) {
|
|
|
5255
5341
|
];
|
|
5256
5342
|
case 1:
|
|
5257
5343
|
data = _state.sent();
|
|
5344
|
+
openaiModels = {
|
|
5345
|
+
object: "list",
|
|
5346
|
+
data: data.data.map(function(m) {
|
|
5347
|
+
return {
|
|
5348
|
+
id: m.id,
|
|
5349
|
+
object: "model",
|
|
5350
|
+
created: m.created,
|
|
5351
|
+
owned_by: m.id.split("/")[0] || "openrouter"
|
|
5352
|
+
};
|
|
5353
|
+
})
|
|
5354
|
+
};
|
|
5258
5355
|
return [
|
|
5259
5356
|
2,
|
|
5260
|
-
new Response(JSON.stringify(
|
|
5357
|
+
new Response(JSON.stringify(openaiModels), {
|
|
5261
5358
|
status: 200,
|
|
5262
5359
|
headers: {
|
|
5263
5360
|
"Content-Type": "application/json"
|
|
@@ -5842,11 +5939,230 @@ var convertScreenshotToolMessages = function(messages5) {
|
|
|
5842
5939
|
return msg;
|
|
5843
5940
|
});
|
|
5844
5941
|
};
|
|
5942
|
+
var resolveApiKey = function(apiKey) {
|
|
5943
|
+
return _async_to_generator(function() {
|
|
5944
|
+
var _tmp;
|
|
5945
|
+
return _ts_generator(this, function(_state) {
|
|
5946
|
+
switch(_state.label){
|
|
5947
|
+
case 0:
|
|
5948
|
+
if (!apiKey) return [
|
|
5949
|
+
2,
|
|
5950
|
+
""
|
|
5951
|
+
];
|
|
5952
|
+
if (!(typeof apiKey === "function")) return [
|
|
5953
|
+
3,
|
|
5954
|
+
2
|
|
5955
|
+
];
|
|
5956
|
+
return [
|
|
5957
|
+
4,
|
|
5958
|
+
apiKey()
|
|
5959
|
+
];
|
|
5960
|
+
case 1:
|
|
5961
|
+
_tmp = _state.sent();
|
|
5962
|
+
return [
|
|
5963
|
+
3,
|
|
5964
|
+
3
|
|
5965
|
+
];
|
|
5966
|
+
case 2:
|
|
5967
|
+
_tmp = apiKey;
|
|
5968
|
+
_state.label = 3;
|
|
5969
|
+
case 3:
|
|
5970
|
+
return [
|
|
5971
|
+
2,
|
|
5972
|
+
_tmp
|
|
5973
|
+
];
|
|
5974
|
+
}
|
|
5975
|
+
});
|
|
5976
|
+
})();
|
|
5977
|
+
};
|
|
5978
|
+
function parseSSE(response) {
|
|
5979
|
+
return _wrap_async_generator(function() {
|
|
5980
|
+
var reader, decoder, buffer, _lines_pop, _ref, done, value, lines, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, line, trimmed, data, unused, err;
|
|
5981
|
+
return _ts_generator(this, function(_state) {
|
|
5982
|
+
switch(_state.label){
|
|
5983
|
+
case 0:
|
|
5984
|
+
reader = response.body.getReader();
|
|
5985
|
+
decoder = new TextDecoder();
|
|
5986
|
+
buffer = "";
|
|
5987
|
+
_state.label = 1;
|
|
5988
|
+
case 1:
|
|
5989
|
+
_state.trys.push([
|
|
5990
|
+
1,
|
|
5991
|
+
,
|
|
5992
|
+
15,
|
|
5993
|
+
16
|
|
5994
|
+
]);
|
|
5995
|
+
_state.label = 2;
|
|
5996
|
+
case 2:
|
|
5997
|
+
if (!true) return [
|
|
5998
|
+
3,
|
|
5999
|
+
14
|
|
6000
|
+
];
|
|
6001
|
+
return [
|
|
6002
|
+
4,
|
|
6003
|
+
_await_async_generator(reader.read())
|
|
6004
|
+
];
|
|
6005
|
+
case 3:
|
|
6006
|
+
_ref = _state.sent(), done = _ref.done, value = _ref.value;
|
|
6007
|
+
if (done) return [
|
|
6008
|
+
3,
|
|
6009
|
+
14
|
|
6010
|
+
];
|
|
6011
|
+
buffer += decoder.decode(value, {
|
|
6012
|
+
stream: true
|
|
6013
|
+
});
|
|
6014
|
+
lines = buffer.split("\n");
|
|
6015
|
+
buffer = (_lines_pop = lines.pop()) !== null && _lines_pop !== void 0 ? _lines_pop : "";
|
|
6016
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
6017
|
+
_state.label = 4;
|
|
6018
|
+
case 4:
|
|
6019
|
+
_state.trys.push([
|
|
6020
|
+
4,
|
|
6021
|
+
11,
|
|
6022
|
+
12,
|
|
6023
|
+
13
|
|
6024
|
+
]);
|
|
6025
|
+
_iterator = lines[Symbol.iterator]();
|
|
6026
|
+
_state.label = 5;
|
|
6027
|
+
case 5:
|
|
6028
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
6029
|
+
3,
|
|
6030
|
+
10
|
|
6031
|
+
];
|
|
6032
|
+
line = _step.value;
|
|
6033
|
+
trimmed = line.trim();
|
|
6034
|
+
if (!trimmed.startsWith("data: ")) return [
|
|
6035
|
+
3,
|
|
6036
|
+
9
|
|
6037
|
+
];
|
|
6038
|
+
data = trimmed.slice(6);
|
|
6039
|
+
if (data === "[DONE]") return [
|
|
6040
|
+
2
|
|
6041
|
+
];
|
|
6042
|
+
_state.label = 6;
|
|
6043
|
+
case 6:
|
|
6044
|
+
_state.trys.push([
|
|
6045
|
+
6,
|
|
6046
|
+
8,
|
|
6047
|
+
,
|
|
6048
|
+
9
|
|
6049
|
+
]);
|
|
6050
|
+
return [
|
|
6051
|
+
4,
|
|
6052
|
+
JSON.parse(data)
|
|
6053
|
+
];
|
|
6054
|
+
case 7:
|
|
6055
|
+
_state.sent();
|
|
6056
|
+
return [
|
|
6057
|
+
3,
|
|
6058
|
+
9
|
|
6059
|
+
];
|
|
6060
|
+
case 8:
|
|
6061
|
+
unused = _state.sent();
|
|
6062
|
+
return [
|
|
6063
|
+
3,
|
|
6064
|
+
9
|
|
6065
|
+
];
|
|
6066
|
+
case 9:
|
|
6067
|
+
_iteratorNormalCompletion = true;
|
|
6068
|
+
return [
|
|
6069
|
+
3,
|
|
6070
|
+
5
|
|
6071
|
+
];
|
|
6072
|
+
case 10:
|
|
6073
|
+
return [
|
|
6074
|
+
3,
|
|
6075
|
+
13
|
|
6076
|
+
];
|
|
6077
|
+
case 11:
|
|
6078
|
+
err = _state.sent();
|
|
6079
|
+
_didIteratorError = true;
|
|
6080
|
+
_iteratorError = err;
|
|
6081
|
+
return [
|
|
6082
|
+
3,
|
|
6083
|
+
13
|
|
6084
|
+
];
|
|
6085
|
+
case 12:
|
|
6086
|
+
try {
|
|
6087
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
6088
|
+
_iterator.return();
|
|
6089
|
+
}
|
|
6090
|
+
} finally{
|
|
6091
|
+
if (_didIteratorError) {
|
|
6092
|
+
throw _iteratorError;
|
|
6093
|
+
}
|
|
6094
|
+
}
|
|
6095
|
+
return [
|
|
6096
|
+
7
|
|
6097
|
+
];
|
|
6098
|
+
case 13:
|
|
6099
|
+
return [
|
|
6100
|
+
3,
|
|
6101
|
+
2
|
|
6102
|
+
];
|
|
6103
|
+
case 14:
|
|
6104
|
+
return [
|
|
6105
|
+
3,
|
|
6106
|
+
16
|
|
6107
|
+
];
|
|
6108
|
+
case 15:
|
|
6109
|
+
reader.releaseLock();
|
|
6110
|
+
return [
|
|
6111
|
+
7
|
|
6112
|
+
];
|
|
6113
|
+
case 16:
|
|
6114
|
+
return [
|
|
6115
|
+
2
|
|
6116
|
+
];
|
|
6117
|
+
}
|
|
6118
|
+
});
|
|
6119
|
+
})();
|
|
6120
|
+
}
|
|
6121
|
+
var rawFetch = function(openRouter, body) {
|
|
6122
|
+
return _async_to_generator(function() {
|
|
6123
|
+
var _ref, _openRouter__baseURL, apiKey, baseURL, headers, request, httpClient;
|
|
6124
|
+
return _ts_generator(this, function(_state) {
|
|
6125
|
+
switch(_state.label){
|
|
6126
|
+
case 0:
|
|
6127
|
+
return [
|
|
6128
|
+
4,
|
|
6129
|
+
resolveApiKey(openRouter._options.apiKey)
|
|
6130
|
+
];
|
|
6131
|
+
case 1:
|
|
6132
|
+
apiKey = _state.sent();
|
|
6133
|
+
baseURL = ((_ref = (_openRouter__baseURL = openRouter._baseURL) === null || _openRouter__baseURL === void 0 ? void 0 : _openRouter__baseURL.toString()) !== null && _ref !== void 0 ? _ref : "https://openrouter.ai/api/v1").replace(/\/+$/, "");
|
|
6134
|
+
headers = {
|
|
6135
|
+
"Content-Type": "application/json",
|
|
6136
|
+
"Authorization": "Bearer ".concat(apiKey)
|
|
6137
|
+
};
|
|
6138
|
+
if (body.stream) {
|
|
6139
|
+
headers["Accept"] = "text/event-stream";
|
|
6140
|
+
}
|
|
6141
|
+
if (openRouter._options.httpReferer) {
|
|
6142
|
+
headers["HTTP-Referer"] = openRouter._options.httpReferer;
|
|
6143
|
+
}
|
|
6144
|
+
if (openRouter._options.xTitle) {
|
|
6145
|
+
headers["X-Title"] = openRouter._options.xTitle;
|
|
6146
|
+
}
|
|
6147
|
+
request = new Request("".concat(baseURL, "/chat/completions"), {
|
|
6148
|
+
method: "POST",
|
|
6149
|
+
headers: headers,
|
|
6150
|
+
body: JSON.stringify(body)
|
|
6151
|
+
});
|
|
6152
|
+
httpClient = openRouter._options.httpClient;
|
|
6153
|
+
return [
|
|
6154
|
+
2,
|
|
6155
|
+
httpClient ? httpClient.request(request) : fetch(request)
|
|
6156
|
+
];
|
|
6157
|
+
}
|
|
6158
|
+
});
|
|
6159
|
+
})();
|
|
6160
|
+
};
|
|
5845
6161
|
var post10 = function(param) {
|
|
5846
6162
|
var openRouter = param.openRouter;
|
|
5847
6163
|
return function(_url, options) {
|
|
5848
6164
|
return _async_to_generator(function() {
|
|
5849
|
-
var body, model, _transformTools, transformedTools, computerUseConfig, resultOptions, response, shouldCleanArtifacts,
|
|
6165
|
+
var body, model, _transformTools, 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, message, toolCalls, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _data_choices1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice1, message1, error;
|
|
5850
6166
|
return _ts_generator(this, function(_state) {
|
|
5851
6167
|
switch(_state.label){
|
|
5852
6168
|
case 0:
|
|
@@ -5864,16 +6180,39 @@ var post10 = function(param) {
|
|
|
5864
6180
|
];
|
|
5865
6181
|
return [
|
|
5866
6182
|
4,
|
|
5867
|
-
openRouter
|
|
6183
|
+
rawFetch(openRouter, resultOptions)
|
|
5868
6184
|
];
|
|
5869
6185
|
case 1:
|
|
5870
6186
|
response = _state.sent();
|
|
6187
|
+
if (!response.ok) {
|
|
6188
|
+
;
|
|
6189
|
+
return [
|
|
6190
|
+
2,
|
|
6191
|
+
new Response(response.body, {
|
|
6192
|
+
status: response.status,
|
|
6193
|
+
headers: {
|
|
6194
|
+
"Content-Type": (_response_headers_get = response.headers.get("Content-Type")) !== null && _response_headers_get !== void 0 ? _response_headers_get : "application/json"
|
|
6195
|
+
}
|
|
6196
|
+
})
|
|
6197
|
+
];
|
|
6198
|
+
}
|
|
5871
6199
|
shouldCleanArtifacts = getQuirks(model).cleanArtifacts;
|
|
6200
|
+
if (!computerUseConfig && !shouldCleanArtifacts) {
|
|
6201
|
+
return [
|
|
6202
|
+
2,
|
|
6203
|
+
new Response(response.body, {
|
|
6204
|
+
status: response.status,
|
|
6205
|
+
headers: {
|
|
6206
|
+
"Content-Type": "text/event-stream"
|
|
6207
|
+
}
|
|
6208
|
+
})
|
|
6209
|
+
];
|
|
6210
|
+
}
|
|
5872
6211
|
if (!computerUseConfig) {
|
|
5873
|
-
|
|
6212
|
+
readableStream2 = new ReadableStream({
|
|
5874
6213
|
start: function start(controller) {
|
|
5875
6214
|
return _async_to_generator(function() {
|
|
5876
|
-
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk,
|
|
6215
|
+
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, delta, d, err;
|
|
5877
6216
|
return _ts_generator(this, function(_state) {
|
|
5878
6217
|
switch(_state.label){
|
|
5879
6218
|
case 0:
|
|
@@ -5886,7 +6225,7 @@ var post10 = function(param) {
|
|
|
5886
6225
|
7,
|
|
5887
6226
|
12
|
|
5888
6227
|
]);
|
|
5889
|
-
_iterator = _async_iterator(response);
|
|
6228
|
+
_iterator = _async_iterator(parseSSE(response));
|
|
5890
6229
|
_state.label = 2;
|
|
5891
6230
|
case 2:
|
|
5892
6231
|
return [
|
|
@@ -5900,12 +6239,10 @@ var post10 = function(param) {
|
|
|
5900
6239
|
];
|
|
5901
6240
|
_value = _step.value;
|
|
5902
6241
|
chunk = _value;
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
delta.content = sanitizeContent(delta.content);
|
|
5908
|
-
}
|
|
6242
|
+
delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : _chunk_choices[0];
|
|
6243
|
+
d = delta === null || delta === void 0 ? void 0 : delta.delta;
|
|
6244
|
+
if ((d === null || d === void 0 ? void 0 : d.content) && typeof d.content === "string") {
|
|
6245
|
+
d.content = sanitizeContent(d.content);
|
|
5909
6246
|
}
|
|
5910
6247
|
controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
|
|
5911
6248
|
_state.label = 4;
|
|
@@ -5974,7 +6311,7 @@ var post10 = function(param) {
|
|
|
5974
6311
|
});
|
|
5975
6312
|
return [
|
|
5976
6313
|
2,
|
|
5977
|
-
new Response(
|
|
6314
|
+
new Response(readableStream2, {
|
|
5978
6315
|
headers: {
|
|
5979
6316
|
"Content-Type": "text/event-stream"
|
|
5980
6317
|
}
|
|
@@ -5982,10 +6319,10 @@ var post10 = function(param) {
|
|
|
5982
6319
|
];
|
|
5983
6320
|
}
|
|
5984
6321
|
displayWidth = computerUseConfig.displayWidth, displayHeight = computerUseConfig.displayHeight;
|
|
5985
|
-
|
|
6322
|
+
readableStream = new ReadableStream({
|
|
5986
6323
|
start: function start(controller) {
|
|
5987
6324
|
return _async_to_generator(function() {
|
|
5988
|
-
var computerCallIndices, argumentBuffers, emittedIndices, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices,
|
|
6325
|
+
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;
|
|
5989
6326
|
return _ts_generator(this, function(_state) {
|
|
5990
6327
|
switch(_state.label){
|
|
5991
6328
|
case 0:
|
|
@@ -6001,7 +6338,7 @@ var post10 = function(param) {
|
|
|
6001
6338
|
7,
|
|
6002
6339
|
12
|
|
6003
6340
|
]);
|
|
6004
|
-
_iterator = _async_iterator(response);
|
|
6341
|
+
_iterator = _async_iterator(parseSSE(response));
|
|
6005
6342
|
_state.label = 2;
|
|
6006
6343
|
case 2:
|
|
6007
6344
|
return [
|
|
@@ -6017,7 +6354,9 @@ var post10 = function(param) {
|
|
|
6017
6354
|
chunk = _value;
|
|
6018
6355
|
choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
|
|
6019
6356
|
choice = choices[0];
|
|
6020
|
-
|
|
6357
|
+
delta = choice === null || choice === void 0 ? void 0 : choice.delta;
|
|
6358
|
+
toolCalls = delta === null || delta === void 0 ? void 0 : delta.tool_calls;
|
|
6359
|
+
if (!toolCalls) {
|
|
6021
6360
|
controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
|
|
6022
6361
|
return [
|
|
6023
6362
|
3,
|
|
@@ -6027,14 +6366,13 @@ var post10 = function(param) {
|
|
|
6027
6366
|
passThrough = [];
|
|
6028
6367
|
_iteratorNormalCompletion = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
6029
6368
|
try {
|
|
6030
|
-
for(_iterator1 =
|
|
6369
|
+
for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
|
|
6031
6370
|
tc = _step1.value;
|
|
6032
|
-
;
|
|
6033
|
-
if ((
|
|
6034
|
-
;
|
|
6371
|
+
fn = tc.function;
|
|
6372
|
+
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
6035
6373
|
;
|
|
6036
6374
|
computerCallIndices.add(tc.index);
|
|
6037
|
-
initialArgs = (_ref =
|
|
6375
|
+
initialArgs = (_ref = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref !== void 0 ? _ref : "";
|
|
6038
6376
|
argumentBuffers.set(tc.index, initialArgs);
|
|
6039
6377
|
if (initialArgs) {
|
|
6040
6378
|
try {
|
|
@@ -6046,7 +6384,7 @@ var post10 = function(param) {
|
|
|
6046
6384
|
model: model
|
|
6047
6385
|
});
|
|
6048
6386
|
passThrough.push(_object_spread_props(_object_spread({}, tc), {
|
|
6049
|
-
function: _object_spread_props(_object_spread({},
|
|
6387
|
+
function: _object_spread_props(_object_spread({}, fn), {
|
|
6050
6388
|
arguments: denormalized
|
|
6051
6389
|
})
|
|
6052
6390
|
}));
|
|
@@ -6055,7 +6393,7 @@ var post10 = function(param) {
|
|
|
6055
6393
|
} catch (unused) {}
|
|
6056
6394
|
}
|
|
6057
6395
|
passThrough.push(_object_spread_props(_object_spread({}, tc), {
|
|
6058
|
-
function: _object_spread_props(_object_spread({},
|
|
6396
|
+
function: _object_spread_props(_object_spread({}, fn), {
|
|
6059
6397
|
arguments: ""
|
|
6060
6398
|
})
|
|
6061
6399
|
}));
|
|
@@ -6063,8 +6401,7 @@ var post10 = function(param) {
|
|
|
6063
6401
|
}
|
|
6064
6402
|
if (computerCallIndices.has(tc.index)) {
|
|
6065
6403
|
;
|
|
6066
|
-
;
|
|
6067
|
-
buf = ((_argumentBuffers_get = argumentBuffers.get(tc.index)) !== null && _argumentBuffers_get !== void 0 ? _argumentBuffers_get : "") + ((_ref1 = (_tc_function2 = tc.function) === null || _tc_function2 === void 0 ? void 0 : _tc_function2.arguments) !== null && _ref1 !== void 0 ? _ref1 : "");
|
|
6404
|
+
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 : "");
|
|
6068
6405
|
argumentBuffers.set(tc.index, buf);
|
|
6069
6406
|
if (!emittedIndices.has(tc.index)) {
|
|
6070
6407
|
try {
|
|
@@ -6106,7 +6443,7 @@ var post10 = function(param) {
|
|
|
6106
6443
|
modifiedChunk = _object_spread_props(_object_spread({}, chunk), {
|
|
6107
6444
|
choices: [
|
|
6108
6445
|
_object_spread_props(_object_spread({}, choice), {
|
|
6109
|
-
delta: _object_spread_props(_object_spread({},
|
|
6446
|
+
delta: _object_spread_props(_object_spread({}, delta), {
|
|
6110
6447
|
tool_calls: passThrough
|
|
6111
6448
|
})
|
|
6112
6449
|
})
|
|
@@ -6226,7 +6563,7 @@ var post10 = function(param) {
|
|
|
6226
6563
|
});
|
|
6227
6564
|
return [
|
|
6228
6565
|
2,
|
|
6229
|
-
new Response(
|
|
6566
|
+
new Response(readableStream, {
|
|
6230
6567
|
headers: {
|
|
6231
6568
|
"Content-Type": "text/event-stream"
|
|
6232
6569
|
}
|
|
@@ -6235,15 +6572,33 @@ var post10 = function(param) {
|
|
|
6235
6572
|
case 2:
|
|
6236
6573
|
_state.trys.push([
|
|
6237
6574
|
2,
|
|
6238
|
-
|
|
6575
|
+
5,
|
|
6239
6576
|
,
|
|
6240
|
-
|
|
6577
|
+
6
|
|
6241
6578
|
]);
|
|
6242
6579
|
return [
|
|
6243
6580
|
4,
|
|
6244
|
-
openRouter
|
|
6581
|
+
rawFetch(openRouter, resultOptions)
|
|
6245
6582
|
];
|
|
6246
6583
|
case 3:
|
|
6584
|
+
response1 = _state.sent();
|
|
6585
|
+
if (!response1.ok) {
|
|
6586
|
+
;
|
|
6587
|
+
return [
|
|
6588
|
+
2,
|
|
6589
|
+
new Response(response1.body, {
|
|
6590
|
+
status: response1.status,
|
|
6591
|
+
headers: {
|
|
6592
|
+
"Content-Type": (_response_headers_get1 = response1.headers.get("Content-Type")) !== null && _response_headers_get1 !== void 0 ? _response_headers_get1 : "application/json"
|
|
6593
|
+
}
|
|
6594
|
+
})
|
|
6595
|
+
];
|
|
6596
|
+
}
|
|
6597
|
+
return [
|
|
6598
|
+
4,
|
|
6599
|
+
response1.json()
|
|
6600
|
+
];
|
|
6601
|
+
case 4:
|
|
6247
6602
|
data = _state.sent();
|
|
6248
6603
|
if (computerUseConfig) {
|
|
6249
6604
|
;
|
|
@@ -6252,10 +6607,11 @@ var post10 = function(param) {
|
|
|
6252
6607
|
for(_iterator = ((_data_choices = data.choices) !== null && _data_choices !== void 0 ? _data_choices : [])[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
6253
6608
|
choice = _step.value;
|
|
6254
6609
|
;
|
|
6255
|
-
;
|
|
6610
|
+
message = choice.message;
|
|
6611
|
+
toolCalls = (_ref = message === null || message === void 0 ? void 0 : message.tool_calls) !== null && _ref !== void 0 ? _ref : [];
|
|
6256
6612
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
6257
6613
|
try {
|
|
6258
|
-
for(_iterator1 =
|
|
6614
|
+
for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
6259
6615
|
tc = _step1.value;
|
|
6260
6616
|
fn = tc.function;
|
|
6261
6617
|
if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
|
|
@@ -6303,9 +6659,9 @@ var post10 = function(param) {
|
|
|
6303
6659
|
try {
|
|
6304
6660
|
for(_iterator2 = ((_data_choices1 = data.choices) !== null && _data_choices1 !== void 0 ? _data_choices1 : [])[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
6305
6661
|
choice1 = _step2.value;
|
|
6306
|
-
;
|
|
6307
|
-
if ((
|
|
6308
|
-
|
|
6662
|
+
message1 = choice1.message;
|
|
6663
|
+
if ((message1 === null || message1 === void 0 ? void 0 : message1.content) && typeof message1.content === "string") {
|
|
6664
|
+
message1.content = sanitizeContent(message1.content);
|
|
6309
6665
|
}
|
|
6310
6666
|
}
|
|
6311
6667
|
} catch (err) {
|
|
@@ -6332,7 +6688,7 @@ var post10 = function(param) {
|
|
|
6332
6688
|
}
|
|
6333
6689
|
})
|
|
6334
6690
|
];
|
|
6335
|
-
case
|
|
6691
|
+
case 5:
|
|
6336
6692
|
error = _state.sent();
|
|
6337
6693
|
return [
|
|
6338
6694
|
2,
|
|
@@ -6345,7 +6701,7 @@ var post10 = function(param) {
|
|
|
6345
6701
|
}
|
|
6346
6702
|
})
|
|
6347
6703
|
];
|
|
6348
|
-
case
|
|
6704
|
+
case 6:
|
|
6349
6705
|
return [
|
|
6350
6706
|
2
|
|
6351
6707
|
];
|