@webex/plugin-meetings 3.12.0-next.11 → 3.12.0-next.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +15 -2
  3. package/dist/aiEnableRequest/index.js.map +1 -1
  4. package/dist/breakouts/breakout.js +8 -3
  5. package/dist/breakouts/breakout.js.map +1 -1
  6. package/dist/breakouts/events.js +29 -14
  7. package/dist/breakouts/events.js.map +1 -1
  8. package/dist/breakouts/index.js +90 -3
  9. package/dist/breakouts/index.js.map +1 -1
  10. package/dist/common/errors/webex-errors.js +49 -5
  11. package/dist/common/errors/webex-errors.js.map +1 -1
  12. package/dist/config.js +2 -2
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants.js +37 -10
  15. package/dist/constants.js.map +1 -1
  16. package/dist/controls-options-manager/constants.js +11 -1
  17. package/dist/controls-options-manager/constants.js.map +1 -1
  18. package/dist/controls-options-manager/index.js +67 -29
  19. package/dist/controls-options-manager/index.js.map +1 -1
  20. package/dist/controls-options-manager/util.js +91 -0
  21. package/dist/controls-options-manager/util.js.map +1 -1
  22. package/dist/hashTree/constants.js +4 -1
  23. package/dist/hashTree/constants.js.map +1 -1
  24. package/dist/hashTree/hashTreeParser.js +1003 -393
  25. package/dist/hashTree/hashTreeParser.js.map +1 -1
  26. package/dist/hashTree/utils.js +20 -0
  27. package/dist/hashTree/utils.js.map +1 -1
  28. package/dist/index.js +7 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/interceptors/dataChannelAuthToken.js +75 -15
  31. package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
  32. package/dist/interceptors/locusRetry.js +23 -8
  33. package/dist/interceptors/locusRetry.js.map +1 -1
  34. package/dist/interpretation/index.js +10 -1
  35. package/dist/interpretation/index.js.map +1 -1
  36. package/dist/interpretation/interpretation.types.js +7 -0
  37. package/dist/interpretation/interpretation.types.js.map +1 -0
  38. package/dist/interpretation/siLanguage.js +1 -1
  39. package/dist/locus-info/controlsUtils.js +4 -1
  40. package/dist/locus-info/controlsUtils.js.map +1 -1
  41. package/dist/locus-info/index.js +406 -121
  42. package/dist/locus-info/index.js.map +1 -1
  43. package/dist/locus-info/infoUtils.js +36 -5
  44. package/dist/locus-info/infoUtils.js.map +1 -1
  45. package/dist/locus-info/types.js +19 -0
  46. package/dist/locus-info/types.js.map +1 -1
  47. package/dist/media/MediaConnectionAwaiter.js +15 -2
  48. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  49. package/dist/media/index.js +8 -2
  50. package/dist/media/index.js.map +1 -1
  51. package/dist/media/properties.js +4 -5
  52. package/dist/media/properties.js.map +1 -1
  53. package/dist/meeting/in-meeting-actions.js +5 -1
  54. package/dist/meeting/in-meeting-actions.js.map +1 -1
  55. package/dist/meeting/index.js +1662 -829
  56. package/dist/meeting/index.js.map +1 -1
  57. package/dist/meeting/locusMediaRequest.js +229 -82
  58. package/dist/meeting/locusMediaRequest.js.map +1 -1
  59. package/dist/meeting/muteState.js +10 -1
  60. package/dist/meeting/muteState.js.map +1 -1
  61. package/dist/meeting/request.js +5 -2
  62. package/dist/meeting/request.js.map +1 -1
  63. package/dist/meeting/util.js +34 -2
  64. package/dist/meeting/util.js.map +1 -1
  65. package/dist/meeting-info/meeting-info-v2.js +2 -2
  66. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  67. package/dist/meetings/index.js +256 -118
  68. package/dist/meetings/index.js.map +1 -1
  69. package/dist/meetings/meetings.types.js +6 -1
  70. package/dist/meetings/meetings.types.js.map +1 -1
  71. package/dist/meetings/request.js +39 -0
  72. package/dist/meetings/request.js.map +1 -1
  73. package/dist/meetings/util.js +116 -18
  74. package/dist/meetings/util.js.map +1 -1
  75. package/dist/member/index.js +10 -0
  76. package/dist/member/index.js.map +1 -1
  77. package/dist/member/types.js.map +1 -1
  78. package/dist/member/util.js +30 -0
  79. package/dist/member/util.js.map +1 -1
  80. package/dist/members/index.js +101 -43
  81. package/dist/members/index.js.map +1 -1
  82. package/dist/members/util.js +8 -1
  83. package/dist/members/util.js.map +1 -1
  84. package/dist/metrics/constants.js +7 -1
  85. package/dist/metrics/constants.js.map +1 -1
  86. package/dist/multistream/codec/constants.js +63 -0
  87. package/dist/multistream/codec/constants.js.map +1 -0
  88. package/dist/multistream/mediaRequestManager.js +62 -15
  89. package/dist/multistream/mediaRequestManager.js.map +1 -1
  90. package/dist/multistream/receiveSlot.js +9 -0
  91. package/dist/multistream/receiveSlot.js.map +1 -1
  92. package/dist/reachability/clusterReachability.js.map +1 -1
  93. package/dist/reachability/index.js +121 -83
  94. package/dist/reachability/index.js.map +1 -1
  95. package/dist/reachability/reachability.types.js +2 -0
  96. package/dist/reachability/reachability.types.js.map +1 -1
  97. package/dist/reachability/util.js +45 -0
  98. package/dist/reachability/util.js.map +1 -1
  99. package/dist/reactions/reactions.type.js.map +1 -1
  100. package/dist/recording-controller/index.js +1 -3
  101. package/dist/recording-controller/index.js.map +1 -1
  102. package/dist/roap/turnDiscovery.js +8 -1
  103. package/dist/roap/turnDiscovery.js.map +1 -1
  104. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  105. package/dist/types/config.d.ts +2 -2
  106. package/dist/types/constants.d.ts +13 -1
  107. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  108. package/dist/types/controls-options-manager/index.d.ts +16 -0
  109. package/dist/types/hashTree/constants.d.ts +1 -0
  110. package/dist/types/hashTree/hashTreeParser.d.ts +178 -22
  111. package/dist/types/hashTree/utils.d.ts +7 -0
  112. package/dist/types/index.d.ts +3 -0
  113. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  114. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  115. package/dist/types/locus-info/index.d.ts +61 -7
  116. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  117. package/dist/types/locus-info/types.d.ts +21 -1
  118. package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
  119. package/dist/types/media/properties.d.ts +6 -2
  120. package/dist/types/meeting/in-meeting-actions.d.ts +4 -0
  121. package/dist/types/meeting/index.d.ts +175 -11
  122. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  123. package/dist/types/meeting/request.d.ts +1 -0
  124. package/dist/types/meeting/util.d.ts +9 -0
  125. package/dist/types/meetings/index.d.ts +38 -18
  126. package/dist/types/meetings/meetings.types.d.ts +15 -0
  127. package/dist/types/meetings/request.d.ts +14 -0
  128. package/dist/types/member/index.d.ts +1 -0
  129. package/dist/types/member/types.d.ts +1 -0
  130. package/dist/types/member/util.d.ts +9 -0
  131. package/dist/types/members/index.d.ts +15 -2
  132. package/dist/types/members/util.d.ts +1 -5
  133. package/dist/types/metrics/constants.d.ts +6 -0
  134. package/dist/types/multistream/codec/constants.d.ts +7 -0
  135. package/dist/types/multistream/mediaRequestManager.d.ts +22 -5
  136. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  137. package/dist/types/reachability/index.d.ts +10 -3
  138. package/dist/types/reachability/reachability.types.d.ts +7 -0
  139. package/dist/types/reachability/util.d.ts +17 -0
  140. package/dist/types/reactions/reactions.type.d.ts +3 -0
  141. package/dist/webinar/index.js +307 -161
  142. package/dist/webinar/index.js.map +1 -1
  143. package/package.json +23 -23
  144. package/src/aiEnableRequest/index.ts +16 -0
  145. package/src/breakouts/breakout.ts +3 -1
  146. package/src/breakouts/events.ts +33 -11
  147. package/src/breakouts/index.ts +110 -1
  148. package/src/common/errors/webex-errors.ts +50 -3
  149. package/src/config.ts +2 -2
  150. package/src/constants.ts +21 -3
  151. package/src/controls-options-manager/constants.ts +14 -1
  152. package/src/controls-options-manager/index.ts +87 -28
  153. package/src/controls-options-manager/util.ts +81 -1
  154. package/src/hashTree/constants.ts +7 -0
  155. package/src/hashTree/hashTreeParser.ts +752 -192
  156. package/src/hashTree/utils.ts +19 -0
  157. package/src/index.ts +6 -0
  158. package/src/interceptors/dataChannelAuthToken.ts +88 -12
  159. package/src/interceptors/locusRetry.ts +25 -4
  160. package/src/interpretation/index.ts +27 -9
  161. package/src/interpretation/interpretation.types.ts +11 -0
  162. package/src/locus-info/controlsUtils.ts +3 -1
  163. package/src/locus-info/index.ts +412 -130
  164. package/src/locus-info/infoUtils.ts +41 -6
  165. package/src/locus-info/types.ts +25 -1
  166. package/src/media/MediaConnectionAwaiter.ts +21 -4
  167. package/src/media/index.ts +10 -1
  168. package/src/media/properties.ts +8 -3
  169. package/src/meeting/in-meeting-actions.ts +8 -0
  170. package/src/meeting/index.ts +913 -111
  171. package/src/meeting/locusMediaRequest.ts +106 -6
  172. package/src/meeting/muteState.ts +10 -1
  173. package/src/meeting/request.ts +11 -0
  174. package/src/meeting/util.ts +46 -5
  175. package/src/meeting-info/meeting-info-v2.ts +4 -2
  176. package/src/meetings/index.ts +168 -79
  177. package/src/meetings/meetings.types.ts +19 -0
  178. package/src/meetings/request.ts +43 -0
  179. package/src/meetings/util.ts +117 -4
  180. package/src/member/index.ts +10 -0
  181. package/src/member/types.ts +1 -0
  182. package/src/member/util.ts +29 -0
  183. package/src/members/index.ts +70 -7
  184. package/src/members/util.ts +12 -4
  185. package/src/metrics/constants.ts +6 -0
  186. package/src/multistream/codec/constants.ts +58 -0
  187. package/src/multistream/mediaRequestManager.ts +119 -28
  188. package/src/multistream/receiveSlot.ts +18 -0
  189. package/src/reachability/clusterReachability.ts +3 -2
  190. package/src/reachability/index.ts +47 -16
  191. package/src/reachability/reachability.types.ts +11 -0
  192. package/src/reachability/util.ts +36 -0
  193. package/src/reactions/reactions.type.ts +3 -0
  194. package/src/recording-controller/index.ts +1 -2
  195. package/src/roap/turnDiscovery.ts +9 -1
  196. package/src/webinar/index.ts +216 -38
  197. package/test/unit/spec/aiEnableRequest/index.ts +86 -0
  198. package/test/unit/spec/breakouts/breakout.ts +9 -3
  199. package/test/unit/spec/breakouts/events.ts +120 -2
  200. package/test/unit/spec/breakouts/index.ts +191 -2
  201. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  202. package/test/unit/spec/controls-options-manager/index.js +244 -29
  203. package/test/unit/spec/controls-options-manager/util.js +165 -0
  204. package/test/unit/spec/hashTree/hashTreeParser.ts +2110 -170
  205. package/test/unit/spec/hashTree/utils.ts +37 -0
  206. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +196 -0
  207. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  208. package/test/unit/spec/interpretation/index.ts +26 -4
  209. package/test/unit/spec/locus-info/controlsUtils.js +172 -57
  210. package/test/unit/spec/locus-info/index.js +643 -63
  211. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  212. package/test/unit/spec/media/MediaConnectionAwaiter.ts +55 -0
  213. package/test/unit/spec/media/index.ts +92 -0
  214. package/test/unit/spec/media/properties.ts +23 -23
  215. package/test/unit/spec/meeting/in-meeting-actions.ts +4 -0
  216. package/test/unit/spec/meeting/index.js +2711 -183
  217. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  218. package/test/unit/spec/meeting/muteState.js +81 -0
  219. package/test/unit/spec/meeting/request.js +12 -0
  220. package/test/unit/spec/meeting/utils.js +153 -1
  221. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  222. package/test/unit/spec/meetings/index.js +467 -36
  223. package/test/unit/spec/meetings/request.js +141 -0
  224. package/test/unit/spec/meetings/utils.js +402 -51
  225. package/test/unit/spec/member/index.js +7 -0
  226. package/test/unit/spec/member/util.js +89 -0
  227. package/test/unit/spec/members/index.js +216 -0
  228. package/test/unit/spec/members/request.js +37 -1
  229. package/test/unit/spec/members/utils.js +63 -0
  230. package/test/unit/spec/multistream/mediaRequestManager.ts +501 -37
  231. package/test/unit/spec/reachability/index.ts +128 -46
  232. package/test/unit/spec/reachability/util.ts +31 -0
  233. package/test/unit/spec/recording-controller/index.js +9 -8
  234. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  235. package/test/unit/spec/webinar/index.ts +332 -31
@@ -15,17 +15,18 @@ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequ
15
15
  _Object$defineProperty(exports, "__esModule", {
16
16
  value: true
17
17
  });
18
- exports.default = exports.MeetingEndedError = exports.LocusInfoUpdateType = void 0;
18
+ exports.default = exports.SyncAllBackoffType = exports.MeetingEndedError = exports.LocusNotFoundError = exports.LocusInfoUpdateType = void 0;
19
19
  var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
20
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
20
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/set"));
21
21
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
22
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
22
23
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
23
24
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
24
25
  var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));
25
26
  var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/parse-int"));
27
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
26
28
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
27
29
  var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/typeof"));
28
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
29
30
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
30
31
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
31
32
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
@@ -37,9 +38,12 @@ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime-corejs2/h
37
38
  var _lodash = require("lodash");
38
39
  var _hashTree = _interopRequireDefault(require("./hashTree"));
39
40
  var _loggerProxy = _interopRequireDefault(require("../common/logs/logger-proxy"));
40
- var _constants = require("../constants");
41
- var _constants2 = require("./constants");
41
+ var _metrics = _interopRequireDefault(require("../metrics"));
42
+ var _constants = _interopRequireDefault(require("../metrics/constants"));
43
+ var _constants2 = require("../constants");
44
+ var _constants3 = require("./constants");
42
45
  var _types = require("./types");
46
+ var _types2 = require("../locus-info/types");
43
47
  var _utils = require("./utils");
44
48
  function ownKeys(e, r) { var t = _Object$keys4(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
45
49
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -48,10 +52,18 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
48
52
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
49
53
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
50
54
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
55
+ var SyncAllBackoffType = exports.SyncAllBackoffType = /*#__PURE__*/function (SyncAllBackoffType) {
56
+ SyncAllBackoffType["NONE"] = "none";
57
+ SyncAllBackoffType["ONLY_LLM"] = "onlyLLM";
58
+ SyncAllBackoffType["ALL"] = "all";
59
+ return SyncAllBackoffType;
60
+ }({});
51
61
  var LocusInfoUpdateType = exports.LocusInfoUpdateType = {
52
62
  OBJECTS_UPDATED: 'OBJECTS_UPDATED',
53
- MEETING_ENDED: 'MEETING_ENDED'
63
+ MEETING_ENDED: 'MEETING_ENDED',
64
+ LOCUS_NOT_FOUND: 'LOCUS_NOT_FOUND'
54
65
  };
66
+ var SYNC_METRICS_DATA_SETS = [_constants3.DataSetNames.MAIN, _constants3.DataSetNames.ATD_ACTIVE, _constants3.DataSetNames.ATD_UNMUTED];
55
67
  /**
56
68
  * This error is thrown if we receive information that the meeting has ended while we're processing some hash messages.
57
69
  * It's handled internally by HashTreeParser and results in MEETING_ENDED being sent up.
@@ -64,11 +76,24 @@ var MeetingEndedError = exports.MeetingEndedError = /*#__PURE__*/function (_Erro
64
76
  (0, _inherits2.default)(MeetingEndedError, _Error);
65
77
  return (0, _createClass2.default)(MeetingEndedError);
66
78
  }(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
79
+ /**
80
+ * This error is thrown when a 404 is received from Locus hash tree endpoints, indicating that the locus URL
81
+ * is no longer valid (e.g. participant moved to a breakout room, or meeting ended).
82
+ * It's handled internally by HashTreeParser and results in LOCUS_NOT_FOUND being sent up.
83
+ */
84
+ var LocusNotFoundError = exports.LocusNotFoundError = /*#__PURE__*/function (_Error2) {
85
+ function LocusNotFoundError() {
86
+ (0, _classCallCheck2.default)(this, LocusNotFoundError);
87
+ return _callSuper(this, LocusNotFoundError, arguments);
88
+ }
89
+ (0, _inherits2.default)(LocusNotFoundError, _Error2);
90
+ return (0, _createClass2.default)(LocusNotFoundError);
91
+ }(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
67
92
  /* Currently Locus always sends Metadata objects only in the "self" dataset.
68
93
  * If this ever changes, update all the code that relies on this constant.
69
94
  */
70
- var MetadataDataSetName = _constants2.DataSetNames.SELF;
71
- var PossibleSentinelMessageDataSetNames = [_constants2.DataSetNames.MAIN, _constants2.DataSetNames.SELF, _constants2.DataSetNames.UNJOINED];
95
+ var MetadataDataSetName = _constants3.DataSetNames.SELF;
96
+ var PossibleSentinelMessageDataSetNames = [_constants3.DataSetNames.MAIN, _constants3.DataSetNames.SELF, _constants3.DataSetNames.UNJOINED];
72
97
 
73
98
  /**
74
99
  * Parses hash tree eventing locus data
@@ -86,19 +111,29 @@ var HashTreeParser = /*#__PURE__*/function () {
86
111
  (0, _defineProperty2.default)(this, "visibleDataSetsUrl", void 0);
87
112
  // url from which we can get info about all data sets
88
113
  (0, _defineProperty2.default)(this, "webexRequest", void 0);
89
- (0, _defineProperty2.default)(this, "locusInfoUpdateCallback", void 0);
114
+ (0, _defineProperty2.default)(this, "callbacks", void 0);
115
+ (0, _defineProperty2.default)(this, "syncLatencyMeetingId", void 0);
90
116
  (0, _defineProperty2.default)(this, "visibleDataSets", void 0);
91
117
  (0, _defineProperty2.default)(this, "debugId", void 0);
92
- (0, _defineProperty2.default)(this, "heartbeatIntervalMs", void 0);
93
118
  (0, _defineProperty2.default)(this, "excludedDataSets", void 0);
94
119
  (0, _defineProperty2.default)(this, "state", void 0);
120
+ (0, _defineProperty2.default)(this, "syncQueue", []);
121
+ (0, _defineProperty2.default)(this, "isSyncInProgress", false);
122
+ // tracks whether syncAllDatasets is currently in its backoff delay phase and with what scope
123
+ (0, _defineProperty2.default)(this, "syncAllBackoffType", SyncAllBackoffType.NONE);
124
+ // datasets that received messages during the syncAllDatasets backoff sleep and should be skipped
125
+ (0, _defineProperty2.default)(this, "dataSetsSyncedDuringBackoff", new _set.default());
126
+ (0, _defineProperty2.default)(this, "syncQueueProcessingPromise", _promise.default.resolve());
127
+ // top-level heartbeat interval from the most recent message, used as fallback when dataset-level value is missing
128
+ (0, _defineProperty2.default)(this, "topLevelHeartbeatIntervalMs", void 0);
95
129
  var _options$initialLocus = options.initialLocus,
96
130
  dataSets = _options$initialLocus.dataSets,
97
131
  locus = _options$initialLocus.locus; // extract dataSets from initialLocus
98
132
 
99
133
  this.debugId = options.debugId;
100
134
  this.webexRequest = options.webexRequest;
101
- this.locusInfoUpdateCallback = options.locusInfoUpdateCallback;
135
+ this.callbacks = options.callbacks;
136
+ this.syncLatencyMeetingId = options.syncLatencyMeetingId;
102
137
  this.excludedDataSets = options.excludedDataSets || [];
103
138
  this.visibleDataSetsUrl = locus === null || locus === void 0 ? void 0 : (_locus$links = locus.links) === null || _locus$links === void 0 ? void 0 : (_locus$links$resource = _locus$links.resources) === null || _locus$links$resource === void 0 ? void 0 : (_locus$links$resource2 = _locus$links$resource.visibleDataSets) === null || _locus$links$resource2 === void 0 ? void 0 : _locus$links$resource2.url;
104
139
  this.setVisibleDataSets(((_options$metadata = options.metadata) === null || _options$metadata === void 0 ? void 0 : _options$metadata.visibleDataSets) || [], dataSets);
@@ -212,83 +247,65 @@ var HashTreeParser = /*#__PURE__*/function () {
212
247
  */
213
248
  }, {
214
249
  key: "initializeNewVisibleDataSet",
215
- value: function initializeNewVisibleDataSet(visibleDataSetInfo, dataSetInfo) {
216
- if (this.isVisibleDataSet(dataSetInfo.name)) {
217
- _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Data set \"").concat(dataSetInfo.name, "\" already exists, skipping init"));
218
- return _promise.default.resolve({
219
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
220
- updatedObjects: []
221
- });
222
- }
223
- _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Adding visible data set \"").concat(dataSetInfo.name, "\""));
224
- if (!this.addToVisibleDataSetsList(visibleDataSetInfo)) {
225
- return _promise.default.resolve({
226
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
227
- updatedObjects: []
228
- });
229
- }
230
- var hashTree = new _hashTree.default([], dataSetInfo.leafCount);
231
- this.dataSets[dataSetInfo.name] = _objectSpread(_objectSpread({}, dataSetInfo), {}, {
232
- hashTree: hashTree
233
- });
234
- return this.sendInitializationSyncRequestToLocus(dataSetInfo.name, 'new visible data set');
235
- }
236
-
237
- /**
238
- * Sends a special sync request to Locus with all leaves empty - this is a way to get all the data for a given dataset.
239
- *
240
- * @param {string} datasetName - name of the dataset for which to send the request
241
- * @param {string} debugText - text to include in logs
242
- * @returns {Promise}
243
- */
244
- }, {
245
- key: "sendInitializationSyncRequestToLocus",
246
- value: function sendInitializationSyncRequestToLocus(datasetName, debugText) {
247
- var _this2 = this;
248
- var dataset = this.dataSets[datasetName];
249
- if (!dataset) {
250
- _loggerProxy.default.logger.warn("HashTreeParser#sendInitializationSyncRequestToLocus --> ".concat(this.debugId, " No data set found for ").concat(datasetName, ", cannot send the request for leaf data"));
251
- return _promise.default.resolve({
252
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
253
- updatedObjects: []
254
- });
250
+ value: (function () {
251
+ var _initializeNewVisibleDataSet = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(visibleDataSetInfo, dataSetInfo) {
252
+ var hashTree;
253
+ return _regenerator.default.wrap(function (_context) {
254
+ while (1) switch (_context.prev = _context.next) {
255
+ case 0:
256
+ if (!this.isVisibleDataSet(dataSetInfo.name)) {
257
+ _context.next = 1;
258
+ break;
259
+ }
260
+ _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Data set \"").concat(dataSetInfo.name, "\" already exists, skipping init"));
261
+ return _context.abrupt("return");
262
+ case 1:
263
+ _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Adding visible data set \"").concat(dataSetInfo.name, "\""));
264
+ if (this.addToVisibleDataSetsList(visibleDataSetInfo)) {
265
+ _context.next = 2;
266
+ break;
267
+ }
268
+ return _context.abrupt("return");
269
+ case 2:
270
+ hashTree = new _hashTree.default([], dataSetInfo.leafCount);
271
+ this.dataSets[dataSetInfo.name] = _objectSpread(_objectSpread({}, dataSetInfo), {}, {
272
+ hashTree: hashTree
273
+ });
274
+ this.enqueueSyncForDataset(dataSetInfo.name, 'new visible data set initialization', true);
275
+ _context.next = 3;
276
+ return this.syncQueueProcessingPromise;
277
+ case 3:
278
+ case "end":
279
+ return _context.stop();
280
+ }
281
+ }, _callee, this);
282
+ }));
283
+ function initializeNewVisibleDataSet(_x, _x2) {
284
+ return _initializeNewVisibleDataSet.apply(this, arguments);
255
285
  }
256
- var emptyLeavesData = new Array(dataset.leafCount).fill([]);
257
- _loggerProxy.default.logger.info("HashTreeParser#sendInitializationSyncRequestToLocus --> ".concat(this.debugId, " Sending initial sync request to Locus for data set \"").concat(datasetName, "\" with empty leaf data"));
258
- return this.sendSyncRequestToLocus(this.dataSets[datasetName], emptyLeavesData).then(function (syncResponse) {
259
- if (syncResponse) {
260
- return {
261
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
262
- updatedObjects: _this2.parseMessage(syncResponse, "via empty leaves /sync API call for ".concat(debugText))
263
- };
264
- }
265
- return {
266
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
267
- updatedObjects: []
268
- };
269
- });
270
- }
271
-
286
+ return initializeNewVisibleDataSet;
287
+ }()
272
288
  /**
273
289
  * Queries Locus for all up-to-date information about all visible data sets
274
290
  *
275
291
  * @returns {Promise}
276
292
  */
293
+ )
277
294
  }, {
278
295
  key: "getAllVisibleDataSetsFromLocus",
279
296
  value: function getAllVisibleDataSetsFromLocus() {
280
- var _this3 = this;
297
+ var _this2 = this;
281
298
  if (!this.visibleDataSetsUrl) {
282
299
  _loggerProxy.default.logger.warn("HashTreeParser#getAllVisibleDataSetsFromLocus --> ".concat(this.debugId, " No visibleDataSetsUrl, cannot get data sets information"));
283
300
  return _promise.default.resolve([]);
284
301
  }
285
302
  return this.webexRequest({
286
- method: _constants.HTTP_VERBS.GET,
303
+ method: _constants2.HTTP_VERBS.GET,
287
304
  uri: this.visibleDataSetsUrl
288
305
  }).then(function (response) {
289
306
  return response.body.dataSets;
290
307
  }).catch(function (error) {
291
- _this3.checkForSentinelHttpResponse(error);
308
+ _this2.checkForSentinelHttpResponse(error);
292
309
  throw error;
293
310
  });
294
311
  }
@@ -302,26 +319,26 @@ var HashTreeParser = /*#__PURE__*/function () {
302
319
  }, {
303
320
  key: "initializeFromMessage",
304
321
  value: (function () {
305
- var _initializeFromMessage = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(message) {
322
+ var _initializeFromMessage = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(message) {
306
323
  var visibleDataSets;
307
- return _regenerator.default.wrap(function (_context) {
308
- while (1) switch (_context.prev = _context.next) {
324
+ return _regenerator.default.wrap(function (_context2) {
325
+ while (1) switch (_context2.prev = _context2.next) {
309
326
  case 0:
310
327
  this.visibleDataSetsUrl = message.visibleDataSetsUrl;
311
328
  _loggerProxy.default.logger.info("HashTreeParser#initializeFromMessage --> ".concat(this.debugId, " visibleDataSetsUrl=").concat(this.visibleDataSetsUrl));
312
- _context.next = 1;
329
+ _context2.next = 1;
313
330
  return this.getAllVisibleDataSetsFromLocus();
314
331
  case 1:
315
- visibleDataSets = _context.sent;
316
- _context.next = 2;
332
+ visibleDataSets = _context2.sent;
333
+ _context2.next = 2;
317
334
  return this.initializeDataSets(visibleDataSets, 'initialization from message');
318
335
  case 2:
319
336
  case "end":
320
- return _context.stop();
337
+ return _context2.stop();
321
338
  }
322
- }, _callee, this);
339
+ }, _callee2, this);
323
340
  }));
324
- function initializeFromMessage(_x) {
341
+ function initializeFromMessage(_x3) {
325
342
  return _initializeFromMessage.apply(this, arguments);
326
343
  }
327
344
  return initializeFromMessage;
@@ -339,34 +356,34 @@ var HashTreeParser = /*#__PURE__*/function () {
339
356
  }, {
340
357
  key: "initializeFromGetLociResponse",
341
358
  value: (function () {
342
- var _initializeFromGetLociResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(locus) {
359
+ var _initializeFromGetLociResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(locus) {
343
360
  var _locus$links2, _locus$links2$resourc, _locus$links2$resourc2;
344
361
  var visibleDataSets;
345
- return _regenerator.default.wrap(function (_context2) {
346
- while (1) switch (_context2.prev = _context2.next) {
362
+ return _regenerator.default.wrap(function (_context3) {
363
+ while (1) switch (_context3.prev = _context3.next) {
347
364
  case 0:
348
365
  if (locus !== null && locus !== void 0 && (_locus$links2 = locus.links) !== null && _locus$links2 !== void 0 && (_locus$links2$resourc = _locus$links2.resources) !== null && _locus$links2$resourc !== void 0 && (_locus$links2$resourc2 = _locus$links2$resourc.visibleDataSets) !== null && _locus$links2$resourc2 !== void 0 && _locus$links2$resourc2.url) {
349
- _context2.next = 1;
366
+ _context3.next = 1;
350
367
  break;
351
368
  }
352
369
  _loggerProxy.default.logger.warn("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " missing visibleDataSets url in GET Loci response, cannot initialize hash trees"));
353
- return _context2.abrupt("return");
370
+ return _context3.abrupt("return");
354
371
  case 1:
355
372
  this.visibleDataSetsUrl = locus.links.resources.visibleDataSets.url;
356
373
  _loggerProxy.default.logger.info("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " visibleDataSets url: ").concat(this.visibleDataSetsUrl));
357
- _context2.next = 2;
374
+ _context3.next = 2;
358
375
  return this.getAllVisibleDataSetsFromLocus();
359
376
  case 2:
360
- visibleDataSets = _context2.sent;
361
- _context2.next = 3;
377
+ visibleDataSets = _context3.sent;
378
+ _context3.next = 3;
362
379
  return this.initializeDataSets(visibleDataSets, 'initialization from GET /loci response');
363
380
  case 3:
364
381
  case "end":
365
- return _context2.stop();
382
+ return _context3.stop();
366
383
  }
367
- }, _callee2, this);
384
+ }, _callee3, this);
368
385
  }));
369
- function initializeFromGetLociResponse(_x2) {
386
+ function initializeFromGetLociResponse(_x4) {
370
387
  return _initializeFromGetLociResponse.apply(this, arguments);
371
388
  }
372
389
  return initializeFromGetLociResponse;
@@ -382,24 +399,23 @@ var HashTreeParser = /*#__PURE__*/function () {
382
399
  }, {
383
400
  key: "initializeDataSets",
384
401
  value: (function () {
385
- var _initializeDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(visibleDataSets, debugText) {
386
- var updatedObjects, _iterator2, _step2, dataSet, name, leafCount, url, data, _t;
387
- return _regenerator.default.wrap(function (_context3) {
388
- while (1) switch (_context3.prev = _context3.next) {
402
+ var _initializeDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(visibleDataSets, debugText) {
403
+ var _iterator2, _step2, dataSet, name, leafCount, url, _t;
404
+ return _regenerator.default.wrap(function (_context4) {
405
+ while (1) switch (_context4.prev = _context4.next) {
389
406
  case 0:
390
407
  if (!(this.state === 'stopped')) {
391
- _context3.next = 1;
408
+ _context4.next = 1;
392
409
  break;
393
410
  }
394
- return _context3.abrupt("return");
411
+ return _context4.abrupt("return");
395
412
  case 1:
396
- updatedObjects = [];
397
- _iterator2 = _createForOfIteratorHelper((0, _utils.sortByInitPriority)(visibleDataSets, _constants2.DATA_SET_INIT_PRIORITY));
398
- _context3.prev = 2;
413
+ _iterator2 = _createForOfIteratorHelper((0, _utils.sortByInitPriority)(visibleDataSets, _constants3.DATA_SET_INIT_PRIORITY));
414
+ _context4.prev = 2;
399
415
  _iterator2.s();
400
416
  case 3:
401
417
  if ((_step2 = _iterator2.n()).done) {
402
- _context3.next = 7;
418
+ _context4.next = 6;
403
419
  break;
404
420
  }
405
421
  dataSet = _step2.value;
@@ -411,59 +427,47 @@ var HashTreeParser = /*#__PURE__*/function () {
411
427
  _loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " dataset \"").concat(name, "\" already exists (").concat(debugText, ")"));
412
428
  }
413
429
  if (this.isVisibleDataSet(name)) {
414
- _context3.next = 4;
430
+ _context4.next = 4;
415
431
  break;
416
432
  }
417
433
  if (this.addToVisibleDataSetsList({
418
434
  name: name,
419
435
  url: url
420
436
  })) {
421
- _context3.next = 4;
437
+ _context4.next = 4;
422
438
  break;
423
439
  }
424
- return _context3.abrupt("continue", 6);
440
+ return _context4.abrupt("continue", 5);
425
441
  case 4:
426
- if (this.dataSets[name].hashTree) {
427
- _context3.next = 6;
428
- break;
442
+ if (!this.dataSets[name].hashTree) {
443
+ _loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " creating hash tree for visible dataset \"").concat(name, "\" (").concat(debugText, ")"));
444
+ this.dataSets[name].hashTree = new _hashTree.default([], leafCount);
445
+ this.enqueueSyncForDataset(name, "initialization sync for ".concat(debugText), true);
429
446
  }
430
- _loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " creating hash tree for visible dataset \"").concat(name, "\" (").concat(debugText, ")"));
431
- this.dataSets[name].hashTree = new _hashTree.default([], leafCount);
432
-
433
- // eslint-disable-next-line no-await-in-loop
434
- _context3.next = 5;
435
- return this.sendInitializationSyncRequestToLocus(name, debugText);
436
447
  case 5:
437
- data = _context3.sent;
438
- if (data.updateType === LocusInfoUpdateType.OBJECTS_UPDATED) {
439
- updatedObjects.push.apply(updatedObjects, (0, _toConsumableArray2.default)(data.updatedObjects || []));
440
- }
448
+ _context4.next = 3;
449
+ break;
441
450
  case 6:
442
- _context3.next = 3;
451
+ _context4.next = 8;
443
452
  break;
444
453
  case 7:
445
- _context3.next = 9;
446
- break;
447
- case 8:
448
- _context3.prev = 8;
449
- _t = _context3["catch"](2);
454
+ _context4.prev = 7;
455
+ _t = _context4["catch"](2);
450
456
  _iterator2.e(_t);
451
- case 9:
452
- _context3.prev = 9;
457
+ case 8:
458
+ _context4.prev = 8;
453
459
  _iterator2.f();
454
- return _context3.finish(9);
460
+ return _context4.finish(8);
461
+ case 9:
462
+ _context4.next = 10;
463
+ return this.syncQueueProcessingPromise;
455
464
  case 10:
456
- this.callLocusInfoUpdateCallback({
457
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
458
- updatedObjects: updatedObjects
459
- });
460
- case 11:
461
465
  case "end":
462
- return _context3.stop();
466
+ return _context4.stop();
463
467
  }
464
- }, _callee3, this, [[2, 8, 9, 10]]);
468
+ }, _callee4, this, [[2, 7, 8, 9]]);
465
469
  }));
466
- function initializeDataSets(_x3, _x4) {
470
+ function initializeDataSets(_x5, _x6) {
467
471
  return _initializeDataSets.apply(this, arguments);
468
472
  }
469
473
  return initializeDataSets;
@@ -599,9 +603,9 @@ var HashTreeParser = /*#__PURE__*/function () {
599
603
  }, {
600
604
  key: "isEndMessage",
601
605
  value: function isEndMessage(message) {
602
- var _this4 = this;
606
+ var _this3 = this;
603
607
  return message.dataSets.some(function (dataSet) {
604
- if (dataSet.leafCount === 1 && dataSet.root === _constants2.EMPTY_HASH && (!_this4.dataSets[dataSet.name] || _this4.dataSets[dataSet.name].version < dataSet.version) && PossibleSentinelMessageDataSetNames.includes(dataSet.name.toLowerCase())) {
608
+ if (dataSet.leafCount === 1 && dataSet.root === _constants3.EMPTY_HASH && (!_this3.dataSets[dataSet.name] || _this3.dataSets[dataSet.name].version < dataSet.version) && PossibleSentinelMessageDataSetNames.includes(dataSet.name.toLowerCase())) {
605
609
  // this is a special way for Locus to indicate that this meeting has ended
606
610
  return true;
607
611
  }
@@ -618,7 +622,7 @@ var HashTreeParser = /*#__PURE__*/function () {
618
622
  }, {
619
623
  key: "handleRootHashHeartBeatMessage",
620
624
  value: function handleRootHashHeartBeatMessage(message) {
621
- var _this5 = this;
625
+ var _this4 = this;
622
626
  var dataSets = message.dataSets;
623
627
  _loggerProxy.default.logger.info("HashTreeParser#handleRootHashMessage --> ".concat(this.debugId, " Received heartbeat root hash message with data sets: ").concat((0, _stringify.default)(dataSets.map(function (_ref2) {
624
628
  var name = _ref2.name,
@@ -632,12 +636,40 @@ var HashTreeParser = /*#__PURE__*/function () {
632
636
  version: version
633
637
  };
634
638
  }))));
639
+ this.cancelPendingSyncsForDataSets(dataSets.map(function (ds) {
640
+ return ds.name;
641
+ }));
635
642
  dataSets.forEach(function (dataSet) {
636
- _this5.updateDataSetInfo(dataSet);
637
- _this5.runSyncAlgorithm(dataSet);
643
+ _this4.updateDataSetInfo(dataSet);
644
+ _this4.runSyncAlgorithm(dataSet);
638
645
  });
639
646
  }
640
647
 
648
+ /**
649
+ * Handles known errors that can happen during syncs
650
+ *
651
+ * @param {any} error - The error to handle
652
+ * @returns {boolean} true if the error was recognized and handled, false otherwise
653
+ */
654
+ }, {
655
+ key: "handleSyncErrors",
656
+ value: function handleSyncErrors(error) {
657
+ if (error instanceof MeetingEndedError) {
658
+ this.callLocusInfoUpdateCallback({
659
+ updateType: LocusInfoUpdateType.MEETING_ENDED
660
+ });
661
+ return true;
662
+ }
663
+ if (error instanceof LocusNotFoundError) {
664
+ this.callLocusInfoUpdateCallback({
665
+ updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND
666
+ });
667
+ this.stop();
668
+ return true;
669
+ }
670
+ return false;
671
+ }
672
+
641
673
  /**
642
674
  * Asynchronously initializes new visible data sets
643
675
  *
@@ -647,18 +679,14 @@ var HashTreeParser = /*#__PURE__*/function () {
647
679
  }, {
648
680
  key: "queueInitForNewVisibleDataSets",
649
681
  value: function queueInitForNewVisibleDataSets(dataSetsRequiringInitialization) {
650
- var _this6 = this;
682
+ var _this5 = this;
651
683
  _loggerProxy.default.logger.info("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(this.debugId, " queuing initialization of new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
652
684
  return ds.name;
653
685
  }).join(', ')));
654
686
  queueMicrotask(function () {
655
- _this6.initializeNewVisibleDataSets(dataSetsRequiringInitialization).catch(function (error) {
656
- if (error instanceof MeetingEndedError) {
657
- _this6.callLocusInfoUpdateCallback({
658
- updateType: LocusInfoUpdateType.MEETING_ENDED
659
- });
660
- } else {
661
- _loggerProxy.default.logger.warn("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(_this6.debugId, " error while initializing new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
687
+ _this5.initializeNewVisibleDataSets(dataSetsRequiringInitialization).catch(function (error) {
688
+ if (!_this5.handleSyncErrors(error)) {
689
+ _loggerProxy.default.logger.warn("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(_this5.debugId, " error while initializing new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
662
690
  return ds.name;
663
691
  }).join(', '), ": "), error);
664
692
  }
@@ -718,14 +746,18 @@ var HashTreeParser = /*#__PURE__*/function () {
718
746
  }, {
719
747
  key: "handleLocusUpdate",
720
748
  value: function handleLocusUpdate(update) {
721
- var _this7 = this;
749
+ var _this6 = this;
722
750
  if (this.state === 'stopped') {
723
751
  return;
724
752
  }
725
753
  var dataSets = update.dataSets,
726
754
  locus = update.locus,
727
755
  metadata = update.metadata;
756
+ _loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received update with dataSets=").concat(dataSets === null || dataSets === void 0 ? void 0 : dataSets.map(function (ds) {
757
+ return ds.name;
758
+ }).join(','), " metadata=").concat(metadata ? 'yes' : 'no'));
728
759
  if (!dataSets) {
760
+ // this happens for example when we handle GET /loci response
729
761
  _loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received hash tree update without dataSets"));
730
762
  } else {
731
763
  var _iterator5 = _createForOfIteratorHelper(dataSets),
@@ -755,9 +787,9 @@ var HashTreeParser = /*#__PURE__*/function () {
755
787
 
756
788
  // then process the data in hash trees, if it is a new version, then add it to updatedObjects
757
789
  (0, _keys.default)(leafInfo).forEach(function (dataSetName) {
758
- if (_this7.dataSets[dataSetName]) {
759
- if (_this7.dataSets[dataSetName].hashTree) {
760
- var appliedChangesList = _this7.dataSets[dataSetName].hashTree.putItems(leafInfo[dataSetName].map(function (leaf) {
790
+ if (_this6.dataSets[dataSetName]) {
791
+ if (_this6.dataSets[dataSetName].hashTree) {
792
+ var appliedChangesList = _this6.dataSets[dataSetName].hashTree.putItems(leafInfo[dataSetName].map(function (leaf) {
761
793
  return {
762
794
  id: leaf.id,
763
795
  type: leaf.type,
@@ -784,10 +816,10 @@ var HashTreeParser = /*#__PURE__*/function () {
784
816
  });
785
817
  } else {
786
818
  // no hash tree means that the data set is not visible
787
- _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(_this7.debugId, " received leaf data for data set \"").concat(dataSetName, "\" that has no hash tree created, ignoring"));
819
+ _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(_this6.debugId, " received leaf data for data set \"").concat(dataSetName, "\" that has no hash tree created, ignoring"));
788
820
  }
789
821
  } else {
790
- _loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(_this7.debugId, " received leaf data for unknown data set \"").concat(dataSetName, "\", ignoring"));
822
+ _loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(_this6.debugId, " received leaf data for unknown data set \"").concat(dataSetName, "\", ignoring"));
791
823
  }
792
824
  });
793
825
  if (updatedObjects.length === 0) {
@@ -823,10 +855,26 @@ var HashTreeParser = /*#__PURE__*/function () {
823
855
  maxMs: receivedDataSet.backoff.maxMs,
824
856
  exponent: receivedDataSet.backoff.exponent
825
857
  };
858
+ this.dataSets[receivedDataSet.name].heartbeatIntervalMs = receivedDataSet.heartbeatIntervalMs;
826
859
  _loggerProxy.default.logger.info("HashTreeParser#updateDataSetInfo --> ".concat(this.debugId, " updated \"").concat(receivedDataSet.name, "\" dataset to version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
827
860
  }
828
861
  }
829
862
 
863
+ /**
864
+ * Updates the leaf count for a data set, resizing its hash tree accordingly.
865
+ *
866
+ * @param {InternalDataSet} dataSet - The data set to update
867
+ * @param {number} newLeafCount - The new leaf count
868
+ * @returns {void}
869
+ */
870
+ }, {
871
+ key: "updateDataSetLeafCount",
872
+ value: function updateDataSetLeafCount(dataSet, newLeafCount) {
873
+ var _dataSet$hashTree;
874
+ (_dataSet$hashTree = dataSet.hashTree) === null || _dataSet$hashTree === void 0 ? void 0 : _dataSet$hashTree.resize(newLeafCount);
875
+ dataSet.leafCount = newLeafCount;
876
+ }
877
+
830
878
  /**
831
879
  * Checks for changes in the visible data sets based on the updated objects.
832
880
  * @param {HashTreeObject[]} updatedObjects - The list of updated hash tree objects.
@@ -835,7 +883,7 @@ var HashTreeParser = /*#__PURE__*/function () {
835
883
  }, {
836
884
  key: "checkForVisibleDataSetChanges",
837
885
  value: function checkForVisibleDataSetChanges(updatedObjects) {
838
- var _this8 = this;
886
+ var _this7 = this;
839
887
  var removedDataSets = [];
840
888
  var addedDataSets = [];
841
889
 
@@ -844,20 +892,20 @@ var HashTreeParser = /*#__PURE__*/function () {
844
892
  var _object$data;
845
893
  if ((0, _utils.isMetadata)(object) && (_object$data = object.data) !== null && _object$data !== void 0 && _object$data.visibleDataSets) {
846
894
  var newVisibleDataSets = object.data.visibleDataSets.filter(function (vds) {
847
- return !_this8.isExcludedDataSet(vds.name);
895
+ return !_this7.isExcludedDataSet(vds.name);
848
896
  });
849
- removedDataSets = _this8.visibleDataSets.filter(function (ds) {
897
+ removedDataSets = _this7.visibleDataSets.filter(function (ds) {
850
898
  return !newVisibleDataSets.some(function (nvs) {
851
899
  return nvs.name === ds.name;
852
900
  });
853
901
  });
854
902
  addedDataSets = newVisibleDataSets.filter(function (nvs) {
855
- return _this8.visibleDataSets.every(function (ds) {
903
+ return _this7.visibleDataSets.every(function (ds) {
856
904
  return ds.name !== nvs.name;
857
905
  });
858
906
  });
859
907
  if (removedDataSets.length > 0 || addedDataSets.length > 0) {
860
- _loggerProxy.default.logger.info("HashTreeParser#checkForVisibleDataSetChanges --> ".concat(_this8.debugId, " visible data sets change: removed: ").concat(removedDataSets.map(function (ds) {
908
+ _loggerProxy.default.logger.info("HashTreeParser#checkForVisibleDataSetChanges --> ".concat(_this7.debugId, " visible data sets change: removed: ").concat(removedDataSets.map(function (ds) {
861
909
  return ds.name;
862
910
  }).join(', '), ", added: ").concat(addedDataSets.map(function (ds) {
863
911
  return ds.name;
@@ -881,7 +929,10 @@ var HashTreeParser = /*#__PURE__*/function () {
881
929
  }, {
882
930
  key: "deleteHashTree",
883
931
  value: function deleteHashTree(dataSetName) {
932
+ var _this$dataSets$dataSe;
884
933
  this.dataSets[dataSetName].hashTree = undefined;
934
+ (_this$dataSets$dataSe = this.dataSets[dataSetName].syncAbortController) === null || _this$dataSets$dataSe === void 0 ? void 0 : _this$dataSets$dataSe.abort();
935
+ this.dataSets[dataSetName].syncAbortController = undefined;
885
936
 
886
937
  // we also need to stop the timers as there is no hash tree anymore to sync
887
938
  if (this.dataSets[dataSetName].timer) {
@@ -911,16 +962,16 @@ var HashTreeParser = /*#__PURE__*/function () {
911
962
  }, {
912
963
  key: "processVisibleDataSetChanges",
913
964
  value: function processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects) {
914
- var _this9 = this;
965
+ var _this8 = this;
915
966
  var dataSetsRequiringInitialization = [];
916
967
 
917
968
  // if a visible data set was removed, we need to tell our client that all objects from it are removed
918
969
  var removedObjects = [];
919
970
  removedDataSets.forEach(function (ds) {
920
- var _this9$dataSets$ds$na;
921
- if ((_this9$dataSets$ds$na = _this9.dataSets[ds.name]) !== null && _this9$dataSets$ds$na !== void 0 && _this9$dataSets$ds$na.hashTree) {
922
- for (var i = 0; i < _this9.dataSets[ds.name].hashTree.numLeaves; i += 1) {
923
- removedObjects.push.apply(removedObjects, (0, _toConsumableArray2.default)(_this9.dataSets[ds.name].hashTree.getLeafData(i).map(function (elementId) {
971
+ var _this8$dataSets$ds$na;
972
+ if ((_this8$dataSets$ds$na = _this8.dataSets[ds.name]) !== null && _this8$dataSets$ds$na !== void 0 && _this8$dataSets$ds$na.hashTree) {
973
+ for (var i = 0; i < _this8.dataSets[ds.name].hashTree.numLeaves; i += 1) {
974
+ removedObjects.push.apply(removedObjects, (0, _toConsumableArray2.default)(_this8.dataSets[ds.name].hashTree.getLeafData(i).map(function (elementId) {
924
975
  return {
925
976
  htMeta: {
926
977
  elementId: elementId,
@@ -930,7 +981,7 @@ var HashTreeParser = /*#__PURE__*/function () {
930
981
  };
931
982
  })));
932
983
  }
933
- _this9.deleteHashTree(ds.name);
984
+ _this8.deleteHashTree(ds.name);
934
985
  }
935
986
  });
936
987
  this.visibleDataSets = this.visibleDataSets.filter(function (vds) {
@@ -991,81 +1042,78 @@ var HashTreeParser = /*#__PURE__*/function () {
991
1042
  }, {
992
1043
  key: "initializeNewVisibleDataSets",
993
1044
  value: (function () {
994
- var _initializeNewVisibleDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(addedDataSets) {
995
- var _this0 = this;
1045
+ var _initializeNewVisibleDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(addedDataSets) {
1046
+ var _this9 = this;
996
1047
  var allDataSets, _iterator7, _step7, _loop, _t2;
997
- return _regenerator.default.wrap(function (_context5) {
998
- while (1) switch (_context5.prev = _context5.next) {
1048
+ return _regenerator.default.wrap(function (_context6) {
1049
+ while (1) switch (_context6.prev = _context6.next) {
999
1050
  case 0:
1000
1051
  if (!(this.state === 'stopped')) {
1001
- _context5.next = 1;
1052
+ _context6.next = 1;
1002
1053
  break;
1003
1054
  }
1004
- return _context5.abrupt("return");
1055
+ return _context6.abrupt("return");
1005
1056
  case 1:
1006
- _context5.next = 2;
1057
+ _context6.next = 2;
1007
1058
  return this.getAllVisibleDataSetsFromLocus();
1008
1059
  case 2:
1009
- allDataSets = _context5.sent;
1010
- _iterator7 = _createForOfIteratorHelper((0, _utils.sortByInitPriority)(addedDataSets, _constants2.DATA_SET_INIT_PRIORITY));
1011
- _context5.prev = 3;
1060
+ allDataSets = _context6.sent;
1061
+ _iterator7 = _createForOfIteratorHelper((0, _utils.sortByInitPriority)(addedDataSets, _constants3.DATA_SET_INIT_PRIORITY));
1062
+ _context6.prev = 3;
1012
1063
  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
1013
- var ds, dataSetInfo, updates;
1014
- return _regenerator.default.wrap(function (_context4) {
1015
- while (1) switch (_context4.prev = _context4.next) {
1064
+ var ds, dataSetInfo;
1065
+ return _regenerator.default.wrap(function (_context5) {
1066
+ while (1) switch (_context5.prev = _context5.next) {
1016
1067
  case 0:
1017
1068
  ds = _step7.value;
1018
1069
  dataSetInfo = allDataSets.find(function (d) {
1019
1070
  return d.name === ds.name;
1020
1071
  });
1021
- _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this0.debugId, " initializing data set \"").concat(ds.name, "\""));
1072
+ _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this9.debugId, " initializing data set \"").concat(ds.name, "\""));
1022
1073
  if (dataSetInfo) {
1023
- _context4.next = 1;
1074
+ _context5.next = 1;
1024
1075
  break;
1025
1076
  }
1026
- _loggerProxy.default.logger.warn("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this0.debugId, " missing info about data set \"").concat(ds.name, "\" in Locus response from visibleDataSetsUrl"));
1027
- _context4.next = 3;
1077
+ _loggerProxy.default.logger.warn("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this9.debugId, " missing info about data set \"").concat(ds.name, "\" in Locus response from visibleDataSetsUrl"));
1078
+ _context5.next = 2;
1028
1079
  break;
1029
1080
  case 1:
1030
- _context4.next = 2;
1031
- return _this0.initializeNewVisibleDataSet(ds, dataSetInfo);
1081
+ _context5.next = 2;
1082
+ return _this9.initializeNewVisibleDataSet(ds, dataSetInfo);
1032
1083
  case 2:
1033
- updates = _context4.sent;
1034
- _this0.callLocusInfoUpdateCallback(updates);
1035
- case 3:
1036
1084
  case "end":
1037
- return _context4.stop();
1085
+ return _context5.stop();
1038
1086
  }
1039
1087
  }, _loop);
1040
1088
  });
1041
1089
  _iterator7.s();
1042
1090
  case 4:
1043
1091
  if ((_step7 = _iterator7.n()).done) {
1044
- _context5.next = 6;
1092
+ _context6.next = 6;
1045
1093
  break;
1046
1094
  }
1047
- return _context5.delegateYield(_loop(), "t0", 5);
1095
+ return _context6.delegateYield(_loop(), "t0", 5);
1048
1096
  case 5:
1049
- _context5.next = 4;
1097
+ _context6.next = 4;
1050
1098
  break;
1051
1099
  case 6:
1052
- _context5.next = 8;
1100
+ _context6.next = 8;
1053
1101
  break;
1054
1102
  case 7:
1055
- _context5.prev = 7;
1056
- _t2 = _context5["catch"](3);
1103
+ _context6.prev = 7;
1104
+ _t2 = _context6["catch"](3);
1057
1105
  _iterator7.e(_t2);
1058
1106
  case 8:
1059
- _context5.prev = 8;
1107
+ _context6.prev = 8;
1060
1108
  _iterator7.f();
1061
- return _context5.finish(8);
1109
+ return _context6.finish(8);
1062
1110
  case 9:
1063
1111
  case "end":
1064
- return _context5.stop();
1112
+ return _context6.stop();
1065
1113
  }
1066
- }, _callee4, this, [[3, 7, 8, 9]]);
1114
+ }, _callee5, this, [[3, 7, 8, 9]]);
1067
1115
  }));
1068
- function initializeNewVisibleDataSets(_x5) {
1116
+ function initializeNewVisibleDataSets(_x7) {
1069
1117
  return _initializeNewVisibleDataSets.apply(this, arguments);
1070
1118
  }
1071
1119
  return initializeNewVisibleDataSets;
@@ -1081,24 +1129,37 @@ var HashTreeParser = /*#__PURE__*/function () {
1081
1129
  }, {
1082
1130
  key: "parseMessage",
1083
1131
  value: function parseMessage(message, debugText) {
1084
- var _message$locusStateEl,
1085
- _this1 = this;
1132
+ var _message$dataSets,
1133
+ _message$locusStateEl,
1134
+ _message$locusStateEl2,
1135
+ _this0 = this;
1086
1136
  if (this.state === 'stopped') {
1087
1137
  return [];
1088
1138
  }
1089
1139
  var dataSets = message.dataSets,
1090
1140
  visibleDataSetsUrl = message.visibleDataSetsUrl;
1091
- _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " received message ").concat(debugText || '', ":"), message);
1092
- if (((_message$locusStateEl = message.locusStateElements) === null || _message$locusStateEl === void 0 ? void 0 : _message$locusStateEl.length) === 0) {
1141
+ _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " ").concat(debugText || '', " dataSets: ").concat((_message$dataSets = message.dataSets) === null || _message$dataSets === void 0 ? void 0 : _message$dataSets.map(function (_ref5) {
1142
+ var name = _ref5.name,
1143
+ version = _ref5.version;
1144
+ return "".concat(name, ":").concat(version);
1145
+ }).join(','), ", elements: ").concat((_message$locusStateEl = message.locusStateElements) === null || _message$locusStateEl === void 0 ? void 0 : _message$locusStateEl.map(function (el) {
1146
+ return "".concat(el.htMeta.elementId.type, ":").concat(el.htMeta.elementId.id, ":").concat(el.htMeta.elementId.version).concat(el.data ? '+' : '-');
1147
+ }).join(',')));
1148
+ if (((_message$locusStateEl2 = message.locusStateElements) === null || _message$locusStateEl2 === void 0 ? void 0 : _message$locusStateEl2.length) === 0) {
1093
1149
  _loggerProxy.default.logger.warn("HashTreeParser#parseMessage --> ".concat(this.debugId, " got empty locusStateElements!!!"));
1094
- // todo: send a metric
1150
+ _metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS, {
1151
+ debugId: this.debugId
1152
+ });
1095
1153
  }
1096
1154
 
1097
1155
  // first, update our metadata about the datasets with info from the message
1098
1156
  this.visibleDataSetsUrl = visibleDataSetsUrl;
1099
1157
  dataSets.forEach(function (dataSet) {
1100
- return _this1.updateDataSetInfo(dataSet);
1158
+ return _this0.updateDataSetInfo(dataSet);
1101
1159
  });
1160
+ this.cancelPendingSyncsForDataSets(dataSets.map(function (ds) {
1161
+ return ds.name;
1162
+ }));
1102
1163
  var updatedObjects = [];
1103
1164
 
1104
1165
  // when we detect new visible datasets, it may be that the metadata about them is not
@@ -1117,9 +1178,9 @@ var HashTreeParser = /*#__PURE__*/function () {
1117
1178
  _step8;
1118
1179
  try {
1119
1180
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1120
- var _this1$dataSets$dataS;
1181
+ var _this0$dataSets$dataS;
1121
1182
  var dataSetName = _step8.value;
1122
- var hashTree = (_this1$dataSets$dataS = _this1.dataSets[dataSetName]) === null || _this1$dataSets$dataS === void 0 ? void 0 : _this1$dataSets$dataS.hashTree;
1183
+ var hashTree = (_this0$dataSets$dataS = _this0.dataSets[dataSetName]) === null || _this0$dataSets$dataS === void 0 ? void 0 : _this0$dataSets$dataS.hashTree;
1123
1184
  if (hashTree && object.data) {
1124
1185
  if (hashTree.putItem(object.htMeta.elementId)) {
1125
1186
  updatedMetadataObjects.push(object);
@@ -1146,8 +1207,8 @@ var HashTreeParser = /*#__PURE__*/function () {
1146
1207
  // and hash trees created for the new visible data sets,
1147
1208
  // so we can now process all the updates from the message
1148
1209
  dataSets.forEach(function (dataSet) {
1149
- if (_this1.dataSets[dataSet.name]) {
1150
- var hashTree = _this1.dataSets[dataSet.name].hashTree;
1210
+ if (_this0.dataSets[dataSet.name]) {
1211
+ var hashTree = _this0.dataSets[dataSet.name].hashTree;
1151
1212
  if (hashTree) {
1152
1213
  var locusStateElementsForThisSet = message.locusStateElements.filter(function (object) {
1153
1214
  return object.htMeta.dataSetNames.includes(dataSet.name);
@@ -1161,20 +1222,20 @@ var HashTreeParser = /*#__PURE__*/function () {
1161
1222
  item: object.htMeta.elementId
1162
1223
  };
1163
1224
  }));
1164
- (0, _lodash.zip)(appliedChangesList, locusStateElementsForThisSet).forEach(function (_ref5) {
1165
- var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
1166
- changeApplied = _ref6[0],
1167
- object = _ref6[1];
1225
+ (0, _lodash.zip)(appliedChangesList, locusStateElementsForThisSet).forEach(function (_ref6) {
1226
+ var _ref7 = (0, _slicedToArray2.default)(_ref6, 2),
1227
+ changeApplied = _ref7[0],
1228
+ object = _ref7[1];
1168
1229
  if (changeApplied) {
1169
1230
  // add to updatedObjects so that our locus DTO will get updated with the new object
1170
1231
  updatedObjects.push(object);
1171
1232
  }
1172
1233
  });
1173
1234
  } else {
1174
- _loggerProxy.default.logger.info("Locus-info:index#parseMessage --> ".concat(_this1.debugId, " unexpected (not visible) dataSet ").concat(dataSet.name, " received in hash tree message"));
1235
+ _loggerProxy.default.logger.info("Locus-info:index#parseMessage --> ".concat(_this0.debugId, " unexpected (not visible) dataSet ").concat(dataSet.name, " received in hash tree message"));
1175
1236
  }
1176
1237
  }
1177
- _this1.runSyncAlgorithm(dataSet);
1238
+ _this0.runSyncAlgorithm(dataSet);
1178
1239
  });
1179
1240
  }
1180
1241
  if (dataSetsRequiringInitialization.length > 0) {
@@ -1200,8 +1261,8 @@ var HashTreeParser = /*#__PURE__*/function () {
1200
1261
  if (this.state === 'stopped') {
1201
1262
  return;
1202
1263
  }
1203
- if (message.heartbeatIntervalMs) {
1204
- this.heartbeatIntervalMs = message.heartbeatIntervalMs;
1264
+ if (message.heartbeatIntervalMs !== undefined) {
1265
+ this.topLevelHeartbeatIntervalMs = message.heartbeatIntervalMs;
1205
1266
  }
1206
1267
  if (this.isEndMessage(message)) {
1207
1268
  _loggerProxy.default.logger.info("HashTreeParser#handleMessage --> ".concat(this.debugId, " received sentinel END MEETING message"));
@@ -1213,6 +1274,10 @@ var HashTreeParser = /*#__PURE__*/function () {
1213
1274
  this.handleRootHashHeartBeatMessage(message);
1214
1275
  this.resetHeartbeatWatchdogs(message.dataSets);
1215
1276
  } else {
1277
+ // Completion of the sync latency metric (client.locus.sync.complete) is driven solely from
1278
+ // Meeting#processLocusLLMEvent once the matching LLM message arrives. body-mode syncs return
1279
+ // the locus state elements in the /sync HTTP response body, but per design the CA metric is
1280
+ // emitted only from the LLM message path, so no completion happens here.
1216
1281
  var updatedObjects = this.parseMessage(message, debugText);
1217
1282
  this.resetHeartbeatWatchdogs(message.dataSets);
1218
1283
  this.callLocusInfoUpdateCallback({
@@ -1222,6 +1287,33 @@ var HashTreeParser = /*#__PURE__*/function () {
1222
1287
  }
1223
1288
  }
1224
1289
 
1290
+ /**
1291
+ * Checks if Locus sync latency metrics should be collected for a dataset.
1292
+ *
1293
+ * @param {string} dataSetName dataset name
1294
+ * @param {boolean} [isInitialization=false] whether this is an initialization sync
1295
+ * @returns {boolean}
1296
+ */
1297
+ }, {
1298
+ key: "shouldCollectSyncMetrics",
1299
+ value: function shouldCollectSyncMetrics(dataSetName) {
1300
+ var isInitialization = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1301
+ return Boolean(this.callbacks.syncLatencyTracker && !isInitialization && SYNC_METRICS_DATA_SETS.includes(dataSetName));
1302
+ }
1303
+ }, {
1304
+ key: "saveSyncBackoffLatency",
1305
+ value: function saveSyncBackoffLatency(dataSetName, randomBackoffTime) {
1306
+ var _this$callbacks$syncL;
1307
+ var isInitialization = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1308
+ if (!this.shouldCollectSyncMetrics(dataSetName, isInitialization)) {
1309
+ return;
1310
+ }
1311
+ (_this$callbacks$syncL = this.callbacks.syncLatencyTracker) === null || _this$callbacks$syncL === void 0 ? void 0 : _this$callbacks$syncL.saveLatency('internal.client.locus.sync.random.backoff', Math.round(randomBackoffTime), {
1312
+ meetingId: this.syncLatencyMeetingId,
1313
+ dataSetName: dataSetName
1314
+ });
1315
+ }
1316
+
1225
1317
  /**
1226
1318
  * Calls the updateInfo callback if there are any updates to report
1227
1319
  *
@@ -1232,7 +1324,7 @@ var HashTreeParser = /*#__PURE__*/function () {
1232
1324
  key: "callLocusInfoUpdateCallback",
1233
1325
  value: function callLocusInfoUpdateCallback(updates) {
1234
1326
  var _updates$updatedObjec,
1235
- _this10 = this;
1327
+ _this1 = this;
1236
1328
  if (this.state === 'stopped') {
1237
1329
  return;
1238
1330
  }
@@ -1247,9 +1339,9 @@ var HashTreeParser = /*#__PURE__*/function () {
1247
1339
  version = elementId.version;
1248
1340
 
1249
1341
  // Check all datasets
1250
- for (var _i2 = 0, _Object$keys3 = (0, _keys.default)(_this10.dataSets); _i2 < _Object$keys3.length; _i2++) {
1342
+ for (var _i2 = 0, _Object$keys3 = (0, _keys.default)(_this1.dataSets); _i2 < _Object$keys3.length; _i2++) {
1251
1343
  var dataSetName = _Object$keys3[_i2];
1252
- var dataSet = _this10.dataSets[dataSetName];
1344
+ var dataSet = _this1.dataSets[dataSetName];
1253
1345
 
1254
1346
  // only visible datasets have hash trees set
1255
1347
  if (dataSet !== null && dataSet !== void 0 && dataSet.hashTree) {
@@ -1258,12 +1350,12 @@ var HashTreeParser = /*#__PURE__*/function () {
1258
1350
  if (object.data) {
1259
1351
  // For updates: filter out if any dataset has a higher version
1260
1352
  if (existingVersion > version) {
1261
- _loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this10.debugId, " Filtering out update for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" has v").concat(existingVersion));
1353
+ _loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this1.debugId, " Filtering out update for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" has v").concat(existingVersion));
1262
1354
  return false;
1263
1355
  }
1264
1356
  } else if (existingVersion >= version) {
1265
1357
  // For removals: filter out if the object still exists in any dataset
1266
- _loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this10.debugId, " Filtering out removal for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" still has v").concat(existingVersion));
1358
+ _loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this1.debugId, " Filtering out removal for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" still has v").concat(existingVersion));
1267
1359
  return false;
1268
1360
  }
1269
1361
  }
@@ -1272,13 +1364,13 @@ var HashTreeParser = /*#__PURE__*/function () {
1272
1364
  return true;
1273
1365
  });
1274
1366
  if (filteredUpdates.length > 0) {
1275
- this.locusInfoUpdateCallback({
1367
+ this.callbacks.locusInfoUpdateCallback({
1276
1368
  updateType: updateType,
1277
1369
  updatedObjects: filteredUpdates
1278
1370
  });
1279
1371
  }
1280
1372
  } else if (updateType !== LocusInfoUpdateType.OBJECTS_UPDATED) {
1281
- this.locusInfoUpdateCallback({
1373
+ this.callbacks.locusInfoUpdateCallback({
1282
1374
  updateType: updateType
1283
1375
  });
1284
1376
  }
@@ -1303,164 +1395,550 @@ var HashTreeParser = /*#__PURE__*/function () {
1303
1395
  * Performs a sync for the given data set.
1304
1396
  *
1305
1397
  * @param {InternalDataSet} dataSet - The data set to sync
1306
- * @param {string} rootHash - Our current root hash for this data set
1307
1398
  * @param {string} reason - The reason for the sync (used for logging)
1399
+ * @param {boolean} [isInitialization] - Whether this is an initialization sync (sends empty leaves data instead of comparing hashes)
1308
1400
  * @returns {Promise<void>}
1309
1401
  */
1310
1402
  }, {
1311
1403
  key: "performSync",
1312
1404
  value: (function () {
1313
- var _performSync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(dataSet, rootHash, reason) {
1314
- var mismatchedLeavesData, receivedHashes, _yield$this$getHashes, hashes, latestDataSetInfo, mismatchedLeaveIndexes, syncResponse, _t3, _t4;
1315
- return _regenerator.default.wrap(function (_context6) {
1316
- while (1) switch (_context6.prev = _context6.next) {
1405
+ var _performSync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6(dataSet, reason, isInitialization) {
1406
+ var _dataSet$syncAbortCon, _this$callbacks$gener, _this$callbacks, _this$callbacks$gener2, _this$callbacks2;
1407
+ var abortController, hashTree, rootHash, shouldCollectMetrics, hashtreeTrackingId, syncTrackingId, syncRequestSent, _this$callbacks$syncL2, leavesData, receivedHashes, hashesResult, mismatchedLeaveIndexes, syncResponse, _this$callbacks$syncL3, _t3, _t4;
1408
+ return _regenerator.default.wrap(function (_context7) {
1409
+ while (1) switch (_context7.prev = _context7.next) {
1317
1410
  case 0:
1318
1411
  if (dataSet.hashTree) {
1319
- _context6.next = 1;
1412
+ _context7.next = 1;
1320
1413
  break;
1321
1414
  }
1322
- return _context6.abrupt("return");
1415
+ return _context7.abrupt("return");
1323
1416
  case 1:
1324
- _context6.prev = 1;
1417
+ abortController = (_dataSet$syncAbortCon = dataSet.syncAbortController) !== null && _dataSet$syncAbortCon !== void 0 ? _dataSet$syncAbortCon : new AbortController();
1418
+ dataSet.syncAbortController = abortController;
1419
+ hashTree = dataSet.hashTree;
1420
+ rootHash = hashTree.getRootHash();
1421
+ shouldCollectMetrics = this.shouldCollectSyncMetrics(dataSet.name, isInitialization); // Generate two distinct tracking ids up-front. Each Locus request must carry its own unique
1422
+ // tracking id, so the /hashtree and /sync requests must not share one. hashtreeTrackingId is
1423
+ // generated first so that syncTrackingId (forced onto the /sync request, stored in metrics, and
1424
+ // used to match the LLM broadcast message) ends up with the later/higher sequence number,
1425
+ // matching the order in which Locus sees the requests. If we never call /hashtree (single-leaf
1426
+ // or initialization syncs), hashtreeTrackingId is simply unused.
1427
+ hashtreeTrackingId = shouldCollectMetrics ? (_this$callbacks$gener = (_this$callbacks = this.callbacks).generateTrackingId) === null || _this$callbacks$gener === void 0 ? void 0 : _this$callbacks$gener.call(_this$callbacks) : undefined;
1428
+ syncTrackingId = shouldCollectMetrics ? (_this$callbacks$gener2 = (_this$callbacks2 = this.callbacks).generateTrackingId) === null || _this$callbacks$gener2 === void 0 ? void 0 : _this$callbacks$gener2.call(_this$callbacks2) : undefined;
1429
+ syncRequestSent = false;
1430
+ if (shouldCollectMetrics) {
1431
+ (_this$callbacks$syncL2 = this.callbacks.syncLatencyTracker) === null || _this$callbacks$syncL2 === void 0 ? void 0 : _this$callbacks$syncL2.saveTimestamp({
1432
+ key: 'internal.client.locus.sync.start',
1433
+ options: {
1434
+ meetingId: this.syncLatencyMeetingId,
1435
+ dataSetName: dataSet.name,
1436
+ trackingId: syncTrackingId
1437
+ }
1438
+ });
1439
+ }
1440
+ _context7.prev = 2;
1325
1441
  _loggerProxy.default.logger.info("HashTreeParser#performSync --> ".concat(this.debugId, " ").concat(reason, ", syncing data set \"").concat(dataSet.name, "\""));
1326
- mismatchedLeavesData = {};
1442
+ leavesData = {};
1443
+ if (isInitialization) {
1444
+ _context7.next = 10;
1445
+ break;
1446
+ }
1327
1447
  if (!(dataSet.leafCount !== 1)) {
1328
- _context6.next = 7;
1448
+ _context7.next = 9;
1329
1449
  break;
1330
1450
  }
1331
- _context6.prev = 2;
1332
- _context6.next = 3;
1333
- return this.getHashesFromLocus(dataSet.name, rootHash);
1334
- case 3:
1335
- _yield$this$getHashes = _context6.sent;
1336
- hashes = _yield$this$getHashes.hashes;
1337
- latestDataSetInfo = _yield$this$getHashes.dataSet;
1338
- receivedHashes = hashes;
1339
- dataSet.hashTree.resize(latestDataSetInfo.leafCount);
1340
- _context6.next = 6;
1341
- break;
1451
+ _context7.prev = 3;
1452
+ _context7.next = 4;
1453
+ return this.getHashesFromLocus(dataSet.name, rootHash, {
1454
+ requestTrackingId: hashtreeTrackingId,
1455
+ metricTrackingId: syncTrackingId
1456
+ });
1342
1457
  case 4:
1343
- _context6.prev = 4;
1344
- _t3 = _context6["catch"](2);
1345
- if (!(_t3.statusCode === 409)) {
1346
- _context6.next = 5;
1458
+ hashesResult = _context7.sent;
1459
+ if (hashesResult) {
1460
+ _context7.next = 5;
1461
+ break;
1462
+ }
1463
+ return _context7.abrupt("return");
1464
+ case 5:
1465
+ receivedHashes = hashesResult.hashes;
1466
+ this.updateDataSetLeafCount(dataSet, hashesResult.dataSet.leafCount);
1467
+ _context7.next = 8;
1468
+ break;
1469
+ case 6:
1470
+ _context7.prev = 6;
1471
+ _t3 = _context7["catch"](3);
1472
+ if (!((_t3 === null || _t3 === void 0 ? void 0 : _t3.statusCode) === 409)) {
1473
+ _context7.next = 7;
1347
1474
  break;
1348
1475
  }
1349
1476
  // this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
1350
1477
  _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(this.debugId, " Got 409 when fetching hashes for data set \"").concat(dataSet.name, "\": ").concat(_t3.message));
1351
- return _context6.abrupt("return");
1352
- case 5:
1478
+ return _context7.abrupt("return");
1479
+ case 7:
1353
1480
  throw _t3;
1354
- case 6:
1481
+ case 8:
1355
1482
  // identify mismatched leaves
1356
- mismatchedLeaveIndexes = dataSet.hashTree.diffHashes(receivedHashes);
1483
+ mismatchedLeaveIndexes = hashTree.diffHashes(receivedHashes);
1357
1484
  mismatchedLeaveIndexes.forEach(function (index) {
1358
- mismatchedLeavesData[index] = dataSet.hashTree.getLeafData(index);
1485
+ leavesData[index] = hashTree.getLeafData(index);
1359
1486
  });
1360
- _context6.next = 8;
1487
+ _context7.next = 10;
1361
1488
  break;
1362
- case 7:
1363
- mismatchedLeavesData[0] = dataSet.hashTree.getLeafData(0);
1364
- case 8:
1365
- if (!((0, _keys.default)(mismatchedLeavesData).length > 0)) {
1366
- _context6.next = 10;
1489
+ case 9:
1490
+ leavesData = {
1491
+ 0: hashTree.getLeafData(0)
1492
+ };
1493
+ case 10:
1494
+ if (!abortController.signal.aborted) {
1495
+ _context7.next = 11;
1367
1496
  break;
1368
1497
  }
1369
- _context6.next = 9;
1370
- return this.sendSyncRequestToLocus(dataSet, mismatchedLeavesData);
1371
- case 9:
1372
- syncResponse = _context6.sent;
1498
+ _loggerProxy.default.logger.info("HashTreeParser#performSync --> ".concat(this.debugId, " abandoning sync for \"").concat(dataSet.name, "\" before /sync - message received during sync"));
1499
+ return _context7.abrupt("return");
1500
+ case 11:
1501
+ // request sync for mismatched leaves
1502
+ syncResponse = null;
1503
+ if (!isInitialization) {
1504
+ _context7.next = 13;
1505
+ break;
1506
+ }
1507
+ _context7.next = 12;
1508
+ return this.sendSyncRequestToLocus(dataSet, {
1509
+ isInitialization: true
1510
+ }, syncTrackingId);
1511
+ case 12:
1512
+ syncResponse = _context7.sent;
1513
+ syncRequestSent = true;
1514
+ _context7.next = 15;
1515
+ break;
1516
+ case 13:
1517
+ if (!((0, _keys.default)(leavesData).length > 0)) {
1518
+ _context7.next = 15;
1519
+ break;
1520
+ }
1521
+ _context7.next = 14;
1522
+ return this.sendSyncRequestToLocus(dataSet, {
1523
+ mismatchedLeavesData: leavesData
1524
+ }, syncTrackingId);
1525
+ case 14:
1526
+ syncResponse = _context7.sent;
1527
+ syncRequestSent = true;
1528
+ case 15:
1373
1529
  // sync API may return nothing (in that case data will arrive via messages)
1374
1530
  // or it may return a response in the same format as messages
1531
+ // We still need to restart the sync timer as a safety net in case the messages don't arrive.
1532
+ this.runSyncAlgorithm(dataSet);
1375
1533
  if (syncResponse) {
1376
- this.handleMessage(syncResponse, 'via sync API');
1534
+ // clear the abort controller before processing the response so that
1535
+ // parseMessage() -> cancelPendingSyncsForDataSets() doesn't log a
1536
+ // misleading "aborting sync" message for this already-completed sync
1537
+ dataSet.syncAbortController = undefined;
1538
+
1539
+ // the format of sync response is the same as messages, so we can reuse the same handler
1540
+ this.handleMessage(syncResponse, "via sync API (".concat(isInitialization ? 'init' : "".concat((0, _keys.default)(leavesData).length, " mismatched leaves"), ")"));
1377
1541
  }
1378
- case 10:
1379
- _context6.next = 12;
1542
+ _context7.next = 17;
1380
1543
  break;
1381
- case 11:
1382
- _context6.prev = 11;
1383
- _t4 = _context6["catch"](1);
1384
- if (_t4 instanceof MeetingEndedError) {
1385
- this.callLocusInfoUpdateCallback({
1386
- updateType: LocusInfoUpdateType.MEETING_ENDED
1387
- });
1388
- } else {
1544
+ case 16:
1545
+ _context7.prev = 16;
1546
+ _t4 = _context7["catch"](2);
1547
+ if (!this.handleSyncErrors(_t4)) {
1389
1548
  _loggerProxy.default.logger.warn("HashTreeParser#performSync --> ".concat(this.debugId, " error during sync for data set \"").concat(dataSet.name, "\":"), _t4);
1390
1549
  }
1391
- case 12:
1550
+ case 17:
1551
+ _context7.prev = 17;
1552
+ if (shouldCollectMetrics && !syncRequestSent) {
1553
+ // Drop only this sync's in-progress record (matched by its tracking id) rather than the
1554
+ // whole dataset, so a still-pending record from an earlier successful sync isn't wiped.
1555
+ // This mirrors the native client's onSyncError(syncId) which discards a single record.
1556
+ (_this$callbacks$syncL3 = this.callbacks.syncLatencyTracker) === null || _this$callbacks$syncL3 === void 0 ? void 0 : _this$callbacks$syncL3.clearLocusSyncLatency(dataSet.name, this.syncLatencyMeetingId, syncTrackingId);
1557
+ }
1558
+ dataSet.syncAbortController = undefined;
1559
+ return _context7.finish(17);
1560
+ case 18:
1392
1561
  case "end":
1393
- return _context6.stop();
1562
+ return _context7.stop();
1394
1563
  }
1395
- }, _callee5, this, [[1, 11], [2, 4]]);
1564
+ }, _callee6, this, [[2, 16, 17, 18], [3, 6]]);
1396
1565
  }));
1397
- function performSync(_x6, _x7, _x8) {
1566
+ function performSync(_x8, _x9, _x0) {
1398
1567
  return _performSync.apply(this, arguments);
1399
1568
  }
1400
1569
  return performSync;
1401
1570
  }()
1571
+ /**
1572
+ * Cancels any pending or in-flight syncs for the specified data sets.
1573
+ * This removes matching entries from the sync queue and aborts any in-flight sync HTTP requests.
1574
+ *
1575
+ * @param {string[]} dataSetNames - The names of the data sets to cancel syncs for
1576
+ * @returns {void}
1577
+ */
1578
+ )
1579
+ }, {
1580
+ key: "cancelPendingSyncsForDataSets",
1581
+ value: function cancelPendingSyncsForDataSets(dataSetNames) {
1582
+ var previousLength = this.syncQueue.length;
1583
+ this.syncQueue = this.syncQueue.filter(function (entry) {
1584
+ return !dataSetNames.includes(entry.dataSetName);
1585
+ });
1586
+ if (previousLength !== this.syncQueue.length) {
1587
+ _loggerProxy.default.logger.info("HashTreeParser#cancelPendingSyncsForDataSets --> ".concat(this.debugId, " removed ").concat(previousLength - this.syncQueue.length, " entries from sync queue for data sets: ").concat(dataSetNames.join(', ')));
1588
+ }
1589
+ this.markDataSetsForSyncAllBackoffSkip(dataSetNames);
1590
+ this.abortInFlightSyncs(dataSetNames);
1591
+ }
1592
+
1593
+ /**
1594
+ * If a syncAllDatasets backoff sleep is in progress, marks the given data sets to be skipped
1595
+ * after the sleep completes.
1596
+ *
1597
+ * @param {string[]} dataSetNames - The names of the data sets to mark
1598
+ * @returns {void}
1599
+ */
1600
+ }, {
1601
+ key: "markDataSetsForSyncAllBackoffSkip",
1602
+ value: function markDataSetsForSyncAllBackoffSkip(dataSetNames) {
1603
+ if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
1604
+ var _iterator9 = _createForOfIteratorHelper(dataSetNames),
1605
+ _step9;
1606
+ try {
1607
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1608
+ var name = _step9.value;
1609
+ this.dataSetsSyncedDuringBackoff.add(name);
1610
+ }
1611
+ } catch (err) {
1612
+ _iterator9.e(err);
1613
+ } finally {
1614
+ _iterator9.f();
1615
+ }
1616
+ }
1617
+ }
1618
+
1619
+ /**
1620
+ * Aborts any in-flight sync HTTP requests for the specified data sets.
1621
+ *
1622
+ * @param {string[]} dataSetNames - The names of the data sets whose syncs should be aborted
1623
+ * @returns {void}
1624
+ */
1625
+ }, {
1626
+ key: "abortInFlightSyncs",
1627
+ value: function abortInFlightSyncs(dataSetNames) {
1628
+ var _iterator0 = _createForOfIteratorHelper(dataSetNames),
1629
+ _step0;
1630
+ try {
1631
+ for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
1632
+ var _this$dataSets$name;
1633
+ var name = _step0.value;
1634
+ if ((_this$dataSets$name = this.dataSets[name]) !== null && _this$dataSets$name !== void 0 && _this$dataSets$name.syncAbortController) {
1635
+ _loggerProxy.default.logger.info("HashTreeParser#cancelPendingSyncsForDataSets --> ".concat(this.debugId, " aborting in-flight sync for data set \"").concat(name, "\""));
1636
+ this.dataSets[name].syncAbortController.abort();
1637
+ }
1638
+ }
1639
+ } catch (err) {
1640
+ _iterator0.e(err);
1641
+ } finally {
1642
+ _iterator0.f();
1643
+ }
1644
+ }
1645
+
1646
+ /**
1647
+ * Enqueues a sync for the given data set. If the data set is already in the queue, the request is ignored.
1648
+ * This ensures that all syncs are executed sequentially and no more than 1 sync runs at a time.
1649
+ *
1650
+ * @param {string} dataSetName - The name of the data set to sync
1651
+ * @param {string} reason - The reason for the sync (used for logging)
1652
+ * @param {boolean} [isInitialization=false] - Whether this is an initialization sync (uses empty leaves data instead of hash comparison)
1653
+ * @returns {void}
1654
+ */
1655
+ }, {
1656
+ key: "enqueueSyncForDataset",
1657
+ value: function enqueueSyncForDataset(dataSetName, reason) {
1658
+ var isInitialization = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1659
+ if (this.state === 'stopped') return;
1660
+ var existingEntry = this.syncQueue.find(function (entry) {
1661
+ return entry.dataSetName === dataSetName;
1662
+ });
1663
+ if (existingEntry) {
1664
+ if (isInitialization) {
1665
+ existingEntry.isInitialization = true;
1666
+ }
1667
+ _loggerProxy.default.logger.info("HashTreeParser#enqueueSyncForDataset --> ".concat(this.debugId, " data set \"").concat(dataSetName, "\" already in sync queue, skipping"));
1668
+ return;
1669
+ }
1670
+ this.syncQueue.push({
1671
+ dataSetName: dataSetName,
1672
+ reason: reason,
1673
+ isInitialization: isInitialization
1674
+ });
1675
+ if (!this.isSyncInProgress) {
1676
+ this.syncQueueProcessingPromise = this.processSyncQueue();
1677
+ }
1678
+ }
1679
+
1680
+ /**
1681
+ * Processes the sync queue sequentially. Only one instance of this method runs at a time.
1682
+ *
1683
+ * @returns {Promise<void>}
1684
+ */
1685
+ }, {
1686
+ key: "processSyncQueue",
1687
+ value: (function () {
1688
+ var _processSyncQueue = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
1689
+ var _ref8, dataSetName, reason, isInitialization, dataSet;
1690
+ return _regenerator.default.wrap(function (_context8) {
1691
+ while (1) switch (_context8.prev = _context8.next) {
1692
+ case 0:
1693
+ if (!this.isSyncInProgress) {
1694
+ _context8.next = 1;
1695
+ break;
1696
+ }
1697
+ return _context8.abrupt("return");
1698
+ case 1:
1699
+ this.isSyncInProgress = true;
1700
+ _context8.prev = 2;
1701
+ case 3:
1702
+ if (!(this.syncQueue.length > 0 && this.state !== 'stopped')) {
1703
+ _context8.next = 6;
1704
+ break;
1705
+ }
1706
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1707
+ _ref8 = this.syncQueue.shift(), dataSetName = _ref8.dataSetName, reason = _ref8.reason, isInitialization = _ref8.isInitialization;
1708
+ dataSet = this.dataSets[dataSetName];
1709
+ if (dataSet !== null && dataSet !== void 0 && dataSet.hashTree) {
1710
+ _context8.next = 4;
1711
+ break;
1712
+ }
1713
+ return _context8.abrupt("continue", 3);
1714
+ case 4:
1715
+ _context8.next = 5;
1716
+ return this.performSync(dataSet, reason, isInitialization);
1717
+ case 5:
1718
+ _context8.next = 3;
1719
+ break;
1720
+ case 6:
1721
+ _context8.prev = 6;
1722
+ this.isSyncInProgress = false;
1723
+ return _context8.finish(6);
1724
+ case 7:
1725
+ case "end":
1726
+ return _context8.stop();
1727
+ }
1728
+ }, _callee7, this, [[2,, 6, 7]]);
1729
+ }));
1730
+ function processSyncQueue() {
1731
+ return _processSyncQueue.apply(this, arguments);
1732
+ }
1733
+ return processSyncQueue;
1734
+ }()
1735
+ /**
1736
+ * sets the backoff type for syncAllDatasets calls, which determines the scope of datasets that will be synced after the backoff delay.
1737
+ *
1738
+ * @param {boolean} onlyLLM - Whether the backoff is for a syncAllDatasets call that is syncing only LLM datasets
1739
+ * @returns {void}
1740
+ */
1741
+ )
1742
+ }, {
1743
+ key: "setSyncAllBackoffType",
1744
+ value: function setSyncAllBackoffType(onlyLLM) {
1745
+ this.syncAllBackoffType = onlyLLM ? SyncAllBackoffType.ONLY_LLM : SyncAllBackoffType.ALL;
1746
+ }
1747
+
1748
+ /**
1749
+ * Checks if a syncAll backoff is already in progress. If so, upgrades the scope from
1750
+ * onlyLLM to all datasets when the new call has a broader scope.
1751
+ *
1752
+ * @param {boolean} onlyLLM - Whether the current call is for LLM datasets only
1753
+ * @returns {boolean} true if a backoff is already pending (caller should return early)
1754
+ */
1755
+ }, {
1756
+ key: "tryUpgradePendingBackoff",
1757
+ value: function tryUpgradePendingBackoff(onlyLLM) {
1758
+ if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
1759
+ if (!onlyLLM && this.syncAllBackoffType === SyncAllBackoffType.ONLY_LLM) {
1760
+ this.setSyncAllBackoffType(false);
1761
+ _loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " upgraded pending syncAll from onlyLLM to all datasets"));
1762
+ }
1763
+ return true;
1764
+ }
1765
+ return false;
1766
+ }
1767
+
1768
+ /**
1769
+ * Syncs all data sets that have hash trees, one by one in sequence, using the priority order
1770
+ * provided by sortByInitPriority().
1771
+ *
1772
+ * If a call is already waiting in the backoff delay phase, a new call with a broader scope
1773
+ * (onlyLLM=false) will upgrade the pending scope, and the dataset list will be computed after
1774
+ * the backoff using the upgraded scope. After the backoff, the sync queue handles deduplication
1775
+ * so no guard is needed.
1776
+ *
1777
+ * @param {Object} [options={}] - Options for syncing
1778
+ * @param {boolean} [options.onlyLLM=false] - Whether to sync only LLM based data sets
1779
+ * @returns {Promise<void>}
1780
+ */
1781
+ }, {
1782
+ key: "syncAllDatasets",
1783
+ value: (function () {
1784
+ var _syncAllDatasets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
1785
+ var options,
1786
+ _options$onlyLLM,
1787
+ onlyLLM,
1788
+ dataSetsToSync,
1789
+ delay,
1790
+ effectiveBackoffType,
1791
+ skippedDataSets,
1792
+ effectiveDataSetsToSync,
1793
+ _iterator1,
1794
+ _step1,
1795
+ ds,
1796
+ _args9 = arguments;
1797
+ return _regenerator.default.wrap(function (_context9) {
1798
+ while (1) switch (_context9.prev = _context9.next) {
1799
+ case 0:
1800
+ options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1801
+ _options$onlyLLM = options.onlyLLM, onlyLLM = _options$onlyLLM === void 0 ? false : _options$onlyLLM;
1802
+ if (!(this.state === 'stopped')) {
1803
+ _context9.next = 1;
1804
+ break;
1805
+ }
1806
+ return _context9.abrupt("return");
1807
+ case 1:
1808
+ if (!this.tryUpgradePendingBackoff(onlyLLM)) {
1809
+ _context9.next = 2;
1810
+ break;
1811
+ }
1812
+ return _context9.abrupt("return");
1813
+ case 2:
1814
+ dataSetsToSync = this.getSortedDataSetsWithHashTrees(onlyLLM);
1815
+ if (!(dataSetsToSync.length === 0)) {
1816
+ _context9.next = 3;
1817
+ break;
1818
+ }
1819
+ return _context9.abrupt("return");
1820
+ case 3:
1821
+ this.setSyncAllBackoffType(onlyLLM);
1822
+ delay = this.getWeightedBackoffTime(dataSetsToSync[0].backoff);
1823
+ _loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " starting backoff delay of ").concat(delay, "ms (onlyLLM=").concat(onlyLLM, ")"));
1824
+
1825
+ // delay the start of the syncs - this is a Locus requirement to avoid thundering herd issues
1826
+ _context9.next = 4;
1827
+ return (0, _utils.sleep)(delay);
1828
+ case 4:
1829
+ // read the (possibly upgraded) scope and clear the backoff flag
1830
+ effectiveBackoffType = this.syncAllBackoffType;
1831
+ skippedDataSets = this.dataSetsSyncedDuringBackoff;
1832
+ this.syncAllBackoffType = SyncAllBackoffType.NONE;
1833
+ this.dataSetsSyncedDuringBackoff = new _set.default();
1834
+ if (!(this.state === 'stopped')) {
1835
+ _context9.next = 5;
1836
+ break;
1837
+ }
1838
+ return _context9.abrupt("return");
1839
+ case 5:
1840
+ // re-evaluate the dataset list after the sleep, since the scope may have been upgraded
1841
+ // and exclude datasets that received messages during the backoff sleep
1842
+ effectiveDataSetsToSync = this.getSortedDataSetsWithHashTrees(effectiveBackoffType === SyncAllBackoffType.ONLY_LLM).filter(function (ds) {
1843
+ return !skippedDataSets.has(ds.name);
1844
+ });
1845
+ if (skippedDataSets.size > 0) {
1846
+ _loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " skipping datasets that received messages during backoff: ").concat((0, _toConsumableArray2.default)(skippedDataSets).join(', ')));
1847
+ }
1848
+ _loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " syncing ").concat(effectiveBackoffType === SyncAllBackoffType.ONLY_LLM ? 'only LLM' : 'all', " datasets: ").concat(effectiveDataSetsToSync.map(function (ds) {
1849
+ return ds.name;
1850
+ }).join(', ')));
1851
+ _iterator1 = _createForOfIteratorHelper(effectiveDataSetsToSync);
1852
+ try {
1853
+ for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
1854
+ ds = _step1.value;
1855
+ this.saveSyncBackoffLatency(ds.name, delay);
1856
+ this.enqueueSyncForDataset(ds.name, 'syncAllDatasets');
1857
+ }
1858
+ } catch (err) {
1859
+ _iterator1.e(err);
1860
+ } finally {
1861
+ _iterator1.f();
1862
+ }
1863
+ _context9.next = 6;
1864
+ return this.syncQueueProcessingPromise;
1865
+ case 6:
1866
+ case "end":
1867
+ return _context9.stop();
1868
+ }
1869
+ }, _callee8, this);
1870
+ }));
1871
+ function syncAllDatasets() {
1872
+ return _syncAllDatasets.apply(this, arguments);
1873
+ }
1874
+ return syncAllDatasets;
1875
+ }()
1876
+ /**
1877
+ * Returns the list of data sets that have hash trees, sorted by the priority order provided by sortByInitPriority().
1878
+ *
1879
+ * @param {boolean} onlyLLM - Whether to include only LLM based data sets
1880
+ * @returns {Array<{name: string, backoff: {maxMs: number, exponent: number}}>} The sorted list of data sets with their backoff configurations
1881
+ */
1882
+ )
1883
+ }, {
1884
+ key: "getSortedDataSetsWithHashTrees",
1885
+ value: function getSortedDataSetsWithHashTrees(onlyLLM) {
1886
+ var dataSets = (0, _values.default)(this.dataSets).filter(function (dataSet) {
1887
+ return dataSet === null || dataSet === void 0 ? void 0 : dataSet.hashTree;
1888
+ }).map(function (dataSet) {
1889
+ return {
1890
+ name: dataSet.name,
1891
+ backoff: dataSet.backoff
1892
+ };
1893
+ });
1894
+ if (onlyLLM) {
1895
+ dataSets = dataSets.filter(function (ds) {
1896
+ return _constants3.LLM_DATASET_NAMES.includes(ds.name);
1897
+ });
1898
+ }
1899
+ return (0, _utils.sortByInitPriority)(dataSets, _constants3.DATA_SET_INIT_PRIORITY);
1900
+ }
1901
+
1402
1902
  /**
1403
1903
  * Runs the sync algorithm for the given data set.
1404
1904
  *
1405
1905
  * @param {DataSet} receivedDataSet - The data set to run the sync algorithm for.
1406
1906
  * @returns {void}
1407
1907
  */
1408
- )
1409
1908
  }, {
1410
1909
  key: "runSyncAlgorithm",
1411
1910
  value: function runSyncAlgorithm(receivedDataSet) {
1412
- var _this11 = this;
1911
+ var _this10 = this;
1413
1912
  var dataSet = this.dataSets[receivedDataSet.name];
1414
1913
  if (!dataSet) {
1415
1914
  _loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " No data set found for ").concat(receivedDataSet.name, ", skipping sync algorithm"));
1416
1915
  return;
1417
1916
  }
1418
1917
  if (!dataSet.hashTree) {
1419
- _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " Data set \"").concat(dataSet.name, "\" has no hash tree, skipping sync algorithm"));
1918
+ // no hash tree, so no need to do any syncing
1919
+ // we fall into this branch often, because Locus sends dataSets in messages that are not visible to us
1920
+
1420
1921
  return;
1421
1922
  }
1422
1923
  dataSet.hashTree.resize(receivedDataSet.leafCount);
1423
-
1424
- // temporary log for the workshop // todo: remove
1425
- var ourCurrentRootHash = dataSet.hashTree.getRootHash();
1426
- _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " dataSet=\"").concat(dataSet.name, "\" version=").concat(dataSet.version, " hashes before starting timer: ours=").concat(ourCurrentRootHash, " Locus=").concat(dataSet.root));
1427
- var delay = dataSet.idleMs + this.getWeightedBackoffTime(dataSet.backoff);
1924
+ var randomBackoffTime = this.getWeightedBackoffTime(dataSet.backoff);
1925
+ var delay = dataSet.idleMs + randomBackoffTime;
1428
1926
  if (delay > 0) {
1429
1927
  if (dataSet.timer) {
1430
1928
  clearTimeout(dataSet.timer);
1431
1929
  }
1432
- _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " setting \"").concat(dataSet.name, "\" sync timer for ").concat(delay));
1433
- dataSet.timer = setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
1434
- var rootHash;
1435
- return _regenerator.default.wrap(function (_context7) {
1436
- while (1) switch (_context7.prev = _context7.next) {
1437
- case 0:
1438
- dataSet.timer = undefined;
1439
- if (dataSet.hashTree) {
1440
- _context7.next = 1;
1441
- break;
1442
- }
1443
- _loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(_this11.debugId, " Data set \"").concat(dataSet.name, "\" no longer has a hash tree, cannot run sync algorithm"));
1444
- return _context7.abrupt("return");
1445
- case 1:
1446
- rootHash = dataSet.hashTree.getRootHash();
1447
- if (!(dataSet.root !== rootHash)) {
1448
- _context7.next = 3;
1449
- break;
1450
- }
1451
- _context7.next = 2;
1452
- return _this11.performSync(dataSet, rootHash, "Root hash mismatch: received=".concat(dataSet.root, ", ours=").concat(rootHash));
1453
- case 2:
1454
- _context7.next = 4;
1455
- break;
1456
- case 3:
1457
- _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(_this11.debugId, " \"").concat(dataSet.name, "\" root hash matching: ").concat(rootHash, ", version=").concat(dataSet.version));
1458
- case 4:
1459
- case "end":
1460
- return _context7.stop();
1461
- }
1462
- }, _callee6);
1463
- })), delay);
1930
+ this.saveSyncBackoffLatency(dataSet.name, randomBackoffTime);
1931
+ dataSet.timer = setTimeout(function () {
1932
+ dataSet.timer = undefined;
1933
+ if (!dataSet.hashTree) {
1934
+ _loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(_this10.debugId, " Data set \"").concat(dataSet.name, "\" no longer has a hash tree, cannot run sync algorithm"));
1935
+ return;
1936
+ }
1937
+ var rootHash = dataSet.hashTree.getRootHash();
1938
+ if (dataSet.root !== rootHash) {
1939
+ _this10.enqueueSyncForDataset(dataSet.name, "Root hash mismatch: received=".concat(dataSet.root, ", ours=").concat(rootHash));
1940
+ }
1941
+ }, delay);
1464
1942
  } else {
1465
1943
  _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " No delay for \"").concat(dataSet.name, "\" data set, skipping sync timer reset/setup"));
1466
1944
  }
@@ -1478,48 +1956,46 @@ var HashTreeParser = /*#__PURE__*/function () {
1478
1956
  }, {
1479
1957
  key: "resetHeartbeatWatchdogs",
1480
1958
  value: function resetHeartbeatWatchdogs(receivedDataSets) {
1481
- var _this12 = this;
1482
- if (!this.heartbeatIntervalMs) {
1483
- return;
1484
- }
1485
- var _iterator9 = _createForOfIteratorHelper(receivedDataSets),
1486
- _step9;
1959
+ var _this11 = this;
1960
+ var _iterator10 = _createForOfIteratorHelper(receivedDataSets),
1961
+ _step10;
1487
1962
  try {
1488
1963
  var _loop2 = function _loop2() {
1489
- var receivedDataSet = _step9.value;
1490
- var dataSet = _this12.dataSets[receivedDataSet.name];
1491
- if (!(dataSet !== null && dataSet !== void 0 && dataSet.hashTree)) {
1492
- // eslint-disable-next-line no-continue
1493
- return 1; // continue
1494
- }
1964
+ var _dataSet$heartbeatInt;
1965
+ var receivedDataSet = _step10.value;
1966
+ var dataSet = _this11.dataSets[receivedDataSet.name];
1495
1967
  if (dataSet.heartbeatWatchdogTimer) {
1496
1968
  clearTimeout(dataSet.heartbeatWatchdogTimer);
1497
1969
  dataSet.heartbeatWatchdogTimer = undefined;
1498
1970
  }
1499
- var backoffTime = _this12.getWeightedBackoffTime(dataSet.backoff);
1500
- var delay = _this12.heartbeatIntervalMs + backoffTime;
1501
- dataSet.heartbeatWatchdogTimer = setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
1502
- return _regenerator.default.wrap(function (_context8) {
1503
- while (1) switch (_context8.prev = _context8.next) {
1504
- case 0:
1505
- dataSet.heartbeatWatchdogTimer = undefined;
1506
- _loggerProxy.default.logger.warn("HashTreeParser#resetHeartbeatWatchdogs --> ".concat(_this12.debugId, " Heartbeat watchdog fired for data set \"").concat(dataSet.name, "\" - no heartbeat received within expected interval, initiating sync"));
1507
- _context8.next = 1;
1508
- return _this12.performSync(dataSet, dataSet.hashTree.getRootHash(), "heartbeat watchdog expired");
1509
- case 1:
1510
- case "end":
1511
- return _context8.stop();
1512
- }
1513
- }, _callee7);
1514
- })), delay);
1971
+
1972
+ // dataset-level heartbeatIntervalMs takes priority; fall back to top-level common value
1973
+ var heartbeatIntervalMs = (_dataSet$heartbeatInt = dataSet === null || dataSet === void 0 ? void 0 : dataSet.heartbeatIntervalMs) !== null && _dataSet$heartbeatInt !== void 0 ? _dataSet$heartbeatInt : _this11.topLevelHeartbeatIntervalMs;
1974
+ if (!(dataSet !== null && dataSet !== void 0 && dataSet.hashTree) || !heartbeatIntervalMs) {
1975
+ // eslint-disable-next-line no-continue
1976
+ return 1; // continue
1977
+ }
1978
+ var backoffTime = _this11.getWeightedBackoffTime(dataSet.backoff);
1979
+ var delay = heartbeatIntervalMs + backoffTime;
1980
+ dataSet.heartbeatWatchdogTimer = setTimeout(function () {
1981
+ dataSet.heartbeatWatchdogTimer = undefined;
1982
+ _loggerProxy.default.logger.warn("HashTreeParser#resetHeartbeatWatchdogs --> ".concat(_this11.debugId, " Heartbeat watchdog fired for data set \"").concat(dataSet.name, "\" - no heartbeat received within expected interval, initiating sync"));
1983
+ _metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, {
1984
+ debugId: _this11.debugId,
1985
+ dataSetName: dataSet.name
1986
+ });
1987
+ _this11.saveSyncBackoffLatency(dataSet.name, backoffTime);
1988
+ _this11.enqueueSyncForDataset(dataSet.name, "heartbeat watchdog expired");
1989
+ _this11.resetHeartbeatWatchdogs([dataSet]);
1990
+ }, delay);
1515
1991
  };
1516
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1992
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1517
1993
  if (_loop2()) continue;
1518
1994
  }
1519
1995
  } catch (err) {
1520
- _iterator9.e(err);
1996
+ _iterator10.e(err);
1521
1997
  } finally {
1522
- _iterator9.f();
1998
+ _iterator10.f();
1523
1999
  }
1524
2000
  }
1525
2001
 
@@ -1553,7 +2029,14 @@ var HashTreeParser = /*#__PURE__*/function () {
1553
2029
  value: function stop() {
1554
2030
  _loggerProxy.default.logger.info("HashTreeParser#stop --> ".concat(this.debugId, " Stopping HashTreeParser, clearing timers and hash trees"));
1555
2031
  this.stopAllTimers();
2032
+ this.syncQueue = [];
2033
+ this.topLevelHeartbeatIntervalMs = undefined;
2034
+ this.syncAllBackoffType = SyncAllBackoffType.NONE;
2035
+ this.dataSetsSyncedDuringBackoff = new _set.default();
1556
2036
  (0, _values.default)(this.dataSets).forEach(function (dataSet) {
2037
+ var _dataSet$syncAbortCon2;
2038
+ (_dataSet$syncAbortCon2 = dataSet.syncAbortController) === null || _dataSet$syncAbortCon2 === void 0 ? void 0 : _dataSet$syncAbortCon2.abort();
2039
+ dataSet.syncAbortController = undefined;
1557
2040
  dataSet.hashTree = undefined;
1558
2041
  });
1559
2042
  this.visibleDataSets = [];
@@ -1573,29 +2056,28 @@ var HashTreeParser = /*#__PURE__*/function () {
1573
2056
  }
1574
2057
 
1575
2058
  /**
1576
- * Resumes the HashTreeParser that was previously stopped.
2059
+ * Resumes the HashTreeParser that was previously stopped, using a hash tree message.
1577
2060
  * @param {HashTreeMessage} message - The message to resume with, it must contain metadata with visible data sets info
1578
2061
  * @returns {void}
1579
2062
  */
1580
2063
  }, {
1581
- key: "resume",
1582
- value: function resume(message) {
1583
- var _message$locusStateEl2, _metadataObject$data;
1584
- // check that message contains metadata with visible data sets - this is essential to be able to resume
1585
- var metadataObject = (_message$locusStateEl2 = message.locusStateElements) === null || _message$locusStateEl2 === void 0 ? void 0 : _message$locusStateEl2.find(function (el) {
2064
+ key: "resumeFromMessage",
2065
+ value: function resumeFromMessage(message) {
2066
+ var _message$locusStateEl3, _metadataObject$data;
2067
+ var metadataObject = (_message$locusStateEl3 = message.locusStateElements) === null || _message$locusStateEl3 === void 0 ? void 0 : _message$locusStateEl3.find(function (el) {
1586
2068
  return (0, _utils.isMetadata)(el);
1587
2069
  });
1588
2070
  if (!(metadataObject !== null && metadataObject !== void 0 && (_metadataObject$data = metadataObject.data) !== null && _metadataObject$data !== void 0 && _metadataObject$data.visibleDataSets)) {
1589
- _loggerProxy.default.logger.warn("HashTreeParser#resume --> ".concat(this.debugId, " Cannot resume HashTreeParser because the message is missing metadata with visible data sets info"));
2071
+ _loggerProxy.default.logger.warn("HashTreeParser#resumeFromMessage --> ".concat(this.debugId, " Cannot resume HashTreeParser because the message is missing metadata with visible data sets info"));
1590
2072
  return;
1591
2073
  }
1592
2074
  this.setVisibleDataSets(metadataObject.data.visibleDataSets, message.dataSets);
1593
2075
  this.dataSets = {};
1594
- var _iterator0 = _createForOfIteratorHelper(message.dataSets),
1595
- _step0;
2076
+ var _iterator11 = _createForOfIteratorHelper(message.dataSets),
2077
+ _step11;
1596
2078
  try {
1597
- for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
1598
- var dataSet = _step0.value;
2079
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
2080
+ var dataSet = _step11.value;
1599
2081
  var name = dataSet.name,
1600
2082
  leafCount = dataSet.leafCount;
1601
2083
  this.dataSets[name] = _objectSpread(_objectSpread({}, dataSet), {}, {
@@ -1603,23 +2085,62 @@ var HashTreeParser = /*#__PURE__*/function () {
1603
2085
  });
1604
2086
  }
1605
2087
  } catch (err) {
1606
- _iterator0.e(err);
2088
+ _iterator11.e(err);
1607
2089
  } finally {
1608
- _iterator0.f();
2090
+ _iterator11.f();
1609
2091
  }
1610
- _loggerProxy.default.logger.info("HashTreeParser#resume --> ".concat(this.debugId, " Resuming HashTreeParser with data sets: ").concat((0, _keys.default)(this.dataSets).join(', '), ", visible data sets: ").concat(this.visibleDataSets.map(function (ds) {
2092
+ _loggerProxy.default.logger.info("HashTreeParser#resumeFromMessage --> ".concat(this.debugId, " Resuming HashTreeParser with data sets: ").concat((0, _keys.default)(this.dataSets).join(', '), ", visible data sets: ").concat(this.visibleDataSets.map(function (ds) {
1611
2093
  return ds.name;
1612
2094
  }).join(', ')));
1613
2095
  this.state = 'active';
1614
2096
  this.handleMessage(message, 'on resume');
1615
2097
  }
2098
+
2099
+ /**
2100
+ * Resumes the HashTreeParser that was previously stopped, using a Locus API response.
2101
+ * Unlike resumeFromMessage(), this does not require metadata/dataSets in the input,
2102
+ * as it fetches all necessary information from Locus via initializeFromGetLociResponse.
2103
+ * @param {LocusDTO} locus - locus object from an API response
2104
+ * @returns {Promise}
2105
+ */
2106
+ }, {
2107
+ key: "resumeFromApiResponse",
2108
+ value: (function () {
2109
+ var _resumeFromApiResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9(locus) {
2110
+ return _regenerator.default.wrap(function (_context0) {
2111
+ while (1) switch (_context0.prev = _context0.next) {
2112
+ case 0:
2113
+ this.state = 'active';
2114
+ this.dataSets = {};
2115
+ _loggerProxy.default.logger.info("HashTreeParser#resumeFromApiResponse --> ".concat(this.debugId, " Resuming HashTreeParser from API response"));
2116
+ _context0.next = 1;
2117
+ return this.initializeFromGetLociResponse(locus);
2118
+ case 1:
2119
+ case "end":
2120
+ return _context0.stop();
2121
+ }
2122
+ }, _callee9, this);
2123
+ }));
2124
+ function resumeFromApiResponse(_x1) {
2125
+ return _resumeFromApiResponse.apply(this, arguments);
2126
+ }
2127
+ return resumeFromApiResponse;
2128
+ }())
1616
2129
  }, {
1617
2130
  key: "checkForSentinelHttpResponse",
1618
2131
  value: function checkForSentinelHttpResponse(error, dataSetName) {
1619
2132
  var _error$body;
2133
+ // 404 for any dataset means the locus is no longer available at this URL - could be replaced or ended
2134
+ // if a dataset is just not visible, we would get a 400
2135
+ if (error.statusCode === 404) {
2136
+ _loggerProxy.default.logger.info("HashTreeParser#checkForSentinelHttpResponse --> ".concat(this.debugId, " Received 404 for data set \"").concat(dataSetName, "\", locus not found"));
2137
+ this.stopAllTimers();
2138
+ throw new LocusNotFoundError();
2139
+ }
1620
2140
  var isValidDataSetForSentinel = dataSetName === undefined || PossibleSentinelMessageDataSetNames.includes(dataSetName.toLowerCase());
1621
- if ((error.statusCode === 409 && ((_error$body = error.body) === null || _error$body === void 0 ? void 0 : _error$body.errorCode) === 2403004 || error.statusCode === 404) && isValidDataSetForSentinel) {
1622
- _loggerProxy.default.logger.info("HashTreeParser#checkForSentinelHttpResponse --> ".concat(this.debugId, " Received ").concat(error.statusCode, " for data set \"").concat(dataSetName, "\", indicating that the meeting has ended"));
2141
+ if (error.statusCode === 409 && ((_error$body = error.body) === null || _error$body === void 0 ? void 0 : _error$body.errorCode) === _types2.LocusErrorCodes.LOCUS_INACTIVE && isValidDataSetForSentinel) {
2142
+ var _error$body2;
2143
+ _loggerProxy.default.logger.info("HashTreeParser#checkForSentinelHttpResponse --> ".concat(this.debugId, " Received ").concat(error.statusCode, "/").concat((_error$body2 = error.body) === null || _error$body2 === void 0 ? void 0 : _error$body2.errorCode, " for data set \"").concat(dataSetName, "\", indicating that the meeting has ended"));
1623
2144
  this.stopAllTimers();
1624
2145
  throw new MeetingEndedError();
1625
2146
  }
@@ -1629,37 +2150,81 @@ var HashTreeParser = /*#__PURE__*/function () {
1629
2150
  * Gets the current hashes from the locus for a specific data set.
1630
2151
  * @param {string} dataSetName
1631
2152
  * @param {string} currentRootHash
1632
- * @returns {string[]}
2153
+ * @param {Object} [trackingIds] tracking ids for the /hashtree request
2154
+ * @param {string} [trackingIds.requestTrackingId] tracking id forced onto the /hashtree HTTP request header (kept distinct from the /sync request's tracking id)
2155
+ * @param {string} [trackingIds.metricTrackingId] tracking id (the /sync request's) under which the hashtree latency milestones are recorded, so they belong to the same sync latency record
2156
+ * @returns {Object|null} An object containing the hashes and leaf count, or null if the hashes match and no sync is needed
1633
2157
  */
1634
2158
  }, {
1635
2159
  key: "getHashesFromLocus",
1636
- value: function getHashesFromLocus(dataSetName, currentRootHash) {
1637
- var _this13 = this;
2160
+ value: function getHashesFromLocus(dataSetName, currentRootHash, trackingIds) {
2161
+ var _this12 = this;
2162
+ var _ref9 = trackingIds !== null && trackingIds !== void 0 ? trackingIds : {},
2163
+ requestTrackingId = _ref9.requestTrackingId,
2164
+ metricTrackingId = _ref9.metricTrackingId;
1638
2165
  _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(this.debugId, " Requesting hashes for data set \"").concat(dataSetName, "\""));
1639
2166
  var dataSet = this.dataSets[dataSetName];
1640
2167
  var url = "".concat(dataSet.url, "/hashtree");
1641
- return this.webexRequest({
1642
- method: _constants.HTTP_VERBS.GET,
2168
+ if (this.shouldCollectSyncMetrics(dataSetName)) {
2169
+ var _this$callbacks$syncL4;
2170
+ (_this$callbacks$syncL4 = this.callbacks.syncLatencyTracker) === null || _this$callbacks$syncL4 === void 0 ? void 0 : _this$callbacks$syncL4.saveTimestamp({
2171
+ key: 'internal.client.locus.hashtree.request',
2172
+ options: {
2173
+ meetingId: this.syncLatencyMeetingId,
2174
+ dataSetName: dataSetName,
2175
+ trackingId: metricTrackingId
2176
+ }
2177
+ });
2178
+ }
2179
+ return this.webexRequest(_objectSpread({
2180
+ method: _constants2.HTTP_VERBS.GET,
1643
2181
  uri: url,
1644
2182
  qs: {
1645
2183
  rootHash: currentRootHash
1646
2184
  }
1647
- }).then(function (response) {
2185
+ }, requestTrackingId ? {
2186
+ headers: {
2187
+ trackingid: requestTrackingId
2188
+ }
2189
+ } : {})).then(function (response) {
1648
2190
  var _response$body, _response$body2;
2191
+ if (_this12.shouldCollectSyncMetrics(dataSetName)) {
2192
+ var _this12$callbacks$syn;
2193
+ (_this12$callbacks$syn = _this12.callbacks.syncLatencyTracker) === null || _this12$callbacks$syn === void 0 ? void 0 : _this12$callbacks$syn.saveTimestamp({
2194
+ key: 'internal.client.locus.hashtree.response',
2195
+ options: {
2196
+ meetingId: _this12.syncLatencyMeetingId,
2197
+ dataSetName: dataSetName,
2198
+ trackingId: metricTrackingId
2199
+ }
2200
+ });
2201
+ }
2202
+ if (!response.body || (0, _lodash.isEmpty)(response.body)) {
2203
+ // 204 with empty body means our hashes match Locus, no sync needed
2204
+ _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Got ").concat(response.statusCode, " with empty body for data set \"").concat(dataSetName, "\", hashes match - no sync needed"));
2205
+ return null;
2206
+ }
1649
2207
  var hashes = (_response$body = response.body) === null || _response$body === void 0 ? void 0 : _response$body.hashes;
1650
2208
  var dataSetFromResponse = (_response$body2 = response.body) === null || _response$body2 === void 0 ? void 0 : _response$body2.dataSet;
1651
2209
  if (!hashes || !(0, _isArray.default)(hashes)) {
1652
- _loggerProxy.default.logger.warn("HashTreeParser#getHashesFromLocus --> ".concat(_this13.debugId, " Locus returned invalid hashes, response body="), response.body);
2210
+ _loggerProxy.default.logger.warn("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Locus returned invalid hashes, response body="), response.body);
1653
2211
  throw new Error("Locus returned invalid hashes: ".concat(hashes));
1654
2212
  }
1655
- _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this13.debugId, " Received hashes for data set \"").concat(dataSetName, "\": ").concat((0, _stringify.default)(hashes)));
2213
+ _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Received hashes for data set \"").concat(dataSetName, "\": ").concat((0, _stringify.default)(hashes)));
1656
2214
  return {
1657
2215
  hashes: hashes,
1658
2216
  dataSet: dataSetFromResponse
1659
2217
  };
1660
2218
  }).catch(function (error) {
1661
- _loggerProxy.default.logger.error("HashTreeParser#getHashesFromLocus --> ".concat(_this13.debugId, " Error ").concat(error.statusCode, " fetching hashes for data set \"").concat(dataSetName, "\":"), error);
1662
- _this13.checkForSentinelHttpResponse(error, dataSet.name);
2219
+ _loggerProxy.default.logger.error("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Error ").concat(error.statusCode, " fetching hashes for data set \"").concat(dataSetName, "\":"), error);
2220
+ _this12.checkForSentinelHttpResponse(error, dataSet.name);
2221
+ _metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_SYNC_FAILURE, {
2222
+ debugId: _this12.debugId,
2223
+ dataSetName: dataSetName,
2224
+ request: 'GET /hashtree',
2225
+ statusCode: error.statusCode,
2226
+ reason: error.message
2227
+ });
1663
2228
  throw error;
1664
2229
  });
1665
2230
  }
@@ -1668,44 +2233,89 @@ var HashTreeParser = /*#__PURE__*/function () {
1668
2233
  * Sends a sync request to Locus for the specified data set.
1669
2234
  *
1670
2235
  * @param {InternalDataSet} dataSet The data set to sync.
1671
- * @param {Record<number, LeafDataItem[]>} mismatchedLeavesData The mismatched leaves data to include in the sync request.
1672
- * @returns {Promise<HashTreeMessage|null>}
2236
+ * @param {Object} options Either `{ isInitialization: true }` for init syncs (uses leafCount=1 with empty leaf data) or `{ mismatchedLeavesData }` for normal syncs.
2237
+ * @param {string} [trackingId] tracking id
2238
+ * @returns {Promise<HashTreeMessage | null>}
1673
2239
  */
1674
2240
  }, {
1675
2241
  key: "sendSyncRequestToLocus",
1676
- value: function sendSyncRequestToLocus(dataSet, mismatchedLeavesData) {
1677
- var _this14 = this;
2242
+ value: function sendSyncRequestToLocus(dataSet, options, trackingId) {
2243
+ var _this13 = this;
1678
2244
  _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(this.debugId, " Sending sync request for data set \"").concat(dataSet.name, "\""));
2245
+ var isInitialization = 'isInitialization' in options;
1679
2246
  var url = "".concat(dataSet.url, "/sync");
1680
2247
  var body = {
1681
- leafCount: dataSet.leafCount,
2248
+ leafCount: isInitialization ? 1 : dataSet.leafCount,
1682
2249
  leafDataEntries: []
1683
2250
  };
1684
- (0, _keys.default)(mismatchedLeavesData).forEach(function (index) {
1685
- var leafIndex = (0, _parseInt2.default)(index, 10);
2251
+ if (isInitialization) {
2252
+ // initialization sync: Locus requires leafCount=1 with a single empty leaf
1686
2253
  body.leafDataEntries.push({
1687
- leafIndex: leafIndex,
1688
- elementIds: mismatchedLeavesData[leafIndex]
2254
+ leafIndex: 0,
2255
+ elementIds: []
1689
2256
  });
1690
- });
1691
- var ourCurrentRootHash = dataSet.hashTree ? dataSet.hashTree.getRootHash() : _constants2.EMPTY_HASH;
1692
- return this.webexRequest({
1693
- method: _constants.HTTP_VERBS.POST,
2257
+ } else {
2258
+ var mismatchedLeavesData = options.mismatchedLeavesData;
2259
+ (0, _keys.default)(mismatchedLeavesData).forEach(function (index) {
2260
+ var leafIndex = (0, _parseInt2.default)(index, 10);
2261
+ body.leafDataEntries.push({
2262
+ leafIndex: leafIndex,
2263
+ elementIds: mismatchedLeavesData[leafIndex]
2264
+ });
2265
+ });
2266
+ }
2267
+ var ourCurrentRootHash = dataSet.hashTree ? dataSet.hashTree.getRootHash() : _constants3.EMPTY_HASH;
2268
+ var shouldCollectMetrics = this.shouldCollectSyncMetrics(dataSet.name, isInitialization);
2269
+ if (shouldCollectMetrics) {
2270
+ var _this$callbacks$syncL5;
2271
+ (_this$callbacks$syncL5 = this.callbacks.syncLatencyTracker) === null || _this$callbacks$syncL5 === void 0 ? void 0 : _this$callbacks$syncL5.saveTimestamp({
2272
+ key: 'internal.client.locus.sync.request',
2273
+ options: {
2274
+ meetingId: this.syncLatencyMeetingId,
2275
+ dataSetName: dataSet.name,
2276
+ trackingId: trackingId
2277
+ }
2278
+ });
2279
+ }
2280
+ return this.webexRequest(_objectSpread(_objectSpread({
2281
+ method: _constants2.HTTP_VERBS.POST,
1694
2282
  uri: url,
1695
2283
  qs: {
1696
2284
  rootHash: ourCurrentRootHash
1697
- },
2285
+ }
2286
+ }, trackingId ? {
2287
+ headers: {
2288
+ trackingid: trackingId
2289
+ }
2290
+ } : {}), {}, {
1698
2291
  body: body
1699
- }).then(function (resp) {
1700
- _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this14.debugId, " Sync request succeeded for \"").concat(dataSet.name, "\""));
2292
+ })).then(function (resp) {
2293
+ if (shouldCollectMetrics) {
2294
+ var _this13$callbacks$syn;
2295
+ (_this13$callbacks$syn = _this13.callbacks.syncLatencyTracker) === null || _this13$callbacks$syn === void 0 ? void 0 : _this13$callbacks$syn.saveTimestamp({
2296
+ key: 'internal.client.locus.sync.response',
2297
+ options: {
2298
+ meetingId: _this13.syncLatencyMeetingId,
2299
+ dataSetName: dataSet.name,
2300
+ trackingId: trackingId
2301
+ }
2302
+ });
2303
+ }
1701
2304
  if (!resp.body || (0, _lodash.isEmpty)(resp.body)) {
1702
- _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this14.debugId, " Got ").concat(resp.statusCode, " with empty body for sync request for data set \"").concat(dataSet.name, "\", data should arrive via messages"));
2305
+ _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this13.debugId, " Got ").concat(resp.statusCode, " with empty body for sync request for data set \"").concat(dataSet.name, "\", data should arrive via messages"));
1703
2306
  return null;
1704
2307
  }
1705
2308
  return resp.body;
1706
2309
  }).catch(function (error) {
1707
- _loggerProxy.default.logger.error("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this14.debugId, " Error ").concat(error.statusCode, " sending sync request for data set \"").concat(dataSet.name, "\":"), error);
1708
- _this14.checkForSentinelHttpResponse(error, dataSet.name);
2310
+ _loggerProxy.default.logger.error("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this13.debugId, " Error ").concat(error.statusCode, " sending sync request for data set \"").concat(dataSet.name, "\":"), error);
2311
+ _this13.checkForSentinelHttpResponse(error, dataSet.name);
2312
+ _metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_SYNC_FAILURE, {
2313
+ debugId: _this13.debugId,
2314
+ dataSetName: dataSet.name,
2315
+ request: 'POST /sync',
2316
+ statusCode: error.statusCode,
2317
+ reason: error.message
2318
+ });
1709
2319
  throw error;
1710
2320
  });
1711
2321
  }