@aslaluroba/help-center-react 3.2.0 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6988,7 +6988,7 @@ var ably = {exports: {}};
6988
6988
  });
6989
6989
  return _withTimeoutAsync2.apply(this, arguments);
6990
6990
  }
6991
- var version = "2.13.0";
6991
+ var version = "2.15.0";
6992
6992
 
6993
6993
  // src/common/lib/util/defaults.ts
6994
6994
  var agent = "ably-js/" + version;
@@ -7236,10 +7236,10 @@ var ably = {exports: {}};
7236
7236
  };
7237
7237
  function defaultGetHeaders(options) {
7238
7238
  var {
7239
- format = defaultHeadersOptions.format,
7239
+ format,
7240
7240
  protocolVersion = defaultHeadersOptions.protocolVersion
7241
7241
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7242
- var accept = contentTypes[format];
7242
+ var accept = contentTypes[format != null ? format : options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */];
7243
7243
  return {
7244
7244
  accept,
7245
7245
  "X-Ably-Version": protocolVersion.toString(),
@@ -7248,11 +7248,11 @@ var ably = {exports: {}};
7248
7248
  }
7249
7249
  function defaultPostHeaders(options) {
7250
7250
  var {
7251
- format = defaultHeadersOptions.format,
7251
+ format,
7252
7252
  protocolVersion = defaultHeadersOptions.protocolVersion
7253
7253
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7254
- var contentType;
7255
- var accept = contentType = contentTypes[format];
7254
+ var accept = contentTypes[format != null ? format : options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */];
7255
+ var contentType = accept;
7256
7256
  return {
7257
7257
  accept,
7258
7258
  "content-type": contentType,
@@ -7576,7 +7576,9 @@ var ably = {exports: {}};
7576
7576
  tokenUri = function tokenUri(host) {
7577
7577
  return client.baseUri(host) + path;
7578
7578
  };
7579
- var requestHeaders = defaults_default.defaultPostHeaders(_this3.client.options);
7579
+ var requestHeaders = defaults_default.defaultPostHeaders(_this3.client.options, {
7580
+ format: "json" /* json */
7581
+ });
7580
7582
  if (resolvedAuthOptions.requestHeaders) _mixin(requestHeaders, resolvedAuthOptions.requestHeaders);
7581
7583
  logger_default.logAction(_this3.logger, logger_default.LOG_MICRO, "Auth.requestToken().requestToken", "Sending POST to " + path + "; Token params: " + JSON.stringify(signedTokenParams));
7582
7584
  _whenPromiseSettles(_this3.client.http.do(HttpMethods_default.Post, tokenUri, requestHeaders, JSON.stringify(signedTokenParams), null), (err, result) => err ? tokenCb(err) : tokenCb(result.error, result.body, result.unpacked));
@@ -9268,9 +9270,7 @@ var ably = {exports: {}};
9268
9270
  return _asyncToGenerator(function* () {
9269
9271
  var client = _this26.client;
9270
9272
  var format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9271
- headers = defaults_default.defaultPostHeaders(client.options, {
9272
- format
9273
- }),
9273
+ headers = defaults_default.defaultPostHeaders(client.options),
9274
9274
  params = {};
9275
9275
  var body = _mixin({
9276
9276
  recipient
@@ -9294,9 +9294,7 @@ var ably = {exports: {}};
9294
9294
  var client = _this27.client;
9295
9295
  var body = devicedetails_default.fromValues(device);
9296
9296
  var format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9297
- headers = defaults_default.defaultPostHeaders(client.options, {
9298
- format
9299
- }),
9297
+ headers = defaults_default.defaultPostHeaders(client.options),
9300
9298
  params = {};
9301
9299
  _mixin(headers, client.options.headers);
9302
9300
  if (client.options.pushFullWait) _mixin(params, {
@@ -9312,9 +9310,7 @@ var ably = {exports: {}};
9312
9310
  return _asyncToGenerator(function* () {
9313
9311
  var client = _this28.client,
9314
9312
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9315
- headers = defaults_default.defaultGetHeaders(client.options, {
9316
- format
9317
- }),
9313
+ headers = defaults_default.defaultGetHeaders(client.options),
9318
9314
  deviceId = deviceIdOrDetails.id || deviceIdOrDetails;
9319
9315
  if (typeof deviceId !== "string" || !deviceId.length) {
9320
9316
  throw new _ErrorInfo2("First argument to DeviceRegistrations#get must be a deviceId string or DeviceDetails", 4e4, 400);
@@ -9330,9 +9326,7 @@ var ably = {exports: {}};
9330
9326
  var client = _this29.client,
9331
9327
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9332
9328
  envelope = _this29.client.http.supportsLinkHeaders ? void 0 : format,
9333
- headers = defaults_default.defaultGetHeaders(client.options, {
9334
- format
9335
- });
9329
+ headers = defaults_default.defaultGetHeaders(client.options);
9336
9330
  _mixin(headers, client.options.headers);
9337
9331
  return new paginatedresource_default(client, "/push/deviceRegistrations", headers, envelope, /*#__PURE__*/function () {
9338
9332
  var _ref3 = _asyncToGenerator(function* (body, headers2, unpacked) {
@@ -9348,10 +9342,7 @@ var ably = {exports: {}};
9348
9342
  var _this30 = this;
9349
9343
  return _asyncToGenerator(function* () {
9350
9344
  var client = _this30.client,
9351
- format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9352
- headers = defaults_default.defaultGetHeaders(client.options, {
9353
- format
9354
- }),
9345
+ headers = defaults_default.defaultGetHeaders(client.options),
9355
9346
  params = {},
9356
9347
  deviceId = deviceIdOrDetails.id || deviceIdOrDetails;
9357
9348
  if (typeof deviceId !== "string" || !deviceId.length) {
@@ -9392,9 +9383,7 @@ var ably = {exports: {}};
9392
9383
  var client = _this32.client;
9393
9384
  var body = pushchannelsubscription_default.fromValues(subscription);
9394
9385
  var format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9395
- headers = defaults_default.defaultPostHeaders(client.options, {
9396
- format
9397
- }),
9386
+ headers = defaults_default.defaultPostHeaders(client.options),
9398
9387
  params = {};
9399
9388
  _mixin(headers, client.options.headers);
9400
9389
  if (client.options.pushFullWait) _mixin(params, {
@@ -9411,9 +9400,7 @@ var ably = {exports: {}};
9411
9400
  var client = _this33.client,
9412
9401
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9413
9402
  envelope = _this33.client.http.supportsLinkHeaders ? void 0 : format,
9414
- headers = defaults_default.defaultGetHeaders(client.options, {
9415
- format
9416
- });
9403
+ headers = defaults_default.defaultGetHeaders(client.options);
9417
9404
  _mixin(headers, client.options.headers);
9418
9405
  return new paginatedresource_default(client, "/push/channelSubscriptions", headers, envelope, /*#__PURE__*/function () {
9419
9406
  var _ref4 = _asyncToGenerator(function* (body, headers2, unpacked) {
@@ -9446,9 +9433,7 @@ var ably = {exports: {}};
9446
9433
  var client = _this35.client,
9447
9434
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9448
9435
  envelope = _this35.client.http.supportsLinkHeaders ? void 0 : format,
9449
- headers = defaults_default.defaultGetHeaders(client.options, {
9450
- format
9451
- });
9436
+ headers = defaults_default.defaultGetHeaders(client.options);
9452
9437
  _mixin(headers, client.options.headers);
9453
9438
  if (client.options.pushFullWait) _mixin(params, {
9454
9439
  fullWait: "true"
@@ -9611,9 +9596,7 @@ var ably = {exports: {}};
9611
9596
  var client = _this38.channel.client,
9612
9597
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9613
9598
  envelope = _this38.channel.client.http.supportsLinkHeaders ? void 0 : format,
9614
- headers = defaults_default.defaultGetHeaders(client.options, {
9615
- format
9616
- });
9599
+ headers = defaults_default.defaultGetHeaders(client.options);
9617
9600
  _mixin(headers, client.options.headers);
9618
9601
  return new paginatedresource_default(client, _this38.channel.client.rest.presenceMixin.basePath(_this38), headers, envelope, /*#__PURE__*/function () {
9619
9602
  var _ref6 = _asyncToGenerator(function* (body, headers2, unpacked) {
@@ -9737,6 +9720,21 @@ var ably = {exports: {}};
9737
9720
  } else if (!this.annotations.summary) {
9738
9721
  this.annotations.summary = {};
9739
9722
  }
9723
+ if (this.annotations && this.annotations.summary) {
9724
+ for (var [type, summaryEntry] of Object.entries(this.annotations.summary)) {
9725
+ if (type.endsWith(":distinct.v1") || type.endsWith(":unique.v1") || type.endsWith(":multiple.v1")) {
9726
+ for (var [, entry] of Object.entries(summaryEntry)) {
9727
+ if (!entry.clipped) {
9728
+ entry.clipped = false;
9729
+ }
9730
+ }
9731
+ } else if (type.endsWith(":flag.v1")) {
9732
+ if (!summaryEntry.clipped) {
9733
+ summaryEntry.clipped = false;
9734
+ }
9735
+ }
9736
+ }
9737
+ }
9740
9738
  }
9741
9739
  encode(options) {
9742
9740
  var _this40 = this;
@@ -9886,9 +9884,7 @@ var ably = {exports: {}};
9886
9884
  options = client.options,
9887
9885
  format = options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9888
9886
  idempotentRestPublishing = client.options.idempotentRestPublishing,
9889
- headers = defaults_default.defaultPostHeaders(client.options, {
9890
- format
9891
- });
9887
+ headers = defaults_default.defaultPostHeaders(client.options);
9892
9888
  _mixin(headers, options.headers);
9893
9889
  if (idempotentRestPublishing && allEmptyIds(messages)) {
9894
9890
  var msgIdBase = yield _randomString(MSG_ID_ENTROPY_BYTES);
@@ -9917,6 +9913,38 @@ var ably = {exports: {}};
9917
9913
  return _this46.client.rest.channelMixin.status(_this46);
9918
9914
  })();
9919
9915
  }
9916
+ getMessage(serialOrMessage) {
9917
+ var _this47 = this;
9918
+ return _asyncToGenerator(function* () {
9919
+ logger_default.logAction(_this47.logger, logger_default.LOG_MICRO, "RestChannel.getMessage()", "channel = " + _this47.name);
9920
+ return _this47.client.rest.channelMixin.getMessage(_this47, serialOrMessage);
9921
+ })();
9922
+ }
9923
+ updateMessage(message, operation, params) {
9924
+ var _this48 = this;
9925
+ return _asyncToGenerator(function* () {
9926
+ logger_default.logAction(_this48.logger, logger_default.LOG_MICRO, "RestChannel.updateMessage()", "channel = " + _this48.name);
9927
+ return _this48.client.rest.channelMixin.updateDeleteMessage(_this48, {
9928
+ isDelete: false
9929
+ }, message, operation, params);
9930
+ })();
9931
+ }
9932
+ deleteMessage(message, operation, params) {
9933
+ var _this49 = this;
9934
+ return _asyncToGenerator(function* () {
9935
+ logger_default.logAction(_this49.logger, logger_default.LOG_MICRO, "RestChannel.deleteMessage()", "channel = " + _this49.name);
9936
+ return _this49.client.rest.channelMixin.updateDeleteMessage(_this49, {
9937
+ isDelete: true
9938
+ }, message, operation, params);
9939
+ })();
9940
+ }
9941
+ getMessageVersions(serialOrMessage, params) {
9942
+ var _this50 = this;
9943
+ return _asyncToGenerator(function* () {
9944
+ logger_default.logAction(_this50.logger, logger_default.LOG_MICRO, "RestChannel.getMessageVersions()", "channel = " + _this50.name);
9945
+ return _this50.client.rest.channelMixin.getMessageVersions(_this50, serialOrMessage, params);
9946
+ })();
9947
+ }
9920
9948
  };
9921
9949
  var restchannel_default = RestChannel;
9922
9950
 
@@ -9945,9 +9973,7 @@ var ably = {exports: {}};
9945
9973
  var client = channel.client,
9946
9974
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9947
9975
  envelope = channel.client.http.supportsLinkHeaders ? void 0 : format,
9948
- headers = defaults_default.defaultGetHeaders(client.options, {
9949
- format
9950
- });
9976
+ headers = defaults_default.defaultGetHeaders(client.options);
9951
9977
  _mixin(headers, client.options.headers);
9952
9978
  return new paginatedresource_default(client, this.basePath(channel) + "/messages", headers, envelope, /*#__PURE__*/function () {
9953
9979
  var _ref7 = _asyncToGenerator(function* (body, headers2, unpacked) {
@@ -9960,16 +9986,81 @@ var ably = {exports: {}};
9960
9986
  }()).get(params);
9961
9987
  }
9962
9988
  static status(channel) {
9963
- var _this47 = this;
9989
+ var _this51 = this;
9964
9990
  return _asyncToGenerator(function* () {
9965
9991
  var format = channel.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */;
9966
- var headers = defaults_default.defaultPostHeaders(channel.client.options, {
9967
- format
9968
- });
9969
- var response = yield resource_default.get(channel.client, _this47.basePath(channel), headers, {}, format, true);
9992
+ var headers = defaults_default.defaultPostHeaders(channel.client.options);
9993
+ var response = yield resource_default.get(channel.client, _this51.basePath(channel), headers, {}, format, true);
9970
9994
  return response.body;
9971
9995
  })();
9972
9996
  }
9997
+ static getMessage(channel, serialOrMessage) {
9998
+ var _this52 = this;
9999
+ return _asyncToGenerator(function* () {
10000
+ var serial = typeof serialOrMessage === "string" ? serialOrMessage : serialOrMessage.serial;
10001
+ if (!serial) {
10002
+ throw new _ErrorInfo2('This message lacks a serial. Make sure you have enabled "Message annotations, updates, and deletes" in channel settings on your dashboard.', 40003, 400);
10003
+ }
10004
+ var client = channel.client;
10005
+ var format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */;
10006
+ var headers = defaults_default.defaultGetHeaders(client.options);
10007
+ _mixin(headers, client.options.headers);
10008
+ var {
10009
+ body,
10010
+ unpacked
10011
+ } = yield resource_default.get(client, _this52.basePath(channel) + "/messages/" + encodeURIComponent(serial), headers, {}, null, true);
10012
+ var decoded = unpacked ? body : _decodeBody(body, client._MsgPack, format);
10013
+ return _fromEncoded2(decoded, channel);
10014
+ })();
10015
+ }
10016
+ static updateDeleteMessage(channel, opts, message, operation, params) {
10017
+ var _this53 = this;
10018
+ return _asyncToGenerator(function* () {
10019
+ if (!message.serial) {
10020
+ throw new _ErrorInfo2('This message lacks a serial and cannot be updated. Make sure you have enabled "Message annotations, updates, and deletes" in channel settings on your dashboard.', 40003, 400);
10021
+ }
10022
+ var client = channel.client;
10023
+ var format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */;
10024
+ var headers = defaults_default.defaultPostHeaders(client.options);
10025
+ _mixin(headers, client.options.headers);
10026
+ var encoded = null;
10027
+ if (message.data !== void 0) {
10028
+ encoded = yield message_default.fromValues(message).encode(channel.channelOptions);
10029
+ }
10030
+ var req = {
10031
+ serial: message.serial,
10032
+ operation,
10033
+ name: message.name,
10034
+ data: encoded && encoded.data,
10035
+ encoding: encoded && encoded.encoding,
10036
+ extras: message.extras
10037
+ };
10038
+ var requestBody = serialize(req, client._MsgPack, format);
10039
+ var method = opts.isDelete ? resource_default.post : resource_default.patch;
10040
+ var pathSuffix = opts.isDelete ? "/delete" : "";
10041
+ yield method(client, _this53.basePath(channel) + "/messages/" + encodeURIComponent(message.serial) + pathSuffix, requestBody, headers, params || {}, null, true);
10042
+ })();
10043
+ }
10044
+ static getMessageVersions(channel, serialOrMessage, params) {
10045
+ var serial = typeof serialOrMessage === "string" ? serialOrMessage : serialOrMessage.serial;
10046
+ if (!serial) {
10047
+ throw new _ErrorInfo2('This message lacks a serial. Make sure you have enabled "Message annotations, updates, and deletes" in channel settings on your dashboard.', 40003, 400);
10048
+ }
10049
+ var client = channel.client;
10050
+ var format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */;
10051
+ var envelope = channel.client.http.supportsLinkHeaders ? void 0 : format;
10052
+ var headers = defaults_default.defaultGetHeaders(client.options);
10053
+ _mixin(headers, client.options.headers);
10054
+ return new paginatedresource_default(client, this.basePath(channel) + "/messages/" + encodeURIComponent(serial) + "/versions", headers, envelope, /*#__PURE__*/function () {
10055
+ var _ref8 = _asyncToGenerator(function* (body, headers2, unpacked) {
10056
+ var decoded = unpacked ? body : _decodeBody(body, client._MsgPack, format);
10057
+ return _fromEncodedArray2(decoded, channel);
10058
+ });
10059
+ return function (_x62, _x63, _x64) {
10060
+ return _ref8.apply(this, arguments);
10061
+ };
10062
+ }()).get(params || {});
10063
+ }
9973
10064
  };
9974
10065
 
9975
10066
  // src/common/lib/client/restpresencemixin.ts
@@ -9978,22 +10069,20 @@ var ably = {exports: {}};
9978
10069
  return RestChannelMixin.basePath(presence.channel) + "/presence";
9979
10070
  }
9980
10071
  static history(presence, params) {
9981
- var _this48 = this;
10072
+ var _this54 = this;
9982
10073
  return _asyncToGenerator(function* () {
9983
10074
  var client = presence.channel.client,
9984
10075
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
9985
10076
  envelope = presence.channel.client.http.supportsLinkHeaders ? void 0 : format,
9986
- headers = defaults_default.defaultGetHeaders(client.options, {
9987
- format
9988
- });
10077
+ headers = defaults_default.defaultGetHeaders(client.options);
9989
10078
  _mixin(headers, client.options.headers);
9990
- return new paginatedresource_default(client, _this48.basePath(presence) + "/history", headers, envelope, /*#__PURE__*/function () {
9991
- var _ref8 = _asyncToGenerator(function* (body, headers2, unpacked) {
10079
+ return new paginatedresource_default(client, _this54.basePath(presence) + "/history", headers, envelope, /*#__PURE__*/function () {
10080
+ var _ref9 = _asyncToGenerator(function* (body, headers2, unpacked) {
9992
10081
  var decoded = unpacked ? body : _decodeBody(body, client._MsgPack, format);
9993
10082
  return _fromEncodedArray(decoded, presence.channel);
9994
10083
  });
9995
- return function (_x62, _x63, _x64) {
9996
- return _ref8.apply(this, arguments);
10084
+ return function (_x65, _x66, _x67) {
10085
+ return _ref9.apply(this, arguments);
9997
10086
  };
9998
10087
  }()).get(params);
9999
10088
  })();
@@ -10015,32 +10104,39 @@ var ably = {exports: {}};
10015
10104
  this.push = new push_default(this.client);
10016
10105
  }
10017
10106
  stats(params) {
10018
- var _this49 = this;
10107
+ var _this55 = this;
10019
10108
  return _asyncToGenerator(function* () {
10020
- var headers = defaults_default.defaultGetHeaders(_this49.client.options),
10021
- format = _this49.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10022
- envelope = _this49.client.http.supportsLinkHeaders ? void 0 : format;
10023
- _mixin(headers, _this49.client.options.headers);
10024
- return new paginatedresource_default(_this49.client, "/stats", headers, envelope, function (body, headers2, unpacked) {
10025
- var statsValues = unpacked ? body : JSON.parse(body);
10026
- for (var i = 0; i < statsValues.length; i++) statsValues[i] = stats_default.fromValues(statsValues[i]);
10027
- return statsValues;
10028
- }).get(params);
10109
+ var headers = defaults_default.defaultGetHeaders(_this55.client.options),
10110
+ format = _this55.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10111
+ envelope = _this55.client.http.supportsLinkHeaders ? void 0 : format;
10112
+ _mixin(headers, _this55.client.options.headers);
10113
+ return new paginatedresource_default(_this55.client, "/stats", headers, envelope, /*#__PURE__*/function () {
10114
+ var _ref0 = _asyncToGenerator(function* (body, _, unpacked) {
10115
+ var statsValues = unpacked ? body : _decodeBody(body, _this55.client._MsgPack, format);
10116
+ for (var i = 0; i < statsValues.length; i++) statsValues[i] = stats_default.fromValues(statsValues[i]);
10117
+ return statsValues;
10118
+ });
10119
+ return function (_x68, _x69, _x70) {
10120
+ return _ref0.apply(this, arguments);
10121
+ };
10122
+ }()).get(params);
10029
10123
  })();
10030
10124
  }
10031
10125
  time(params) {
10032
- var _this50 = this;
10126
+ var _this56 = this;
10033
10127
  return _asyncToGenerator(function* () {
10034
- var headers = defaults_default.defaultGetHeaders(_this50.client.options);
10035
- if (_this50.client.options.headers) _mixin(headers, _this50.client.options.headers);
10128
+ var headers = defaults_default.defaultGetHeaders(_this56.client.options, {
10129
+ format: "json" /* json */
10130
+ });
10131
+ if (_this56.client.options.headers) _mixin(headers, _this56.client.options.headers);
10036
10132
  var timeUri = host => {
10037
- return _this50.client.baseUri(host) + "/time";
10133
+ return _this56.client.baseUri(host) + "/time";
10038
10134
  };
10039
10135
  var {
10040
10136
  error,
10041
10137
  body,
10042
10138
  unpacked
10043
- } = yield _this50.client.http.do(HttpMethods_default.Get, timeUri, headers, null, params);
10139
+ } = yield _this56.client.http.do(HttpMethods_default.Get, timeUri, headers, null, params);
10044
10140
  if (error) {
10045
10141
  throw error;
10046
10142
  }
@@ -10049,47 +10145,47 @@ var ably = {exports: {}};
10049
10145
  if (!time) {
10050
10146
  throw new _ErrorInfo2("Internal error (unexpected result type from GET /time)", 5e4, 500);
10051
10147
  }
10052
- _this50.client.serverTimeOffset = time - Date.now();
10148
+ _this56.client.serverTimeOffset = time - Date.now();
10053
10149
  return time;
10054
10150
  })();
10055
10151
  }
10056
10152
  request(method, path, version2, params, body, customHeaders) {
10057
- var _this51 = this;
10153
+ var _this57 = this;
10058
10154
  return _asyncToGenerator(function* () {
10059
10155
  var _a2;
10060
10156
  var [encoder, decoder, format] = (() => {
10061
- if (_this51.client.options.useBinaryProtocol) {
10062
- if (!_this51.client._MsgPack) {
10157
+ if (_this57.client.options.useBinaryProtocol) {
10158
+ if (!_this57.client._MsgPack) {
10063
10159
  _throwMissingPluginError("MsgPack");
10064
10160
  }
10065
- return [_this51.client._MsgPack.encode, _this51.client._MsgPack.decode, "msgpack" /* msgpack */];
10161
+ return [_this57.client._MsgPack.encode, _this57.client._MsgPack.decode, "msgpack" /* msgpack */];
10066
10162
  } else {
10067
10163
  return [JSON.stringify, JSON.parse, "json" /* json */];
10068
10164
  }
10069
10165
  })();
10070
- var envelope = _this51.client.http.supportsLinkHeaders ? void 0 : format;
10166
+ var envelope = _this57.client.http.supportsLinkHeaders ? void 0 : format;
10071
10167
  params = params || {};
10072
10168
  var _method = method.toLowerCase();
10073
- var headers = _method == "get" ? defaults_default.defaultGetHeaders(_this51.client.options, {
10169
+ var headers = _method == "get" ? defaults_default.defaultGetHeaders(_this57.client.options, {
10074
10170
  format,
10075
10171
  protocolVersion: version2
10076
- }) : defaults_default.defaultPostHeaders(_this51.client.options, {
10172
+ }) : defaults_default.defaultPostHeaders(_this57.client.options, {
10077
10173
  format,
10078
10174
  protocolVersion: version2
10079
10175
  });
10080
10176
  if (typeof body !== "string") {
10081
10177
  body = (_a2 = encoder(body)) != null ? _a2 : null;
10082
10178
  }
10083
- _mixin(headers, _this51.client.options.headers);
10179
+ _mixin(headers, _this57.client.options.headers);
10084
10180
  if (customHeaders) {
10085
10181
  _mixin(headers, customHeaders);
10086
10182
  }
10087
- var paginatedResource = new paginatedresource_default(_this51.client, path, headers, envelope, /*#__PURE__*/function () {
10088
- var _ref9 = _asyncToGenerator(function* (resbody, headers2, unpacked) {
10183
+ var paginatedResource = new paginatedresource_default(_this57.client, path, headers, envelope, /*#__PURE__*/function () {
10184
+ var _ref1 = _asyncToGenerator(function* (resbody, headers2, unpacked) {
10089
10185
  return _ensureArray(unpacked ? resbody : decoder(resbody));
10090
10186
  });
10091
- return function (_x65, _x66, _x67) {
10092
- return _ref9.apply(this, arguments);
10187
+ return function (_x71, _x72, _x73) {
10188
+ return _ref1.apply(this, arguments);
10093
10189
  };
10094
10190
  }(), /* useHttpPaginatedResponse: */
10095
10191
  true);
@@ -10104,7 +10200,7 @@ var ably = {exports: {}};
10104
10200
  })();
10105
10201
  }
10106
10202
  batchPublish(specOrSpecs) {
10107
- var _this52 = this;
10203
+ var _this58 = this;
10108
10204
  return _asyncToGenerator(function* () {
10109
10205
  var requestBodyDTO;
10110
10206
  var singleSpecMode;
@@ -10115,14 +10211,12 @@ var ably = {exports: {}};
10115
10211
  requestBodyDTO = [specOrSpecs];
10116
10212
  singleSpecMode = true;
10117
10213
  }
10118
- var format = _this52.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10119
- headers = defaults_default.defaultPostHeaders(_this52.client.options, {
10120
- format
10121
- });
10122
- if (_this52.client.options.headers) _mixin(headers, _this52.client.options.headers);
10123
- var requestBody = _encodeBody(requestBodyDTO, _this52.client._MsgPack, format);
10124
- var response = yield resource_default.post(_this52.client, "/messages", requestBody, headers, {}, null, true);
10125
- var batchResults = response.unpacked ? response.body : _decodeBody(response.body, _this52.client._MsgPack, format);
10214
+ var format = _this58.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10215
+ headers = defaults_default.defaultPostHeaders(_this58.client.options);
10216
+ if (_this58.client.options.headers) _mixin(headers, _this58.client.options.headers);
10217
+ var requestBody = _encodeBody(requestBodyDTO, _this58.client._MsgPack, format);
10218
+ var response = yield resource_default.post(_this58.client, "/messages", requestBody, headers, {}, null, true);
10219
+ var batchResults = response.unpacked ? response.body : _decodeBody(response.body, _this58.client._MsgPack, format);
10126
10220
  if (singleSpecMode) {
10127
10221
  return batchResults[0];
10128
10222
  } else {
@@ -10131,39 +10225,35 @@ var ably = {exports: {}};
10131
10225
  })();
10132
10226
  }
10133
10227
  batchPresence(channels) {
10134
- var _this53 = this;
10228
+ var _this59 = this;
10135
10229
  return _asyncToGenerator(function* () {
10136
- var format = _this53.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10137
- headers = defaults_default.defaultPostHeaders(_this53.client.options, {
10138
- format
10139
- });
10140
- if (_this53.client.options.headers) _mixin(headers, _this53.client.options.headers);
10230
+ var format = _this59.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10231
+ headers = defaults_default.defaultGetHeaders(_this59.client.options);
10232
+ if (_this59.client.options.headers) _mixin(headers, _this59.client.options.headers);
10141
10233
  var channelsParam = channels.join(",");
10142
- var response = yield resource_default.get(_this53.client, "/presence", headers, {
10234
+ var response = yield resource_default.get(_this59.client, "/presence", headers, {
10143
10235
  channels: channelsParam
10144
10236
  }, null, true);
10145
- return response.unpacked ? response.body : _decodeBody(response.body, _this53.client._MsgPack, format);
10237
+ return response.unpacked ? response.body : _decodeBody(response.body, _this59.client._MsgPack, format);
10146
10238
  })();
10147
10239
  }
10148
10240
  revokeTokens(specifiers, options) {
10149
- var _this54 = this;
10241
+ var _this60 = this;
10150
10242
  return _asyncToGenerator(function* () {
10151
- if (useTokenAuth(_this54.client.options)) {
10243
+ if (useTokenAuth(_this60.client.options)) {
10152
10244
  throw new _ErrorInfo2("Cannot revoke tokens when using token auth", 40162, 401);
10153
10245
  }
10154
- var keyName = _this54.client.options.keyName;
10246
+ var keyName = _this60.client.options.keyName;
10155
10247
  var resolvedOptions = options != null ? options : {};
10156
10248
  var requestBodyDTO = __spreadValues({
10157
10249
  targets: specifiers.map(specifier => "".concat(specifier.type, ":").concat(specifier.value))
10158
10250
  }, resolvedOptions);
10159
- var format = _this54.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10160
- headers = defaults_default.defaultPostHeaders(_this54.client.options, {
10161
- format
10162
- });
10163
- if (_this54.client.options.headers) _mixin(headers, _this54.client.options.headers);
10164
- var requestBody = _encodeBody(requestBodyDTO, _this54.client._MsgPack, format);
10165
- var response = yield resource_default.post(_this54.client, "/keys/".concat(keyName, "/revokeTokens"), requestBody, headers, {}, null, true);
10166
- return response.unpacked ? response.body : _decodeBody(response.body, _this54.client._MsgPack, format);
10251
+ var format = _this60.client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10252
+ headers = defaults_default.defaultPostHeaders(_this60.client.options);
10253
+ if (_this60.client.options.headers) _mixin(headers, _this60.client.options.headers);
10254
+ var requestBody = _encodeBody(requestBodyDTO, _this60.client._MsgPack, format);
10255
+ var response = yield resource_default.post(_this60.client, "/keys/".concat(keyName, "/revokeTokens"), requestBody, headers, {}, null, true);
10256
+ return response.unpacked ? response.body : _decodeBody(response.body, _this60.client._MsgPack, format);
10167
10257
  })();
10168
10258
  }
10169
10259
  };
@@ -10247,7 +10337,7 @@ var ably = {exports: {}};
10247
10337
 
10248
10338
  // src/common/lib/types/annotation.ts
10249
10339
  var actions4 = ["annotation.create", "annotation.delete"];
10250
- function fromEncoded3(_x68, _x69, _x70) {
10340
+ function fromEncoded3(_x74, _x75, _x76) {
10251
10341
  return _fromEncoded8.apply(this, arguments);
10252
10342
  }
10253
10343
  function _fromEncoded8() {
@@ -10257,7 +10347,7 @@ var ably = {exports: {}};
10257
10347
  });
10258
10348
  return _fromEncoded8.apply(this, arguments);
10259
10349
  }
10260
- function fromEncodedArray3(_x71, _x72, _x73) {
10350
+ function fromEncodedArray3(_x77, _x78, _x79) {
10261
10351
  return _fromEncodedArray8.apply(this, arguments);
10262
10352
  }
10263
10353
  function _fromEncodedArray8() {
@@ -10268,7 +10358,7 @@ var ably = {exports: {}};
10268
10358
  });
10269
10359
  return _fromEncodedArray8.apply(this, arguments);
10270
10360
  }
10271
- function _fromEncoded3(_x74, _x75) {
10361
+ function _fromEncoded3(_x80, _x81) {
10272
10362
  return _fromEncoded9.apply(this, arguments);
10273
10363
  }
10274
10364
  function _fromEncoded9() {
@@ -10277,7 +10367,7 @@ var ably = {exports: {}};
10277
10367
  });
10278
10368
  return _fromEncoded9.apply(this, arguments);
10279
10369
  }
10280
- function _fromEncodedArray3(_x76, _x77) {
10370
+ function _fromEncodedArray3(_x82, _x83) {
10281
10371
  return _fromEncodedArray9.apply(this, arguments);
10282
10372
  }
10283
10373
  function _fromEncodedArray9() {
@@ -10290,10 +10380,10 @@ var ably = {exports: {}};
10290
10380
  }
10291
10381
  var Annotation = class _Annotation extends BaseMessage {
10292
10382
  encode() {
10293
- var _this55 = this;
10383
+ var _this61 = this;
10294
10384
  return _asyncToGenerator(function* () {
10295
- var res = Object.assign(new WireAnnotation(), _this55, {
10296
- action: actions4.indexOf(_this55.action || "annotation.create")
10385
+ var res = Object.assign(new WireAnnotation(), _this61, {
10386
+ action: actions4.indexOf(_this61.action || "annotation.create")
10297
10387
  });
10298
10388
  return encode(res, {});
10299
10389
  })();
@@ -10322,10 +10412,10 @@ var ably = {exports: {}};
10322
10412
  return values.map(v => _WireAnnotation.fromValues(v));
10323
10413
  }
10324
10414
  decode(channelOptions, logger) {
10325
- var _this56 = this;
10415
+ var _this62 = this;
10326
10416
  return _asyncToGenerator(function* () {
10327
- var res = Object.assign(new Annotation(), __spreadProps(__spreadValues({}, _this56), {
10328
- action: actions4[_this56.action]
10417
+ var res = Object.assign(new Annotation(), __spreadProps(__spreadValues({}, _this62), {
10418
+ action: actions4[_this62.action]
10329
10419
  }));
10330
10420
  try {
10331
10421
  yield decode(res, channelOptions);
@@ -10394,47 +10484,43 @@ var ably = {exports: {}};
10394
10484
  this.channel = channel;
10395
10485
  }
10396
10486
  publish(msgOrSerial, annotationValues) {
10397
- var _this57 = this;
10487
+ var _this63 = this;
10398
10488
  return _asyncToGenerator(function* () {
10399
10489
  var annotation = constructValidateAnnotation(msgOrSerial, annotationValues);
10400
10490
  var wireAnnotation = yield annotation.encode();
10401
- var client = _this57.channel.client,
10491
+ var client = _this63.channel.client,
10402
10492
  options = client.options,
10403
10493
  format = options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10404
- headers = defaults_default.defaultPostHeaders(client.options, {
10405
- format
10406
- }),
10494
+ headers = defaults_default.defaultPostHeaders(client.options),
10407
10495
  params = {};
10408
10496
  _mixin(headers, client.options.headers);
10409
10497
  var requestBody = _encodeBody([wireAnnotation], client._MsgPack, format);
10410
- yield resource_default.post(client, basePathForSerial(_this57.channel, annotation.messageSerial), requestBody, headers, params, null, true);
10498
+ yield resource_default.post(client, basePathForSerial(_this63.channel, annotation.messageSerial), requestBody, headers, params, null, true);
10411
10499
  })();
10412
10500
  }
10413
10501
  delete(msgOrSerial, annotationValues) {
10414
- var _this58 = this;
10502
+ var _this64 = this;
10415
10503
  return _asyncToGenerator(function* () {
10416
10504
  annotationValues.action = "annotation.delete";
10417
- return _this58.publish(msgOrSerial, annotationValues);
10505
+ return _this64.publish(msgOrSerial, annotationValues);
10418
10506
  })();
10419
10507
  }
10420
10508
  get(msgOrSerial, params) {
10421
- var _this59 = this;
10509
+ var _this65 = this;
10422
10510
  return _asyncToGenerator(function* () {
10423
- var client = _this59.channel.client,
10511
+ var client = _this65.channel.client,
10424
10512
  messageSerial = serialFromMsgOrSerial(msgOrSerial),
10425
10513
  format = client.options.useBinaryProtocol ? "msgpack" /* msgpack */ : "json" /* json */,
10426
10514
  envelope = client.http.supportsLinkHeaders ? void 0 : format,
10427
- headers = defaults_default.defaultGetHeaders(client.options, {
10428
- format
10429
- });
10515
+ headers = defaults_default.defaultGetHeaders(client.options);
10430
10516
  _mixin(headers, client.options.headers);
10431
- return new paginatedresource_default(client, basePathForSerial(_this59.channel, messageSerial), headers, envelope, /*#__PURE__*/function () {
10432
- var _ref0 = _asyncToGenerator(function* (body, _, unpacked) {
10517
+ return new paginatedresource_default(client, basePathForSerial(_this65.channel, messageSerial), headers, envelope, /*#__PURE__*/function () {
10518
+ var _ref10 = _asyncToGenerator(function* (body, _, unpacked) {
10433
10519
  var decoded = unpacked ? body : _decodeBody(body, client._MsgPack, format);
10434
- return _fromEncodedArray3(decoded, _this59.channel);
10520
+ return _fromEncodedArray3(decoded, _this65.channel);
10435
10521
  });
10436
- return function (_x78, _x79, _x80) {
10437
- return _ref0.apply(this, arguments);
10522
+ return function (_x84, _x85, _x86) {
10523
+ return _ref10.apply(this, arguments);
10438
10524
  };
10439
10525
  }()).get(params);
10440
10526
  })();
@@ -10605,7 +10691,7 @@ var ably = {exports: {}};
10605
10691
  this._mode = 0;
10606
10692
  this.retryCount = 0;
10607
10693
  this.history = /*#__PURE__*/function () {
10608
- var _ref1 = _asyncToGenerator(function* (params) {
10694
+ var _ref11 = _asyncToGenerator(function* (params) {
10609
10695
  logger_default.logAction(this.logger, logger_default.LOG_MICRO, "RealtimeChannel.history()", "channel = " + this.name);
10610
10696
  var restMixin = this.client.rest.channelMixin;
10611
10697
  if (params && params.untilAttach) {
@@ -10620,8 +10706,8 @@ var ably = {exports: {}};
10620
10706
  }
10621
10707
  return restMixin.history(this, params);
10622
10708
  });
10623
- return function (_x81) {
10624
- return _ref1.apply(this, arguments);
10709
+ return function (_x87) {
10710
+ return _ref11.apply(this, arguments);
10625
10711
  };
10626
10712
  }();
10627
10713
  this.whenState = state => {
@@ -10700,20 +10786,20 @@ var ably = {exports: {}};
10700
10786
  return args;
10701
10787
  }
10702
10788
  setOptions(options) {
10703
- var _this60 = this;
10789
+ var _this66 = this;
10704
10790
  return _asyncToGenerator(function* () {
10705
10791
  var _a2;
10706
- var previousChannelOptions = _this60.channelOptions;
10792
+ var previousChannelOptions = _this66.channelOptions;
10707
10793
  var err = validateChannelOptions(options);
10708
10794
  if (err) {
10709
10795
  throw err;
10710
10796
  }
10711
- _this60.channelOptions = normaliseChannelOptions((_a2 = _this60.client._Crypto) != null ? _a2 : null, _this60.logger, options);
10712
- if (_this60._decodingContext) _this60._decodingContext.channelOptions = _this60.channelOptions;
10713
- if (_this60._shouldReattachToSetOptions(options, previousChannelOptions)) {
10714
- _this60.attachImpl();
10797
+ _this66.channelOptions = normaliseChannelOptions((_a2 = _this66.client._Crypto) != null ? _a2 : null, _this66.logger, options);
10798
+ if (_this66._decodingContext) _this66._decodingContext.channelOptions = _this66.channelOptions;
10799
+ if (_this66._shouldReattachToSetOptions(options, previousChannelOptions)) {
10800
+ _this66.attachImpl();
10715
10801
  return new Promise((resolve, reject) => {
10716
- _this60._allChannelChanges.once(["attached", "update", "detached", "failed"], function (stateChange) {
10802
+ _this66._allChannelChanges.once(["attached", "update", "detached", "failed"], function (stateChange) {
10717
10803
  switch (this.event) {
10718
10804
  case "update":
10719
10805
  case "attached":
@@ -10750,7 +10836,7 @@ var ably = {exports: {}};
10750
10836
  }
10751
10837
  publish() {
10752
10838
  var _arguments2 = arguments,
10753
- _this61 = this;
10839
+ _this67 = this;
10754
10840
  return _asyncToGenerator(function* () {
10755
10841
  var messages;
10756
10842
  var argCount = _arguments2.length;
@@ -10768,20 +10854,20 @@ var ably = {exports: {}};
10768
10854
  data: _arguments2.length <= 1 ? undefined : _arguments2[1]
10769
10855
  })];
10770
10856
  }
10771
- var maxMessageSize = _this61.client.options.maxMessageSize;
10772
- var wireMessages = yield encodeArray(messages, _this61.channelOptions);
10857
+ var maxMessageSize = _this67.client.options.maxMessageSize;
10858
+ var wireMessages = yield encodeArray(messages, _this67.channelOptions);
10773
10859
  var size = getMessagesSize(wireMessages);
10774
10860
  if (size > maxMessageSize) {
10775
10861
  throw new _ErrorInfo2("Maximum size of messages that can be published at once exceeded (was ".concat(size, " bytes; limit is ").concat(maxMessageSize, " bytes)"), 40009, 400);
10776
10862
  }
10777
- _this61.throwIfUnpublishableState();
10778
- logger_default.logAction(_this61.logger, logger_default.LOG_MICRO, "RealtimeChannel.publish()", "sending message; channel state is " + _this61.state + ", message count = " + wireMessages.length);
10863
+ _this67.throwIfUnpublishableState();
10864
+ logger_default.logAction(_this67.logger, logger_default.LOG_MICRO, "RealtimeChannel.publish()", "sending message; channel state is " + _this67.state + ", message count = " + wireMessages.length);
10779
10865
  var pm = fromValues({
10780
10866
  action: actions.MESSAGE,
10781
- channel: _this61.name,
10867
+ channel: _this67.name,
10782
10868
  messages: wireMessages
10783
10869
  });
10784
- return _this61.sendMessage(pm);
10870
+ return _this67.sendMessage(pm);
10785
10871
  })();
10786
10872
  }
10787
10873
  throwIfUnpublishableState() {
@@ -10801,13 +10887,13 @@ var ably = {exports: {}};
10801
10887
  }
10802
10888
  }
10803
10889
  attach() {
10804
- var _this62 = this;
10890
+ var _this68 = this;
10805
10891
  return _asyncToGenerator(function* () {
10806
- if (_this62.state === "attached") {
10892
+ if (_this68.state === "attached") {
10807
10893
  return null;
10808
10894
  }
10809
10895
  return new Promise((resolve, reject) => {
10810
- _this62._attach(false, null, (err, result) => err ? reject(err) : resolve(result));
10896
+ _this68._attach(false, null, (err, result) => err ? reject(err) : resolve(result));
10811
10897
  });
10812
10898
  })();
10813
10899
  }
@@ -10865,25 +10951,25 @@ var ably = {exports: {}};
10865
10951
  this.sendMessage(attachMsg).catch(noop);
10866
10952
  }
10867
10953
  detach() {
10868
- var _this63 = this;
10954
+ var _this69 = this;
10869
10955
  return _asyncToGenerator(function* () {
10870
- var connectionManager = _this63.connectionManager;
10956
+ var connectionManager = _this69.connectionManager;
10871
10957
  if (!connectionManager.activeState()) {
10872
10958
  throw connectionManager.getError();
10873
10959
  }
10874
- switch (_this63.state) {
10960
+ switch (_this69.state) {
10875
10961
  case "suspended":
10876
- _this63.notifyState("detached");
10962
+ _this69.notifyState("detached");
10877
10963
  return;
10878
10964
  case "detached":
10879
10965
  return;
10880
10966
  case "failed":
10881
10967
  throw new _ErrorInfo2("Unable to detach; channel state = failed", 90001, 400);
10882
10968
  default:
10883
- _this63.requestState("detaching");
10969
+ _this69.requestState("detaching");
10884
10970
  case "detaching":
10885
10971
  return new Promise((resolve, reject) => {
10886
- _this63.once(function (stateChange) {
10972
+ _this69.once(function (stateChange) {
10887
10973
  switch (this.event) {
10888
10974
  case "detached":
10889
10975
  resolve();
@@ -10912,22 +10998,22 @@ var ably = {exports: {}};
10912
10998
  }
10913
10999
  subscribe() {
10914
11000
  var _arguments3 = arguments,
10915
- _this64 = this;
11001
+ _this70 = this;
10916
11002
  return _asyncToGenerator(function* () {
10917
11003
  for (var _len0 = _arguments3.length, args = new Array(_len0), _key0 = 0; _key0 < _len0; _key0++) {
10918
11004
  args[_key0] = _arguments3[_key0];
10919
11005
  }
10920
11006
  var [event, listener] = _RealtimeChannel.processListenerArgs(args);
10921
- if (_this64.state === "failed") {
10922
- throw _ErrorInfo2.fromValues(_this64.invalidStateError());
11007
+ if (_this70.state === "failed") {
11008
+ throw _ErrorInfo2.fromValues(_this70.invalidStateError());
10923
11009
  }
10924
11010
  if (event && typeof event === "object" && !Array.isArray(event)) {
10925
- _this64.client._FilteredSubscriptions.subscribeFilter(_this64, event, listener);
11011
+ _this70.client._FilteredSubscriptions.subscribeFilter(_this70, event, listener);
10926
11012
  } else {
10927
- _this64.subscriptions.on(event, listener);
11013
+ _this70.subscriptions.on(event, listener);
10928
11014
  }
10929
- if (_this64.channelOptions.attachOnSubscribe !== false) {
10930
- return _this64.attach();
11015
+ if (_this70.channelOptions.attachOnSubscribe !== false) {
11016
+ return _this70.attach();
10931
11017
  } else {
10932
11018
  return null;
10933
11019
  }
@@ -10966,10 +11052,10 @@ var ably = {exports: {}};
10966
11052
  connectionManager.send(syncMessage);
10967
11053
  }
10968
11054
  sendMessage(msg) {
10969
- var _this65 = this;
11055
+ var _this71 = this;
10970
11056
  return _asyncToGenerator(function* () {
10971
11057
  return new Promise((resolve, reject) => {
10972
- _this65.connectionManager.send(msg, _this65.client.options.queueMessages, err => {
11058
+ _this71.connectionManager.send(msg, _this71.client.options.queueMessages, err => {
10973
11059
  if (err) {
10974
11060
  reject(err);
10975
11061
  } else {
@@ -10980,14 +11066,14 @@ var ably = {exports: {}};
10980
11066
  })();
10981
11067
  }
10982
11068
  sendPresence(presence) {
10983
- var _this66 = this;
11069
+ var _this72 = this;
10984
11070
  return _asyncToGenerator(function* () {
10985
11071
  var msg = fromValues({
10986
11072
  action: actions.PRESENCE,
10987
- channel: _this66.name,
11073
+ channel: _this72.name,
10988
11074
  presence
10989
11075
  });
10990
- return _this66.sendMessage(msg);
11076
+ return _this72.sendMessage(msg);
10991
11077
  })();
10992
11078
  }
10993
11079
  sendState(objectMessages) {
@@ -11000,61 +11086,61 @@ var ably = {exports: {}};
11000
11086
  }
11001
11087
  // Access to this method is synchronised by ConnectionManager#processChannelMessage, in order to synchronise access to the state stored in _decodingContext.
11002
11088
  processMessage(message) {
11003
- var _this67 = this;
11089
+ var _this73 = this;
11004
11090
  return _asyncToGenerator(function* () {
11005
11091
  if (message.action === actions.ATTACHED || message.action === actions.MESSAGE || message.action === actions.PRESENCE || message.action === actions.OBJECT || message.action === actions.ANNOTATION) {
11006
- _this67.setChannelSerial(message.channelSerial);
11092
+ _this73.setChannelSerial(message.channelSerial);
11007
11093
  }
11008
11094
  var syncChannelSerial,
11009
11095
  isSync = false;
11010
11096
  switch (message.action) {
11011
11097
  case actions.ATTACHED:
11012
11098
  {
11013
- _this67.properties.attachSerial = message.channelSerial;
11014
- _this67._mode = message.getMode();
11015
- _this67.params = message.params || {};
11099
+ _this73.properties.attachSerial = message.channelSerial;
11100
+ _this73._mode = message.getMode();
11101
+ _this73.params = message.params || {};
11016
11102
  var modesFromFlags = message.decodeModesFromFlags();
11017
- _this67.modes = modesFromFlags && _allToLowerCase(modesFromFlags) || void 0;
11103
+ _this73.modes = modesFromFlags && _allToLowerCase(modesFromFlags) || void 0;
11018
11104
  var resumed = message.hasFlag("RESUMED");
11019
11105
  var hasPresence = message.hasFlag("HAS_PRESENCE");
11020
11106
  var hasBacklog = message.hasFlag("HAS_BACKLOG");
11021
11107
  var hasObjects = message.hasFlag("HAS_OBJECTS");
11022
- if (_this67.state === "attached") {
11108
+ if (_this73.state === "attached") {
11023
11109
  if (!resumed) {
11024
- if (_this67._presence) {
11025
- _this67._presence.onAttached(hasPresence);
11110
+ if (_this73._presence) {
11111
+ _this73._presence.onAttached(hasPresence);
11026
11112
  }
11027
- if (_this67._objects) {
11028
- _this67._objects.onAttached(hasObjects);
11113
+ if (_this73._objects) {
11114
+ _this73._objects.onAttached(hasObjects);
11029
11115
  }
11030
11116
  }
11031
- var change = new channelstatechange_default(_this67.state, _this67.state, resumed, hasBacklog, message.error);
11032
- _this67._allChannelChanges.emit("update", change);
11033
- if (!resumed || _this67.channelOptions.updateOnAttached) {
11034
- _this67.emit("update", change);
11117
+ var change = new channelstatechange_default(_this73.state, _this73.state, resumed, hasBacklog, message.error);
11118
+ _this73._allChannelChanges.emit("update", change);
11119
+ if (!resumed || _this73.channelOptions.updateOnAttached) {
11120
+ _this73.emit("update", change);
11035
11121
  }
11036
- } else if (_this67.state === "detaching") {
11037
- _this67.checkPendingState();
11122
+ } else if (_this73.state === "detaching") {
11123
+ _this73.checkPendingState();
11038
11124
  } else {
11039
- _this67.notifyState("attached", message.error, resumed, hasPresence, hasBacklog, hasObjects);
11125
+ _this73.notifyState("attached", message.error, resumed, hasPresence, hasBacklog, hasObjects);
11040
11126
  }
11041
11127
  break;
11042
11128
  }
11043
11129
  case actions.DETACHED:
11044
11130
  {
11045
11131
  var detachErr = message.error ? _ErrorInfo2.fromValues(message.error) : new _ErrorInfo2("Channel detached", 90001, 404);
11046
- if (_this67.state === "detaching") {
11047
- _this67.notifyState("detached", detachErr);
11048
- } else if (_this67.state === "attaching") {
11049
- _this67.notifyState("suspended", detachErr);
11050
- } else if (_this67.state === "attached" || _this67.state === "suspended") {
11051
- _this67.requestState("attaching", detachErr);
11132
+ if (_this73.state === "detaching") {
11133
+ _this73.notifyState("detached", detachErr);
11134
+ } else if (_this73.state === "attaching") {
11135
+ _this73.notifyState("suspended", detachErr);
11136
+ } else if (_this73.state === "attached" || _this73.state === "suspended") {
11137
+ _this73.requestState("attaching", detachErr);
11052
11138
  }
11053
11139
  break;
11054
11140
  }
11055
11141
  case actions.SYNC:
11056
11142
  isSync = true;
11057
- syncChannelSerial = _this67.syncChannelSerial = message.channelSerial;
11143
+ syncChannelSerial = _this73.syncChannelSerial = message.channelSerial;
11058
11144
  if (!message.presence) break;
11059
11145
  case actions.PRESENCE:
11060
11146
  {
@@ -11062,45 +11148,45 @@ var ably = {exports: {}};
11062
11148
  break;
11063
11149
  }
11064
11150
  populateFieldsFromParent(message);
11065
- var options = _this67.channelOptions;
11066
- if (_this67._presence) {
11151
+ var options = _this73.channelOptions;
11152
+ if (_this73._presence) {
11067
11153
  var presenceMessages = yield Promise.all(message.presence.map(wpm => {
11068
- return wpm.decode(options, _this67.logger);
11154
+ return wpm.decode(options, _this73.logger);
11069
11155
  }));
11070
- _this67._presence.setPresence(presenceMessages, isSync, syncChannelSerial);
11156
+ _this73._presence.setPresence(presenceMessages, isSync, syncChannelSerial);
11071
11157
  }
11072
11158
  break;
11073
11159
  }
11074
11160
  case actions.OBJECT:
11075
11161
  case actions.OBJECT_SYNC:
11076
11162
  {
11077
- if (!_this67._objects || !message.state) {
11163
+ if (!_this73._objects || !message.state) {
11078
11164
  return;
11079
11165
  }
11080
11166
  populateFieldsFromParent(message);
11081
- var format = _this67.client.connection.connectionManager.getActiveTransportFormat();
11082
- var objectMessages = message.state.map(om => om.decode(_this67.client, format));
11167
+ var format = _this73.client.connection.connectionManager.getActiveTransportFormat();
11168
+ var objectMessages = message.state.map(om => om.decode(_this73.client, format));
11083
11169
  if (message.action === actions.OBJECT) {
11084
- _this67._objects.handleObjectMessages(objectMessages);
11170
+ _this73._objects.handleObjectMessages(objectMessages);
11085
11171
  } else {
11086
- _this67._objects.handleObjectSyncMessages(objectMessages, message.channelSerial);
11172
+ _this73._objects.handleObjectSyncMessages(objectMessages, message.channelSerial);
11087
11173
  }
11088
11174
  break;
11089
11175
  }
11090
11176
  case actions.MESSAGE:
11091
11177
  {
11092
- if (_this67.state !== "attached") {
11093
- logger_default.logAction(_this67.logger, logger_default.LOG_MAJOR, "RealtimeChannel.processMessage()", 'Message "' + message.id + '" skipped as this channel "' + _this67.name + '" state is not "attached" (state is "' + _this67.state + '").');
11178
+ if (_this73.state !== "attached") {
11179
+ logger_default.logAction(_this73.logger, logger_default.LOG_MAJOR, "RealtimeChannel.processMessage()", 'Message "' + message.id + '" skipped as this channel "' + _this73.name + '" state is not "attached" (state is "' + _this73.state + '").');
11094
11180
  return;
11095
11181
  }
11096
11182
  populateFieldsFromParent(message);
11097
11183
  var encoded = message.messages,
11098
11184
  firstMessage = encoded[0],
11099
11185
  lastMessage = encoded[encoded.length - 1];
11100
- if (firstMessage.extras && firstMessage.extras.delta && firstMessage.extras.delta.from !== _this67._lastPayload.messageId) {
11101
- var msg = 'Delta message decode failure - previous message not available for message "' + message.id + '" on this channel "' + _this67.name + '".';
11102
- logger_default.logAction(_this67.logger, logger_default.LOG_ERROR, "RealtimeChannel.processMessage()", msg);
11103
- _this67._startDecodeFailureRecovery(new _ErrorInfo2(msg, 40018, 400));
11186
+ if (firstMessage.extras && firstMessage.extras.delta && firstMessage.extras.delta.from !== _this73._lastPayload.messageId) {
11187
+ var msg = 'Delta message decode failure - previous message not available for message "' + message.id + '" on this channel "' + _this73.name + '".';
11188
+ logger_default.logAction(_this73.logger, logger_default.LOG_ERROR, "RealtimeChannel.processMessage()", msg);
11189
+ _this73._startDecodeFailureRecovery(new _ErrorInfo2(msg, 40018, 400));
11104
11190
  break;
11105
11191
  }
11106
11192
  var messages = [];
@@ -11108,34 +11194,34 @@ var ably = {exports: {}};
11108
11194
  var {
11109
11195
  decoded,
11110
11196
  err
11111
- } = yield encoded[i].decodeWithErr(_this67._decodingContext, _this67.logger);
11197
+ } = yield encoded[i].decodeWithErr(_this73._decodingContext, _this73.logger);
11112
11198
  messages[i] = decoded;
11113
11199
  if (err) {
11114
11200
  switch (err.code) {
11115
11201
  case 40018:
11116
- _this67._startDecodeFailureRecovery(err);
11202
+ _this73._startDecodeFailureRecovery(err);
11117
11203
  return;
11118
11204
  case 40019:
11119
11205
  case 40021:
11120
- _this67.notifyState("failed", err);
11206
+ _this73.notifyState("failed", err);
11121
11207
  return;
11122
11208
  }
11123
11209
  }
11124
11210
  }
11125
- _this67._lastPayload.messageId = lastMessage.id;
11126
- _this67._lastPayload.protocolMessageChannelSerial = message.channelSerial;
11127
- _this67.onEvent(messages);
11211
+ _this73._lastPayload.messageId = lastMessage.id;
11212
+ _this73._lastPayload.protocolMessageChannelSerial = message.channelSerial;
11213
+ _this73.onEvent(messages);
11128
11214
  break;
11129
11215
  }
11130
11216
  case actions.ANNOTATION:
11131
11217
  {
11132
11218
  populateFieldsFromParent(message);
11133
- var _options = _this67.channelOptions;
11134
- if (_this67._annotations) {
11219
+ var _options = _this73.channelOptions;
11220
+ if (_this73._annotations) {
11135
11221
  var annotations = yield Promise.all((message.annotations || []).map(wpm => {
11136
- return wpm.decode(_options, _this67.logger);
11222
+ return wpm.decode(_options, _this73.logger);
11137
11223
  }));
11138
- _this67._annotations._processIncoming(annotations);
11224
+ _this73._annotations._processIncoming(annotations);
11139
11225
  }
11140
11226
  break;
11141
11227
  }
@@ -11143,14 +11229,14 @@ var ably = {exports: {}};
11143
11229
  {
11144
11230
  var _err = message.error;
11145
11231
  if (_err && _err.code == 80016) {
11146
- _this67.checkPendingState();
11232
+ _this73.checkPendingState();
11147
11233
  } else {
11148
- _this67.notifyState("failed", _ErrorInfo2.fromValues(_err));
11234
+ _this73.notifyState("failed", _ErrorInfo2.fromValues(_err));
11149
11235
  }
11150
11236
  break;
11151
11237
  }
11152
11238
  default:
11153
- logger_default.logAction(_this67.logger, logger_default.LOG_MAJOR, "RealtimeChannel.processMessage()", "Protocol error: unrecognised message action (" + message.action + ")");
11239
+ logger_default.logAction(_this73.logger, logger_default.LOG_MAJOR, "RealtimeChannel.processMessage()", "Protocol error: unrecognised message action (" + message.action + ")");
11154
11240
  }
11155
11241
  })();
11156
11242
  }
@@ -11306,9 +11392,45 @@ var ably = {exports: {}};
11306
11392
  }
11307
11393
  }
11308
11394
  status() {
11309
- var _this68 = this;
11395
+ var _this74 = this;
11396
+ return _asyncToGenerator(function* () {
11397
+ return _this74.client.rest.channelMixin.status(_this74);
11398
+ })();
11399
+ }
11400
+ getMessage(serialOrMessage) {
11401
+ var _this75 = this;
11402
+ return _asyncToGenerator(function* () {
11403
+ logger_default.logAction(_this75.logger, logger_default.LOG_MICRO, "RealtimeChannel.getMessage()", "channel = " + _this75.name);
11404
+ var restMixin = _this75.client.rest.channelMixin;
11405
+ return restMixin.getMessage(_this75, serialOrMessage);
11406
+ })();
11407
+ }
11408
+ updateMessage(message, operation, params) {
11409
+ var _this76 = this;
11410
+ return _asyncToGenerator(function* () {
11411
+ logger_default.logAction(_this76.logger, logger_default.LOG_MICRO, "RealtimeChannel.updateMessage()", "channel = " + _this76.name);
11412
+ var restMixin = _this76.client.rest.channelMixin;
11413
+ return restMixin.updateDeleteMessage(_this76, {
11414
+ isDelete: false
11415
+ }, message, operation, params);
11416
+ })();
11417
+ }
11418
+ deleteMessage(message, operation, params) {
11419
+ var _this77 = this;
11420
+ return _asyncToGenerator(function* () {
11421
+ logger_default.logAction(_this77.logger, logger_default.LOG_MICRO, "RealtimeChannel.deleteMessage()", "channel = " + _this77.name);
11422
+ var restMixin = _this77.client.rest.channelMixin;
11423
+ return restMixin.updateDeleteMessage(_this77, {
11424
+ isDelete: true
11425
+ }, message, operation, params);
11426
+ })();
11427
+ }
11428
+ getMessageVersions(serialOrMessage, params) {
11429
+ var _this78 = this;
11310
11430
  return _asyncToGenerator(function* () {
11311
- return _this68.client.rest.channelMixin.status(_this68);
11431
+ logger_default.logAction(_this78.logger, logger_default.LOG_MICRO, "RealtimeChannel.getMessageVersions()", "channel = " + _this78.name);
11432
+ var restMixin = _this78.client.rest.channelMixin;
11433
+ return restMixin.getMessageVersions(_this78, serialOrMessage, params);
11312
11434
  })();
11313
11435
  }
11314
11436
  };
@@ -11327,31 +11449,31 @@ var ably = {exports: {}};
11327
11449
  this.subscriptions = new eventemitter_default(this.logger);
11328
11450
  }
11329
11451
  publish(msgOrSerial, annotationValues) {
11330
- var _this69 = this;
11452
+ var _this79 = this;
11331
11453
  return _asyncToGenerator(function* () {
11332
- var channelName = _this69.channel.name;
11454
+ var channelName = _this79.channel.name;
11333
11455
  var annotation = constructValidateAnnotation(msgOrSerial, annotationValues);
11334
11456
  var wireAnnotation = yield annotation.encode();
11335
- _this69.channel.throwIfUnpublishableState();
11336
- logger_default.logAction(_this69.logger, logger_default.LOG_MICRO, "RealtimeAnnotations.publish()", "channelName = " + channelName + ", sending annotation with messageSerial = " + annotation.messageSerial + ", type = " + annotation.type);
11457
+ _this79.channel.throwIfUnpublishableState();
11458
+ logger_default.logAction(_this79.logger, logger_default.LOG_MICRO, "RealtimeAnnotations.publish()", "channelName = " + channelName + ", sending annotation with messageSerial = " + annotation.messageSerial + ", type = " + annotation.type);
11337
11459
  var pm = fromValues({
11338
11460
  action: actions.ANNOTATION,
11339
11461
  channel: channelName,
11340
11462
  annotations: [wireAnnotation]
11341
11463
  });
11342
- return _this69.channel.sendMessage(pm);
11464
+ return _this79.channel.sendMessage(pm);
11343
11465
  })();
11344
11466
  }
11345
11467
  delete(msgOrSerial, annotationValues) {
11346
- var _this70 = this;
11468
+ var _this80 = this;
11347
11469
  return _asyncToGenerator(function* () {
11348
11470
  annotationValues.action = "annotation.delete";
11349
- return _this70.publish(msgOrSerial, annotationValues);
11471
+ return _this80.publish(msgOrSerial, annotationValues);
11350
11472
  })();
11351
11473
  }
11352
11474
  subscribe() {
11353
11475
  var _arguments4 = arguments,
11354
- _this71 = this;
11476
+ _this81 = this;
11355
11477
  return _asyncToGenerator(function* () {
11356
11478
  for (var _len10 = _arguments4.length, _args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
11357
11479
  _args[_key10] = _arguments4[_key10];
@@ -11359,15 +11481,15 @@ var ably = {exports: {}};
11359
11481
  var args = realtimechannel_default.processListenerArgs(_args);
11360
11482
  var event = args[0];
11361
11483
  var listener = args[1];
11362
- var channel = _this71.channel;
11484
+ var channel = _this81.channel;
11363
11485
  if (channel.state === "failed") {
11364
11486
  throw _ErrorInfo2.fromValues(channel.invalidStateError());
11365
11487
  }
11366
- _this71.subscriptions.on(event, listener);
11367
- if (_this71.channel.channelOptions.attachOnSubscribe !== false) {
11488
+ _this81.subscriptions.on(event, listener);
11489
+ if (_this81.channel.channelOptions.attachOnSubscribe !== false) {
11368
11490
  yield channel.attach();
11369
11491
  }
11370
- if ((_this71.channel.state === "attached" && _this71.channel._mode & flags.ANNOTATION_SUBSCRIBE) === 0) {
11492
+ if ((_this81.channel.state === "attached" && _this81.channel._mode & flags.ANNOTATION_SUBSCRIBE) === 0) {
11371
11493
  throw new _ErrorInfo2("You are trying to add an annotation listener, but you haven't requested the annotation_subscribe channel mode in ChannelOptions, so this won't do anything (we only deliver annotations to clients who have explicitly requested them)", 93001, 400);
11372
11494
  }
11373
11495
  })();
@@ -11387,9 +11509,9 @@ var ably = {exports: {}};
11387
11509
  }
11388
11510
  }
11389
11511
  get(msgOrSerial, params) {
11390
- var _this72 = this;
11512
+ var _this82 = this;
11391
11513
  return _asyncToGenerator(function* () {
11392
- return restannotations_default.prototype.get.call(_this72, msgOrSerial, params);
11514
+ return restannotations_default.prototype.get.call(_this82, msgOrSerial, params);
11393
11515
  })();
11394
11516
  }
11395
11517
  };
@@ -13051,23 +13173,23 @@ var ably = {exports: {}};
13051
13173
  }
13052
13174
  }
13053
13175
  processChannelMessage(message) {
13054
- var _this73 = this;
13176
+ var _this83 = this;
13055
13177
  return _asyncToGenerator(function* () {
13056
- yield _this73.realtime.channels.processChannelMessage(message);
13178
+ yield _this83.realtime.channels.processChannelMessage(message);
13057
13179
  })();
13058
13180
  }
13059
13181
  ping() {
13060
- var _this74 = this;
13182
+ var _this84 = this;
13061
13183
  return _asyncToGenerator(function* () {
13062
13184
  var _a2;
13063
- if (_this74.state.state !== "connected") {
13185
+ if (_this84.state.state !== "connected") {
13064
13186
  throw new _ErrorInfo2("Unable to ping service; not connected", 4e4, 400);
13065
13187
  }
13066
- var transport = (_a2 = _this74.activeProtocol) == null ? void 0 : _a2.getTransport();
13188
+ var transport = (_a2 = _this84.activeProtocol) == null ? void 0 : _a2.getTransport();
13067
13189
  if (!transport) {
13068
- throw _this74.getStateError();
13190
+ throw _this84.getStateError();
13069
13191
  }
13070
- logger_default.logAction(_this74.logger, logger_default.LOG_MINOR, "ConnectionManager.ping()", "transport = " + transport);
13192
+ logger_default.logAction(_this84.logger, logger_default.LOG_MINOR, "ConnectionManager.ping()", "transport = " + transport);
13071
13193
  var pingStart = Date.now();
13072
13194
  var id = _cheapRandStr();
13073
13195
  return _withTimeoutAsync(new Promise(resolve => {
@@ -13079,7 +13201,7 @@ var ably = {exports: {}};
13079
13201
  };
13080
13202
  transport.on("heartbeat", onHeartbeat);
13081
13203
  transport.ping(id);
13082
- }), _this74.options.timeouts.realtimeRequestTimeout, "Timeout waiting for heartbeat response");
13204
+ }), _this84.options.timeouts.realtimeRequestTimeout, "Timeout waiting for heartbeat response");
13083
13205
  })();
13084
13206
  }
13085
13207
  abort(error) {
@@ -13228,10 +13350,10 @@ var ably = {exports: {}};
13228
13350
  });
13229
13351
  }
13230
13352
  ping() {
13231
- var _this75 = this;
13353
+ var _this85 = this;
13232
13354
  return _asyncToGenerator(function* () {
13233
- logger_default.logAction(_this75.logger, logger_default.LOG_MINOR, "Connection.ping()", "");
13234
- return _this75.connectionManager.ping();
13355
+ logger_default.logAction(_this85.logger, logger_default.LOG_MINOR, "Connection.ping()", "");
13356
+ return _this85.connectionManager.ping();
13235
13357
  })();
13236
13358
  }
13237
13359
  close() {
@@ -13287,6 +13409,9 @@ var ably = {exports: {}};
13287
13409
  get channels() {
13288
13410
  return this._channels;
13289
13411
  }
13412
+ get clientId() {
13413
+ return this.auth.clientId;
13414
+ }
13290
13415
  connect() {
13291
13416
  logger_default.logAction(this.logger, logger_default.LOG_MINOR, "Realtime.connect()", "");
13292
13417
  this.connection.connect();
@@ -13327,16 +13452,16 @@ var ably = {exports: {}};
13327
13452
  }
13328
13453
  // Access to this method is synchronised by ConnectionManager#processChannelMessage.
13329
13454
  processChannelMessage(msg) {
13330
- var _this76 = this;
13455
+ var _this86 = this;
13331
13456
  return _asyncToGenerator(function* () {
13332
13457
  var channelName = msg.channel;
13333
13458
  if (channelName === void 0) {
13334
- logger_default.logAction(_this76.logger, logger_default.LOG_ERROR, "Channels.processChannelMessage()", "received event unspecified channel, action = " + msg.action);
13459
+ logger_default.logAction(_this86.logger, logger_default.LOG_ERROR, "Channels.processChannelMessage()", "received event unspecified channel, action = " + msg.action);
13335
13460
  return;
13336
13461
  }
13337
- var channel = _this76.all[channelName];
13462
+ var channel = _this86.all[channelName];
13338
13463
  if (!channel) {
13339
- logger_default.logAction(_this76.logger, logger_default.LOG_ERROR, "Channels.processChannelMessage()", "received event for non-existent channel: " + channelName);
13464
+ logger_default.logAction(_this86.logger, logger_default.LOG_ERROR, "Channels.processChannelMessage()", "received event for non-existent channel: " + channelName);
13340
13465
  return;
13341
13466
  }
13342
13467
  yield channel.processMessage(msg);
@@ -13591,43 +13716,43 @@ var ably = {exports: {}};
13591
13716
  this.pendingPresence = [];
13592
13717
  }
13593
13718
  enter(data) {
13594
- var _this77 = this;
13719
+ var _this87 = this;
13595
13720
  return _asyncToGenerator(function* () {
13596
- if (isAnonymousOrWildcard(_this77)) {
13721
+ if (isAnonymousOrWildcard(_this87)) {
13597
13722
  throw new _ErrorInfo2("clientId must be specified to enter a presence channel", 40012, 400);
13598
13723
  }
13599
- return _this77._enterOrUpdateClient(void 0, void 0, data, "enter");
13724
+ return _this87._enterOrUpdateClient(void 0, void 0, data, "enter");
13600
13725
  })();
13601
13726
  }
13602
13727
  update(data) {
13603
- var _this78 = this;
13728
+ var _this88 = this;
13604
13729
  return _asyncToGenerator(function* () {
13605
- if (isAnonymousOrWildcard(_this78)) {
13730
+ if (isAnonymousOrWildcard(_this88)) {
13606
13731
  throw new _ErrorInfo2("clientId must be specified to update presence data", 40012, 400);
13607
13732
  }
13608
- return _this78._enterOrUpdateClient(void 0, void 0, data, "update");
13733
+ return _this88._enterOrUpdateClient(void 0, void 0, data, "update");
13609
13734
  })();
13610
13735
  }
13611
13736
  enterClient(clientId, data) {
13612
- var _this79 = this;
13737
+ var _this89 = this;
13613
13738
  return _asyncToGenerator(function* () {
13614
- return _this79._enterOrUpdateClient(void 0, clientId, data, "enter");
13739
+ return _this89._enterOrUpdateClient(void 0, clientId, data, "enter");
13615
13740
  })();
13616
13741
  }
13617
13742
  updateClient(clientId, data) {
13618
- var _this80 = this;
13743
+ var _this90 = this;
13619
13744
  return _asyncToGenerator(function* () {
13620
- return _this80._enterOrUpdateClient(void 0, clientId, data, "update");
13745
+ return _this90._enterOrUpdateClient(void 0, clientId, data, "update");
13621
13746
  })();
13622
13747
  }
13623
13748
  _enterOrUpdateClient(id, clientId, data, action) {
13624
- var _this81 = this;
13749
+ var _this91 = this;
13625
13750
  return _asyncToGenerator(function* () {
13626
- var channel = _this81.channel;
13751
+ var channel = _this91.channel;
13627
13752
  if (!channel.connectionManager.activeState()) {
13628
13753
  throw channel.connectionManager.getError();
13629
13754
  }
13630
- logger_default.logAction(_this81.logger, logger_default.LOG_MICRO, "RealtimePresence." + action + "Client()", "channel = " + channel.name + ", id = " + id + ", client = " + (clientId || "(implicit) " + getClientId(_this81)));
13755
+ logger_default.logAction(_this91.logger, logger_default.LOG_MICRO, "RealtimePresence." + action + "Client()", "channel = " + channel.name + ", id = " + id + ", client = " + (clientId || "(implicit) " + getClientId(_this91)));
13631
13756
  var presence = presencemessage_default.fromData(data);
13632
13757
  presence.action = action;
13633
13758
  if (id) {
@@ -13645,7 +13770,7 @@ var ably = {exports: {}};
13645
13770
  channel.attach();
13646
13771
  case "attaching":
13647
13772
  return new Promise((resolve, reject) => {
13648
- _this81.pendingPresence.push({
13773
+ _this91.pendingPresence.push({
13649
13774
  presence: wirePresMsg,
13650
13775
  callback: err => err ? reject(err) : resolve()
13651
13776
  });
@@ -13660,22 +13785,22 @@ var ably = {exports: {}};
13660
13785
  })();
13661
13786
  }
13662
13787
  leave(data) {
13663
- var _this82 = this;
13788
+ var _this92 = this;
13664
13789
  return _asyncToGenerator(function* () {
13665
- if (isAnonymousOrWildcard(_this82)) {
13790
+ if (isAnonymousOrWildcard(_this92)) {
13666
13791
  throw new _ErrorInfo2("clientId must have been specified to enter or leave a presence channel", 40012, 400);
13667
13792
  }
13668
- return _this82.leaveClient(void 0, data);
13793
+ return _this92.leaveClient(void 0, data);
13669
13794
  })();
13670
13795
  }
13671
13796
  leaveClient(clientId, data) {
13672
- var _this83 = this;
13797
+ var _this93 = this;
13673
13798
  return _asyncToGenerator(function* () {
13674
- var channel = _this83.channel;
13799
+ var channel = _this93.channel;
13675
13800
  if (!channel.connectionManager.activeState()) {
13676
13801
  throw channel.connectionManager.getError();
13677
13802
  }
13678
- logger_default.logAction(_this83.logger, logger_default.LOG_MICRO, "RealtimePresence.leaveClient()", "leaving; channel = " + _this83.channel.name + ", client = " + clientId);
13803
+ logger_default.logAction(_this93.logger, logger_default.LOG_MICRO, "RealtimePresence.leaveClient()", "leaving; channel = " + _this93.channel.name + ", client = " + clientId);
13679
13804
  var presence = presencemessage_default.fromData(data);
13680
13805
  presence.action = "leave";
13681
13806
  if (clientId) {
@@ -13687,7 +13812,7 @@ var ably = {exports: {}};
13687
13812
  return channel.sendPresence([wirePresMsg]);
13688
13813
  case "attaching":
13689
13814
  return new Promise((resolve, reject) => {
13690
- _this83.pendingPresence.push({
13815
+ _this93.pendingPresence.push({
13691
13816
  presence: wirePresMsg,
13692
13817
  callback: err => err ? reject(err) : resolve()
13693
13818
  });
@@ -13703,14 +13828,14 @@ var ably = {exports: {}};
13703
13828
  })();
13704
13829
  }
13705
13830
  get(params) {
13706
- var _this84 = this;
13831
+ var _this94 = this;
13707
13832
  return _asyncToGenerator(function* () {
13708
13833
  var waitForSync = !params || ("waitForSync" in params ? params.waitForSync : true);
13709
13834
  return new Promise((resolve, reject) => {
13710
13835
  function returnMembers(members) {
13711
13836
  resolve(params ? members.list(params) : members.values());
13712
13837
  }
13713
- if (_this84.channel.state === "suspended") {
13838
+ if (_this94.channel.state === "suspended") {
13714
13839
  if (waitForSync) {
13715
13840
  reject(_ErrorInfo2.fromValues({
13716
13841
  statusCode: 400,
@@ -13718,12 +13843,12 @@ var ably = {exports: {}};
13718
13843
  message: "Presence state is out of sync due to channel being in the SUSPENDED state"
13719
13844
  }));
13720
13845
  } else {
13721
- returnMembers(_this84.members);
13846
+ returnMembers(_this94.members);
13722
13847
  }
13723
13848
  return;
13724
13849
  }
13725
- waitAttached(_this84.channel, err => reject(err), () => {
13726
- var members = _this84.members;
13850
+ waitAttached(_this94.channel, err => reject(err), () => {
13851
+ var members = _this94.members;
13727
13852
  if (waitForSync) {
13728
13853
  members.waitSync(function () {
13729
13854
  returnMembers(members);
@@ -13736,19 +13861,19 @@ var ably = {exports: {}};
13736
13861
  })();
13737
13862
  }
13738
13863
  history(params) {
13739
- var _this85 = this;
13864
+ var _this95 = this;
13740
13865
  return _asyncToGenerator(function* () {
13741
- logger_default.logAction(_this85.logger, logger_default.LOG_MICRO, "RealtimePresence.history()", "channel = " + _this85.name);
13742
- var restMixin = _this85.channel.client.rest.presenceMixin;
13866
+ logger_default.logAction(_this95.logger, logger_default.LOG_MICRO, "RealtimePresence.history()", "channel = " + _this95.name);
13867
+ var restMixin = _this95.channel.client.rest.presenceMixin;
13743
13868
  if (params && params.untilAttach) {
13744
- if (_this85.channel.state === "attached") {
13869
+ if (_this95.channel.state === "attached") {
13745
13870
  delete params.untilAttach;
13746
- params.from_serial = _this85.channel.properties.attachSerial;
13871
+ params.from_serial = _this95.channel.properties.attachSerial;
13747
13872
  } else {
13748
- throw new _ErrorInfo2("option untilAttach requires the channel to be attached, was: " + _this85.channel.state, 4e4, 400);
13873
+ throw new _ErrorInfo2("option untilAttach requires the channel to be attached, was: " + _this95.channel.state, 4e4, 400);
13749
13874
  }
13750
13875
  }
13751
- return restMixin.history(_this85, params);
13876
+ return restMixin.history(_this95, params);
13752
13877
  })();
13753
13878
  }
13754
13879
  setPresence(presenceSet, isSync, syncChannelSerial) {
@@ -13876,7 +14001,7 @@ var ably = {exports: {}};
13876
14001
  }
13877
14002
  subscribe() {
13878
14003
  var _arguments5 = arguments,
13879
- _this86 = this;
14004
+ _this96 = this;
13880
14005
  return _asyncToGenerator(function* () {
13881
14006
  for (var _len12 = _arguments5.length, _args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
13882
14007
  _args[_key12] = _arguments5[_key12];
@@ -13884,11 +14009,11 @@ var ably = {exports: {}};
13884
14009
  var args = realtimechannel_default.processListenerArgs(_args);
13885
14010
  var event = args[0];
13886
14011
  var listener = args[1];
13887
- var channel = _this86.channel;
14012
+ var channel = _this96.channel;
13888
14013
  if (channel.state === "failed") {
13889
14014
  throw _ErrorInfo2.fromValues(channel.invalidStateError());
13890
14015
  }
13891
- _this86.subscriptions.on(event, listener);
14016
+ _this96.subscriptions.on(event, listener);
13892
14017
  if (channel.channelOptions.attachOnSubscribe !== false) {
13893
14018
  yield channel.attach();
13894
14019
  }
@@ -14060,8 +14185,8 @@ var ably = {exports: {}};
14060
14185
  isRef: !!((_f = (_e = m.extras) == null ? void 0 : _e.ref) == null ? void 0 : _f.timeserial),
14061
14186
  clientId: m.clientId
14062
14187
  };
14063
- if (Object.entries(filter).find(_ref10 => {
14064
- var [key, value] = _ref10;
14188
+ if (Object.entries(filter).find(_ref12 => {
14189
+ var [key, value] = _ref12;
14065
14190
  return value !== void 0 ? mapping[key] !== value : false;
14066
14191
  })) {
14067
14192
  return;
@@ -14089,8 +14214,8 @@ var ably = {exports: {}};
14089
14214
  return [];
14090
14215
  }
14091
14216
  if (!realListener && filter) {
14092
- return Array.from(channel.filteredSubscriptions.entries()).map(_ref11 => {
14093
- var [key, filterMaps] = _ref11;
14217
+ return Array.from(channel.filteredSubscriptions.entries()).map(_ref13 => {
14218
+ var [key, filterMaps] = _ref13;
14094
14219
  var _a2;
14095
14220
  var listenerMaps = filterMaps.get(filter);
14096
14221
  filterMaps.delete(filter);
@@ -14562,38 +14687,38 @@ var ably = {exports: {}};
14562
14687
  return output;
14563
14688
  }
14564
14689
  encrypt(plaintext) {
14565
- var _this87 = this;
14690
+ var _this97 = this;
14566
14691
  return _asyncToGenerator(function* () {
14567
- logger_default.logAction(_this87.logger, logger_default.LOG_MICRO, "CBCCipher.encrypt()", "");
14568
- var iv = yield _this87.getIv();
14569
- var cryptoKey = yield crypto.subtle.importKey("raw", _this87.key, _this87.webCryptoAlgorithm, false, ["encrypt"]);
14692
+ logger_default.logAction(_this97.logger, logger_default.LOG_MICRO, "CBCCipher.encrypt()", "");
14693
+ var iv = yield _this97.getIv();
14694
+ var cryptoKey = yield crypto.subtle.importKey("raw", _this97.key, _this97.webCryptoAlgorithm, false, ["encrypt"]);
14570
14695
  var ciphertext = yield crypto.subtle.encrypt({
14571
- name: _this87.webCryptoAlgorithm,
14696
+ name: _this97.webCryptoAlgorithm,
14572
14697
  iv
14573
14698
  }, cryptoKey, plaintext);
14574
- return _this87.concat(iv, ciphertext);
14699
+ return _this97.concat(iv, ciphertext);
14575
14700
  })();
14576
14701
  }
14577
14702
  decrypt(ciphertext) {
14578
- var _this88 = this;
14703
+ var _this98 = this;
14579
14704
  return _asyncToGenerator(function* () {
14580
- logger_default.logAction(_this88.logger, logger_default.LOG_MICRO, "CBCCipher.decrypt()", "");
14705
+ logger_default.logAction(_this98.logger, logger_default.LOG_MICRO, "CBCCipher.decrypt()", "");
14581
14706
  var ciphertextArrayBuffer = bufferUtils.toArrayBuffer(ciphertext);
14582
14707
  var iv = ciphertextArrayBuffer.slice(0, DEFAULT_BLOCKLENGTH);
14583
14708
  var ciphertextBody = ciphertextArrayBuffer.slice(DEFAULT_BLOCKLENGTH);
14584
- var cryptoKey = yield crypto.subtle.importKey("raw", _this88.key, _this88.webCryptoAlgorithm, false, ["decrypt"]);
14709
+ var cryptoKey = yield crypto.subtle.importKey("raw", _this98.key, _this98.webCryptoAlgorithm, false, ["decrypt"]);
14585
14710
  return crypto.subtle.decrypt({
14586
- name: _this88.webCryptoAlgorithm,
14711
+ name: _this98.webCryptoAlgorithm,
14587
14712
  iv
14588
14713
  }, cryptoKey, ciphertextBody);
14589
14714
  })();
14590
14715
  }
14591
14716
  getIv() {
14592
- var _this89 = this;
14717
+ var _this99 = this;
14593
14718
  return _asyncToGenerator(function* () {
14594
- if (_this89.iv) {
14595
- var iv = _this89.iv;
14596
- _this89.iv = null;
14719
+ if (_this99.iv) {
14720
+ var iv = _this99.iv;
14721
+ _this99.iv = null;
14597
14722
  return iv;
14598
14723
  }
14599
14724
  var randomBlock = yield config.getRandomArrayBuffer(DEFAULT_BLOCKLENGTH);
@@ -14640,7 +14765,7 @@ var ably = {exports: {}};
14640
14765
  if (Platform.Config.xhrSupported && xhrRequestImplementation) {
14641
14766
  this.supportsAuthHeaders = true;
14642
14767
  this.Request = /*#__PURE__*/function () {
14643
- var _ref12 = _asyncToGenerator(function* (method, uri, headers, params, body) {
14768
+ var _ref14 = _asyncToGenerator(function* (method, uri, headers, params, body) {
14644
14769
  return new Promise(resolve => {
14645
14770
  var _a3;
14646
14771
  var req = xhrRequestImplementation.createRequest(uri, headers, params, body, XHRStates_default.REQ_SEND, (_a3 = client && client.options.timeouts) != null ? _a3 : null, this.logger, method);
@@ -14654,8 +14779,8 @@ var ably = {exports: {}};
14654
14779
  req.exec();
14655
14780
  });
14656
14781
  });
14657
- return function (_x82, _x83, _x84, _x85, _x86) {
14658
- return _ref12.apply(this, arguments);
14782
+ return function (_x88, _x89, _x90, _x91, _x92) {
14783
+ return _ref14.apply(this, arguments);
14659
14784
  };
14660
14785
  }();
14661
14786
  if (client == null ? void 0 : client.options.disableConnectivityCheck) {
@@ -14680,11 +14805,11 @@ var ably = {exports: {}};
14680
14805
  } else if (Platform.Config.fetchSupported && fetchRequestImplementation) {
14681
14806
  this.supportsAuthHeaders = true;
14682
14807
  this.Request = /*#__PURE__*/function () {
14683
- var _ref15 = _asyncToGenerator(function* (method, uri, headers, params, body) {
14808
+ var _ref17 = _asyncToGenerator(function* (method, uri, headers, params, body) {
14684
14809
  return fetchRequestImplementation(method, client != null ? client : null, uri, headers, params, body);
14685
14810
  });
14686
- return function (_x87, _x88, _x89, _x90, _x91) {
14687
- return _ref15.apply(this, arguments);
14811
+ return function (_x93, _x94, _x95, _x96, _x97) {
14812
+ return _ref17.apply(this, arguments);
14688
14813
  };
14689
14814
  }();
14690
14815
  if (client == null ? void 0 : client.options.disableConnectivityCheck) {
@@ -14715,14 +14840,14 @@ var ably = {exports: {}};
14715
14840
  return (_b = (_a2 = this.client) == null ? void 0 : _a2.logger) != null ? _b : logger_default.defaultLogger;
14716
14841
  }
14717
14842
  doUri(method, uri, headers, body, params) {
14718
- var _this90 = this;
14843
+ var _this100 = this;
14719
14844
  return _asyncToGenerator(function* () {
14720
- if (!_this90.Request) {
14845
+ if (!_this100.Request) {
14721
14846
  return {
14722
14847
  error: new PartialErrorInfo("Request invoked before assigned to", null, 500)
14723
14848
  };
14724
14849
  }
14725
- return _this90.Request(method, uri, headers, params, body);
14850
+ return _this100.Request(method, uri, headers, params, body);
14726
14851
  })();
14727
14852
  }
14728
14853
  shouldFallback(errorInfo) {
@@ -14852,7 +14977,7 @@ var ably = {exports: {}};
14852
14977
  globalObject4.crypto.getRandomValues(byteArray);
14853
14978
  return byteArray.buffer;
14854
14979
  });
14855
- function getRandomArrayBuffer(_x92) {
14980
+ function getRandomArrayBuffer(_x98) {
14856
14981
  return _getRandomArrayBuffer.apply(this, arguments);
14857
14982
  }
14858
14983
  return getRandomArrayBuffer;
@@ -15997,7 +16122,7 @@ var ably = {exports: {}};
15997
16122
  });
15998
16123
  return result;
15999
16124
  }
16000
- function fetchRequest(_x93, _x94, _x95, _x96, _x97, _x98) {
16125
+ function fetchRequest(_x99, _x100, _x101, _x102, _x103, _x104) {
16001
16126
  return _fetchRequest.apply(this, arguments);
16002
16127
  } // src/platform/web/lib/http/request/index.ts
16003
16128
  function _fetchRequest() {
@@ -16146,10 +16271,19 @@ class ClientAblyService {
16146
16271
  token: ablyToken,
16147
16272
  autoConnect: true
16148
16273
  });
16274
+ _this.client.connection.on('failed', stateChange => {
16275
+ var _a;
16276
+ console.error('[AblyService] Connection state: failed', {
16277
+ reason: (_a = stateChange.reason) === null || _a === void 0 ? void 0 : _a.message,
16278
+ error: stateChange.reason
16279
+ });
16280
+ });
16149
16281
  // Wait for connection to be established
16150
16282
  yield new Promise((resolve, reject) => {
16151
16283
  if (!_this.client) {
16152
- reject(new Error('Failed to initialize Ably client'));
16284
+ var error = new Error('Failed to initialize Ably client');
16285
+ console.error('[AblyService]', error);
16286
+ reject(error);
16153
16287
  return;
16154
16288
  }
16155
16289
  _this.client.connection.once('connected', () => {
@@ -16158,23 +16292,38 @@ class ClientAblyService {
16158
16292
  resolve();
16159
16293
  });
16160
16294
  _this.client.connection.once('failed', stateChange => {
16161
- var _a;
16162
- reject(new Error("Ably connection failed: ".concat(((_a = stateChange.reason) === null || _a === void 0 ? void 0 : _a.message) || 'Unknown error')));
16295
+ var _a, _b;
16296
+ var error = new Error("Ably connection failed: ".concat(((_a = stateChange.reason) === null || _a === void 0 ? void 0 : _a.message) || 'Unknown error'));
16297
+ console.error('[AblyService] Connection failed', {
16298
+ reason: (_b = stateChange.reason) === null || _b === void 0 ? void 0 : _b.message,
16299
+ error: stateChange.reason
16300
+ });
16301
+ reject(error);
16163
16302
  });
16164
16303
  _this.client.connection.once('disconnected', stateChange => {
16165
- var _a;
16166
- reject(new Error("Ably connection disconnected: ".concat(((_a = stateChange.reason) === null || _a === void 0 ? void 0 : _a.message) || 'Unknown error')));
16304
+ var _a, _b;
16305
+ var error = new Error("Ably connection disconnected: ".concat(((_a = stateChange.reason) === null || _a === void 0 ? void 0 : _a.message) || 'Unknown error'));
16306
+ console.error('[AblyService] Connection disconnected', {
16307
+ reason: (_b = stateChange.reason) === null || _b === void 0 ? void 0 : _b.message
16308
+ });
16309
+ reject(error);
16167
16310
  });
16168
16311
  // Set a timeout for connection
16169
16312
  setTimeout(() => {
16170
16313
  if (!_this.isConnected) {
16171
- reject(new Error('Ably connection timeout'));
16314
+ var _error = new Error('Ably connection timeout');
16315
+ console.error('[AblyService] Connection timeout after 10 seconds');
16316
+ reject(_error);
16172
16317
  }
16173
16318
  }, 10000);
16174
16319
  });
16175
16320
  // Subscribe to the session room
16176
16321
  yield _this.joinChannel(sessionId, onMessageReceived, tenantId);
16177
16322
  } catch (error) {
16323
+ console.error('[AblyService] Error in startConnection', {
16324
+ error,
16325
+ sessionId
16326
+ });
16178
16327
  _this.isConnected = false;
16179
16328
  _this.sessionId = null;
16180
16329
  throw error;
@@ -16185,23 +16334,53 @@ class ClientAblyService {
16185
16334
  var _this2 = this;
16186
16335
  return _asyncToGenerator(function* () {
16187
16336
  if (!_this2.client) {
16188
- throw new Error('Chat client not initialized');
16337
+ var error = new Error('Chat client not initialized');
16338
+ console.error('[AblyService] joinChannel error:', error);
16339
+ throw error;
16189
16340
  }
16190
16341
  var roomName = "session:".concat(tenantId, ":").concat(sessionId);
16191
16342
  // Set up raw channel subscription for server messages
16192
16343
  if (_this2.client) {
16193
16344
  _this2.channel = _this2.client.channels.get(roomName);
16345
+ _this2.channel.on('failed', stateChange => {
16346
+ var _a;
16347
+ console.error('[AblyService] Channel failed', {
16348
+ roomName,
16349
+ reason: (_a = stateChange.reason) === null || _a === void 0 ? void 0 : _a.message,
16350
+ error: stateChange.reason
16351
+ });
16352
+ });
16194
16353
  // Subscribe to assistant/system responses
16195
16354
  _this2.channel.subscribe('ReceiveMessage', message => {
16196
- var _a, _b, _c, _d, _e;
16355
+ var _a, _b, _c, _d, _e, _f, _g, _h;
16197
16356
  try {
16198
- var messageContent = typeof message.data === 'string' ? message.data : ((_a = message.data) === null || _a === void 0 ? void 0 : _a.content) || ((_b = message.data) === null || _b === void 0 ? void 0 : _b.message);
16199
- var senderType = ((_c = message.data) === null || _c === void 0 ? void 0 : _c.senderType) || 3; // Assistant
16200
- var needsAgent = ((_d = message.data) === null || _d === void 0 ? void 0 : _d.needsAgent) || false;
16201
- var attachments = ((_e = message.data) === null || _e === void 0 ? void 0 : _e.attachments) || [];
16202
- onMessageReceived(messageContent, senderType, needsAgent, attachments);
16357
+ // Ensure messageContent is always a string (default to empty string if undefined)
16358
+ var messageContent = typeof message.data === 'string' ? message.data : (_d = (_b = (_a = message.data) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : (_c = message.data) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : '';
16359
+ var senderType = ((_e = message.data) === null || _e === void 0 ? void 0 : _e.senderType) || 3; // Assistant
16360
+ var needsAgent = ((_f = message.data) === null || _f === void 0 ? void 0 : _f.needsAgent) || ((_g = message.data) === null || _g === void 0 ? void 0 : _g.actionType) == 'needs_agent' || false;
16361
+ var attachments = ((_h = message.data) === null || _h === void 0 ? void 0 : _h.attachments) || [];
16362
+ // Extract downloadUrl from attachments (Ably now returns downloadUrl directly)
16363
+ // Attachments can be: strings (URLs), objects with downloadUrl, or objects with id
16364
+ var attachmentUrls = attachments.map(attachment => {
16365
+ if (typeof attachment === 'string') {
16366
+ // If it's already a string, it's a URL
16367
+ return attachment;
16368
+ } else if (attachment === null || attachment === void 0 ? void 0 : attachment.downloadUrl) {
16369
+ // If it's an object with downloadUrl, use that
16370
+ return attachment.downloadUrl;
16371
+ } else if (attachment === null || attachment === void 0 ? void 0 : attachment.url) {
16372
+ // Fallback to url property
16373
+ return attachment.url;
16374
+ }
16375
+ // If it's an object with id, we'll need to keep it for backward compatibility
16376
+ return null;
16377
+ }).filter(url => url !== null);
16378
+ onMessageReceived(messageContent, senderType, needsAgent, attachmentUrls);
16203
16379
  } catch (error) {
16204
- // Handle error silently
16380
+ console.error('[AblyService] Error processing message', {
16381
+ error,
16382
+ message
16383
+ });
16205
16384
  }
16206
16385
  });
16207
16386
  yield _this2.channel.attach();
@@ -16231,6 +16410,9 @@ class ClientAblyService {
16231
16410
  _this3.isConnected = false;
16232
16411
  _this3.sessionId = null;
16233
16412
  } catch (error) {
16413
+ console.error('[AblyService] Error in stopConnection', {
16414
+ error
16415
+ });
16234
16416
  // Reset state even if there's an error
16235
16417
  _this3.isConnected = false;
16236
16418
  _this3.sessionId = null;
@@ -16383,19 +16565,21 @@ function useTypewriter(text) {
16383
16565
  var onType = arguments.length > 2 ? arguments[2] : undefined;
16384
16566
  var [displayedText, setDisplayedText] = React.useState('');
16385
16567
  React.useEffect(() => {
16568
+ // Ensure text is always a string to prevent errors
16569
+ var safeText = text !== null && text !== void 0 ? text : '';
16386
16570
  var index = 0;
16387
16571
  setDisplayedText('');
16388
16572
  var interval = setInterval(() => {
16389
16573
  setDisplayedText(() => {
16390
- var next = text.slice(0, index + 1);
16574
+ var next = safeText.slice(0, index + 1);
16391
16575
  index++;
16392
16576
  if (onType) onType();
16393
- if (index >= text.length) clearInterval(interval);
16577
+ if (index >= safeText.length) clearInterval(interval);
16394
16578
  return next;
16395
16579
  });
16396
16580
  }, speed);
16397
16581
  return () => clearInterval(interval);
16398
- }, [text]);
16582
+ }, [text, onType]);
16399
16583
  return displayedText;
16400
16584
  }
16401
16585
 
@@ -34182,11 +34366,13 @@ var AgentResponse = _ref => {
34182
34366
  messageId,
34183
34367
  onType
34184
34368
  } = _ref;
34369
+ // Ensure messageContent is always a string to prevent errors
34370
+ var safeMessageContent = messageContent !== null && messageContent !== void 0 ? messageContent : '';
34185
34371
  var shouldAnimate = (senderType === 2 || senderType === 3) && !seenMessagesRef.has(messageId);
34186
- var animatedText = useTypewriter(messageContent, 20, onType);
34187
- var finalMessage = shouldAnimate ? animatedText : messageContent;
34372
+ var animatedText = useTypewriter(safeMessageContent, 20, onType);
34373
+ var finalMessage = shouldAnimate ? animatedText : safeMessageContent;
34188
34374
  // Mark message as "seen" after full animation
34189
- if (shouldAnimate && finalMessage === messageContent) {
34375
+ if (shouldAnimate && finalMessage === safeMessageContent) {
34190
34376
  seenMessagesRef.add(messageId);
34191
34377
  }
34192
34378
  return jsxRuntime.jsx("div", {
@@ -34336,6 +34522,32 @@ var ImagePreviewDialog = _ref => {
34336
34522
  y: 0
34337
34523
  });
34338
34524
  }, []);
34525
+ var handleDownload = React.useCallback(/*#__PURE__*/_asyncToGenerator(function* () {
34526
+ if (!currentImageUrl) return;
34527
+ try {
34528
+ // Fetch the image as a blob
34529
+ var response = yield fetch(currentImageUrl);
34530
+ var blob = yield response.blob();
34531
+ // Create a temporary URL for the blob
34532
+ var blobUrl = URL.createObjectURL(blob);
34533
+ // Extract filename from URL or use a default
34534
+ var urlParts = currentImageUrl.split('/');
34535
+ var filename = urlParts[urlParts.length - 1].split('?')[0] || 'image.png';
34536
+ // Create a temporary anchor element and trigger download
34537
+ var link = document.createElement('a');
34538
+ link.href = blobUrl;
34539
+ link.download = filename;
34540
+ document.body.appendChild(link);
34541
+ link.click();
34542
+ // Cleanup
34543
+ document.body.removeChild(link);
34544
+ URL.revokeObjectURL(blobUrl);
34545
+ } catch (error) {
34546
+ console.error('Failed to download image:', error);
34547
+ // Fallback: open in new tab if download fails
34548
+ window.open(currentImageUrl, '_blank');
34549
+ }
34550
+ }), [currentImageUrl]);
34339
34551
  var handleClose = React.useCallback(() => {
34340
34552
  setZoomLevel(1);
34341
34553
  setImagePosition({
@@ -34536,6 +34748,27 @@ var ImagePreviewDialog = _ref => {
34536
34748
  "aria-label": 'Reset zoom',
34537
34749
  type: 'button',
34538
34750
  children: "Reset"
34751
+ }), jsxRuntime.jsx("div", {
34752
+ className: 'babylai-h-9 babylai-w-px babylai-bg-white/20 babylai-mx-1'
34753
+ }), jsxRuntime.jsx(Button, {
34754
+ variant: 'ghost',
34755
+ size: 'icon',
34756
+ onClick: handleDownload,
34757
+ className: 'babylai-text-white hover:babylai-text-white/80 hover:babylai-bg-white/10 babylai-h-9 babylai-w-9',
34758
+ "aria-label": 'Download image',
34759
+ type: 'button',
34760
+ children: jsxRuntime.jsx("svg", {
34761
+ className: 'babylai-w-5 babylai-h-5',
34762
+ fill: 'none',
34763
+ stroke: 'currentColor',
34764
+ viewBox: '0 0 24 24',
34765
+ children: jsxRuntime.jsx("path", {
34766
+ strokeLinecap: 'round',
34767
+ strokeLinejoin: 'round',
34768
+ strokeWidth: 2,
34769
+ d: 'M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4'
34770
+ })
34771
+ })
34539
34772
  })]
34540
34773
  }), hasMultipleImages && jsxRuntime.jsx("div", {
34541
34774
  className: cn('babylai-absolute babylai-top-4 babylai-z-[60]', 'babylai-bg-black/50 babylai-backdrop-blur-sm babylai-rounded-lg babylai-px-4 babylai-py-2', dir === 'rtl' ? 'babylai-right-1/2 babylai-translate-x-1/2' : 'babylai-left-1/2 -babylai-translate-x-1/2'),
@@ -34569,6 +34802,7 @@ ImagePreviewDialog.displayName = 'ImagePreviewDialog';
34569
34802
  var ImageAttachment = _ref => {
34570
34803
  var {
34571
34804
  fileId,
34805
+ imageUrl: propImageUrl,
34572
34806
  className,
34573
34807
  enablePreview = true,
34574
34808
  onClick
@@ -34576,30 +34810,39 @@ var ImageAttachment = _ref => {
34576
34810
  var {
34577
34811
  i18n
34578
34812
  } = useLocalTranslation();
34579
- var [imageUrl, setImageUrl] = React.useState(null);
34580
- var [loading, setLoading] = React.useState(true);
34813
+ var [imageUrl, setImageUrl] = React.useState(propImageUrl || null);
34814
+ var [loading, setLoading] = React.useState(!propImageUrl && !!fileId);
34581
34815
  var [error, setError] = React.useState(false);
34582
34816
  var [isPreviewOpen, setIsPreviewOpen] = React.useState(false);
34583
34817
  React.useEffect(() => {
34584
- var fetchImageUrl = /*#__PURE__*/function () {
34585
- var _ref2 = _asyncToGenerator(function* () {
34586
- try {
34587
- setLoading(true);
34588
- setError(false);
34589
- var response = yield presignDownload(fileId, i18n.language);
34590
- setImageUrl(response.downloadUrl);
34591
- } catch (err) {
34592
- setError(true);
34593
- } finally {
34594
- setLoading(false);
34595
- }
34596
- });
34597
- return function fetchImageUrl() {
34598
- return _ref2.apply(this, arguments);
34599
- };
34600
- }();
34601
- fetchImageUrl();
34602
- }, [fileId, i18n.language]);
34818
+ // If we have a direct URL, use it immediately
34819
+ if (propImageUrl) {
34820
+ setImageUrl(propImageUrl);
34821
+ setLoading(false);
34822
+ return;
34823
+ }
34824
+ // If we only have a fileId, fetch the URL using presignDownload
34825
+ if (fileId) {
34826
+ var fetchImageUrl = /*#__PURE__*/function () {
34827
+ var _ref2 = _asyncToGenerator(function* () {
34828
+ try {
34829
+ setLoading(true);
34830
+ setError(false);
34831
+ var response = yield presignDownload(fileId, i18n.language);
34832
+ setImageUrl(response.downloadUrl);
34833
+ } catch (err) {
34834
+ setError(true);
34835
+ } finally {
34836
+ setLoading(false);
34837
+ }
34838
+ });
34839
+ return function fetchImageUrl() {
34840
+ return _ref2.apply(this, arguments);
34841
+ };
34842
+ }();
34843
+ fetchImageUrl();
34844
+ }
34845
+ }, [fileId, propImageUrl, i18n.language]);
34603
34846
  var handleImageClick = () => {
34604
34847
  if (onClick) {
34605
34848
  onClick();
@@ -38151,39 +38394,63 @@ var ChatWindowFooter = props => {
38151
38394
  var _a;
38152
38395
  (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
38153
38396
  }, []);
38154
- var handleFileSelect = React.useCallback(/*#__PURE__*/function () {
38155
- var _ref = _asyncToGenerator(function* (e) {
38156
- var files = Array.from(e.target.files || []);
38157
- // Validate that all files are images
38158
- var imageFiles = files.filter(file => file.type.startsWith('image/'));
38159
- // Only image files are allowed
38160
- // Create preview URLs and add to selected files
38161
- var newFiles = imageFiles.map(file => ({
38162
- file,
38163
- previewUrl: URL.createObjectURL(file),
38164
- uploading: false,
38165
- uploadedId: null,
38166
- error: null
38167
- }));
38168
- setSelectedFiles(prev => [...prev, ...newFiles]);
38169
- // Clear the input
38170
- if (fileInputRef.current) {
38171
- fileInputRef.current.value = '';
38397
+ var handleFileSelect = React.useCallback(e => {
38398
+ var files = Array.from(e.target.files || []);
38399
+ // Validate that all files are images
38400
+ var imageFiles = files.filter(file => file.type.startsWith('image/'));
38401
+ // Create preview URLs and add to selected files (don't upload yet)
38402
+ var newFiles = imageFiles.map(file => ({
38403
+ file,
38404
+ previewUrl: URL.createObjectURL(file),
38405
+ uploading: false,
38406
+ uploadedId: null,
38407
+ error: null
38408
+ }));
38409
+ setSelectedFiles(prev => [...prev, ...newFiles]);
38410
+ // Clear the input
38411
+ if (fileInputRef.current) {
38412
+ fileInputRef.current.value = '';
38413
+ }
38414
+ // Don't upload files immediately - wait for send button click
38415
+ }, []);
38416
+ // Removed handleUploadFiles - files are now uploaded in handleSendMessageWithAttachments
38417
+ var handleRemoveFile = React.useCallback(previewUrl => {
38418
+ setSelectedFiles(prev => {
38419
+ var fileToRemove = prev.find(f => f.previewUrl === previewUrl);
38420
+ if (fileToRemove) {
38421
+ URL.revokeObjectURL(fileToRemove.previewUrl);
38172
38422
  }
38173
- // Start uploading immediately
38174
- yield handleUploadFiles(newFiles);
38423
+ return prev.filter(f => f.previewUrl !== previewUrl);
38175
38424
  });
38176
- return function (_x) {
38177
- return _ref.apply(this, arguments);
38178
- };
38179
- }(), []);
38180
- var handleUploadFiles = React.useCallback(/*#__PURE__*/function () {
38181
- var _ref2 = _asyncToGenerator(function* (filesToUpload) {
38182
- // Get session ID
38183
- var sessionId;
38425
+ }, []);
38426
+ var handleSendMessageWithAttachments = React.useCallback(/*#__PURE__*/_asyncToGenerator(function* () {
38427
+ // Prevent sending if already loading
38428
+ if (props.isLoading) {
38429
+ return;
38430
+ }
38431
+ // Get files that need to be uploaded (those without uploadedId)
38432
+ var filesToUpload = selectedFiles.filter(f => f.uploadedId === null && !f.error);
38433
+ var alreadyUploadedIds = selectedFiles.filter(f => f.uploadedId !== null).map(f => f.uploadedId);
38434
+ // Declare uploadedIds outside the if block so it's accessible later
38435
+ var uploadedIds = [];
38436
+ // If there are files to upload, upload them first
38437
+ if (filesToUpload.length > 0) {
38438
+ // Get session ID - only use existing, never create new one
38439
+ var sessionId = null;
38184
38440
  try {
38185
- sessionId = yield props.onEnsureSession();
38441
+ // Only use existing sessionId, never call onEnsureSession
38442
+ if (props.sessionId) {
38443
+ sessionId = props.sessionId;
38444
+ } else {
38445
+ // Mark all files as error
38446
+ setSelectedFiles(prev => prev.map(f => filesToUpload.some(ftl => ftl.previewUrl === f.previewUrl) ? _objectSpread2(_objectSpread2({}, f), {}, {
38447
+ error: 'No session available',
38448
+ uploading: false
38449
+ }) : f));
38450
+ return;
38451
+ }
38186
38452
  } catch (error) {
38453
+ console.error('[ChatWindowFooter] Failed to get sessionId for file upload:', error);
38187
38454
  // Mark all files as error
38188
38455
  setSelectedFiles(prev => prev.map(f => filesToUpload.some(ftl => ftl.previewUrl === f.previewUrl) ? _objectSpread2(_objectSpread2({}, f), {}, {
38189
38456
  error: 'Failed to initialize session',
@@ -38191,7 +38458,9 @@ var ChatWindowFooter = props => {
38191
38458
  }) : f));
38192
38459
  return;
38193
38460
  }
38194
- // Upload each file
38461
+ // Upload each file and collect uploaded IDs
38462
+ uploadedIds = [];
38463
+ var hasUploadErrors = false;
38195
38464
  var _loop = function* _loop(fileDto) {
38196
38465
  try {
38197
38466
  // Mark as uploading
@@ -38202,7 +38471,6 @@ var ChatWindowFooter = props => {
38202
38471
  // Get presigned URL
38203
38472
  var presignResponse = yield presignUpload(sessionId, fileDto.file, i18n.language);
38204
38473
  // Upload file to presigned URL using axios
38205
- // Important: Content-Type must match the file type (e.g., 'image/png'), not 'multipart/form-data'
38206
38474
  var uploadResponse = yield axios$1.put(presignResponse.uploadUrl, fileDto.file, {
38207
38475
  headers: {
38208
38476
  'Content-Type': fileDto.file.type
@@ -38214,6 +38482,8 @@ var ChatWindowFooter = props => {
38214
38482
  if (uploadResponse.status !== 200 && uploadResponse.status !== 204) {
38215
38483
  throw new Error("Upload failed with status ".concat(uploadResponse.status));
38216
38484
  }
38485
+ // Collect uploaded ID
38486
+ uploadedIds.push(presignResponse.id);
38217
38487
  // Update with uploaded ID
38218
38488
  setSelectedFiles(prev => prev.map(f => f.previewUrl === fileDto.previewUrl ? _objectSpread2(_objectSpread2({}, f), {}, {
38219
38489
  uploading: false,
@@ -38221,6 +38491,8 @@ var ChatWindowFooter = props => {
38221
38491
  error: null
38222
38492
  }) : f));
38223
38493
  } catch (error) {
38494
+ console.error('[ChatWindowFooter] File upload failed:', error);
38495
+ hasUploadErrors = true;
38224
38496
  setSelectedFiles(prev => prev.map(f => f.previewUrl === fileDto.previewUrl ? _objectSpread2(_objectSpread2({}, f), {}, {
38225
38497
  uploading: false,
38226
38498
  error: 'Upload failed',
@@ -38231,43 +38503,28 @@ var ChatWindowFooter = props => {
38231
38503
  for (var fileDto of filesToUpload) {
38232
38504
  yield* _loop(fileDto);
38233
38505
  }
38234
- });
38235
- return function (_x2) {
38236
- return _ref2.apply(this, arguments);
38237
- };
38238
- }(), [props.onEnsureSession, i18n.language]);
38239
- var handleRemoveFile = React.useCallback(previewUrl => {
38240
- setSelectedFiles(prev => {
38241
- var fileToRemove = prev.find(f => f.previewUrl === previewUrl);
38242
- if (fileToRemove) {
38243
- URL.revokeObjectURL(fileToRemove.previewUrl);
38506
+ // If any uploads failed, don't send the message
38507
+ if (hasUploadErrors) {
38508
+ console.error('[ChatWindowFooter] Some files failed to upload, not sending message');
38509
+ return;
38244
38510
  }
38245
- return prev.filter(f => f.previewUrl !== previewUrl);
38246
- });
38247
- }, []);
38248
- var handleSendMessageWithAttachments = React.useCallback(() => {
38249
- // Only allow sending if all files have finished uploading (either successfully or with error)
38250
- var hasUploadingFiles = selectedFiles.some(f => f.uploading);
38251
- if (hasUploadingFiles) {
38252
- return; // Prevent sending if any files are still uploading
38253
- }
38254
- // Get all successfully uploaded file IDs
38255
- var attachmentIds = selectedFiles.filter(f => f.uploadedId !== null).map(f => f.uploadedId);
38511
+ }
38512
+ // Get all successfully uploaded file IDs (already uploaded + newly uploaded)
38513
+ // Use uploadedIds from the upload loop instead of reading from state
38514
+ var allAttachmentIds = [...alreadyUploadedIds, ...uploadedIds];
38256
38515
  // Call the original send message with attachment IDs
38257
- props.handleSendMessage(attachmentIds);
38516
+ props.handleSendMessage(allAttachmentIds);
38258
38517
  // Clear selected files and revoke URLs
38259
38518
  selectedFiles.forEach(f => URL.revokeObjectURL(f.previewUrl));
38260
38519
  setSelectedFiles([]);
38261
- }, [selectedFiles, props]);
38520
+ }), [selectedFiles, props, i18n.language]);
38262
38521
  // Check if any files are currently uploading
38263
38522
  var hasUploadingFiles = selectedFiles.some(f => f.uploading);
38264
- // Check if there are files that haven't finished (no uploadedId, no error, not uploading)
38265
- // This shouldn't happen in normal flow, but we check for safety
38266
- var hasPendingFiles = selectedFiles.some(f => !f.uploading && f.uploadedId === null && f.error === null);
38267
- // Check if all files have errors (no successful uploads)
38268
- var hasSuccessfulUploads = selectedFiles.some(f => f.uploadedId !== null);
38269
- var allFilesHaveErrors = selectedFiles.length > 0 && !hasSuccessfulUploads && !hasUploadingFiles && !hasPendingFiles;
38270
- var isSendDisabled = props.isLoading || props.inputMessage.trim() === '' || hasUploadingFiles || hasPendingFiles || allFilesHaveErrors;
38523
+ // Check if there are files with errors
38524
+ var hasFileErrors = selectedFiles.some(f => f.error !== null);
38525
+ // Allow sending if there's text OR files selected (files will be uploaded on send)
38526
+ var hasContentToSend = props.inputMessage.trim() !== '' || selectedFiles.length > 0;
38527
+ var isSendDisabled = props.isLoading || !hasContentToSend || hasUploadingFiles || hasFileErrors;
38271
38528
  var handleKeyDown = React.useCallback(e => {
38272
38529
  if (e.key === 'Enter' && !e.shiftKey) {
38273
38530
  e.preventDefault();
@@ -38432,10 +38689,12 @@ var MessageComponent = /*#__PURE__*/React__default["default"].memo(_ref => {
38432
38689
  var isFirstHumanAgentMessage = index === firstHumanAgentIndex && message.senderType === 2;
38433
38690
  var textDirection = message.senderType === 1 ? 'babylai-justify-end' : 'babylai-justify-start';
38434
38691
  var handleImageClick = React.useCallback(clickedIndex => {
38435
- if (message.attachmentIds && message.attachmentIds.length > 0) {
38436
- onImageClick(message.attachmentIds, clickedIndex);
38692
+ // Use attachmentUrls if available (from Ably), otherwise use attachmentIds (user-sent)
38693
+ var attachments = message.attachmentUrls || message.attachmentIds || [];
38694
+ if (attachments.length > 0) {
38695
+ onImageClick(attachments, clickedIndex);
38437
38696
  }
38438
- }, [message.attachmentIds, onImageClick]);
38697
+ }, [message.attachmentIds, message.attachmentUrls, onImageClick]);
38439
38698
  return jsxRuntime.jsxs("div", {
38440
38699
  children: [isFirstHumanAgentMessage && jsxRuntime.jsx("div", {
38441
38700
  className: 'babylai-flex babylai-justify-center babylai-items-center babylai-my-4',
@@ -38458,14 +38717,21 @@ var MessageComponent = /*#__PURE__*/React__default["default"].memo(_ref => {
38458
38717
  className: 'babylai-flex-shrink-0 babylai-me-3 babylai-w-8'
38459
38718
  }), jsxRuntime.jsxs("div", {
38460
38719
  className: 'babylai-flex babylai-flex-col babylai-gap-2',
38461
- children: [message.attachmentIds && message.attachmentIds.length > 0 && jsxRuntime.jsx("div", {
38720
+ children: [message.attachmentUrls && message.attachmentUrls.length > 0 && jsxRuntime.jsx("div", {
38721
+ className: 'babylai-flex babylai-flex-row babylai-flex-wrap babylai-gap-2 babylai-max-w-full',
38722
+ children: message.attachmentUrls.map((attachmentUrl, imgIndex) => jsxRuntime.jsx(ImageAttachment, {
38723
+ imageUrl: attachmentUrl,
38724
+ enablePreview: false,
38725
+ onClick: () => handleImageClick(imgIndex)
38726
+ }, attachmentUrl))
38727
+ }), message.attachmentIds && message.attachmentIds.length > 0 && jsxRuntime.jsx("div", {
38462
38728
  className: 'babylai-flex babylai-flex-row babylai-flex-wrap babylai-gap-2 babylai-max-w-full',
38463
38729
  children: message.attachmentIds.map((attachmentId, imgIndex) => jsxRuntime.jsx(ImageAttachment, {
38464
38730
  fileId: attachmentId,
38465
38731
  enablePreview: false,
38466
38732
  onClick: () => handleImageClick(imgIndex)
38467
38733
  }, attachmentId))
38468
- }), jsxRuntime.jsx(AgentResponse$1, {
38734
+ }), message.messageContent && message.messageContent.trim() !== '' && jsxRuntime.jsx(AgentResponse$1, {
38469
38735
  messageContent: message.messageContent,
38470
38736
  senderType: message.senderType,
38471
38737
  messageId: message.id,
@@ -38510,7 +38776,8 @@ var ChatWindow = /*#__PURE__*/React__default["default"].memo(_ref3 => {
38510
38776
  onEnsureSession,
38511
38777
  messages,
38512
38778
  assistantStatus = 'loading',
38513
- needsAgent
38779
+ needsAgent,
38780
+ sessionId
38514
38781
  } = _ref3;
38515
38782
  var {
38516
38783
  i18n
@@ -38553,7 +38820,8 @@ var ChatWindow = /*#__PURE__*/React__default["default"].memo(_ref3 => {
38553
38820
  };
38554
38821
  }, []);
38555
38822
  var handleSendMessage = React.useCallback(attachmentIds => {
38556
- if (inputMessage.trim()) {
38823
+ // Allow sending if there's text OR attachments
38824
+ if (inputMessage.trim() || attachmentIds.length > 0) {
38557
38825
  onSendMessage(inputMessage, attachmentIds);
38558
38826
  setInputMessage('');
38559
38827
  }
@@ -38564,13 +38832,32 @@ var ChatWindow = /*#__PURE__*/React__default["default"].memo(_ref3 => {
38564
38832
  }, [messages]);
38565
38833
  // Handle image gallery opening
38566
38834
  var handleImageClick = React.useCallback(/*#__PURE__*/function () {
38567
- var _ref4 = _asyncToGenerator(function* (attachmentIds, clickedIndex) {
38568
- if (!attachmentIds || attachmentIds.length === 0) {
38835
+ var _ref4 = _asyncToGenerator(function* (attachmentIdsOrUrls, clickedIndex) {
38836
+ var _a, _b;
38837
+ if (!attachmentIdsOrUrls || attachmentIdsOrUrls.length === 0) {
38569
38838
  return;
38570
38839
  }
38571
38840
  try {
38572
- // Fetch all image URLs with comprehensive error handling
38573
- var imageUrlPromises = attachmentIds.map(fileId => {
38841
+ // Check if the first item is a URL (starts with http:// or https://)
38842
+ // If so, they're all URLs from Ably and can be used directly
38843
+ var isUrl = ((_a = attachmentIdsOrUrls[0]) === null || _a === void 0 ? void 0 : _a.startsWith('http://')) || ((_b = attachmentIdsOrUrls[0]) === null || _b === void 0 ? void 0 : _b.startsWith('https://'));
38844
+ var imageUrls;
38845
+ if (isUrl) {
38846
+ // These are already URLs from Ably, use them directly (no async needed)
38847
+ imageUrls = attachmentIdsOrUrls.filter(url => url !== null && url.length > 0);
38848
+ // Open gallery immediately with URLs
38849
+ if (imageUrls.length > 0) {
38850
+ var _adjustedIndex = Math.max(0, Math.min(clickedIndex, imageUrls.length - 1));
38851
+ setGalleryState({
38852
+ isOpen: true,
38853
+ imageUrls,
38854
+ initialIndex: _adjustedIndex
38855
+ });
38856
+ }
38857
+ return; // Exit early since we don't need to fetch anything
38858
+ }
38859
+ // These are file IDs, need to fetch URLs using presignDownload
38860
+ var imageUrlPromises = attachmentIdsOrUrls.map(fileId => {
38574
38861
  if (!fileId || typeof fileId !== 'string') {
38575
38862
  return Promise.resolve(null);
38576
38863
  }
@@ -38584,7 +38871,7 @@ var ChatWindow = /*#__PURE__*/React__default["default"].memo(_ref3 => {
38584
38871
  return null;
38585
38872
  });
38586
38873
  });
38587
- var imageUrls = (yield Promise.all(imageUrlPromises)).filter(url => url !== null && url.length > 0);
38874
+ imageUrls = (yield Promise.all(imageUrlPromises)).filter(url => url !== null && url.length > 0);
38588
38875
  if (imageUrls.length === 0) {
38589
38876
  return;
38590
38877
  }
@@ -38646,7 +38933,8 @@ var ChatWindow = /*#__PURE__*/React__default["default"].memo(_ref3 => {
38646
38933
  handleSendMessage: handleSendMessage,
38647
38934
  setInputMessage: setInputMessage,
38648
38935
  isLoading: isLoading,
38649
- onEnsureSession: onEnsureSession
38936
+ onEnsureSession: onEnsureSession,
38937
+ sessionId: sessionId
38650
38938
  }), galleryState.isOpen && galleryState.imageUrls.length > 0 && jsxRuntime.jsx(ImagePreviewDialog, {
38651
38939
  imageUrls: galleryState.imageUrls,
38652
38940
  initialIndex: galleryState.initialIndex,
@@ -39265,7 +39553,8 @@ var HelpPopup = _ref => {
39265
39553
  }
39266
39554
  }, [onStartChat, setSelectedOption, sessionId, setStartNewChatConfirmation, setTempSelectedOption]);
39267
39555
  var handleSendMessage = React.useCallback((message, attachmentIds) => {
39268
- if (message.trim()) {
39556
+ // Allow sending if there's text OR attachments
39557
+ if (message.trim() || attachmentIds.length > 0) {
39269
39558
  onSendMessage(message.trim(), attachmentIds);
39270
39559
  }
39271
39560
  }, [onSendMessage]);
@@ -39321,7 +39610,8 @@ var HelpPopup = _ref => {
39321
39610
  messages: memoizedMessages,
39322
39611
  assistantStatus: assistantStatus,
39323
39612
  needsAgent: needsAgent,
39324
- isAblyConnected: isAblyConnected
39613
+ isAblyConnected: isAblyConnected,
39614
+ sessionId: sessionId
39325
39615
  })]
39326
39616
  });
39327
39617
  }
@@ -39460,7 +39750,7 @@ var HelpCenterContent = _ref => {
39460
39750
  sentAt: new Date(),
39461
39751
  isSeen: true
39462
39752
  }, attachments.length > 0 && {
39463
- attachmentIds: attachments
39753
+ attachmentUrls: attachments
39464
39754
  });
39465
39755
  return [...prevMessages, newMessage];
39466
39756
  });
@@ -39589,10 +39879,11 @@ var HelpCenterContent = _ref => {
39589
39879
  var handleEnsureSession = /*#__PURE__*/function () {
39590
39880
  var _ref7 = _asyncToGenerator(function* () {
39591
39881
  // If we already have a session ID and connection, return it
39592
- if (sessionId && isAblyConnected) {
39882
+ // NEVER create a new session if one already exists
39883
+ if (sessionId) {
39593
39884
  return sessionId;
39594
39885
  }
39595
- // If we have a selected option but no session, create one
39886
+ // Only create a new session if we don't have one and have a selected option
39596
39887
  if (selectedOption) {
39597
39888
  var newSessionId = yield startNewChatSession(selectedOption);
39598
39889
  return newSessionId;
@@ -39606,28 +39897,32 @@ var HelpCenterContent = _ref => {
39606
39897
  var handleSendMessage = /*#__PURE__*/function () {
39607
39898
  var _ref8 = _asyncToGenerator(function* (message) {
39608
39899
  var attachmentIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
39609
- if (message.trim() !== '') {
39900
+ // Allow sending if there's text OR attachments
39901
+ if (message.trim() !== '' || attachmentIds.length > 0) {
39610
39902
  try {
39611
39903
  setAssistantStatus('typing');
39612
39904
  var userMessage = {
39613
39905
  id: Date.now(),
39614
39906
  senderType: 1,
39615
- messageContent: message,
39907
+ messageContent: message || '',
39908
+ // Use empty string if message is empty but attachments exist
39616
39909
  sentAt: new Date(),
39617
39910
  isSeen: false,
39618
39911
  attachmentIds: attachmentIds.length > 0 ? attachmentIds : undefined
39619
39912
  };
39620
39913
  setMessages(prevMessages => [...prevMessages, userMessage]);
39621
- // Handle session creation if needed
39914
+ // Handle session creation if needed - only create if no session exists
39622
39915
  var currentSessionId = sessionId;
39623
- if (!isAblyConnected && selectedOption) {
39916
+ // Only create a new session if we don't have one and we have a selected option
39917
+ // This ensures session is only created once with the first message
39918
+ if (!currentSessionId && !isAblyConnected && selectedOption) {
39624
39919
  currentSessionId = yield startNewChatSession(selectedOption);
39625
39920
  }
39626
39921
  if (!currentSessionId) {
39627
39922
  throw new Error('No active session available');
39628
39923
  }
39629
39924
  var messageDto = _objectSpread2({
39630
- messageContent: message
39925
+ messageContent: message || ''
39631
39926
  }, attachmentIds.length > 0 && {
39632
39927
  attachmentIds
39633
39928
  });