supercompat 3.17.3 → 3.18.1

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 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(data), {
5357
+ new Response(JSON.stringify(openaiModels), {
5261
5358
  status: 200,
5262
5359
  headers: {
5263
5360
  "Content-Type": "application/json"
@@ -5842,18 +5939,239 @@ 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
- var openRouter = param.openRouter;
6162
+ var openRouter = param.openRouter, provider = param.provider;
5847
6163
  return function(_url, options) {
5848
6164
  return _async_to_generator(function() {
5849
- var body, model, _transformTools, transformedTools, computerUseConfig, resultOptions, response, shouldCleanArtifacts, stream2, displayWidth, displayHeight, stream, data, _data_choices, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, choice, _ref, _choice_message, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, fn, _data_choices1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice1, _choice_message1, error;
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:
5853
6169
  body = JSON.parse(options.body);
5854
6170
  model = body.model;
5855
6171
  _transformTools = transformTools(body.tools, model), transformedTools = _transformTools.tools, computerUseConfig = _transformTools.computerUseConfig;
5856
- resultOptions = _object_spread({}, body, computerUseConfig && body.messages ? {
6172
+ resultOptions = _object_spread({}, body, provider && !body.provider ? {
6173
+ provider: provider
6174
+ } : {}, computerUseConfig && body.messages ? {
5857
6175
  messages: convertScreenshotToolMessages(body.messages)
5858
6176
  } : {}, transformedTools.length > 0 ? {
5859
6177
  tools: transformedTools
@@ -5864,16 +6182,39 @@ var post10 = function(param) {
5864
6182
  ];
5865
6183
  return [
5866
6184
  4,
5867
- openRouter.chat.completions.create(resultOptions)
6185
+ rawFetch(openRouter, resultOptions)
5868
6186
  ];
5869
6187
  case 1:
5870
6188
  response = _state.sent();
6189
+ if (!response.ok) {
6190
+ ;
6191
+ return [
6192
+ 2,
6193
+ new Response(response.body, {
6194
+ status: response.status,
6195
+ headers: {
6196
+ "Content-Type": (_response_headers_get = response.headers.get("Content-Type")) !== null && _response_headers_get !== void 0 ? _response_headers_get : "application/json"
6197
+ }
6198
+ })
6199
+ ];
6200
+ }
5871
6201
  shouldCleanArtifacts = getQuirks(model).cleanArtifacts;
6202
+ if (!computerUseConfig && !shouldCleanArtifacts) {
6203
+ return [
6204
+ 2,
6205
+ new Response(response.body, {
6206
+ status: response.status,
6207
+ headers: {
6208
+ "Content-Type": "text/event-stream"
6209
+ }
6210
+ })
6211
+ ];
6212
+ }
5872
6213
  if (!computerUseConfig) {
5873
- stream2 = new ReadableStream({
6214
+ readableStream2 = new ReadableStream({
5874
6215
  start: function start(controller) {
5875
6216
  return _async_to_generator(function() {
5876
- var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices_, _chunk_choices, delta, err;
6217
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, delta, d, err;
5877
6218
  return _ts_generator(this, function(_state) {
5878
6219
  switch(_state.label){
5879
6220
  case 0:
@@ -5886,7 +6227,7 @@ var post10 = function(param) {
5886
6227
  7,
5887
6228
  12
5888
6229
  ]);
5889
- _iterator = _async_iterator(response);
6230
+ _iterator = _async_iterator(parseSSE(response));
5890
6231
  _state.label = 2;
5891
6232
  case 2:
5892
6233
  return [
@@ -5900,12 +6241,10 @@ var post10 = function(param) {
5900
6241
  ];
5901
6242
  _value = _step.value;
5902
6243
  chunk = _value;
5903
- if (shouldCleanArtifacts) {
5904
- ;
5905
- delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : (_chunk_choices_ = _chunk_choices[0]) === null || _chunk_choices_ === void 0 ? void 0 : _chunk_choices_.delta;
5906
- if (delta === null || delta === void 0 ? void 0 : delta.content) {
5907
- delta.content = sanitizeContent(delta.content);
5908
- }
6244
+ delta = (_chunk_choices = chunk.choices) === null || _chunk_choices === void 0 ? void 0 : _chunk_choices[0];
6245
+ d = delta === null || delta === void 0 ? void 0 : delta.delta;
6246
+ if ((d === null || d === void 0 ? void 0 : d.content) && typeof d.content === "string") {
6247
+ d.content = sanitizeContent(d.content);
5909
6248
  }
5910
6249
  controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
5911
6250
  _state.label = 4;
@@ -5974,7 +6313,7 @@ var post10 = function(param) {
5974
6313
  });
5975
6314
  return [
5976
6315
  2,
5977
- new Response(stream2, {
6316
+ new Response(readableStream2, {
5978
6317
  headers: {
5979
6318
  "Content-Type": "text/event-stream"
5980
6319
  }
@@ -5982,10 +6321,10 @@ var post10 = function(param) {
5982
6321
  ];
5983
6322
  }
5984
6323
  displayWidth = computerUseConfig.displayWidth, displayHeight = computerUseConfig.displayHeight;
5985
- stream = new ReadableStream({
6324
+ readableStream = new ReadableStream({
5986
6325
  start: function start(controller) {
5987
6326
  return _async_to_generator(function() {
5988
- var computerCallIndices, argumentBuffers, emittedIndices, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, _choice_delta, choices, choice, passThrough, _iteratorNormalCompletion, _didIteratorError1, _iteratorError1, _iterator1, _step1, tc, _tc_function, _ref, _tc_function1, initialArgs, denormalized, _argumentBuffers_get, _ref1, _tc_function2, buf, denormalized1, modifiedChunk, err1, _iteratorNormalCompletion1, _didIteratorError2, _iteratorError2, _iterator2, _step2, _step_value, index, buf1, denormalized2, flushChunk;
6327
+ 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
6328
  return _ts_generator(this, function(_state) {
5990
6329
  switch(_state.label){
5991
6330
  case 0:
@@ -6001,7 +6340,7 @@ var post10 = function(param) {
6001
6340
  7,
6002
6341
  12
6003
6342
  ]);
6004
- _iterator = _async_iterator(response);
6343
+ _iterator = _async_iterator(parseSSE(response));
6005
6344
  _state.label = 2;
6006
6345
  case 2:
6007
6346
  return [
@@ -6017,7 +6356,9 @@ var post10 = function(param) {
6017
6356
  chunk = _value;
6018
6357
  choices = (_chunk_choices = chunk.choices) !== null && _chunk_choices !== void 0 ? _chunk_choices : [];
6019
6358
  choice = choices[0];
6020
- if (!(choice === null || choice === void 0 ? void 0 : (_choice_delta = choice.delta) === null || _choice_delta === void 0 ? void 0 : _choice_delta.tool_calls)) {
6359
+ delta = choice === null || choice === void 0 ? void 0 : choice.delta;
6360
+ toolCalls = delta === null || delta === void 0 ? void 0 : delta.tool_calls;
6361
+ if (!toolCalls) {
6021
6362
  controller.enqueue("data: ".concat(JSON.stringify(chunk), "\n\n"));
6022
6363
  return [
6023
6364
  3,
@@ -6027,14 +6368,13 @@ var post10 = function(param) {
6027
6368
  passThrough = [];
6028
6369
  _iteratorNormalCompletion = true, _didIteratorError1 = false, _iteratorError1 = undefined;
6029
6370
  try {
6030
- for(_iterator1 = choice.delta.tool_calls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
6371
+ for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){
6031
6372
  tc = _step1.value;
6032
- ;
6033
- if (((_tc_function = tc.function) === null || _tc_function === void 0 ? void 0 : _tc_function.name) === "computer_call") {
6034
- ;
6373
+ fn = tc.function;
6374
+ if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
6035
6375
  ;
6036
6376
  computerCallIndices.add(tc.index);
6037
- initialArgs = (_ref = (_tc_function1 = tc.function) === null || _tc_function1 === void 0 ? void 0 : _tc_function1.arguments) !== null && _ref !== void 0 ? _ref : "";
6377
+ initialArgs = (_ref = fn === null || fn === void 0 ? void 0 : fn.arguments) !== null && _ref !== void 0 ? _ref : "";
6038
6378
  argumentBuffers.set(tc.index, initialArgs);
6039
6379
  if (initialArgs) {
6040
6380
  try {
@@ -6046,7 +6386,7 @@ var post10 = function(param) {
6046
6386
  model: model
6047
6387
  });
6048
6388
  passThrough.push(_object_spread_props(_object_spread({}, tc), {
6049
- function: _object_spread_props(_object_spread({}, tc.function), {
6389
+ function: _object_spread_props(_object_spread({}, fn), {
6050
6390
  arguments: denormalized
6051
6391
  })
6052
6392
  }));
@@ -6055,7 +6395,7 @@ var post10 = function(param) {
6055
6395
  } catch (unused) {}
6056
6396
  }
6057
6397
  passThrough.push(_object_spread_props(_object_spread({}, tc), {
6058
- function: _object_spread_props(_object_spread({}, tc.function), {
6398
+ function: _object_spread_props(_object_spread({}, fn), {
6059
6399
  arguments: ""
6060
6400
  })
6061
6401
  }));
@@ -6063,8 +6403,7 @@ var post10 = function(param) {
6063
6403
  }
6064
6404
  if (computerCallIndices.has(tc.index)) {
6065
6405
  ;
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 : "");
6406
+ 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
6407
  argumentBuffers.set(tc.index, buf);
6069
6408
  if (!emittedIndices.has(tc.index)) {
6070
6409
  try {
@@ -6106,7 +6445,7 @@ var post10 = function(param) {
6106
6445
  modifiedChunk = _object_spread_props(_object_spread({}, chunk), {
6107
6446
  choices: [
6108
6447
  _object_spread_props(_object_spread({}, choice), {
6109
- delta: _object_spread_props(_object_spread({}, choice.delta), {
6448
+ delta: _object_spread_props(_object_spread({}, delta), {
6110
6449
  tool_calls: passThrough
6111
6450
  })
6112
6451
  })
@@ -6226,7 +6565,7 @@ var post10 = function(param) {
6226
6565
  });
6227
6566
  return [
6228
6567
  2,
6229
- new Response(stream, {
6568
+ new Response(readableStream, {
6230
6569
  headers: {
6231
6570
  "Content-Type": "text/event-stream"
6232
6571
  }
@@ -6235,15 +6574,33 @@ var post10 = function(param) {
6235
6574
  case 2:
6236
6575
  _state.trys.push([
6237
6576
  2,
6238
- 4,
6577
+ 5,
6239
6578
  ,
6240
- 5
6579
+ 6
6241
6580
  ]);
6242
6581
  return [
6243
6582
  4,
6244
- openRouter.chat.completions.create(resultOptions)
6583
+ rawFetch(openRouter, resultOptions)
6245
6584
  ];
6246
6585
  case 3:
6586
+ response1 = _state.sent();
6587
+ if (!response1.ok) {
6588
+ ;
6589
+ return [
6590
+ 2,
6591
+ new Response(response1.body, {
6592
+ status: response1.status,
6593
+ headers: {
6594
+ "Content-Type": (_response_headers_get1 = response1.headers.get("Content-Type")) !== null && _response_headers_get1 !== void 0 ? _response_headers_get1 : "application/json"
6595
+ }
6596
+ })
6597
+ ];
6598
+ }
6599
+ return [
6600
+ 4,
6601
+ response1.json()
6602
+ ];
6603
+ case 4:
6247
6604
  data = _state.sent();
6248
6605
  if (computerUseConfig) {
6249
6606
  ;
@@ -6252,10 +6609,11 @@ var post10 = function(param) {
6252
6609
  for(_iterator = ((_data_choices = data.choices) !== null && _data_choices !== void 0 ? _data_choices : [])[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6253
6610
  choice = _step.value;
6254
6611
  ;
6255
- ;
6612
+ message = choice.message;
6613
+ toolCalls = (_ref = message === null || message === void 0 ? void 0 : message.tool_calls) !== null && _ref !== void 0 ? _ref : [];
6256
6614
  _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
6257
6615
  try {
6258
- for(_iterator1 = ((_ref = (_choice_message = choice.message) === null || _choice_message === void 0 ? void 0 : _choice_message.tool_calls) !== null && _ref !== void 0 ? _ref : [])[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
6616
+ for(_iterator1 = toolCalls[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
6259
6617
  tc = _step1.value;
6260
6618
  fn = tc.function;
6261
6619
  if ((fn === null || fn === void 0 ? void 0 : fn.name) === "computer_call") {
@@ -6303,9 +6661,9 @@ var post10 = function(param) {
6303
6661
  try {
6304
6662
  for(_iterator2 = ((_data_choices1 = data.choices) !== null && _data_choices1 !== void 0 ? _data_choices1 : [])[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
6305
6663
  choice1 = _step2.value;
6306
- ;
6307
- if ((_choice_message1 = choice1.message) === null || _choice_message1 === void 0 ? void 0 : _choice_message1.content) {
6308
- choice1.message.content = sanitizeContent(choice1.message.content);
6664
+ message1 = choice1.message;
6665
+ if ((message1 === null || message1 === void 0 ? void 0 : message1.content) && typeof message1.content === "string") {
6666
+ message1.content = sanitizeContent(message1.content);
6309
6667
  }
6310
6668
  }
6311
6669
  } catch (err) {
@@ -6332,7 +6690,7 @@ var post10 = function(param) {
6332
6690
  }
6333
6691
  })
6334
6692
  ];
6335
- case 4:
6693
+ case 5:
6336
6694
  error = _state.sent();
6337
6695
  return [
6338
6696
  2,
@@ -6345,7 +6703,7 @@ var post10 = function(param) {
6345
6703
  }
6346
6704
  })
6347
6705
  ];
6348
- case 5:
6706
+ case 6:
6349
6707
  return [
6350
6708
  2
6351
6709
  ];
@@ -6356,16 +6714,17 @@ var post10 = function(param) {
6356
6714
  };
6357
6715
  // src/adapters/client/openRouterClientAdapter/completions/index.ts
6358
6716
  var completions10 = function(param) {
6359
- var openRouter = param.openRouter;
6717
+ var openRouter = param.openRouter, provider = param.provider;
6360
6718
  return {
6361
6719
  post: post10({
6362
- openRouter: openRouter
6720
+ openRouter: openRouter,
6721
+ provider: provider
6363
6722
  })
6364
6723
  };
6365
6724
  };
6366
6725
  // src/adapters/client/openRouterClientAdapter/index.ts
6367
6726
  var openRouterClientAdapter = function(param) {
6368
- var openRouter = param.openRouter;
6727
+ var openRouter = param.openRouter, provider = param.provider;
6369
6728
  return {
6370
6729
  client: openRouter,
6371
6730
  requestHandlers: {
@@ -6373,7 +6732,8 @@ var openRouterClientAdapter = function(param) {
6373
6732
  openRouter: openRouter
6374
6733
  }),
6375
6734
  "^/(?:v1|/?openai)/chat/completions$": completions10({
6376
- openRouter: openRouter
6735
+ openRouter: openRouter,
6736
+ provider: provider
6377
6737
  })
6378
6738
  }
6379
6739
  };