@liveblocks/core 2.16.0 → 2.16.1-ai

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.16.0";
9
+ var PKG_VERSION = "2.16.1-ai";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -166,14 +166,6 @@ function wrapWithTitle(method) {
166
166
  var warnWithTitle = wrapWithTitle("warn");
167
167
  var errorWithTitle = wrapWithTitle("error");
168
168
 
169
- // src/lib/guards.ts
170
- function isPlainObject(blob) {
171
- return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
172
- }
173
- function isStartsWithOperator(blob) {
174
- return isPlainObject(blob) && typeof blob.startsWith === "string";
175
- }
176
-
177
169
  // src/lib/utils.ts
178
170
  function raise(msg) {
179
171
  throw new Error(msg);
@@ -259,48 +251,13 @@ function memoizeOnSuccess(factoryFn) {
259
251
  }
260
252
 
261
253
  // src/lib/autoRetry.ts
262
- var HttpError = class _HttpError extends Error {
263
-
264
-
265
- constructor(message, response, details) {
254
+ var HttpError = class extends Error {
255
+ constructor(message, status, details) {
266
256
  super(message);
267
- this.name = "HttpError";
268
- this.response = response;
257
+ this.message = message;
258
+ this.status = status;
269
259
  this.details = details;
270
260
  }
271
- static async fromResponse(response) {
272
- let bodyAsText;
273
- try {
274
- bodyAsText = await response.text();
275
- } catch (e2) {
276
- }
277
- const bodyAsJson = bodyAsText ? tryParseJson(bodyAsText) : void 0;
278
- let bodyAsJsonObject;
279
- if (isPlainObject(bodyAsJson)) {
280
- bodyAsJsonObject = bodyAsJson;
281
- }
282
- let message = "";
283
- message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _2 => _2.message]) === "string" ? bodyAsJsonObject.message : "";
284
- message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _3 => _3.error]) === "string" ? bodyAsJsonObject.error : "";
285
- if (bodyAsJson === void 0) {
286
- message ||= bodyAsText || "";
287
- }
288
- message ||= response.statusText;
289
- let path;
290
- try {
291
- path = new URL(response.url).pathname;
292
- } catch (e3) {
293
- }
294
- message += path !== void 0 ? ` (got status ${response.status} from ${path})` : ` (got status ${response.status})`;
295
- const details = bodyAsJsonObject;
296
- return new _HttpError(message, response, details);
297
- }
298
- /**
299
- * Convenience accessor for response.status.
300
- */
301
- get status() {
302
- return this.response.status;
303
- }
304
261
  };
305
262
  var DONT_RETRY_4XX = (x) => x instanceof HttpError && x.status >= 400 && x.status < 500;
306
263
  async function autoRetry(promiseFn, maxTries, backoff, shouldStopRetrying = DONT_RETRY_4XX) {
@@ -363,15 +320,10 @@ function makeEventSource() {
363
320
  res(event);
364
321
  }
365
322
  });
366
- }).finally(() => _optionalChain([unsub, 'optionalCall', _4 => _4()]));
323
+ }).finally(() => _optionalChain([unsub, 'optionalCall', _2 => _2()]));
367
324
  }
368
325
  function notify(event) {
369
- let called = false;
370
- for (const callback of _observers) {
371
- callback(event);
372
- called = true;
373
- }
374
- return called;
326
+ _observers.forEach((callback) => callback(event));
375
327
  }
376
328
  function count() {
377
329
  return _observers.size;
@@ -412,9 +364,8 @@ function makeBufferableEventSource() {
412
364
  function notifyOrBuffer(event) {
413
365
  if (_buffer !== null) {
414
366
  _buffer.push(event);
415
- return false;
416
367
  } else {
417
- return eventSource2.notify(event);
368
+ eventSource2.notify(event);
418
369
  }
419
370
  }
420
371
  return {
@@ -554,7 +505,7 @@ var Signal = class extends AbstractSignal {
554
505
  this.#value = "(disposed)";
555
506
  }
556
507
  get() {
557
- _optionalChain([trackedReads, 'optionalAccess', _5 => _5.add, 'call', _6 => _6(this)]);
508
+ _optionalChain([trackedReads, 'optionalAccess', _3 => _3.add, 'call', _4 => _4(this)]);
558
509
  return this.#value;
559
510
  }
560
511
  set(newValue) {
@@ -664,7 +615,7 @@ var DerivedSignal = class _DerivedSignal extends AbstractSignal {
664
615
  if (this.#dirty) {
665
616
  this.#recompute();
666
617
  }
667
- _optionalChain([trackedReads, 'optionalAccess', _7 => _7.add, 'call', _8 => _8(this)]);
618
+ _optionalChain([trackedReads, 'optionalAccess', _5 => _5.add, 'call', _6 => _6(this)]);
668
619
  return this.#prevValue;
669
620
  }
670
621
  /**
@@ -694,7 +645,7 @@ var MutableSignal = class extends AbstractSignal {
694
645
  this.#state = "(disposed)";
695
646
  }
696
647
  get() {
697
- _optionalChain([trackedReads, 'optionalAccess', _9 => _9.add, 'call', _10 => _10(this)]);
648
+ _optionalChain([trackedReads, 'optionalAccess', _7 => _7.add, 'call', _8 => _8(this)]);
698
649
  return this.#state;
699
650
  }
700
651
  /**
@@ -719,15 +670,32 @@ var MutableSignal = class extends AbstractSignal {
719
670
  };
720
671
 
721
672
  // src/lib/stringify.ts
673
+ var EXPLICIT_UNDEFINED_PLACEHOLDER = "_explicit_undefined";
722
674
  function replacer(_key, value) {
723
675
  return value !== null && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).sort().reduce((sorted, key) => {
724
676
  sorted[key] = value[key];
725
677
  return sorted;
726
- }, {}) : value;
678
+ }, {}) : value === void 0 ? EXPLICIT_UNDEFINED_PLACEHOLDER : value;
679
+ }
680
+ function reviver(key, value) {
681
+ if (!key && value === EXPLICIT_UNDEFINED_PLACEHOLDER) {
682
+ return void 0;
683
+ }
684
+ if (value && typeof value === "object") {
685
+ for (const k in value) {
686
+ if (value[k] === EXPLICIT_UNDEFINED_PLACEHOLDER) {
687
+ Object.defineProperty(value, k, { value: void 0 });
688
+ }
689
+ }
690
+ }
691
+ return value;
727
692
  }
728
693
  function stringify(value) {
729
694
  return JSON.stringify(value, replacer);
730
695
  }
696
+ function unstringify(value) {
697
+ return JSON.parse(value, reviver);
698
+ }
731
699
 
732
700
  // src/lib/batch.ts
733
701
  var DEFAULT_SIZE = 50;
@@ -780,7 +748,7 @@ var Batch = (_class = class {
780
748
  const results = await this.#callback(inputs);
781
749
  this.error = false;
782
750
  calls.forEach((call, index) => {
783
- const result = _optionalChain([results, 'optionalAccess', _11 => _11[index]]);
751
+ const result = _optionalChain([results, 'optionalAccess', _9 => _9[index]]);
784
752
  if (!Array.isArray(results)) {
785
753
  call.reject(new Error("Callback must return an array."));
786
754
  } else if (calls.length !== results.length) {
@@ -943,6 +911,14 @@ var DefaultMap = class extends Map {
943
911
  }
944
912
  };
945
913
 
914
+ // src/lib/guards.ts
915
+ function isPlainObject(blob) {
916
+ return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
917
+ }
918
+ function isStartsWithOperator(blob) {
919
+ return isPlainObject(blob) && typeof blob.startsWith === "string";
920
+ }
921
+
946
922
  // src/lib/objectToQuery.ts
947
923
  var identifierRegex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
948
924
  function objectToQuery(obj) {
@@ -992,7 +968,9 @@ function objectToQuery(obj) {
992
968
  ...getFiltersFromKeyValuePairsWithOperator(nKeyValuePairsWithOperator)
993
969
  ];
994
970
  });
995
- return filterList.map(({ key, operator, value }) => `${key}${operator}${quote(value)}`).join(" ");
971
+ return filterList.map(
972
+ ({ key, operator, value }) => formatFilter(key, operator, formatFilterValue(value))
973
+ ).join(" AND ");
996
974
  }
997
975
  var getFiltersFromKeyValuePairs = (keyValuePairs) => {
998
976
  const filters = [];
@@ -1019,27 +997,29 @@ var getFiltersFromKeyValuePairsWithOperator = (keyValuePairsWithOperator) => {
1019
997
  return filters;
1020
998
  };
1021
999
  var isSimpleValue = (value) => {
1022
- return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
1000
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1001
+ };
1002
+ var formatFilter = (key, operator, value) => {
1003
+ return `${key}${operator}${value}`;
1023
1004
  };
1024
1005
  var formatFilterKey = (key, nestedKey) => {
1025
1006
  if (nestedKey) {
1026
- return `${key}[${quote(nestedKey)}]`;
1007
+ return `${key}[${JSON.stringify(nestedKey)}]`;
1027
1008
  }
1028
1009
  return key;
1029
1010
  };
1011
+ var formatFilterValue = (value) => {
1012
+ if (typeof value === "string") {
1013
+ if (isStringEmpty(value)) {
1014
+ throw new Error("Value cannot be empty");
1015
+ }
1016
+ return JSON.stringify(value);
1017
+ }
1018
+ return value.toString();
1019
+ };
1030
1020
  var isStringEmpty = (value) => {
1031
1021
  return !value || value.toString().trim() === "";
1032
1022
  };
1033
- function quote(input) {
1034
- const result = JSON.stringify(input);
1035
- if (typeof input !== "string") {
1036
- return result;
1037
- }
1038
- if (result.includes("'")) {
1039
- return result;
1040
- }
1041
- return `'${result.slice(1, -1).replace(/\\"/g, '"')}'`;
1042
- }
1043
1023
 
1044
1024
  // src/lib/url.ts
1045
1025
  function toURLSearchParams(params) {
@@ -1297,11 +1277,11 @@ function createApiClient({
1297
1277
  `Upload of attachment ${options.attachment.id} was aborted.`,
1298
1278
  "AbortError"
1299
1279
  ) : void 0;
1300
- if (_optionalChain([abortSignal, 'optionalAccess', _12 => _12.aborted])) {
1280
+ if (_optionalChain([abortSignal, 'optionalAccess', _10 => _10.aborted])) {
1301
1281
  throw abortError;
1302
1282
  }
1303
1283
  const handleRetryError = (err) => {
1304
- if (_optionalChain([abortSignal, 'optionalAccess', _13 => _13.aborted])) {
1284
+ if (_optionalChain([abortSignal, 'optionalAccess', _11 => _11.aborted])) {
1305
1285
  throw abortError;
1306
1286
  }
1307
1287
  if (err instanceof HttpError && err.status === 413) {
@@ -1373,7 +1353,7 @@ function createApiClient({
1373
1353
  try {
1374
1354
  uploadId = createMultiPartUpload.uploadId;
1375
1355
  const parts = splitFileIntoParts(attachment.file);
1376
- if (_optionalChain([abortSignal, 'optionalAccess', _14 => _14.aborted])) {
1356
+ if (_optionalChain([abortSignal, 'optionalAccess', _12 => _12.aborted])) {
1377
1357
  throw abortError;
1378
1358
  }
1379
1359
  const batches = chunk(parts, 5);
@@ -1400,7 +1380,7 @@ function createApiClient({
1400
1380
  }
1401
1381
  uploadedParts.push(...await Promise.all(uploadedPartsPromises));
1402
1382
  }
1403
- if (_optionalChain([abortSignal, 'optionalAccess', _15 => _15.aborted])) {
1383
+ if (_optionalChain([abortSignal, 'optionalAccess', _13 => _13.aborted])) {
1404
1384
  throw abortError;
1405
1385
  }
1406
1386
  const sortedUploadedParts = uploadedParts.sort(
@@ -1416,7 +1396,7 @@ function createApiClient({
1416
1396
  { signal: abortSignal }
1417
1397
  );
1418
1398
  } catch (error3) {
1419
- if (uploadId && _optionalChain([error3, 'optionalAccess', _16 => _16.name]) && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
1399
+ if (uploadId && _optionalChain([error3, 'optionalAccess', _14 => _14.name]) && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
1420
1400
  try {
1421
1401
  await httpClient.rawDelete(
1422
1402
  url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}`,
@@ -1556,6 +1536,25 @@ function createApiClient({
1556
1536
  }
1557
1537
  );
1558
1538
  }
1539
+ async function executeContextualPrompt(options) {
1540
+ const result = await httpClient.post(
1541
+ url`/v2/c/rooms/${options.roomId}/ai/contextual-prompt`,
1542
+ await authManager.getAuthValue({
1543
+ requestedScope: "room:read",
1544
+ roomId: options.roomId
1545
+ }),
1546
+ {
1547
+ prompt: options.prompt,
1548
+ selectionText: options.selectionText,
1549
+ context: options.context
1550
+ },
1551
+ { signal: options.signal }
1552
+ );
1553
+ if (!result || result.content.length === 0) {
1554
+ throw new Error("No content returned from server");
1555
+ }
1556
+ return result.content[0].text;
1557
+ }
1559
1558
  async function listTextVersions(options) {
1560
1559
  const result = await httpClient.get(
1561
1560
  url`/v2/c/rooms/${options.roomId}/versions`,
@@ -1623,7 +1622,7 @@ function createApiClient({
1623
1622
  url`/v2/c/inbox-notifications`,
1624
1623
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
1625
1624
  {
1626
- cursor: _optionalChain([options, 'optionalAccess', _17 => _17.cursor]),
1625
+ cursor: _optionalChain([options, 'optionalAccess', _15 => _15.cursor]),
1627
1626
  limit: PAGE_SIZE
1628
1627
  }
1629
1628
  );
@@ -1707,7 +1706,7 @@ function createApiClient({
1707
1706
  }
1708
1707
  async function getUserThreads_experimental(options) {
1709
1708
  let query;
1710
- if (_optionalChain([options, 'optionalAccess', _18 => _18.query])) {
1709
+ if (_optionalChain([options, 'optionalAccess', _16 => _16.query])) {
1711
1710
  query = objectToQuery(options.query);
1712
1711
  }
1713
1712
  const PAGE_SIZE = 50;
@@ -1715,7 +1714,7 @@ function createApiClient({
1715
1714
  url`/v2/c/threads`,
1716
1715
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
1717
1716
  {
1718
- cursor: _optionalChain([options, 'optionalAccess', _19 => _19.cursor]),
1717
+ cursor: _optionalChain([options, 'optionalAccess', _17 => _17.cursor]),
1719
1718
  query,
1720
1719
  limit: PAGE_SIZE
1721
1720
  }
@@ -1796,7 +1795,9 @@ function createApiClient({
1796
1795
  deleteInboxNotification,
1797
1796
  // User threads
1798
1797
  getUserThreads_experimental,
1799
- getUserThreadsSince_experimental
1798
+ getUserThreadsSince_experimental,
1799
+ // ai
1800
+ executeContextualPrompt
1800
1801
  };
1801
1802
  }
1802
1803
  function getBearerTokenFromAuthValue(authValue) {
@@ -1840,7 +1841,7 @@ var HttpClient = class {
1840
1841
  // These headers are default, but can be overriden by custom headers
1841
1842
  "Content-Type": "application/json; charset=utf-8",
1842
1843
  // Possible header overrides
1843
- ..._optionalChain([options, 'optionalAccess', _20 => _20.headers]),
1844
+ ..._optionalChain([options, 'optionalAccess', _18 => _18.headers]),
1844
1845
  // Cannot be overriden by custom headers
1845
1846
  Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
1846
1847
  "X-LB-Client": PKG_VERSION || "dev"
@@ -1864,12 +1865,19 @@ var HttpClient = class {
1864
1865
  async #fetch(endpoint, authValue, options, params) {
1865
1866
  const response = await this.#rawFetch(endpoint, authValue, options, params);
1866
1867
  if (!response.ok) {
1867
- throw await HttpError.fromResponse(response);
1868
+ let error3;
1869
+ try {
1870
+ const errorBody = await response.json();
1871
+ error3 = new HttpError(errorBody.message, response.status, errorBody);
1872
+ } catch (e2) {
1873
+ error3 = new HttpError(response.statusText, response.status);
1874
+ }
1875
+ throw error3;
1868
1876
  }
1869
1877
  let body;
1870
1878
  try {
1871
1879
  body = await response.json();
1872
- } catch (e4) {
1880
+ } catch (e3) {
1873
1881
  body = {};
1874
1882
  }
1875
1883
  return body;
@@ -2315,7 +2323,7 @@ var FSM = class {
2315
2323
  });
2316
2324
  }
2317
2325
  #getTargetFn(eventName) {
2318
- return _optionalChain([this, 'access', _21 => _21.#allowedTransitions, 'access', _22 => _22.get, 'call', _23 => _23(this.currentState), 'optionalAccess', _24 => _24.get, 'call', _25 => _25(eventName)]);
2326
+ return _optionalChain([this, 'access', _19 => _19.#allowedTransitions, 'access', _20 => _20.get, 'call', _21 => _21(this.currentState), 'optionalAccess', _22 => _22.get, 'call', _23 => _23(eventName)]);
2319
2327
  }
2320
2328
  /**
2321
2329
  * Exits the current state, and executes any necessary cleanup functions.
@@ -2332,7 +2340,7 @@ var FSM = class {
2332
2340
  this.#currentContext.allowPatching((patchableContext) => {
2333
2341
  levels = _nullishCoalesce(levels, () => ( this.#cleanupStack.length));
2334
2342
  for (let i = 0; i < levels; i++) {
2335
- _optionalChain([this, 'access', _26 => _26.#cleanupStack, 'access', _27 => _27.pop, 'call', _28 => _28(), 'optionalCall', _29 => _29(patchableContext)]);
2343
+ _optionalChain([this, 'access', _24 => _24.#cleanupStack, 'access', _25 => _25.pop, 'call', _26 => _26(), 'optionalCall', _27 => _27(patchableContext)]);
2336
2344
  }
2337
2345
  });
2338
2346
  }
@@ -2348,7 +2356,7 @@ var FSM = class {
2348
2356
  this.#currentContext.allowPatching((patchableContext) => {
2349
2357
  for (const pattern of enterPatterns) {
2350
2358
  const enterFn = this.#enterFns.get(pattern);
2351
- const cleanupFn = _optionalChain([enterFn, 'optionalCall', _30 => _30(patchableContext)]);
2359
+ const cleanupFn = _optionalChain([enterFn, 'optionalCall', _28 => _28(patchableContext)]);
2352
2360
  if (typeof cleanupFn === "function") {
2353
2361
  this.#cleanupStack.push(cleanupFn);
2354
2362
  } else {
@@ -2508,6 +2516,13 @@ var StopRetrying = class extends Error {
2508
2516
  super(reason);
2509
2517
  }
2510
2518
  };
2519
+ var LiveblocksError = class extends Error {
2520
+ /** @internal */
2521
+ constructor(message, code) {
2522
+ super(message);
2523
+ this.code = code;
2524
+ }
2525
+ };
2511
2526
  function nextBackoffDelay(currentDelay, delays) {
2512
2527
  return _nullishCoalesce(delays.find((delay) => delay > currentDelay), () => ( delays[delays.length - 1]));
2513
2528
  }
@@ -2617,10 +2632,11 @@ var assign = (patch) => (ctx) => ctx.patch(patch);
2617
2632
  function createConnectionStateMachine(delegates, options) {
2618
2633
  const onMessage = makeBufferableEventSource();
2619
2634
  onMessage.pause();
2620
- const onConnectionError = makeEventSource();
2621
- function fireErrorEvent(message, code) {
2635
+ const onLiveblocksError = makeEventSource();
2636
+ function fireErrorEvent(errmsg, errcode) {
2622
2637
  return () => {
2623
- onConnectionError.notify({ message, code });
2638
+ const err = new LiveblocksError(errmsg, errcode);
2639
+ onLiveblocksError.notify(err);
2624
2640
  };
2625
2641
  }
2626
2642
  const initialContext = {
@@ -2742,7 +2758,7 @@ function createConnectionStateMachine(delegates, options) {
2742
2758
  }
2743
2759
  function waitForActorId(event) {
2744
2760
  const serverMsg = tryParseJson(event.data);
2745
- if (_optionalChain([serverMsg, 'optionalAccess', _31 => _31.type]) === 104 /* ROOM_STATE */) {
2761
+ if (_optionalChain([serverMsg, 'optionalAccess', _29 => _29.type]) === 104 /* ROOM_STATE */) {
2746
2762
  didReceiveActor();
2747
2763
  }
2748
2764
  }
@@ -2851,12 +2867,12 @@ function createConnectionStateMachine(delegates, options) {
2851
2867
  const sendHeartbeat = {
2852
2868
  target: "@ok.awaiting-pong",
2853
2869
  effect: (ctx) => {
2854
- _optionalChain([ctx, 'access', _32 => _32.socket, 'optionalAccess', _33 => _33.send, 'call', _34 => _34("ping")]);
2870
+ _optionalChain([ctx, 'access', _30 => _30.socket, 'optionalAccess', _31 => _31.send, 'call', _32 => _32("ping")]);
2855
2871
  }
2856
2872
  };
2857
2873
  const maybeHeartbeat = () => {
2858
2874
  const doc = typeof document !== "undefined" ? document : void 0;
2859
- const canZombie = _optionalChain([doc, 'optionalAccess', _35 => _35.visibilityState]) === "hidden" && delegates.canZombie();
2875
+ const canZombie = _optionalChain([doc, 'optionalAccess', _33 => _33.visibilityState]) === "hidden" && delegates.canZombie();
2860
2876
  return canZombie ? "@idle.zombie" : sendHeartbeat;
2861
2877
  };
2862
2878
  machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
@@ -2895,7 +2911,7 @@ function createConnectionStateMachine(delegates, options) {
2895
2911
  // socket, or not. So always check to see if the socket is still OPEN or
2896
2912
  // not. When still OPEN, don't transition.
2897
2913
  EXPLICIT_SOCKET_ERROR: (_, context) => {
2898
- if (_optionalChain([context, 'access', _36 => _36.socket, 'optionalAccess', _37 => _37.readyState]) === 1) {
2914
+ if (_optionalChain([context, 'access', _34 => _34.socket, 'optionalAccess', _35 => _35.readyState]) === 1) {
2899
2915
  return null;
2900
2916
  }
2901
2917
  return {
@@ -2947,17 +2963,17 @@ function createConnectionStateMachine(delegates, options) {
2947
2963
  machine.send({ type: "NAVIGATOR_ONLINE" });
2948
2964
  }
2949
2965
  function onVisibilityChange() {
2950
- if (_optionalChain([doc, 'optionalAccess', _38 => _38.visibilityState]) === "visible") {
2966
+ if (_optionalChain([doc, 'optionalAccess', _36 => _36.visibilityState]) === "visible") {
2951
2967
  machine.send({ type: "WINDOW_GOT_FOCUS" });
2952
2968
  }
2953
2969
  }
2954
- _optionalChain([win, 'optionalAccess', _39 => _39.addEventListener, 'call', _40 => _40("online", onNetworkBackOnline)]);
2955
- _optionalChain([win, 'optionalAccess', _41 => _41.addEventListener, 'call', _42 => _42("offline", onNetworkOffline)]);
2956
- _optionalChain([root, 'optionalAccess', _43 => _43.addEventListener, 'call', _44 => _44("visibilitychange", onVisibilityChange)]);
2970
+ _optionalChain([win, 'optionalAccess', _37 => _37.addEventListener, 'call', _38 => _38("online", onNetworkBackOnline)]);
2971
+ _optionalChain([win, 'optionalAccess', _39 => _39.addEventListener, 'call', _40 => _40("offline", onNetworkOffline)]);
2972
+ _optionalChain([root, 'optionalAccess', _41 => _41.addEventListener, 'call', _42 => _42("visibilitychange", onVisibilityChange)]);
2957
2973
  return () => {
2958
- _optionalChain([root, 'optionalAccess', _45 => _45.removeEventListener, 'call', _46 => _46("visibilitychange", onVisibilityChange)]);
2959
- _optionalChain([win, 'optionalAccess', _47 => _47.removeEventListener, 'call', _48 => _48("online", onNetworkBackOnline)]);
2960
- _optionalChain([win, 'optionalAccess', _49 => _49.removeEventListener, 'call', _50 => _50("offline", onNetworkOffline)]);
2974
+ _optionalChain([root, 'optionalAccess', _43 => _43.removeEventListener, 'call', _44 => _44("visibilitychange", onVisibilityChange)]);
2975
+ _optionalChain([win, 'optionalAccess', _45 => _45.removeEventListener, 'call', _46 => _46("online", onNetworkBackOnline)]);
2976
+ _optionalChain([win, 'optionalAccess', _47 => _47.removeEventListener, 'call', _48 => _48("offline", onNetworkOffline)]);
2961
2977
  teardownSocket(ctx.socket);
2962
2978
  };
2963
2979
  });
@@ -2978,7 +2994,7 @@ function createConnectionStateMachine(delegates, options) {
2978
2994
  didConnect,
2979
2995
  didDisconnect,
2980
2996
  onMessage: onMessage.observable,
2981
- onConnectionError: onConnectionError.observable
2997
+ onLiveblocksError: onLiveblocksError.observable
2982
2998
  }
2983
2999
  };
2984
3000
  }
@@ -2998,7 +3014,7 @@ var ManagedSocket = class {
2998
3014
  getStatus() {
2999
3015
  try {
3000
3016
  return toNewConnectionStatus(this.#machine);
3001
- } catch (e5) {
3017
+ } catch (e4) {
3002
3018
  return "initial";
3003
3019
  }
3004
3020
  }
@@ -3046,7 +3062,7 @@ var ManagedSocket = class {
3046
3062
  * message if this is somehow impossible.
3047
3063
  */
3048
3064
  send(data) {
3049
- const socket = _optionalChain([this, 'access', _51 => _51.#machine, 'access', _52 => _52.context, 'optionalAccess', _53 => _53.socket]);
3065
+ const socket = _optionalChain([this, 'access', _49 => _49.#machine, 'access', _50 => _50.context, 'optionalAccess', _51 => _51.socket]);
3050
3066
  if (socket === null) {
3051
3067
  warn("Cannot send: not connected yet", data);
3052
3068
  } else if (socket.readyState !== 1) {
@@ -3150,7 +3166,7 @@ function createAuthManager(authOptions, onAuthenticate) {
3150
3166
  return void 0;
3151
3167
  }
3152
3168
  async function makeAuthRequest(options) {
3153
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _54 => _54.polyfills, 'optionalAccess', _55 => _55.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
3169
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _52 => _52.polyfills, 'optionalAccess', _53 => _53.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
3154
3170
  if (authentication.type === "private") {
3155
3171
  if (fetcher === void 0) {
3156
3172
  throw new StopRetrying(
@@ -3166,7 +3182,7 @@ function createAuthManager(authOptions, onAuthenticate) {
3166
3182
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
3167
3183
  );
3168
3184
  }
3169
- _optionalChain([onAuthenticate, 'optionalCall', _56 => _56(parsed.parsed)]);
3185
+ _optionalChain([onAuthenticate, 'optionalCall', _54 => _54(parsed.parsed)]);
3170
3186
  return parsed;
3171
3187
  }
3172
3188
  if (authentication.type === "custom") {
@@ -3174,7 +3190,7 @@ function createAuthManager(authOptions, onAuthenticate) {
3174
3190
  if (response && typeof response === "object") {
3175
3191
  if (typeof response.token === "string") {
3176
3192
  const parsed = parseAuthToken(response.token);
3177
- _optionalChain([onAuthenticate, 'optionalCall', _57 => _57(parsed.parsed)]);
3193
+ _optionalChain([onAuthenticate, 'optionalCall', _55 => _55(parsed.parsed)]);
3178
3194
  return parsed;
3179
3195
  } else if (typeof response.error === "string") {
3180
3196
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -3335,7 +3351,7 @@ function sendToPanel(message, options) {
3335
3351
  ...message,
3336
3352
  source: "liveblocks-devtools-client"
3337
3353
  };
3338
- if (!(_optionalChain([options, 'optionalAccess', _58 => _58.force]) || _bridgeActive)) {
3354
+ if (!(_optionalChain([options, 'optionalAccess', _56 => _56.force]) || _bridgeActive)) {
3339
3355
  return;
3340
3356
  }
3341
3357
  window.postMessage(fullMsg, "*");
@@ -3343,7 +3359,7 @@ function sendToPanel(message, options) {
3343
3359
  var eventSource = makeEventSource();
3344
3360
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
3345
3361
  window.addEventListener("message", (event) => {
3346
- if (event.source === window && _optionalChain([event, 'access', _59 => _59.data, 'optionalAccess', _60 => _60.source]) === "liveblocks-devtools-panel") {
3362
+ if (event.source === window && _optionalChain([event, 'access', _57 => _57.data, 'optionalAccess', _58 => _58.source]) === "liveblocks-devtools-panel") {
3347
3363
  eventSource.notify(event.data);
3348
3364
  } else {
3349
3365
  }
@@ -3485,7 +3501,7 @@ function fullSync(room) {
3485
3501
  msg: "room::sync::full",
3486
3502
  roomId: room.id,
3487
3503
  status: room.getStatus(),
3488
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _61 => _61.toTreeNode, 'call', _62 => _62("root"), 'access', _63 => _63.payload]), () => ( null)),
3504
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _59 => _59.toTreeNode, 'call', _60 => _60("root"), 'access', _61 => _61.payload]), () => ( null)),
3489
3505
  me,
3490
3506
  others
3491
3507
  });
@@ -3909,7 +3925,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
3909
3925
  return [
3910
3926
  {
3911
3927
  type: 8 /* CREATE_REGISTER */,
3912
- opId: _optionalChain([pool, 'optionalAccess', _64 => _64.generateOpId, 'call', _65 => _65()]),
3928
+ opId: _optionalChain([pool, 'optionalAccess', _62 => _62.generateOpId, 'call', _63 => _63()]),
3913
3929
  id: this._id,
3914
3930
  parentId,
3915
3931
  parentKey,
@@ -4015,7 +4031,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4015
4031
  const ops = [];
4016
4032
  const op = {
4017
4033
  id: this._id,
4018
- opId: _optionalChain([pool, 'optionalAccess', _66 => _66.generateOpId, 'call', _67 => _67()]),
4034
+ opId: _optionalChain([pool, 'optionalAccess', _64 => _64.generateOpId, 'call', _65 => _65()]),
4019
4035
  type: 2 /* CREATE_LIST */,
4020
4036
  parentId,
4021
4037
  parentKey
@@ -4286,7 +4302,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4286
4302
  #applyInsertUndoRedo(op) {
4287
4303
  const { id, parentKey: key } = op;
4288
4304
  const child = creationOpToLiveNode(op);
4289
- if (_optionalChain([this, 'access', _68 => _68._pool, 'optionalAccess', _69 => _69.getNode, 'call', _70 => _70(id)]) !== void 0) {
4305
+ if (_optionalChain([this, 'access', _66 => _66._pool, 'optionalAccess', _67 => _67.getNode, 'call', _68 => _68(id)]) !== void 0) {
4290
4306
  return { modified: false };
4291
4307
  }
4292
4308
  child._attach(id, nn(this._pool));
@@ -4294,8 +4310,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
4294
4310
  const existingItemIndex = this._indexOfPosition(key);
4295
4311
  let newKey = key;
4296
4312
  if (existingItemIndex !== -1) {
4297
- const before2 = _optionalChain([this, 'access', _71 => _71.#items, 'access', _72 => _72[existingItemIndex], 'optionalAccess', _73 => _73._parentPos]);
4298
- const after2 = _optionalChain([this, 'access', _74 => _74.#items, 'access', _75 => _75[existingItemIndex + 1], 'optionalAccess', _76 => _76._parentPos]);
4313
+ const before2 = _optionalChain([this, 'access', _69 => _69.#items, 'access', _70 => _70[existingItemIndex], 'optionalAccess', _71 => _71._parentPos]);
4314
+ const after2 = _optionalChain([this, 'access', _72 => _72.#items, 'access', _73 => _73[existingItemIndex + 1], 'optionalAccess', _74 => _74._parentPos]);
4299
4315
  newKey = makePosition(before2, after2);
4300
4316
  child._setParentLink(this, newKey);
4301
4317
  }
@@ -4309,7 +4325,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4309
4325
  #applySetUndoRedo(op) {
4310
4326
  const { id, parentKey: key } = op;
4311
4327
  const child = creationOpToLiveNode(op);
4312
- if (_optionalChain([this, 'access', _77 => _77._pool, 'optionalAccess', _78 => _78.getNode, 'call', _79 => _79(id)]) !== void 0) {
4328
+ if (_optionalChain([this, 'access', _75 => _75._pool, 'optionalAccess', _76 => _76.getNode, 'call', _77 => _77(id)]) !== void 0) {
4313
4329
  return { modified: false };
4314
4330
  }
4315
4331
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -4430,7 +4446,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4430
4446
  } else {
4431
4447
  this.#items[existingItemIndex]._setParentLink(
4432
4448
  this,
4433
- makePosition(newKey, _optionalChain([this, 'access', _80 => _80.#items, 'access', _81 => _81[existingItemIndex + 1], 'optionalAccess', _82 => _82._parentPos]))
4449
+ makePosition(newKey, _optionalChain([this, 'access', _78 => _78.#items, 'access', _79 => _79[existingItemIndex + 1], 'optionalAccess', _80 => _80._parentPos]))
4434
4450
  );
4435
4451
  const previousIndex = this.#items.indexOf(child);
4436
4452
  child._setParentLink(this, newKey);
@@ -4455,7 +4471,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4455
4471
  if (existingItemIndex !== -1) {
4456
4472
  this.#items[existingItemIndex]._setParentLink(
4457
4473
  this,
4458
- makePosition(newKey, _optionalChain([this, 'access', _83 => _83.#items, 'access', _84 => _84[existingItemIndex + 1], 'optionalAccess', _85 => _85._parentPos]))
4474
+ makePosition(newKey, _optionalChain([this, 'access', _81 => _81.#items, 'access', _82 => _82[existingItemIndex + 1], 'optionalAccess', _83 => _83._parentPos]))
4459
4475
  );
4460
4476
  }
4461
4477
  child._setParentLink(this, newKey);
@@ -4474,7 +4490,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4474
4490
  if (existingItemIndex !== -1) {
4475
4491
  this.#items[existingItemIndex]._setParentLink(
4476
4492
  this,
4477
- makePosition(newKey, _optionalChain([this, 'access', _86 => _86.#items, 'access', _87 => _87[existingItemIndex + 1], 'optionalAccess', _88 => _88._parentPos]))
4493
+ makePosition(newKey, _optionalChain([this, 'access', _84 => _84.#items, 'access', _85 => _85[existingItemIndex + 1], 'optionalAccess', _86 => _86._parentPos]))
4478
4494
  );
4479
4495
  }
4480
4496
  child._setParentLink(this, newKey);
@@ -4501,7 +4517,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4501
4517
  if (existingItemIndex !== -1) {
4502
4518
  this.#items[existingItemIndex]._setParentLink(
4503
4519
  this,
4504
- makePosition(newKey, _optionalChain([this, 'access', _89 => _89.#items, 'access', _90 => _90[existingItemIndex + 1], 'optionalAccess', _91 => _91._parentPos]))
4520
+ makePosition(newKey, _optionalChain([this, 'access', _87 => _87.#items, 'access', _88 => _88[existingItemIndex + 1], 'optionalAccess', _89 => _89._parentPos]))
4505
4521
  );
4506
4522
  }
4507
4523
  child._setParentLink(this, newKey);
@@ -4559,7 +4575,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4559
4575
  * @param element The element to add to the end of the LiveList.
4560
4576
  */
4561
4577
  push(element) {
4562
- _optionalChain([this, 'access', _92 => _92._pool, 'optionalAccess', _93 => _93.assertStorageIsWritable, 'call', _94 => _94()]);
4578
+ _optionalChain([this, 'access', _90 => _90._pool, 'optionalAccess', _91 => _91.assertStorageIsWritable, 'call', _92 => _92()]);
4563
4579
  return this.insert(element, this.length);
4564
4580
  }
4565
4581
  /**
@@ -4568,7 +4584,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4568
4584
  * @param index The index at which you want to insert the element.
4569
4585
  */
4570
4586
  insert(element, index) {
4571
- _optionalChain([this, 'access', _95 => _95._pool, 'optionalAccess', _96 => _96.assertStorageIsWritable, 'call', _97 => _97()]);
4587
+ _optionalChain([this, 'access', _93 => _93._pool, 'optionalAccess', _94 => _94.assertStorageIsWritable, 'call', _95 => _95()]);
4572
4588
  if (index < 0 || index > this.#items.length) {
4573
4589
  throw new Error(
4574
4590
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -4598,7 +4614,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4598
4614
  * @param targetIndex The index where the element should be after moving.
4599
4615
  */
4600
4616
  move(index, targetIndex) {
4601
- _optionalChain([this, 'access', _98 => _98._pool, 'optionalAccess', _99 => _99.assertStorageIsWritable, 'call', _100 => _100()]);
4617
+ _optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.assertStorageIsWritable, 'call', _98 => _98()]);
4602
4618
  if (targetIndex < 0) {
4603
4619
  throw new Error("targetIndex cannot be less than 0");
4604
4620
  }
@@ -4656,7 +4672,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4656
4672
  * @param index The index of the element to delete
4657
4673
  */
4658
4674
  delete(index) {
4659
- _optionalChain([this, 'access', _101 => _101._pool, 'optionalAccess', _102 => _102.assertStorageIsWritable, 'call', _103 => _103()]);
4675
+ _optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.assertStorageIsWritable, 'call', _101 => _101()]);
4660
4676
  if (index < 0 || index >= this.#items.length) {
4661
4677
  throw new Error(
4662
4678
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -4689,7 +4705,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4689
4705
  }
4690
4706
  }
4691
4707
  clear() {
4692
- _optionalChain([this, 'access', _104 => _104._pool, 'optionalAccess', _105 => _105.assertStorageIsWritable, 'call', _106 => _106()]);
4708
+ _optionalChain([this, 'access', _102 => _102._pool, 'optionalAccess', _103 => _103.assertStorageIsWritable, 'call', _104 => _104()]);
4693
4709
  if (this._pool) {
4694
4710
  const ops = [];
4695
4711
  const reverseOps = [];
@@ -4723,7 +4739,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4723
4739
  }
4724
4740
  }
4725
4741
  set(index, item) {
4726
- _optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.assertStorageIsWritable, 'call', _109 => _109()]);
4742
+ _optionalChain([this, 'access', _105 => _105._pool, 'optionalAccess', _106 => _106.assertStorageIsWritable, 'call', _107 => _107()]);
4727
4743
  if (index < 0 || index >= this.#items.length) {
4728
4744
  throw new Error(
4729
4745
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -4869,7 +4885,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4869
4885
  #shiftItemPosition(index, key) {
4870
4886
  const shiftedPosition = makePosition(
4871
4887
  key,
4872
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[index + 1], 'optionalAccess', _112 => _112._parentPos]) : void 0
4888
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _108 => _108.#items, 'access', _109 => _109[index + 1], 'optionalAccess', _110 => _110._parentPos]) : void 0
4873
4889
  );
4874
4890
  this.#items[index]._setParentLink(this, shiftedPosition);
4875
4891
  }
@@ -4994,7 +5010,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
4994
5010
  const ops = [];
4995
5011
  const op = {
4996
5012
  id: this._id,
4997
- opId: _optionalChain([pool, 'optionalAccess', _113 => _113.generateOpId, 'call', _114 => _114()]),
5013
+ opId: _optionalChain([pool, 'optionalAccess', _111 => _111.generateOpId, 'call', _112 => _112()]),
4998
5014
  type: 7 /* CREATE_MAP */,
4999
5015
  parentId,
5000
5016
  parentKey
@@ -5129,7 +5145,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
5129
5145
  * @param value The value of the element to add. Should be serializable to JSON.
5130
5146
  */
5131
5147
  set(key, value) {
5132
- _optionalChain([this, 'access', _115 => _115._pool, 'optionalAccess', _116 => _116.assertStorageIsWritable, 'call', _117 => _117()]);
5148
+ _optionalChain([this, 'access', _113 => _113._pool, 'optionalAccess', _114 => _114.assertStorageIsWritable, 'call', _115 => _115()]);
5133
5149
  const oldValue = this.#map.get(key);
5134
5150
  if (oldValue) {
5135
5151
  oldValue._detach();
@@ -5175,7 +5191,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
5175
5191
  * @returns true if an element existed and has been removed, or false if the element does not exist.
5176
5192
  */
5177
5193
  delete(key) {
5178
- _optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.assertStorageIsWritable, 'call', _120 => _120()]);
5194
+ _optionalChain([this, 'access', _116 => _116._pool, 'optionalAccess', _117 => _117.assertStorageIsWritable, 'call', _118 => _118()]);
5179
5195
  const item = this.#map.get(key);
5180
5196
  if (item === void 0) {
5181
5197
  return false;
@@ -5354,7 +5370,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5354
5370
  if (this._id === void 0) {
5355
5371
  throw new Error("Cannot serialize item is not attached");
5356
5372
  }
5357
- const opId = _optionalChain([pool, 'optionalAccess', _121 => _121.generateOpId, 'call', _122 => _122()]);
5373
+ const opId = _optionalChain([pool, 'optionalAccess', _119 => _119.generateOpId, 'call', _120 => _120()]);
5358
5374
  const ops = [];
5359
5375
  const op = {
5360
5376
  type: 4 /* CREATE_OBJECT */,
@@ -5626,7 +5642,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5626
5642
  * @param value The value of the property to add
5627
5643
  */
5628
5644
  set(key, value) {
5629
- _optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.assertStorageIsWritable, 'call', _125 => _125()]);
5645
+ _optionalChain([this, 'access', _121 => _121._pool, 'optionalAccess', _122 => _122.assertStorageIsWritable, 'call', _123 => _123()]);
5630
5646
  this.update({ [key]: value });
5631
5647
  }
5632
5648
  /**
@@ -5641,7 +5657,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5641
5657
  * @param key The key of the property to delete
5642
5658
  */
5643
5659
  delete(key) {
5644
- _optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.assertStorageIsWritable, 'call', _128 => _128()]);
5660
+ _optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.assertStorageIsWritable, 'call', _126 => _126()]);
5645
5661
  const keyAsString = key;
5646
5662
  const oldValue = this.#map.get(keyAsString);
5647
5663
  if (oldValue === void 0) {
@@ -5694,7 +5710,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5694
5710
  * @param patch The object used to overrides properties
5695
5711
  */
5696
5712
  update(patch) {
5697
- _optionalChain([this, 'access', _129 => _129._pool, 'optionalAccess', _130 => _130.assertStorageIsWritable, 'call', _131 => _131()]);
5713
+ _optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.assertStorageIsWritable, 'call', _129 => _129()]);
5698
5714
  if (this._pool === void 0 || this._id === void 0) {
5699
5715
  for (const key in patch) {
5700
5716
  const newValue = patch[key];
@@ -6242,83 +6258,6 @@ var ManagedOthers = class {
6242
6258
  }
6243
6259
  };
6244
6260
 
6245
- // src/types/LiveblocksError.ts
6246
- var LiveblocksError = class _LiveblocksError extends Error {
6247
-
6248
- constructor(message, context, cause) {
6249
- super(message, { cause });
6250
- this.context = context;
6251
- this.name = "LiveblocksError";
6252
- }
6253
- /** Convenience accessor for error.context.roomId (if available) */
6254
- get roomId() {
6255
- return this.context.roomId;
6256
- }
6257
- /** @deprecated Prefer using `context.code` instead, to enable type narrowing */
6258
- get code() {
6259
- return this.context.code;
6260
- }
6261
- /**
6262
- * Creates a LiveblocksError from a generic error, by attaching Liveblocks
6263
- * contextual information like room ID, thread ID, etc.
6264
- */
6265
- static from(context, cause) {
6266
- return new _LiveblocksError(
6267
- defaultMessageFromContext(context),
6268
- context,
6269
- cause
6270
- );
6271
- }
6272
- };
6273
- function defaultMessageFromContext(context) {
6274
- switch (context.type) {
6275
- case "ROOM_CONNECTION_ERROR": {
6276
- switch (context.code) {
6277
- case 4001:
6278
- return "Not allowed to connect to the room";
6279
- case 4005:
6280
- return "Room is already full";
6281
- case 4006:
6282
- return "Kicked out of the room, because the room ID changed";
6283
- default:
6284
- return "Could not connect to the room";
6285
- }
6286
- }
6287
- case "CREATE_THREAD_ERROR":
6288
- return "Could not create new thread";
6289
- case "DELETE_THREAD_ERROR":
6290
- return "Could not delete thread";
6291
- case "EDIT_THREAD_METADATA_ERROR":
6292
- return "Could not edit thread metadata";
6293
- case "MARK_THREAD_AS_RESOLVED_ERROR":
6294
- return "Could not mark thread as resolved";
6295
- case "MARK_THREAD_AS_UNRESOLVED_ERROR":
6296
- return "Could not mark thread as unresolved";
6297
- case "CREATE_COMMENT_ERROR":
6298
- return "Could not create new comment";
6299
- case "EDIT_COMMENT_ERROR":
6300
- return "Could not edit comment";
6301
- case "DELETE_COMMENT_ERROR":
6302
- return "Could not delete comment";
6303
- case "ADD_REACTION_ERROR":
6304
- return "Could not add reaction";
6305
- case "REMOVE_REACTION_ERROR":
6306
- return "Could not remove reaction";
6307
- case "MARK_INBOX_NOTIFICATION_AS_READ_ERROR":
6308
- return "Could not mark inbox notification as read";
6309
- case "DELETE_INBOX_NOTIFICATION_ERROR":
6310
- return "Could not delete inbox notification";
6311
- case "MARK_ALL_INBOX_NOTIFICATIONS_AS_READ_ERROR":
6312
- return "Could not mark all inbox notifications as read";
6313
- case "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR":
6314
- return "Could not delete all inbox notifications";
6315
- case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
6316
- return "Could not update notification settings";
6317
- default:
6318
- return assertNever(context, "Unhandled case");
6319
- }
6320
- }
6321
-
6322
6261
  // src/room.ts
6323
6262
  var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 1024;
6324
6263
  function makeIdFactory(connectionId) {
@@ -6343,15 +6282,15 @@ function installBackgroundTabSpy() {
6343
6282
  const doc = typeof document !== "undefined" ? document : void 0;
6344
6283
  const inBackgroundSince = { current: null };
6345
6284
  function onVisibilityChange() {
6346
- if (_optionalChain([doc, 'optionalAccess', _132 => _132.visibilityState]) === "hidden") {
6285
+ if (_optionalChain([doc, 'optionalAccess', _130 => _130.visibilityState]) === "hidden") {
6347
6286
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
6348
6287
  } else {
6349
6288
  inBackgroundSince.current = null;
6350
6289
  }
6351
6290
  }
6352
- _optionalChain([doc, 'optionalAccess', _133 => _133.addEventListener, 'call', _134 => _134("visibilitychange", onVisibilityChange)]);
6291
+ _optionalChain([doc, 'optionalAccess', _131 => _131.addEventListener, 'call', _132 => _132("visibilitychange", onVisibilityChange)]);
6353
6292
  const unsub = () => {
6354
- _optionalChain([doc, 'optionalAccess', _135 => _135.removeEventListener, 'call', _136 => _136("visibilitychange", onVisibilityChange)]);
6293
+ _optionalChain([doc, 'optionalAccess', _133 => _133.removeEventListener, 'call', _134 => _134("visibilitychange", onVisibilityChange)]);
6355
6294
  };
6356
6295
  return [inBackgroundSince, unsub];
6357
6296
  }
@@ -6483,17 +6422,13 @@ function createRoom(options, config) {
6483
6422
  managedSocket.events.statusDidChange.subscribe(handleConnectionLossEvent);
6484
6423
  managedSocket.events.didConnect.subscribe(onDidConnect);
6485
6424
  managedSocket.events.didDisconnect.subscribe(onDidDisconnect);
6486
- managedSocket.events.onConnectionError.subscribe(({ message, code }) => {
6487
- const type = "ROOM_CONNECTION_ERROR";
6488
- const err = new LiveblocksError(message, { type, code, roomId });
6489
- const didNotify = config.errorEventSource.notify(err);
6490
- if (!didNotify) {
6491
- if (process.env.NODE_ENV !== "production") {
6492
- error2(
6493
- `Connection to websocket server closed. Reason: ${message} (code: ${code}).`
6494
- );
6495
- }
6425
+ managedSocket.events.onLiveblocksError.subscribe((err) => {
6426
+ if (process.env.NODE_ENV !== "production") {
6427
+ error2(
6428
+ `Connection to websocket server closed. Reason: ${err.message} (code: ${err.code}).`
6429
+ );
6496
6430
  }
6431
+ eventHub.error.notify(err);
6497
6432
  });
6498
6433
  const pool = {
6499
6434
  roomId: config.roomId,
@@ -6536,7 +6471,7 @@ function createRoom(options, config) {
6536
6471
  }
6537
6472
  },
6538
6473
  assertStorageIsWritable: () => {
6539
- const scopes = _optionalChain([context, 'access', _137 => _137.dynamicSessionInfoSig, 'access', _138 => _138.get, 'call', _139 => _139(), 'optionalAccess', _140 => _140.scopes]);
6474
+ const scopes = _optionalChain([context, 'access', _135 => _135.dynamicSessionInfoSig, 'access', _136 => _136.get, 'call', _137 => _137(), 'optionalAccess', _138 => _138.scopes]);
6540
6475
  if (scopes === void 0) {
6541
6476
  return;
6542
6477
  }
@@ -6556,6 +6491,7 @@ function createRoom(options, config) {
6556
6491
  self: makeEventSource(),
6557
6492
  myPresence: makeEventSource(),
6558
6493
  others: makeEventSource(),
6494
+ error: makeEventSource(),
6559
6495
  storageBatch: makeEventSource(),
6560
6496
  history: makeEventSource(),
6561
6497
  storageDidLoad: makeEventSource(),
@@ -6589,9 +6525,15 @@ function createRoom(options, config) {
6589
6525
  async function createTextVersion() {
6590
6526
  return httpClient.createTextVersion({ roomId });
6591
6527
  }
6528
+ async function executeContextualPrompt(options2) {
6529
+ return httpClient.executeContextualPrompt({
6530
+ roomId,
6531
+ ...options2
6532
+ });
6533
+ }
6592
6534
  function sendMessages(messages) {
6593
6535
  const serializedPayload = JSON.stringify(messages);
6594
- const nonce = _optionalChain([context, 'access', _141 => _141.dynamicSessionInfoSig, 'access', _142 => _142.get, 'call', _143 => _143(), 'optionalAccess', _144 => _144.nonce]);
6536
+ const nonce = _optionalChain([context, 'access', _139 => _139.dynamicSessionInfoSig, 'access', _140 => _140.get, 'call', _141 => _141(), 'optionalAccess', _142 => _142.nonce]);
6595
6537
  if (config.unstable_fallbackToHTTP && nonce) {
6596
6538
  const size = new TextEncoder().encode(serializedPayload).length;
6597
6539
  if (size > MAX_SOCKET_MESSAGE_SIZE) {
@@ -6649,7 +6591,7 @@ function createRoom(options, config) {
6649
6591
  } else {
6650
6592
  context.root = LiveObject._fromItems(message.items, pool);
6651
6593
  }
6652
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _145 => _145.get, 'call', _146 => _146(), 'optionalAccess', _147 => _147.canWrite]), () => ( true));
6594
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _143 => _143.get, 'call', _144 => _144(), 'optionalAccess', _145 => _145.canWrite]), () => ( true));
6653
6595
  const stackSizeBefore = context.undoStack.length;
6654
6596
  for (const key in context.initialStorage) {
6655
6597
  if (context.root.get(key) === void 0) {
@@ -6852,7 +6794,7 @@ function createRoom(options, config) {
6852
6794
  }
6853
6795
  context.myPresence.patch(patch);
6854
6796
  if (context.activeBatch) {
6855
- if (_optionalChain([options2, 'optionalAccess', _148 => _148.addToHistory])) {
6797
+ if (_optionalChain([options2, 'optionalAccess', _146 => _146.addToHistory])) {
6856
6798
  context.activeBatch.reverseOps.unshift({
6857
6799
  type: "presence",
6858
6800
  data: oldValues
@@ -6861,7 +6803,7 @@ function createRoom(options, config) {
6861
6803
  context.activeBatch.updates.presence = true;
6862
6804
  } else {
6863
6805
  flushNowOrSoon();
6864
- if (_optionalChain([options2, 'optionalAccess', _149 => _149.addToHistory])) {
6806
+ if (_optionalChain([options2, 'optionalAccess', _147 => _147.addToHistory])) {
6865
6807
  addToUndoStack([{ type: "presence", data: oldValues }]);
6866
6808
  }
6867
6809
  notify({ presence: true });
@@ -7058,7 +7000,7 @@ function createRoom(options, config) {
7058
7000
  if (process.env.NODE_ENV !== "production") {
7059
7001
  const traces = /* @__PURE__ */ new Set();
7060
7002
  for (const opId of message.opIds) {
7061
- const trace = _optionalChain([context, 'access', _150 => _150.opStackTraces, 'optionalAccess', _151 => _151.get, 'call', _152 => _152(opId)]);
7003
+ const trace = _optionalChain([context, 'access', _148 => _148.opStackTraces, 'optionalAccess', _149 => _149.get, 'call', _150 => _150(opId)]);
7062
7004
  if (trace) {
7063
7005
  traces.add(trace);
7064
7006
  }
@@ -7192,7 +7134,7 @@ ${Array.from(traces).join("\n\n")}`
7192
7134
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
7193
7135
  createOrUpdateRootFromMessage(message);
7194
7136
  applyAndSendOps(unacknowledgedOps);
7195
- _optionalChain([_resolveStoragePromise, 'optionalCall', _153 => _153()]);
7137
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _151 => _151()]);
7196
7138
  notifyStorageStatus();
7197
7139
  eventHub.storageDidLoad.notify();
7198
7140
  }
@@ -7395,6 +7337,7 @@ ${Array.from(traces).join("\n\n")}`
7395
7337
  others: eventHub.others.observable,
7396
7338
  self: eventHub.self.observable,
7397
7339
  myPresence: eventHub.myPresence.observable,
7340
+ error: eventHub.error.observable,
7398
7341
  /** @deprecated */
7399
7342
  storage: eventHub.storageBatch.observable,
7400
7343
  storageBatch: eventHub.storageBatch.observable,
@@ -7414,8 +7357,8 @@ ${Array.from(traces).join("\n\n")}`
7414
7357
  async function getThreads(options2) {
7415
7358
  return httpClient.getThreads({
7416
7359
  roomId,
7417
- query: _optionalChain([options2, 'optionalAccess', _154 => _154.query]),
7418
- cursor: _optionalChain([options2, 'optionalAccess', _155 => _155.cursor])
7360
+ query: _optionalChain([options2, 'optionalAccess', _152 => _152.query]),
7361
+ cursor: _optionalChain([options2, 'optionalAccess', _153 => _153.cursor])
7419
7362
  });
7420
7363
  }
7421
7364
  async function getThread(threadId) {
@@ -7516,7 +7459,7 @@ ${Array.from(traces).join("\n\n")}`
7516
7459
  function getNotificationSettings(options2) {
7517
7460
  return httpClient.getNotificationSettings({
7518
7461
  roomId,
7519
- signal: _optionalChain([options2, 'optionalAccess', _156 => _156.signal])
7462
+ signal: _optionalChain([options2, 'optionalAccess', _154 => _154.signal])
7520
7463
  });
7521
7464
  }
7522
7465
  function updateNotificationSettings(settings) {
@@ -7538,7 +7481,7 @@ ${Array.from(traces).join("\n\n")}`
7538
7481
  {
7539
7482
  [kInternal]: {
7540
7483
  get presenceBuffer() {
7541
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _157 => _157.buffer, 'access', _158 => _158.presenceUpdates, 'optionalAccess', _159 => _159.data]), () => ( null)));
7484
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _155 => _155.buffer, 'access', _156 => _156.presenceUpdates, 'optionalAccess', _157 => _157.data]), () => ( null)));
7542
7485
  },
7543
7486
  // prettier-ignore
7544
7487
  get undoStack() {
@@ -7553,9 +7496,9 @@ ${Array.from(traces).join("\n\n")}`
7553
7496
  return context.yjsProvider;
7554
7497
  },
7555
7498
  setYjsProvider(newProvider) {
7556
- _optionalChain([context, 'access', _160 => _160.yjsProvider, 'optionalAccess', _161 => _161.off, 'call', _162 => _162("status", yjsStatusDidChange)]);
7499
+ _optionalChain([context, 'access', _158 => _158.yjsProvider, 'optionalAccess', _159 => _159.off, 'call', _160 => _160("status", yjsStatusDidChange)]);
7557
7500
  context.yjsProvider = newProvider;
7558
- _optionalChain([newProvider, 'optionalAccess', _163 => _163.on, 'call', _164 => _164("status", yjsStatusDidChange)]);
7501
+ _optionalChain([newProvider, 'optionalAccess', _161 => _161.on, 'call', _162 => _162("status", yjsStatusDidChange)]);
7559
7502
  context.yjsProviderDidChange.notify();
7560
7503
  },
7561
7504
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -7573,6 +7516,8 @@ ${Array.from(traces).join("\n\n")}`
7573
7516
  getTextVersion,
7574
7517
  // create a version
7575
7518
  createTextVersion,
7519
+ // execute contextual prompt
7520
+ executeContextualPrompt,
7576
7521
  // Support for the Liveblocks browser extension
7577
7522
  getSelf_forDevTools: () => selfAsTreeNode.get(),
7578
7523
  getOthers_forDevTools: () => others_forDevTools.get(),
@@ -7585,17 +7530,13 @@ ${Array.from(traces).join("\n\n")}`
7585
7530
  attachmentUrlsStore: httpClient.getOrCreateAttachmentUrlsStore(roomId)
7586
7531
  },
7587
7532
  id: config.roomId,
7588
- subscribe: makeClassicSubscribeFn(
7589
- config.roomId,
7590
- events,
7591
- config.errorEventSource
7592
- ),
7533
+ subscribe: makeClassicSubscribeFn(events),
7593
7534
  connect: () => managedSocket.connect(),
7594
7535
  reconnect: () => managedSocket.reconnect(),
7595
7536
  disconnect: () => managedSocket.disconnect(),
7596
7537
  destroy: () => {
7597
7538
  syncSourceForStorage.destroy();
7598
- _optionalChain([context, 'access', _165 => _165.yjsProvider, 'optionalAccess', _166 => _166.off, 'call', _167 => _167("status", yjsStatusDidChange)]);
7539
+ _optionalChain([context, 'access', _163 => _163.yjsProvider, 'optionalAccess', _164 => _164.off, 'call', _165 => _165("status", yjsStatusDidChange)]);
7599
7540
  syncSourceForYjs.destroy();
7600
7541
  uninstallBgTabSpy();
7601
7542
  managedSocket.destroy();
@@ -7658,7 +7599,7 @@ ${Array.from(traces).join("\n\n")}`
7658
7599
  { enumerable: false }
7659
7600
  );
7660
7601
  }
7661
- function makeClassicSubscribeFn(roomId, events, errorEvents) {
7602
+ function makeClassicSubscribeFn(events) {
7662
7603
  function subscribeToLiveStructureDeeply(node, callback) {
7663
7604
  return events.storageBatch.subscribe((updates) => {
7664
7605
  const relatedUpdates = updates.filter(
@@ -7698,13 +7639,8 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
7698
7639
  return cb(others, internalEvent);
7699
7640
  });
7700
7641
  }
7701
- case "error": {
7702
- return errorEvents.subscribe((err) => {
7703
- if (err.roomId === roomId) {
7704
- return callback(err);
7705
- }
7706
- });
7707
- }
7642
+ case "error":
7643
+ return events.error.subscribe(callback);
7708
7644
  case "status":
7709
7645
  return events.status.subscribe(callback);
7710
7646
  case "lost-connection":
@@ -7739,7 +7675,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
7739
7675
  }
7740
7676
  if (isLiveNode(first)) {
7741
7677
  const node = first;
7742
- if (_optionalChain([options, 'optionalAccess', _168 => _168.isDeep])) {
7678
+ if (_optionalChain([options, 'optionalAccess', _166 => _166.isDeep])) {
7743
7679
  const storageCallback = second;
7744
7680
  return subscribeToLiveStructureDeeply(node, storageCallback);
7745
7681
  } else {
@@ -7818,8 +7754,8 @@ function createClient(options) {
7818
7754
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
7819
7755
  currentUserId.set(() => userId);
7820
7756
  });
7821
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _169 => _169.polyfills, 'optionalAccess', _170 => _170.fetch]) || /* istanbul ignore next */
7822
- _optionalChain([globalThis, 'access', _171 => _171.fetch, 'optionalAccess', _172 => _172.bind, 'call', _173 => _173(globalThis)]);
7757
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _167 => _167.polyfills, 'optionalAccess', _168 => _168.fetch]) || /* istanbul ignore next */
7758
+ _optionalChain([globalThis, 'access', _169 => _169.fetch, 'optionalAccess', _170 => _170.bind, 'call', _171 => _171(globalThis)]);
7823
7759
  const httpClient = createApiClient({
7824
7760
  baseUrl,
7825
7761
  fetchPolyfill,
@@ -7870,13 +7806,12 @@ function createClient(options) {
7870
7806
  createSocket: makeCreateSocketDelegateForRoom(
7871
7807
  roomId,
7872
7808
  baseUrl,
7873
- _optionalChain([clientOptions, 'access', _174 => _174.polyfills, 'optionalAccess', _175 => _175.WebSocket])
7809
+ _optionalChain([clientOptions, 'access', _172 => _172.polyfills, 'optionalAccess', _173 => _173.WebSocket])
7874
7810
  ),
7875
7811
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
7876
7812
  })),
7877
7813
  enableDebugLogging: clientOptions.enableDebugLogging,
7878
7814
  baseUrl,
7879
- errorEventSource: liveblocksErrorSource,
7880
7815
  unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
7881
7816
  unstable_streamData: !!clientOptions.unstable_streamData,
7882
7817
  roomHttpClient: httpClient,
@@ -7893,7 +7828,7 @@ function createClient(options) {
7893
7828
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
7894
7829
  if (shouldConnect) {
7895
7830
  if (typeof atob === "undefined") {
7896
- if (_optionalChain([clientOptions, 'access', _176 => _176.polyfills, 'optionalAccess', _177 => _177.atob]) === void 0) {
7831
+ if (_optionalChain([clientOptions, 'access', _174 => _174.polyfills, 'optionalAccess', _175 => _175.atob]) === void 0) {
7897
7832
  throw new Error(
7898
7833
  "You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
7899
7834
  );
@@ -7905,7 +7840,7 @@ function createClient(options) {
7905
7840
  return leaseRoom(newRoomDetails);
7906
7841
  }
7907
7842
  function getRoom(roomId) {
7908
- const room = _optionalChain([roomsById, 'access', _178 => _178.get, 'call', _179 => _179(roomId), 'optionalAccess', _180 => _180.room]);
7843
+ const room = _optionalChain([roomsById, 'access', _176 => _176.get, 'call', _177 => _177(roomId), 'optionalAccess', _178 => _178.room]);
7909
7844
  return room ? room : null;
7910
7845
  }
7911
7846
  function logout() {
@@ -7925,7 +7860,7 @@ function createClient(options) {
7925
7860
  const batchedResolveUsers = new Batch(
7926
7861
  async (batchedUserIds) => {
7927
7862
  const userIds = batchedUserIds.flat();
7928
- const users = await _optionalChain([resolveUsers, 'optionalCall', _181 => _181({ userIds })]);
7863
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _179 => _179({ userIds })]);
7929
7864
  warnIfNoResolveUsers();
7930
7865
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
7931
7866
  },
@@ -7943,7 +7878,7 @@ function createClient(options) {
7943
7878
  const batchedResolveRoomsInfo = new Batch(
7944
7879
  async (batchedRoomIds) => {
7945
7880
  const roomIds = batchedRoomIds.flat();
7946
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _182 => _182({ roomIds })]);
7881
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _180 => _180({ roomIds })]);
7947
7882
  warnIfNoResolveRoomsInfo();
7948
7883
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
7949
7884
  },
@@ -7959,7 +7894,6 @@ function createClient(options) {
7959
7894
  }
7960
7895
  const syncStatusSources = [];
7961
7896
  const syncStatusSignal = new Signal("synchronized");
7962
- const liveblocksErrorSource = makeEventSource();
7963
7897
  function getSyncStatus() {
7964
7898
  const status = syncStatusSignal.get();
7965
7899
  return status === "synchronizing" ? status : "synchronized";
@@ -7996,7 +7930,7 @@ function createClient(options) {
7996
7930
  }
7997
7931
  };
7998
7932
  const win = typeof window !== "undefined" ? window : void 0;
7999
- _optionalChain([win, 'optionalAccess', _183 => _183.addEventListener, 'call', _184 => _184("beforeunload", maybePreventClose)]);
7933
+ _optionalChain([win, 'optionalAccess', _181 => _181.addEventListener, 'call', _182 => _182("beforeunload", maybePreventClose)]);
8000
7934
  }
8001
7935
  const client = Object.defineProperty(
8002
7936
  {
@@ -8019,7 +7953,6 @@ function createClient(options) {
8019
7953
  },
8020
7954
  getSyncStatus,
8021
7955
  events: {
8022
- error: liveblocksErrorSource,
8023
7956
  syncStatus: syncStatusSignal
8024
7957
  },
8025
7958
  // Internal
@@ -8035,14 +7968,7 @@ function createClient(options) {
8035
7968
  httpClient,
8036
7969
  // Type-level helper only, it's effectively only an identity-function at runtime
8037
7970
  as: () => client,
8038
- createSyncSource,
8039
- emitError: (context, cause) => {
8040
- const error3 = LiveblocksError.from(context, cause);
8041
- const didNotify = liveblocksErrorSource.notify(error3);
8042
- if (!didNotify) {
8043
- error2(error3.message);
8044
- }
8045
- }
7971
+ createSyncSource
8046
7972
  }
8047
7973
  },
8048
7974
  kInternal,
@@ -8121,7 +8047,7 @@ var commentBodyElementsTypes = {
8121
8047
  mention: "inline"
8122
8048
  };
8123
8049
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
8124
- if (!body || !_optionalChain([body, 'optionalAccess', _185 => _185.content])) {
8050
+ if (!body || !_optionalChain([body, 'optionalAccess', _183 => _183.content])) {
8125
8051
  return;
8126
8052
  }
8127
8053
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -8131,13 +8057,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
8131
8057
  for (const block of body.content) {
8132
8058
  if (type === "all" || type === "block") {
8133
8059
  if (guard(block)) {
8134
- _optionalChain([visitor, 'optionalCall', _186 => _186(block)]);
8060
+ _optionalChain([visitor, 'optionalCall', _184 => _184(block)]);
8135
8061
  }
8136
8062
  }
8137
8063
  if (type === "all" || type === "inline") {
8138
8064
  for (const inline of block.children) {
8139
8065
  if (guard(inline)) {
8140
- _optionalChain([visitor, 'optionalCall', _187 => _187(inline)]);
8066
+ _optionalChain([visitor, 'optionalCall', _185 => _185(inline)]);
8141
8067
  }
8142
8068
  }
8143
8069
  }
@@ -8162,7 +8088,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
8162
8088
  userIds
8163
8089
  });
8164
8090
  for (const [index, userId] of userIds.entries()) {
8165
- const user = _optionalChain([users, 'optionalAccess', _188 => _188[index]]);
8091
+ const user = _optionalChain([users, 'optionalAccess', _186 => _186[index]]);
8166
8092
  if (user) {
8167
8093
  resolvedUsers.set(userId, user);
8168
8094
  }
@@ -8289,7 +8215,7 @@ var stringifyCommentBodyPlainElements = {
8289
8215
  text: ({ element }) => element.text,
8290
8216
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
8291
8217
  mention: ({ element, user }) => {
8292
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _189 => _189.name]), () => ( element.id))}`;
8218
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _187 => _187.name]), () => ( element.id))}`;
8293
8219
  }
8294
8220
  };
8295
8221
  var stringifyCommentBodyHtmlElements = {
@@ -8319,7 +8245,7 @@ var stringifyCommentBodyHtmlElements = {
8319
8245
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${_nullishCoalesce(element.text, () => ( element.url))}</a>`;
8320
8246
  },
8321
8247
  mention: ({ element, user }) => {
8322
- return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _190 => _190.name]), () => ( element.id))}</span>`;
8248
+ return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _188 => _188.name]), () => ( element.id))}</span>`;
8323
8249
  }
8324
8250
  };
8325
8251
  var stringifyCommentBodyMarkdownElements = {
@@ -8349,19 +8275,19 @@ var stringifyCommentBodyMarkdownElements = {
8349
8275
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
8350
8276
  },
8351
8277
  mention: ({ element, user }) => {
8352
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _191 => _191.name]), () => ( element.id))}`;
8278
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _189 => _189.name]), () => ( element.id))}`;
8353
8279
  }
8354
8280
  };
8355
8281
  async function stringifyCommentBody(body, options) {
8356
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _192 => _192.format]), () => ( "plain"));
8357
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _193 => _193.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
8282
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _190 => _190.format]), () => ( "plain"));
8283
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _191 => _191.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
8358
8284
  const elements = {
8359
8285
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
8360
- ..._optionalChain([options, 'optionalAccess', _194 => _194.elements])
8286
+ ..._optionalChain([options, 'optionalAccess', _192 => _192.elements])
8361
8287
  };
8362
8288
  const resolvedUsers = await resolveUsersInCommentBody(
8363
8289
  body,
8364
- _optionalChain([options, 'optionalAccess', _195 => _195.resolveUsers])
8290
+ _optionalChain([options, 'optionalAccess', _193 => _193.resolveUsers])
8365
8291
  );
8366
8292
  const blocks = body.content.flatMap((block, blockIndex) => {
8367
8293
  switch (block.type) {
@@ -8652,12 +8578,12 @@ function legacy_patchImmutableNode(state, path, update) {
8652
8578
  }
8653
8579
  const newState = Object.assign({}, state);
8654
8580
  for (const key in update.updates) {
8655
- if (_optionalChain([update, 'access', _196 => _196.updates, 'access', _197 => _197[key], 'optionalAccess', _198 => _198.type]) === "update") {
8581
+ if (_optionalChain([update, 'access', _194 => _194.updates, 'access', _195 => _195[key], 'optionalAccess', _196 => _196.type]) === "update") {
8656
8582
  const val = update.node.get(key);
8657
8583
  if (val !== void 0) {
8658
8584
  newState[key] = lsonToJson(val);
8659
8585
  }
8660
- } else if (_optionalChain([update, 'access', _199 => _199.updates, 'access', _200 => _200[key], 'optionalAccess', _201 => _201.type]) === "delete") {
8586
+ } else if (_optionalChain([update, 'access', _197 => _197.updates, 'access', _198 => _198[key], 'optionalAccess', _199 => _199.type]) === "delete") {
8661
8587
  delete newState[key];
8662
8588
  }
8663
8589
  }
@@ -8718,12 +8644,12 @@ function legacy_patchImmutableNode(state, path, update) {
8718
8644
  }
8719
8645
  const newState = Object.assign({}, state);
8720
8646
  for (const key in update.updates) {
8721
- if (_optionalChain([update, 'access', _202 => _202.updates, 'access', _203 => _203[key], 'optionalAccess', _204 => _204.type]) === "update") {
8647
+ if (_optionalChain([update, 'access', _200 => _200.updates, 'access', _201 => _201[key], 'optionalAccess', _202 => _202.type]) === "update") {
8722
8648
  const value = update.node.get(key);
8723
8649
  if (value !== void 0) {
8724
8650
  newState[key] = lsonToJson(value);
8725
8651
  }
8726
- } else if (_optionalChain([update, 'access', _205 => _205.updates, 'access', _206 => _206[key], 'optionalAccess', _207 => _207.type]) === "delete") {
8652
+ } else if (_optionalChain([update, 'access', _203 => _203.updates, 'access', _204 => _204[key], 'optionalAccess', _205 => _205.type]) === "delete") {
8727
8653
  delete newState[key];
8728
8654
  }
8729
8655
  }
@@ -8794,9 +8720,9 @@ function makePoller(callback, intervalMs, options) {
8794
8720
  const startTime = performance.now();
8795
8721
  const doc = typeof document !== "undefined" ? document : void 0;
8796
8722
  const win = typeof window !== "undefined" ? window : void 0;
8797
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _208 => _208.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
8723
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _206 => _206.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
8798
8724
  const context = {
8799
- inForeground: _optionalChain([doc, 'optionalAccess', _209 => _209.visibilityState]) !== "hidden",
8725
+ inForeground: _optionalChain([doc, 'optionalAccess', _207 => _207.visibilityState]) !== "hidden",
8800
8726
  lastSuccessfulPollAt: startTime,
8801
8727
  count: 0,
8802
8728
  backoff: 0
@@ -8874,11 +8800,10 @@ function makePoller(callback, intervalMs, options) {
8874
8800
  pollNowIfStale();
8875
8801
  }
8876
8802
  function onVisibilityChange() {
8877
- setInForeground(_optionalChain([doc, 'optionalAccess', _210 => _210.visibilityState]) !== "hidden");
8803
+ setInForeground(_optionalChain([doc, 'optionalAccess', _208 => _208.visibilityState]) !== "hidden");
8878
8804
  }
8879
- _optionalChain([doc, 'optionalAccess', _211 => _211.addEventListener, 'call', _212 => _212("visibilitychange", onVisibilityChange)]);
8880
- _optionalChain([win, 'optionalAccess', _213 => _213.addEventListener, 'call', _214 => _214("online", onVisibilityChange)]);
8881
- _optionalChain([win, 'optionalAccess', _215 => _215.addEventListener, 'call', _216 => _216("focus", pollNowIfStale)]);
8805
+ _optionalChain([doc, 'optionalAccess', _209 => _209.addEventListener, 'call', _210 => _210("visibilitychange", onVisibilityChange)]);
8806
+ _optionalChain([win, 'optionalAccess', _211 => _211.addEventListener, 'call', _212 => _212("online", onVisibilityChange)]);
8882
8807
  fsm.start();
8883
8808
  return {
8884
8809
  inc,
@@ -9097,5 +9022,5 @@ var NotificationsApiError = HttpError;
9097
9022
 
9098
9023
 
9099
9024
 
9100
- exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
9025
+ exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.unstringify = unstringify; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
9101
9026
  //# sourceMappingURL=index.js.map