@liveblocks/core 3.3.3 → 3.4.0-alpha1

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.3.3";
9
+ var PKG_VERSION = "3.4.0-alpha1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -243,6 +243,14 @@ function memoizeOnSuccess(factoryFn) {
243
243
  return cached;
244
244
  };
245
245
  }
246
+ function findLastIndex(arr, predicate) {
247
+ for (let i = arr.length - 1; i >= 0; i--) {
248
+ if (predicate(arr[i], i, arr)) {
249
+ return i;
250
+ }
251
+ }
252
+ return -1;
253
+ }
246
254
 
247
255
  // src/lib/signals.ts
248
256
  var kSinks = Symbol("kSinks");
@@ -1332,6 +1340,9 @@ function sanitizeUrl(url2) {
1332
1340
  if (url2.startsWith("www.")) {
1333
1341
  url2 = "https://" + url2;
1334
1342
  }
1343
+ if (url2 === "#") {
1344
+ return url2;
1345
+ }
1335
1346
  try {
1336
1347
  const isAbsolute = ABSOLUTE_URL_REGEX.test(url2);
1337
1348
  const urlObject = new URL(
@@ -1375,6 +1386,14 @@ function generateUrl(url2, params, hash) {
1375
1386
  }
1376
1387
  return isAbsolute ? urlObject.href : urlObject.href.replace(PLACEHOLDER_BASE_URL, "");
1377
1388
  }
1389
+ function isUrl(string) {
1390
+ try {
1391
+ new URL(string);
1392
+ return true;
1393
+ } catch (_) {
1394
+ return false;
1395
+ }
1396
+ }
1378
1397
 
1379
1398
  // src/api-client.ts
1380
1399
  function createApiClient({
@@ -3798,8 +3817,102 @@ function parseAuthToken(rawTokenString) {
3798
3817
  };
3799
3818
  }
3800
3819
 
3820
+ // src/lib/parsePartialJsonObject.ts
3821
+ function parsePartialJsonObject(partial) {
3822
+ partial = partial.trimStart();
3823
+ if (partial.charAt(0) !== "{") {
3824
+ return {};
3825
+ }
3826
+ if (partial.trimEnd().endsWith("}")) {
3827
+ const quickCheck = tryParseJson(partial);
3828
+ if (quickCheck) {
3829
+ return quickCheck;
3830
+ }
3831
+ }
3832
+ let result = partial;
3833
+ let quoteCount = 0;
3834
+ let escaped = false;
3835
+ for (let i = 0; i < result.length; i++) {
3836
+ const char = result[i];
3837
+ if (escaped) {
3838
+ escaped = false;
3839
+ } else if (char === "\\") {
3840
+ escaped = true;
3841
+ } else if (char === '"') {
3842
+ quoteCount++;
3843
+ }
3844
+ }
3845
+ if (quoteCount % 2 === 1) {
3846
+ result += '"';
3847
+ }
3848
+ result = result.trimEnd();
3849
+ if (result.endsWith(",")) {
3850
+ result = result.slice(0, -1);
3851
+ }
3852
+ if (result.endsWith(".")) {
3853
+ result = result.slice(0, -1);
3854
+ }
3855
+ const stack = [];
3856
+ let inString = false;
3857
+ escaped = false;
3858
+ for (let i = 0; i < result.length; i++) {
3859
+ const char = result[i];
3860
+ if (inString) {
3861
+ if (escaped) {
3862
+ escaped = false;
3863
+ } else if (char === "\\") {
3864
+ escaped = true;
3865
+ } else if (char === '"') {
3866
+ inString = false;
3867
+ }
3868
+ } else {
3869
+ if (char === '"') {
3870
+ inString = true;
3871
+ } else if (char === "{") {
3872
+ stack.push("}");
3873
+ } else if (char === "[") {
3874
+ stack.push("]");
3875
+ } else if (char === "}" && stack.length > 0 && stack[stack.length - 1] === "}") {
3876
+ stack.pop();
3877
+ } else if (char === "]" && stack.length > 0 && stack[stack.length - 1] === "]") {
3878
+ stack.pop();
3879
+ }
3880
+ }
3881
+ }
3882
+ const suffix = stack.reverse().join("");
3883
+ {
3884
+ const attempt = tryParseJson(result + suffix);
3885
+ if (attempt) {
3886
+ return attempt;
3887
+ }
3888
+ }
3889
+ if (result.endsWith(":")) {
3890
+ result = result.slice(0, -1);
3891
+ }
3892
+ if (result.endsWith('"')) {
3893
+ let pos = result.length - 2;
3894
+ escaped = false;
3895
+ while (pos >= 0) {
3896
+ if (escaped) {
3897
+ escaped = false;
3898
+ } else if (result[pos] === "\\") {
3899
+ escaped = true;
3900
+ } else if (result[pos] === '"') {
3901
+ result = result.slice(0, pos);
3902
+ break;
3903
+ }
3904
+ pos--;
3905
+ }
3906
+ }
3907
+ if (result.endsWith(",")) {
3908
+ result = result.slice(0, -1);
3909
+ }
3910
+ result += suffix;
3911
+ return _nullishCoalesce(tryParseJson(result), () => ( {}));
3912
+ }
3913
+
3801
3914
  // src/types/ai.ts
3802
- function appendDelta(content, delta) {
3915
+ function patchContentWithDelta(content, delta) {
3803
3916
  const lastPart = content[content.length - 1];
3804
3917
  switch (delta.type) {
3805
3918
  case "text-delta":
@@ -3819,9 +3932,44 @@ function appendDelta(content, delta) {
3819
3932
  });
3820
3933
  }
3821
3934
  break;
3822
- case "tool-invocation":
3823
- content.push(delta);
3935
+ case "tool-stream": {
3936
+ let _cacheKey = "";
3937
+ let _cachedArgs = {};
3938
+ const toolInvocation = {
3939
+ type: "tool-invocation",
3940
+ stage: "receiving",
3941
+ invocationId: delta.invocationId,
3942
+ name: delta.name,
3943
+ partialArgsText: "",
3944
+ get partialArgs() {
3945
+ if (this.partialArgsText !== _cacheKey) {
3946
+ _cachedArgs = parsePartialJsonObject(this.partialArgsText);
3947
+ _cacheKey = this.partialArgsText;
3948
+ }
3949
+ return _cachedArgs;
3950
+ }
3951
+ };
3952
+ content.push(toolInvocation);
3953
+ break;
3954
+ }
3955
+ case "tool-delta": {
3956
+ if (_optionalChain([lastPart, 'optionalAccess', _57 => _57.type]) === "tool-invocation" && lastPart.stage === "receiving") {
3957
+ lastPart.partialArgsText += delta.delta;
3958
+ }
3959
+ break;
3960
+ }
3961
+ case "tool-invocation": {
3962
+ const existingIndex = findLastIndex(
3963
+ content,
3964
+ (part) => part.type === "tool-invocation" && part.invocationId === delta.invocationId
3965
+ );
3966
+ if (existingIndex > -1) {
3967
+ content[existingIndex] = delta;
3968
+ } else {
3969
+ content.push(delta);
3970
+ }
3824
3971
  break;
3972
+ }
3825
3973
  default:
3826
3974
  return assertNever(delta, "Unhandled case");
3827
3975
  }
@@ -3908,7 +4056,7 @@ function createStore_forTools() {
3908
4056
  return DerivedSignal.from(() => {
3909
4057
  return (
3910
4058
  // A tool that's registered and scoped to a specific chat ID...
3911
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _57 => _57.get, 'call', _58 => _58()]), () => ( // ...or a globally registered tool
4059
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _58 => _58.get, 'call', _59 => _59()]), () => ( // ...or a globally registered tool
3912
4060
  toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
3913
4061
  );
3914
4062
  });
@@ -3938,8 +4086,8 @@ function createStore_forTools() {
3938
4086
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
3939
4087
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
3940
4088
  return Array.from([
3941
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _59 => _59.entries, 'call', _60 => _60()]), () => ( [])),
3942
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _61 => _61.entries, 'call', _62 => _62()]), () => ( []))
4089
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _60 => _60.entries, 'call', _61 => _61()]), () => ( [])),
4090
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _62 => _62.entries, 'call', _63 => _63()]), () => ( []))
3943
4091
  ]).flatMap(([name, tool\u03A3]) => {
3944
4092
  const tool = tool\u03A3.get();
3945
4093
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -4040,7 +4188,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4040
4188
  } else {
4041
4189
  continue;
4042
4190
  }
4043
- const executeFn = _optionalChain([toolsStore, 'access', _63 => _63.getTool\u03A3, 'call', _64 => _64(toolInvocation.name, message.chatId), 'access', _65 => _65.get, 'call', _66 => _66(), 'optionalAccess', _67 => _67.execute]);
4191
+ const executeFn = _optionalChain([toolsStore, 'access', _64 => _64.getTool\u03A3, 'call', _65 => _65(toolInvocation.name, message.chatId), 'access', _66 => _66.get, 'call', _67 => _67(), 'optionalAccess', _68 => _68.execute]);
4044
4192
  if (executeFn) {
4045
4193
  (async () => {
4046
4194
  const result = await executeFn(toolInvocation.args, {
@@ -4063,7 +4211,10 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4063
4211
  }
4064
4212
  }
4065
4213
  } else {
4066
- myMessages.delete(message.id);
4214
+ if (message.role === "assistant" && message.status === "generating") {
4215
+ } else {
4216
+ myMessages.delete(message.id);
4217
+ }
4067
4218
  }
4068
4219
  });
4069
4220
  }
@@ -4071,7 +4222,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4071
4222
  generatingMessages\u03A3.mutate((lut) => {
4072
4223
  const message = lut.get(messageId);
4073
4224
  if (message === void 0) return false;
4074
- appendDelta(message.contentSoFar, delta);
4225
+ patchContentWithDelta(message.contentSoFar, delta);
4075
4226
  lut.set(messageId, message);
4076
4227
  return true;
4077
4228
  });
@@ -4135,8 +4286,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4135
4286
  const spine = [];
4136
4287
  let lastVisitedMessage = null;
4137
4288
  for (const message2 of pool.walkUp(leaf.id)) {
4138
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _68 => _68(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _69 => _69.id]), () => ( null));
4139
- const next = _nullishCoalesce(_optionalChain([first, 'call', _70 => _70(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _71 => _71.id]), () => ( null));
4289
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _69 => _69(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _70 => _70.id]), () => ( null));
4290
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _71 => _71(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _72 => _72.id]), () => ( null));
4140
4291
  if (!message2.deletedAt || prev || next) {
4141
4292
  const node = {
4142
4293
  ...message2,
@@ -4319,7 +4470,7 @@ function createAi(config) {
4319
4470
  if ("event" in msg) {
4320
4471
  switch (msg.event) {
4321
4472
  case "cmd-failed":
4322
- _optionalChain([pendingCmd, 'optionalAccess', _72 => _72.reject, 'call', _73 => _73(new Error(msg.error))]);
4473
+ _optionalChain([pendingCmd, 'optionalAccess', _73 => _73.reject, 'call', _74 => _74(new Error(msg.error))]);
4323
4474
  break;
4324
4475
  case "delta": {
4325
4476
  const { id, delta } = msg;
@@ -4401,7 +4552,7 @@ function createAi(config) {
4401
4552
  return assertNever(msg, "Unhandled case");
4402
4553
  }
4403
4554
  }
4404
- _optionalChain([pendingCmd, 'optionalAccess', _74 => _74.resolve, 'call', _75 => _75(msg)]);
4555
+ _optionalChain([pendingCmd, 'optionalAccess', _75 => _75.resolve, 'call', _76 => _76(msg)]);
4405
4556
  }
4406
4557
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4407
4558
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4486,9 +4637,9 @@ function createAi(config) {
4486
4637
  invocationId,
4487
4638
  result,
4488
4639
  generationOptions: {
4489
- copilotId: _optionalChain([options, 'optionalAccess', _76 => _76.copilotId]),
4490
- stream: _optionalChain([options, 'optionalAccess', _77 => _77.stream]),
4491
- timeout: _optionalChain([options, 'optionalAccess', _78 => _78.timeout]),
4640
+ copilotId: _optionalChain([options, 'optionalAccess', _77 => _77.copilotId]),
4641
+ stream: _optionalChain([options, 'optionalAccess', _78 => _78.stream]),
4642
+ timeout: _optionalChain([options, 'optionalAccess', _79 => _79.timeout]),
4492
4643
  // Knowledge and tools aren't coming from the options, but retrieved
4493
4644
  // from the global context
4494
4645
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4517,24 +4668,24 @@ function createAi(config) {
4517
4668
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4518
4669
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4519
4670
  const globalKnowledge = context.knowledge.get();
4520
- const requestKnowledge = _optionalChain([options, 'optionalAccess', _79 => _79.knowledge]) || [];
4671
+ const requestKnowledge = _optionalChain([options, 'optionalAccess', _80 => _80.knowledge]) || [];
4521
4672
  const combinedKnowledge = [...globalKnowledge, ...requestKnowledge];
4522
4673
  const tools = context.toolsStore.getToolDescriptions(chatId);
4674
+ messagesStore.markMine(targetMessageId);
4523
4675
  const resp = await sendClientMsgWithResponse({
4524
4676
  cmd: "ask-in-chat",
4525
4677
  chatId,
4526
4678
  sourceMessage: userMessage,
4527
4679
  targetMessageId,
4528
4680
  generationOptions: {
4529
- copilotId: _optionalChain([options, 'optionalAccess', _80 => _80.copilotId]),
4530
- stream: _optionalChain([options, 'optionalAccess', _81 => _81.stream]),
4531
- timeout: _optionalChain([options, 'optionalAccess', _82 => _82.timeout]),
4681
+ copilotId: _optionalChain([options, 'optionalAccess', _81 => _81.copilotId]),
4682
+ stream: _optionalChain([options, 'optionalAccess', _82 => _82.stream]),
4683
+ timeout: _optionalChain([options, 'optionalAccess', _83 => _83.timeout]),
4532
4684
  // Combine global knowledge with request-specific knowledge
4533
4685
  knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
4534
4686
  tools: tools.length > 0 ? tools : void 0
4535
4687
  }
4536
4688
  });
4537
- messagesStore.markMine(resp.targetMessage.id);
4538
4689
  return resp;
4539
4690
  },
4540
4691
  abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
@@ -4565,7 +4716,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
4565
4716
  }
4566
4717
  const url2 = new URL(baseUrl);
4567
4718
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
4568
- url2.pathname = "/ai/v4";
4719
+ url2.pathname = "/ai/v5";
4569
4720
  if (authValue.type === "secret") {
4570
4721
  url2.searchParams.set("tok", authValue.token.raw);
4571
4722
  } else if (authValue.type === "public") {
@@ -4629,7 +4780,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4629
4780
  return void 0;
4630
4781
  }
4631
4782
  async function makeAuthRequest(options) {
4632
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _83 => _83.polyfills, 'optionalAccess', _84 => _84.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4783
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _84 => _84.polyfills, 'optionalAccess', _85 => _85.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4633
4784
  if (authentication.type === "private") {
4634
4785
  if (fetcher === void 0) {
4635
4786
  throw new StopRetrying(
@@ -4645,7 +4796,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4645
4796
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
4646
4797
  );
4647
4798
  }
4648
- _optionalChain([onAuthenticate, 'optionalCall', _85 => _85(parsed.parsed)]);
4799
+ _optionalChain([onAuthenticate, 'optionalCall', _86 => _86(parsed.parsed)]);
4649
4800
  return parsed;
4650
4801
  }
4651
4802
  if (authentication.type === "custom") {
@@ -4653,7 +4804,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4653
4804
  if (response && typeof response === "object") {
4654
4805
  if (typeof response.token === "string") {
4655
4806
  const parsed = parseAuthToken(response.token);
4656
- _optionalChain([onAuthenticate, 'optionalCall', _86 => _86(parsed.parsed)]);
4807
+ _optionalChain([onAuthenticate, 'optionalCall', _87 => _87(parsed.parsed)]);
4657
4808
  return parsed;
4658
4809
  } else if (typeof response.error === "string") {
4659
4810
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -4811,7 +4962,7 @@ function sendToPanel(message, options) {
4811
4962
  ...message,
4812
4963
  source: "liveblocks-devtools-client"
4813
4964
  };
4814
- if (!(_optionalChain([options, 'optionalAccess', _87 => _87.force]) || _bridgeActive)) {
4965
+ if (!(_optionalChain([options, 'optionalAccess', _88 => _88.force]) || _bridgeActive)) {
4815
4966
  return;
4816
4967
  }
4817
4968
  window.postMessage(fullMsg, "*");
@@ -4819,7 +4970,7 @@ function sendToPanel(message, options) {
4819
4970
  var eventSource = makeEventSource();
4820
4971
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
4821
4972
  window.addEventListener("message", (event) => {
4822
- if (event.source === window && _optionalChain([event, 'access', _88 => _88.data, 'optionalAccess', _89 => _89.source]) === "liveblocks-devtools-panel") {
4973
+ if (event.source === window && _optionalChain([event, 'access', _89 => _89.data, 'optionalAccess', _90 => _90.source]) === "liveblocks-devtools-panel") {
4823
4974
  eventSource.notify(event.data);
4824
4975
  } else {
4825
4976
  }
@@ -4961,7 +5112,7 @@ function fullSync(room) {
4961
5112
  msg: "room::sync::full",
4962
5113
  roomId: room.id,
4963
5114
  status: room.getStatus(),
4964
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _90 => _90.toTreeNode, 'call', _91 => _91("root"), 'access', _92 => _92.payload]), () => ( null)),
5115
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _91 => _91.toTreeNode, 'call', _92 => _92("root"), 'access', _93 => _93.payload]), () => ( null)),
4965
5116
  me,
4966
5117
  others
4967
5118
  });
@@ -5252,7 +5403,7 @@ function createManagedPool(roomId, options) {
5252
5403
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5253
5404
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5254
5405
  dispatch(ops, reverse, storageUpdates) {
5255
- _optionalChain([onDispatch, 'optionalCall', _93 => _93(ops, reverse, storageUpdates)]);
5406
+ _optionalChain([onDispatch, 'optionalCall', _94 => _94(ops, reverse, storageUpdates)]);
5256
5407
  },
5257
5408
  assertStorageIsWritable: () => {
5258
5409
  if (!isStorageWritable()) {
@@ -5479,7 +5630,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5479
5630
  return [
5480
5631
  {
5481
5632
  type: 8 /* CREATE_REGISTER */,
5482
- opId: _optionalChain([pool, 'optionalAccess', _94 => _94.generateOpId, 'call', _95 => _95()]),
5633
+ opId: _optionalChain([pool, 'optionalAccess', _95 => _95.generateOpId, 'call', _96 => _96()]),
5483
5634
  id: this._id,
5484
5635
  parentId,
5485
5636
  parentKey,
@@ -5585,7 +5736,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5585
5736
  const ops = [];
5586
5737
  const op = {
5587
5738
  id: this._id,
5588
- opId: _optionalChain([pool, 'optionalAccess', _96 => _96.generateOpId, 'call', _97 => _97()]),
5739
+ opId: _optionalChain([pool, 'optionalAccess', _97 => _97.generateOpId, 'call', _98 => _98()]),
5589
5740
  type: 2 /* CREATE_LIST */,
5590
5741
  parentId,
5591
5742
  parentKey
@@ -5856,7 +6007,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5856
6007
  #applyInsertUndoRedo(op) {
5857
6008
  const { id, parentKey: key } = op;
5858
6009
  const child = creationOpToLiveNode(op);
5859
- if (_optionalChain([this, 'access', _98 => _98._pool, 'optionalAccess', _99 => _99.getNode, 'call', _100 => _100(id)]) !== void 0) {
6010
+ if (_optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.getNode, 'call', _101 => _101(id)]) !== void 0) {
5860
6011
  return { modified: false };
5861
6012
  }
5862
6013
  child._attach(id, nn(this._pool));
@@ -5864,8 +6015,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
5864
6015
  const existingItemIndex = this._indexOfPosition(key);
5865
6016
  let newKey = key;
5866
6017
  if (existingItemIndex !== -1) {
5867
- const before2 = _optionalChain([this, 'access', _101 => _101.#items, 'access', _102 => _102[existingItemIndex], 'optionalAccess', _103 => _103._parentPos]);
5868
- const after2 = _optionalChain([this, 'access', _104 => _104.#items, 'access', _105 => _105[existingItemIndex + 1], 'optionalAccess', _106 => _106._parentPos]);
6018
+ const before2 = _optionalChain([this, 'access', _102 => _102.#items, 'access', _103 => _103[existingItemIndex], 'optionalAccess', _104 => _104._parentPos]);
6019
+ const after2 = _optionalChain([this, 'access', _105 => _105.#items, 'access', _106 => _106[existingItemIndex + 1], 'optionalAccess', _107 => _107._parentPos]);
5869
6020
  newKey = makePosition(before2, after2);
5870
6021
  child._setParentLink(this, newKey);
5871
6022
  }
@@ -5879,7 +6030,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5879
6030
  #applySetUndoRedo(op) {
5880
6031
  const { id, parentKey: key } = op;
5881
6032
  const child = creationOpToLiveNode(op);
5882
- if (_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.getNode, 'call', _109 => _109(id)]) !== void 0) {
6033
+ if (_optionalChain([this, 'access', _108 => _108._pool, 'optionalAccess', _109 => _109.getNode, 'call', _110 => _110(id)]) !== void 0) {
5883
6034
  return { modified: false };
5884
6035
  }
5885
6036
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -6000,7 +6151,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6000
6151
  } else {
6001
6152
  this.#items[existingItemIndex]._setParentLink(
6002
6153
  this,
6003
- makePosition(newKey, _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[existingItemIndex + 1], 'optionalAccess', _112 => _112._parentPos]))
6154
+ makePosition(newKey, _optionalChain([this, 'access', _111 => _111.#items, 'access', _112 => _112[existingItemIndex + 1], 'optionalAccess', _113 => _113._parentPos]))
6004
6155
  );
6005
6156
  const previousIndex = this.#items.indexOf(child);
6006
6157
  child._setParentLink(this, newKey);
@@ -6025,7 +6176,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6025
6176
  if (existingItemIndex !== -1) {
6026
6177
  this.#items[existingItemIndex]._setParentLink(
6027
6178
  this,
6028
- makePosition(newKey, _optionalChain([this, 'access', _113 => _113.#items, 'access', _114 => _114[existingItemIndex + 1], 'optionalAccess', _115 => _115._parentPos]))
6179
+ makePosition(newKey, _optionalChain([this, 'access', _114 => _114.#items, 'access', _115 => _115[existingItemIndex + 1], 'optionalAccess', _116 => _116._parentPos]))
6029
6180
  );
6030
6181
  }
6031
6182
  child._setParentLink(this, newKey);
@@ -6044,7 +6195,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6044
6195
  if (existingItemIndex !== -1) {
6045
6196
  this.#items[existingItemIndex]._setParentLink(
6046
6197
  this,
6047
- makePosition(newKey, _optionalChain([this, 'access', _116 => _116.#items, 'access', _117 => _117[existingItemIndex + 1], 'optionalAccess', _118 => _118._parentPos]))
6198
+ makePosition(newKey, _optionalChain([this, 'access', _117 => _117.#items, 'access', _118 => _118[existingItemIndex + 1], 'optionalAccess', _119 => _119._parentPos]))
6048
6199
  );
6049
6200
  }
6050
6201
  child._setParentLink(this, newKey);
@@ -6071,7 +6222,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6071
6222
  if (existingItemIndex !== -1) {
6072
6223
  this.#items[existingItemIndex]._setParentLink(
6073
6224
  this,
6074
- makePosition(newKey, _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120[existingItemIndex + 1], 'optionalAccess', _121 => _121._parentPos]))
6225
+ makePosition(newKey, _optionalChain([this, 'access', _120 => _120.#items, 'access', _121 => _121[existingItemIndex + 1], 'optionalAccess', _122 => _122._parentPos]))
6075
6226
  );
6076
6227
  }
6077
6228
  child._setParentLink(this, newKey);
@@ -6129,7 +6280,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6129
6280
  * @param element The element to add to the end of the LiveList.
6130
6281
  */
6131
6282
  push(element) {
6132
- _optionalChain([this, 'access', _122 => _122._pool, 'optionalAccess', _123 => _123.assertStorageIsWritable, 'call', _124 => _124()]);
6283
+ _optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.assertStorageIsWritable, 'call', _125 => _125()]);
6133
6284
  return this.insert(element, this.length);
6134
6285
  }
6135
6286
  /**
@@ -6138,7 +6289,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6138
6289
  * @param index The index at which you want to insert the element.
6139
6290
  */
6140
6291
  insert(element, index) {
6141
- _optionalChain([this, 'access', _125 => _125._pool, 'optionalAccess', _126 => _126.assertStorageIsWritable, 'call', _127 => _127()]);
6292
+ _optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.assertStorageIsWritable, 'call', _128 => _128()]);
6142
6293
  if (index < 0 || index > this.#items.length) {
6143
6294
  throw new Error(
6144
6295
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6168,7 +6319,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6168
6319
  * @param targetIndex The index where the element should be after moving.
6169
6320
  */
6170
6321
  move(index, targetIndex) {
6171
- _optionalChain([this, 'access', _128 => _128._pool, 'optionalAccess', _129 => _129.assertStorageIsWritable, 'call', _130 => _130()]);
6322
+ _optionalChain([this, 'access', _129 => _129._pool, 'optionalAccess', _130 => _130.assertStorageIsWritable, 'call', _131 => _131()]);
6172
6323
  if (targetIndex < 0) {
6173
6324
  throw new Error("targetIndex cannot be less than 0");
6174
6325
  }
@@ -6226,7 +6377,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6226
6377
  * @param index The index of the element to delete
6227
6378
  */
6228
6379
  delete(index) {
6229
- _optionalChain([this, 'access', _131 => _131._pool, 'optionalAccess', _132 => _132.assertStorageIsWritable, 'call', _133 => _133()]);
6380
+ _optionalChain([this, 'access', _132 => _132._pool, 'optionalAccess', _133 => _133.assertStorageIsWritable, 'call', _134 => _134()]);
6230
6381
  if (index < 0 || index >= this.#items.length) {
6231
6382
  throw new Error(
6232
6383
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6259,7 +6410,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6259
6410
  }
6260
6411
  }
6261
6412
  clear() {
6262
- _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6413
+ _optionalChain([this, 'access', _135 => _135._pool, 'optionalAccess', _136 => _136.assertStorageIsWritable, 'call', _137 => _137()]);
6263
6414
  if (this._pool) {
6264
6415
  const ops = [];
6265
6416
  const reverseOps = [];
@@ -6293,7 +6444,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6293
6444
  }
6294
6445
  }
6295
6446
  set(index, item) {
6296
- _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6447
+ _optionalChain([this, 'access', _138 => _138._pool, 'optionalAccess', _139 => _139.assertStorageIsWritable, 'call', _140 => _140()]);
6297
6448
  if (index < 0 || index >= this.#items.length) {
6298
6449
  throw new Error(
6299
6450
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6439,7 +6590,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6439
6590
  #shiftItemPosition(index, key) {
6440
6591
  const shiftedPosition = makePosition(
6441
6592
  key,
6442
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _140 => _140.#items, 'access', _141 => _141[index + 1], 'optionalAccess', _142 => _142._parentPos]) : void 0
6593
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _141 => _141.#items, 'access', _142 => _142[index + 1], 'optionalAccess', _143 => _143._parentPos]) : void 0
6443
6594
  );
6444
6595
  this.#items[index]._setParentLink(this, shiftedPosition);
6445
6596
  }
@@ -6564,7 +6715,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6564
6715
  const ops = [];
6565
6716
  const op = {
6566
6717
  id: this._id,
6567
- opId: _optionalChain([pool, 'optionalAccess', _143 => _143.generateOpId, 'call', _144 => _144()]),
6718
+ opId: _optionalChain([pool, 'optionalAccess', _144 => _144.generateOpId, 'call', _145 => _145()]),
6568
6719
  type: 7 /* CREATE_MAP */,
6569
6720
  parentId,
6570
6721
  parentKey
@@ -6699,7 +6850,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6699
6850
  * @param value The value of the element to add. Should be serializable to JSON.
6700
6851
  */
6701
6852
  set(key, value) {
6702
- _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
6853
+ _optionalChain([this, 'access', _146 => _146._pool, 'optionalAccess', _147 => _147.assertStorageIsWritable, 'call', _148 => _148()]);
6703
6854
  const oldValue = this.#map.get(key);
6704
6855
  if (oldValue) {
6705
6856
  oldValue._detach();
@@ -6745,7 +6896,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6745
6896
  * @returns true if an element existed and has been removed, or false if the element does not exist.
6746
6897
  */
6747
6898
  delete(key) {
6748
- _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
6899
+ _optionalChain([this, 'access', _149 => _149._pool, 'optionalAccess', _150 => _150.assertStorageIsWritable, 'call', _151 => _151()]);
6749
6900
  const item = this.#map.get(key);
6750
6901
  if (item === void 0) {
6751
6902
  return false;
@@ -6935,7 +7086,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
6935
7086
  if (this._id === void 0) {
6936
7087
  throw new Error("Cannot serialize item is not attached");
6937
7088
  }
6938
- const opId = _optionalChain([pool, 'optionalAccess', _151 => _151.generateOpId, 'call', _152 => _152()]);
7089
+ const opId = _optionalChain([pool, 'optionalAccess', _152 => _152.generateOpId, 'call', _153 => _153()]);
6939
7090
  const ops = [];
6940
7091
  const op = {
6941
7092
  type: 4 /* CREATE_OBJECT */,
@@ -7207,7 +7358,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7207
7358
  * @param value The value of the property to add
7208
7359
  */
7209
7360
  set(key, value) {
7210
- _optionalChain([this, 'access', _153 => _153._pool, 'optionalAccess', _154 => _154.assertStorageIsWritable, 'call', _155 => _155()]);
7361
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
7211
7362
  this.update({ [key]: value });
7212
7363
  }
7213
7364
  /**
@@ -7222,7 +7373,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7222
7373
  * @param key The key of the property to delete
7223
7374
  */
7224
7375
  delete(key) {
7225
- _optionalChain([this, 'access', _156 => _156._pool, 'optionalAccess', _157 => _157.assertStorageIsWritable, 'call', _158 => _158()]);
7376
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
7226
7377
  const keyAsString = key;
7227
7378
  const oldValue = this.#map.get(keyAsString);
7228
7379
  if (oldValue === void 0) {
@@ -7275,7 +7426,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7275
7426
  * @param patch The object used to overrides properties
7276
7427
  */
7277
7428
  update(patch) {
7278
- _optionalChain([this, 'access', _159 => _159._pool, 'optionalAccess', _160 => _160.assertStorageIsWritable, 'call', _161 => _161()]);
7429
+ _optionalChain([this, 'access', _160 => _160._pool, 'optionalAccess', _161 => _161.assertStorageIsWritable, 'call', _162 => _162()]);
7279
7430
  if (_LiveObject.detectLargeObjects) {
7280
7431
  const data = {};
7281
7432
  for (const [key, value] of this.#map) {
@@ -8023,15 +8174,15 @@ function installBackgroundTabSpy() {
8023
8174
  const doc = typeof document !== "undefined" ? document : void 0;
8024
8175
  const inBackgroundSince = { current: null };
8025
8176
  function onVisibilityChange() {
8026
- if (_optionalChain([doc, 'optionalAccess', _162 => _162.visibilityState]) === "hidden") {
8177
+ if (_optionalChain([doc, 'optionalAccess', _163 => _163.visibilityState]) === "hidden") {
8027
8178
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
8028
8179
  } else {
8029
8180
  inBackgroundSince.current = null;
8030
8181
  }
8031
8182
  }
8032
- _optionalChain([doc, 'optionalAccess', _163 => _163.addEventListener, 'call', _164 => _164("visibilitychange", onVisibilityChange)]);
8183
+ _optionalChain([doc, 'optionalAccess', _164 => _164.addEventListener, 'call', _165 => _165("visibilitychange", onVisibilityChange)]);
8033
8184
  const unsub = () => {
8034
- _optionalChain([doc, 'optionalAccess', _165 => _165.removeEventListener, 'call', _166 => _166("visibilitychange", onVisibilityChange)]);
8185
+ _optionalChain([doc, 'optionalAccess', _166 => _166.removeEventListener, 'call', _167 => _167("visibilitychange", onVisibilityChange)]);
8035
8186
  };
8036
8187
  return [inBackgroundSince, unsub];
8037
8188
  }
@@ -8211,7 +8362,7 @@ function createRoom(options, config) {
8211
8362
  }
8212
8363
  }
8213
8364
  function isStorageWritable() {
8214
- const scopes = _optionalChain([context, 'access', _167 => _167.dynamicSessionInfoSig, 'access', _168 => _168.get, 'call', _169 => _169(), 'optionalAccess', _170 => _170.scopes]);
8365
+ const scopes = _optionalChain([context, 'access', _168 => _168.dynamicSessionInfoSig, 'access', _169 => _169.get, 'call', _170 => _170(), 'optionalAccess', _171 => _171.scopes]);
8215
8366
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8216
8367
  }
8217
8368
  const eventHub = {
@@ -8337,7 +8488,7 @@ function createRoom(options, config) {
8337
8488
  }
8338
8489
  case "experimental-fallback-to-http": {
8339
8490
  warn("Message is too large for websockets, so sending over HTTP instead");
8340
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _171 => _171.dynamicSessionInfoSig, 'access', _172 => _172.get, 'call', _173 => _173(), 'optionalAccess', _174 => _174.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8491
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _172 => _172.dynamicSessionInfoSig, 'access', _173 => _173.get, 'call', _174 => _174(), 'optionalAccess', _175 => _175.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8341
8492
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8342
8493
  if (!resp.ok && resp.status === 403) {
8343
8494
  managedSocket.reconnect();
@@ -8388,7 +8539,7 @@ function createRoom(options, config) {
8388
8539
  } else {
8389
8540
  context.root = LiveObject._fromItems(message.items, context.pool);
8390
8541
  }
8391
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _175 => _175.get, 'call', _176 => _176(), 'optionalAccess', _177 => _177.canWrite]), () => ( true));
8542
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _176 => _176.get, 'call', _177 => _177(), 'optionalAccess', _178 => _178.canWrite]), () => ( true));
8392
8543
  const stackSizeBefore = context.undoStack.length;
8393
8544
  for (const key in context.initialStorage) {
8394
8545
  if (context.root.get(key) === void 0) {
@@ -8591,7 +8742,7 @@ function createRoom(options, config) {
8591
8742
  }
8592
8743
  context.myPresence.patch(patch);
8593
8744
  if (context.activeBatch) {
8594
- if (_optionalChain([options2, 'optionalAccess', _178 => _178.addToHistory])) {
8745
+ if (_optionalChain([options2, 'optionalAccess', _179 => _179.addToHistory])) {
8595
8746
  context.activeBatch.reverseOps.pushLeft({
8596
8747
  type: "presence",
8597
8748
  data: oldValues
@@ -8600,7 +8751,7 @@ function createRoom(options, config) {
8600
8751
  context.activeBatch.updates.presence = true;
8601
8752
  } else {
8602
8753
  flushNowOrSoon();
8603
- if (_optionalChain([options2, 'optionalAccess', _179 => _179.addToHistory])) {
8754
+ if (_optionalChain([options2, 'optionalAccess', _180 => _180.addToHistory])) {
8604
8755
  addToUndoStack([{ type: "presence", data: oldValues }]);
8605
8756
  }
8606
8757
  notify({ presence: true });
@@ -8797,7 +8948,7 @@ function createRoom(options, config) {
8797
8948
  if (process.env.NODE_ENV !== "production") {
8798
8949
  const traces = /* @__PURE__ */ new Set();
8799
8950
  for (const opId of message.opIds) {
8800
- const trace = _optionalChain([context, 'access', _180 => _180.opStackTraces, 'optionalAccess', _181 => _181.get, 'call', _182 => _182(opId)]);
8951
+ const trace = _optionalChain([context, 'access', _181 => _181.opStackTraces, 'optionalAccess', _182 => _182.get, 'call', _183 => _183(opId)]);
8801
8952
  if (trace) {
8802
8953
  traces.add(trace);
8803
8954
  }
@@ -8931,7 +9082,7 @@ ${Array.from(traces).join("\n\n")}`
8931
9082
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
8932
9083
  createOrUpdateRootFromMessage(message);
8933
9084
  applyAndSendOps(unacknowledgedOps);
8934
- _optionalChain([_resolveStoragePromise, 'optionalCall', _183 => _183()]);
9085
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _184 => _184()]);
8935
9086
  notifyStorageStatus();
8936
9087
  eventHub.storageDidLoad.notify();
8937
9088
  }
@@ -9152,8 +9303,8 @@ ${Array.from(traces).join("\n\n")}`
9152
9303
  async function getThreads(options2) {
9153
9304
  return httpClient.getThreads({
9154
9305
  roomId,
9155
- query: _optionalChain([options2, 'optionalAccess', _184 => _184.query]),
9156
- cursor: _optionalChain([options2, 'optionalAccess', _185 => _185.cursor])
9306
+ query: _optionalChain([options2, 'optionalAccess', _185 => _185.query]),
9307
+ cursor: _optionalChain([options2, 'optionalAccess', _186 => _186.cursor])
9157
9308
  });
9158
9309
  }
9159
9310
  async function getThread(threadId) {
@@ -9260,7 +9411,7 @@ ${Array.from(traces).join("\n\n")}`
9260
9411
  function getSubscriptionSettings(options2) {
9261
9412
  return httpClient.getSubscriptionSettings({
9262
9413
  roomId,
9263
- signal: _optionalChain([options2, 'optionalAccess', _186 => _186.signal])
9414
+ signal: _optionalChain([options2, 'optionalAccess', _187 => _187.signal])
9264
9415
  });
9265
9416
  }
9266
9417
  function updateSubscriptionSettings(settings) {
@@ -9282,7 +9433,7 @@ ${Array.from(traces).join("\n\n")}`
9282
9433
  {
9283
9434
  [kInternal]: {
9284
9435
  get presenceBuffer() {
9285
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _187 => _187.buffer, 'access', _188 => _188.presenceUpdates, 'optionalAccess', _189 => _189.data]), () => ( null)));
9436
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _188 => _188.buffer, 'access', _189 => _189.presenceUpdates, 'optionalAccess', _190 => _190.data]), () => ( null)));
9286
9437
  },
9287
9438
  // prettier-ignore
9288
9439
  get undoStack() {
@@ -9297,9 +9448,9 @@ ${Array.from(traces).join("\n\n")}`
9297
9448
  return context.yjsProvider;
9298
9449
  },
9299
9450
  setYjsProvider(newProvider) {
9300
- _optionalChain([context, 'access', _190 => _190.yjsProvider, 'optionalAccess', _191 => _191.off, 'call', _192 => _192("status", yjsStatusDidChange)]);
9451
+ _optionalChain([context, 'access', _191 => _191.yjsProvider, 'optionalAccess', _192 => _192.off, 'call', _193 => _193("status", yjsStatusDidChange)]);
9301
9452
  context.yjsProvider = newProvider;
9302
- _optionalChain([newProvider, 'optionalAccess', _193 => _193.on, 'call', _194 => _194("status", yjsStatusDidChange)]);
9453
+ _optionalChain([newProvider, 'optionalAccess', _194 => _194.on, 'call', _195 => _195("status", yjsStatusDidChange)]);
9303
9454
  context.yjsProviderDidChange.notify();
9304
9455
  },
9305
9456
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9345,7 +9496,7 @@ ${Array.from(traces).join("\n\n")}`
9345
9496
  source.dispose();
9346
9497
  }
9347
9498
  eventHub.roomWillDestroy.notify();
9348
- _optionalChain([context, 'access', _195 => _195.yjsProvider, 'optionalAccess', _196 => _196.off, 'call', _197 => _197("status", yjsStatusDidChange)]);
9499
+ _optionalChain([context, 'access', _196 => _196.yjsProvider, 'optionalAccess', _197 => _197.off, 'call', _198 => _198("status", yjsStatusDidChange)]);
9349
9500
  syncSourceForStorage.destroy();
9350
9501
  syncSourceForYjs.destroy();
9351
9502
  uninstallBgTabSpy();
@@ -9495,7 +9646,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9495
9646
  }
9496
9647
  if (isLiveNode(first)) {
9497
9648
  const node = first;
9498
- if (_optionalChain([options, 'optionalAccess', _198 => _198.isDeep])) {
9649
+ if (_optionalChain([options, 'optionalAccess', _199 => _199.isDeep])) {
9499
9650
  const storageCallback = second;
9500
9651
  return subscribeToLiveStructureDeeply(node, storageCallback);
9501
9652
  } else {
@@ -9574,8 +9725,8 @@ function createClient(options) {
9574
9725
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9575
9726
  currentUserId.set(() => userId);
9576
9727
  });
9577
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _199 => _199.polyfills, 'optionalAccess', _200 => _200.fetch]) || /* istanbul ignore next */
9578
- _optionalChain([globalThis, 'access', _201 => _201.fetch, 'optionalAccess', _202 => _202.bind, 'call', _203 => _203(globalThis)]);
9728
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _200 => _200.polyfills, 'optionalAccess', _201 => _201.fetch]) || /* istanbul ignore next */
9729
+ _optionalChain([globalThis, 'access', _202 => _202.fetch, 'optionalAccess', _203 => _203.bind, 'call', _204 => _204(globalThis)]);
9579
9730
  const httpClient = createApiClient({
9580
9731
  baseUrl,
9581
9732
  fetchPolyfill,
@@ -9593,7 +9744,7 @@ function createClient(options) {
9593
9744
  delegates: {
9594
9745
  createSocket: makeCreateSocketDelegateForAi(
9595
9746
  baseUrl,
9596
- _optionalChain([clientOptions, 'access', _204 => _204.polyfills, 'optionalAccess', _205 => _205.WebSocket])
9747
+ _optionalChain([clientOptions, 'access', _205 => _205.polyfills, 'optionalAccess', _206 => _206.WebSocket])
9597
9748
  ),
9598
9749
  authenticate: async () => {
9599
9750
  const resp = await authManager.getAuthValue({
@@ -9661,7 +9812,7 @@ function createClient(options) {
9661
9812
  createSocket: makeCreateSocketDelegateForRoom(
9662
9813
  roomId,
9663
9814
  baseUrl,
9664
- _optionalChain([clientOptions, 'access', _206 => _206.polyfills, 'optionalAccess', _207 => _207.WebSocket])
9815
+ _optionalChain([clientOptions, 'access', _207 => _207.polyfills, 'optionalAccess', _208 => _208.WebSocket])
9665
9816
  ),
9666
9817
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
9667
9818
  })),
@@ -9684,7 +9835,7 @@ function createClient(options) {
9684
9835
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
9685
9836
  if (shouldConnect) {
9686
9837
  if (typeof atob === "undefined") {
9687
- if (_optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.atob]) === void 0) {
9838
+ if (_optionalChain([clientOptions, 'access', _209 => _209.polyfills, 'optionalAccess', _210 => _210.atob]) === void 0) {
9688
9839
  throw new Error(
9689
9840
  "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"
9690
9841
  );
@@ -9696,7 +9847,7 @@ function createClient(options) {
9696
9847
  return leaseRoom(newRoomDetails);
9697
9848
  }
9698
9849
  function getRoom(roomId) {
9699
- const room = _optionalChain([roomsById, 'access', _210 => _210.get, 'call', _211 => _211(roomId), 'optionalAccess', _212 => _212.room]);
9850
+ const room = _optionalChain([roomsById, 'access', _211 => _211.get, 'call', _212 => _212(roomId), 'optionalAccess', _213 => _213.room]);
9700
9851
  return room ? room : null;
9701
9852
  }
9702
9853
  function logout() {
@@ -9716,7 +9867,7 @@ function createClient(options) {
9716
9867
  const batchedResolveUsers = new Batch(
9717
9868
  async (batchedUserIds) => {
9718
9869
  const userIds = batchedUserIds.flat();
9719
- const users = await _optionalChain([resolveUsers, 'optionalCall', _213 => _213({ userIds })]);
9870
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _214 => _214({ userIds })]);
9720
9871
  warnIfNoResolveUsers();
9721
9872
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
9722
9873
  },
@@ -9734,7 +9885,7 @@ function createClient(options) {
9734
9885
  const batchedResolveRoomsInfo = new Batch(
9735
9886
  async (batchedRoomIds) => {
9736
9887
  const roomIds = batchedRoomIds.flat();
9737
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _214 => _214({ roomIds })]);
9888
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _215 => _215({ roomIds })]);
9738
9889
  warnIfNoResolveRoomsInfo();
9739
9890
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
9740
9891
  },
@@ -9787,7 +9938,7 @@ function createClient(options) {
9787
9938
  }
9788
9939
  };
9789
9940
  const win = typeof window !== "undefined" ? window : void 0;
9790
- _optionalChain([win, 'optionalAccess', _215 => _215.addEventListener, 'call', _216 => _216("beforeunload", maybePreventClose)]);
9941
+ _optionalChain([win, 'optionalAccess', _216 => _216.addEventListener, 'call', _217 => _217("beforeunload", maybePreventClose)]);
9791
9942
  }
9792
9943
  async function getNotificationSettings(options2) {
9793
9944
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -9926,7 +10077,7 @@ var commentBodyElementsTypes = {
9926
10077
  mention: "inline"
9927
10078
  };
9928
10079
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9929
- if (!body || !_optionalChain([body, 'optionalAccess', _217 => _217.content])) {
10080
+ if (!body || !_optionalChain([body, 'optionalAccess', _218 => _218.content])) {
9930
10081
  return;
9931
10082
  }
9932
10083
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -9936,13 +10087,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9936
10087
  for (const block of body.content) {
9937
10088
  if (type === "all" || type === "block") {
9938
10089
  if (guard(block)) {
9939
- _optionalChain([visitor, 'optionalCall', _218 => _218(block)]);
10090
+ _optionalChain([visitor, 'optionalCall', _219 => _219(block)]);
9940
10091
  }
9941
10092
  }
9942
10093
  if (type === "all" || type === "inline") {
9943
10094
  for (const inline of block.children) {
9944
10095
  if (guard(inline)) {
9945
- _optionalChain([visitor, 'optionalCall', _219 => _219(inline)]);
10096
+ _optionalChain([visitor, 'optionalCall', _220 => _220(inline)]);
9946
10097
  }
9947
10098
  }
9948
10099
  }
@@ -9976,7 +10127,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
9976
10127
  userIds
9977
10128
  });
9978
10129
  for (const [index, userId] of userIds.entries()) {
9979
- const user = _optionalChain([users, 'optionalAccess', _220 => _220[index]]);
10130
+ const user = _optionalChain([users, 'optionalAccess', _221 => _221[index]]);
9980
10131
  if (user) {
9981
10132
  resolvedUsers.set(userId, user);
9982
10133
  }
@@ -10095,7 +10246,7 @@ var stringifyCommentBodyPlainElements = {
10095
10246
  text: ({ element }) => element.text,
10096
10247
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
10097
10248
  mention: ({ element, user }) => {
10098
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _221 => _221.name]), () => ( element.id))}`;
10249
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _222 => _222.name]), () => ( element.id))}`;
10099
10250
  }
10100
10251
  };
10101
10252
  var stringifyCommentBodyHtmlElements = {
@@ -10125,7 +10276,7 @@ var stringifyCommentBodyHtmlElements = {
10125
10276
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10126
10277
  },
10127
10278
  mention: ({ element, user }) => {
10128
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _222 => _222.name]) ? html`${_optionalChain([user, 'optionalAccess', _223 => _223.name])}` : element.id}</span>`;
10279
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _223 => _223.name]) ? html`${_optionalChain([user, 'optionalAccess', _224 => _224.name])}` : element.id}</span>`;
10129
10280
  }
10130
10281
  };
10131
10282
  var stringifyCommentBodyMarkdownElements = {
@@ -10155,19 +10306,19 @@ var stringifyCommentBodyMarkdownElements = {
10155
10306
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10156
10307
  },
10157
10308
  mention: ({ element, user }) => {
10158
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _224 => _224.name]), () => ( element.id))}`;
10309
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _225 => _225.name]), () => ( element.id))}`;
10159
10310
  }
10160
10311
  };
10161
10312
  async function stringifyCommentBody(body, options) {
10162
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _225 => _225.format]), () => ( "plain"));
10163
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _226 => _226.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10313
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _226 => _226.format]), () => ( "plain"));
10314
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _227 => _227.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10164
10315
  const elements = {
10165
10316
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10166
- ..._optionalChain([options, 'optionalAccess', _227 => _227.elements])
10317
+ ..._optionalChain([options, 'optionalAccess', _228 => _228.elements])
10167
10318
  };
10168
10319
  const resolvedUsers = await resolveUsersInCommentBody(
10169
10320
  body,
10170
- _optionalChain([options, 'optionalAccess', _228 => _228.resolveUsers])
10321
+ _optionalChain([options, 'optionalAccess', _229 => _229.resolveUsers])
10171
10322
  );
10172
10323
  const blocks = body.content.flatMap((block, blockIndex) => {
10173
10324
  switch (block.type) {
@@ -10453,12 +10604,12 @@ function legacy_patchImmutableNode(state, path, update) {
10453
10604
  }
10454
10605
  const newState = Object.assign({}, state);
10455
10606
  for (const key in update.updates) {
10456
- if (_optionalChain([update, 'access', _229 => _229.updates, 'access', _230 => _230[key], 'optionalAccess', _231 => _231.type]) === "update") {
10607
+ if (_optionalChain([update, 'access', _230 => _230.updates, 'access', _231 => _231[key], 'optionalAccess', _232 => _232.type]) === "update") {
10457
10608
  const val = update.node.get(key);
10458
10609
  if (val !== void 0) {
10459
10610
  newState[key] = lsonToJson(val);
10460
10611
  }
10461
- } else if (_optionalChain([update, 'access', _232 => _232.updates, 'access', _233 => _233[key], 'optionalAccess', _234 => _234.type]) === "delete") {
10612
+ } else if (_optionalChain([update, 'access', _233 => _233.updates, 'access', _234 => _234[key], 'optionalAccess', _235 => _235.type]) === "delete") {
10462
10613
  delete newState[key];
10463
10614
  }
10464
10615
  }
@@ -10519,12 +10670,12 @@ function legacy_patchImmutableNode(state, path, update) {
10519
10670
  }
10520
10671
  const newState = Object.assign({}, state);
10521
10672
  for (const key in update.updates) {
10522
- if (_optionalChain([update, 'access', _235 => _235.updates, 'access', _236 => _236[key], 'optionalAccess', _237 => _237.type]) === "update") {
10673
+ if (_optionalChain([update, 'access', _236 => _236.updates, 'access', _237 => _237[key], 'optionalAccess', _238 => _238.type]) === "update") {
10523
10674
  const value = update.node.get(key);
10524
10675
  if (value !== void 0) {
10525
10676
  newState[key] = lsonToJson(value);
10526
10677
  }
10527
- } else if (_optionalChain([update, 'access', _238 => _238.updates, 'access', _239 => _239[key], 'optionalAccess', _240 => _240.type]) === "delete") {
10678
+ } else if (_optionalChain([update, 'access', _239 => _239.updates, 'access', _240 => _240[key], 'optionalAccess', _241 => _241.type]) === "delete") {
10528
10679
  delete newState[key];
10529
10680
  }
10530
10681
  }
@@ -10604,9 +10755,9 @@ function makePoller(callback, intervalMs, options) {
10604
10755
  const startTime = performance.now();
10605
10756
  const doc = typeof document !== "undefined" ? document : void 0;
10606
10757
  const win = typeof window !== "undefined" ? window : void 0;
10607
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _241 => _241.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10758
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _242 => _242.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10608
10759
  const context = {
10609
- inForeground: _optionalChain([doc, 'optionalAccess', _242 => _242.visibilityState]) !== "hidden",
10760
+ inForeground: _optionalChain([doc, 'optionalAccess', _243 => _243.visibilityState]) !== "hidden",
10610
10761
  lastSuccessfulPollAt: startTime,
10611
10762
  count: 0,
10612
10763
  backoff: 0
@@ -10687,11 +10838,11 @@ function makePoller(callback, intervalMs, options) {
10687
10838
  pollNowIfStale();
10688
10839
  }
10689
10840
  function onVisibilityChange() {
10690
- setInForeground(_optionalChain([doc, 'optionalAccess', _243 => _243.visibilityState]) !== "hidden");
10841
+ setInForeground(_optionalChain([doc, 'optionalAccess', _244 => _244.visibilityState]) !== "hidden");
10691
10842
  }
10692
- _optionalChain([doc, 'optionalAccess', _244 => _244.addEventListener, 'call', _245 => _245("visibilitychange", onVisibilityChange)]);
10693
- _optionalChain([win, 'optionalAccess', _246 => _246.addEventListener, 'call', _247 => _247("online", onVisibilityChange)]);
10694
- _optionalChain([win, 'optionalAccess', _248 => _248.addEventListener, 'call', _249 => _249("focus", pollNowIfStale)]);
10843
+ _optionalChain([doc, 'optionalAccess', _245 => _245.addEventListener, 'call', _246 => _246("visibilitychange", onVisibilityChange)]);
10844
+ _optionalChain([win, 'optionalAccess', _247 => _247.addEventListener, 'call', _248 => _248("online", onVisibilityChange)]);
10845
+ _optionalChain([win, 'optionalAccess', _249 => _249.addEventListener, 'call', _250 => _250("focus", pollNowIfStale)]);
10695
10846
  fsm.start();
10696
10847
  return {
10697
10848
  inc,
@@ -10819,5 +10970,7 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
10819
10970
 
10820
10971
 
10821
10972
 
10822
- exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
10973
+
10974
+
10975
+ exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
10823
10976
  //# sourceMappingURL=index.cjs.map