@vibedeckx/linux-x64 0.3.4 → 0.3.6

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.
Files changed (2) hide show
  1. package/dist/bin.js +1215 -1019
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -16572,44 +16572,44 @@ var require_base64 = __commonJS({
16572
16572
  s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
16573
16573
  var i;
16574
16574
  base643.encode = function encode3(buffer, start, end) {
16575
- var parts = null, chunk = [];
16575
+ var parts = null, chunk2 = [];
16576
16576
  var i2 = 0, j = 0, t;
16577
16577
  while (start < end) {
16578
16578
  var b2 = buffer[start++];
16579
16579
  switch (j) {
16580
16580
  case 0:
16581
- chunk[i2++] = b64[b2 >> 2];
16581
+ chunk2[i2++] = b64[b2 >> 2];
16582
16582
  t = (b2 & 3) << 4;
16583
16583
  j = 1;
16584
16584
  break;
16585
16585
  case 1:
16586
- chunk[i2++] = b64[t | b2 >> 4];
16586
+ chunk2[i2++] = b64[t | b2 >> 4];
16587
16587
  t = (b2 & 15) << 2;
16588
16588
  j = 2;
16589
16589
  break;
16590
16590
  case 2:
16591
- chunk[i2++] = b64[t | b2 >> 6];
16592
- chunk[i2++] = b64[b2 & 63];
16591
+ chunk2[i2++] = b64[t | b2 >> 6];
16592
+ chunk2[i2++] = b64[b2 & 63];
16593
16593
  j = 0;
16594
16594
  break;
16595
16595
  }
16596
16596
  if (i2 > 8191) {
16597
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
16597
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk2));
16598
16598
  i2 = 0;
16599
16599
  }
16600
16600
  }
16601
16601
  if (j) {
16602
- chunk[i2++] = b64[t];
16603
- chunk[i2++] = 61;
16602
+ chunk2[i2++] = b64[t];
16603
+ chunk2[i2++] = 61;
16604
16604
  if (j === 1)
16605
- chunk[i2++] = 61;
16605
+ chunk2[i2++] = 61;
16606
16606
  }
16607
16607
  if (parts) {
16608
16608
  if (i2)
16609
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i2)));
16609
+ parts.push(String.fromCharCode.apply(String, chunk2.slice(0, i2)));
16610
16610
  return parts.join("");
16611
16611
  }
16612
- return String.fromCharCode.apply(String, chunk.slice(0, i2));
16612
+ return String.fromCharCode.apply(String, chunk2.slice(0, i2));
16613
16613
  };
16614
16614
  var invalidEncoding = "invalid encoding";
16615
16615
  base643.decode = function decode3(string4, buffer, offset) {
@@ -25600,15 +25600,15 @@ function sendWithHttp(request, url2, headers, compression, userAgent, agent, dat
25600
25600
  const req = request(options, (res) => {
25601
25601
  const responseData = [];
25602
25602
  let responseSize = 0;
25603
- res.on("data", (chunk) => {
25604
- responseSize += chunk.length;
25603
+ res.on("data", (chunk2) => {
25604
+ responseSize += chunk2.length;
25605
25605
  if (responseSize > MAX_RESPONSE_BODY_SIZE) {
25606
25606
  const sizeError = new Error(`OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`);
25607
25607
  resolve3({ status: "failure", error: sizeError });
25608
25608
  res.destroy();
25609
25609
  return;
25610
25610
  }
25611
- responseData.push(chunk);
25611
+ responseData.push(chunk2);
25612
25612
  });
25613
25613
  res.on("end", () => {
25614
25614
  if (res.statusCode && res.statusCode <= 299) {
@@ -29501,7 +29501,7 @@ ${callerStack}`;
29501
29501
  var _a26, _b18;
29502
29502
  return (_b18 = (_a26 = this.call) === null || _a26 === void 0 ? void 0 : _a26.getAuthContext()) !== null && _b18 !== void 0 ? _b18 : null;
29503
29503
  }
29504
- _write(chunk, encoding, cb) {
29504
+ _write(chunk2, encoding, cb) {
29505
29505
  var _a26;
29506
29506
  const context2 = {
29507
29507
  callback: cb
@@ -29510,7 +29510,7 @@ ${callerStack}`;
29510
29510
  if (!Number.isNaN(flags)) {
29511
29511
  context2.flags = flags;
29512
29512
  }
29513
- (_a26 = this.call) === null || _a26 === void 0 ? void 0 : _a26.sendMessageWithContext(context2, chunk);
29513
+ (_a26 = this.call) === null || _a26 === void 0 ? void 0 : _a26.sendMessageWithContext(context2, chunk2);
29514
29514
  }
29515
29515
  _final(cb) {
29516
29516
  var _a26;
@@ -29541,7 +29541,7 @@ ${callerStack}`;
29541
29541
  var _a26;
29542
29542
  (_a26 = this.call) === null || _a26 === void 0 ? void 0 : _a26.startRead();
29543
29543
  }
29544
- _write(chunk, encoding, cb) {
29544
+ _write(chunk2, encoding, cb) {
29545
29545
  var _a26;
29546
29546
  const context2 = {
29547
29547
  callback: cb
@@ -29550,7 +29550,7 @@ ${callerStack}`;
29550
29550
  if (!Number.isNaN(flags)) {
29551
29551
  context2.flags = flags;
29552
29552
  }
29553
- (_a26 = this.call) === null || _a26 === void 0 ? void 0 : _a26.sendMessageWithContext(context2, chunk);
29553
+ (_a26 = this.call) === null || _a26 === void 0 ? void 0 : _a26.sendMessageWithContext(context2, chunk2);
29554
29554
  }
29555
29555
  _final(cb) {
29556
29556
  var _a26;
@@ -40112,9 +40112,9 @@ var require_compression_filter = __commonJS({
40112
40112
  let totalLength = 0;
40113
40113
  const messageParts = [];
40114
40114
  const decompresser = zlib2.createInflate();
40115
- decompresser.on("data", (chunk) => {
40116
- messageParts.push(chunk);
40117
- totalLength += chunk.byteLength;
40115
+ decompresser.on("data", (chunk2) => {
40116
+ messageParts.push(chunk2);
40117
+ totalLength += chunk2.byteLength;
40118
40118
  if (this.maxRecvMessageLength !== -1 && totalLength > this.maxRecvMessageLength) {
40119
40119
  decompresser.destroy();
40120
40120
  reject({
@@ -40152,9 +40152,9 @@ var require_compression_filter = __commonJS({
40152
40152
  let totalLength = 0;
40153
40153
  const messageParts = [];
40154
40154
  const decompresser = zlib2.createGunzip();
40155
- decompresser.on("data", (chunk) => {
40156
- messageParts.push(chunk);
40157
- totalLength += chunk.byteLength;
40155
+ decompresser.on("data", (chunk2) => {
40156
+ messageParts.push(chunk2);
40157
+ totalLength += chunk2.byteLength;
40158
40158
  if (this.maxRecvMessageLength !== -1 && totalLength > this.maxRecvMessageLength) {
40159
40159
  decompresser.destroy();
40160
40160
  reject({
@@ -44598,8 +44598,8 @@ var require_server_call = __commonJS({
44598
44598
  getMetricsRecorder() {
44599
44599
  return this.call.getMetricsRecorder();
44600
44600
  }
44601
- _write(chunk, encoding, callback) {
44602
- this.call.sendMessage(chunk, callback);
44601
+ _write(chunk2, encoding, callback) {
44602
+ this.call.sendMessage(chunk2, callback);
44603
44603
  }
44604
44604
  _final(callback) {
44605
44605
  var _a26;
@@ -44656,8 +44656,8 @@ var require_server_call = __commonJS({
44656
44656
  _read(size) {
44657
44657
  this.call.startRead();
44658
44658
  }
44659
- _write(chunk, encoding, callback) {
44660
- this.call.sendMessage(chunk, callback);
44659
+ _write(chunk2, encoding, callback) {
44660
+ this.call.sendMessage(chunk2, callback);
44661
44661
  }
44662
44662
  _final(callback) {
44663
44663
  var _a26;
@@ -45810,9 +45810,9 @@ var require_server_interceptors = __commonJS({
45810
45810
  return new Promise((resolve3, reject) => {
45811
45811
  let totalLength = 0;
45812
45812
  const messageParts = [];
45813
- decompresser.on("data", (chunk) => {
45814
- messageParts.push(chunk);
45815
- totalLength += chunk.byteLength;
45813
+ decompresser.on("data", (chunk2) => {
45814
+ messageParts.push(chunk2);
45815
+ totalLength += chunk2.byteLength;
45816
45816
  if (this.maxReceiveMessageSize !== -1 && totalLength > this.maxReceiveMessageSize) {
45817
45817
  decompresser.destroy();
45818
45818
  reject({
@@ -50761,8 +50761,8 @@ var require_util4 = __commonJS({
50761
50761
  const { request } = url2.protocol === "http:" ? http : https;
50762
50762
  const req = request(url2, reqOpts, (res) => {
50763
50763
  let rawData = "";
50764
- res.on("data", (chunk) => {
50765
- rawData += chunk;
50764
+ res.on("data", (chunk2) => {
50765
+ rawData += chunk2;
50766
50766
  });
50767
50767
  res.on("end", () => {
50768
50768
  const statusCode = res.statusCode || 0;
@@ -74262,8 +74262,8 @@ var require_content_type_parser = __commonJS({
74262
74262
  payload.on("end", onEnd);
74263
74263
  payload.on("error", onEnd);
74264
74264
  payload.resume();
74265
- function onData(chunk) {
74266
- receivedLength += asString ? Buffer.byteLength(chunk) : chunk.length;
74265
+ function onData(chunk2) {
74266
+ receivedLength += asString ? Buffer.byteLength(chunk2) : chunk2.length;
74267
74267
  const { receivedEncodedLength = 0 } = payload;
74268
74268
  if (receivedLength > limit || receivedEncodedLength > limit) {
74269
74269
  payload.removeListener("data", onData);
@@ -74273,9 +74273,9 @@ var require_content_type_parser = __commonJS({
74273
74273
  return;
74274
74274
  }
74275
74275
  if (asString) {
74276
- body += chunk;
74276
+ body += chunk2;
74277
74277
  } else {
74278
- body.push(chunk);
74278
+ body.push(chunk2);
74279
74279
  }
74280
74280
  }
74281
74281
  function onEnd(err) {
@@ -78513,8 +78513,8 @@ var require_core = __commonJS({
78513
78513
  return this;
78514
78514
  }
78515
78515
  case "object": {
78516
- const cacheKey = schemaKeyRef;
78517
- this._cache.delete(cacheKey);
78516
+ const cacheKey2 = schemaKeyRef;
78517
+ this._cache.delete(cacheKey2);
78518
78518
  let id = schemaKeyRef[this.opts.schemaId];
78519
78519
  if (id) {
78520
78520
  id = (0, resolve_1.normalizeId)(id);
@@ -93993,10 +93993,10 @@ var require_request2 = __commonJS({
93993
93993
  const payload = this._lightMyRequest.payload;
93994
93994
  let more = true;
93995
93995
  let pushed = false;
93996
- let chunk;
93997
- while (more && (chunk = payload.read())) {
93996
+ let chunk2;
93997
+ while (more && (chunk2 = payload.read())) {
93998
93998
  pushed = true;
93999
- more = this.push(chunk);
93999
+ more = this.push(chunk2);
94000
94000
  }
94001
94001
  if (more && !pushed) {
94002
94002
  this._lightMyRequest.payload.once("readable", this._read.bind(this));
@@ -95275,7 +95275,7 @@ var require_light_my_request = __commonJS({
95275
95275
  return next();
95276
95276
  }
95277
95277
  const chunks = [];
95278
- payload.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
95278
+ payload.on("data", (chunk2) => chunks.push(Buffer.from(chunk2)));
95279
95279
  payload.on("end", () => {
95280
95280
  const payload2 = Buffer.concat(chunks);
95281
95281
  req.headers["content-length"] = req.headers["content-length"] || "" + payload2.length;
@@ -99527,7 +99527,7 @@ var require_commonjs5 = __commonJS({
99527
99527
  */
99528
99528
  set aborted(_3) {
99529
99529
  }
99530
- write(chunk, encoding, cb) {
99530
+ write(chunk2, encoding, cb) {
99531
99531
  if (this[ABORTED2])
99532
99532
  return false;
99533
99533
  if (this[EOF])
@@ -99543,12 +99543,12 @@ var require_commonjs5 = __commonJS({
99543
99543
  if (!encoding)
99544
99544
  encoding = "utf8";
99545
99545
  const fn = this[ASYNC] ? defer : nodefer;
99546
- if (!this[OBJECTMODE] && !Buffer.isBuffer(chunk)) {
99547
- if (isArrayBufferView(chunk)) {
99548
- chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
99549
- } else if (isArrayBufferLike(chunk)) {
99550
- chunk = Buffer.from(chunk);
99551
- } else if (typeof chunk !== "string") {
99546
+ if (!this[OBJECTMODE] && !Buffer.isBuffer(chunk2)) {
99547
+ if (isArrayBufferView(chunk2)) {
99548
+ chunk2 = Buffer.from(chunk2.buffer, chunk2.byteOffset, chunk2.byteLength);
99549
+ } else if (isArrayBufferLike(chunk2)) {
99550
+ chunk2 = Buffer.from(chunk2);
99551
+ } else if (typeof chunk2 !== "string") {
99552
99552
  throw new Error("Non-contiguous data written to non-objectMode stream");
99553
99553
  }
99554
99554
  }
@@ -99556,35 +99556,35 @@ var require_commonjs5 = __commonJS({
99556
99556
  if (this[FLOWING] && this[BUFFERLENGTH] !== 0)
99557
99557
  this[FLUSH](true);
99558
99558
  if (this[FLOWING])
99559
- this.emit("data", chunk);
99559
+ this.emit("data", chunk2);
99560
99560
  else
99561
- this[BUFFERPUSH](chunk);
99561
+ this[BUFFERPUSH](chunk2);
99562
99562
  if (this[BUFFERLENGTH] !== 0)
99563
99563
  this.emit("readable");
99564
99564
  if (cb)
99565
99565
  fn(cb);
99566
99566
  return this[FLOWING];
99567
99567
  }
99568
- if (!chunk.length) {
99568
+ if (!chunk2.length) {
99569
99569
  if (this[BUFFERLENGTH] !== 0)
99570
99570
  this.emit("readable");
99571
99571
  if (cb)
99572
99572
  fn(cb);
99573
99573
  return this[FLOWING];
99574
99574
  }
99575
- if (typeof chunk === "string" && // unless it is a string already ready for us to use
99575
+ if (typeof chunk2 === "string" && // unless it is a string already ready for us to use
99576
99576
  !(encoding === this[ENCODING] && !this[DECODER]?.lastNeed)) {
99577
- chunk = Buffer.from(chunk, encoding);
99577
+ chunk2 = Buffer.from(chunk2, encoding);
99578
99578
  }
99579
- if (Buffer.isBuffer(chunk) && this[ENCODING]) {
99580
- chunk = this[DECODER].write(chunk);
99579
+ if (Buffer.isBuffer(chunk2) && this[ENCODING]) {
99580
+ chunk2 = this[DECODER].write(chunk2);
99581
99581
  }
99582
99582
  if (this[FLOWING] && this[BUFFERLENGTH] !== 0)
99583
99583
  this[FLUSH](true);
99584
99584
  if (this[FLOWING])
99585
- this.emit("data", chunk);
99585
+ this.emit("data", chunk2);
99586
99586
  else
99587
- this[BUFFERPUSH](chunk);
99587
+ this[BUFFERPUSH](chunk2);
99588
99588
  if (this[BUFFERLENGTH] !== 0)
99589
99589
  this.emit("readable");
99590
99590
  if (cb)
@@ -99623,39 +99623,39 @@ var require_commonjs5 = __commonJS({
99623
99623
  this[MAYBE_EMIT_END]();
99624
99624
  return ret;
99625
99625
  }
99626
- [READ](n, chunk) {
99626
+ [READ](n, chunk2) {
99627
99627
  if (this[OBJECTMODE])
99628
99628
  this[BUFFERSHIFT]();
99629
99629
  else {
99630
- const c = chunk;
99630
+ const c = chunk2;
99631
99631
  if (n === c.length || n === null)
99632
99632
  this[BUFFERSHIFT]();
99633
99633
  else if (typeof c === "string") {
99634
99634
  this[BUFFER][0] = c.slice(n);
99635
- chunk = c.slice(0, n);
99635
+ chunk2 = c.slice(0, n);
99636
99636
  this[BUFFERLENGTH] -= n;
99637
99637
  } else {
99638
99638
  this[BUFFER][0] = c.subarray(n);
99639
- chunk = c.subarray(0, n);
99639
+ chunk2 = c.subarray(0, n);
99640
99640
  this[BUFFERLENGTH] -= n;
99641
99641
  }
99642
99642
  }
99643
- this.emit("data", chunk);
99643
+ this.emit("data", chunk2);
99644
99644
  if (!this[BUFFER].length && !this[EOF])
99645
99645
  this.emit("drain");
99646
- return chunk;
99646
+ return chunk2;
99647
99647
  }
99648
- end(chunk, encoding, cb) {
99649
- if (typeof chunk === "function") {
99650
- cb = chunk;
99651
- chunk = void 0;
99648
+ end(chunk2, encoding, cb) {
99649
+ if (typeof chunk2 === "function") {
99650
+ cb = chunk2;
99651
+ chunk2 = void 0;
99652
99652
  }
99653
99653
  if (typeof encoding === "function") {
99654
99654
  cb = encoding;
99655
99655
  encoding = "utf8";
99656
99656
  }
99657
- if (chunk !== void 0)
99658
- this.write(chunk, encoding);
99657
+ if (chunk2 !== void 0)
99658
+ this.write(chunk2, encoding);
99659
99659
  if (cb)
99660
99660
  this.once("end", cb);
99661
99661
  this[EOF] = true;
@@ -99720,12 +99720,12 @@ var require_commonjs5 = __commonJS({
99720
99720
  get paused() {
99721
99721
  return this[PAUSED];
99722
99722
  }
99723
- [BUFFERPUSH](chunk) {
99723
+ [BUFFERPUSH](chunk2) {
99724
99724
  if (this[OBJECTMODE])
99725
99725
  this[BUFFERLENGTH] += 1;
99726
99726
  else
99727
- this[BUFFERLENGTH] += chunk.length;
99728
- this[BUFFER].push(chunk);
99727
+ this[BUFFERLENGTH] += chunk2.length;
99728
+ this[BUFFER].push(chunk2);
99729
99729
  }
99730
99730
  [BUFFERSHIFT]() {
99731
99731
  if (this[OBJECTMODE])
@@ -99740,8 +99740,8 @@ var require_commonjs5 = __commonJS({
99740
99740
  if (!noDrain && !this[BUFFER].length && !this[EOF])
99741
99741
  this.emit("drain");
99742
99742
  }
99743
- [FLUSHCHUNK](chunk) {
99744
- this.emit("data", chunk);
99743
+ [FLUSHCHUNK](chunk2) {
99744
+ this.emit("data", chunk2);
99745
99745
  return this[FLOWING];
99746
99746
  }
99747
99747
  /**
@@ -106259,14 +106259,14 @@ var require_permessage_deflate = __commonJS({
106259
106259
  }
106260
106260
  };
106261
106261
  module.exports = PerMessageDeflate;
106262
- function deflateOnData(chunk) {
106263
- this[kBuffers].push(chunk);
106264
- this[kTotalLength] += chunk.length;
106262
+ function deflateOnData(chunk2) {
106263
+ this[kBuffers].push(chunk2);
106264
+ this[kTotalLength] += chunk2.length;
106265
106265
  }
106266
- function inflateOnData(chunk) {
106267
- this[kTotalLength] += chunk.length;
106266
+ function inflateOnData(chunk2) {
106267
+ this[kTotalLength] += chunk2.length;
106268
106268
  if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
106269
- this[kBuffers].push(chunk);
106269
+ this[kBuffers].push(chunk2);
106270
106270
  return;
106271
106271
  }
106272
106272
  this[kError] = new RangeError("Max payload size exceeded");
@@ -106560,10 +106560,10 @@ var require_receiver = __commonJS({
106560
106560
  * @param {Function} cb Callback
106561
106561
  * @private
106562
106562
  */
106563
- _write(chunk, encoding, cb) {
106563
+ _write(chunk2, encoding, cb) {
106564
106564
  if (this._opcode === 8 && this._state == GET_INFO) return cb();
106565
- this._bufferedBytes += chunk.length;
106566
- this._buffers.push(chunk);
106565
+ this._bufferedBytes += chunk2.length;
106566
+ this._buffers.push(chunk2);
106567
106567
  this.startLoop(cb);
106568
106568
  }
106569
106569
  /**
@@ -107959,7 +107959,7 @@ var require_websocket = __commonJS({
107959
107959
  var http = __require("http");
107960
107960
  var net2 = __require("net");
107961
107961
  var tls = __require("tls");
107962
- var { randomBytes: randomBytes3, createHash: createHash8 } = __require("crypto");
107962
+ var { randomBytes: randomBytes3, createHash: createHash9 } = __require("crypto");
107963
107963
  var { Duplex, Readable: Readable4 } = __require("stream");
107964
107964
  var { URL: URL2 } = __require("url");
107965
107965
  var PerMessageDeflate = require_permessage_deflate();
@@ -108619,7 +108619,7 @@ var require_websocket = __commonJS({
108619
108619
  abortHandshake(websocket, socket, "Invalid Upgrade header");
108620
108620
  return;
108621
108621
  }
108622
- const digest = createHash8("sha1").update(key + GUID).digest("base64");
108622
+ const digest = createHash9("sha1").update(key + GUID).digest("base64");
108623
108623
  if (res.headers["sec-websocket-accept"] !== digest) {
108624
108624
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
108625
108625
  return;
@@ -108800,8 +108800,8 @@ var require_websocket = __commonJS({
108800
108800
  this.removeListener("end", socketOnEnd);
108801
108801
  websocket._readyState = WebSocket2.CLOSING;
108802
108802
  if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
108803
- const chunk = this.read(this._readableState.length);
108804
- websocket._receiver.write(chunk);
108803
+ const chunk2 = this.read(this._readableState.length);
108804
+ websocket._receiver.write(chunk2);
108805
108805
  }
108806
108806
  websocket._receiver.end();
108807
108807
  this[kWebSocket] = void 0;
@@ -108813,8 +108813,8 @@ var require_websocket = __commonJS({
108813
108813
  websocket._receiver.on("finish", receiverOnFinish);
108814
108814
  }
108815
108815
  }
108816
- function socketOnData(chunk) {
108817
- if (!this[kWebSocket]._receiver.write(chunk)) {
108816
+ function socketOnData(chunk2) {
108817
+ if (!this[kWebSocket]._receiver.write(chunk2)) {
108818
108818
  this.pause();
108819
108819
  }
108820
108820
  }
@@ -108917,14 +108917,14 @@ var require_stream = __commonJS({
108917
108917
  duplex._read = function() {
108918
108918
  if (ws.isPaused) ws.resume();
108919
108919
  };
108920
- duplex._write = function(chunk, encoding, callback) {
108920
+ duplex._write = function(chunk2, encoding, callback) {
108921
108921
  if (ws.readyState === ws.CONNECTING) {
108922
108922
  ws.once("open", function open4() {
108923
- duplex._write(chunk, encoding, callback);
108923
+ duplex._write(chunk2, encoding, callback);
108924
108924
  });
108925
108925
  return;
108926
108926
  }
108927
- ws.send(chunk, callback);
108927
+ ws.send(chunk2, callback);
108928
108928
  };
108929
108929
  duplex.on("end", duplexOnEnd);
108930
108930
  duplex.on("error", duplexOnError);
@@ -108986,7 +108986,7 @@ var require_websocket_server = __commonJS({
108986
108986
  var EventEmitter3 = __require("events");
108987
108987
  var http = __require("http");
108988
108988
  var { Duplex } = __require("stream");
108989
- var { createHash: createHash8 } = __require("crypto");
108989
+ var { createHash: createHash9 } = __require("crypto");
108990
108990
  var extension = require_extension();
108991
108991
  var PerMessageDeflate = require_permessage_deflate();
108992
108992
  var subprotocol = require_subprotocol();
@@ -109287,7 +109287,7 @@ var require_websocket_server = __commonJS({
109287
109287
  );
109288
109288
  }
109289
109289
  if (this._state > RUNNING) return abortHandshake(socket, 503);
109290
- const digest = createHash8("sha1").update(key + GUID).digest("base64");
109290
+ const digest = createHash9("sha1").update(key + GUID).digest("base64");
109291
109291
  const headers = [
109292
109292
  "HTTP/1.1 101 Switching Protocols",
109293
109293
  "Upgrade: websocket",
@@ -109879,8 +109879,8 @@ var require_stream_writable = __commonJS({
109879
109879
  var Buffer3 = __require("buffer").Buffer;
109880
109880
  var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
109881
109881
  };
109882
- function _uint8ArrayToBuffer(chunk) {
109883
- return Buffer3.from(chunk);
109882
+ function _uint8ArrayToBuffer(chunk2) {
109883
+ return Buffer3.from(chunk2);
109884
109884
  }
109885
109885
  function _isUint8Array(obj) {
109886
109886
  return Buffer3.isBuffer(obj) || obj instanceof OurUint8Array;
@@ -109993,12 +109993,12 @@ var require_stream_writable = __commonJS({
109993
109993
  errorOrDestroy(stream, er);
109994
109994
  process.nextTick(cb, er);
109995
109995
  }
109996
- function validChunk(stream, state, chunk, cb) {
109996
+ function validChunk(stream, state, chunk2, cb) {
109997
109997
  var er;
109998
- if (chunk === null) {
109998
+ if (chunk2 === null) {
109999
109999
  er = new ERR_STREAM_NULL_VALUES();
110000
- } else if (typeof chunk !== "string" && !state.objectMode) {
110001
- er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk);
110000
+ } else if (typeof chunk2 !== "string" && !state.objectMode) {
110001
+ er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk2);
110002
110002
  }
110003
110003
  if (er) {
110004
110004
  errorOrDestroy(stream, er);
@@ -110007,12 +110007,12 @@ var require_stream_writable = __commonJS({
110007
110007
  }
110008
110008
  return true;
110009
110009
  }
110010
- Writable2.prototype.write = function(chunk, encoding, cb) {
110010
+ Writable2.prototype.write = function(chunk2, encoding, cb) {
110011
110011
  var state = this._writableState;
110012
110012
  var ret = false;
110013
- var isBuf = !state.objectMode && _isUint8Array(chunk);
110014
- if (isBuf && !Buffer3.isBuffer(chunk)) {
110015
- chunk = _uint8ArrayToBuffer(chunk);
110013
+ var isBuf = !state.objectMode && _isUint8Array(chunk2);
110014
+ if (isBuf && !Buffer3.isBuffer(chunk2)) {
110015
+ chunk2 = _uint8ArrayToBuffer(chunk2);
110016
110016
  }
110017
110017
  if (typeof encoding === "function") {
110018
110018
  cb = encoding;
@@ -110022,9 +110022,9 @@ var require_stream_writable = __commonJS({
110022
110022
  else if (!encoding) encoding = state.defaultEncoding;
110023
110023
  if (typeof cb !== "function") cb = nop;
110024
110024
  if (state.ending) writeAfterEnd(this, cb);
110025
- else if (isBuf || validChunk(this, state, chunk, cb)) {
110025
+ else if (isBuf || validChunk(this, state, chunk2, cb)) {
110026
110026
  state.pendingcb++;
110027
- ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
110027
+ ret = writeOrBuffer(this, state, isBuf, chunk2, encoding, cb);
110028
110028
  }
110029
110029
  return ret;
110030
110030
  };
@@ -110053,11 +110053,11 @@ var require_stream_writable = __commonJS({
110053
110053
  return this._writableState && this._writableState.getBuffer();
110054
110054
  }
110055
110055
  });
110056
- function decodeChunk(state, chunk, encoding) {
110057
- if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") {
110058
- chunk = Buffer3.from(chunk, encoding);
110056
+ function decodeChunk(state, chunk2, encoding) {
110057
+ if (!state.objectMode && state.decodeStrings !== false && typeof chunk2 === "string") {
110058
+ chunk2 = Buffer3.from(chunk2, encoding);
110059
110059
  }
110060
- return chunk;
110060
+ return chunk2;
110061
110061
  }
110062
110062
  Object.defineProperty(Writable2.prototype, "writableHighWaterMark", {
110063
110063
  // making it explicit this property is not enumerable
@@ -110068,23 +110068,23 @@ var require_stream_writable = __commonJS({
110068
110068
  return this._writableState.highWaterMark;
110069
110069
  }
110070
110070
  });
110071
- function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
110071
+ function writeOrBuffer(stream, state, isBuf, chunk2, encoding, cb) {
110072
110072
  if (!isBuf) {
110073
- var newChunk = decodeChunk(state, chunk, encoding);
110074
- if (chunk !== newChunk) {
110073
+ var newChunk = decodeChunk(state, chunk2, encoding);
110074
+ if (chunk2 !== newChunk) {
110075
110075
  isBuf = true;
110076
110076
  encoding = "buffer";
110077
- chunk = newChunk;
110077
+ chunk2 = newChunk;
110078
110078
  }
110079
110079
  }
110080
- var len = state.objectMode ? 1 : chunk.length;
110080
+ var len = state.objectMode ? 1 : chunk2.length;
110081
110081
  state.length += len;
110082
110082
  var ret = state.length < state.highWaterMark;
110083
110083
  if (!ret) state.needDrain = true;
110084
110084
  if (state.writing || state.corked) {
110085
110085
  var last = state.lastBufferedRequest;
110086
110086
  state.lastBufferedRequest = {
110087
- chunk,
110087
+ chunk: chunk2,
110088
110088
  encoding,
110089
110089
  isBuf,
110090
110090
  callback: cb,
@@ -110097,18 +110097,18 @@ var require_stream_writable = __commonJS({
110097
110097
  }
110098
110098
  state.bufferedRequestCount += 1;
110099
110099
  } else {
110100
- doWrite(stream, state, false, len, chunk, encoding, cb);
110100
+ doWrite(stream, state, false, len, chunk2, encoding, cb);
110101
110101
  }
110102
110102
  return ret;
110103
110103
  }
110104
- function doWrite(stream, state, writev, len, chunk, encoding, cb) {
110104
+ function doWrite(stream, state, writev, len, chunk2, encoding, cb) {
110105
110105
  state.writelen = len;
110106
110106
  state.writecb = cb;
110107
110107
  state.writing = true;
110108
110108
  state.sync = true;
110109
110109
  if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED("write"));
110110
- else if (writev) stream._writev(chunk, state.onwrite);
110111
- else stream._write(chunk, encoding, state.onwrite);
110110
+ else if (writev) stream._writev(chunk2, state.onwrite);
110111
+ else stream._write(chunk2, encoding, state.onwrite);
110112
110112
  state.sync = false;
110113
110113
  }
110114
110114
  function onwriteError(stream, state, sync, er, cb) {
@@ -110191,11 +110191,11 @@ var require_stream_writable = __commonJS({
110191
110191
  state.bufferedRequestCount = 0;
110192
110192
  } else {
110193
110193
  while (entry) {
110194
- var chunk = entry.chunk;
110194
+ var chunk2 = entry.chunk;
110195
110195
  var encoding = entry.encoding;
110196
110196
  var cb = entry.callback;
110197
- var len = state.objectMode ? 1 : chunk.length;
110198
- doWrite(stream, state, false, len, chunk, encoding, cb);
110197
+ var len = state.objectMode ? 1 : chunk2.length;
110198
+ doWrite(stream, state, false, len, chunk2, encoding, cb);
110199
110199
  entry = entry.next;
110200
110200
  state.bufferedRequestCount--;
110201
110201
  if (state.writing) {
@@ -110207,21 +110207,21 @@ var require_stream_writable = __commonJS({
110207
110207
  state.bufferedRequest = entry;
110208
110208
  state.bufferProcessing = false;
110209
110209
  }
110210
- Writable2.prototype._write = function(chunk, encoding, cb) {
110210
+ Writable2.prototype._write = function(chunk2, encoding, cb) {
110211
110211
  cb(new ERR_METHOD_NOT_IMPLEMENTED("_write()"));
110212
110212
  };
110213
110213
  Writable2.prototype._writev = null;
110214
- Writable2.prototype.end = function(chunk, encoding, cb) {
110214
+ Writable2.prototype.end = function(chunk2, encoding, cb) {
110215
110215
  var state = this._writableState;
110216
- if (typeof chunk === "function") {
110217
- cb = chunk;
110218
- chunk = null;
110216
+ if (typeof chunk2 === "function") {
110217
+ cb = chunk2;
110218
+ chunk2 = null;
110219
110219
  encoding = null;
110220
110220
  } else if (typeof encoding === "function") {
110221
110221
  cb = encoding;
110222
110222
  encoding = null;
110223
110223
  }
110224
- if (chunk !== null && chunk !== void 0) this.write(chunk, encoding);
110224
+ if (chunk2 !== null && chunk2 !== void 0) this.write(chunk2, encoding);
110225
110225
  if (state.corked) {
110226
110226
  state.corked = 1;
110227
110227
  this.uncork();
@@ -111067,8 +111067,8 @@ var require_stream_readable = __commonJS({
111067
111067
  var Buffer3 = __require("buffer").Buffer;
111068
111068
  var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
111069
111069
  };
111070
- function _uint8ArrayToBuffer(chunk) {
111071
- return Buffer3.from(chunk);
111070
+ function _uint8ArrayToBuffer(chunk2) {
111071
+ return Buffer3.from(chunk2);
111072
111072
  }
111073
111073
  function _isUint8Array(obj) {
111074
111074
  return Buffer3.isBuffer(obj) || obj instanceof OurUint8Array;
@@ -111172,14 +111172,14 @@ var require_stream_readable = __commonJS({
111172
111172
  Readable4.prototype._destroy = function(err, cb) {
111173
111173
  cb(err);
111174
111174
  };
111175
- Readable4.prototype.push = function(chunk, encoding) {
111175
+ Readable4.prototype.push = function(chunk2, encoding) {
111176
111176
  var state = this._readableState;
111177
111177
  var skipChunkCheck;
111178
111178
  if (!state.objectMode) {
111179
- if (typeof chunk === "string") {
111179
+ if (typeof chunk2 === "string") {
111180
111180
  encoding = encoding || state.defaultEncoding;
111181
111181
  if (encoding !== state.encoding) {
111182
- chunk = Buffer3.from(chunk, encoding);
111182
+ chunk2 = Buffer3.from(chunk2, encoding);
111183
111183
  encoding = "";
111184
111184
  }
111185
111185
  skipChunkCheck = true;
@@ -111187,29 +111187,29 @@ var require_stream_readable = __commonJS({
111187
111187
  } else {
111188
111188
  skipChunkCheck = true;
111189
111189
  }
111190
- return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
111190
+ return readableAddChunk(this, chunk2, encoding, false, skipChunkCheck);
111191
111191
  };
111192
- Readable4.prototype.unshift = function(chunk) {
111193
- return readableAddChunk(this, chunk, null, true, false);
111192
+ Readable4.prototype.unshift = function(chunk2) {
111193
+ return readableAddChunk(this, chunk2, null, true, false);
111194
111194
  };
111195
- function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
111196
- debug("readableAddChunk", chunk);
111195
+ function readableAddChunk(stream, chunk2, encoding, addToFront, skipChunkCheck) {
111196
+ debug("readableAddChunk", chunk2);
111197
111197
  var state = stream._readableState;
111198
- if (chunk === null) {
111198
+ if (chunk2 === null) {
111199
111199
  state.reading = false;
111200
111200
  onEofChunk(stream, state);
111201
111201
  } else {
111202
111202
  var er;
111203
- if (!skipChunkCheck) er = chunkInvalid(state, chunk);
111203
+ if (!skipChunkCheck) er = chunkInvalid(state, chunk2);
111204
111204
  if (er) {
111205
111205
  errorOrDestroy(stream, er);
111206
- } else if (state.objectMode || chunk && chunk.length > 0) {
111207
- if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer3.prototype) {
111208
- chunk = _uint8ArrayToBuffer(chunk);
111206
+ } else if (state.objectMode || chunk2 && chunk2.length > 0) {
111207
+ if (typeof chunk2 !== "string" && !state.objectMode && Object.getPrototypeOf(chunk2) !== Buffer3.prototype) {
111208
+ chunk2 = _uint8ArrayToBuffer(chunk2);
111209
111209
  }
111210
111210
  if (addToFront) {
111211
111211
  if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());
111212
- else addChunk(stream, state, chunk, true);
111212
+ else addChunk(stream, state, chunk2, true);
111213
111213
  } else if (state.ended) {
111214
111214
  errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
111215
111215
  } else if (state.destroyed) {
@@ -111217,11 +111217,11 @@ var require_stream_readable = __commonJS({
111217
111217
  } else {
111218
111218
  state.reading = false;
111219
111219
  if (state.decoder && !encoding) {
111220
- chunk = state.decoder.write(chunk);
111221
- if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);
111220
+ chunk2 = state.decoder.write(chunk2);
111221
+ if (state.objectMode || chunk2.length !== 0) addChunk(stream, state, chunk2, false);
111222
111222
  else maybeReadMore(stream, state);
111223
111223
  } else {
111224
- addChunk(stream, state, chunk, false);
111224
+ addChunk(stream, state, chunk2, false);
111225
111225
  }
111226
111226
  }
111227
111227
  } else if (!addToFront) {
@@ -111231,22 +111231,22 @@ var require_stream_readable = __commonJS({
111231
111231
  }
111232
111232
  return !state.ended && (state.length < state.highWaterMark || state.length === 0);
111233
111233
  }
111234
- function addChunk(stream, state, chunk, addToFront) {
111234
+ function addChunk(stream, state, chunk2, addToFront) {
111235
111235
  if (state.flowing && state.length === 0 && !state.sync) {
111236
111236
  state.awaitDrain = 0;
111237
- stream.emit("data", chunk);
111237
+ stream.emit("data", chunk2);
111238
111238
  } else {
111239
- state.length += state.objectMode ? 1 : chunk.length;
111240
- if (addToFront) state.buffer.unshift(chunk);
111241
- else state.buffer.push(chunk);
111239
+ state.length += state.objectMode ? 1 : chunk2.length;
111240
+ if (addToFront) state.buffer.unshift(chunk2);
111241
+ else state.buffer.push(chunk2);
111242
111242
  if (state.needReadable) emitReadable(stream);
111243
111243
  }
111244
111244
  maybeReadMore(stream, state);
111245
111245
  }
111246
- function chunkInvalid(state, chunk) {
111246
+ function chunkInvalid(state, chunk2) {
111247
111247
  var er;
111248
- if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== void 0 && !state.objectMode) {
111249
- er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk);
111248
+ if (!_isUint8Array(chunk2) && typeof chunk2 !== "string" && chunk2 !== void 0 && !state.objectMode) {
111249
+ er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk2);
111250
111250
  }
111251
111251
  return er;
111252
111252
  }
@@ -111355,10 +111355,10 @@ var require_stream_readable = __commonJS({
111355
111355
  debug("onEofChunk");
111356
111356
  if (state.ended) return;
111357
111357
  if (state.decoder) {
111358
- var chunk = state.decoder.end();
111359
- if (chunk && chunk.length) {
111360
- state.buffer.push(chunk);
111361
- state.length += state.objectMode ? 1 : chunk.length;
111358
+ var chunk2 = state.decoder.end();
111359
+ if (chunk2 && chunk2.length) {
111360
+ state.buffer.push(chunk2);
111361
+ state.length += state.objectMode ? 1 : chunk2.length;
111362
111362
  }
111363
111363
  }
111364
111364
  state.ended = true;
@@ -111462,9 +111462,9 @@ var require_stream_readable = __commonJS({
111462
111462
  if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
111463
111463
  }
111464
111464
  src.on("data", ondata);
111465
- function ondata(chunk) {
111465
+ function ondata(chunk2) {
111466
111466
  debug("ondata");
111467
- var ret = dest.write(chunk);
111467
+ var ret = dest.write(chunk2);
111468
111468
  debug("dest.write", ret);
111469
111469
  if (ret === false) {
111470
111470
  if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
@@ -111645,17 +111645,17 @@ var require_stream_readable = __commonJS({
111645
111645
  stream.on("end", function() {
111646
111646
  debug("wrapped end");
111647
111647
  if (state.decoder && !state.ended) {
111648
- var chunk = state.decoder.end();
111649
- if (chunk && chunk.length) _this.push(chunk);
111648
+ var chunk2 = state.decoder.end();
111649
+ if (chunk2 && chunk2.length) _this.push(chunk2);
111650
111650
  }
111651
111651
  _this.push(null);
111652
111652
  });
111653
- stream.on("data", function(chunk) {
111653
+ stream.on("data", function(chunk2) {
111654
111654
  debug("wrapped data");
111655
- if (state.decoder) chunk = state.decoder.write(chunk);
111656
- if (state.objectMode && (chunk === null || chunk === void 0)) return;
111657
- else if (!state.objectMode && (!chunk || !chunk.length)) return;
111658
- var ret = _this.push(chunk);
111655
+ if (state.decoder) chunk2 = state.decoder.write(chunk2);
111656
+ if (state.objectMode && (chunk2 === null || chunk2 === void 0)) return;
111657
+ else if (!state.objectMode && (!chunk2 || !chunk2.length)) return;
111658
+ var ret = _this.push(chunk2);
111659
111659
  if (!ret) {
111660
111660
  paused = true;
111661
111661
  stream.pause();
@@ -111844,17 +111844,17 @@ var require_stream_transform = __commonJS({
111844
111844
  done(this, null, null);
111845
111845
  }
111846
111846
  }
111847
- Transform.prototype.push = function(chunk, encoding) {
111847
+ Transform.prototype.push = function(chunk2, encoding) {
111848
111848
  this._transformState.needTransform = false;
111849
- return Duplex.prototype.push.call(this, chunk, encoding);
111849
+ return Duplex.prototype.push.call(this, chunk2, encoding);
111850
111850
  };
111851
- Transform.prototype._transform = function(chunk, encoding, cb) {
111851
+ Transform.prototype._transform = function(chunk2, encoding, cb) {
111852
111852
  cb(new ERR_METHOD_NOT_IMPLEMENTED("_transform()"));
111853
111853
  };
111854
- Transform.prototype._write = function(chunk, encoding, cb) {
111854
+ Transform.prototype._write = function(chunk2, encoding, cb) {
111855
111855
  var ts = this._transformState;
111856
111856
  ts.writecb = cb;
111857
- ts.writechunk = chunk;
111857
+ ts.writechunk = chunk2;
111858
111858
  ts.writeencoding = encoding;
111859
111859
  if (!ts.transforming) {
111860
111860
  var rs = this._readableState;
@@ -111897,8 +111897,8 @@ var require_stream_passthrough = __commonJS({
111897
111897
  if (!(this instanceof PassThrough)) return new PassThrough(options);
111898
111898
  Transform.call(this, options);
111899
111899
  }
111900
- PassThrough.prototype._transform = function(chunk, encoding, cb) {
111901
- cb(null, chunk);
111900
+ PassThrough.prototype._transform = function(chunk2, encoding, cb) {
111901
+ cb(null, chunk2);
111902
111902
  };
111903
111903
  }
111904
111904
  });
@@ -112441,13 +112441,13 @@ var require_websocket2 = __commonJS({
112441
112441
  clientStream.removeListener("data", onData);
112442
112442
  resolve3(ws);
112443
112443
  });
112444
- const onData = (chunk) => {
112445
- if (chunk.toString().includes("HTTP/1.1 101 Switching Protocols")) {
112444
+ const onData = (chunk2) => {
112445
+ if (chunk2.toString().includes("HTTP/1.1 101 Switching Protocols")) {
112446
112446
  ws._isServer = false;
112447
112447
  ws.setSocket(clientStream, head, { maxPayload: 0 });
112448
112448
  } else {
112449
112449
  clientStream.removeListener("data", onData);
112450
- const statusCode = Number(statusCodeReg.exec(chunk.toString())[1]);
112450
+ const statusCode = Number(statusCodeReg.exec(chunk2.toString())[1]);
112451
112451
  reject(new Error("Unexpected server response: " + statusCode));
112452
112452
  }
112453
112453
  };
@@ -112623,15 +112623,15 @@ var require_sbmh = __commonJS({
112623
112623
  this.matches = 0;
112624
112624
  this._bufpos = 0;
112625
112625
  };
112626
- SBMH.prototype.push = function(chunk, pos) {
112627
- if (!Buffer.isBuffer(chunk)) {
112628
- chunk = Buffer.from(chunk, "binary");
112626
+ SBMH.prototype.push = function(chunk2, pos) {
112627
+ if (!Buffer.isBuffer(chunk2)) {
112628
+ chunk2 = Buffer.from(chunk2, "binary");
112629
112629
  }
112630
- const chlen = chunk.length;
112630
+ const chlen = chunk2.length;
112631
112631
  this._bufpos = pos || 0;
112632
112632
  let r;
112633
112633
  while (r !== chlen && this.matches < this.maxMatches) {
112634
- r = this._sbmh_feed(chunk);
112634
+ r = this._sbmh_feed(chunk2);
112635
112635
  }
112636
112636
  return r;
112637
112637
  };
@@ -114067,8 +114067,8 @@ var require_multipart = __commonJS({
114067
114067
  checkFinished();
114068
114068
  });
114069
114069
  }
114070
- Multipart.prototype.write = function(chunk, cb) {
114071
- const r = this.parser.write(chunk);
114070
+ Multipart.prototype.write = function(chunk2, cb) {
114071
+ const r = this.parser.write(chunk2);
114072
114072
  if (r && !this._pause) {
114073
114073
  cb();
114074
114074
  } else {
@@ -114565,8 +114565,8 @@ var require_main = __commonJS({
114565
114565
  }
114566
114566
  throw new Error("Unsupported Content-Type.");
114567
114567
  };
114568
- Busboy.prototype._write = function(chunk, encoding, cb) {
114569
- this._parser.write(chunk, cb);
114568
+ Busboy.prototype._write = function(chunk2, encoding, cb) {
114569
+ this._parser.write(chunk2, cb);
114570
114570
  };
114571
114571
  module.exports = Busboy;
114572
114572
  module.exports.default = Busboy;
@@ -115308,8 +115308,8 @@ var require_multipart2 = __commonJS({
115308
115308
  }
115309
115309
  const fileChunks = [];
115310
115310
  let err;
115311
- for await (const chunk of this.file) {
115312
- fileChunks.push(chunk);
115311
+ for await (const chunk2 of this.file) {
115312
+ fileChunks.push(chunk2);
115313
115313
  if (throwFileSizeLimit && this.file.truncated) {
115314
115314
  err = new RequestFileTooLargeError();
115315
115315
  err.part = this;
@@ -118335,13 +118335,13 @@ var require_request3 = __commonJS({
118335
118335
  channels.create.publish({ request: this });
118336
118336
  }
118337
118337
  }
118338
- onBodySent(chunk) {
118338
+ onBodySent(chunk2) {
118339
118339
  if (channels.bodyChunkSent.hasSubscribers) {
118340
- channels.bodyChunkSent.publish({ request: this, chunk });
118340
+ channels.bodyChunkSent.publish({ request: this, chunk: chunk2 });
118341
118341
  }
118342
118342
  if (this[kHandler].onBodySent) {
118343
118343
  try {
118344
- return this[kHandler].onBodySent(chunk);
118344
+ return this[kHandler].onBodySent(chunk2);
118345
118345
  } catch (err) {
118346
118346
  this.abort(err);
118347
118347
  }
@@ -118384,14 +118384,14 @@ var require_request3 = __commonJS({
118384
118384
  this.abort(err);
118385
118385
  }
118386
118386
  }
118387
- onData(chunk) {
118387
+ onData(chunk2) {
118388
118388
  assert2(!this.aborted);
118389
118389
  assert2(!this.completed);
118390
118390
  if (channels.bodyChunkReceived.hasSubscribers) {
118391
- channels.bodyChunkReceived.publish({ request: this, chunk });
118391
+ channels.bodyChunkReceived.publish({ request: this, chunk: chunk2 });
118392
118392
  }
118393
118393
  try {
118394
- return this[kHandler].onData(chunk);
118394
+ return this[kHandler].onData(chunk2);
118395
118395
  } catch (err) {
118396
118396
  this.abort(err);
118397
118397
  return false;
@@ -121490,17 +121490,17 @@ var require_util8 = __commonJS({
121490
121490
  const bytes = [];
121491
121491
  let byteLength = 0;
121492
121492
  do {
121493
- const { done, value: chunk } = await reader.read();
121493
+ const { done, value: chunk2 } = await reader.read();
121494
121494
  if (done) {
121495
121495
  successSteps(Buffer.concat(bytes, byteLength));
121496
121496
  return;
121497
121497
  }
121498
- if (!isUint8Array(chunk)) {
121498
+ if (!isUint8Array(chunk2)) {
121499
121499
  failureSteps(new TypeError("Received non-Uint8Array chunk"));
121500
121500
  return;
121501
121501
  }
121502
- bytes.push(chunk);
121503
- byteLength += chunk.length;
121502
+ bytes.push(chunk2);
121503
+ byteLength += chunk2.length;
121504
121504
  } while (true);
121505
121505
  } catch (e) {
121506
121506
  failureSteps(e);
@@ -121606,18 +121606,18 @@ var require_util8 = __commonJS({
121606
121606
  super();
121607
121607
  this.#zlibOptions = zlibOptions;
121608
121608
  }
121609
- _transform(chunk, encoding, callback) {
121609
+ _transform(chunk2, encoding, callback) {
121610
121610
  if (!this._inflateStream) {
121611
- if (chunk.length === 0) {
121611
+ if (chunk2.length === 0) {
121612
121612
  callback();
121613
121613
  return;
121614
121614
  }
121615
- this._inflateStream = (chunk[0] & 15) === 8 ? zlib2.createInflate(this.#zlibOptions) : zlib2.createInflateRaw(this.#zlibOptions);
121615
+ this._inflateStream = (chunk2[0] & 15) === 8 ? zlib2.createInflate(this.#zlibOptions) : zlib2.createInflateRaw(this.#zlibOptions);
121616
121616
  this._inflateStream.on("data", this.push.bind(this));
121617
121617
  this._inflateStream.on("end", () => this.push(null));
121618
121618
  this._inflateStream.on("error", (err) => this.destroy(err));
121619
121619
  }
121620
- this._inflateStream.write(chunk, encoding, callback);
121620
+ this._inflateStream.write(chunk2, encoding, callback);
121621
121621
  }
121622
121622
  _final(callback) {
121623
121623
  if (this._inflateStream) {
@@ -122352,29 +122352,29 @@ Content-Disposition: form-data`;
122352
122352
  let hasUnknownSizeValue = false;
122353
122353
  for (const [name25, value] of object3) {
122354
122354
  if (typeof value === "string") {
122355
- const chunk2 = textEncoder.encode(prefix + `; name="${formdataEscape(normalizeLinefeeds(name25))}"\r
122355
+ const chunk3 = textEncoder.encode(prefix + `; name="${formdataEscape(normalizeLinefeeds(name25))}"\r
122356
122356
  \r
122357
122357
  ${normalizeLinefeeds(value)}\r
122358
122358
  `);
122359
- blobParts.push(chunk2);
122360
- length += chunk2.byteLength;
122359
+ blobParts.push(chunk3);
122360
+ length += chunk3.byteLength;
122361
122361
  } else {
122362
- const chunk2 = textEncoder.encode(`${prefix}; name="${formdataEscape(normalizeLinefeeds(name25))}"` + (value.name ? `; filename="${formdataEscape(value.name)}"` : "") + `\r
122362
+ const chunk3 = textEncoder.encode(`${prefix}; name="${formdataEscape(normalizeLinefeeds(name25))}"` + (value.name ? `; filename="${formdataEscape(value.name)}"` : "") + `\r
122363
122363
  Content-Type: ${value.type || "application/octet-stream"}\r
122364
122364
  \r
122365
122365
  `);
122366
- blobParts.push(chunk2, value, rn);
122366
+ blobParts.push(chunk3, value, rn);
122367
122367
  if (typeof value.size === "number") {
122368
- length += chunk2.byteLength + value.size + rn.byteLength;
122368
+ length += chunk3.byteLength + value.size + rn.byteLength;
122369
122369
  } else {
122370
122370
  hasUnknownSizeValue = true;
122371
122371
  }
122372
122372
  }
122373
122373
  }
122374
- const chunk = textEncoder.encode(`--${boundary}--\r
122374
+ const chunk2 = textEncoder.encode(`--${boundary}--\r
122375
122375
  `);
122376
- blobParts.push(chunk);
122377
- length += chunk.byteLength;
122376
+ blobParts.push(chunk2);
122377
+ length += chunk2.byteLength;
122378
122378
  if (hasUnknownSizeValue) {
122379
122379
  length = null;
122380
122380
  }
@@ -122801,41 +122801,41 @@ var require_client_h1 = __commonJS({
122801
122801
  }
122802
122802
  readMore() {
122803
122803
  while (!this.paused && this.ptr) {
122804
- const chunk = this.socket.read();
122805
- if (chunk === null) {
122804
+ const chunk2 = this.socket.read();
122805
+ if (chunk2 === null) {
122806
122806
  break;
122807
122807
  }
122808
- this.execute(chunk);
122808
+ this.execute(chunk2);
122809
122809
  }
122810
122810
  }
122811
122811
  /**
122812
122812
  * @param {Buffer} chunk
122813
122813
  */
122814
- execute(chunk) {
122814
+ execute(chunk2) {
122815
122815
  assert2(currentParser === null);
122816
122816
  assert2(this.ptr != null);
122817
122817
  assert2(!this.paused);
122818
122818
  const { socket, llhttp } = this;
122819
- if (chunk.length > currentBufferSize) {
122819
+ if (chunk2.length > currentBufferSize) {
122820
122820
  if (currentBufferPtr) {
122821
122821
  llhttp.free(currentBufferPtr);
122822
122822
  }
122823
- currentBufferSize = Math.ceil(chunk.length / 4096) * 4096;
122823
+ currentBufferSize = Math.ceil(chunk2.length / 4096) * 4096;
122824
122824
  currentBufferPtr = llhttp.malloc(currentBufferSize);
122825
122825
  }
122826
- new Uint8Array(llhttp.memory.buffer, currentBufferPtr, currentBufferSize).set(chunk);
122826
+ new Uint8Array(llhttp.memory.buffer, currentBufferPtr, currentBufferSize).set(chunk2);
122827
122827
  try {
122828
122828
  let ret;
122829
122829
  try {
122830
- currentBufferRef = chunk;
122830
+ currentBufferRef = chunk2;
122831
122831
  currentParser = this;
122832
- ret = llhttp.llhttp_execute(this.ptr, currentBufferPtr, chunk.length);
122832
+ ret = llhttp.llhttp_execute(this.ptr, currentBufferPtr, chunk2.length);
122833
122833
  } finally {
122834
122834
  currentParser = null;
122835
122835
  currentBufferRef = null;
122836
122836
  }
122837
122837
  if (ret !== constants3.ERROR.OK) {
122838
- const data = chunk.subarray(llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr);
122838
+ const data = chunk2.subarray(llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr);
122839
122839
  if (ret === constants3.ERROR.PAUSED_UPGRADE) {
122840
122840
  this.onUpgrade(data);
122841
122841
  } else if (ret === constants3.ERROR.PAUSED) {
@@ -123434,12 +123434,12 @@ upgrade: ${upgrade}\r
123434
123434
  assert2(contentLength !== 0 || client[kRunning] === 0, "stream body cannot be pipelined");
123435
123435
  let finished = false;
123436
123436
  const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header });
123437
- const onData = function(chunk) {
123437
+ const onData = function(chunk2) {
123438
123438
  if (finished) {
123439
123439
  return;
123440
123440
  }
123441
123441
  try {
123442
- if (!writer.write(chunk) && this.pause) {
123442
+ if (!writer.write(chunk2) && this.pause) {
123443
123443
  this.pause();
123444
123444
  }
123445
123445
  } catch (err) {
@@ -123574,11 +123574,11 @@ upgrade: ${upgrade}\r
123574
123574
  socket.on("close", onDrain).on("drain", onDrain);
123575
123575
  const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header });
123576
123576
  try {
123577
- for await (const chunk of body) {
123577
+ for await (const chunk2 of body) {
123578
123578
  if (socket[kError]) {
123579
123579
  throw socket[kError];
123580
123580
  }
123581
- if (!writer.write(chunk)) {
123581
+ if (!writer.write(chunk2)) {
123582
123582
  await waitForDrain();
123583
123583
  }
123584
123584
  }
@@ -123616,7 +123616,7 @@ upgrade: ${upgrade}\r
123616
123616
  * @param {Buffer} chunk
123617
123617
  * @returns
123618
123618
  */
123619
- write(chunk) {
123619
+ write(chunk2) {
123620
123620
  const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this;
123621
123621
  if (socket[kError]) {
123622
123622
  throw socket[kError];
@@ -123624,7 +123624,7 @@ upgrade: ${upgrade}\r
123624
123624
  if (socket.destroyed) {
123625
123625
  return false;
123626
123626
  }
123627
- const len = Buffer.byteLength(chunk);
123627
+ const len = Buffer.byteLength(chunk2);
123628
123628
  if (!len) {
123629
123629
  return true;
123630
123630
  }
@@ -123654,9 +123654,9 @@ ${len.toString(16)}\r
123654
123654
  `, "latin1");
123655
123655
  }
123656
123656
  this.bytesWritten += len;
123657
- const ret = socket.write(chunk);
123657
+ const ret = socket.write(chunk2);
123658
123658
  socket.uncork();
123659
- request.onBodySent(chunk);
123659
+ request.onBodySent(chunk2);
123660
123660
  if (!ret) {
123661
123661
  if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
123662
123662
  if (socket[kParser].timeout.refresh) {
@@ -124207,8 +124207,8 @@ var require_client_h2 = __commonJS({
124207
124207
  stream.pause();
124208
124208
  }
124209
124209
  });
124210
- stream.on("data", (chunk) => {
124211
- if (request.onData(chunk) === false) {
124210
+ stream.on("data", (chunk2) => {
124211
+ if (request.onData(chunk2) === false) {
124212
124212
  stream.pause();
124213
124213
  }
124214
124214
  });
@@ -124374,8 +124374,8 @@ var require_client_h2 = __commonJS({
124374
124374
  }
124375
124375
  );
124376
124376
  util2.addListener(pipe2, "data", onPipeData);
124377
- function onPipeData(chunk) {
124378
- request.onBodySent(chunk);
124377
+ function onPipeData(chunk2) {
124378
+ request.onBodySent(chunk2);
124379
124379
  }
124380
124380
  }
124381
124381
  async function writeBlob(abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
@@ -124419,12 +124419,12 @@ var require_client_h2 = __commonJS({
124419
124419
  });
124420
124420
  h2stream.on("close", onDrain).on("drain", onDrain);
124421
124421
  try {
124422
- for await (const chunk of body) {
124422
+ for await (const chunk2 of body) {
124423
124423
  if (socket[kError]) {
124424
124424
  throw socket[kError];
124425
124425
  }
124426
- const res = h2stream.write(chunk);
124427
- request.onBodySent(chunk);
124426
+ const res = h2stream.write(chunk2);
124427
+ request.onBodySent(chunk2);
124428
124428
  if (!res) {
124429
124429
  await waitForDrain();
124430
124430
  }
@@ -126300,12 +126300,12 @@ var require_retry_handler = __commonJS({
126300
126300
  });
126301
126301
  }
126302
126302
  }
126303
- onResponseData(controller, chunk) {
126303
+ onResponseData(controller, chunk2) {
126304
126304
  if (this.error) {
126305
126305
  return;
126306
126306
  }
126307
- this.start += chunk.length;
126308
- this.handler.onResponseData?.(controller, chunk);
126307
+ this.start += chunk2.length;
126308
+ this.handler.onResponseData?.(controller, chunk2);
126309
126309
  }
126310
126310
  onResponseEnd(controller, trailers) {
126311
126311
  if (this.error && this.retryOpts.throwOnError) {
@@ -126560,15 +126560,15 @@ var require_readable2 = __commonJS({
126560
126560
  * @param {Buffer|null} chunk
126561
126561
  * @returns {boolean}
126562
126562
  */
126563
- push(chunk) {
126564
- if (chunk) {
126565
- this[kBytesRead] += chunk.length;
126563
+ push(chunk2) {
126564
+ if (chunk2) {
126565
+ this[kBytesRead] += chunk2.length;
126566
126566
  if (this[kConsume]) {
126567
- consumePush(this[kConsume], chunk);
126568
- return this[kReading] ? super.push(chunk) : true;
126567
+ consumePush(this[kConsume], chunk2);
126568
+ return this[kReading] ? super.push(chunk2) : true;
126569
126569
  }
126570
126570
  }
126571
- return super.push(chunk);
126571
+ return super.push(chunk2);
126572
126572
  }
126573
126573
  /**
126574
126574
  * Consumes and returns the body as a string.
@@ -126759,8 +126759,8 @@ var require_readable2 = __commonJS({
126759
126759
  consumePush(consume2, state.buffer[n]);
126760
126760
  }
126761
126761
  } else {
126762
- for (const chunk of state.buffer) {
126763
- consumePush(consume2, chunk);
126762
+ for (const chunk2 of state.buffer) {
126763
+ consumePush(consume2, chunk2);
126764
126764
  }
126765
126765
  }
126766
126766
  if (state.endEmitted) {
@@ -126797,9 +126797,9 @@ var require_readable2 = __commonJS({
126797
126797
  const buffer = new Uint8Array(Buffer.allocUnsafeSlow(length).buffer);
126798
126798
  let offset = 0;
126799
126799
  for (let i = 0; i < chunks.length; ++i) {
126800
- const chunk = chunks[i];
126801
- buffer.set(chunk, offset);
126802
- offset += chunk.length;
126800
+ const chunk2 = chunks[i];
126801
+ buffer.set(chunk2, offset);
126802
+ offset += chunk2.length;
126803
126803
  }
126804
126804
  return buffer;
126805
126805
  }
@@ -126822,9 +126822,9 @@ var require_readable2 = __commonJS({
126822
126822
  stream.destroy(err);
126823
126823
  }
126824
126824
  }
126825
- function consumePush(consume2, chunk) {
126826
- consume2.length += chunk.length;
126827
- consume2.body.push(chunk);
126825
+ function consumePush(consume2, chunk2) {
126826
+ consume2.length += chunk2.length;
126827
+ consume2.body.push(chunk2);
126828
126828
  }
126829
126829
  function consumeFinish(consume2, err) {
126830
126830
  if (consume2.body === null) {
@@ -126969,8 +126969,8 @@ var require_api_request = __commonJS({
126969
126969
  }
126970
126970
  }
126971
126971
  }
126972
- onData(chunk) {
126973
- return this.res.push(chunk);
126972
+ onData(chunk2) {
126973
+ return this.res.push(chunk2);
126974
126974
  }
126975
126975
  onComplete(trailers) {
126976
126976
  util2.parseHeaders(trailers, this.trailers);
@@ -127185,9 +127185,9 @@ var require_api_stream = __commonJS({
127185
127185
  const needDrain = res.writableNeedDrain !== void 0 ? res.writableNeedDrain : res._writableState?.needDrain;
127186
127186
  return needDrain !== true;
127187
127187
  }
127188
- onData(chunk) {
127188
+ onData(chunk2) {
127189
127189
  const { res } = this;
127190
- return res ? res.write(chunk) : true;
127190
+ return res ? res.write(chunk2) : true;
127191
127191
  }
127192
127192
  onComplete(trailers) {
127193
127193
  const { res } = this;
@@ -127328,9 +127328,9 @@ var require_api_pipeline = __commonJS({
127328
127328
  body.resume();
127329
127329
  }
127330
127330
  },
127331
- write: (chunk, encoding, callback) => {
127331
+ write: (chunk2, encoding, callback) => {
127332
127332
  const { req } = this;
127333
- if (req.push(chunk, encoding) || req._readableState.destroyed) {
127333
+ if (req.push(chunk2, encoding) || req._readableState.destroyed) {
127334
127334
  callback();
127335
127335
  } else {
127336
127336
  req[kResume] = callback;
@@ -127395,9 +127395,9 @@ var require_api_pipeline = __commonJS({
127395
127395
  if (!body || typeof body.on !== "function") {
127396
127396
  throw new InvalidReturnValueError("expected Readable");
127397
127397
  }
127398
- body.on("data", (chunk) => {
127398
+ body.on("data", (chunk2) => {
127399
127399
  const { ret, body: body2 } = this;
127400
- if (!ret.push(chunk) && body2.pause) {
127400
+ if (!ret.push(chunk2) && body2.pause) {
127401
127401
  body2.pause();
127402
127402
  }
127403
127403
  }).on("error", (err) => {
@@ -127414,9 +127414,9 @@ var require_api_pipeline = __commonJS({
127414
127414
  });
127415
127415
  this.body = body;
127416
127416
  }
127417
- onData(chunk) {
127417
+ onData(chunk2) {
127418
127418
  const { res } = this;
127419
- return res.push(chunk);
127419
+ return res.push(chunk2);
127420
127420
  }
127421
127421
  onComplete(trailers) {
127422
127422
  const { res } = this;
@@ -128569,8 +128569,8 @@ var require_pending_interceptors_formatter = __commonJS({
128569
128569
  module.exports = class PendingInterceptorsFormatter {
128570
128570
  constructor({ disableColors } = {}) {
128571
128571
  this.transform = new Transform({
128572
- transform(chunk, _enc, cb) {
128573
- cb(null, chunk);
128572
+ transform(chunk2, _enc, cb) {
128573
+ cb(null, chunk2);
128574
128574
  }
128575
128575
  });
128576
128576
  this.logger = new Console({
@@ -129364,9 +129364,9 @@ var require_snapshot_agent = __commonJS({
129364
129364
  responseData.headers = headers;
129365
129365
  return handler.onResponseStart(controller, statusCode, headers, statusMessage);
129366
129366
  },
129367
- onResponseData(controller, chunk) {
129368
- responseData.body.push(chunk);
129369
- return handler.onResponseData(controller, chunk);
129367
+ onResponseData(controller, chunk2) {
129368
+ responseData.body.push(chunk2);
129369
+ return handler.onResponseData(controller, chunk2);
129370
129370
  },
129371
129371
  onResponseEnd(controller, trailers) {
129372
129372
  responseData.trailers = trailers;
@@ -129741,10 +129741,10 @@ var require_redirect_handler = __commonJS({
129741
129741
  this.opts.origin = origin;
129742
129742
  this.opts.query = null;
129743
129743
  }
129744
- onResponseData(controller, chunk) {
129744
+ onResponseData(controller, chunk2) {
129745
129745
  if (this.location) {
129746
129746
  } else {
129747
- this.handler.onResponseData?.(controller, chunk);
129747
+ this.handler.onResponseData?.(controller, chunk2);
129748
129748
  }
129749
129749
  }
129750
129750
  onResponseEnd(controller, trailers) {
@@ -129854,11 +129854,11 @@ var require_response_error = __commonJS({
129854
129854
  this.#decoder = new TextDecoder("utf-8");
129855
129855
  }
129856
129856
  }
129857
- onResponseData(controller, chunk) {
129857
+ onResponseData(controller, chunk2) {
129858
129858
  if (this.#statusCode < 400) {
129859
- return super.onResponseData(controller, chunk);
129859
+ return super.onResponseData(controller, chunk2);
129860
129860
  }
129861
- this.#body += this.#decoder?.decode(chunk, { stream: true }) ?? "";
129861
+ this.#body += this.#decoder?.decode(chunk2, { stream: true }) ?? "";
129862
129862
  }
129863
129863
  onResponseEnd(controller, trailers) {
129864
129864
  if (this.#statusCode >= 400) {
@@ -129971,8 +129971,8 @@ var require_dump = __commonJS({
129971
129971
  err = this.#controller?.reason ?? err;
129972
129972
  super.onResponseError(controller, err);
129973
129973
  }
129974
- onResponseData(controller, chunk) {
129975
- this.#size = this.#size + chunk.length;
129974
+ onResponseData(controller, chunk2) {
129975
+ this.#size = this.#size + chunk2.length;
129976
129976
  if (this.#size >= this.#maxSize) {
129977
129977
  this.#dumped = true;
129978
129978
  if (this.aborted === true) {
@@ -130610,15 +130610,15 @@ var require_cache = __commonJS({
130610
130610
  }
130611
130611
  }
130612
130612
  }
130613
- function makeDeduplicationKey(cacheKey, excludeHeaders) {
130614
- let key = `${cacheKey.origin}:${cacheKey.method}:${cacheKey.path}`;
130615
- if (cacheKey.headers) {
130616
- const sortedHeaders = Object.keys(cacheKey.headers).sort();
130613
+ function makeDeduplicationKey(cacheKey2, excludeHeaders) {
130614
+ let key = `${cacheKey2.origin}:${cacheKey2.method}:${cacheKey2.path}`;
130615
+ if (cacheKey2.headers) {
130616
+ const sortedHeaders = Object.keys(cacheKey2.headers).sort();
130617
130617
  for (const header of sortedHeaders) {
130618
130618
  if (excludeHeaders?.has(header.toLowerCase())) {
130619
130619
  continue;
130620
130620
  }
130621
- const value = cacheKey.headers[header];
130621
+ const value = cacheKey2.headers[header];
130622
130622
  key += `:${header}=${Array.isArray(value) ? value.join(",") : value}`;
130623
130623
  }
130624
130624
  }
@@ -131196,11 +131196,11 @@ var require_cache_handler = __commonJS({
131196
131196
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} cacheKey
131197
131197
  * @param {import('../../types/dispatcher.d.ts').default.DispatchHandler} handler
131198
131198
  */
131199
- constructor({ store, type, cacheByDefault }, cacheKey, handler) {
131199
+ constructor({ store, type, cacheByDefault }, cacheKey2, handler) {
131200
131200
  this.#store = store;
131201
131201
  this.#cacheType = type;
131202
131202
  this.#cacheByDefault = cacheByDefault;
131203
- this.#cacheKey = cacheKey;
131203
+ this.#cacheKey = cacheKey2;
131204
131204
  this.#handler = handler;
131205
131205
  }
131206
131206
  onRequestStart(controller, context2) {
@@ -131292,9 +131292,9 @@ var require_cache_handler = __commonJS({
131292
131292
  if (typeof cachedValue.body.values === "function") {
131293
131293
  const bodyIterator = cachedValue.body.values();
131294
131294
  const streamCachedBody = () => {
131295
- for (const chunk of bodyIterator) {
131296
- const full = this.#writeStream.write(chunk) === false;
131297
- this.#handler.onResponseData?.(controller, chunk);
131295
+ for (const chunk2 of bodyIterator) {
131296
+ const full = this.#writeStream.write(chunk2) === false;
131297
+ this.#handler.onResponseData?.(controller, chunk2);
131298
131298
  if (full) {
131299
131299
  break;
131300
131300
  }
@@ -131312,9 +131312,9 @@ var require_cache_handler = __commonJS({
131312
131312
  });
131313
131313
  streamCachedBody();
131314
131314
  } else if (typeof cachedValue.body.on === "function") {
131315
- cachedValue.body.on("data", (chunk) => {
131316
- this.#writeStream.write(chunk);
131317
- this.#handler.onResponseData?.(controller, chunk);
131315
+ cachedValue.body.on("data", (chunk2) => {
131316
+ this.#writeStream.write(chunk2);
131317
+ this.#handler.onResponseData?.(controller, chunk2);
131318
131318
  }).on("end", () => {
131319
131319
  this.#writeStream.end();
131320
131320
  }).on("error", () => {
@@ -131357,11 +131357,11 @@ var require_cache_handler = __commonJS({
131357
131357
  downstreamOnHeaders();
131358
131358
  }
131359
131359
  }
131360
- onResponseData(controller, chunk) {
131361
- if (this.#writeStream?.write(chunk) === false) {
131360
+ onResponseData(controller, chunk2) {
131361
+ if (this.#writeStream?.write(chunk2) === false) {
131362
131362
  controller.pause();
131363
131363
  }
131364
- this.#handler.onResponseData?.(controller, chunk);
131364
+ this.#handler.onResponseData?.(controller, chunk2);
131365
131365
  }
131366
131366
  onResponseEnd(controller, trailers) {
131367
131367
  this.#writeStream?.end();
@@ -131602,15 +131602,15 @@ var require_memory_cache_store = __commonJS({
131602
131602
  const store = this;
131603
131603
  const entry = { ...key, ...val, body: [], size: 0 };
131604
131604
  return new Writable2({
131605
- write(chunk, encoding, callback) {
131606
- if (typeof chunk === "string") {
131607
- chunk = Buffer.from(chunk, encoding);
131605
+ write(chunk2, encoding, callback) {
131606
+ if (typeof chunk2 === "string") {
131607
+ chunk2 = Buffer.from(chunk2, encoding);
131608
131608
  }
131609
- entry.size += chunk.byteLength;
131609
+ entry.size += chunk2.byteLength;
131610
131610
  if (entry.size >= store.#maxEntrySize) {
131611
131611
  this.destroy();
131612
131612
  } else {
131613
- entry.body.push(chunk);
131613
+ entry.body.push(chunk2);
131614
131614
  }
131615
131615
  callback(null);
131616
131616
  },
@@ -131740,11 +131740,11 @@ var require_cache_revalidation_handler = __commonJS({
131740
131740
  statusMessage
131741
131741
  );
131742
131742
  }
131743
- onResponseData(controller, chunk) {
131743
+ onResponseData(controller, chunk2) {
131744
131744
  if (this.#successful) {
131745
131745
  return;
131746
131746
  }
131747
- return this.#handler.onResponseData?.(controller, chunk);
131747
+ return this.#handler.onResponseData?.(controller, chunk2);
131748
131748
  }
131749
131749
  onResponseEnd(controller, trailers) {
131750
131750
  if (this.#successful) {
@@ -131834,7 +131834,7 @@ var require_cache2 = __commonJS({
131834
131834
  const staleWhileRevalidateExpiry = result.staleAt + staleWhileRevalidate * 1e3;
131835
131835
  return now3 <= staleWhileRevalidateExpiry;
131836
131836
  }
131837
- function handleUncachedResponse(dispatch, globalOpts, cacheKey, handler, opts, reqCacheControl) {
131837
+ function handleUncachedResponse(dispatch, globalOpts, cacheKey2, handler, opts, reqCacheControl) {
131838
131838
  if (reqCacheControl?.["only-if-cached"]) {
131839
131839
  let aborted2 = false;
131840
131840
  try {
@@ -131862,7 +131862,7 @@ var require_cache2 = __commonJS({
131862
131862
  }
131863
131863
  return true;
131864
131864
  }
131865
- return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
131865
+ return dispatch(opts, new CacheHandler(globalOpts, cacheKey2, handler));
131866
131866
  }
131867
131867
  function sendCachedValue(handler, opts, result, age, context2, isStale2) {
131868
131868
  const stream = util2.isStream(result.body) ? result.body : Readable4.from(result.body ?? []);
@@ -131913,18 +131913,18 @@ var require_cache2 = __commonJS({
131913
131913
  if (opts.method === "HEAD") {
131914
131914
  stream.destroy();
131915
131915
  } else {
131916
- stream.on("data", function(chunk) {
131917
- handler.onResponseData?.(controller, chunk);
131916
+ stream.on("data", function(chunk2) {
131917
+ handler.onResponseData?.(controller, chunk2);
131918
131918
  });
131919
131919
  }
131920
131920
  }
131921
- function handleResult2(dispatch, globalOpts, cacheKey, handler, opts, reqCacheControl, result) {
131921
+ function handleResult2(dispatch, globalOpts, cacheKey2, handler, opts, reqCacheControl, result) {
131922
131922
  if (!result) {
131923
- return handleUncachedResponse(dispatch, globalOpts, cacheKey, handler, opts, reqCacheControl);
131923
+ return handleUncachedResponse(dispatch, globalOpts, cacheKey2, handler, opts, reqCacheControl);
131924
131924
  }
131925
131925
  const now3 = Date.now();
131926
131926
  if (now3 > result.deleteAt) {
131927
- return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
131927
+ return dispatch(opts, new CacheHandler(globalOpts, cacheKey2, handler));
131928
131928
  }
131929
131929
  const age = Math.round((now3 - result.cachedAt) / 1e3);
131930
131930
  if (reqCacheControl?.["max-age"] && age >= reqCacheControl["max-age"]) {
@@ -131934,7 +131934,7 @@ var require_cache2 = __commonJS({
131934
131934
  const revalidate = needsRevalidation(result, reqCacheControl, opts);
131935
131935
  if (stale || revalidate) {
131936
131936
  if (util2.isStream(opts.body) && util2.bodyLength(opts.body) !== 0) {
131937
- return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
131937
+ return dispatch(opts, new CacheHandler(globalOpts, cacheKey2, handler));
131938
131938
  }
131939
131939
  if (!revalidate && withinStaleWhileRevalidateWindow(result)) {
131940
131940
  sendCachedValue(handler, opts, result, age, null, true);
@@ -131958,7 +131958,7 @@ var require_cache2 = __commonJS({
131958
131958
  ...opts,
131959
131959
  headers: headers2
131960
131960
  },
131961
- new CacheHandler(globalOpts, cacheKey, {
131961
+ new CacheHandler(globalOpts, cacheKey2, {
131962
131962
  // Silent handler that just updates the cache
131963
131963
  onRequestStart() {
131964
131964
  },
@@ -132009,7 +132009,7 @@ var require_cache2 = __commonJS({
132009
132009
  result.body.on("error", nop).destroy();
132010
132010
  }
132011
132011
  },
132012
- new CacheHandler(globalOpts, cacheKey, handler),
132012
+ new CacheHandler(globalOpts, cacheKey2, handler),
132013
132013
  withinStaleIfErrorThreshold
132014
132014
  )
132015
132015
  );
@@ -132078,13 +132078,13 @@ var require_cache2 = __commonJS({
132078
132078
  if (reqCacheControl?.["no-store"]) {
132079
132079
  return dispatch(opts2, handler);
132080
132080
  }
132081
- const cacheKey = makeCacheKey(opts2);
132082
- const result = store.get(cacheKey);
132081
+ const cacheKey2 = makeCacheKey(opts2);
132082
+ const result = store.get(cacheKey2);
132083
132083
  if (result && typeof result.then === "function") {
132084
132084
  return result.then((result2) => handleResult2(
132085
132085
  dispatch,
132086
132086
  globalOpts,
132087
- cacheKey,
132087
+ cacheKey2,
132088
132088
  handler,
132089
132089
  opts2,
132090
132090
  reqCacheControl,
@@ -132094,7 +132094,7 @@ var require_cache2 = __commonJS({
132094
132094
  return handleResult2(
132095
132095
  dispatch,
132096
132096
  globalOpts,
132097
- cacheKey,
132097
+ cacheKey2,
132098
132098
  handler,
132099
132099
  opts2,
132100
132100
  reqCacheControl,
@@ -132189,9 +132189,9 @@ var require_decompress = __commonJS({
132189
132189
  */
132190
132190
  #setupDecompressorEvents(decompressor, controller) {
132191
132191
  decompressor.on("readable", () => {
132192
- let chunk;
132193
- while ((chunk = decompressor.read()) !== null) {
132194
- const result = super.onResponseData(controller, chunk);
132192
+ let chunk2;
132193
+ while ((chunk2 = decompressor.read()) !== null) {
132194
+ const result = super.onResponseData(controller, chunk2);
132195
132195
  if (result === false) {
132196
132196
  break;
132197
132197
  }
@@ -132267,12 +132267,12 @@ var require_decompress = __commonJS({
132267
132267
  * @param {Buffer} chunk
132268
132268
  * @returns {void}
132269
132269
  */
132270
- onResponseData(controller, chunk) {
132270
+ onResponseData(controller, chunk2) {
132271
132271
  if (this.#decompressors.length > 0) {
132272
- this.#decompressors[0].write(chunk);
132272
+ this.#decompressors[0].write(chunk2);
132273
132273
  return;
132274
132274
  }
132275
- super.onResponseData(controller, chunk);
132275
+ super.onResponseData(controller, chunk2);
132276
132276
  }
132277
132277
  /**
132278
132278
  * @param {Controller} controller
@@ -132410,9 +132410,9 @@ var require_deduplication_handler = __commonJS({
132410
132410
  * @param {import('../../types/dispatcher.d.ts').default.DispatchController} controller
132411
132411
  * @param {Buffer} chunk
132412
132412
  */
132413
- onResponseData(controller, chunk) {
132414
- this.#chunks.push(Buffer.from(chunk));
132415
- this.#primaryHandler.onResponseData?.(controller, chunk);
132413
+ onResponseData(controller, chunk2) {
132414
+ this.#chunks.push(Buffer.from(chunk2));
132415
+ this.#primaryHandler.onResponseData?.(controller, chunk2);
132416
132416
  }
132417
132417
  /**
132418
132418
  * @param {import('../../types/dispatcher.d.ts').default.DispatchController} controller
@@ -132568,8 +132568,8 @@ var require_deduplicate = __commonJS({
132568
132568
  }
132569
132569
  }
132570
132570
  }
132571
- const cacheKey = makeCacheKey(opts2);
132572
- const dedupeKey = makeDeduplicationKey(cacheKey, excludeHeaderNamesSet);
132571
+ const cacheKey2 = makeCacheKey(opts2);
132572
+ const dedupeKey = makeDeduplicationKey(cacheKey2, excludeHeaderNamesSet);
132573
132573
  const pendingHandler = pendingRequests.get(dedupeKey);
132574
132574
  if (pendingHandler) {
132575
132575
  pendingHandler.addWaitingHandler(handler);
@@ -132845,10 +132845,10 @@ var require_sqlite_cache_store = __commonJS({
132845
132845
  const store = this;
132846
132846
  return new Writable2({
132847
132847
  decodeStrings: true,
132848
- write(chunk, encoding, callback) {
132849
- size += chunk.byteLength;
132848
+ write(chunk2, encoding, callback) {
132849
+ size += chunk2.byteLength;
132850
132850
  if (size < store.#maxEntrySize) {
132851
- body.push(chunk);
132851
+ body.push(chunk2);
132852
132852
  } else {
132853
132853
  this.destroy();
132854
132854
  }
@@ -135773,11 +135773,11 @@ var require_fetch2 = __commonJS({
135773
135773
  });
135774
135774
  return true;
135775
135775
  },
135776
- onData(chunk) {
135776
+ onData(chunk2) {
135777
135777
  if (fetchParams.controller.dump) {
135778
135778
  return;
135779
135779
  }
135780
- const bytes = chunk;
135780
+ const bytes = chunk2;
135781
135781
  timingInfo.encodedBodySize += bytes.byteLength;
135782
135782
  return this.body.push(bytes);
135783
135783
  },
@@ -137774,7 +137774,7 @@ var require_permessage_deflate2 = __commonJS({
137774
137774
  this.#options.serverNoContextTakeover = extensions.has("server_no_context_takeover");
137775
137775
  this.#options.serverMaxWindowBits = extensions.get("server_max_window_bits");
137776
137776
  }
137777
- decompress(chunk, fin, callback) {
137777
+ decompress(chunk2, fin, callback) {
137778
137778
  if (!this.#inflate) {
137779
137779
  let windowBits = Z_DEFAULT_WINDOWBITS;
137780
137780
  if (this.#options.serverMaxWindowBits) {
@@ -137796,7 +137796,7 @@ var require_permessage_deflate2 = __commonJS({
137796
137796
  callback(err);
137797
137797
  });
137798
137798
  }
137799
- this.#inflate.write(chunk);
137799
+ this.#inflate.write(chunk2);
137800
137800
  if (fin) {
137801
137801
  this.#inflate.write(tail);
137802
137802
  }
@@ -137855,9 +137855,9 @@ var require_receiver2 = __commonJS({
137855
137855
  * @param {Buffer} chunk
137856
137856
  * @param {() => void} callback
137857
137857
  */
137858
- _write(chunk, _3, callback) {
137859
- this.#buffers.push(chunk);
137860
- this.#byteOffset += chunk.length;
137858
+ _write(chunk2, _3, callback) {
137859
+ this.#buffers.push(chunk2);
137860
+ this.#byteOffset += chunk2.length;
137861
137861
  this.#loop = true;
137862
137862
  this.run(callback);
137863
137863
  }
@@ -138257,8 +138257,8 @@ var require_websocket3 = __commonJS({
138257
138257
  onMessage: (opcode, data) => this.#onMessage(opcode, data),
138258
138258
  onParserError: (err) => failWebsocketConnection(this.#handler, null, err.message),
138259
138259
  onParserDrain: () => this.#onParserDrain(),
138260
- onSocketData: (chunk) => {
138261
- if (!this.#parser.write(chunk)) {
138260
+ onSocketData: (chunk2) => {
138261
+ if (!this.#parser.write(chunk2)) {
138262
138262
  this.#handler.socket.pause();
138263
138263
  }
138264
138264
  },
@@ -138810,8 +138810,8 @@ var require_websocketstream = __commonJS({
138810
138810
  onMessage: (opcode, data) => this.#onMessage(opcode, data),
138811
138811
  onParserError: (err) => failWebsocketConnection(this.#handler, null, err.message),
138812
138812
  onParserDrain: () => this.#handler.socket.resume(),
138813
- onSocketData: (chunk) => {
138814
- if (!this.#parser.write(chunk)) {
138813
+ onSocketData: (chunk2) => {
138814
+ if (!this.#parser.write(chunk2)) {
138815
138815
  this.#handler.socket.pause();
138816
138816
  }
138817
138817
  },
@@ -138906,18 +138906,18 @@ var require_websocketstream = __commonJS({
138906
138906
  const reason = closeInfo.reason;
138907
138907
  closeWebSocketConnection(this.#handler, code, reason, true);
138908
138908
  }
138909
- #write(chunk) {
138910
- chunk = webidl.converters.WebSocketStreamWrite(chunk);
138909
+ #write(chunk2) {
138910
+ chunk2 = webidl.converters.WebSocketStreamWrite(chunk2);
138911
138911
  const promise2 = createDeferredPromise();
138912
138912
  let data = null;
138913
138913
  let opcode = null;
138914
- if (webidl.is.BufferSource(chunk)) {
138915
- data = new Uint8Array(ArrayBuffer.isView(chunk) ? new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength) : chunk.slice());
138914
+ if (webidl.is.BufferSource(chunk2)) {
138915
+ data = new Uint8Array(ArrayBuffer.isView(chunk2) ? new Uint8Array(chunk2.buffer, chunk2.byteOffset, chunk2.byteLength) : chunk2.slice());
138916
138916
  opcode = opcodes.BINARY;
138917
138917
  } else {
138918
138918
  let string4;
138919
138919
  try {
138920
- string4 = webidl.converters.DOMString(chunk);
138920
+ string4 = webidl.converters.DOMString(chunk2);
138921
138921
  } catch (e) {
138922
138922
  promise2.reject(e);
138923
138923
  return promise2.promise;
@@ -138948,15 +138948,15 @@ var require_websocketstream = __commonJS({
138948
138948
  this.#readableStreamController = controller;
138949
138949
  },
138950
138950
  pull(controller) {
138951
- let chunk;
138952
- while (controller.desiredSize > 0 && (chunk = response.socket.read()) !== null) {
138953
- controller.enqueue(chunk);
138951
+ let chunk2;
138952
+ while (controller.desiredSize > 0 && (chunk2 = response.socket.read()) !== null) {
138953
+ controller.enqueue(chunk2);
138954
138954
  }
138955
138955
  },
138956
138956
  cancel: (reason) => this.#cancel(reason)
138957
138957
  });
138958
138958
  const writable = new WritableStream({
138959
- write: (chunk) => this.#write(chunk),
138959
+ write: (chunk2) => this.#write(chunk2),
138960
138960
  close: () => closeWebSocketConnection(this.#handler, null, null),
138961
138961
  abort: (reason) => this.#closeUsingReason(reason)
138962
138962
  });
@@ -138974,18 +138974,18 @@ var require_websocketstream = __commonJS({
138974
138974
  if (this.#handler.readyState !== states.OPEN) {
138975
138975
  return;
138976
138976
  }
138977
- let chunk;
138977
+ let chunk2;
138978
138978
  if (type === opcodes.TEXT) {
138979
138979
  try {
138980
- chunk = utf8Decode(data);
138980
+ chunk2 = utf8Decode(data);
138981
138981
  } catch {
138982
138982
  failWebsocketConnection(this.#handler, "Received invalid UTF-8 in text frame.");
138983
138983
  return;
138984
138984
  }
138985
138985
  } else if (type === opcodes.BINARY) {
138986
- chunk = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
138986
+ chunk2 = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
138987
138987
  }
138988
- this.#readableStreamController.enqueue(chunk);
138988
+ this.#readableStreamController.enqueue(chunk2);
138989
138989
  }
138990
138990
  /** @type {import('../websocket').Handler['onSocketClose']} */
138991
138991
  #onSocketClose() {
@@ -139159,15 +139159,15 @@ var require_eventsource_stream = __commonJS({
139159
139159
  * @param {Function} callback
139160
139160
  * @returns {void}
139161
139161
  */
139162
- _transform(chunk, _encoding, callback) {
139163
- if (chunk.length === 0) {
139162
+ _transform(chunk2, _encoding, callback) {
139163
+ if (chunk2.length === 0) {
139164
139164
  callback();
139165
139165
  return;
139166
139166
  }
139167
139167
  if (this.buffer) {
139168
- this.buffer = Buffer.concat([this.buffer, chunk]);
139168
+ this.buffer = Buffer.concat([this.buffer, chunk2]);
139169
139169
  } else {
139170
- this.buffer = chunk;
139170
+ this.buffer = chunk2;
139171
139171
  }
139172
139172
  if (this.checkBOM) {
139173
139173
  switch (this.buffer.length) {
@@ -139878,9 +139878,9 @@ var require_helpers = __commonJS({
139878
139878
  async function toBuffer(stream) {
139879
139879
  let length = 0;
139880
139880
  const chunks = [];
139881
- for await (const chunk of stream) {
139882
- length += chunk.length;
139883
- chunks.push(chunk);
139881
+ for await (const chunk2 of stream) {
139882
+ length += chunk2.length;
139883
+ chunks.push(chunk2);
139884
139884
  }
139885
139885
  return Buffer.concat(chunks, length);
139886
139886
  }
@@ -145878,8 +145878,8 @@ function getFromCache(kid) {
145878
145878
  function getCacheValues() {
145879
145879
  return Object.values(cache);
145880
145880
  }
145881
- function setInCache(cacheKey, jwk, shouldExpire = true) {
145882
- cache[cacheKey] = jwk;
145881
+ function setInCache(cacheKey2, jwk, shouldExpire = true) {
145882
+ cache[cacheKey2] = jwk;
145883
145883
  lastUpdatedAt = shouldExpire ? Date.now() : -1;
145884
145884
  }
145885
145885
  function loadClerkJwkFromPem(params) {
@@ -152317,16 +152317,16 @@ var require_split2 = __commonJS({
152317
152317
  var { StringDecoder } = __require("string_decoder");
152318
152318
  var kLast = /* @__PURE__ */ Symbol("last");
152319
152319
  var kDecoder = /* @__PURE__ */ Symbol("decoder");
152320
- function transform2(chunk, enc, cb) {
152320
+ function transform2(chunk2, enc, cb) {
152321
152321
  let list;
152322
152322
  if (this.overflow) {
152323
- const buf = this[kDecoder].write(chunk);
152323
+ const buf = this[kDecoder].write(chunk2);
152324
152324
  list = buf.split(this.matcher);
152325
152325
  if (list.length === 1) return cb();
152326
152326
  list.shift();
152327
152327
  this.overflow = false;
152328
152328
  } else {
152329
- this[kLast] += this[kDecoder].write(chunk);
152329
+ this[kLast] += this[kDecoder].write(chunk2);
152330
152330
  list = this[kLast].split(this.matcher);
152331
152331
  }
152332
152332
  this[kLast] = list.pop();
@@ -154326,8 +154326,8 @@ var require_pino_pretty = __commonJS({
154326
154326
  const stream = new Transform({
154327
154327
  objectMode: true,
154328
154328
  autoDestroy: true,
154329
- transform(chunk, enc, cb) {
154330
- const line = pretty3(chunk);
154329
+ transform(chunk2, enc, cb) {
154330
+ const line = pretty3(chunk2);
154331
154331
  cb(null, line);
154332
154332
  }
154333
154333
  });
@@ -205180,6 +205180,13 @@ function findTurnOpeningUserEntry(entries, beforeIndex) {
205180
205180
  }
205181
205181
  return opening;
205182
205182
  }
205183
+ function findLatestUserEntry(entries) {
205184
+ for (let i = entries.length - 1; i >= 0; i--) {
205185
+ const entry = entries[i];
205186
+ if (entry?.type === "user") return entry;
205187
+ }
205188
+ return void 0;
205189
+ }
205183
205190
  function resolveNotificationDisposition(openingUserEntry) {
205184
205191
  if (openingUserEntry?.type !== "user") return "result";
205185
205192
  if (openingUserEntry.notificationDisposition) return openingUserEntry.notificationDisposition;
@@ -210405,7 +210412,7 @@ function createParser(callbacks) {
210405
210412
  const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
210406
210413
  let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
210407
210414
  function feed(newChunk) {
210408
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
210415
+ const chunk2 = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk2}`);
210409
210416
  for (const line of complete)
210410
210417
  parseLine(line);
210411
210418
  incompleteLine = incomplete, isFirstChunk = false;
@@ -210473,19 +210480,19 @@ function createParser(callbacks) {
210473
210480
  }
210474
210481
  return { feed, reset };
210475
210482
  }
210476
- function splitLines(chunk) {
210483
+ function splitLines(chunk2) {
210477
210484
  const lines = [];
210478
210485
  let incompleteLine = "", searchIndex = 0;
210479
- for (; searchIndex < chunk.length; ) {
210480
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
210486
+ for (; searchIndex < chunk2.length; ) {
210487
+ const crIndex = chunk2.indexOf("\r", searchIndex), lfIndex = chunk2.indexOf(`
210481
210488
  `, searchIndex);
210482
210489
  let lineEnd = -1;
210483
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
210484
- incompleteLine = chunk.slice(searchIndex);
210490
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk2.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
210491
+ incompleteLine = chunk2.slice(searchIndex);
210485
210492
  break;
210486
210493
  } else {
210487
- const line = chunk.slice(searchIndex, lineEnd);
210488
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
210494
+ const line = chunk2.slice(searchIndex, lineEnd);
210495
+ lines.push(line), searchIndex = lineEnd + 1, chunk2[searchIndex - 1] === "\r" && chunk2[searchIndex] === `
210489
210496
  ` && searchIndex++;
210490
210497
  }
210491
210498
  }
@@ -210509,8 +210516,8 @@ var EventSourceParserStream = class extends TransformStream {
210509
210516
  onComment
210510
210517
  });
210511
210518
  },
210512
- transform(chunk) {
210513
- parser.feed(chunk);
210519
+ transform(chunk2) {
210520
+ parser.feed(chunk2);
210514
210521
  }
210515
210522
  });
210516
210523
  }
@@ -210685,9 +210692,9 @@ async function readResponseWithSizeLimit({
210685
210692
  }
210686
210693
  const result = new Uint8Array(totalBytes);
210687
210694
  let offset = 0;
210688
- for (const chunk of chunks) {
210689
- result.set(chunk, offset);
210690
- offset += chunk.length;
210695
+ for (const chunk2 of chunks) {
210696
+ result.set(chunk2, offset);
210697
+ offset += chunk2.length;
210691
210698
  }
210692
210699
  return result;
210693
210700
  }
@@ -213189,9 +213196,9 @@ var GatewayLanguageModel = class {
213189
213196
  controller.enqueue({ type: "stream-start", warnings });
213190
213197
  }
213191
213198
  },
213192
- transform(chunk, controller) {
213193
- if (chunk.success) {
213194
- const streamPart = chunk.value;
213199
+ transform(chunk2, controller) {
213200
+ if (chunk2.success) {
213201
+ const streamPart = chunk2.value;
213195
213202
  if (streamPart.type === "raw" && !options.includeRawChunks) {
213196
213203
  return;
213197
213204
  }
@@ -213201,7 +213208,7 @@ var GatewayLanguageModel = class {
213201
213208
  controller.enqueue(streamPart);
213202
213209
  } else {
213203
213210
  controller.error(
213204
- chunk.error
213211
+ chunk2.error
213205
213212
  );
213206
213213
  }
213207
213214
  }
@@ -214408,17 +214415,17 @@ function asLanguageModelV3(model) {
214408
214415
  function convertV2StreamToV3(stream) {
214409
214416
  return stream.pipeThrough(
214410
214417
  new TransformStream({
214411
- transform(chunk, controller) {
214412
- switch (chunk.type) {
214418
+ transform(chunk2, controller) {
214419
+ switch (chunk2.type) {
214413
214420
  case "finish":
214414
214421
  controller.enqueue({
214415
- ...chunk,
214416
- finishReason: convertV2FinishReasonToV3(chunk.finishReason),
214417
- usage: convertV2UsageToV3(chunk.usage)
214422
+ ...chunk2,
214423
+ finishReason: convertV2FinishReasonToV3(chunk2.finishReason),
214424
+ usage: convertV2UsageToV3(chunk2.usage)
214418
214425
  });
214419
214426
  break;
214420
214427
  default:
214421
- controller.enqueue(chunk);
214428
+ controller.enqueue(chunk2);
214422
214429
  break;
214423
214430
  }
214424
214431
  }
@@ -218364,8 +218371,8 @@ var uiMessageChunkSchema = lazySchema(
218364
218371
  ])
218365
218372
  )
218366
218373
  );
218367
- function isDataUIMessageChunk(chunk) {
218368
- return chunk.type.startsWith("data-");
218374
+ function isDataUIMessageChunk(chunk2) {
218375
+ return chunk2.type.startsWith("data-");
218369
218376
  }
218370
218377
  function isStaticToolUIPart(part) {
218371
218378
  return part.type.startsWith("tool-");
@@ -218406,7 +218413,7 @@ function processUIMessageStream({
218406
218413
  }) {
218407
218414
  return stream.pipeThrough(
218408
218415
  new TransformStream({
218409
- async transform(chunk, controller) {
218416
+ async transform(chunk2, controller) {
218410
218417
  await runUpdateMessageJob(async ({ state, write }) => {
218411
218418
  var _a212, _b18, _c, _d;
218412
218419
  function getToolInvocation(toolCallId) {
@@ -218514,45 +218521,45 @@ function processUIMessageStream({
218514
218521
  state.message.metadata = mergedMetadata;
218515
218522
  }
218516
218523
  }
218517
- switch (chunk.type) {
218524
+ switch (chunk2.type) {
218518
218525
  case "text-start": {
218519
218526
  const textPart = {
218520
218527
  type: "text",
218521
218528
  text: "",
218522
- providerMetadata: chunk.providerMetadata,
218529
+ providerMetadata: chunk2.providerMetadata,
218523
218530
  state: "streaming"
218524
218531
  };
218525
- state.activeTextParts[chunk.id] = textPart;
218532
+ state.activeTextParts[chunk2.id] = textPart;
218526
218533
  state.message.parts.push(textPart);
218527
218534
  write();
218528
218535
  break;
218529
218536
  }
218530
218537
  case "text-delta": {
218531
- const textPart = state.activeTextParts[chunk.id];
218538
+ const textPart = state.activeTextParts[chunk2.id];
218532
218539
  if (textPart == null) {
218533
218540
  throw new UIMessageStreamError({
218534
218541
  chunkType: "text-delta",
218535
- chunkId: chunk.id,
218536
- message: `Received text-delta for missing text part with ID "${chunk.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`
218542
+ chunkId: chunk2.id,
218543
+ message: `Received text-delta for missing text part with ID "${chunk2.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`
218537
218544
  });
218538
218545
  }
218539
- textPart.text += chunk.delta;
218540
- textPart.providerMetadata = (_a212 = chunk.providerMetadata) != null ? _a212 : textPart.providerMetadata;
218546
+ textPart.text += chunk2.delta;
218547
+ textPart.providerMetadata = (_a212 = chunk2.providerMetadata) != null ? _a212 : textPart.providerMetadata;
218541
218548
  write();
218542
218549
  break;
218543
218550
  }
218544
218551
  case "text-end": {
218545
- const textPart = state.activeTextParts[chunk.id];
218552
+ const textPart = state.activeTextParts[chunk2.id];
218546
218553
  if (textPart == null) {
218547
218554
  throw new UIMessageStreamError({
218548
218555
  chunkType: "text-end",
218549
- chunkId: chunk.id,
218550
- message: `Received text-end for missing text part with ID "${chunk.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`
218556
+ chunkId: chunk2.id,
218557
+ message: `Received text-end for missing text part with ID "${chunk2.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`
218551
218558
  });
218552
218559
  }
218553
218560
  textPart.state = "done";
218554
- textPart.providerMetadata = (_b18 = chunk.providerMetadata) != null ? _b18 : textPart.providerMetadata;
218555
- delete state.activeTextParts[chunk.id];
218561
+ textPart.providerMetadata = (_b18 = chunk2.providerMetadata) != null ? _b18 : textPart.providerMetadata;
218562
+ delete state.activeTextParts[chunk2.id];
218556
218563
  write();
218557
218564
  break;
218558
218565
  }
@@ -218560,48 +218567,48 @@ function processUIMessageStream({
218560
218567
  const reasoningPart = {
218561
218568
  type: "reasoning",
218562
218569
  text: "",
218563
- providerMetadata: chunk.providerMetadata,
218570
+ providerMetadata: chunk2.providerMetadata,
218564
218571
  state: "streaming"
218565
218572
  };
218566
- state.activeReasoningParts[chunk.id] = reasoningPart;
218573
+ state.activeReasoningParts[chunk2.id] = reasoningPart;
218567
218574
  state.message.parts.push(reasoningPart);
218568
218575
  write();
218569
218576
  break;
218570
218577
  }
218571
218578
  case "reasoning-delta": {
218572
- const reasoningPart = state.activeReasoningParts[chunk.id];
218579
+ const reasoningPart = state.activeReasoningParts[chunk2.id];
218573
218580
  if (reasoningPart == null) {
218574
218581
  throw new UIMessageStreamError({
218575
218582
  chunkType: "reasoning-delta",
218576
- chunkId: chunk.id,
218577
- message: `Received reasoning-delta for missing reasoning part with ID "${chunk.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`
218583
+ chunkId: chunk2.id,
218584
+ message: `Received reasoning-delta for missing reasoning part with ID "${chunk2.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`
218578
218585
  });
218579
218586
  }
218580
- reasoningPart.text += chunk.delta;
218581
- reasoningPart.providerMetadata = (_c = chunk.providerMetadata) != null ? _c : reasoningPart.providerMetadata;
218587
+ reasoningPart.text += chunk2.delta;
218588
+ reasoningPart.providerMetadata = (_c = chunk2.providerMetadata) != null ? _c : reasoningPart.providerMetadata;
218582
218589
  write();
218583
218590
  break;
218584
218591
  }
218585
218592
  case "reasoning-end": {
218586
- const reasoningPart = state.activeReasoningParts[chunk.id];
218593
+ const reasoningPart = state.activeReasoningParts[chunk2.id];
218587
218594
  if (reasoningPart == null) {
218588
218595
  throw new UIMessageStreamError({
218589
218596
  chunkType: "reasoning-end",
218590
- chunkId: chunk.id,
218591
- message: `Received reasoning-end for missing reasoning part with ID "${chunk.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
218597
+ chunkId: chunk2.id,
218598
+ message: `Received reasoning-end for missing reasoning part with ID "${chunk2.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
218592
218599
  });
218593
218600
  }
218594
- reasoningPart.providerMetadata = (_d = chunk.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
218601
+ reasoningPart.providerMetadata = (_d = chunk2.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
218595
218602
  reasoningPart.state = "done";
218596
- delete state.activeReasoningParts[chunk.id];
218603
+ delete state.activeReasoningParts[chunk2.id];
218597
218604
  write();
218598
218605
  break;
218599
218606
  }
218600
218607
  case "file": {
218601
218608
  state.message.parts.push({
218602
218609
  type: "file",
218603
- mediaType: chunk.mediaType,
218604
- url: chunk.url
218610
+ mediaType: chunk2.mediaType,
218611
+ url: chunk2.url
218605
218612
  });
218606
218613
  write();
218607
218614
  break;
@@ -218609,10 +218616,10 @@ function processUIMessageStream({
218609
218616
  case "source-url": {
218610
218617
  state.message.parts.push({
218611
218618
  type: "source-url",
218612
- sourceId: chunk.sourceId,
218613
- url: chunk.url,
218614
- title: chunk.title,
218615
- providerMetadata: chunk.providerMetadata
218619
+ sourceId: chunk2.sourceId,
218620
+ url: chunk2.url,
218621
+ title: chunk2.title,
218622
+ providerMetadata: chunk2.providerMetadata
218616
218623
  });
218617
218624
  write();
218618
218625
  break;
@@ -218620,64 +218627,64 @@ function processUIMessageStream({
218620
218627
  case "source-document": {
218621
218628
  state.message.parts.push({
218622
218629
  type: "source-document",
218623
- sourceId: chunk.sourceId,
218624
- mediaType: chunk.mediaType,
218625
- title: chunk.title,
218626
- filename: chunk.filename,
218627
- providerMetadata: chunk.providerMetadata
218630
+ sourceId: chunk2.sourceId,
218631
+ mediaType: chunk2.mediaType,
218632
+ title: chunk2.title,
218633
+ filename: chunk2.filename,
218634
+ providerMetadata: chunk2.providerMetadata
218628
218635
  });
218629
218636
  write();
218630
218637
  break;
218631
218638
  }
218632
218639
  case "tool-input-start": {
218633
218640
  const toolInvocations = state.message.parts.filter(isStaticToolUIPart);
218634
- state.partialToolCalls[chunk.toolCallId] = {
218641
+ state.partialToolCalls[chunk2.toolCallId] = {
218635
218642
  text: "",
218636
- toolName: chunk.toolName,
218643
+ toolName: chunk2.toolName,
218637
218644
  index: toolInvocations.length,
218638
- dynamic: chunk.dynamic,
218639
- title: chunk.title
218645
+ dynamic: chunk2.dynamic,
218646
+ title: chunk2.title
218640
218647
  };
218641
- if (chunk.dynamic) {
218648
+ if (chunk2.dynamic) {
218642
218649
  updateDynamicToolPart({
218643
- toolCallId: chunk.toolCallId,
218644
- toolName: chunk.toolName,
218650
+ toolCallId: chunk2.toolCallId,
218651
+ toolName: chunk2.toolName,
218645
218652
  state: "input-streaming",
218646
218653
  input: void 0,
218647
- providerExecuted: chunk.providerExecuted,
218648
- title: chunk.title,
218649
- providerMetadata: chunk.providerMetadata
218654
+ providerExecuted: chunk2.providerExecuted,
218655
+ title: chunk2.title,
218656
+ providerMetadata: chunk2.providerMetadata
218650
218657
  });
218651
218658
  } else {
218652
218659
  updateToolPart({
218653
- toolCallId: chunk.toolCallId,
218654
- toolName: chunk.toolName,
218660
+ toolCallId: chunk2.toolCallId,
218661
+ toolName: chunk2.toolName,
218655
218662
  state: "input-streaming",
218656
218663
  input: void 0,
218657
- providerExecuted: chunk.providerExecuted,
218658
- title: chunk.title,
218659
- providerMetadata: chunk.providerMetadata
218664
+ providerExecuted: chunk2.providerExecuted,
218665
+ title: chunk2.title,
218666
+ providerMetadata: chunk2.providerMetadata
218660
218667
  });
218661
218668
  }
218662
218669
  write();
218663
218670
  break;
218664
218671
  }
218665
218672
  case "tool-input-delta": {
218666
- const partialToolCall = state.partialToolCalls[chunk.toolCallId];
218673
+ const partialToolCall = state.partialToolCalls[chunk2.toolCallId];
218667
218674
  if (partialToolCall == null) {
218668
218675
  throw new UIMessageStreamError({
218669
218676
  chunkType: "tool-input-delta",
218670
- chunkId: chunk.toolCallId,
218671
- message: `Received tool-input-delta for missing tool call with ID "${chunk.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`
218677
+ chunkId: chunk2.toolCallId,
218678
+ message: `Received tool-input-delta for missing tool call with ID "${chunk2.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`
218672
218679
  });
218673
218680
  }
218674
- partialToolCall.text += chunk.inputTextDelta;
218681
+ partialToolCall.text += chunk2.inputTextDelta;
218675
218682
  const { value: partialArgs } = await parsePartialJson(
218676
218683
  partialToolCall.text
218677
218684
  );
218678
218685
  if (partialToolCall.dynamic) {
218679
218686
  updateDynamicToolPart({
218680
- toolCallId: chunk.toolCallId,
218687
+ toolCallId: chunk2.toolCallId,
218681
218688
  toolName: partialToolCall.toolName,
218682
218689
  state: "input-streaming",
218683
218690
  input: partialArgs,
@@ -218685,7 +218692,7 @@ function processUIMessageStream({
218685
218692
  });
218686
218693
  } else {
218687
218694
  updateToolPart({
218688
- toolCallId: chunk.toolCallId,
218695
+ toolCallId: chunk2.toolCallId,
218689
218696
  toolName: partialToolCall.toolName,
218690
218697
  state: "input-streaming",
218691
218698
  input: partialArgs,
@@ -218696,96 +218703,96 @@ function processUIMessageStream({
218696
218703
  break;
218697
218704
  }
218698
218705
  case "tool-input-available": {
218699
- if (chunk.dynamic) {
218706
+ if (chunk2.dynamic) {
218700
218707
  updateDynamicToolPart({
218701
- toolCallId: chunk.toolCallId,
218702
- toolName: chunk.toolName,
218708
+ toolCallId: chunk2.toolCallId,
218709
+ toolName: chunk2.toolName,
218703
218710
  state: "input-available",
218704
- input: chunk.input,
218705
- providerExecuted: chunk.providerExecuted,
218706
- providerMetadata: chunk.providerMetadata,
218707
- title: chunk.title
218711
+ input: chunk2.input,
218712
+ providerExecuted: chunk2.providerExecuted,
218713
+ providerMetadata: chunk2.providerMetadata,
218714
+ title: chunk2.title
218708
218715
  });
218709
218716
  } else {
218710
218717
  updateToolPart({
218711
- toolCallId: chunk.toolCallId,
218712
- toolName: chunk.toolName,
218718
+ toolCallId: chunk2.toolCallId,
218719
+ toolName: chunk2.toolName,
218713
218720
  state: "input-available",
218714
- input: chunk.input,
218715
- providerExecuted: chunk.providerExecuted,
218716
- providerMetadata: chunk.providerMetadata,
218717
- title: chunk.title
218721
+ input: chunk2.input,
218722
+ providerExecuted: chunk2.providerExecuted,
218723
+ providerMetadata: chunk2.providerMetadata,
218724
+ title: chunk2.title
218718
218725
  });
218719
218726
  }
218720
218727
  write();
218721
- if (onToolCall && !chunk.providerExecuted) {
218728
+ if (onToolCall && !chunk2.providerExecuted) {
218722
218729
  await onToolCall({
218723
- toolCall: chunk
218730
+ toolCall: chunk2
218724
218731
  });
218725
218732
  }
218726
218733
  break;
218727
218734
  }
218728
218735
  case "tool-input-error": {
218729
- if (chunk.dynamic) {
218736
+ if (chunk2.dynamic) {
218730
218737
  updateDynamicToolPart({
218731
- toolCallId: chunk.toolCallId,
218732
- toolName: chunk.toolName,
218738
+ toolCallId: chunk2.toolCallId,
218739
+ toolName: chunk2.toolName,
218733
218740
  state: "output-error",
218734
- input: chunk.input,
218735
- errorText: chunk.errorText,
218736
- providerExecuted: chunk.providerExecuted,
218737
- providerMetadata: chunk.providerMetadata
218741
+ input: chunk2.input,
218742
+ errorText: chunk2.errorText,
218743
+ providerExecuted: chunk2.providerExecuted,
218744
+ providerMetadata: chunk2.providerMetadata
218738
218745
  });
218739
218746
  } else {
218740
218747
  updateToolPart({
218741
- toolCallId: chunk.toolCallId,
218742
- toolName: chunk.toolName,
218748
+ toolCallId: chunk2.toolCallId,
218749
+ toolName: chunk2.toolName,
218743
218750
  state: "output-error",
218744
218751
  input: void 0,
218745
- rawInput: chunk.input,
218746
- errorText: chunk.errorText,
218747
- providerExecuted: chunk.providerExecuted,
218748
- providerMetadata: chunk.providerMetadata
218752
+ rawInput: chunk2.input,
218753
+ errorText: chunk2.errorText,
218754
+ providerExecuted: chunk2.providerExecuted,
218755
+ providerMetadata: chunk2.providerMetadata
218749
218756
  });
218750
218757
  }
218751
218758
  write();
218752
218759
  break;
218753
218760
  }
218754
218761
  case "tool-approval-request": {
218755
- const toolInvocation = getToolInvocation(chunk.toolCallId);
218762
+ const toolInvocation = getToolInvocation(chunk2.toolCallId);
218756
218763
  toolInvocation.state = "approval-requested";
218757
- toolInvocation.approval = { id: chunk.approvalId };
218764
+ toolInvocation.approval = { id: chunk2.approvalId };
218758
218765
  write();
218759
218766
  break;
218760
218767
  }
218761
218768
  case "tool-output-denied": {
218762
- const toolInvocation = getToolInvocation(chunk.toolCallId);
218769
+ const toolInvocation = getToolInvocation(chunk2.toolCallId);
218763
218770
  toolInvocation.state = "output-denied";
218764
218771
  write();
218765
218772
  break;
218766
218773
  }
218767
218774
  case "tool-output-available": {
218768
- const toolInvocation = getToolInvocation(chunk.toolCallId);
218775
+ const toolInvocation = getToolInvocation(chunk2.toolCallId);
218769
218776
  if (toolInvocation.type === "dynamic-tool") {
218770
218777
  updateDynamicToolPart({
218771
- toolCallId: chunk.toolCallId,
218778
+ toolCallId: chunk2.toolCallId,
218772
218779
  toolName: toolInvocation.toolName,
218773
218780
  state: "output-available",
218774
218781
  input: toolInvocation.input,
218775
- output: chunk.output,
218776
- preliminary: chunk.preliminary,
218777
- providerExecuted: chunk.providerExecuted,
218782
+ output: chunk2.output,
218783
+ preliminary: chunk2.preliminary,
218784
+ providerExecuted: chunk2.providerExecuted,
218778
218785
  title: toolInvocation.title
218779
218786
  });
218780
218787
  } else {
218781
218788
  updateToolPart({
218782
- toolCallId: chunk.toolCallId,
218789
+ toolCallId: chunk2.toolCallId,
218783
218790
  toolName: getStaticToolName(toolInvocation),
218784
218791
  state: "output-available",
218785
218792
  input: toolInvocation.input,
218786
- output: chunk.output,
218787
- providerExecuted: chunk.providerExecuted,
218788
- preliminary: chunk.preliminary,
218793
+ output: chunk2.output,
218794
+ providerExecuted: chunk2.providerExecuted,
218795
+ preliminary: chunk2.preliminary,
218789
218796
  title: toolInvocation.title
218790
218797
  });
218791
218798
  }
@@ -218793,26 +218800,26 @@ function processUIMessageStream({
218793
218800
  break;
218794
218801
  }
218795
218802
  case "tool-output-error": {
218796
- const toolInvocation = getToolInvocation(chunk.toolCallId);
218803
+ const toolInvocation = getToolInvocation(chunk2.toolCallId);
218797
218804
  if (toolInvocation.type === "dynamic-tool") {
218798
218805
  updateDynamicToolPart({
218799
- toolCallId: chunk.toolCallId,
218806
+ toolCallId: chunk2.toolCallId,
218800
218807
  toolName: toolInvocation.toolName,
218801
218808
  state: "output-error",
218802
218809
  input: toolInvocation.input,
218803
- errorText: chunk.errorText,
218804
- providerExecuted: chunk.providerExecuted,
218810
+ errorText: chunk2.errorText,
218811
+ providerExecuted: chunk2.providerExecuted,
218805
218812
  title: toolInvocation.title
218806
218813
  });
218807
218814
  } else {
218808
218815
  updateToolPart({
218809
- toolCallId: chunk.toolCallId,
218816
+ toolCallId: chunk2.toolCallId,
218810
218817
  toolName: getStaticToolName(toolInvocation),
218811
218818
  state: "output-error",
218812
218819
  input: toolInvocation.input,
218813
218820
  rawInput: toolInvocation.rawInput,
218814
- errorText: chunk.errorText,
218815
- providerExecuted: chunk.providerExecuted,
218821
+ errorText: chunk2.errorText,
218822
+ providerExecuted: chunk2.providerExecuted,
218816
218823
  title: toolInvocation.title
218817
218824
  });
218818
218825
  }
@@ -218829,54 +218836,54 @@ function processUIMessageStream({
218829
218836
  break;
218830
218837
  }
218831
218838
  case "start": {
218832
- if (chunk.messageId != null) {
218833
- state.message.id = chunk.messageId;
218839
+ if (chunk2.messageId != null) {
218840
+ state.message.id = chunk2.messageId;
218834
218841
  }
218835
- await updateMessageMetadata(chunk.messageMetadata);
218836
- if (chunk.messageId != null || chunk.messageMetadata != null) {
218842
+ await updateMessageMetadata(chunk2.messageMetadata);
218843
+ if (chunk2.messageId != null || chunk2.messageMetadata != null) {
218837
218844
  write();
218838
218845
  }
218839
218846
  break;
218840
218847
  }
218841
218848
  case "finish": {
218842
- if (chunk.finishReason != null) {
218843
- state.finishReason = chunk.finishReason;
218849
+ if (chunk2.finishReason != null) {
218850
+ state.finishReason = chunk2.finishReason;
218844
218851
  }
218845
- await updateMessageMetadata(chunk.messageMetadata);
218846
- if (chunk.messageMetadata != null) {
218852
+ await updateMessageMetadata(chunk2.messageMetadata);
218853
+ if (chunk2.messageMetadata != null) {
218847
218854
  write();
218848
218855
  }
218849
218856
  break;
218850
218857
  }
218851
218858
  case "message-metadata": {
218852
- await updateMessageMetadata(chunk.messageMetadata);
218853
- if (chunk.messageMetadata != null) {
218859
+ await updateMessageMetadata(chunk2.messageMetadata);
218860
+ if (chunk2.messageMetadata != null) {
218854
218861
  write();
218855
218862
  }
218856
218863
  break;
218857
218864
  }
218858
218865
  case "error": {
218859
- onError == null ? void 0 : onError(new Error(chunk.errorText));
218866
+ onError == null ? void 0 : onError(new Error(chunk2.errorText));
218860
218867
  break;
218861
218868
  }
218862
218869
  default: {
218863
- if (isDataUIMessageChunk(chunk)) {
218864
- if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk.type]) != null) {
218870
+ if (isDataUIMessageChunk(chunk2)) {
218871
+ if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk2.type]) != null) {
218865
218872
  const partIdx = state.message.parts.findIndex(
218866
- (p2) => "id" in p2 && "data" in p2 && p2.id === chunk.id && p2.type === chunk.type
218873
+ (p2) => "id" in p2 && "data" in p2 && p2.id === chunk2.id && p2.type === chunk2.type
218867
218874
  );
218868
218875
  const actualPartIdx = partIdx >= 0 ? partIdx : state.message.parts.length;
218869
218876
  await validateTypes({
218870
- value: chunk.data,
218871
- schema: dataPartSchemas[chunk.type],
218877
+ value: chunk2.data,
218878
+ schema: dataPartSchemas[chunk2.type],
218872
218879
  context: {
218873
218880
  field: `message.parts[${actualPartIdx}].data`,
218874
- entityName: chunk.type,
218875
- entityId: chunk.id
218881
+ entityName: chunk2.type,
218882
+ entityId: chunk2.id
218876
218883
  }
218877
218884
  });
218878
218885
  }
218879
- const dataChunk = chunk;
218886
+ const dataChunk = chunk2;
218880
218887
  if (dataChunk.transient) {
218881
218888
  onData == null ? void 0 : onData(dataChunk);
218882
218889
  break;
@@ -218894,7 +218901,7 @@ function processUIMessageStream({
218894
218901
  }
218895
218902
  }
218896
218903
  }
218897
- controller.enqueue(chunk);
218904
+ controller.enqueue(chunk2);
218898
218905
  });
218899
218906
  }
218900
218907
  })
@@ -218917,17 +218924,17 @@ function handleUIMessageStreamFinish({
218917
218924
  let isAborted2 = false;
218918
218925
  const idInjectedStream = stream.pipeThrough(
218919
218926
  new TransformStream({
218920
- transform(chunk, controller) {
218921
- if (chunk.type === "start") {
218922
- const startChunk = chunk;
218927
+ transform(chunk2, controller) {
218928
+ if (chunk2.type === "start") {
218929
+ const startChunk = chunk2;
218923
218930
  if (startChunk.messageId == null && messageId != null) {
218924
218931
  startChunk.messageId = messageId;
218925
218932
  }
218926
218933
  }
218927
- if (chunk.type === "abort") {
218934
+ if (chunk2.type === "abort") {
218928
218935
  isAborted2 = true;
218929
218936
  }
218930
- controller.enqueue(chunk);
218937
+ controller.enqueue(chunk2);
218931
218938
  }
218932
218939
  })
218933
218940
  );
@@ -218985,11 +218992,11 @@ function handleUIMessageStreamFinish({
218985
218992
  onError
218986
218993
  }).pipeThrough(
218987
218994
  new TransformStream({
218988
- async transform(chunk, controller) {
218989
- if (chunk.type === "finish-step") {
218995
+ async transform(chunk2, controller) {
218996
+ if (chunk2.type === "finish-step") {
218990
218997
  await callOnStepFinish();
218991
218998
  }
218992
- controller.enqueue(chunk);
218999
+ controller.enqueue(chunk2);
218993
219000
  },
218994
219001
  // @ts-expect-error cancel is still new and missing from types https://developer.mozilla.org/en-US/docs/Web/API/TransformStream#browser_compatibility
218995
219002
  async cancel() {
@@ -219230,8 +219237,8 @@ function runToolsTransformation({
219230
219237
  }
219231
219238
  }
219232
219239
  const forwardStream = new TransformStream({
219233
- async transform(chunk, controller) {
219234
- const chunkType = chunk.type;
219240
+ async transform(chunk2, controller) {
219241
+ const chunkType = chunk2.type;
219235
219242
  switch (chunkType) {
219236
219243
  case "stream-start":
219237
219244
  case "text-start":
@@ -219247,15 +219254,15 @@ function runToolsTransformation({
219247
219254
  case "response-metadata":
219248
219255
  case "error":
219249
219256
  case "raw": {
219250
- controller.enqueue(chunk);
219257
+ controller.enqueue(chunk2);
219251
219258
  break;
219252
219259
  }
219253
219260
  case "file": {
219254
219261
  controller.enqueue({
219255
219262
  type: "file",
219256
219263
  file: new DefaultGeneratedFileWithType({
219257
- data: chunk.data,
219258
- mediaType: chunk.mediaType
219264
+ data: chunk2.data,
219265
+ mediaType: chunk2.mediaType
219259
219266
  })
219260
219267
  });
219261
219268
  break;
@@ -219263,28 +219270,28 @@ function runToolsTransformation({
219263
219270
  case "finish": {
219264
219271
  finishChunk = {
219265
219272
  type: "finish",
219266
- finishReason: chunk.finishReason.unified,
219267
- rawFinishReason: chunk.finishReason.raw,
219268
- usage: asLanguageModelUsage(chunk.usage),
219269
- providerMetadata: chunk.providerMetadata
219273
+ finishReason: chunk2.finishReason.unified,
219274
+ rawFinishReason: chunk2.finishReason.raw,
219275
+ usage: asLanguageModelUsage(chunk2.usage),
219276
+ providerMetadata: chunk2.providerMetadata
219270
219277
  };
219271
219278
  break;
219272
219279
  }
219273
219280
  case "tool-approval-request": {
219274
- const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
219281
+ const toolCall = toolCallsByToolCallId.get(chunk2.toolCallId);
219275
219282
  if (toolCall == null) {
219276
219283
  toolResultsStreamController.enqueue({
219277
219284
  type: "error",
219278
219285
  error: new ToolCallNotFoundForApprovalError({
219279
- toolCallId: chunk.toolCallId,
219280
- approvalId: chunk.approvalId
219286
+ toolCallId: chunk2.toolCallId,
219287
+ approvalId: chunk2.approvalId
219281
219288
  })
219282
219289
  });
219283
219290
  break;
219284
219291
  }
219285
219292
  controller.enqueue({
219286
219293
  type: "tool-approval-request",
219287
- approvalId: chunk.approvalId,
219294
+ approvalId: chunk2.approvalId,
219288
219295
  toolCall
219289
219296
  });
219290
219297
  break;
@@ -219292,7 +219299,7 @@ function runToolsTransformation({
219292
219299
  case "tool-call": {
219293
219300
  try {
219294
219301
  const toolCall = await parseToolCall({
219295
- toolCall: chunk,
219302
+ toolCall: chunk2,
219296
219303
  tools,
219297
219304
  repairToolCall,
219298
219305
  system,
@@ -219375,26 +219382,26 @@ function runToolsTransformation({
219375
219382
  break;
219376
219383
  }
219377
219384
  case "tool-result": {
219378
- const toolName = chunk.toolName;
219379
- if (chunk.isError) {
219385
+ const toolName = chunk2.toolName;
219386
+ if (chunk2.isError) {
219380
219387
  toolResultsStreamController.enqueue({
219381
219388
  type: "tool-error",
219382
- toolCallId: chunk.toolCallId,
219389
+ toolCallId: chunk2.toolCallId,
219383
219390
  toolName,
219384
- input: toolInputs.get(chunk.toolCallId),
219391
+ input: toolInputs.get(chunk2.toolCallId),
219385
219392
  providerExecuted: true,
219386
- error: chunk.result,
219387
- dynamic: chunk.dynamic
219393
+ error: chunk2.result,
219394
+ dynamic: chunk2.dynamic
219388
219395
  });
219389
219396
  } else {
219390
219397
  controller.enqueue({
219391
219398
  type: "tool-result",
219392
- toolCallId: chunk.toolCallId,
219399
+ toolCallId: chunk2.toolCallId,
219393
219400
  toolName,
219394
- input: toolInputs.get(chunk.toolCallId),
219395
- output: chunk.result,
219401
+ input: toolInputs.get(chunk2.toolCallId),
219402
+ output: chunk2.result,
219396
219403
  providerExecuted: true,
219397
- dynamic: chunk.dynamic
219404
+ dynamic: chunk2.dynamic
219398
219405
  });
219399
219406
  }
219400
219407
  break;
@@ -219415,8 +219422,8 @@ function runToolsTransformation({
219415
219422
  return Promise.all([
219416
219423
  generatorStream.pipeThrough(forwardStream).pipeTo(
219417
219424
  new WritableStream({
219418
- write(chunk) {
219419
- controller.enqueue(chunk);
219425
+ write(chunk2) {
219426
+ controller.enqueue(chunk2);
219420
219427
  },
219421
219428
  close() {
219422
219429
  }
@@ -219424,8 +219431,8 @@ function runToolsTransformation({
219424
219431
  ),
219425
219432
  toolResultsStream.pipeTo(
219426
219433
  new WritableStream({
219427
- write(chunk) {
219428
- controller.enqueue(chunk);
219434
+ write(chunk2) {
219435
+ controller.enqueue(chunk2);
219429
219436
  },
219430
219437
  close() {
219431
219438
  controller.close();
@@ -219554,35 +219561,35 @@ function createOutputTransformStream(output) {
219554
219561
  textChunk = "";
219555
219562
  }
219556
219563
  return new TransformStream({
219557
- async transform(chunk, controller) {
219564
+ async transform(chunk2, controller) {
219558
219565
  var _a212;
219559
- if (chunk.type === "finish-step" && textChunk.length > 0) {
219566
+ if (chunk2.type === "finish-step" && textChunk.length > 0) {
219560
219567
  publishTextChunk({ controller });
219561
219568
  }
219562
- if (chunk.type !== "text-delta" && chunk.type !== "text-start" && chunk.type !== "text-end") {
219563
- controller.enqueue({ part: chunk, partialOutput: void 0 });
219569
+ if (chunk2.type !== "text-delta" && chunk2.type !== "text-start" && chunk2.type !== "text-end") {
219570
+ controller.enqueue({ part: chunk2, partialOutput: void 0 });
219564
219571
  return;
219565
219572
  }
219566
219573
  if (firstTextChunkId == null) {
219567
- firstTextChunkId = chunk.id;
219568
- } else if (chunk.id !== firstTextChunkId) {
219569
- controller.enqueue({ part: chunk, partialOutput: void 0 });
219574
+ firstTextChunkId = chunk2.id;
219575
+ } else if (chunk2.id !== firstTextChunkId) {
219576
+ controller.enqueue({ part: chunk2, partialOutput: void 0 });
219570
219577
  return;
219571
219578
  }
219572
- if (chunk.type === "text-start") {
219573
- controller.enqueue({ part: chunk, partialOutput: void 0 });
219579
+ if (chunk2.type === "text-start") {
219580
+ controller.enqueue({ part: chunk2, partialOutput: void 0 });
219574
219581
  return;
219575
219582
  }
219576
- if (chunk.type === "text-end") {
219583
+ if (chunk2.type === "text-end") {
219577
219584
  if (textChunk.length > 0) {
219578
219585
  publishTextChunk({ controller });
219579
219586
  }
219580
- controller.enqueue({ part: chunk, partialOutput: void 0 });
219587
+ controller.enqueue({ part: chunk2, partialOutput: void 0 });
219581
219588
  return;
219582
219589
  }
219583
- text2 += chunk.text;
219584
- textChunk += chunk.text;
219585
- textProviderMetadata = (_a212 = chunk.providerMetadata) != null ? _a212 : textProviderMetadata;
219590
+ text2 += chunk2.text;
219591
+ textChunk += chunk2.text;
219592
+ textProviderMetadata = (_a212 = chunk2.providerMetadata) != null ? _a212 : textProviderMetadata;
219586
219593
  const result = await output.parsePartialOutput({ text: text2 });
219587
219594
  if (result !== void 0) {
219588
219595
  const currentJson = JSON.stringify(result.partial);
@@ -219658,10 +219665,10 @@ var DefaultStreamTextResult = class {
219658
219665
  let activeTextContent = {};
219659
219666
  let activeReasoningContent = {};
219660
219667
  const eventProcessor = new TransformStream({
219661
- async transform(chunk, controller) {
219668
+ async transform(chunk2, controller) {
219662
219669
  var _a212, _b18, _c, _d;
219663
- controller.enqueue(chunk);
219664
- const { part } = chunk;
219670
+ controller.enqueue(chunk2);
219671
+ const { part } = chunk2;
219665
219672
  if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
219666
219673
  await (onChunk == null ? void 0 : onChunk({ chunk: part }));
219667
219674
  }
@@ -220309,11 +220316,11 @@ var DefaultStreamTextResult = class {
220309
220316
  self2.addStream(
220310
220317
  streamWithToolResults.pipeThrough(
220311
220318
  new TransformStream({
220312
- async transform(chunk, controller) {
220319
+ async transform(chunk2, controller) {
220313
220320
  var _a222, _b24, _c2, _d2, _e2;
220314
220321
  resetChunkTimeout();
220315
- if (chunk.type === "stream-start") {
220316
- warnings = chunk.warnings;
220322
+ if (chunk2.type === "stream-start") {
220323
+ warnings = chunk2.warnings;
220317
220324
  return;
220318
220325
  }
220319
220326
  if (stepFirstChunk) {
@@ -220331,70 +220338,70 @@ var DefaultStreamTextResult = class {
220331
220338
  warnings: warnings != null ? warnings : []
220332
220339
  });
220333
220340
  }
220334
- const chunkType = chunk.type;
220341
+ const chunkType = chunk2.type;
220335
220342
  switch (chunkType) {
220336
220343
  case "tool-approval-request":
220337
220344
  case "text-start":
220338
220345
  case "text-end": {
220339
- controller.enqueue(chunk);
220346
+ controller.enqueue(chunk2);
220340
220347
  break;
220341
220348
  }
220342
220349
  case "text-delta": {
220343
- if (chunk.delta.length > 0) {
220350
+ if (chunk2.delta.length > 0) {
220344
220351
  controller.enqueue({
220345
220352
  type: "text-delta",
220346
- id: chunk.id,
220347
- text: chunk.delta,
220348
- providerMetadata: chunk.providerMetadata
220353
+ id: chunk2.id,
220354
+ text: chunk2.delta,
220355
+ providerMetadata: chunk2.providerMetadata
220349
220356
  });
220350
- activeText += chunk.delta;
220357
+ activeText += chunk2.delta;
220351
220358
  }
220352
220359
  break;
220353
220360
  }
220354
220361
  case "reasoning-start":
220355
220362
  case "reasoning-end": {
220356
- controller.enqueue(chunk);
220363
+ controller.enqueue(chunk2);
220357
220364
  break;
220358
220365
  }
220359
220366
  case "reasoning-delta": {
220360
220367
  controller.enqueue({
220361
220368
  type: "reasoning-delta",
220362
- id: chunk.id,
220363
- text: chunk.delta,
220364
- providerMetadata: chunk.providerMetadata
220369
+ id: chunk2.id,
220370
+ text: chunk2.delta,
220371
+ providerMetadata: chunk2.providerMetadata
220365
220372
  });
220366
220373
  break;
220367
220374
  }
220368
220375
  case "tool-call": {
220369
- controller.enqueue(chunk);
220370
- stepToolCalls.push(chunk);
220376
+ controller.enqueue(chunk2);
220377
+ stepToolCalls.push(chunk2);
220371
220378
  break;
220372
220379
  }
220373
220380
  case "tool-result": {
220374
- controller.enqueue(chunk);
220375
- if (!chunk.preliminary) {
220376
- stepToolOutputs.push(chunk);
220381
+ controller.enqueue(chunk2);
220382
+ if (!chunk2.preliminary) {
220383
+ stepToolOutputs.push(chunk2);
220377
220384
  }
220378
220385
  break;
220379
220386
  }
220380
220387
  case "tool-error": {
220381
- controller.enqueue(chunk);
220382
- stepToolOutputs.push(chunk);
220388
+ controller.enqueue(chunk2);
220389
+ stepToolOutputs.push(chunk2);
220383
220390
  break;
220384
220391
  }
220385
220392
  case "response-metadata": {
220386
220393
  stepResponse = {
220387
- id: (_a222 = chunk.id) != null ? _a222 : stepResponse.id,
220388
- timestamp: (_b24 = chunk.timestamp) != null ? _b24 : stepResponse.timestamp,
220389
- modelId: (_c2 = chunk.modelId) != null ? _c2 : stepResponse.modelId
220394
+ id: (_a222 = chunk2.id) != null ? _a222 : stepResponse.id,
220395
+ timestamp: (_b24 = chunk2.timestamp) != null ? _b24 : stepResponse.timestamp,
220396
+ modelId: (_c2 = chunk2.modelId) != null ? _c2 : stepResponse.modelId
220390
220397
  };
220391
220398
  break;
220392
220399
  }
220393
220400
  case "finish": {
220394
- stepUsage = chunk.usage;
220395
- stepFinishReason = chunk.finishReason;
220396
- stepRawFinishReason = chunk.rawFinishReason;
220397
- stepProviderMetadata = chunk.providerMetadata;
220401
+ stepUsage = chunk2.usage;
220402
+ stepFinishReason = chunk2.finishReason;
220403
+ stepRawFinishReason = chunk2.rawFinishReason;
220404
+ stepProviderMetadata = chunk2.providerMetadata;
220398
220405
  const msToFinish = now22() - startTimestampMs;
220399
220406
  doStreamSpan.addEvent("ai.stream.finish");
220400
220407
  doStreamSpan.setAttributes({
@@ -220404,59 +220411,59 @@ var DefaultStreamTextResult = class {
220404
220411
  break;
220405
220412
  }
220406
220413
  case "file": {
220407
- controller.enqueue(chunk);
220414
+ controller.enqueue(chunk2);
220408
220415
  break;
220409
220416
  }
220410
220417
  case "source": {
220411
- controller.enqueue(chunk);
220418
+ controller.enqueue(chunk2);
220412
220419
  break;
220413
220420
  }
220414
220421
  case "tool-input-start": {
220415
- activeToolCallToolNames[chunk.id] = chunk.toolName;
220416
- const tool2 = tools == null ? void 0 : tools[chunk.toolName];
220422
+ activeToolCallToolNames[chunk2.id] = chunk2.toolName;
220423
+ const tool2 = tools == null ? void 0 : tools[chunk2.toolName];
220417
220424
  if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
220418
220425
  await tool2.onInputStart({
220419
- toolCallId: chunk.id,
220426
+ toolCallId: chunk2.id,
220420
220427
  messages: stepInputMessages,
220421
220428
  abortSignal,
220422
220429
  experimental_context
220423
220430
  });
220424
220431
  }
220425
220432
  controller.enqueue({
220426
- ...chunk,
220427
- dynamic: (_e2 = chunk.dynamic) != null ? _e2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
220433
+ ...chunk2,
220434
+ dynamic: (_e2 = chunk2.dynamic) != null ? _e2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
220428
220435
  title: tool2 == null ? void 0 : tool2.title
220429
220436
  });
220430
220437
  break;
220431
220438
  }
220432
220439
  case "tool-input-end": {
220433
- delete activeToolCallToolNames[chunk.id];
220434
- controller.enqueue(chunk);
220440
+ delete activeToolCallToolNames[chunk2.id];
220441
+ controller.enqueue(chunk2);
220435
220442
  break;
220436
220443
  }
220437
220444
  case "tool-input-delta": {
220438
- const toolName = activeToolCallToolNames[chunk.id];
220445
+ const toolName = activeToolCallToolNames[chunk2.id];
220439
220446
  const tool2 = tools == null ? void 0 : tools[toolName];
220440
220447
  if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
220441
220448
  await tool2.onInputDelta({
220442
- inputTextDelta: chunk.delta,
220443
- toolCallId: chunk.id,
220449
+ inputTextDelta: chunk2.delta,
220450
+ toolCallId: chunk2.id,
220444
220451
  messages: stepInputMessages,
220445
220452
  abortSignal,
220446
220453
  experimental_context
220447
220454
  });
220448
220455
  }
220449
- controller.enqueue(chunk);
220456
+ controller.enqueue(chunk2);
220450
220457
  break;
220451
220458
  }
220452
220459
  case "error": {
220453
- controller.enqueue(chunk);
220460
+ controller.enqueue(chunk2);
220454
220461
  stepFinishReason = "error";
220455
220462
  break;
220456
220463
  }
220457
220464
  case "raw": {
220458
220465
  if (includeRawChunks2) {
220459
- controller.enqueue(chunk);
220466
+ controller.enqueue(chunk2);
220460
220467
  }
220461
220468
  break;
220462
220469
  }
@@ -221923,17 +221930,17 @@ var DeepSeekChatLanguageModel = class {
221923
221930
  start(controller) {
221924
221931
  controller.enqueue({ type: "stream-start", warnings });
221925
221932
  },
221926
- transform(chunk, controller) {
221933
+ transform(chunk2, controller) {
221927
221934
  var _a26, _b18, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
221928
221935
  if (options.includeRawChunks) {
221929
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
221936
+ controller.enqueue({ type: "raw", rawValue: chunk2.rawValue });
221930
221937
  }
221931
- if (!chunk.success) {
221938
+ if (!chunk2.success) {
221932
221939
  finishReason = { unified: "error", raw: void 0 };
221933
- controller.enqueue({ type: "error", error: chunk.error });
221940
+ controller.enqueue({ type: "error", error: chunk2.error });
221934
221941
  return;
221935
221942
  }
221936
- const value = chunk.value;
221943
+ const value = chunk2.value;
221937
221944
  if ("error" in value) {
221938
221945
  finishReason = { unified: "error", raw: void 0 };
221939
221946
  controller.enqueue({ type: "error", error: value.error.message });
@@ -222534,7 +222541,7 @@ function createParser2(callbacks) {
222534
222541
  const { onEvent = noop3, onError = noop3, onRetry = noop3, onComment } = callbacks;
222535
222542
  let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
222536
222543
  function feed(newChunk) {
222537
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines2(`${incompleteLine}${chunk}`);
222544
+ const chunk2 = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines2(`${incompleteLine}${chunk2}`);
222538
222545
  for (const line of complete)
222539
222546
  parseLine(line);
222540
222547
  incompleteLine = incomplete, isFirstChunk = false;
@@ -222602,19 +222609,19 @@ function createParser2(callbacks) {
222602
222609
  }
222603
222610
  return { feed, reset };
222604
222611
  }
222605
- function splitLines2(chunk) {
222612
+ function splitLines2(chunk2) {
222606
222613
  const lines = [];
222607
222614
  let incompleteLine = "", searchIndex = 0;
222608
- for (; searchIndex < chunk.length; ) {
222609
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
222615
+ for (; searchIndex < chunk2.length; ) {
222616
+ const crIndex = chunk2.indexOf("\r", searchIndex), lfIndex = chunk2.indexOf(`
222610
222617
  `, searchIndex);
222611
222618
  let lineEnd = -1;
222612
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
222613
- incompleteLine = chunk.slice(searchIndex);
222619
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk2.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
222620
+ incompleteLine = chunk2.slice(searchIndex);
222614
222621
  break;
222615
222622
  } else {
222616
- const line = chunk.slice(searchIndex, lineEnd);
222617
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
222623
+ const line = chunk2.slice(searchIndex, lineEnd);
222624
+ lines.push(line), searchIndex = lineEnd + 1, chunk2[searchIndex - 1] === "\r" && chunk2[searchIndex] === `
222618
222625
  ` && searchIndex++;
222619
222626
  }
222620
222627
  }
@@ -222636,8 +222643,8 @@ var EventSourceParserStream2 = class extends TransformStream {
222636
222643
  onComment
222637
222644
  });
222638
222645
  },
222639
- transform(chunk) {
222640
- parser.feed(chunk);
222646
+ transform(chunk2) {
222647
+ parser.feed(chunk2);
222641
222648
  }
222642
222649
  });
222643
222650
  }
@@ -225718,17 +225725,17 @@ var OpenRouterChatLanguageModel = class {
225718
225725
  return {
225719
225726
  stream: safeResponse.pipeThrough(
225720
225727
  new TransformStream({
225721
- transform(chunk, controller) {
225728
+ transform(chunk2, controller) {
225722
225729
  var _a173, _b172, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
225723
225730
  if (options.includeRawChunks) {
225724
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
225731
+ controller.enqueue({ type: "raw", rawValue: chunk2.rawValue });
225725
225732
  }
225726
- if (!chunk.success) {
225733
+ if (!chunk2.success) {
225727
225734
  finishReason = createFinishReason("error");
225728
- controller.enqueue({ type: "error", error: chunk.error });
225735
+ controller.enqueue({ type: "error", error: chunk2.error });
225729
225736
  return;
225730
225737
  }
225731
- const value = chunk.value;
225738
+ const value = chunk2.value;
225732
225739
  if ("error" in value) {
225733
225740
  finishReason = createFinishReason("error");
225734
225741
  controller.enqueue({ type: "error", error: value.error });
@@ -226480,17 +226487,17 @@ var OpenRouterCompletionLanguageModel = class {
226480
226487
  return {
226481
226488
  stream: safeResponse.pipeThrough(
226482
226489
  new TransformStream({
226483
- transform(chunk, controller) {
226490
+ transform(chunk2, controller) {
226484
226491
  var _a163, _b162, _c, _d, _e;
226485
226492
  if (options.includeRawChunks) {
226486
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
226493
+ controller.enqueue({ type: "raw", rawValue: chunk2.rawValue });
226487
226494
  }
226488
- if (!chunk.success) {
226495
+ if (!chunk2.success) {
226489
226496
  finishReason = createFinishReason("error");
226490
- controller.enqueue({ type: "error", error: chunk.error });
226497
+ controller.enqueue({ type: "error", error: chunk2.error });
226491
226498
  return;
226492
226499
  }
226493
- const value = chunk.value;
226500
+ const value = chunk2.value;
226494
226501
  if ("error" in value) {
226495
226502
  finishReason = createFinishReason("error");
226496
226503
  controller.enqueue({ type: "error", error: value.error });
@@ -227083,14 +227090,38 @@ async function generateSessionTitle(storage, userMessage, userId) {
227083
227090
  import { execFileSync as execFileSync2 } from "child_process";
227084
227091
  var MAX_BUFFER = 10 * 1024 * 1024;
227085
227092
  var ABSENT = "absent";
227086
- function git(cwd, args) {
227093
+ function git(cwd, args, input) {
227087
227094
  return execFileSync2("git", args, {
227088
227095
  cwd,
227089
227096
  encoding: "utf-8",
227090
227097
  maxBuffer: MAX_BUFFER,
227098
+ input,
227091
227099
  stdio: ["pipe", "pipe", "pipe"]
227092
227100
  });
227093
227101
  }
227102
+ var PATHS_PER_BATCH = 200;
227103
+ function chunk(items, size) {
227104
+ const out = [];
227105
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
227106
+ return out;
227107
+ }
227108
+ function hashObjects(worktreePath, paths) {
227109
+ const hashes = /* @__PURE__ */ new Map();
227110
+ for (const batch of chunk(paths, PATHS_PER_BATCH)) {
227111
+ let shas = [];
227112
+ try {
227113
+ shas = git(worktreePath, ["hash-object", "--", ...batch]).split("\n").map((l) => l.trim()).filter(Boolean);
227114
+ } catch {
227115
+ shas = [];
227116
+ }
227117
+ if (shas.length !== batch.length) {
227118
+ for (const p2 of batch) hashes.set(p2, git(worktreePath, ["hash-object", "--", p2]).trim());
227119
+ continue;
227120
+ }
227121
+ batch.forEach((p2, i) => hashes.set(p2, shas[i]));
227122
+ }
227123
+ return hashes;
227124
+ }
227094
227125
  function captureSnapshot(worktreePath) {
227095
227126
  try {
227096
227127
  const head = git(worktreePath, ["rev-parse", "HEAD"]).trim();
@@ -227103,13 +227134,15 @@ function captureSnapshot(worktreePath) {
227103
227134
  "--name-status",
227104
227135
  "--no-renames"
227105
227136
  ]);
227137
+ const toHash = [];
227106
227138
  for (const line of nameStatus.split("\n")) {
227107
227139
  if (!line.trim()) continue;
227108
227140
  const tab = line.indexOf(" ");
227109
227141
  if (tab < 0) continue;
227110
227142
  const status = line.slice(0, tab).trim();
227111
227143
  const p2 = line.slice(tab + 1).trim();
227112
- dirty[p2] = status.startsWith("D") ? ABSENT : git(worktreePath, ["hash-object", p2]).trim();
227144
+ if (status.startsWith("D")) dirty[p2] = ABSENT;
227145
+ else toHash.push(p2);
227113
227146
  }
227114
227147
  const untracked = git(worktreePath, [
227115
227148
  "-c",
@@ -227120,8 +227153,9 @@ function captureSnapshot(worktreePath) {
227120
227153
  ]);
227121
227154
  for (const p2 of untracked.split("\n")) {
227122
227155
  const t = p2.trim();
227123
- if (t) dirty[t] = git(worktreePath, ["hash-object", t]).trim();
227156
+ if (t) toHash.push(t);
227124
227157
  }
227158
+ for (const [p2, sha] of hashObjects(worktreePath, toHash)) dirty[p2] = sha;
227125
227159
  return { head, dirty };
227126
227160
  } catch {
227127
227161
  return null;
@@ -227134,6 +227168,33 @@ function blobShaOrAbsent(worktreePath, head, filePath) {
227134
227168
  return ABSENT;
227135
227169
  }
227136
227170
  }
227171
+ var BATCH_CHECK_FOUND = /^([0-9a-f]{40,64}) [a-z]+ \d+$/;
227172
+ function blobShasAt(worktreePath, head, paths) {
227173
+ const out = /* @__PURE__ */ new Map();
227174
+ const batchable = [];
227175
+ for (const p2 of paths) {
227176
+ if (p2.includes("\n")) out.set(p2, blobShaOrAbsent(worktreePath, head, p2));
227177
+ else batchable.push(p2);
227178
+ }
227179
+ for (const batch of chunk(batchable, PATHS_PER_BATCH)) {
227180
+ let lines = [];
227181
+ try {
227182
+ const stdin = batch.map((p2) => `${head}:${p2}`).join("\n") + "\n";
227183
+ lines = git(worktreePath, ["cat-file", "--batch-check"], stdin).split("\n").filter((l) => l.length > 0);
227184
+ } catch {
227185
+ lines = [];
227186
+ }
227187
+ if (lines.length !== batch.length) {
227188
+ for (const p2 of batch) out.set(p2, blobShaOrAbsent(worktreePath, head, p2));
227189
+ continue;
227190
+ }
227191
+ batch.forEach((p2, i) => {
227192
+ const found = BATCH_CHECK_FOUND.exec(lines[i]);
227193
+ out.set(p2, found ? found[1] : ABSENT);
227194
+ });
227195
+ }
227196
+ return out;
227197
+ }
227137
227198
  function computeScope(start, end, worktreePath) {
227138
227199
  const candidates = /* @__PURE__ */ new Set();
227139
227200
  if (start.head !== end.head) {
@@ -227153,18 +227214,29 @@ function computeScope(start, end, worktreePath) {
227153
227214
  }
227154
227215
  for (const p2 of Object.keys(start.dirty)) candidates.add(p2);
227155
227216
  for (const p2 of Object.keys(end.dirty)) candidates.add(p2);
227217
+ const candidateList = [...candidates];
227218
+ const startShas = blobShasAt(
227219
+ worktreePath,
227220
+ start.head,
227221
+ candidateList.filter((f2) => start.dirty[f2] === void 0)
227222
+ );
227223
+ const endShas = blobShasAt(
227224
+ worktreePath,
227225
+ end.head,
227226
+ candidateList.filter((f2) => end.dirty[f2] === void 0)
227227
+ );
227156
227228
  const changed = [];
227157
- for (const f2 of candidates) {
227158
- const startSha = start.dirty[f2] ?? blobShaOrAbsent(worktreePath, start.head, f2);
227159
- const endSha = end.dirty[f2] ?? blobShaOrAbsent(worktreePath, end.head, f2);
227229
+ for (const f2 of candidateList) {
227230
+ const startSha = start.dirty[f2] ?? startShas.get(f2) ?? ABSENT;
227231
+ const endSha = end.dirty[f2] ?? endShas.get(f2) ?? ABSENT;
227160
227232
  if (startSha !== endSha) changed.push(f2);
227161
227233
  }
227162
227234
  changed.sort();
227163
227235
  return { changedFiles: changed, startHead: start.head };
227164
227236
  }
227165
- async function recordTurnSnapshot(storage, sessionId, turnEndIndex, worktreePath) {
227237
+ async function recordTurnSnapshot(storage, sessionId, turnEndIndex, worktreePath, captured) {
227166
227238
  try {
227167
- const snap = captureSnapshot(worktreePath);
227239
+ const snap = captured ?? captureSnapshot(worktreePath);
227168
227240
  if (!snap) return;
227169
227241
  await storage.turnSnapshots.create({
227170
227242
  session_id: sessionId,
@@ -227802,7 +227874,7 @@ var AgentSessionManager = class {
227802
227874
  });
227803
227875
  }
227804
227876
  if (!skipDb && !stored) {
227805
- await recordTurnSnapshot(this.storage, sessionId, -1, absoluteWorktreePath);
227877
+ await recordTurnSnapshot(this.storage, sessionId, -1, absoluteWorktreePath, opts.startSnapshot);
227806
227878
  }
227807
227879
  const storedEntries = stored ? await this.storage.agentSessions.getEntries(sessionId) : [];
227808
227880
  const store = storedEntries.length > 0 ? this.rebuildStoreFromRows(storedEntries, sessionId) : (() => {
@@ -228169,6 +228241,10 @@ var AgentSessionManager = class {
228169
228241
  if (event.type === "turn_started" || event.type === "text" || event.type === "thinking" || event.type === "tool_use" || event.type === "tool_result" || event.type === "approval_request") {
228170
228242
  this.applyCompletionTimerAction(session, session.completion.noteTurnActivity());
228171
228243
  }
228244
+ if (session.turnOpenSince === null && (event.type === "turn_started" || event.type === "text" || event.type === "thinking" || event.type === "tool_use" || event.type === "tool_result" || event.type === "approval_request")) {
228245
+ session.turnOpenSince = timestamp;
228246
+ session.turnDisposition = resolveNotificationDisposition(findLatestUserEntry(session.store.entries));
228247
+ }
228172
228248
  if (session.status !== "running" && (event.type === "text" || event.type === "thinking" || event.type === "tool_use" || event.type === "tool_result" || event.type === "approval_request")) {
228173
228249
  session.status = "running";
228174
228250
  if (!session.skipDb) await this.storage.agentSessions.updateStatus(sessionId, "running");
@@ -229992,19 +230068,19 @@ var RemoteNotificationSync = class {
229992
230068
  }
229993
230069
  async syncMappings(remoteServerId, mappings) {
229994
230070
  for (let i = 0; i < mappings.length; i += MAX_SESSIONS_PER_REQUEST) {
229995
- const chunk = mappings.slice(i, i + MAX_SESSIONS_PER_REQUEST);
229996
- await this.syncChunk(remoteServerId, chunk).catch(
230071
+ const chunk2 = mappings.slice(i, i + MAX_SESSIONS_PER_REQUEST);
230072
+ await this.syncChunk(remoteServerId, chunk2).catch(
229997
230073
  (err) => console.warn(`[RemoteNotifications] chunk sync for ${remoteServerId} failed:`, err)
229998
230074
  );
229999
230075
  }
230000
230076
  }
230001
- async syncChunk(remoteServerId, chunk) {
230002
- const target = await this.resolveTarget(chunk[0]);
230077
+ async syncChunk(remoteServerId, chunk2) {
230078
+ const target = await this.resolveTarget(chunk2[0]);
230003
230079
  if (!target) {
230004
- console.warn(`[RemoteNotifications] no remote link for server ${remoteServerId}; skipping ${chunk.length} mapping(s)`);
230080
+ console.warn(`[RemoteNotifications] no remote link for server ${remoteServerId}; skipping ${chunk2.length} mapping(s)`);
230005
230081
  return;
230006
230082
  }
230007
- let pending = new Map(chunk.map((m2) => [m2.remote_session_id, m2]));
230083
+ let pending = new Map(chunk2.map((m2) => [m2.remote_session_id, m2]));
230008
230084
  for (let page = 0; page < MAX_PAGES_PER_SYNC && pending.size > 0; page++) {
230009
230085
  const cursors = await this.storage.notificationSyncCursors.getMany(
230010
230086
  remoteServerId,
@@ -230244,6 +230320,26 @@ function tryParseWsMessage(raw) {
230244
230320
  return void 0;
230245
230321
  }
230246
230322
  }
230323
+ function isEntryPatchFrame(parsed) {
230324
+ if (!parsed || !("JsonPatch" in parsed)) return false;
230325
+ const ops = parsed.JsonPatch;
230326
+ if (!Array.isArray(ops)) return false;
230327
+ return ops.some((op) => typeof op?.path === "string" && op.path.startsWith("/entries/"));
230328
+ }
230329
+ function entryPatchFrames(messages) {
230330
+ const frames = [];
230331
+ for (const raw of messages) {
230332
+ if (isEntryPatchFrame(tryParseWsMessage(raw))) frames.push(raw);
230333
+ }
230334
+ return frames;
230335
+ }
230336
+ function isSequencePrefix(cached2, replay) {
230337
+ if (cached2.length > replay.length) return false;
230338
+ for (let i = 0; i < cached2.length; i++) {
230339
+ if (cached2[i] !== replay[i]) return false;
230340
+ }
230341
+ return true;
230342
+ }
230247
230343
  async function persistRemoteSessionActivityFrame(storage, sessionId, remoteInfo, parsed, activityAt = Date.now()) {
230248
230344
  const projectId = projectIdFromRemoteSessionId(sessionId, remoteInfo);
230249
230345
  const statusEvent = statusEventFromRemotePatch(parsed, sessionId, remoteInfo);
@@ -230307,6 +230403,7 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
230307
230403
  const raw = data.toString();
230308
230404
  const parsed = tryParseWsMessage(raw);
230309
230405
  if (!parsed) return;
230406
+ if ("keepalive" in parsed) return;
230310
230407
  const kind = "JsonPatch" in parsed ? "JsonPatch" : "finished" in parsed ? "finished" : "taskCompleted" in parsed ? "taskCompleted" : "workflowRunUpdated" in parsed ? "workflowRunUpdated" : "processAlive" in parsed ? "processAlive" : "branchActivity" in parsed ? "branchActivity" : "Ready" in parsed ? "Ready" : "error" in parsed ? "error" : "other";
230311
230408
  if (kind === "JsonPatch") {
230312
230409
  const ops = parsed.JsonPatch;
@@ -230454,23 +230551,18 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
230454
230551
  if ("Ready" in parsed) {
230455
230552
  syncing = false;
230456
230553
  const currentEntry = cache2.get(sessionId);
230457
- const cachedMsgCount = currentEntry.messages.length;
230458
- if (replayBuffer.length > cachedMsgCount) {
230459
- const delta = replayBuffer.slice(cachedMsgCount);
230460
- console.log(`[AgentWS] Sync delta: ${delta.length} new msgs for ${sessionId}`);
230554
+ const cachedSeq = entryPatchFrames(currentEntry.messages);
230555
+ const extendsCache = isSequencePrefix(cachedSeq, replayBuffer);
230556
+ if (extendsCache && replayBuffer.length > cachedSeq.length) {
230557
+ const delta = replayBuffer.slice(cachedSeq.length);
230558
+ console.log(`[AgentWS] Sync delta: ${delta.length} new entry patches for ${sessionId} (remote=${replayBuffer.length}, cached=${cachedSeq.length})`);
230461
230559
  for (const msg of delta) {
230462
- const p2 = tryParseWsMessage(msg);
230463
- cache2.appendMessage(sessionId, msg, !!(p2 && "JsonPatch" in p2));
230560
+ cache2.appendMessage(sessionId, msg, true);
230464
230561
  cache2.broadcast(sessionId, msg);
230465
230562
  }
230466
- } else if (replayBuffer.length < cachedMsgCount) {
230467
- console.log(`[AgentWS] Sync stale cache for ${sessionId}: remote=${replayBuffer.length}, cached=${cachedMsgCount}`);
230468
- let newPatchCount = 0;
230469
- for (const msg of replayBuffer) {
230470
- const p2 = tryParseWsMessage(msg);
230471
- if (p2 && "JsonPatch" in p2) newPatchCount++;
230472
- }
230473
- cache2.replaceAll(sessionId, [...replayBuffer], newPatchCount);
230563
+ } else if (!extendsCache) {
230564
+ console.log(`[AgentWS] Sync replace for ${sessionId}: remote=${replayBuffer.length}, cached=${cachedSeq.length} (sequence diverged or shrank)`);
230565
+ cache2.replaceAll(sessionId, [...replayBuffer], replayBuffer.length);
230474
230566
  const clearPatch = {
230475
230567
  JsonPatch: [{
230476
230568
  op: "replace",
@@ -230488,12 +230580,15 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
230488
230580
  remoteWs.on("message", handleLiveMessage);
230489
230581
  return;
230490
230582
  }
230491
- if ("JsonPatch" in parsed || "taskCompleted" in parsed || "error" in parsed) {
230583
+ if (isEntryPatchFrame(parsed)) {
230492
230584
  replayBuffer.push(raw);
230585
+ return;
230493
230586
  }
230494
230587
  if ("finished" in parsed) {
230495
230588
  cache2.setFinished(sessionId);
230589
+ return;
230496
230590
  }
230591
+ handleLiveMessage(data);
230497
230592
  });
230498
230593
  }
230499
230594
  remoteWs.on("error", (error48) => {
@@ -234286,19 +234381,19 @@ function boundedRecentMessagesKeeping(messages, pinned, limit, maxUtf8Bytes) {
234286
234381
  function splitUtf8Content(content, maxUtf8Bytes) {
234287
234382
  if (Buffer.byteLength(content, "utf8") <= maxUtf8Bytes) return [content];
234288
234383
  const chunks = [];
234289
- let chunk = "";
234384
+ let chunk2 = "";
234290
234385
  let bytes = 0;
234291
234386
  for (const character of content) {
234292
234387
  const characterBytes = Buffer.byteLength(character, "utf8");
234293
- if (bytes + characterBytes > maxUtf8Bytes && chunk) {
234294
- chunks.push(chunk);
234295
- chunk = "";
234388
+ if (bytes + characterBytes > maxUtf8Bytes && chunk2) {
234389
+ chunks.push(chunk2);
234390
+ chunk2 = "";
234296
234391
  bytes = 0;
234297
234392
  }
234298
- chunk += character;
234393
+ chunk2 += character;
234299
234394
  bytes += characterBytes;
234300
234395
  }
234301
- if (chunk) chunks.push(chunk);
234396
+ if (chunk2) chunks.push(chunk2);
234302
234397
  return chunks;
234303
234398
  }
234304
234399
  var ProjectChatNotFoundError = class extends Error {
@@ -236511,8 +236606,9 @@ var WorkflowEngine = class {
236511
236606
  return run2;
236512
236607
  }
236513
236608
  let scope = null;
236609
+ let endSnap = null;
236514
236610
  try {
236515
- const endSnap = captureSnapshot(worktreePath);
236611
+ endSnap = captureSnapshot(worktreePath);
236516
236612
  const startSnap = await resolveStartSnapshot(
236517
236613
  this.storage,
236518
236614
  opts.sourceSessionId,
@@ -236531,7 +236627,9 @@ var WorkflowEngine = class {
236531
236627
  false,
236532
236628
  "plan",
236533
236629
  opts.reviewerAgentType ?? "claude-code",
236534
- true
236630
+ true,
236631
+ false,
236632
+ { startSnapshot: endSnap }
236535
236633
  );
236536
236634
  const taskContext = extractTaskContextBefore(entries, turnEndIndex);
236537
236635
  await this.agentOps.setFinalSessionTitle(
@@ -240395,8 +240493,8 @@ function computeBranchMergeStatus(repoPath, branch, target) {
240395
240493
  const missing = !branchTip ? branch : target;
240396
240494
  throw Object.assign(new Error(`Branch not found: ${missing}`), { statusCode: 400 });
240397
240495
  }
240398
- const cacheKey = `${repoPath}\0${branch}\0${target}`;
240399
- const cached2 = statusCache.get(cacheKey);
240496
+ const cacheKey2 = `${repoPath}\0${branch}\0${target}`;
240497
+ const cached2 = statusCache.get(cacheKey2);
240400
240498
  if (cached2 && cached2.branchTip === branchTip && cached2.targetTip === targetTip) {
240401
240499
  return { status: cached2.status, unmergedCount: cached2.unmergedCount };
240402
240500
  }
@@ -240418,7 +240516,7 @@ function computeBranchMergeStatus(repoPath, branch, target) {
240418
240516
  unmergedCount = 0;
240419
240517
  }
240420
240518
  }
240421
- statusCache.set(cacheKey, { branchTip, targetTip, status, unmergedCount });
240519
+ statusCache.set(cacheKey2, { branchTip, targetTip, status, unmergedCount });
240422
240520
  return { status, unmergedCount };
240423
240521
  }
240424
240522
  function isDirty2(worktreePath) {
@@ -241562,8 +241660,355 @@ async function writePasteToTempFile(content) {
241562
241660
  return { path: filePath, size: Buffer.byteLength(content, "utf8") };
241563
241661
  }
241564
241662
 
241663
+ // src/utils/review-brief.ts
241664
+ import { createHash as createHash5 } from "crypto";
241665
+ var BASE_TIMEOUT_MS = 15e3;
241666
+ var JUDGMENT_TIMEOUT_MS = 9e4;
241667
+ var TIMEOUT_MS_PER_1K_CHARS = 120;
241668
+ var MAX_TIMEOUT_MS = 6e4;
241669
+ var PER_MESSAGE_MAX_CHARS = 6e3;
241670
+ var COMPACT_TRIGGER_CHARS = 12e4;
241671
+ var COMPACT_SLICE_BUDGETS = [96e3, 24e3, 6e3];
241672
+ var RECENT_VERBATIM_RATIO = 0.3;
241673
+ var MIN_RECENT_VERBATIM_CHARS = 2e3;
241674
+ var MAX_FOLD_CALLS = 8;
241675
+ var COMPACT_SUMMARY_MAX_CHARS = 6e3;
241676
+ var COMPACT_SUMMARY_MAX_TOKENS = 3e3;
241677
+ var REVERSALS_MAX_CHARS = 2e3;
241678
+ var REVERSALS_MAX_TOKENS = 2e3;
241679
+ var BRIEF_MAX_CHARS = 4e3;
241680
+ var BRIEF_MAX_TOKENS = 3e3;
241681
+ var REVERSAL_MIN_CHARS = 6e3;
241682
+ var SEP = "\n\n";
241683
+ var COMPACTION_NOTE = "_Note: the source conversation was compressed before distillation \u2014 older turns were summarized rather than read verbatim._";
241684
+ var BRIEF_TRUNCATION_NOTE = "\n\n_[brief truncated at the length limit \u2014 treat it as incomplete]_";
241685
+ var SYSTEM_PROMPT2 = [
241686
+ "You distill a coding-agent conversation into an intent brief for an independent code reviewer.",
241687
+ "The reviewer will NOT see the conversation \u2014 only your brief plus the actual code, so capture what the code alone cannot show:",
241688
+ "0. Dominant question \u2014 1 or 2 sentences: the single question the reviewer must answer to judge this work (what must actually work, toward what goal). Derive it from the conversation's own emphasis \u2014 what the user repeated, finally decided, or reversed course over \u2014 never from your own engineering judgment. If the conversation does not clearly support one, write 'unclear' instead of inventing one.",
241689
+ "1. The original request and its goal.",
241690
+ "2. Hard constraints \u2014 requirements whose violation the user would treat as failure regardless of everything else (security, data loss, an explicit compatibility or behaviour promise). Only list ones the user actually stated; an empty section is fine.",
241691
+ "3. Constraints and decisions, including approaches that were rejected and why. A rejection counts whether the user made it or the agent made it under a principle the user set.",
241692
+ "4. Non-goals, trade-offs and limitations that were acknowledged and accepted.",
241693
+ "5. Behaviour established by actually running something \u2014 observed output, exit codes, error text, which stream an error arrived on. Report what was observed; that is evidence the reviewer cannot recover by reading code.",
241694
+ "Tag every item under headings 3 and 4 with exactly [settled] or [tentative] \u2014 the bare tag; keep any justification to a few words or omit it, always after the tag, never inside the brackets. Settled ONLY when the user explicitly confirmed it, instructed it, or reversed course to it; an agent proposal the user never answered is tentative \u2014 silence is never settled.",
241695
+ "Within each heading, order items by how much they matter to the dominant question, not by when they were said.",
241696
+ "Later statements supersede earlier ones on the same topic. An option explored at length early is often rejected later in a single sentence, and the rejection wins. Where the conversation ends in a decision table or summary, that is authoritative wherever it conflicts with earlier prose.",
241697
+ "The input may arrive as numbered compressed slices followed by verbatim recent turns. Slice numbers are chronological: a later slice overrules an earlier one.",
241698
+ "Decisions the agent made that the user did not contradict are worth reporting, but user silence only ever yields tentative status.",
241699
+ "Do NOT include the agent's self-assessment or any claim that the work is correct or complete \u2014 the reviewer must judge that independently.",
241700
+ "Every statement must trace to something in the conversation. If a heading has nothing real to report, say so rather than inventing plausible-sounding content.",
241701
+ "Write concise markdown bullets under those numbered headings, under 500 words total, in the same language as the conversation. Reply with the brief only."
241702
+ ].join("\n");
241703
+ var REVERSAL_SYSTEM_PROMPT = [
241704
+ "You read a coding-agent conversation and report ONLY the conclusions that were later reversed, dropped, or replaced.",
241705
+ "A design conversation converges by killing its own hypotheses: an option explored in depth early is often rejected later in one sentence, so weigh finality over how much was written.",
241706
+ "A reversal counts whether the user or the agent made it. Ignore rewording that leaves the decision intact.",
241707
+ "Output one line per reversal: SUPERSEDED: <what was concluded earlier> -> <what replaced it> (<why>)",
241708
+ "Report the most decisive reversals first and stay under 200 words \u2014 a list that runs long will be discarded whole, so prioritise rather than pad.",
241709
+ "If nothing was reversed, reply with exactly: NONE"
241710
+ ].join("\n");
241711
+ var COMPACT_SYSTEM_PROMPT = [
241712
+ "You compress one slice of a coding-agent conversation. A later pass will distill the whole thing into an intent brief for a code reviewer.",
241713
+ "You are told which slice of how many this is. Other slices are compressed separately and you cannot see them, so never present a conclusion here as final \u2014 a later slice may overturn it.",
241714
+ "Preserve, in this order of priority:",
241715
+ "1. Reversals and corrections \u2014 any conclusion that was dropped, replaced, or corrected. Quote the deciding sentence verbatim.",
241716
+ "2. Constraints and decisions the user stated, and approaches that were rejected, with the reason. Preserve who made each decision \u2014 an explicit user confirmation must stay distinguishable from an agent proposal the user never answered; quote the user's deciding sentence when there is one.",
241717
+ "3. Behaviour established by actually running something: observed output, exit codes, error text, which stream an error arrived on.",
241718
+ "4. Trade-offs that were acknowledged and accepted.",
241719
+ "Drop: exploration narrative, restated background, tool mechanics, and anything a reviewer could recover by reading the code.",
241720
+ "Stay under 800 words. An over-long slice is discarded whole rather than cut short, so drop lower-priority material instead of running over.",
241721
+ "Keep the conversation's own language. Reply with the compressed slice only, no preamble."
241722
+ ].join("\n");
241723
+ function timeoutForInput(chars) {
241724
+ return Math.min(MAX_TIMEOUT_MS, BASE_TIMEOUT_MS + Math.floor(chars / 1e3) * TIMEOUT_MS_PER_1K_CHARS);
241725
+ }
241726
+ function isSizeRelatedFailure(error48) {
241727
+ const err = error48;
241728
+ if (err?.name === "AbortError" || err?.name === "TimeoutError") return true;
241729
+ const message = err?.message ?? "";
241730
+ return /context[ _-]?length|maximum context|too many tokens|token limit|prompt is too long|request too large|timed? ?out/i.test(
241731
+ message
241732
+ );
241733
+ }
241734
+ function withinLimit(text2, max, label) {
241735
+ if (text2.length <= max) return true;
241736
+ console.warn(`[ReviewBrief] ${label} ran to ${text2.length} chars (limit ${max}) \u2014 discarding rather than truncating`);
241737
+ return false;
241738
+ }
241739
+ function capMessage(text2) {
241740
+ return text2.length > PER_MESSAGE_MAX_CHARS ? text2.slice(0, PER_MESSAGE_MAX_CHARS) + "\u2026" : text2;
241741
+ }
241742
+ function toEntries(messages) {
241743
+ const entries = [];
241744
+ for (const msg of messages) {
241745
+ if (!msg) continue;
241746
+ if (msg.type === "user" && !msg.event) {
241747
+ const text2 = extractUserText(msg.content).trim();
241748
+ if (text2) entries.push({ role: "User", text: capMessage(text2) });
241749
+ } else if (msg.type === "assistant" && typeof msg.content === "string") {
241750
+ const text2 = msg.content.trim();
241751
+ if (text2) entries.push({ role: "Agent", text: capMessage(text2) });
241752
+ }
241753
+ }
241754
+ return entries;
241755
+ }
241756
+ function render(entry) {
241757
+ return `${entry.role}: ${entry.text}`;
241758
+ }
241759
+ function renderAll(entries) {
241760
+ return entries.map(render).join(SEP);
241761
+ }
241762
+ function serializeConversationForBrief(messages) {
241763
+ return renderAll(toEntries(messages));
241764
+ }
241765
+ function projectMessagesForBrief(messages) {
241766
+ return toEntries(messages).map(
241767
+ (entry) => entry.role === "User" ? { type: "user", content: entry.text, timestamp: 0 } : { type: "assistant", content: entry.text, timestamp: 0 }
241768
+ );
241769
+ }
241770
+ function splitRecent(entries, maxChars) {
241771
+ let size = 0;
241772
+ let i = entries.length;
241773
+ while (i > 0) {
241774
+ const len = render(entries[i - 1]).length + SEP.length;
241775
+ if (size + len > maxChars) break;
241776
+ size += len;
241777
+ i--;
241778
+ }
241779
+ return { older: entries.slice(0, i), recent: entries.slice(i) };
241780
+ }
241781
+ function chunkEntries(entries, maxChars) {
241782
+ const chunks = [];
241783
+ let current = [];
241784
+ let size = 0;
241785
+ for (const entry of entries) {
241786
+ const len = render(entry).length + SEP.length;
241787
+ if (current.length > 0 && size + len > maxChars) {
241788
+ chunks.push(current);
241789
+ current = [];
241790
+ size = 0;
241791
+ }
241792
+ current.push(entry);
241793
+ size += len;
241794
+ }
241795
+ if (current.length > 0) chunks.push(current);
241796
+ return chunks;
241797
+ }
241798
+ function telemetryFor(functionId, userId) {
241799
+ return userId ? {
241800
+ isEnabled: true,
241801
+ functionId,
241802
+ metadata: { userId, tags: ["vibedeckx", functionId] }
241803
+ } : void 0;
241804
+ }
241805
+ async function compactChunk(model, chunk2, part, total, userId) {
241806
+ try {
241807
+ const result = await generateText({
241808
+ model,
241809
+ system: COMPACT_SYSTEM_PROMPT,
241810
+ prompt: `Slice ${part} of ${total}.
241811
+
241812
+ ${chunk2}`,
241813
+ timeout: timeoutForInput(chunk2.length),
241814
+ maxOutputTokens: COMPACT_SUMMARY_MAX_TOKENS,
241815
+ experimental_telemetry: telemetryFor("review-intent-brief-compact", userId)
241816
+ });
241817
+ const { text: rawText, finishReason } = result;
241818
+ if (finishReason === "length") {
241819
+ console.warn(`[ReviewBrief] slice ${part}/${total} summary hit the token cap \u2014 discarding`);
241820
+ return null;
241821
+ }
241822
+ const text2 = (rawText ?? "").trim();
241823
+ if (text2.length === 0) {
241824
+ console.warn(`[ReviewBrief] slice ${part}/${total} came back empty (finishReason: ${finishReason ?? "unknown"})`);
241825
+ return null;
241826
+ }
241827
+ return withinLimit(text2, COMPACT_SUMMARY_MAX_CHARS, `slice ${part}/${total} summary`) ? text2 : null;
241828
+ } catch (error48) {
241829
+ if (isSizeRelatedFailure(error48)) throw error48;
241830
+ console.warn(`[ReviewBrief] compaction of slice ${part}/${total} failed:`, error48.message);
241831
+ return null;
241832
+ }
241833
+ }
241834
+ async function compactConversation(model, messages, options = {}) {
241835
+ const sliceChars = options.sliceChars ?? COMPACT_SLICE_BUDGETS[0];
241836
+ const recentChars = Math.max(MIN_RECENT_VERBATIM_CHARS, Math.floor(sliceChars * RECENT_VERBATIM_RATIO));
241837
+ const entries = toEntries(messages);
241838
+ if (entries.length === 0) return null;
241839
+ const { older, recent } = splitRecent(entries, recentChars);
241840
+ if (older.length === 0) return null;
241841
+ const chunks = chunkEntries(older, sliceChars);
241842
+ if (chunks.length > MAX_FOLD_CALLS) {
241843
+ console.warn(
241844
+ `[ReviewBrief] conversation needs ${chunks.length} slices of ${sliceChars} chars (max ${MAX_FOLD_CALLS}) \u2014 falling back to tier 2`
241845
+ );
241846
+ return null;
241847
+ }
241848
+ const settled = await Promise.allSettled(
241849
+ chunks.map((chunk2, i) => compactChunk(model, renderAll(chunk2), i + 1, chunks.length, options.userId))
241850
+ );
241851
+ const sizeRejection = settled.find((r) => r.status === "rejected" && isSizeRelatedFailure(r.reason));
241852
+ if (sizeRejection) throw sizeRejection.reason;
241853
+ if (settled.some((r) => r.status === "rejected" || r.value === null)) return null;
241854
+ const parts = settled.map(
241855
+ (r, i) => `[Compressed slice ${i + 1} of ${chunks.length}]
241856
+ ${r.value}`
241857
+ );
241858
+ if (recent.length > 0) parts.push(`[Recent turns, verbatim]
241859
+ ${renderAll(recent)}`);
241860
+ return parts.join(SEP);
241861
+ }
241862
+ function buildBriefPrompt(conversation, reversals) {
241863
+ const preamble = reversals ? "Conclusions this conversation reversed. The right-hand side is the current state \u2014 never report the left-hand side as what was decided:\n" + reversals + SEP : "";
241864
+ return `${preamble}Distill this conversation into an intent brief:
241865
+
241866
+ ${conversation}`;
241867
+ }
241868
+ function appendCompactionNote(brief, compacted) {
241869
+ return compacted ? `${brief}${SEP}${COMPACTION_NOTE}` : brief;
241870
+ }
241871
+ async function extractReversalsWithModel(model, conversation, options = {}) {
241872
+ if (conversation.trim().length < REVERSAL_MIN_CHARS) return null;
241873
+ try {
241874
+ const result = await generateText({
241875
+ model,
241876
+ system: REVERSAL_SYSTEM_PROMPT,
241877
+ prompt: `Report the reversals in this conversation:
241878
+
241879
+ ${conversation}`,
241880
+ timeout: JUDGMENT_TIMEOUT_MS,
241881
+ maxOutputTokens: REVERSALS_MAX_TOKENS,
241882
+ experimental_telemetry: telemetryFor("review-intent-brief-reversals", options.userId)
241883
+ });
241884
+ const { text: rawText, finishReason } = result;
241885
+ if (finishReason === "length") {
241886
+ console.warn("[ReviewBrief] reversal list hit the token cap \u2014 discarding");
241887
+ return null;
241888
+ }
241889
+ const text2 = (rawText ?? "").trim();
241890
+ if (text2.length === 0 || /^none\b/i.test(text2)) return null;
241891
+ return withinLimit(text2, REVERSALS_MAX_CHARS, "reversal list") ? text2 : null;
241892
+ } catch (error48) {
241893
+ if (!isSizeRelatedFailure(error48)) throw error48;
241894
+ console.warn("[ReviewBrief] reversal pass hit a size limit \u2014 skipping it:", error48.message);
241895
+ return null;
241896
+ }
241897
+ }
241898
+ async function generateIntentBriefWithModel(model, conversation, options = {}) {
241899
+ if (conversation.trim().length === 0) return null;
241900
+ try {
241901
+ const result = await generateText({
241902
+ model,
241903
+ system: SYSTEM_PROMPT2,
241904
+ prompt: buildBriefPrompt(conversation, options.reversals ?? null),
241905
+ timeout: JUDGMENT_TIMEOUT_MS,
241906
+ maxOutputTokens: BRIEF_MAX_TOKENS,
241907
+ experimental_telemetry: telemetryFor("review-intent-brief", options.userId)
241908
+ });
241909
+ const { text: rawText, finishReason } = result;
241910
+ const text2 = (rawText ?? "").trim();
241911
+ if (text2.length === 0) {
241912
+ console.warn(`[ReviewBrief] model returned empty text (finishReason: ${finishReason ?? "unknown"})`);
241913
+ return null;
241914
+ }
241915
+ if (finishReason === "length") return text2.slice(0, BRIEF_MAX_CHARS) + BRIEF_TRUNCATION_NOTE;
241916
+ return text2.length <= BRIEF_MAX_CHARS ? text2 : text2.slice(0, BRIEF_MAX_CHARS) + BRIEF_TRUNCATION_NOTE;
241917
+ } catch (error48) {
241918
+ if (options.rethrowSizeFailures && isSizeRelatedFailure(error48)) throw error48;
241919
+ console.warn("[ReviewBrief] AI generation failed:", error48.message);
241920
+ return null;
241921
+ }
241922
+ }
241923
+ async function distill(model, conversation, userId, rethrowSizeFailures) {
241924
+ const reversals = await extractReversalsWithModel(model, conversation, { userId });
241925
+ return generateIntentBriefWithModel(model, conversation, { userId, reversals, rethrowSizeFailures });
241926
+ }
241927
+ var BRIEF_CACHE_TTL_MS = 30 * 6e4;
241928
+ var BRIEF_CACHE_MAX_ENTRIES = 50;
241929
+ var briefCache = /* @__PURE__ */ new Map();
241930
+ var briefInFlight = /* @__PURE__ */ new Map();
241931
+ function cacheKey(userId, conversation) {
241932
+ return createHash5("sha256").update(userId).update("\0").update(conversation).digest("hex");
241933
+ }
241934
+ function readBriefCache(key) {
241935
+ const hit = briefCache.get(key);
241936
+ if (!hit) return null;
241937
+ if (Date.now() - hit.at > BRIEF_CACHE_TTL_MS) {
241938
+ briefCache.delete(key);
241939
+ return null;
241940
+ }
241941
+ return hit.brief;
241942
+ }
241943
+ function writeBriefCache(key, brief) {
241944
+ briefCache.set(key, { brief, at: Date.now() });
241945
+ while (briefCache.size > BRIEF_CACHE_MAX_ENTRIES) {
241946
+ const oldest = briefCache.keys().next();
241947
+ if (oldest.done) break;
241948
+ briefCache.delete(oldest.value);
241949
+ }
241950
+ }
241951
+ async function generateIntentBrief(storage, userId, messages) {
241952
+ let conversation;
241953
+ let mainOk;
241954
+ let fastOk;
241955
+ try {
241956
+ const config2 = await getChatProviderConfig(storage, userId);
241957
+ mainOk = isModelConfigured(config2, config2.main);
241958
+ fastOk = isModelConfigured(config2, config2.fast);
241959
+ if (!mainOk && !fastOk) return null;
241960
+ conversation = serializeConversationForBrief(messages);
241961
+ if (!conversation) return null;
241962
+ } catch (error48) {
241963
+ console.warn("[ReviewBrief] generation failed:", error48.message);
241964
+ return null;
241965
+ }
241966
+ const key = cacheKey(userId, conversation);
241967
+ const cached2 = readBriefCache(key);
241968
+ if (cached2 !== null) return cached2;
241969
+ const pending = briefInFlight.get(key);
241970
+ if (pending) return pending;
241971
+ const run2 = distillConversation(storage, userId, messages, conversation, mainOk, fastOk).then((brief) => {
241972
+ if (brief !== null) writeBriefCache(key, brief);
241973
+ return brief;
241974
+ }).finally(() => briefInFlight.delete(key));
241975
+ briefInFlight.set(key, run2);
241976
+ return run2;
241977
+ }
241978
+ async function distillConversation(storage, userId, messages, conversation, mainOk, fastOk) {
241979
+ try {
241980
+ const distillModel = mainOk ? await resolveChatModel(storage, userId) : await resolveFastChatModel(storage, userId);
241981
+ const compactModel = fastOk ? await resolveFastChatModel(storage, userId) : distillModel;
241982
+ if (conversation.length <= COMPACT_TRIGGER_CHARS) {
241983
+ try {
241984
+ const brief = await distill(distillModel, conversation, userId, true);
241985
+ return brief === null ? null : appendCompactionNote(brief, false);
241986
+ } catch (error48) {
241987
+ if (!isSizeRelatedFailure(error48)) throw error48;
241988
+ console.warn("[ReviewBrief] full conversation rejected as too large \u2014 compacting and retrying");
241989
+ }
241990
+ }
241991
+ for (const sliceChars of COMPACT_SLICE_BUDGETS) {
241992
+ try {
241993
+ const compacted = await compactConversation(compactModel, messages, { userId, sliceChars });
241994
+ if (compacted === null) return null;
241995
+ const brief = await distill(distillModel, compacted, userId, true);
241996
+ return brief === null ? null : appendCompactionNote(brief, true);
241997
+ } catch (error48) {
241998
+ if (!isSizeRelatedFailure(error48)) throw error48;
241999
+ console.warn(`[ReviewBrief] ${sliceChars}-char slices still too large \u2014 retrying smaller`);
242000
+ }
242001
+ }
242002
+ console.warn("[ReviewBrief] could not compact the conversation small enough \u2014 falling back to tier 2");
242003
+ return null;
242004
+ } catch (error48) {
242005
+ console.warn("[ReviewBrief] generation failed:", error48.message);
242006
+ return null;
242007
+ }
242008
+ }
242009
+
241565
242010
  // src/routes/agent-session-routes.ts
241566
- import { createHash as createHash5, randomUUID as randomUUID15 } from "crypto";
242011
+ import { createHash as createHash6, randomUUID as randomUUID15 } from "crypto";
241567
242012
 
241568
242013
  // src/protocol/model-suggestions.ts
241569
242014
  var MODEL_SUGGESTIONS = {
@@ -241609,7 +242054,7 @@ var routes12 = async (fastify2) => {
241609
242054
  }
241610
242055
  function instructionContentHash(content) {
241611
242056
  const canonical = typeof content === "string" ? JSON.stringify({ type: "string", content }) : JSON.stringify(content.map((part) => part.type === "text" ? { type: "text", text: part.text } : { type: "image", mediaType: part.mediaType, data: part.data }));
241612
- return createHash5("sha256").update(canonical).digest("hex");
242057
+ return createHash6("sha256").update(canonical).digest("hex");
241613
242058
  }
241614
242059
  function proxyAuto(remoteServerId, method, apiPath, body) {
241615
242060
  return proxyToRemoteAuto(remoteServerId, method, apiPath, body, {
@@ -242239,6 +242684,16 @@ var routes12 = async (fastify2) => {
242239
242684
  });
242240
242685
  }
242241
242686
  );
242687
+ fastify2.get(
242688
+ "/api/agent-sessions/:sessionId/brief-source",
242689
+ async (req, reply) => {
242690
+ const session = fastify2.agentSessionManager.getSession(req.params.sessionId);
242691
+ if (!session) return reply.code(404).send({ error: "Session not found" });
242692
+ return reply.code(200).send({
242693
+ messages: projectMessagesForBrief(fastify2.agentSessionManager.getMessages(req.params.sessionId))
242694
+ });
242695
+ }
242696
+ );
242242
242697
  fastify2.post("/api/agent-sessions/:sessionId/message", { bodyLimit: 10 * 1024 * 1024 }, async (req, reply) => {
242243
242698
  const authResult = requireUserFacingUserId(req, reply);
242244
242699
  if (authResult === null) return;
@@ -243377,7 +243832,7 @@ var chat_session_routes_default = (0, import_fastify_plugin16.default)(routes15,
243377
243832
 
243378
243833
  // src/routes/project-chat-routes.ts
243379
243834
  var import_fastify_plugin17 = __toESM(require_plugin2(), 1);
243380
- import { createHash as createHash6, randomUUID as randomUUID16 } from "crypto";
243835
+ import { createHash as createHash7, randomUUID as randomUUID16 } from "crypto";
243381
243836
  var MAX_TITLE_LENGTH = 200;
243382
243837
  var MAX_MESSAGE_LENGTH = 1e5;
243383
243838
  var THREAD_PAGE_LIMIT = 50;
@@ -243546,7 +244001,7 @@ var routes16 = async (fastify2) => {
243546
244001
  const body = parseCreateBody(req.body);
243547
244002
  if (!body) return reply.code(400).send({ error: "Body must contain only an optional non-empty message" });
243548
244003
  const createRequestId = body.createRequestId ?? randomUUID16();
243549
- const createPayloadHash = createHash6("sha256").update(JSON.stringify({ message: body.message ?? null })).digest("hex");
244004
+ const createPayloadHash = createHash7("sha256").update(JSON.stringify({ message: body.message ?? null })).digest("hex");
243550
244005
  let accepted;
243551
244006
  try {
243552
244007
  accepted = await fastify2.storage.projectChatThreads.createIdempotent({
@@ -244179,304 +244634,6 @@ var command_routes_default = (0, import_fastify_plugin21.default)(routes20, { na
244179
244634
 
244180
244635
  // src/routes/workflow-run-routes.ts
244181
244636
  var import_fastify_plugin22 = __toESM(require_plugin2(), 1);
244182
-
244183
- // src/utils/review-brief.ts
244184
- var BASE_TIMEOUT_MS = 15e3;
244185
- var JUDGMENT_TIMEOUT_MS = 9e4;
244186
- var TIMEOUT_MS_PER_1K_CHARS = 120;
244187
- var MAX_TIMEOUT_MS = 6e4;
244188
- var PER_MESSAGE_MAX_CHARS = 6e3;
244189
- var COMPACT_TRIGGER_CHARS = 12e4;
244190
- var COMPACT_SLICE_BUDGETS = [96e3, 24e3, 6e3];
244191
- var RECENT_VERBATIM_RATIO = 0.3;
244192
- var MIN_RECENT_VERBATIM_CHARS = 2e3;
244193
- var MAX_FOLD_CALLS = 8;
244194
- var COMPACT_SUMMARY_MAX_CHARS = 6e3;
244195
- var COMPACT_SUMMARY_MAX_TOKENS = 3e3;
244196
- var REVERSALS_MAX_CHARS = 2e3;
244197
- var REVERSALS_MAX_TOKENS = 2e3;
244198
- var BRIEF_MAX_CHARS = 4e3;
244199
- var BRIEF_MAX_TOKENS = 3e3;
244200
- var REVERSAL_MIN_CHARS = 6e3;
244201
- var SEP = "\n\n";
244202
- var COMPACTION_NOTE = "_Note: the source conversation was compressed before distillation \u2014 older turns were summarized rather than read verbatim._";
244203
- var BRIEF_TRUNCATION_NOTE = "\n\n_[brief truncated at the length limit \u2014 treat it as incomplete]_";
244204
- var SYSTEM_PROMPT2 = [
244205
- "You distill a coding-agent conversation into an intent brief for an independent code reviewer.",
244206
- "The reviewer will NOT see the conversation \u2014 only your brief plus the actual code, so capture what the code alone cannot show:",
244207
- "0. Dominant question \u2014 1 or 2 sentences: the single question the reviewer must answer to judge this work (what must actually work, toward what goal). Derive it from the conversation's own emphasis \u2014 what the user repeated, finally decided, or reversed course over \u2014 never from your own engineering judgment. If the conversation does not clearly support one, write 'unclear' instead of inventing one.",
244208
- "1. The original request and its goal.",
244209
- "2. Hard constraints \u2014 requirements whose violation the user would treat as failure regardless of everything else (security, data loss, an explicit compatibility or behaviour promise). Only list ones the user actually stated; an empty section is fine.",
244210
- "3. Constraints and decisions, including approaches that were rejected and why. A rejection counts whether the user made it or the agent made it under a principle the user set.",
244211
- "4. Non-goals, trade-offs and limitations that were acknowledged and accepted.",
244212
- "5. Behaviour established by actually running something \u2014 observed output, exit codes, error text, which stream an error arrived on. Report what was observed; that is evidence the reviewer cannot recover by reading code.",
244213
- "Tag every item under headings 3 and 4 with exactly [settled] or [tentative] \u2014 the bare tag; keep any justification to a few words or omit it, always after the tag, never inside the brackets. Settled ONLY when the user explicitly confirmed it, instructed it, or reversed course to it; an agent proposal the user never answered is tentative \u2014 silence is never settled.",
244214
- "Within each heading, order items by how much they matter to the dominant question, not by when they were said.",
244215
- "Later statements supersede earlier ones on the same topic. An option explored at length early is often rejected later in a single sentence, and the rejection wins. Where the conversation ends in a decision table or summary, that is authoritative wherever it conflicts with earlier prose.",
244216
- "The input may arrive as numbered compressed slices followed by verbatim recent turns. Slice numbers are chronological: a later slice overrules an earlier one.",
244217
- "Decisions the agent made that the user did not contradict are worth reporting, but user silence only ever yields tentative status.",
244218
- "Do NOT include the agent's self-assessment or any claim that the work is correct or complete \u2014 the reviewer must judge that independently.",
244219
- "Every statement must trace to something in the conversation. If a heading has nothing real to report, say so rather than inventing plausible-sounding content.",
244220
- "Write concise markdown bullets under those numbered headings, under 500 words total, in the same language as the conversation. Reply with the brief only."
244221
- ].join("\n");
244222
- var REVERSAL_SYSTEM_PROMPT = [
244223
- "You read a coding-agent conversation and report ONLY the conclusions that were later reversed, dropped, or replaced.",
244224
- "A design conversation converges by killing its own hypotheses: an option explored in depth early is often rejected later in one sentence, so weigh finality over how much was written.",
244225
- "A reversal counts whether the user or the agent made it. Ignore rewording that leaves the decision intact.",
244226
- "Output one line per reversal: SUPERSEDED: <what was concluded earlier> -> <what replaced it> (<why>)",
244227
- "Report the most decisive reversals first and stay under 200 words \u2014 a list that runs long will be discarded whole, so prioritise rather than pad.",
244228
- "If nothing was reversed, reply with exactly: NONE"
244229
- ].join("\n");
244230
- var COMPACT_SYSTEM_PROMPT = [
244231
- "You compress one slice of a coding-agent conversation. A later pass will distill the whole thing into an intent brief for a code reviewer.",
244232
- "You are told which slice of how many this is. Other slices are compressed separately and you cannot see them, so never present a conclusion here as final \u2014 a later slice may overturn it.",
244233
- "Preserve, in this order of priority:",
244234
- "1. Reversals and corrections \u2014 any conclusion that was dropped, replaced, or corrected. Quote the deciding sentence verbatim.",
244235
- "2. Constraints and decisions the user stated, and approaches that were rejected, with the reason. Preserve who made each decision \u2014 an explicit user confirmation must stay distinguishable from an agent proposal the user never answered; quote the user's deciding sentence when there is one.",
244236
- "3. Behaviour established by actually running something: observed output, exit codes, error text, which stream an error arrived on.",
244237
- "4. Trade-offs that were acknowledged and accepted.",
244238
- "Drop: exploration narrative, restated background, tool mechanics, and anything a reviewer could recover by reading the code.",
244239
- "Stay under 800 words. An over-long slice is discarded whole rather than cut short, so drop lower-priority material instead of running over.",
244240
- "Keep the conversation's own language. Reply with the compressed slice only, no preamble."
244241
- ].join("\n");
244242
- function timeoutForInput(chars) {
244243
- return Math.min(MAX_TIMEOUT_MS, BASE_TIMEOUT_MS + Math.floor(chars / 1e3) * TIMEOUT_MS_PER_1K_CHARS);
244244
- }
244245
- function isSizeRelatedFailure(error48) {
244246
- const err = error48;
244247
- if (err?.name === "AbortError" || err?.name === "TimeoutError") return true;
244248
- const message = err?.message ?? "";
244249
- return /context[ _-]?length|maximum context|too many tokens|token limit|prompt is too long|request too large|timed? ?out/i.test(
244250
- message
244251
- );
244252
- }
244253
- function withinLimit(text2, max, label) {
244254
- if (text2.length <= max) return true;
244255
- console.warn(`[ReviewBrief] ${label} ran to ${text2.length} chars (limit ${max}) \u2014 discarding rather than truncating`);
244256
- return false;
244257
- }
244258
- function capMessage(text2) {
244259
- return text2.length > PER_MESSAGE_MAX_CHARS ? text2.slice(0, PER_MESSAGE_MAX_CHARS) + "\u2026" : text2;
244260
- }
244261
- function toEntries(messages) {
244262
- const entries = [];
244263
- for (const msg of messages) {
244264
- if (!msg) continue;
244265
- if (msg.type === "user" && !msg.event) {
244266
- const text2 = extractUserText(msg.content).trim();
244267
- if (text2) entries.push({ role: "User", text: capMessage(text2) });
244268
- } else if (msg.type === "assistant" && typeof msg.content === "string") {
244269
- const text2 = msg.content.trim();
244270
- if (text2) entries.push({ role: "Agent", text: capMessage(text2) });
244271
- }
244272
- }
244273
- return entries;
244274
- }
244275
- function render(entry) {
244276
- return `${entry.role}: ${entry.text}`;
244277
- }
244278
- function renderAll(entries) {
244279
- return entries.map(render).join(SEP);
244280
- }
244281
- function serializeConversationForBrief(messages) {
244282
- return renderAll(toEntries(messages));
244283
- }
244284
- function splitRecent(entries, maxChars) {
244285
- let size = 0;
244286
- let i = entries.length;
244287
- while (i > 0) {
244288
- const len = render(entries[i - 1]).length + SEP.length;
244289
- if (size + len > maxChars) break;
244290
- size += len;
244291
- i--;
244292
- }
244293
- return { older: entries.slice(0, i), recent: entries.slice(i) };
244294
- }
244295
- function chunkEntries(entries, maxChars) {
244296
- const chunks = [];
244297
- let current = [];
244298
- let size = 0;
244299
- for (const entry of entries) {
244300
- const len = render(entry).length + SEP.length;
244301
- if (current.length > 0 && size + len > maxChars) {
244302
- chunks.push(current);
244303
- current = [];
244304
- size = 0;
244305
- }
244306
- current.push(entry);
244307
- size += len;
244308
- }
244309
- if (current.length > 0) chunks.push(current);
244310
- return chunks;
244311
- }
244312
- function telemetryFor(functionId, userId) {
244313
- return userId ? {
244314
- isEnabled: true,
244315
- functionId,
244316
- metadata: { userId, tags: ["vibedeckx", functionId] }
244317
- } : void 0;
244318
- }
244319
- async function compactChunk(model, chunk, part, total, userId) {
244320
- try {
244321
- const result = await generateText({
244322
- model,
244323
- system: COMPACT_SYSTEM_PROMPT,
244324
- prompt: `Slice ${part} of ${total}.
244325
-
244326
- ${chunk}`,
244327
- timeout: timeoutForInput(chunk.length),
244328
- maxOutputTokens: COMPACT_SUMMARY_MAX_TOKENS,
244329
- experimental_telemetry: telemetryFor("review-intent-brief-compact", userId)
244330
- });
244331
- const { text: rawText, finishReason } = result;
244332
- if (finishReason === "length") {
244333
- console.warn(`[ReviewBrief] slice ${part}/${total} summary hit the token cap \u2014 discarding`);
244334
- return null;
244335
- }
244336
- const text2 = (rawText ?? "").trim();
244337
- if (text2.length === 0) {
244338
- console.warn(`[ReviewBrief] slice ${part}/${total} came back empty (finishReason: ${finishReason ?? "unknown"})`);
244339
- return null;
244340
- }
244341
- return withinLimit(text2, COMPACT_SUMMARY_MAX_CHARS, `slice ${part}/${total} summary`) ? text2 : null;
244342
- } catch (error48) {
244343
- if (isSizeRelatedFailure(error48)) throw error48;
244344
- console.warn(`[ReviewBrief] compaction of slice ${part}/${total} failed:`, error48.message);
244345
- return null;
244346
- }
244347
- }
244348
- async function compactConversation(model, messages, options = {}) {
244349
- const sliceChars = options.sliceChars ?? COMPACT_SLICE_BUDGETS[0];
244350
- const recentChars = Math.max(MIN_RECENT_VERBATIM_CHARS, Math.floor(sliceChars * RECENT_VERBATIM_RATIO));
244351
- const entries = toEntries(messages);
244352
- if (entries.length === 0) return null;
244353
- const { older, recent } = splitRecent(entries, recentChars);
244354
- if (older.length === 0) return null;
244355
- const chunks = chunkEntries(older, sliceChars);
244356
- if (chunks.length > MAX_FOLD_CALLS) {
244357
- console.warn(
244358
- `[ReviewBrief] conversation needs ${chunks.length} slices of ${sliceChars} chars (max ${MAX_FOLD_CALLS}) \u2014 falling back to tier 2`
244359
- );
244360
- return null;
244361
- }
244362
- const settled = await Promise.allSettled(
244363
- chunks.map((chunk, i) => compactChunk(model, renderAll(chunk), i + 1, chunks.length, options.userId))
244364
- );
244365
- const sizeRejection = settled.find((r) => r.status === "rejected" && isSizeRelatedFailure(r.reason));
244366
- if (sizeRejection) throw sizeRejection.reason;
244367
- if (settled.some((r) => r.status === "rejected" || r.value === null)) return null;
244368
- const parts = settled.map(
244369
- (r, i) => `[Compressed slice ${i + 1} of ${chunks.length}]
244370
- ${r.value}`
244371
- );
244372
- if (recent.length > 0) parts.push(`[Recent turns, verbatim]
244373
- ${renderAll(recent)}`);
244374
- return parts.join(SEP);
244375
- }
244376
- function buildBriefPrompt(conversation, reversals) {
244377
- const preamble = reversals ? "Conclusions this conversation reversed. The right-hand side is the current state \u2014 never report the left-hand side as what was decided:\n" + reversals + SEP : "";
244378
- return `${preamble}Distill this conversation into an intent brief:
244379
-
244380
- ${conversation}`;
244381
- }
244382
- function appendCompactionNote(brief, compacted) {
244383
- return compacted ? `${brief}${SEP}${COMPACTION_NOTE}` : brief;
244384
- }
244385
- async function extractReversalsWithModel(model, conversation, options = {}) {
244386
- if (conversation.trim().length < REVERSAL_MIN_CHARS) return null;
244387
- try {
244388
- const result = await generateText({
244389
- model,
244390
- system: REVERSAL_SYSTEM_PROMPT,
244391
- prompt: `Report the reversals in this conversation:
244392
-
244393
- ${conversation}`,
244394
- timeout: JUDGMENT_TIMEOUT_MS,
244395
- maxOutputTokens: REVERSALS_MAX_TOKENS,
244396
- experimental_telemetry: telemetryFor("review-intent-brief-reversals", options.userId)
244397
- });
244398
- const { text: rawText, finishReason } = result;
244399
- if (finishReason === "length") {
244400
- console.warn("[ReviewBrief] reversal list hit the token cap \u2014 discarding");
244401
- return null;
244402
- }
244403
- const text2 = (rawText ?? "").trim();
244404
- if (text2.length === 0 || /^none\b/i.test(text2)) return null;
244405
- return withinLimit(text2, REVERSALS_MAX_CHARS, "reversal list") ? text2 : null;
244406
- } catch (error48) {
244407
- if (!isSizeRelatedFailure(error48)) throw error48;
244408
- console.warn("[ReviewBrief] reversal pass hit a size limit \u2014 skipping it:", error48.message);
244409
- return null;
244410
- }
244411
- }
244412
- async function generateIntentBriefWithModel(model, conversation, options = {}) {
244413
- if (conversation.trim().length === 0) return null;
244414
- try {
244415
- const result = await generateText({
244416
- model,
244417
- system: SYSTEM_PROMPT2,
244418
- prompt: buildBriefPrompt(conversation, options.reversals ?? null),
244419
- timeout: JUDGMENT_TIMEOUT_MS,
244420
- maxOutputTokens: BRIEF_MAX_TOKENS,
244421
- experimental_telemetry: telemetryFor("review-intent-brief", options.userId)
244422
- });
244423
- const { text: rawText, finishReason } = result;
244424
- const text2 = (rawText ?? "").trim();
244425
- if (text2.length === 0) {
244426
- console.warn(`[ReviewBrief] model returned empty text (finishReason: ${finishReason ?? "unknown"})`);
244427
- return null;
244428
- }
244429
- if (finishReason === "length") return text2.slice(0, BRIEF_MAX_CHARS) + BRIEF_TRUNCATION_NOTE;
244430
- return text2.length <= BRIEF_MAX_CHARS ? text2 : text2.slice(0, BRIEF_MAX_CHARS) + BRIEF_TRUNCATION_NOTE;
244431
- } catch (error48) {
244432
- if (options.rethrowSizeFailures && isSizeRelatedFailure(error48)) throw error48;
244433
- console.warn("[ReviewBrief] AI generation failed:", error48.message);
244434
- return null;
244435
- }
244436
- }
244437
- async function distill(model, conversation, userId, rethrowSizeFailures) {
244438
- const reversals = await extractReversalsWithModel(model, conversation, { userId });
244439
- return generateIntentBriefWithModel(model, conversation, { userId, reversals, rethrowSizeFailures });
244440
- }
244441
- async function generateIntentBrief(storage, userId, messages) {
244442
- try {
244443
- const config2 = await getChatProviderConfig(storage, userId);
244444
- const mainOk = isModelConfigured(config2, config2.main);
244445
- const fastOk = isModelConfigured(config2, config2.fast);
244446
- if (!mainOk && !fastOk) return null;
244447
- const conversation = serializeConversationForBrief(messages);
244448
- if (!conversation) return null;
244449
- const distillModel = mainOk ? await resolveChatModel(storage, userId) : await resolveFastChatModel(storage, userId);
244450
- const compactModel = fastOk ? await resolveFastChatModel(storage, userId) : distillModel;
244451
- if (conversation.length <= COMPACT_TRIGGER_CHARS) {
244452
- try {
244453
- const brief = await distill(distillModel, conversation, userId, true);
244454
- return brief === null ? null : appendCompactionNote(brief, false);
244455
- } catch (error48) {
244456
- if (!isSizeRelatedFailure(error48)) throw error48;
244457
- console.warn("[ReviewBrief] full conversation rejected as too large \u2014 compacting and retrying");
244458
- }
244459
- }
244460
- for (const sliceChars of COMPACT_SLICE_BUDGETS) {
244461
- try {
244462
- const compacted = await compactConversation(compactModel, messages, { userId, sliceChars });
244463
- if (compacted === null) return null;
244464
- const brief = await distill(distillModel, compacted, userId, true);
244465
- return brief === null ? null : appendCompactionNote(brief, true);
244466
- } catch (error48) {
244467
- if (!isSizeRelatedFailure(error48)) throw error48;
244468
- console.warn(`[ReviewBrief] ${sliceChars}-char slices still too large \u2014 retrying smaller`);
244469
- }
244470
- }
244471
- console.warn("[ReviewBrief] could not compact the conversation small enough \u2014 falling back to tier 2");
244472
- return null;
244473
- } catch (error48) {
244474
- console.warn("[ReviewBrief] generation failed:", error48.message);
244475
- return null;
244476
- }
244477
- }
244478
-
244479
- // src/routes/workflow-run-routes.ts
244480
244637
  function parseReviewerAgentType(raw) {
244481
244638
  if (raw === void 0) return void 0;
244482
244639
  return typeof raw === "string" && REVIEWER_AGENT_TYPES.has(raw) ? raw : null;
@@ -244539,7 +244696,7 @@ async function routes21(fastify2) {
244539
244696
  const historyResult = await proxyAuto(
244540
244697
  remoteInfo,
244541
244698
  "GET",
244542
- `/api/agent-sessions/${remoteInfo.remoteSessionId}`
244699
+ `/api/agent-sessions/${remoteInfo.remoteSessionId}/brief-source`
244543
244700
  );
244544
244701
  if (!historyResult.ok) return void 0;
244545
244702
  messages = historyResult.data.messages ?? [];
@@ -245476,6 +245633,7 @@ function attachRemoteProcessStream(fastify2, processId, send, onTerminal) {
245476
245633
  } catch {
245477
245634
  }
245478
245635
  if (!parsed) return;
245636
+ if ("keepalive" in parsed) return;
245479
245637
  send(parsed);
245480
245638
  if (parsed.type === "finished" || parsed.type === "error") terminalSignalSent = true;
245481
245639
  if (parsed.type === "finished" || parsed.type === "error") {
@@ -245630,6 +245788,47 @@ async function userOwnsSession(fastify2, sessionId, userId) {
245630
245788
  return !!await fastify2.storage.projects.getById(session.project_id, userId);
245631
245789
  }
245632
245790
 
245791
+ // src/utils/ws-heartbeat.ts
245792
+ var DEFAULT_INTERVAL_MS = 3e4;
245793
+ function attachWsHeartbeat(socket, { label, intervalMs = DEFAULT_INTERVAL_MS, keepalive = false }) {
245794
+ let awaitingPong = false;
245795
+ const markAlive = () => {
245796
+ awaitingPong = false;
245797
+ };
245798
+ socket.on("pong", markAlive);
245799
+ socket.on("message", markAlive);
245800
+ const timer = setInterval(() => {
245801
+ if (socket.readyState !== wrapper_default.OPEN) return;
245802
+ if (awaitingPong) {
245803
+ console.log(`[WsHeartbeat] ${label}: no pong within ${intervalMs * 2}ms \u2014 terminating dead socket`);
245804
+ try {
245805
+ socket.terminate();
245806
+ } catch {
245807
+ }
245808
+ return;
245809
+ }
245810
+ awaitingPong = true;
245811
+ try {
245812
+ socket.ping();
245813
+ } catch {
245814
+ }
245815
+ if (keepalive) {
245816
+ try {
245817
+ socket.send(JSON.stringify({ keepalive: Date.now() }));
245818
+ } catch {
245819
+ }
245820
+ }
245821
+ }, intervalMs);
245822
+ let cleaned = false;
245823
+ return () => {
245824
+ if (cleaned) return;
245825
+ cleaned = true;
245826
+ clearInterval(timer);
245827
+ socket.off("pong", markAlive);
245828
+ socket.off("message", markAlive);
245829
+ };
245830
+ }
245831
+
245633
245832
  // src/routes/websocket-routes.ts
245634
245833
  var routes24 = async (fastify2) => {
245635
245834
  fastify2.reverseConnectManager.setStatusChangeHandler((remoteServerId, status) => {
@@ -245688,10 +245887,14 @@ var routes24 = async (fastify2) => {
245688
245887
  }
245689
245888
  return;
245690
245889
  }
245890
+ const stopHeartbeat = attachWsHeartbeat(socket, {
245891
+ label: `ProjectChatWS thread=${req.params.threadId}`
245892
+ });
245691
245893
  let cleaned = false;
245692
245894
  const cleanup = () => {
245693
245895
  if (cleaned) return;
245694
245896
  cleaned = true;
245897
+ stopHeartbeat();
245695
245898
  unsubscribe();
245696
245899
  };
245697
245900
  socket.on("close", cleanup);
@@ -245723,11 +245926,9 @@ var routes24 = async (fastify2) => {
245723
245926
  return;
245724
245927
  }
245725
245928
  console.log(`[WebSocket] Client connected for process ${processId}`);
245726
- const pingInterval = setInterval(() => {
245727
- if (socket.readyState === wrapper_default.OPEN) {
245728
- socket.ping();
245729
- }
245730
- }, 3e4);
245929
+ const stopHeartbeat = attachWsHeartbeat(socket, {
245930
+ label: `ExecutorWS process=${processId}`
245931
+ });
245731
245932
  const send = (msg) => {
245732
245933
  try {
245733
245934
  socket.send(JSON.stringify(msg));
@@ -245753,7 +245954,7 @@ var routes24 = async (fastify2) => {
245753
245954
  });
245754
245955
  socket.on("close", () => {
245755
245956
  console.log(`[WebSocket] Client disconnected from process ${processId}`);
245756
- clearInterval(pingInterval);
245957
+ stopHeartbeat();
245757
245958
  handle.cleanup();
245758
245959
  });
245759
245960
  }
@@ -245769,11 +245970,7 @@ var routes24 = async (fastify2) => {
245769
245970
  return;
245770
245971
  }
245771
245972
  console.log(`[ExecutorMux] Client connected`);
245772
- const pingInterval = setInterval(() => {
245773
- if (socket.readyState === wrapper_default.OPEN) {
245774
- socket.ping();
245775
- }
245776
- }, 3e4);
245973
+ const stopHeartbeat = attachWsHeartbeat(socket, { label: "ExecutorMux" });
245777
245974
  const subs = /* @__PURE__ */ new Map();
245778
245975
  const handleInputMap = /* @__PURE__ */ new Map();
245779
245976
  const subscribeProcess = async (processId) => {
@@ -245832,7 +246029,7 @@ var routes24 = async (fastify2) => {
245832
246029
  });
245833
246030
  socket.on("close", () => {
245834
246031
  console.log(`[ExecutorMux] Client disconnected; cleaning ${subs.size} subscriptions`);
245835
- clearInterval(pingInterval);
246032
+ stopHeartbeat();
245836
246033
  for (const cleanup of subs.values()) cleanup();
245837
246034
  subs.clear();
245838
246035
  handleInputMap.clear();
@@ -245876,15 +246073,15 @@ var routes24 = async (fastify2) => {
245876
246073
  return;
245877
246074
  }
245878
246075
  console.log(`[AgentWS] Client connected for session ${sessionId}`);
245879
- const pingInterval = setInterval(() => {
245880
- if (socket.readyState === wrapper_default.OPEN) {
245881
- socket.ping();
245882
- }
245883
- }, 3e4);
246076
+ const stopHeartbeat = attachWsHeartbeat(socket, {
246077
+ label: `AgentWS session=${sessionId}`,
246078
+ keepalive: true
246079
+ });
245884
246080
  if (sessionId.startsWith("remote-")) {
245885
246081
  const remoteInfo = fastify2.remoteSessionMap.get(sessionId);
245886
246082
  if (!remoteInfo) {
245887
246083
  console.log(`[AgentWS] Remote session ${sessionId} not found in map`);
246084
+ stopHeartbeat();
245888
246085
  socket.send(JSON.stringify({ type: "error", message: "Remote session not found" }));
245889
246086
  socket.close();
245890
246087
  return;
@@ -245911,7 +246108,7 @@ var routes24 = async (fastify2) => {
245911
246108
  }
245912
246109
  cache2.addSubscriber(sessionId, socket);
245913
246110
  socket.on("close", () => {
245914
- clearInterval(pingInterval);
246111
+ stopHeartbeat();
245915
246112
  cache2.removeSubscriber(sessionId, socket);
245916
246113
  });
245917
246114
  return;
@@ -245952,7 +246149,7 @@ var routes24 = async (fastify2) => {
245952
246149
  });
245953
246150
  socket.on("close", () => {
245954
246151
  console.log(`[AgentWS] Client disconnected from remote session ${sessionId}`);
245955
- clearInterval(pingInterval);
246152
+ stopHeartbeat();
245956
246153
  cache2.removeSubscriber(sessionId, socket);
245957
246154
  });
245958
246155
  return;
@@ -245960,7 +246157,7 @@ var routes24 = async (fastify2) => {
245960
246157
  const unsubscribe = fastify2.agentSessionManager.subscribe(sessionId, socket);
245961
246158
  if (!unsubscribe) {
245962
246159
  console.log(`[AgentWS] Session ${sessionId} not found`);
245963
- clearInterval(pingInterval);
246160
+ stopHeartbeat();
245964
246161
  socket.send(JSON.stringify({ error: "Session not found" }));
245965
246162
  socket.close();
245966
246163
  return;
@@ -245979,7 +246176,7 @@ var routes24 = async (fastify2) => {
245979
246176
  });
245980
246177
  socket.on("close", () => {
245981
246178
  console.log(`[AgentWS] Client disconnected from session ${sessionId}`);
245982
- clearInterval(pingInterval);
246179
+ stopHeartbeat();
245983
246180
  unsubscribe?.();
245984
246181
  });
245985
246182
  }
@@ -246035,15 +246232,11 @@ var routes24 = async (fastify2) => {
246035
246232
  }
246036
246233
  }
246037
246234
  console.log(`[ChatWS] Client connected for session ${sessionId}`);
246038
- const pingInterval = setInterval(() => {
246039
- if (socket.readyState === wrapper_default.OPEN) {
246040
- socket.ping();
246041
- }
246042
- }, 3e4);
246235
+ const stopHeartbeat = attachWsHeartbeat(socket, { label: `ChatWS session=${sessionId}` });
246043
246236
  const unsubscribe = fastify2.chatSessionManager.subscribe(sessionId, socket);
246044
246237
  if (!unsubscribe) {
246045
246238
  console.log(`[ChatWS] Session ${sessionId} not found`);
246046
- clearInterval(pingInterval);
246239
+ stopHeartbeat();
246047
246240
  socket.send(JSON.stringify({ error: "Session not found" }));
246048
246241
  socket.close();
246049
246242
  return;
@@ -246063,7 +246256,7 @@ var routes24 = async (fastify2) => {
246063
246256
  });
246064
246257
  socket.on("close", () => {
246065
246258
  console.log(`[ChatWS] Client disconnected from session ${sessionId}`);
246066
- clearInterval(pingInterval);
246259
+ stopHeartbeat();
246067
246260
  unsubscribe?.();
246068
246261
  });
246069
246262
  }
@@ -246074,7 +246267,7 @@ var websocket_routes_default = (0, import_fastify_plugin25.default)(routes24, {
246074
246267
 
246075
246268
  // src/routes/reverse-connect-routes.ts
246076
246269
  var import_fastify_plugin26 = __toESM(require_plugin2(), 1);
246077
- import { randomBytes as randomBytes2, createHash as createHash7, verify as cryptoVerify } from "crypto";
246270
+ import { randomBytes as randomBytes2, createHash as createHash8, verify as cryptoVerify } from "crypto";
246078
246271
 
246079
246272
  // src/utils/rate-limited-warn.ts
246080
246273
  function createRateLimitedWarn(windowMs, maxKeys) {
@@ -246224,7 +246417,7 @@ var routes25 = async (fastify2) => {
246224
246417
  socket.close(4003, "Bad machine signature");
246225
246418
  return;
246226
246419
  }
246227
- const fingerprint = createHash7("sha256").update(publicKey).digest("hex");
246420
+ const fingerprint = createHash8("sha256").update(publicKey).digest("hex");
246228
246421
  const { owned, created } = await fastify2.storage.machineIdentity.claimOrVerify(fingerprint, publicKey, ownerId);
246229
246422
  if (!owned) {
246230
246423
  console.warn(`[ReverseConnect] Machine ${fingerprint.slice(0, 12)} owner mismatch \u2014 rejecting ${serverId}`);
@@ -248720,8 +248913,8 @@ var RotatingFileStream = class extends Writable {
248720
248913
  _final(callback) {
248721
248914
  this.refinal(void 0, callback);
248722
248915
  }
248723
- _write(chunk, encoding, callback) {
248724
- this.rewrite([{ chunk, encoding }], 0, callback);
248916
+ _write(chunk2, encoding, callback) {
248917
+ this.rewrite([{ chunk: chunk2, encoding }], 0, callback);
248725
248918
  }
248726
248919
  _writev(chunks, callback) {
248727
248920
  this.rewrite(chunks, 0, callback);
@@ -248745,13 +248938,13 @@ var RotatingFileStream = class extends Writable {
248745
248938
  if (this.initPromise)
248746
248939
  await this.initPromise;
248747
248940
  for (let i = 0; i < chunks.length; ++i) {
248748
- const { chunk } = chunks[i];
248749
- this.size += chunk.length;
248941
+ const { chunk: chunk2 } = chunks[i];
248942
+ this.size += chunk2.length;
248750
248943
  if (this.timeoutPromise)
248751
248944
  await this.timeoutPromise;
248752
- await this.file.write(chunk);
248945
+ await this.file.write(chunk2);
248753
248946
  if (teeToStdout && !this.stdout.destroyed)
248754
- this.stdout.write(chunk);
248947
+ this.stdout.write(chunk2);
248755
248948
  if (size && this.size >= size)
248756
248949
  await this.rotate();
248757
248950
  }
@@ -249772,6 +249965,9 @@ var WORKER_CAPABILITIES = {
249772
249965
  "http:POST /api/path/agent-sessions": { since: "0.2.0", summary: "\u521B\u5EFA\u4F1A\u8BDD" },
249773
249966
  "http:POST /api/path/agent-sessions/new": { since: "0.2.0", summary: "\u521B\u5EFA\u4F1A\u8BDD(\u6307\u5B9A ID)" },
249774
249967
  "http:GET /api/agent-sessions/:param": { since: "0.2.0", summary: "\u8BFB\u4F1A\u8BDD\u8BE6\u60C5/\u5BF9\u8BDD" },
249968
+ // Additive: a worker below 0.3.6 404s it and the hub's intent-brief
249969
+ // distillation degrades to the deterministic excerpt (tier 2).
249970
+ "http:GET /api/agent-sessions/:param/brief-source": { since: "0.3.6", summary: "\u8BFB\u4F1A\u8BDD\u5BF9\u8BDD(\u4EC5\u84B8\u998F\u7528\u6587\u672C)" },
249775
249971
  "http:POST /api/agent-sessions/:param/message": { since: "0.2.0", summary: "\u53D1\u6D88\u606F\u7ED9\u4F1A\u8BDD" },
249776
249972
  "http:POST /api/agent-sessions/:param/paste": { since: "0.2.0", summary: "\u7C98\u8D34\u56FE\u7247/\u957F\u6587\u672C" },
249777
249973
  "http:POST /api/agent-sessions/:param/stop": { since: "0.2.0", summary: "\u505C\u6B62\u4F1A\u8BDD turn" },