@liveblocks/core 3.23.0-file1 → 3.23.0-file3

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.cjs 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 = "3.23.0-file1";
9
+ var PKG_VERSION = "3.23.0-file3";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1663,7 +1663,7 @@ var LiveFile = class _LiveFile extends AbstractCrdt {
1663
1663
  /** @internal */
1664
1664
  _toTreeNode(key) {
1665
1665
  return {
1666
- type: "Json",
1666
+ type: "LiveFile",
1667
1667
  id: _nullishCoalesce(this._id, () => ( nanoid())),
1668
1668
  key,
1669
1669
  payload: this.#data
@@ -1919,8 +1919,10 @@ var Batch = (_class = class {
1919
1919
  this.#clearDelayTimeout();
1920
1920
  }
1921
1921
  }, _class);
1922
- function createBatchStore(batch2) {
1922
+ function createBatchStore(batch2, options) {
1923
1923
  const signal = new MutableSignal(/* @__PURE__ */ new Map());
1924
+ const cacheExpiryTimeouts = /* @__PURE__ */ new Map();
1925
+ const pendingEnqueues = /* @__PURE__ */ new Map();
1924
1926
  function getCacheKey(args) {
1925
1927
  return stableStringify(args);
1926
1928
  }
@@ -1935,7 +1937,42 @@ function createBatchStore(batch2) {
1935
1937
  }
1936
1938
  });
1937
1939
  }
1940
+ function clearCacheExpiry(cacheKey) {
1941
+ const timeoutId = cacheExpiryTimeouts.get(cacheKey);
1942
+ if (timeoutId !== void 0) {
1943
+ clearTimeout(timeoutId);
1944
+ cacheExpiryTimeouts.delete(cacheKey);
1945
+ }
1946
+ }
1947
+ function scheduleCacheExpiry(input, expiresAt) {
1948
+ const cacheKey = getCacheKey(input);
1949
+ clearCacheExpiry(cacheKey);
1950
+ if (expiresAt === void 0 || !Number.isFinite(expiresAt)) {
1951
+ return;
1952
+ }
1953
+ const timeoutId = setTimeout(
1954
+ () => {
1955
+ cacheExpiryTimeouts.delete(cacheKey);
1956
+ invalidate([input]);
1957
+ },
1958
+ Math.max(0, expiresAt - Date.now())
1959
+ );
1960
+ cacheExpiryTimeouts.set(cacheKey, timeoutId);
1961
+ }
1938
1962
  function invalidate(inputs) {
1963
+ if (Array.isArray(inputs)) {
1964
+ for (const input of inputs) {
1965
+ const cacheKey = getCacheKey(input);
1966
+ clearCacheExpiry(cacheKey);
1967
+ pendingEnqueues.delete(cacheKey);
1968
+ }
1969
+ } else {
1970
+ for (const timeoutId of cacheExpiryTimeouts.values()) {
1971
+ clearTimeout(timeoutId);
1972
+ }
1973
+ cacheExpiryTimeouts.clear();
1974
+ pendingEnqueues.clear();
1975
+ }
1939
1976
  signal.mutate((cache) => {
1940
1977
  if (Array.isArray(inputs)) {
1941
1978
  for (const input of inputs) {
@@ -1946,23 +1983,54 @@ function createBatchStore(batch2) {
1946
1983
  }
1947
1984
  });
1948
1985
  }
1949
- async function enqueue(input) {
1950
- const cacheKey = getCacheKey(input);
1951
- const cache = signal.get();
1952
- if (cache.has(cacheKey)) {
1953
- return;
1954
- }
1986
+ async function processEnqueue(input, cacheKey, batchResult$, pendingEnqueueId) {
1955
1987
  try {
1956
- update({ key: cacheKey, state: { isLoading: true } });
1957
- const result = await batch2.get(input);
1988
+ const result = await batchResult$;
1989
+ if (_optionalChain([pendingEnqueues, 'access', _27 => _27.get, 'call', _28 => _28(cacheKey), 'optionalAccess', _29 => _29.id]) !== pendingEnqueueId) {
1990
+ return;
1991
+ }
1958
1992
  update({ key: cacheKey, state: { isLoading: false, data: result } });
1993
+ scheduleCacheExpiry(input, _optionalChain([options, 'optionalAccess', _30 => _30.getCacheExpiry, 'optionalCall', _31 => _31(result)]));
1959
1994
  } catch (error3) {
1995
+ if (_optionalChain([pendingEnqueues, 'access', _32 => _32.get, 'call', _33 => _33(cacheKey), 'optionalAccess', _34 => _34.id]) !== pendingEnqueueId) {
1996
+ return;
1997
+ }
1998
+ scheduleCacheExpiry(input, _optionalChain([options, 'optionalAccess', _35 => _35.getErrorCacheExpiry, 'optionalCall', _36 => _36(error3)]));
1960
1999
  update({
1961
2000
  key: cacheKey,
1962
2001
  state: { isLoading: false, error: error3 }
1963
2002
  });
2003
+ } finally {
2004
+ if (_optionalChain([pendingEnqueues, 'access', _37 => _37.get, 'call', _38 => _38(cacheKey), 'optionalAccess', _39 => _39.id]) === pendingEnqueueId) {
2005
+ pendingEnqueues.delete(cacheKey);
2006
+ }
1964
2007
  }
1965
2008
  }
2009
+ function enqueue(input) {
2010
+ const cacheKey = getCacheKey(input);
2011
+ const existingEnqueue = pendingEnqueues.get(cacheKey);
2012
+ if (existingEnqueue !== void 0) {
2013
+ return existingEnqueue.promise;
2014
+ }
2015
+ const cache = signal.get();
2016
+ if (cache.has(cacheKey)) {
2017
+ return Promise.resolve();
2018
+ }
2019
+ const batchResult$ = batch2.get(input);
2020
+ const pendingEnqueueId = /* @__PURE__ */ Symbol();
2021
+ const pendingEnqueue$ = processEnqueue(
2022
+ input,
2023
+ cacheKey,
2024
+ batchResult$,
2025
+ pendingEnqueueId
2026
+ );
2027
+ pendingEnqueues.set(cacheKey, {
2028
+ id: pendingEnqueueId,
2029
+ promise: pendingEnqueue$
2030
+ });
2031
+ update({ key: cacheKey, state: { isLoading: true } });
2032
+ return pendingEnqueue$;
2033
+ }
1966
2034
  function setData(entries2) {
1967
2035
  update(
1968
2036
  entries2.map((entry) => ({
@@ -1970,6 +2038,9 @@ function createBatchStore(batch2) {
1970
2038
  state: { isLoading: false, data: entry[1] }
1971
2039
  }))
1972
2040
  );
2041
+ for (const [input, output] of entries2) {
2042
+ scheduleCacheExpiry(input, _optionalChain([options, 'optionalAccess', _40 => _40.getCacheExpiry, 'optionalCall', _41 => _41(output)]));
2043
+ }
1973
2044
  }
1974
2045
  function getItemState(input) {
1975
2046
  const cacheKey = getCacheKey(input);
@@ -1979,7 +2050,22 @@ function createBatchStore(batch2) {
1979
2050
  function getData(input) {
1980
2051
  const cacheKey = getCacheKey(input);
1981
2052
  const cache = signal.get();
1982
- return _optionalChain([cache, 'access', _27 => _27.get, 'call', _28 => _28(cacheKey), 'optionalAccess', _29 => _29.data]);
2053
+ return _optionalChain([cache, 'access', _42 => _42.get, 'call', _43 => _43(cacheKey), 'optionalAccess', _44 => _44.data]);
2054
+ }
2055
+ function waitUntilItemCacheExpires(input) {
2056
+ const cacheKey = getCacheKey(input);
2057
+ if (!cacheExpiryTimeouts.has(cacheKey)) {
2058
+ return void 0;
2059
+ }
2060
+ const initialState = signal.get().get(cacheKey);
2061
+ return new Promise((resolve) => {
2062
+ const unsubscribe = signal.subscribe(() => {
2063
+ if (signal.get().get(cacheKey) !== initialState) {
2064
+ unsubscribe();
2065
+ resolve();
2066
+ }
2067
+ });
2068
+ });
1983
2069
  }
1984
2070
  function _cacheKeys() {
1985
2071
  const cache = signal.get();
@@ -1991,6 +2077,7 @@ function createBatchStore(batch2) {
1991
2077
  setData,
1992
2078
  getItemState,
1993
2079
  getData,
2080
+ waitUntilItemCacheExpires,
1994
2081
  invalidate,
1995
2082
  batch: batch2,
1996
2083
  _cacheKeys
@@ -2274,6 +2361,10 @@ function isUrl(string) {
2274
2361
  // src/api-client.ts
2275
2362
  var ROOM_FILE_PART_SIZE = 5 * 1024 * 1024;
2276
2363
  var ROOM_FILE_RETRY_ATTEMPTS = 10;
2364
+ var FILE_URL_EXPIRY_BUFFER = 3e4;
2365
+ var FILE_URL_ERROR_RETRY_DELAY = 1e3;
2366
+ var FILE_URL_ERROR_MAX_ATTEMPTS = 3;
2367
+ var FILE_URL_ERROR_ATTEMPTS_EXPIRY = 3e4;
2277
2368
  var ROOM_FILE_RETRY_DELAYS = [
2278
2369
  2e3,
2279
2370
  2e3,
@@ -2286,10 +2377,13 @@ var ROOM_FILE_RETRY_DELAYS = [
2286
2377
  2e3,
2287
2378
  2e3
2288
2379
  ];
2380
+ var FileUrlRetryableError = class extends Error {
2381
+ };
2289
2382
  async function uploadRoomFile({
2290
2383
  file,
2291
2384
  signal,
2292
2385
  abortErrorMessage,
2386
+ retryMultipartCompletion,
2293
2387
  uploadSingle,
2294
2388
  createMultipartUpload,
2295
2389
  uploadMultipartPart,
@@ -2297,17 +2391,14 @@ async function uploadRoomFile({
2297
2391
  abortMultipartUpload
2298
2392
  }) {
2299
2393
  const abortError = createAbortError(abortErrorMessage);
2300
- if (_optionalChain([signal, 'optionalAccess', _30 => _30.aborted])) {
2394
+ if (_optionalChain([signal, 'optionalAccess', _45 => _45.aborted])) {
2301
2395
  throw abortError;
2302
2396
  }
2303
2397
  const handleRetryError = (err) => {
2304
- if (_optionalChain([signal, 'optionalAccess', _31 => _31.aborted])) {
2398
+ if (_optionalChain([signal, 'optionalAccess', _46 => _46.aborted])) {
2305
2399
  throw abortError;
2306
2400
  }
2307
- if (err instanceof HttpError && err.status === 413) {
2308
- throw err;
2309
- }
2310
- return false;
2401
+ return err instanceof HttpError && err.status >= 400 && err.status < 500;
2311
2402
  };
2312
2403
  if (file.size <= ROOM_FILE_PART_SIZE) {
2313
2404
  return autoRetry(
@@ -2319,15 +2410,10 @@ async function uploadRoomFile({
2319
2410
  }
2320
2411
  let uploadId;
2321
2412
  const uploadedParts = [];
2322
- const multipartUpload = await autoRetry(
2323
- createMultipartUpload,
2324
- ROOM_FILE_RETRY_ATTEMPTS,
2325
- ROOM_FILE_RETRY_DELAYS,
2326
- handleRetryError
2327
- );
2413
+ const multipartUpload = await createMultipartUpload();
2328
2414
  try {
2329
2415
  uploadId = multipartUpload.uploadId;
2330
- if (_optionalChain([signal, 'optionalAccess', _32 => _32.aborted])) {
2416
+ if (_optionalChain([signal, 'optionalAccess', _47 => _47.aborted])) {
2331
2417
  throw abortError;
2332
2418
  }
2333
2419
  const batches = chunk(splitFileIntoParts(file), 5);
@@ -2345,15 +2431,20 @@ async function uploadRoomFile({
2345
2431
  }
2346
2432
  uploadedParts.push(...await Promise.all(uploadedPartsPromises));
2347
2433
  }
2348
- if (_optionalChain([signal, 'optionalAccess', _33 => _33.aborted])) {
2434
+ if (_optionalChain([signal, 'optionalAccess', _48 => _48.aborted])) {
2349
2435
  throw abortError;
2350
2436
  }
2351
- return completeMultipartUpload(
2352
- uploadId,
2353
- uploadedParts.sort((a, b) => a.partNumber - b.partNumber)
2437
+ const sortedParts = uploadedParts.sort(
2438
+ (a, b) => a.partNumber - b.partNumber
2354
2439
  );
2440
+ return retryMultipartCompletion ? autoRetry(
2441
+ () => completeMultipartUpload(multipartUpload.uploadId, sortedParts),
2442
+ ROOM_FILE_RETRY_ATTEMPTS,
2443
+ ROOM_FILE_RETRY_DELAYS,
2444
+ handleRetryError
2445
+ ) : completeMultipartUpload(uploadId, sortedParts);
2355
2446
  } catch (error3) {
2356
- if (uploadId && isAbortOrTimeoutError(error3)) {
2447
+ if (uploadId) {
2357
2448
  try {
2358
2449
  await abortMultipartUpload(uploadId);
2359
2450
  } catch (e8) {
@@ -2375,9 +2466,6 @@ function splitFileIntoParts(file) {
2375
2466
  }
2376
2467
  return parts;
2377
2468
  }
2378
- function isAbortOrTimeoutError(error3) {
2379
- return error3 instanceof Error && (error3.name === "AbortError" || error3.name === "TimeoutError");
2380
- }
2381
2469
  function createAbortError(message) {
2382
2470
  if (typeof DOMException === "function") {
2383
2471
  return new DOMException(message, "AbortError");
@@ -2446,7 +2534,7 @@ function createApiClient({
2446
2534
  url`/v2/c/rooms/${options.roomId}/threads`,
2447
2535
  await authManager.getAuthValue({
2448
2536
  roomId: options.roomId,
2449
- resource: commentsResourceForVisibility(_optionalChain([options, 'access', _34 => _34.query, 'optionalAccess', _35 => _35.visibility])),
2537
+ resource: commentsResourceForVisibility(_optionalChain([options, 'access', _49 => _49.query, 'optionalAccess', _50 => _50.visibility])),
2450
2538
  access: "read"
2451
2539
  }),
2452
2540
  {
@@ -2504,7 +2592,7 @@ function createApiClient({
2504
2592
  hasMentions: options.query.hasMentions
2505
2593
  })
2506
2594
  },
2507
- { signal: _optionalChain([requestOptions, 'optionalAccess', _36 => _36.signal]) }
2595
+ { signal: _optionalChain([requestOptions, 'optionalAccess', _51 => _51.signal]) }
2508
2596
  );
2509
2597
  return result;
2510
2598
  }
@@ -2706,6 +2794,7 @@ function createApiClient({
2706
2794
  file: attachment.file,
2707
2795
  signal: options.signal,
2708
2796
  abortErrorMessage: `Upload of attachment ${attachment.id} was aborted.`,
2797
+ retryMultipartCompletion: false,
2709
2798
  uploadSingle: async () => httpClient.putBlob(
2710
2799
  url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/upload/${attachment.name}`,
2711
2800
  await authManager.getAuthValue({
@@ -2769,6 +2858,7 @@ function createApiClient({
2769
2858
  file,
2770
2859
  signal: options.signal,
2771
2860
  abortErrorMessage: `Upload of file ${fileId} was aborted.`,
2861
+ retryMultipartCompletion: true,
2772
2862
  uploadSingle: async () => httpClient.putBlob(
2773
2863
  url`/v2/c/rooms/${roomId}/storage/files/${fileId}/upload/${file.name}`,
2774
2864
  await authManager.getAuthValue({
@@ -2854,10 +2944,37 @@ function createApiClient({
2854
2944
  return batch2.get(options.attachmentId);
2855
2945
  }
2856
2946
  const fileUrlsBatchStoresByRoom = new DefaultMap((roomId) => {
2947
+ const errorAttempts = /* @__PURE__ */ new Map();
2948
+ const clearErrorAttempts = (fileId) => {
2949
+ const attempts = errorAttempts.get(fileId);
2950
+ if (attempts !== void 0) {
2951
+ clearTimeout(attempts.cleanupTimeoutId);
2952
+ errorAttempts.delete(fileId);
2953
+ }
2954
+ };
2955
+ const shouldRetryFileUrlError = (fileId) => {
2956
+ const previousAttempts = errorAttempts.get(fileId);
2957
+ if (previousAttempts !== void 0) {
2958
+ clearTimeout(previousAttempts.cleanupTimeoutId);
2959
+ }
2960
+ const count = (_nullishCoalesce(_optionalChain([previousAttempts, 'optionalAccess', _52 => _52.count]), () => ( 0))) + 1;
2961
+ if (count >= FILE_URL_ERROR_MAX_ATTEMPTS) {
2962
+ errorAttempts.delete(fileId);
2963
+ return false;
2964
+ }
2965
+ errorAttempts.set(fileId, {
2966
+ count,
2967
+ cleanupTimeoutId: setTimeout(
2968
+ () => errorAttempts.delete(fileId),
2969
+ FILE_URL_ERROR_ATTEMPTS_EXPIRY
2970
+ )
2971
+ });
2972
+ return true;
2973
+ };
2857
2974
  const batch2 = new Batch(
2858
2975
  async (batchedFileIds) => {
2859
2976
  const fileIds = batchedFileIds.flat();
2860
- const { urls } = await httpClient.post(
2977
+ const { urls, expiresAt } = await httpClient.post(
2861
2978
  url`/v2/c/rooms/${roomId}/storage/files/presigned-urls`,
2862
2979
  await authManager.getAuthValue({
2863
2980
  roomId,
@@ -2866,20 +2983,34 @@ function createApiClient({
2866
2983
  }),
2867
2984
  { fileIds }
2868
2985
  );
2869
- return urls.map(
2870
- (url2) => _nullishCoalesce(url2, () => ( new Error("There was an error while getting this file's URL")))
2871
- );
2986
+ const expiresAtTimestamp = Date.parse(expiresAt);
2987
+ return urls.map((url2, index) => {
2988
+ const fileId = fileIds[index];
2989
+ if (url2 !== null) {
2990
+ clearErrorAttempts(fileId);
2991
+ return { url: url2, expiresAt: expiresAtTimestamp };
2992
+ }
2993
+ if (shouldRetryFileUrlError(fileId)) {
2994
+ return new FileUrlRetryableError(
2995
+ "There was an error while getting this file's URL"
2996
+ );
2997
+ }
2998
+ return new Error("There was an error while getting this file's URL");
2999
+ });
2872
3000
  },
2873
3001
  { delay: 50 }
2874
3002
  );
2875
- return createBatchStore(batch2);
3003
+ return createBatchStore(batch2, {
3004
+ getCacheExpiry: ({ expiresAt }) => expiresAt - FILE_URL_EXPIRY_BUFFER,
3005
+ getErrorCacheExpiry: (error3) => error3 instanceof FileUrlRetryableError ? Date.now() + FILE_URL_ERROR_RETRY_DELAY : void 0
3006
+ });
2876
3007
  });
2877
3008
  function getOrCreateFileUrlsStore(roomId) {
2878
3009
  return fileUrlsBatchStoresByRoom.getOrCreate(roomId);
2879
3010
  }
2880
- function getFileUrl(options) {
3011
+ async function getFileUrl(options) {
2881
3012
  const batch2 = getOrCreateFileUrlsStore(options.roomId).batch;
2882
- return batch2.get(options.fileId);
3013
+ return (await batch2.get(options.fileId)).url;
2883
3014
  }
2884
3015
  async function getSubscriptionSettings(options) {
2885
3016
  return httpClient.get(
@@ -3089,14 +3220,14 @@ function createApiClient({
3089
3220
  async function getInboxNotifications(options) {
3090
3221
  const PAGE_SIZE = 50;
3091
3222
  let query;
3092
- if (_optionalChain([options, 'optionalAccess', _37 => _37.query])) {
3223
+ if (_optionalChain([options, 'optionalAccess', _53 => _53.query])) {
3093
3224
  query = objectToQuery(options.query);
3094
3225
  }
3095
3226
  const json = await httpClient.get(
3096
3227
  url`/v2/c/inbox-notifications`,
3097
3228
  await authManager.getAuthValue({ resource: "personal", access: "write" }),
3098
3229
  {
3099
- cursor: _optionalChain([options, 'optionalAccess', _38 => _38.cursor]),
3230
+ cursor: _optionalChain([options, 'optionalAccess', _54 => _54.cursor]),
3100
3231
  limit: PAGE_SIZE,
3101
3232
  query
3102
3233
  }
@@ -3115,7 +3246,7 @@ function createApiClient({
3115
3246
  }
3116
3247
  async function getInboxNotificationsSince(options) {
3117
3248
  let query;
3118
- if (_optionalChain([options, 'optionalAccess', _39 => _39.query])) {
3249
+ if (_optionalChain([options, 'optionalAccess', _55 => _55.query])) {
3119
3250
  query = objectToQuery(options.query);
3120
3251
  }
3121
3252
  const json = await httpClient.get(
@@ -3144,14 +3275,14 @@ function createApiClient({
3144
3275
  }
3145
3276
  async function getUnreadInboxNotificationsCount(options) {
3146
3277
  let query;
3147
- if (_optionalChain([options, 'optionalAccess', _40 => _40.query])) {
3278
+ if (_optionalChain([options, 'optionalAccess', _56 => _56.query])) {
3148
3279
  query = objectToQuery(options.query);
3149
3280
  }
3150
3281
  const { count } = await httpClient.get(
3151
3282
  url`/v2/c/inbox-notifications/count`,
3152
3283
  await authManager.getAuthValue({ resource: "personal", access: "write" }),
3153
3284
  { query },
3154
- { signal: _optionalChain([options, 'optionalAccess', _41 => _41.signal]) }
3285
+ { signal: _optionalChain([options, 'optionalAccess', _57 => _57.signal]) }
3155
3286
  );
3156
3287
  return count;
3157
3288
  }
@@ -3201,7 +3332,7 @@ function createApiClient({
3201
3332
  url`/v2/c/notification-settings`,
3202
3333
  await authManager.getAuthValue({ resource: "personal", access: "write" }),
3203
3334
  void 0,
3204
- { signal: _optionalChain([options, 'optionalAccess', _42 => _42.signal]) }
3335
+ { signal: _optionalChain([options, 'optionalAccess', _58 => _58.signal]) }
3205
3336
  );
3206
3337
  }
3207
3338
  async function updateNotificationSettings(settings) {
@@ -3213,7 +3344,7 @@ function createApiClient({
3213
3344
  }
3214
3345
  async function getUserThreads_experimental(options) {
3215
3346
  let query;
3216
- if (_optionalChain([options, 'optionalAccess', _43 => _43.query])) {
3347
+ if (_optionalChain([options, 'optionalAccess', _59 => _59.query])) {
3217
3348
  query = objectToQuery(options.query);
3218
3349
  }
3219
3350
  const PAGE_SIZE = 50;
@@ -3221,7 +3352,7 @@ function createApiClient({
3221
3352
  url`/v2/c/threads`,
3222
3353
  await authManager.getAuthValue({ resource: "personal", access: "write" }),
3223
3354
  {
3224
- cursor: _optionalChain([options, 'optionalAccess', _44 => _44.cursor]),
3355
+ cursor: _optionalChain([options, 'optionalAccess', _60 => _60.cursor]),
3225
3356
  query,
3226
3357
  limit: PAGE_SIZE
3227
3358
  }
@@ -3400,7 +3531,7 @@ var HttpClient = class {
3400
3531
  // These headers are default, but can be overriden by custom headers
3401
3532
  "Content-Type": "application/json; charset=utf-8",
3402
3533
  // Possible header overrides
3403
- ..._optionalChain([options, 'optionalAccess', _45 => _45.headers]),
3534
+ ..._optionalChain([options, 'optionalAccess', _61 => _61.headers]),
3404
3535
  // Cannot be overriden by custom headers
3405
3536
  Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
3406
3537
  "X-LB-Client": PKG_VERSION || "dev"
@@ -3408,7 +3539,7 @@ var HttpClient = class {
3408
3539
  });
3409
3540
  const xwarn = response.headers.get("X-LB-Warn");
3410
3541
  if (xwarn) {
3411
- const method = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _46 => _46.method, 'optionalAccess', _47 => _47.toUpperCase, 'call', _48 => _48()]), () => ( "GET"));
3542
+ const method = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.method, 'optionalAccess', _63 => _63.toUpperCase, 'call', _64 => _64()]), () => ( "GET"));
3412
3543
  const msg = `${xwarn} (${method} ${endpoint})`;
3413
3544
  if (response.ok) {
3414
3545
  warn(msg);
@@ -3890,7 +4021,7 @@ var FSM = class {
3890
4021
  });
3891
4022
  }
3892
4023
  #getTargetFn(eventName) {
3893
- return _optionalChain([this, 'access', _49 => _49.#allowedTransitions, 'access', _50 => _50.get, 'call', _51 => _51(this.currentState), 'optionalAccess', _52 => _52.get, 'call', _53 => _53(eventName)]);
4024
+ return _optionalChain([this, 'access', _65 => _65.#allowedTransitions, 'access', _66 => _66.get, 'call', _67 => _67(this.currentState), 'optionalAccess', _68 => _68.get, 'call', _69 => _69(eventName)]);
3894
4025
  }
3895
4026
  /**
3896
4027
  * Exits the current state, and executes any necessary cleanup functions.
@@ -3909,7 +4040,7 @@ var FSM = class {
3909
4040
  this.#currentContext.allowPatching((patchableContext) => {
3910
4041
  levels = _nullishCoalesce(levels, () => ( this.#cleanupStack.length));
3911
4042
  for (let i = 0; i < levels; i++) {
3912
- _optionalChain([this, 'access', _54 => _54.#cleanupStack, 'access', _55 => _55.pop, 'call', _56 => _56(), 'optionalCall', _57 => _57(patchableContext)]);
4043
+ _optionalChain([this, 'access', _70 => _70.#cleanupStack, 'access', _71 => _71.pop, 'call', _72 => _72(), 'optionalCall', _73 => _73(patchableContext)]);
3913
4044
  const entryTime = this.#entryTimesStack.pop();
3914
4045
  if (entryTime !== void 0 && // ...but avoid computing state names if nobody is listening
3915
4046
  this.#eventHub.didExitState.count() > 0) {
@@ -3937,7 +4068,7 @@ var FSM = class {
3937
4068
  this.#currentContext.allowPatching((patchableContext) => {
3938
4069
  for (const pattern of enterPatterns) {
3939
4070
  const enterFn = this.#enterFns.get(pattern);
3940
- const cleanupFn = _optionalChain([enterFn, 'optionalCall', _58 => _58(patchableContext)]);
4071
+ const cleanupFn = _optionalChain([enterFn, 'optionalCall', _74 => _74(patchableContext)]);
3941
4072
  if (typeof cleanupFn === "function") {
3942
4073
  this.#cleanupStack.push(cleanupFn);
3943
4074
  } else {
@@ -4364,7 +4495,7 @@ function createConnectionStateMachine(delegates, options) {
4364
4495
  }
4365
4496
  function waitForActorId(event) {
4366
4497
  const serverMsg = tryParseJson(event.data);
4367
- if (_optionalChain([serverMsg, 'optionalAccess', _59 => _59.type]) === ServerMsgCode.ROOM_STATE) {
4498
+ if (_optionalChain([serverMsg, 'optionalAccess', _75 => _75.type]) === ServerMsgCode.ROOM_STATE) {
4368
4499
  if (options.enableDebugLogging && socketOpenAt !== null) {
4369
4500
  const elapsed = performance.now() - socketOpenAt;
4370
4501
  warn(
@@ -4492,12 +4623,12 @@ function createConnectionStateMachine(delegates, options) {
4492
4623
  const sendHeartbeat = {
4493
4624
  target: "@ok.awaiting-pong",
4494
4625
  effect: (ctx) => {
4495
- _optionalChain([ctx, 'access', _60 => _60.socket, 'optionalAccess', _61 => _61.send, 'call', _62 => _62("ping")]);
4626
+ _optionalChain([ctx, 'access', _76 => _76.socket, 'optionalAccess', _77 => _77.send, 'call', _78 => _78("ping")]);
4496
4627
  }
4497
4628
  };
4498
4629
  const maybeHeartbeat = () => {
4499
4630
  const doc = typeof document !== "undefined" ? document : void 0;
4500
- const canZombie = _optionalChain([doc, 'optionalAccess', _63 => _63.visibilityState]) === "hidden" && delegates.canZombie();
4631
+ const canZombie = _optionalChain([doc, 'optionalAccess', _79 => _79.visibilityState]) === "hidden" && delegates.canZombie();
4501
4632
  return canZombie ? "@idle.zombie" : sendHeartbeat;
4502
4633
  };
4503
4634
  machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
@@ -4537,7 +4668,7 @@ function createConnectionStateMachine(delegates, options) {
4537
4668
  // socket, or not. So always check to see if the socket is still OPEN or
4538
4669
  // not. When still OPEN, don't transition.
4539
4670
  EXPLICIT_SOCKET_ERROR: (_, context) => {
4540
- if (_optionalChain([context, 'access', _64 => _64.socket, 'optionalAccess', _65 => _65.readyState]) === 1) {
4671
+ if (_optionalChain([context, 'access', _80 => _80.socket, 'optionalAccess', _81 => _81.readyState]) === 1) {
4541
4672
  return IGNORE;
4542
4673
  }
4543
4674
  return {
@@ -4589,17 +4720,17 @@ function createConnectionStateMachine(delegates, options) {
4589
4720
  machine.send({ type: "NAVIGATOR_ONLINE" });
4590
4721
  }
4591
4722
  function onVisibilityChange() {
4592
- if (_optionalChain([doc, 'optionalAccess', _66 => _66.visibilityState]) === "visible") {
4723
+ if (_optionalChain([doc, 'optionalAccess', _82 => _82.visibilityState]) === "visible") {
4593
4724
  machine.send({ type: "WINDOW_GOT_FOCUS" });
4594
4725
  }
4595
4726
  }
4596
- _optionalChain([win, 'optionalAccess', _67 => _67.addEventListener, 'call', _68 => _68("online", onNetworkBackOnline)]);
4597
- _optionalChain([win, 'optionalAccess', _69 => _69.addEventListener, 'call', _70 => _70("offline", onNetworkOffline)]);
4598
- _optionalChain([root, 'optionalAccess', _71 => _71.addEventListener, 'call', _72 => _72("visibilitychange", onVisibilityChange)]);
4727
+ _optionalChain([win, 'optionalAccess', _83 => _83.addEventListener, 'call', _84 => _84("online", onNetworkBackOnline)]);
4728
+ _optionalChain([win, 'optionalAccess', _85 => _85.addEventListener, 'call', _86 => _86("offline", onNetworkOffline)]);
4729
+ _optionalChain([root, 'optionalAccess', _87 => _87.addEventListener, 'call', _88 => _88("visibilitychange", onVisibilityChange)]);
4599
4730
  return () => {
4600
- _optionalChain([root, 'optionalAccess', _73 => _73.removeEventListener, 'call', _74 => _74("visibilitychange", onVisibilityChange)]);
4601
- _optionalChain([win, 'optionalAccess', _75 => _75.removeEventListener, 'call', _76 => _76("online", onNetworkBackOnline)]);
4602
- _optionalChain([win, 'optionalAccess', _77 => _77.removeEventListener, 'call', _78 => _78("offline", onNetworkOffline)]);
4731
+ _optionalChain([root, 'optionalAccess', _89 => _89.removeEventListener, 'call', _90 => _90("visibilitychange", onVisibilityChange)]);
4732
+ _optionalChain([win, 'optionalAccess', _91 => _91.removeEventListener, 'call', _92 => _92("online", onNetworkBackOnline)]);
4733
+ _optionalChain([win, 'optionalAccess', _93 => _93.removeEventListener, 'call', _94 => _94("offline", onNetworkOffline)]);
4603
4734
  teardownSocket(ctx.socket);
4604
4735
  };
4605
4736
  });
@@ -4688,7 +4819,7 @@ var ManagedSocket = class {
4688
4819
  * message if this is somehow impossible.
4689
4820
  */
4690
4821
  send(data) {
4691
- const socket = _optionalChain([this, 'access', _79 => _79.#machine, 'access', _80 => _80.context, 'optionalAccess', _81 => _81.socket]);
4822
+ const socket = _optionalChain([this, 'access', _95 => _95.#machine, 'access', _96 => _96.context, 'optionalAccess', _97 => _97.socket]);
4692
4823
  if (socket === null) {
4693
4824
  warn("Cannot send: not connected yet", data);
4694
4825
  } else if (socket.readyState !== 1) {
@@ -5150,7 +5281,7 @@ function createStore_forKnowledge() {
5150
5281
  }
5151
5282
  function getKnowledgeForChat(chatId) {
5152
5283
  const globalKnowledge = knowledgeByChatId.getOrCreate(kWILDCARD).get();
5153
- const scopedKnowledge = _nullishCoalesce(_optionalChain([knowledgeByChatId, 'access', _82 => _82.get, 'call', _83 => _83(chatId), 'optionalAccess', _84 => _84.get, 'call', _85 => _85()]), () => ( []));
5284
+ const scopedKnowledge = _nullishCoalesce(_optionalChain([knowledgeByChatId, 'access', _98 => _98.get, 'call', _99 => _99(chatId), 'optionalAccess', _100 => _100.get, 'call', _101 => _101()]), () => ( []));
5154
5285
  return [...globalKnowledge, ...scopedKnowledge];
5155
5286
  }
5156
5287
  return {
@@ -5175,7 +5306,7 @@ function createStore_forTools() {
5175
5306
  return DerivedSignal.from(() => {
5176
5307
  return (
5177
5308
  // A tool that's registered and scoped to a specific chat ID...
5178
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _86 => _86.get, 'call', _87 => _87()]), () => ( // ...or a globally registered tool
5309
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _102 => _102.get, 'call', _103 => _103()]), () => ( // ...or a globally registered tool
5179
5310
  toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
5180
5311
  );
5181
5312
  });
@@ -5205,8 +5336,8 @@ function createStore_forTools() {
5205
5336
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
5206
5337
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
5207
5338
  return Array.from([
5208
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _88 => _88.entries, 'call', _89 => _89()]), () => ( [])),
5209
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _90 => _90.entries, 'call', _91 => _91()]), () => ( []))
5339
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _104 => _104.entries, 'call', _105 => _105()]), () => ( [])),
5340
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _106 => _106.entries, 'call', _107 => _107()]), () => ( []))
5210
5341
  ]).flatMap(([name, tool\u03A3]) => {
5211
5342
  const tool = tool\u03A3.get();
5212
5343
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -5309,7 +5440,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
5309
5440
  } else {
5310
5441
  continue;
5311
5442
  }
5312
- const executeFn = _optionalChain([toolsStore, 'access', _92 => _92.getTool\u03A3, 'call', _93 => _93(toolInvocation.name, message.chatId), 'access', _94 => _94.get, 'call', _95 => _95(), 'optionalAccess', _96 => _96.execute]);
5443
+ const executeFn = _optionalChain([toolsStore, 'access', _108 => _108.getTool\u03A3, 'call', _109 => _109(toolInvocation.name, message.chatId), 'access', _110 => _110.get, 'call', _111 => _111(), 'optionalAccess', _112 => _112.execute]);
5313
5444
  if (executeFn) {
5314
5445
  (async () => {
5315
5446
  const result = await executeFn(toolInvocation.args, {
@@ -5408,8 +5539,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
5408
5539
  const spine = [];
5409
5540
  let lastVisitedMessage = null;
5410
5541
  for (const message2 of pool.walkUp(leaf.id)) {
5411
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _97 => _97(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _98 => _98.id]), () => ( null));
5412
- const next = _nullishCoalesce(_optionalChain([first, 'call', _99 => _99(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _100 => _100.id]), () => ( null));
5542
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _113 => _113(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _114 => _114.id]), () => ( null));
5543
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _115 => _115(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _116 => _116.id]), () => ( null));
5413
5544
  if (!message2.deletedAt || prev || next) {
5414
5545
  const node = {
5415
5546
  ...message2,
@@ -5475,7 +5606,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
5475
5606
  const latest = pool.sorted.findRight(
5476
5607
  (m) => m.role === "assistant" && !m.deletedAt
5477
5608
  );
5478
- return _optionalChain([latest, 'optionalAccess', _101 => _101.copilotId]);
5609
+ return _optionalChain([latest, 'optionalAccess', _117 => _117.copilotId]);
5479
5610
  }
5480
5611
  return {
5481
5612
  // Readers
@@ -5506,11 +5637,11 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
5506
5637
  *getAutoExecutingMessageIds() {
5507
5638
  for (const messageId of myMessages) {
5508
5639
  const message = getMessageById(messageId);
5509
- if (_optionalChain([message, 'optionalAccess', _102 => _102.role]) === "assistant" && message.status === "awaiting-tool") {
5640
+ if (_optionalChain([message, 'optionalAccess', _118 => _118.role]) === "assistant" && message.status === "awaiting-tool") {
5510
5641
  const isAutoExecuting = message.contentSoFar.some((part) => {
5511
5642
  if (part.type === "tool-invocation" && part.stage === "executing") {
5512
5643
  const tool = toolsStore.getTool\u03A3(part.name, message.chatId).get();
5513
- return typeof _optionalChain([tool, 'optionalAccess', _103 => _103.execute]) === "function";
5644
+ return typeof _optionalChain([tool, 'optionalAccess', _119 => _119.execute]) === "function";
5514
5645
  }
5515
5646
  return false;
5516
5647
  });
@@ -5658,7 +5789,7 @@ function createAi(config) {
5658
5789
  flushPendingDeltas();
5659
5790
  switch (msg.event) {
5660
5791
  case "cmd-failed":
5661
- _optionalChain([pendingCmd, 'optionalAccess', _104 => _104.reject, 'call', _105 => _105(new Error(msg.error))]);
5792
+ _optionalChain([pendingCmd, 'optionalAccess', _120 => _120.reject, 'call', _121 => _121(new Error(msg.error))]);
5662
5793
  break;
5663
5794
  case "settle": {
5664
5795
  context.messagesStore.upsert(msg.message);
@@ -5735,7 +5866,7 @@ function createAi(config) {
5735
5866
  return assertNever(msg, "Unhandled case");
5736
5867
  }
5737
5868
  }
5738
- _optionalChain([pendingCmd, 'optionalAccess', _106 => _106.resolve, 'call', _107 => _107(msg)]);
5869
+ _optionalChain([pendingCmd, 'optionalAccess', _122 => _122.resolve, 'call', _123 => _123(msg)]);
5739
5870
  }
5740
5871
  managedSocket.events.onMessage.subscribe(handleServerMessage);
5741
5872
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -5811,9 +5942,9 @@ function createAi(config) {
5811
5942
  invocationId,
5812
5943
  result,
5813
5944
  generationOptions: {
5814
- copilotId: _optionalChain([options, 'optionalAccess', _108 => _108.copilotId]),
5815
- stream: _optionalChain([options, 'optionalAccess', _109 => _109.stream]),
5816
- timeout: _optionalChain([options, 'optionalAccess', _110 => _110.timeout]),
5945
+ copilotId: _optionalChain([options, 'optionalAccess', _124 => _124.copilotId]),
5946
+ stream: _optionalChain([options, 'optionalAccess', _125 => _125.stream]),
5947
+ timeout: _optionalChain([options, 'optionalAccess', _126 => _126.timeout]),
5817
5948
  // Knowledge and tools aren't coming from the options, but retrieved
5818
5949
  // from the global context
5819
5950
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -5831,7 +5962,7 @@ function createAi(config) {
5831
5962
  }
5832
5963
  }
5833
5964
  const win = typeof window !== "undefined" ? window : void 0;
5834
- _optionalChain([win, 'optionalAccess', _111 => _111.addEventListener, 'call', _112 => _112("beforeunload", handleBeforeUnload, { once: true })]);
5965
+ _optionalChain([win, 'optionalAccess', _127 => _127.addEventListener, 'call', _128 => _128("beforeunload", handleBeforeUnload, { once: true })]);
5835
5966
  return Object.defineProperty(
5836
5967
  {
5837
5968
  [kInternal]: {
@@ -5850,7 +5981,7 @@ function createAi(config) {
5850
5981
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
5851
5982
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
5852
5983
  const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
5853
- const requestKnowledge = _optionalChain([options, 'optionalAccess', _113 => _113.knowledge]) || [];
5984
+ const requestKnowledge = _optionalChain([options, 'optionalAccess', _129 => _129.knowledge]) || [];
5854
5985
  const combinedKnowledge = [...knowledge, ...requestKnowledge];
5855
5986
  const tools = context.toolsStore.getToolDescriptions(chatId);
5856
5987
  messagesStore.markMine(targetMessageId);
@@ -5860,9 +5991,9 @@ function createAi(config) {
5860
5991
  sourceMessage: userMessage,
5861
5992
  targetMessageId,
5862
5993
  generationOptions: {
5863
- copilotId: _optionalChain([options, 'optionalAccess', _114 => _114.copilotId]),
5864
- stream: _optionalChain([options, 'optionalAccess', _115 => _115.stream]),
5865
- timeout: _optionalChain([options, 'optionalAccess', _116 => _116.timeout]),
5994
+ copilotId: _optionalChain([options, 'optionalAccess', _130 => _130.copilotId]),
5995
+ stream: _optionalChain([options, 'optionalAccess', _131 => _131.stream]),
5996
+ timeout: _optionalChain([options, 'optionalAccess', _132 => _132.timeout]),
5866
5997
  // Combine global knowledge with request-specific knowledge
5867
5998
  knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
5868
5999
  tools: tools.length > 0 ? tools : void 0
@@ -5934,7 +6065,7 @@ function replaceOrAppend(content, newItem, keyFn, now2) {
5934
6065
  }
5935
6066
  }
5936
6067
  function closePart(prevPart, endedAt) {
5937
- if (_optionalChain([prevPart, 'optionalAccess', _117 => _117.type]) === "reasoning") {
6068
+ if (_optionalChain([prevPart, 'optionalAccess', _133 => _133.type]) === "reasoning") {
5938
6069
  prevPart.endedAt ??= endedAt;
5939
6070
  }
5940
6071
  }
@@ -5949,7 +6080,7 @@ function patchContentWithDelta(content, delta) {
5949
6080
  const lastPart = parts[parts.length - 1];
5950
6081
  switch (delta.type) {
5951
6082
  case "text-delta":
5952
- if (_optionalChain([lastPart, 'optionalAccess', _118 => _118.type]) === "text") {
6083
+ if (_optionalChain([lastPart, 'optionalAccess', _134 => _134.type]) === "text") {
5953
6084
  lastPart.text += delta.textDelta;
5954
6085
  } else {
5955
6086
  closePart(lastPart, now2);
@@ -5957,7 +6088,7 @@ function patchContentWithDelta(content, delta) {
5957
6088
  }
5958
6089
  break;
5959
6090
  case "reasoning-delta":
5960
- if (_optionalChain([lastPart, 'optionalAccess', _119 => _119.type]) === "reasoning") {
6091
+ if (_optionalChain([lastPart, 'optionalAccess', _135 => _135.type]) === "reasoning") {
5961
6092
  lastPart.text += delta.textDelta;
5962
6093
  } else {
5963
6094
  closePart(lastPart, now2);
@@ -5977,8 +6108,8 @@ function patchContentWithDelta(content, delta) {
5977
6108
  break;
5978
6109
  }
5979
6110
  case "tool-delta": {
5980
- if (_optionalChain([lastPart, 'optionalAccess', _120 => _120.type]) === "tool-invocation" && lastPart.stage === "receiving") {
5981
- _optionalChain([lastPart, 'access', _121 => _121.__appendDelta, 'optionalCall', _122 => _122(delta.delta)]);
6111
+ if (_optionalChain([lastPart, 'optionalAccess', _136 => _136.type]) === "tool-invocation" && lastPart.stage === "receiving") {
6112
+ _optionalChain([lastPart, 'access', _137 => _137.__appendDelta, 'optionalCall', _138 => _138(delta.delta)]);
5982
6113
  }
5983
6114
  break;
5984
6115
  }
@@ -6333,7 +6464,7 @@ function explicitAccessForResource(source, resource) {
6333
6464
  }
6334
6465
  function permissionForAccessLevel(resource, access, field = resource) {
6335
6466
  const permissions = PERMISSIONS_BY_RESOURCE[resource][access];
6336
- const permission = _optionalChain([permissions, 'optionalAccess', _123 => _123[0]]);
6467
+ const permission = _optionalChain([permissions, 'optionalAccess', _139 => _139[0]]);
6337
6468
  if (permission !== void 0) {
6338
6469
  return permission;
6339
6470
  }
@@ -6443,7 +6574,7 @@ function createAuthManager(authOptions, onAuthenticate) {
6443
6574
  return void 0;
6444
6575
  }
6445
6576
  async function makeAuthRequest(options) {
6446
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _124 => _124.polyfills, 'optionalAccess', _125 => _125.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
6577
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _140 => _140.polyfills, 'optionalAccess', _141 => _141.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
6447
6578
  if (authentication.type === "private") {
6448
6579
  if (fetcher === void 0) {
6449
6580
  throw new StopRetrying(
@@ -6456,14 +6587,14 @@ function createAuthManager(authOptions, onAuthenticate) {
6456
6587
  const parsed = parseAuthToken(response.token);
6457
6588
  if (seenTokens.has(parsed.raw)) {
6458
6589
  const cachedToken = getCachedToken(options);
6459
- if (_optionalChain([cachedToken, 'optionalAccess', _126 => _126.raw]) === parsed.raw) {
6590
+ if (_optionalChain([cachedToken, 'optionalAccess', _142 => _142.raw]) === parsed.raw) {
6460
6591
  return cachedToken;
6461
6592
  }
6462
6593
  throw new StopRetrying(
6463
6594
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
6464
6595
  );
6465
6596
  }
6466
- _optionalChain([onAuthenticate, 'optionalCall', _127 => _127(parsed.parsed)]);
6597
+ _optionalChain([onAuthenticate, 'optionalCall', _143 => _143(parsed.parsed)]);
6467
6598
  return parsed;
6468
6599
  }
6469
6600
  if (authentication.type === "custom") {
@@ -6471,7 +6602,7 @@ function createAuthManager(authOptions, onAuthenticate) {
6471
6602
  if (response && typeof response === "object") {
6472
6603
  if (typeof response.token === "string") {
6473
6604
  const parsed = parseAuthToken(response.token);
6474
- _optionalChain([onAuthenticate, 'optionalCall', _128 => _128(parsed.parsed)]);
6605
+ _optionalChain([onAuthenticate, 'optionalCall', _144 => _144(parsed.parsed)]);
6475
6606
  return parsed;
6476
6607
  } else if (typeof response.error === "string") {
6477
6608
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -7171,7 +7302,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7171
7302
  #applyInsertUndoRedo(op) {
7172
7303
  const { id, parentKey: key } = op;
7173
7304
  const child = creationOpToLiveNode(op);
7174
- if (_optionalChain([this, 'access', _129 => _129._pool, 'optionalAccess', _130 => _130.getNode, 'call', _131 => _131(id)]) !== void 0) {
7305
+ if (_optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.getNode, 'call', _147 => _147(id)]) !== void 0) {
7175
7306
  return { modified: false };
7176
7307
  }
7177
7308
  child._attach(id, nn(this._pool));
@@ -7179,8 +7310,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
7179
7310
  const existingItemIndex = this._indexOfPosition(key);
7180
7311
  let newKey = key;
7181
7312
  if (existingItemIndex !== -1) {
7182
- const before2 = _optionalChain([this, 'access', _132 => _132.#items, 'access', _133 => _133.at, 'call', _134 => _134(existingItemIndex), 'optionalAccess', _135 => _135._parentPos]);
7183
- const after2 = _optionalChain([this, 'access', _136 => _136.#items, 'access', _137 => _137.at, 'call', _138 => _138(existingItemIndex + 1), 'optionalAccess', _139 => _139._parentPos]);
7313
+ const before2 = _optionalChain([this, 'access', _148 => _148.#items, 'access', _149 => _149.at, 'call', _150 => _150(existingItemIndex), 'optionalAccess', _151 => _151._parentPos]);
7314
+ const after2 = _optionalChain([this, 'access', _152 => _152.#items, 'access', _153 => _153.at, 'call', _154 => _154(existingItemIndex + 1), 'optionalAccess', _155 => _155._parentPos]);
7184
7315
  newKey = makePosition(before2, after2);
7185
7316
  child._setParentLink(this, newKey);
7186
7317
  }
@@ -7194,7 +7325,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7194
7325
  #applySetUndoRedo(op) {
7195
7326
  const { id, parentKey: key } = op;
7196
7327
  const child = creationOpToLiveNode(op);
7197
- if (_optionalChain([this, 'access', _140 => _140._pool, 'optionalAccess', _141 => _141.getNode, 'call', _142 => _142(id)]) !== void 0) {
7328
+ if (_optionalChain([this, 'access', _156 => _156._pool, 'optionalAccess', _157 => _157.getNode, 'call', _158 => _158(id)]) !== void 0) {
7198
7329
  return { modified: false };
7199
7330
  }
7200
7331
  const indexOfItemWithSameKey = this._indexOfPosition(key);
@@ -7315,7 +7446,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7315
7446
  } else {
7316
7447
  this.#updateItemPositionAt(
7317
7448
  existingItemIndex,
7318
- makePosition(newKey, _optionalChain([this, 'access', _143 => _143.#items, 'access', _144 => _144.at, 'call', _145 => _145(existingItemIndex + 1), 'optionalAccess', _146 => _146._parentPos]))
7449
+ makePosition(newKey, _optionalChain([this, 'access', _159 => _159.#items, 'access', _160 => _160.at, 'call', _161 => _161(existingItemIndex + 1), 'optionalAccess', _162 => _162._parentPos]))
7319
7450
  );
7320
7451
  const previousIndex = this.#items.findIndex((item) => item === child);
7321
7452
  this.#updateItemPosition(child, newKey);
@@ -7342,7 +7473,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7342
7473
  this,
7343
7474
  makePosition(
7344
7475
  newKey,
7345
- _optionalChain([this, 'access', _147 => _147.#items, 'access', _148 => _148.at, 'call', _149 => _149(existingItemIndex + 1), 'optionalAccess', _150 => _150._parentPos])
7476
+ _optionalChain([this, 'access', _163 => _163.#items, 'access', _164 => _164.at, 'call', _165 => _165(existingItemIndex + 1), 'optionalAccess', _166 => _166._parentPos])
7346
7477
  )
7347
7478
  );
7348
7479
  this.#items.reposition(existingItem);
@@ -7366,7 +7497,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7366
7497
  existingItemIndex,
7367
7498
  makePosition(
7368
7499
  newKey,
7369
- _optionalChain([this, 'access', _151 => _151.#items, 'access', _152 => _152.at, 'call', _153 => _153(existingItemIndex + 1), 'optionalAccess', _154 => _154._parentPos])
7500
+ _optionalChain([this, 'access', _167 => _167.#items, 'access', _168 => _168.at, 'call', _169 => _169(existingItemIndex + 1), 'optionalAccess', _170 => _170._parentPos])
7370
7501
  )
7371
7502
  );
7372
7503
  }
@@ -7394,7 +7525,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7394
7525
  if (existingItemIndex !== -1) {
7395
7526
  actualNewKey = makePosition(
7396
7527
  newKey,
7397
- _optionalChain([this, 'access', _155 => _155.#items, 'access', _156 => _156.at, 'call', _157 => _157(existingItemIndex + 1), 'optionalAccess', _158 => _158._parentPos])
7528
+ _optionalChain([this, 'access', _171 => _171.#items, 'access', _172 => _172.at, 'call', _173 => _173(existingItemIndex + 1), 'optionalAccess', _174 => _174._parentPos])
7398
7529
  );
7399
7530
  }
7400
7531
  this.#updateItemPosition(child, actualNewKey);
@@ -7468,14 +7599,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
7468
7599
  * instead of resolving its position against the client's stale view.
7469
7600
  */
7470
7601
  #injectAt(element, index, intent) {
7471
- _optionalChain([this, 'access', _159 => _159._pool, 'optionalAccess', _160 => _160.assertStorageIsWritable, 'call', _161 => _161()]);
7602
+ _optionalChain([this, 'access', _175 => _175._pool, 'optionalAccess', _176 => _176.assertStorageIsWritable, 'call', _177 => _177()]);
7472
7603
  if (index < 0 || index > this.#items.length) {
7473
7604
  throw new Error(
7474
7605
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
7475
7606
  );
7476
7607
  }
7477
- const before2 = _optionalChain([this, 'access', _162 => _162.#items, 'access', _163 => _163.at, 'call', _164 => _164(index - 1), 'optionalAccess', _165 => _165._parentPos]);
7478
- const after2 = _optionalChain([this, 'access', _166 => _166.#items, 'access', _167 => _167.at, 'call', _168 => _168(index), 'optionalAccess', _169 => _169._parentPos]);
7608
+ const before2 = _optionalChain([this, 'access', _178 => _178.#items, 'access', _179 => _179.at, 'call', _180 => _180(index - 1), 'optionalAccess', _181 => _181._parentPos]);
7609
+ const after2 = _optionalChain([this, 'access', _182 => _182.#items, 'access', _183 => _183.at, 'call', _184 => _184(index), 'optionalAccess', _185 => _185._parentPos]);
7479
7610
  const position = makePosition(before2, after2);
7480
7611
  const value = lsonToLiveNode(element);
7481
7612
  value._setParentLink(this, position);
@@ -7499,7 +7630,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7499
7630
  * @param targetIndex The index where the element should be after moving.
7500
7631
  */
7501
7632
  move(index, targetIndex) {
7502
- _optionalChain([this, 'access', _170 => _170._pool, 'optionalAccess', _171 => _171.assertStorageIsWritable, 'call', _172 => _172()]);
7633
+ _optionalChain([this, 'access', _186 => _186._pool, 'optionalAccess', _187 => _187.assertStorageIsWritable, 'call', _188 => _188()]);
7503
7634
  if (targetIndex < 0) {
7504
7635
  throw new Error("targetIndex cannot be less than 0");
7505
7636
  }
@@ -7517,11 +7648,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
7517
7648
  let beforePosition = null;
7518
7649
  let afterPosition = null;
7519
7650
  if (index < targetIndex) {
7520
- afterPosition = targetIndex === this.#items.length - 1 ? void 0 : _optionalChain([this, 'access', _173 => _173.#items, 'access', _174 => _174.at, 'call', _175 => _175(targetIndex + 1), 'optionalAccess', _176 => _176._parentPos]);
7651
+ afterPosition = targetIndex === this.#items.length - 1 ? void 0 : _optionalChain([this, 'access', _189 => _189.#items, 'access', _190 => _190.at, 'call', _191 => _191(targetIndex + 1), 'optionalAccess', _192 => _192._parentPos]);
7521
7652
  beforePosition = this.#items.at(targetIndex)._parentPos;
7522
7653
  } else {
7523
7654
  afterPosition = this.#items.at(targetIndex)._parentPos;
7524
- beforePosition = targetIndex === 0 ? void 0 : _optionalChain([this, 'access', _177 => _177.#items, 'access', _178 => _178.at, 'call', _179 => _179(targetIndex - 1), 'optionalAccess', _180 => _180._parentPos]);
7655
+ beforePosition = targetIndex === 0 ? void 0 : _optionalChain([this, 'access', _193 => _193.#items, 'access', _194 => _194.at, 'call', _195 => _195(targetIndex - 1), 'optionalAccess', _196 => _196._parentPos]);
7525
7656
  }
7526
7657
  const position = makePosition(beforePosition, afterPosition);
7527
7658
  const item = this.#items.at(index);
@@ -7556,7 +7687,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7556
7687
  * @param index The index of the element to delete
7557
7688
  */
7558
7689
  delete(index) {
7559
- _optionalChain([this, 'access', _181 => _181._pool, 'optionalAccess', _182 => _182.assertStorageIsWritable, 'call', _183 => _183()]);
7690
+ _optionalChain([this, 'access', _197 => _197._pool, 'optionalAccess', _198 => _198.assertStorageIsWritable, 'call', _199 => _199()]);
7560
7691
  if (index < 0 || index >= this.#items.length) {
7561
7692
  throw new Error(
7562
7693
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -7589,7 +7720,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7589
7720
  }
7590
7721
  }
7591
7722
  clear() {
7592
- _optionalChain([this, 'access', _184 => _184._pool, 'optionalAccess', _185 => _185.assertStorageIsWritable, 'call', _186 => _186()]);
7723
+ _optionalChain([this, 'access', _200 => _200._pool, 'optionalAccess', _201 => _201.assertStorageIsWritable, 'call', _202 => _202()]);
7593
7724
  if (this._pool) {
7594
7725
  const ops = [];
7595
7726
  const reverseOps = [];
@@ -7623,7 +7754,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7623
7754
  }
7624
7755
  }
7625
7756
  set(index, item) {
7626
- _optionalChain([this, 'access', _187 => _187._pool, 'optionalAccess', _188 => _188.assertStorageIsWritable, 'call', _189 => _189()]);
7757
+ _optionalChain([this, 'access', _203 => _203._pool, 'optionalAccess', _204 => _204.assertStorageIsWritable, 'call', _205 => _205()]);
7627
7758
  if (index < 0 || index >= this.#items.length) {
7628
7759
  throw new Error(
7629
7760
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -7782,7 +7913,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7782
7913
  #shiftItemPosition(index, key) {
7783
7914
  const shiftedPosition = makePosition(
7784
7915
  key,
7785
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _190 => _190.#items, 'access', _191 => _191.at, 'call', _192 => _192(index + 1), 'optionalAccess', _193 => _193._parentPos]) : void 0
7916
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _206 => _206.#items, 'access', _207 => _207.at, 'call', _208 => _208(index + 1), 'optionalAccess', _209 => _209._parentPos]) : void 0
7786
7917
  );
7787
7918
  this.#updateItemPositionAt(index, shiftedPosition);
7788
7919
  }
@@ -8031,7 +8162,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
8031
8162
  * @param value The value of the element to add. Should be serializable to JSON.
8032
8163
  */
8033
8164
  set(key, value) {
8034
- _optionalChain([this, 'access', _194 => _194._pool, 'optionalAccess', _195 => _195.assertStorageIsWritable, 'call', _196 => _196()]);
8165
+ _optionalChain([this, 'access', _210 => _210._pool, 'optionalAccess', _211 => _211.assertStorageIsWritable, 'call', _212 => _212()]);
8035
8166
  const oldValue = this.#map.get(key);
8036
8167
  if (oldValue) {
8037
8168
  oldValue._detach();
@@ -8077,7 +8208,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
8077
8208
  * @returns true if an element existed and has been removed, or false if the element does not exist.
8078
8209
  */
8079
8210
  delete(key) {
8080
- _optionalChain([this, 'access', _197 => _197._pool, 'optionalAccess', _198 => _198.assertStorageIsWritable, 'call', _199 => _199()]);
8211
+ _optionalChain([this, 'access', _213 => _213._pool, 'optionalAccess', _214 => _214.assertStorageIsWritable, 'call', _215 => _215()]);
8081
8212
  const item = this.#map.get(key);
8082
8213
  if (item === void 0) {
8083
8214
  return false;
@@ -8247,6 +8378,8 @@ function reconcile(live, json, config) {
8247
8378
  return reconcileLiveList(live, json, config);
8248
8379
  } else if (isLiveMap(live) && isPlainObject(json)) {
8249
8380
  return reconcileLiveMap(live, config);
8381
+ } else if (isLiveFile(live) && shallow(live.data, json)) {
8382
+ return live;
8250
8383
  } else {
8251
8384
  return deepLiveify(json, config);
8252
8385
  }
@@ -8689,20 +8822,20 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8689
8822
  * Caveat: this method will not add changes to the undo/redo stack.
8690
8823
  */
8691
8824
  setLocal(key, value) {
8692
- _optionalChain([this, 'access', _200 => _200._pool, 'optionalAccess', _201 => _201.assertStorageIsWritable, 'call', _202 => _202()]);
8825
+ _optionalChain([this, 'access', _216 => _216._pool, 'optionalAccess', _217 => _217.assertStorageIsWritable, 'call', _218 => _218()]);
8693
8826
  const deleteResult = this.#prepareDelete(key);
8694
8827
  this.#local.set(key, value);
8695
8828
  this.invalidate();
8696
8829
  if (this._pool !== void 0 && this._id !== void 0) {
8697
- const ops = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _203 => _203[0]]), () => ( []));
8698
- const reverse = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _204 => _204[1]]), () => ( []));
8699
- const storageUpdates = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _205 => _205[2]]), () => ( /* @__PURE__ */ new Map()));
8830
+ const ops = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _219 => _219[0]]), () => ( []));
8831
+ const reverse = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _220 => _220[1]]), () => ( []));
8832
+ const storageUpdates = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _221 => _221[2]]), () => ( /* @__PURE__ */ new Map()));
8700
8833
  const existing = storageUpdates.get(this._id);
8701
8834
  storageUpdates.set(this._id, {
8702
8835
  node: this,
8703
8836
  type: "LiveObject",
8704
8837
  updates: {
8705
- ..._optionalChain([existing, 'optionalAccess', _206 => _206.updates]),
8838
+ ..._optionalChain([existing, 'optionalAccess', _222 => _222.updates]),
8706
8839
  [key]: { type: "update" }
8707
8840
  }
8708
8841
  });
@@ -8722,7 +8855,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8722
8855
  * #synced or pool/id are unavailable. Does NOT dispatch.
8723
8856
  */
8724
8857
  #prepareDelete(key) {
8725
- _optionalChain([this, 'access', _207 => _207._pool, 'optionalAccess', _208 => _208.assertStorageIsWritable, 'call', _209 => _209()]);
8858
+ _optionalChain([this, 'access', _223 => _223._pool, 'optionalAccess', _224 => _224.assertStorageIsWritable, 'call', _225 => _225()]);
8726
8859
  const k = key;
8727
8860
  if (this.#local.has(k) && !this.#synced.has(k)) {
8728
8861
  const oldValue2 = this.#local.get(k);
@@ -8798,7 +8931,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8798
8931
  const result = this.#prepareDelete(key);
8799
8932
  if (result) {
8800
8933
  const [ops, reverse, storageUpdates] = result;
8801
- _optionalChain([this, 'access', _210 => _210._pool, 'optionalAccess', _211 => _211.dispatch, 'call', _212 => _212(ops, reverse, storageUpdates)]);
8934
+ _optionalChain([this, 'access', _226 => _226._pool, 'optionalAccess', _227 => _227.dispatch, 'call', _228 => _228(ops, reverse, storageUpdates)]);
8802
8935
  }
8803
8936
  }
8804
8937
  /**
@@ -8806,7 +8939,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8806
8939
  * @param patch The object used to overrides properties
8807
8940
  */
8808
8941
  update(patch) {
8809
- _optionalChain([this, 'access', _213 => _213._pool, 'optionalAccess', _214 => _214.assertStorageIsWritable, 'call', _215 => _215()]);
8942
+ _optionalChain([this, 'access', _229 => _229._pool, 'optionalAccess', _230 => _230.assertStorageIsWritable, 'call', _231 => _231()]);
8810
8943
  if (_LiveObject.detectLargeObjects) {
8811
8944
  const data = {};
8812
8945
  for (const [key, value] of this.#synced) {
@@ -9173,8 +9306,31 @@ function isJsonEq(a, b) {
9173
9306
  }
9174
9307
  function diffNodeMap(prev, next) {
9175
9308
  const ops = [];
9176
- prev.forEach((_, id) => {
9177
- if (!next.get(id)) {
9309
+ const idsToRecreate = /* @__PURE__ */ new Set();
9310
+ next.forEach((nextCrdt, id) => {
9311
+ const currentCrdt = prev.get(id);
9312
+ if (currentCrdt === void 0) {
9313
+ return;
9314
+ }
9315
+ if (currentCrdt.type !== nextCrdt.type || currentCrdt.type === CrdtType.FILE && nextCrdt.type === CrdtType.FILE && (currentCrdt.data.id !== nextCrdt.data.id || currentCrdt.data.name !== nextCrdt.data.name || currentCrdt.data.size !== nextCrdt.data.size || currentCrdt.data.mimeType !== nextCrdt.data.mimeType)) {
9316
+ idsToRecreate.add(id);
9317
+ }
9318
+ });
9319
+ let foundDescendant = true;
9320
+ while (foundDescendant) {
9321
+ foundDescendant = false;
9322
+ for (const nodes of [prev, next]) {
9323
+ nodes.forEach((crdt, id) => {
9324
+ if (!idsToRecreate.has(id) && crdt.parentId !== void 0 && idsToRecreate.has(crdt.parentId)) {
9325
+ idsToRecreate.add(id);
9326
+ foundDescendant = true;
9327
+ }
9328
+ });
9329
+ }
9330
+ }
9331
+ prev.forEach((crdt, id) => {
9332
+ const parentWillBeRecreated = crdt.parentId !== void 0 && idsToRecreate.has(crdt.parentId);
9333
+ if ((!next.has(id) || idsToRecreate.has(id)) && !parentWillBeRecreated) {
9178
9334
  ops.push({ type: OpCode.DELETE_CRDT, id });
9179
9335
  }
9180
9336
  });
@@ -9185,7 +9341,7 @@ function diffNodeMap(prev, next) {
9185
9341
  }
9186
9342
  emitted.add(id);
9187
9343
  const parentId = crdt.parentId;
9188
- if (parentId !== void 0 && !prev.has(parentId)) {
9344
+ if (parentId !== void 0 && (!prev.has(parentId) || idsToRecreate.has(parentId))) {
9189
9345
  const parentCrdt = next.get(parentId);
9190
9346
  if (parentCrdt !== void 0) {
9191
9347
  emitCreate(parentId, parentCrdt);
@@ -9244,29 +9400,25 @@ function diffNodeMap(prev, next) {
9244
9400
  }
9245
9401
  next.forEach((crdt, id) => {
9246
9402
  const currentCrdt = prev.get(id);
9247
- if (currentCrdt) {
9248
- if (crdt.type === CrdtType.OBJECT) {
9249
- if (currentCrdt.type !== CrdtType.OBJECT) {
9250
- ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
9251
- } else {
9252
- const changed = /* @__PURE__ */ new Map();
9253
- for (const key of Object.keys(crdt.data)) {
9254
- const value = crdt.data[key];
9255
- if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
9256
- changed.set(key, value);
9257
- }
9258
- }
9259
- if (changed.size > 0) {
9260
- ops.push({
9261
- type: OpCode.UPDATE_OBJECT,
9262
- id,
9263
- data: Object.fromEntries(changed)
9264
- });
9403
+ if (currentCrdt && !idsToRecreate.has(id)) {
9404
+ if (crdt.type === CrdtType.OBJECT && currentCrdt.type === CrdtType.OBJECT) {
9405
+ const changed = /* @__PURE__ */ new Map();
9406
+ for (const key of Object.keys(crdt.data)) {
9407
+ const value = crdt.data[key];
9408
+ if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
9409
+ changed.set(key, value);
9265
9410
  }
9266
- for (const key of Object.keys(currentCrdt.data)) {
9267
- if (!(key in crdt.data)) {
9268
- ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
9269
- }
9411
+ }
9412
+ if (changed.size > 0) {
9413
+ ops.push({
9414
+ type: OpCode.UPDATE_OBJECT,
9415
+ id,
9416
+ data: Object.fromEntries(changed)
9417
+ });
9418
+ }
9419
+ for (const key of Object.keys(currentCrdt.data)) {
9420
+ if (!(key in crdt.data)) {
9421
+ ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
9270
9422
  }
9271
9423
  }
9272
9424
  }
@@ -9338,7 +9490,7 @@ function sendToPanel(message, options) {
9338
9490
  ...message,
9339
9491
  source: "liveblocks-devtools-client"
9340
9492
  };
9341
- if (!(_optionalChain([options, 'optionalAccess', _216 => _216.force]) || _bridgeActive)) {
9493
+ if (!(_optionalChain([options, 'optionalAccess', _232 => _232.force]) || _bridgeActive)) {
9342
9494
  return;
9343
9495
  }
9344
9496
  window.postMessage(fullMsg, "*");
@@ -9346,7 +9498,7 @@ function sendToPanel(message, options) {
9346
9498
  var eventSource = makeEventSource();
9347
9499
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
9348
9500
  window.addEventListener("message", (event) => {
9349
- if (event.source === window && _optionalChain([event, 'access', _217 => _217.data, 'optionalAccess', _218 => _218.source]) === "liveblocks-devtools-panel") {
9501
+ if (event.source === window && _optionalChain([event, 'access', _233 => _233.data, 'optionalAccess', _234 => _234.source]) === "liveblocks-devtools-panel") {
9350
9502
  eventSource.notify(event.data);
9351
9503
  } else {
9352
9504
  }
@@ -9488,7 +9640,7 @@ function fullSync(room) {
9488
9640
  msg: "room::sync::full",
9489
9641
  roomId: room.id,
9490
9642
  status: room.getStatus(),
9491
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _219 => _219.toTreeNode, 'call', _220 => _220("root"), 'access', _221 => _221.payload]), () => ( null)),
9643
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _235 => _235.toTreeNode, 'call', _236 => _236("root"), 'access', _237 => _237.payload]), () => ( null)),
9492
9644
  me,
9493
9645
  others
9494
9646
  });
@@ -10175,15 +10327,15 @@ function installBackgroundTabSpy() {
10175
10327
  const doc = typeof document !== "undefined" ? document : void 0;
10176
10328
  const inBackgroundSince = { current: null };
10177
10329
  function onVisibilityChange() {
10178
- if (_optionalChain([doc, 'optionalAccess', _222 => _222.visibilityState]) === "hidden") {
10330
+ if (_optionalChain([doc, 'optionalAccess', _238 => _238.visibilityState]) === "hidden") {
10179
10331
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
10180
10332
  } else {
10181
10333
  inBackgroundSince.current = null;
10182
10334
  }
10183
10335
  }
10184
- _optionalChain([doc, 'optionalAccess', _223 => _223.addEventListener, 'call', _224 => _224("visibilitychange", onVisibilityChange)]);
10336
+ _optionalChain([doc, 'optionalAccess', _239 => _239.addEventListener, 'call', _240 => _240("visibilitychange", onVisibilityChange)]);
10185
10337
  const unsub = () => {
10186
- _optionalChain([doc, 'optionalAccess', _225 => _225.removeEventListener, 'call', _226 => _226("visibilitychange", onVisibilityChange)]);
10338
+ _optionalChain([doc, 'optionalAccess', _241 => _241.removeEventListener, 'call', _242 => _242("visibilitychange", onVisibilityChange)]);
10187
10339
  };
10188
10340
  return [inBackgroundSince, unsub];
10189
10341
  }
@@ -10207,7 +10359,7 @@ function makeNodeMapBuffer() {
10207
10359
  function topLevelKeysOf(nodes) {
10208
10360
  const keys2 = /* @__PURE__ */ new Set();
10209
10361
  const root = nodes.get("root");
10210
- for (const key in _optionalChain([root, 'optionalAccess', _227 => _227.data])) {
10362
+ for (const key in _optionalChain([root, 'optionalAccess', _243 => _243.data])) {
10211
10363
  keys2.add(key);
10212
10364
  }
10213
10365
  for (const node of nodes.values()) {
@@ -10390,7 +10542,7 @@ function createRoom(options, config) {
10390
10542
  }
10391
10543
  }
10392
10544
  function isStorageWritable() {
10393
- const permissionMatrix = _optionalChain([context, 'access', _228 => _228.dynamicSessionInfoSig, 'access', _229 => _229.get, 'call', _230 => _230(), 'optionalAccess', _231 => _231.permissionMatrix]);
10545
+ const permissionMatrix = _optionalChain([context, 'access', _244 => _244.dynamicSessionInfoSig, 'access', _245 => _245.get, 'call', _246 => _246(), 'optionalAccess', _247 => _247.permissionMatrix]);
10394
10546
  return permissionMatrix !== void 0 ? hasPermissionAccess(permissionMatrix, "storage", "write") : true;
10395
10547
  }
10396
10548
  const eventHub = {
@@ -10510,7 +10662,7 @@ function createRoom(options, config) {
10510
10662
  context.pool
10511
10663
  );
10512
10664
  }
10513
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _232 => _232.get, 'call', _233 => _233(), 'optionalAccess', _234 => _234.canWrite]), () => ( true));
10665
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _248 => _248.get, 'call', _249 => _249(), 'optionalAccess', _250 => _250.canWrite]), () => ( true));
10514
10666
  const serverTopLevelKeys = topLevelKeysOf(nodes);
10515
10667
  const root = context.root;
10516
10668
  disableHistory(() => {
@@ -10743,7 +10895,7 @@ function createRoom(options, config) {
10743
10895
  }
10744
10896
  context.myPresence.patch(patch);
10745
10897
  if (context.activeBatch) {
10746
- if (_optionalChain([options2, 'optionalAccess', _235 => _235.addToHistory])) {
10898
+ if (_optionalChain([options2, 'optionalAccess', _251 => _251.addToHistory])) {
10747
10899
  context.activeBatch.reverseOps.pushLeft({
10748
10900
  type: "presence",
10749
10901
  data: oldValues
@@ -10752,7 +10904,7 @@ function createRoom(options, config) {
10752
10904
  context.activeBatch.updates.presence = true;
10753
10905
  } else {
10754
10906
  flushNowOrSoon();
10755
- if (_optionalChain([options2, 'optionalAccess', _236 => _236.addToHistory])) {
10907
+ if (_optionalChain([options2, 'optionalAccess', _252 => _252.addToHistory])) {
10756
10908
  addToUndoStack([{ type: "presence", data: oldValues }]);
10757
10909
  }
10758
10910
  notify({ presence: true });
@@ -10931,11 +11083,11 @@ function createRoom(options, config) {
10931
11083
  break;
10932
11084
  }
10933
11085
  case ServerMsgCode.STORAGE_CHUNK:
10934
- _optionalChain([stopwatch, 'optionalAccess', _237 => _237.lap, 'call', _238 => _238()]);
11086
+ _optionalChain([stopwatch, 'optionalAccess', _253 => _253.lap, 'call', _254 => _254()]);
10935
11087
  nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
10936
11088
  break;
10937
11089
  case ServerMsgCode.STORAGE_STREAM_END: {
10938
- const timing = _optionalChain([stopwatch, 'optionalAccess', _239 => _239.stop, 'call', _240 => _240()]);
11090
+ const timing = _optionalChain([stopwatch, 'optionalAccess', _255 => _255.stop, 'call', _256 => _256()]);
10939
11091
  if (timing) {
10940
11092
  const ms = (v) => `${v.toFixed(1)}ms`;
10941
11093
  const rest = timing.laps.slice(1);
@@ -11070,11 +11222,11 @@ function createRoom(options, config) {
11070
11222
  } else if (pendingFeedsRequests.has(requestId)) {
11071
11223
  const pending = pendingFeedsRequests.get(requestId);
11072
11224
  pendingFeedsRequests.delete(requestId);
11073
- _optionalChain([pending, 'optionalAccess', _241 => _241.reject, 'call', _242 => _242(err)]);
11225
+ _optionalChain([pending, 'optionalAccess', _257 => _257.reject, 'call', _258 => _258(err)]);
11074
11226
  } else if (pendingFeedMessagesRequests.has(requestId)) {
11075
11227
  const pending = pendingFeedMessagesRequests.get(requestId);
11076
11228
  pendingFeedMessagesRequests.delete(requestId);
11077
- _optionalChain([pending, 'optionalAccess', _243 => _243.reject, 'call', _244 => _244(err)]);
11229
+ _optionalChain([pending, 'optionalAccess', _259 => _259.reject, 'call', _260 => _260(err)]);
11078
11230
  }
11079
11231
  eventHub.feeds.notify(message);
11080
11232
  break;
@@ -11228,10 +11380,10 @@ function createRoom(options, config) {
11228
11380
  timeoutId,
11229
11381
  kind,
11230
11382
  feedId,
11231
- messageId: _optionalChain([options2, 'optionalAccess', _245 => _245.messageId]),
11232
- expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _246 => _246.expectedClientMessageId])
11383
+ messageId: _optionalChain([options2, 'optionalAccess', _261 => _261.messageId]),
11384
+ expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _262 => _262.expectedClientMessageId])
11233
11385
  });
11234
- if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _247 => _247.expectedClientMessageId]) === void 0) {
11386
+ if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _263 => _263.expectedClientMessageId]) === void 0) {
11235
11387
  const q = _nullishCoalesce(pendingAddMessageFifoByFeed.get(feedId), () => ( []));
11236
11388
  q.push(requestId);
11237
11389
  pendingAddMessageFifoByFeed.set(feedId, q);
@@ -11282,10 +11434,10 @@ function createRoom(options, config) {
11282
11434
  }
11283
11435
  if (!matched) {
11284
11436
  const q = pendingAddMessageFifoByFeed.get(message.feedId);
11285
- const headId = _optionalChain([q, 'optionalAccess', _248 => _248[0]]);
11437
+ const headId = _optionalChain([q, 'optionalAccess', _264 => _264[0]]);
11286
11438
  if (headId !== void 0) {
11287
11439
  const pending = pendingFeedMutations.get(headId);
11288
- if (_optionalChain([pending, 'optionalAccess', _249 => _249.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
11440
+ if (_optionalChain([pending, 'optionalAccess', _265 => _265.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
11289
11441
  settleFeedMutation(headId, "ok");
11290
11442
  }
11291
11443
  }
@@ -11321,7 +11473,7 @@ function createRoom(options, config) {
11321
11473
  const unacknowledgedOps2 = [...context.unacknowledgedOps.values()];
11322
11474
  createOrUpdateRootFromMessage(nodes);
11323
11475
  applyAndSendOfflineOps(unacknowledgedOps2);
11324
- _optionalChain([_resolveStoragePromise, 'optionalCall', _250 => _250()]);
11476
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _266 => _266()]);
11325
11477
  notifyStorageStatus();
11326
11478
  eventHub.storageDidLoad.notify();
11327
11479
  }
@@ -11330,7 +11482,7 @@ function createRoom(options, config) {
11330
11482
  if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
11331
11483
  messages.push({ type: ClientMsgCode.FETCH_STORAGE });
11332
11484
  nodeMapBuffer.take();
11333
- _optionalChain([stopwatch, 'optionalAccess', _251 => _251.start, 'call', _252 => _252()]);
11485
+ _optionalChain([stopwatch, 'optionalAccess', _267 => _267.start, 'call', _268 => _268()]);
11334
11486
  }
11335
11487
  }
11336
11488
  function startLoadingStorage() {
@@ -11384,10 +11536,10 @@ function createRoom(options, config) {
11384
11536
  const message = {
11385
11537
  type: ClientMsgCode.FETCH_FEEDS,
11386
11538
  requestId,
11387
- cursor: _optionalChain([options2, 'optionalAccess', _253 => _253.cursor]),
11388
- since: _optionalChain([options2, 'optionalAccess', _254 => _254.since]),
11389
- limit: _optionalChain([options2, 'optionalAccess', _255 => _255.limit]),
11390
- metadata: _optionalChain([options2, 'optionalAccess', _256 => _256.metadata])
11539
+ cursor: _optionalChain([options2, 'optionalAccess', _269 => _269.cursor]),
11540
+ since: _optionalChain([options2, 'optionalAccess', _270 => _270.since]),
11541
+ limit: _optionalChain([options2, 'optionalAccess', _271 => _271.limit]),
11542
+ metadata: _optionalChain([options2, 'optionalAccess', _272 => _272.metadata])
11391
11543
  };
11392
11544
  context.buffer.messages.push(message);
11393
11545
  flushNowOrSoon();
@@ -11407,9 +11559,9 @@ function createRoom(options, config) {
11407
11559
  type: ClientMsgCode.FETCH_FEED_MESSAGES,
11408
11560
  requestId,
11409
11561
  feedId,
11410
- cursor: _optionalChain([options2, 'optionalAccess', _257 => _257.cursor]),
11411
- since: _optionalChain([options2, 'optionalAccess', _258 => _258.since]),
11412
- limit: _optionalChain([options2, 'optionalAccess', _259 => _259.limit])
11562
+ cursor: _optionalChain([options2, 'optionalAccess', _273 => _273.cursor]),
11563
+ since: _optionalChain([options2, 'optionalAccess', _274 => _274.since]),
11564
+ limit: _optionalChain([options2, 'optionalAccess', _275 => _275.limit])
11413
11565
  };
11414
11566
  context.buffer.messages.push(message);
11415
11567
  flushNowOrSoon();
@@ -11428,8 +11580,8 @@ function createRoom(options, config) {
11428
11580
  type: ClientMsgCode.ADD_FEED,
11429
11581
  requestId,
11430
11582
  feedId,
11431
- metadata: _optionalChain([options2, 'optionalAccess', _260 => _260.metadata]),
11432
- createdAt: _optionalChain([options2, 'optionalAccess', _261 => _261.createdAt])
11583
+ metadata: _optionalChain([options2, 'optionalAccess', _276 => _276.metadata]),
11584
+ createdAt: _optionalChain([options2, 'optionalAccess', _277 => _277.createdAt])
11433
11585
  };
11434
11586
  context.buffer.messages.push(message);
11435
11587
  flushNowOrSoon();
@@ -11463,15 +11615,15 @@ function createRoom(options, config) {
11463
11615
  function addFeedMessage(feedId, data, options2) {
11464
11616
  const requestId = nanoid();
11465
11617
  const promise = registerFeedMutation(requestId, "add-message", feedId, {
11466
- expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _262 => _262.id])
11618
+ expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _278 => _278.id])
11467
11619
  });
11468
11620
  const message = {
11469
11621
  type: ClientMsgCode.ADD_FEED_MESSAGE,
11470
11622
  requestId,
11471
11623
  feedId,
11472
11624
  data,
11473
- id: _optionalChain([options2, 'optionalAccess', _263 => _263.id]),
11474
- createdAt: _optionalChain([options2, 'optionalAccess', _264 => _264.createdAt])
11625
+ id: _optionalChain([options2, 'optionalAccess', _279 => _279.id]),
11626
+ createdAt: _optionalChain([options2, 'optionalAccess', _280 => _280.createdAt])
11475
11627
  };
11476
11628
  context.buffer.messages.push(message);
11477
11629
  flushNowOrSoon();
@@ -11488,7 +11640,7 @@ function createRoom(options, config) {
11488
11640
  feedId,
11489
11641
  messageId,
11490
11642
  data,
11491
- updatedAt: _optionalChain([options2, 'optionalAccess', _265 => _265.updatedAt])
11643
+ updatedAt: _optionalChain([options2, 'optionalAccess', _281 => _281.updatedAt])
11492
11644
  };
11493
11645
  context.buffer.messages.push(message);
11494
11646
  flushNowOrSoon();
@@ -11695,8 +11847,8 @@ function createRoom(options, config) {
11695
11847
  async function getThreads(options2) {
11696
11848
  return httpClient.getThreads({
11697
11849
  roomId,
11698
- query: _optionalChain([options2, 'optionalAccess', _266 => _266.query]),
11699
- cursor: _optionalChain([options2, 'optionalAccess', _267 => _267.cursor])
11850
+ query: _optionalChain([options2, 'optionalAccess', _282 => _282.query]),
11851
+ cursor: _optionalChain([options2, 'optionalAccess', _283 => _283.cursor])
11700
11852
  });
11701
11853
  }
11702
11854
  async function getThread(threadId) {
@@ -11829,7 +11981,7 @@ function createRoom(options, config) {
11829
11981
  function getSubscriptionSettings(options2) {
11830
11982
  return httpClient.getSubscriptionSettings({
11831
11983
  roomId,
11832
- signal: _optionalChain([options2, 'optionalAccess', _268 => _268.signal])
11984
+ signal: _optionalChain([options2, 'optionalAccess', _284 => _284.signal])
11833
11985
  });
11834
11986
  }
11835
11987
  function updateSubscriptionSettings(settings) {
@@ -11851,7 +12003,7 @@ function createRoom(options, config) {
11851
12003
  {
11852
12004
  [kInternal]: {
11853
12005
  get presenceBuffer() {
11854
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _269 => _269.buffer, 'access', _270 => _270.presenceUpdates, 'optionalAccess', _271 => _271.data]), () => ( null)));
12006
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _285 => _285.buffer, 'access', _286 => _286.presenceUpdates, 'optionalAccess', _287 => _287.data]), () => ( null)));
11855
12007
  },
11856
12008
  // prettier-ignore
11857
12009
  get undoStack() {
@@ -11866,15 +12018,15 @@ function createRoom(options, config) {
11866
12018
  return context.yjsProvider;
11867
12019
  },
11868
12020
  setYjsProvider(newProvider) {
11869
- _optionalChain([context, 'access', _272 => _272.yjsProvider, 'optionalAccess', _273 => _273.off, 'call', _274 => _274("status", yjsStatusDidChange)]);
12021
+ _optionalChain([context, 'access', _288 => _288.yjsProvider, 'optionalAccess', _289 => _289.off, 'call', _290 => _290("status", yjsStatusDidChange)]);
11870
12022
  context.yjsProvider = newProvider;
11871
- _optionalChain([newProvider, 'optionalAccess', _275 => _275.on, 'call', _276 => _276("status", yjsStatusDidChange)]);
12023
+ _optionalChain([newProvider, 'optionalAccess', _291 => _291.on, 'call', _292 => _292("status", yjsStatusDidChange)]);
11872
12024
  context.yjsProviderDidChange.notify();
11873
12025
  },
11874
12026
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
11875
12027
  // send metadata when using a text editor
11876
12028
  reportTextEditor,
11877
- getPermissionMatrix: () => _optionalChain([context, 'access', _277 => _277.dynamicSessionInfoSig, 'access', _278 => _278.get, 'call', _279 => _279(), 'optionalAccess', _280 => _280.permissionMatrix]),
12029
+ getPermissionMatrix: () => _optionalChain([context, 'access', _293 => _293.dynamicSessionInfoSig, 'access', _294 => _294.get, 'call', _295 => _295(), 'optionalAccess', _296 => _296.permissionMatrix]),
11878
12030
  // create a text mention when using a text editor
11879
12031
  createTextMention,
11880
12032
  // delete a text mention when using a text editor
@@ -11937,7 +12089,7 @@ ${dumpPool(
11937
12089
  source.dispose();
11938
12090
  }
11939
12091
  eventHub.roomWillDestroy.notify();
11940
- _optionalChain([context, 'access', _281 => _281.yjsProvider, 'optionalAccess', _282 => _282.off, 'call', _283 => _283("status", yjsStatusDidChange)]);
12092
+ _optionalChain([context, 'access', _297 => _297.yjsProvider, 'optionalAccess', _298 => _298.off, 'call', _299 => _299("status", yjsStatusDidChange)]);
11941
12093
  syncSourceForStorage.destroy();
11942
12094
  syncSourceForYjs.destroy();
11943
12095
  uninstallBgTabSpy();
@@ -12101,7 +12253,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
12101
12253
  }
12102
12254
  if (isLiveNode(first)) {
12103
12255
  const node = first;
12104
- if (_optionalChain([options, 'optionalAccess', _284 => _284.isDeep])) {
12256
+ if (_optionalChain([options, 'optionalAccess', _300 => _300.isDeep])) {
12105
12257
  const storageCallback = second;
12106
12258
  return subscribeToLiveStructureDeeply(node, storageCallback);
12107
12259
  } else {
@@ -12191,8 +12343,8 @@ function createClient(options) {
12191
12343
  const authManager = createAuthManager(options, (token) => {
12192
12344
  currentUserId.set(() => token.uid);
12193
12345
  });
12194
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _285 => _285.polyfills, 'optionalAccess', _286 => _286.fetch]) || /* istanbul ignore next */
12195
- _optionalChain([globalThis, 'access', _287 => _287.fetch, 'optionalAccess', _288 => _288.bind, 'call', _289 => _289(globalThis)]);
12346
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _301 => _301.polyfills, 'optionalAccess', _302 => _302.fetch]) || /* istanbul ignore next */
12347
+ _optionalChain([globalThis, 'access', _303 => _303.fetch, 'optionalAccess', _304 => _304.bind, 'call', _305 => _305(globalThis)]);
12196
12348
  const httpClient = createApiClient({
12197
12349
  baseUrl,
12198
12350
  fetchPolyfill,
@@ -12209,7 +12361,7 @@ function createClient(options) {
12209
12361
  delegates: {
12210
12362
  createSocket: makeCreateSocketDelegateForAi(
12211
12363
  baseUrl,
12212
- _optionalChain([clientOptions, 'access', _290 => _290.polyfills, 'optionalAccess', _291 => _291.WebSocket])
12364
+ _optionalChain([clientOptions, 'access', _306 => _306.polyfills, 'optionalAccess', _307 => _307.WebSocket])
12213
12365
  ),
12214
12366
  authenticate: async () => {
12215
12367
  const resp = await authManager.getAuthValue({
@@ -12280,7 +12432,7 @@ function createClient(options) {
12280
12432
  createSocket: makeCreateSocketDelegateForRoom(
12281
12433
  roomId,
12282
12434
  baseUrl,
12283
- _optionalChain([clientOptions, 'access', _292 => _292.polyfills, 'optionalAccess', _293 => _293.WebSocket])
12435
+ _optionalChain([clientOptions, 'access', _308 => _308.polyfills, 'optionalAccess', _309 => _309.WebSocket])
12284
12436
  ),
12285
12437
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
12286
12438
  })),
@@ -12302,7 +12454,7 @@ function createClient(options) {
12302
12454
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
12303
12455
  if (shouldConnect) {
12304
12456
  if (typeof atob === "undefined") {
12305
- if (_optionalChain([clientOptions, 'access', _294 => _294.polyfills, 'optionalAccess', _295 => _295.atob]) === void 0) {
12457
+ if (_optionalChain([clientOptions, 'access', _310 => _310.polyfills, 'optionalAccess', _311 => _311.atob]) === void 0) {
12306
12458
  throw new Error(
12307
12459
  "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"
12308
12460
  );
@@ -12314,7 +12466,7 @@ function createClient(options) {
12314
12466
  return leaseRoom(newRoomDetails);
12315
12467
  }
12316
12468
  function getRoom(roomId) {
12317
- const room = _optionalChain([roomsById, 'access', _296 => _296.get, 'call', _297 => _297(roomId), 'optionalAccess', _298 => _298.room]);
12469
+ const room = _optionalChain([roomsById, 'access', _312 => _312.get, 'call', _313 => _313(roomId), 'optionalAccess', _314 => _314.room]);
12318
12470
  return room ? room : null;
12319
12471
  }
12320
12472
  function logout() {
@@ -12330,7 +12482,7 @@ function createClient(options) {
12330
12482
  const batchedResolveUsers = new Batch(
12331
12483
  async (batchedUserIds) => {
12332
12484
  const userIds = batchedUserIds.flat();
12333
- const users = await _optionalChain([resolveUsers, 'optionalCall', _299 => _299({ userIds })]);
12485
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _315 => _315({ userIds })]);
12334
12486
  warnOnceIf(
12335
12487
  !resolveUsers,
12336
12488
  "Set the resolveUsers option in createClient to specify user info."
@@ -12347,7 +12499,7 @@ function createClient(options) {
12347
12499
  const batchedResolveRoomsInfo = new Batch(
12348
12500
  async (batchedRoomIds) => {
12349
12501
  const roomIds = batchedRoomIds.flat();
12350
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _300 => _300({ roomIds })]);
12502
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _316 => _316({ roomIds })]);
12351
12503
  warnOnceIf(
12352
12504
  !resolveRoomsInfo,
12353
12505
  "Set the resolveRoomsInfo option in createClient to specify room info."
@@ -12364,7 +12516,7 @@ function createClient(options) {
12364
12516
  const batchedResolveGroupsInfo = new Batch(
12365
12517
  async (batchedGroupIds) => {
12366
12518
  const groupIds = batchedGroupIds.flat();
12367
- const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _301 => _301({ groupIds })]);
12519
+ const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _317 => _317({ groupIds })]);
12368
12520
  warnOnceIf(
12369
12521
  !resolveGroupsInfo,
12370
12522
  "Set the resolveGroupsInfo option in createClient to specify group info."
@@ -12423,7 +12575,7 @@ function createClient(options) {
12423
12575
  }
12424
12576
  };
12425
12577
  const win = typeof window !== "undefined" ? window : void 0;
12426
- _optionalChain([win, 'optionalAccess', _302 => _302.addEventListener, 'call', _303 => _303("beforeunload", maybePreventClose)]);
12578
+ _optionalChain([win, 'optionalAccess', _318 => _318.addEventListener, 'call', _319 => _319("beforeunload", maybePreventClose)]);
12427
12579
  }
12428
12580
  async function getNotificationSettings(options2) {
12429
12581
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -12551,7 +12703,7 @@ var commentBodyElementsTypes = {
12551
12703
  mention: "inline"
12552
12704
  };
12553
12705
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
12554
- if (!body || !_optionalChain([body, 'optionalAccess', _304 => _304.content])) {
12706
+ if (!body || !_optionalChain([body, 'optionalAccess', _320 => _320.content])) {
12555
12707
  return;
12556
12708
  }
12557
12709
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -12561,13 +12713,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
12561
12713
  for (const block of body.content) {
12562
12714
  if (type === "all" || type === "block") {
12563
12715
  if (guard(block)) {
12564
- _optionalChain([visitor, 'optionalCall', _305 => _305(block)]);
12716
+ _optionalChain([visitor, 'optionalCall', _321 => _321(block)]);
12565
12717
  }
12566
12718
  }
12567
12719
  if (type === "all" || type === "inline") {
12568
12720
  for (const inline of block.children) {
12569
12721
  if (guard(inline)) {
12570
- _optionalChain([visitor, 'optionalCall', _306 => _306(inline)]);
12722
+ _optionalChain([visitor, 'optionalCall', _322 => _322(inline)]);
12571
12723
  }
12572
12724
  }
12573
12725
  }
@@ -12737,7 +12889,7 @@ var stringifyCommentBodyPlainElements = {
12737
12889
  text: ({ element }) => element.text,
12738
12890
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
12739
12891
  mention: ({ element, user, group }) => {
12740
- return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _307 => _307.name]), () => ( _optionalChain([group, 'optionalAccess', _308 => _308.name]))), () => ( element.id))}`;
12892
+ return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _323 => _323.name]), () => ( _optionalChain([group, 'optionalAccess', _324 => _324.name]))), () => ( element.id))}`;
12741
12893
  }
12742
12894
  };
12743
12895
  var stringifyCommentBodyHtmlElements = {
@@ -12767,7 +12919,7 @@ var stringifyCommentBodyHtmlElements = {
12767
12919
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
12768
12920
  },
12769
12921
  mention: ({ element, user, group }) => {
12770
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _309 => _309.name]) ? html`${_optionalChain([user, 'optionalAccess', _310 => _310.name])}` : _optionalChain([group, 'optionalAccess', _311 => _311.name]) ? html`${_optionalChain([group, 'optionalAccess', _312 => _312.name])}` : element.id}</span>`;
12922
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _325 => _325.name]) ? html`${_optionalChain([user, 'optionalAccess', _326 => _326.name])}` : _optionalChain([group, 'optionalAccess', _327 => _327.name]) ? html`${_optionalChain([group, 'optionalAccess', _328 => _328.name])}` : element.id}</span>`;
12771
12923
  }
12772
12924
  };
12773
12925
  var stringifyCommentBodyMarkdownElements = {
@@ -12797,20 +12949,20 @@ var stringifyCommentBodyMarkdownElements = {
12797
12949
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
12798
12950
  },
12799
12951
  mention: ({ element, user, group }) => {
12800
- return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _313 => _313.name]), () => ( _optionalChain([group, 'optionalAccess', _314 => _314.name]))), () => ( element.id))}`;
12952
+ return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _329 => _329.name]), () => ( _optionalChain([group, 'optionalAccess', _330 => _330.name]))), () => ( element.id))}`;
12801
12953
  }
12802
12954
  };
12803
12955
  async function stringifyCommentBody(body, options) {
12804
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _315 => _315.format]), () => ( "plain"));
12805
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _316 => _316.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
12956
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _331 => _331.format]), () => ( "plain"));
12957
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _332 => _332.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
12806
12958
  const elements = {
12807
12959
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
12808
- ..._optionalChain([options, 'optionalAccess', _317 => _317.elements])
12960
+ ..._optionalChain([options, 'optionalAccess', _333 => _333.elements])
12809
12961
  };
12810
12962
  const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
12811
12963
  body,
12812
- _optionalChain([options, 'optionalAccess', _318 => _318.resolveUsers]),
12813
- _optionalChain([options, 'optionalAccess', _319 => _319.resolveGroupsInfo])
12964
+ _optionalChain([options, 'optionalAccess', _334 => _334.resolveUsers]),
12965
+ _optionalChain([options, 'optionalAccess', _335 => _335.resolveGroupsInfo])
12814
12966
  );
12815
12967
  const blocks = body.content.flatMap((block, blockIndex) => {
12816
12968
  switch (block.type) {
@@ -12950,9 +13102,9 @@ function makePoller(callback, intervalMs, options) {
12950
13102
  const startTime = performance.now();
12951
13103
  const doc = typeof document !== "undefined" ? document : void 0;
12952
13104
  const win = typeof window !== "undefined" ? window : void 0;
12953
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _320 => _320.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
13105
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _336 => _336.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
12954
13106
  const context = {
12955
- inForeground: _optionalChain([doc, 'optionalAccess', _321 => _321.visibilityState]) !== "hidden",
13107
+ inForeground: _optionalChain([doc, 'optionalAccess', _337 => _337.visibilityState]) !== "hidden",
12956
13108
  lastSuccessfulPollAt: startTime,
12957
13109
  count: 0,
12958
13110
  backoff: 0
@@ -13033,11 +13185,11 @@ function makePoller(callback, intervalMs, options) {
13033
13185
  pollNowIfStale();
13034
13186
  }
13035
13187
  function onVisibilityChange() {
13036
- setInForeground(_optionalChain([doc, 'optionalAccess', _322 => _322.visibilityState]) !== "hidden");
13188
+ setInForeground(_optionalChain([doc, 'optionalAccess', _338 => _338.visibilityState]) !== "hidden");
13037
13189
  }
13038
- _optionalChain([doc, 'optionalAccess', _323 => _323.addEventListener, 'call', _324 => _324("visibilitychange", onVisibilityChange)]);
13039
- _optionalChain([win, 'optionalAccess', _325 => _325.addEventListener, 'call', _326 => _326("online", onVisibilityChange)]);
13040
- _optionalChain([win, 'optionalAccess', _327 => _327.addEventListener, 'call', _328 => _328("focus", pollNowIfStale)]);
13190
+ _optionalChain([doc, 'optionalAccess', _339 => _339.addEventListener, 'call', _340 => _340("visibilitychange", onVisibilityChange)]);
13191
+ _optionalChain([win, 'optionalAccess', _341 => _341.addEventListener, 'call', _342 => _342("online", onVisibilityChange)]);
13192
+ _optionalChain([win, 'optionalAccess', _343 => _343.addEventListener, 'call', _344 => _344("focus", pollNowIfStale)]);
13041
13193
  fsm.start();
13042
13194
  return {
13043
13195
  inc,