@webex/plugin-meetings 3.12.0 → 3.13.0

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