@liveblocks/core 3.5.4 → 3.6.1-preview1

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.5.4";
9
+ var PKG_VERSION = "3.6.1-preview1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -3987,23 +3987,46 @@ var IncrementalJsonParser = class {
3987
3987
  };
3988
3988
 
3989
3989
  // src/types/ai.ts
3990
+ function replaceOrAppend(content, newItem, keyFn, now2) {
3991
+ const existingIndex = findLastIndex(
3992
+ content,
3993
+ (item) => item.type === newItem.type && keyFn(item) === keyFn(newItem)
3994
+ );
3995
+ if (existingIndex > -1) {
3996
+ content[existingIndex] = newItem;
3997
+ } else {
3998
+ closePart(content[content.length - 1], now2);
3999
+ content.push(newItem);
4000
+ }
4001
+ }
4002
+ function closePart(prevPart, endedAt) {
4003
+ if (_optionalChain([prevPart, 'optionalAccess', _55 => _55.type]) === "reasoning") {
4004
+ prevPart.endedAt ??= endedAt;
4005
+ }
4006
+ }
3990
4007
  function patchContentWithDelta(content, delta) {
4008
+ if (delta === null)
4009
+ return;
4010
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
3991
4011
  const lastPart = content[content.length - 1];
3992
4012
  switch (delta.type) {
3993
4013
  case "text-delta":
3994
- if (_optionalChain([lastPart, 'optionalAccess', _55 => _55.type]) === "text") {
4014
+ if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "text") {
3995
4015
  lastPart.text += delta.textDelta;
3996
4016
  } else {
4017
+ closePart(lastPart, now2);
3997
4018
  content.push({ type: "text", text: delta.textDelta });
3998
4019
  }
3999
4020
  break;
4000
4021
  case "reasoning-delta":
4001
- if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "reasoning") {
4022
+ if (_optionalChain([lastPart, 'optionalAccess', _57 => _57.type]) === "reasoning") {
4002
4023
  lastPart.text += delta.textDelta;
4003
4024
  } else {
4025
+ closePart(lastPart, now2);
4004
4026
  content.push({
4005
4027
  type: "reasoning",
4006
- text: _nullishCoalesce(delta.textDelta, () => ( ""))
4028
+ text: _nullishCoalesce(delta.textDelta, () => ( "")),
4029
+ startedAt: now2
4007
4030
  });
4008
4031
  }
4009
4032
  break;
@@ -4016,23 +4039,17 @@ function patchContentWithDelta(content, delta) {
4016
4039
  break;
4017
4040
  }
4018
4041
  case "tool-delta": {
4019
- if (_optionalChain([lastPart, 'optionalAccess', _57 => _57.type]) === "tool-invocation" && lastPart.stage === "receiving") {
4020
- _optionalChain([lastPart, 'access', _58 => _58.__appendDelta, 'optionalCall', _59 => _59(delta.delta)]);
4042
+ if (_optionalChain([lastPart, 'optionalAccess', _58 => _58.type]) === "tool-invocation" && lastPart.stage === "receiving") {
4043
+ _optionalChain([lastPart, 'access', _59 => _59.__appendDelta, 'optionalCall', _60 => _60(delta.delta)]);
4021
4044
  }
4022
4045
  break;
4023
4046
  }
4024
- case "tool-invocation": {
4025
- const existingIndex = findLastIndex(
4026
- content,
4027
- (part) => part.type === "tool-invocation" && part.invocationId === delta.invocationId
4028
- );
4029
- if (existingIndex > -1) {
4030
- content[existingIndex] = delta;
4031
- } else {
4032
- content.push(delta);
4033
- }
4047
+ case "tool-invocation":
4048
+ replaceOrAppend(content, delta, (x) => x.invocationId, now2);
4049
+ break;
4050
+ case "retrieval":
4051
+ replaceOrAppend(content, delta, (x) => x.id, now2);
4034
4052
  break;
4035
- }
4036
4053
  default:
4037
4054
  return assertNever(delta, "Unhandled case");
4038
4055
  }
@@ -4044,16 +4061,20 @@ function createReceivingToolInvocation(invocationId, name, partialArgsText = "")
4044
4061
  stage: "receiving",
4045
4062
  invocationId,
4046
4063
  name,
4064
+ // --- Alternative implementation for FRONTEND only ------------------------
4047
4065
  get partialArgsText() {
4048
4066
  return parser.source;
4049
4067
  },
4068
+ // prettier-ignore
4050
4069
  get partialArgs() {
4051
4070
  return parser.json;
4052
4071
  },
4053
- // Internal method to append deltas
4072
+ // prettier-ignore
4054
4073
  __appendDelta(delta) {
4055
4074
  parser.append(delta);
4056
4075
  }
4076
+ // prettier-ignore
4077
+ // ------------------------------------------------------------------------
4057
4078
  };
4058
4079
  }
4059
4080
 
@@ -4138,7 +4159,7 @@ function createStore_forTools() {
4138
4159
  return DerivedSignal.from(() => {
4139
4160
  return (
4140
4161
  // A tool that's registered and scoped to a specific chat ID...
4141
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _60 => _60.get, 'call', _61 => _61()]), () => ( // ...or a globally registered tool
4162
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _61 => _61.get, 'call', _62 => _62()]), () => ( // ...or a globally registered tool
4142
4163
  toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
4143
4164
  );
4144
4165
  });
@@ -4168,8 +4189,8 @@ function createStore_forTools() {
4168
4189
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
4169
4190
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
4170
4191
  return Array.from([
4171
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _62 => _62.entries, 'call', _63 => _63()]), () => ( [])),
4172
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _64 => _64.entries, 'call', _65 => _65()]), () => ( []))
4192
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _63 => _63.entries, 'call', _64 => _64()]), () => ( [])),
4193
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _65 => _65.entries, 'call', _66 => _66()]), () => ( []))
4173
4194
  ]).flatMap(([name, tool\u03A3]) => {
4174
4195
  const tool = tool\u03A3.get();
4175
4196
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -4272,7 +4293,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4272
4293
  } else {
4273
4294
  continue;
4274
4295
  }
4275
- const executeFn = _optionalChain([toolsStore, 'access', _66 => _66.getTool\u03A3, 'call', _67 => _67(toolInvocation.name, message.chatId), 'access', _68 => _68.get, 'call', _69 => _69(), 'optionalAccess', _70 => _70.execute]);
4296
+ const executeFn = _optionalChain([toolsStore, 'access', _67 => _67.getTool\u03A3, 'call', _68 => _68(toolInvocation.name, message.chatId), 'access', _69 => _69.get, 'call', _70 => _70(), 'optionalAccess', _71 => _71.execute]);
4276
4297
  if (executeFn) {
4277
4298
  (async () => {
4278
4299
  const result = await executeFn(toolInvocation.args, {
@@ -4371,8 +4392,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4371
4392
  const spine = [];
4372
4393
  let lastVisitedMessage = null;
4373
4394
  for (const message2 of pool.walkUp(leaf.id)) {
4374
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _71 => _71(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _72 => _72.id]), () => ( null));
4375
- const next = _nullishCoalesce(_optionalChain([first, 'call', _73 => _73(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _74 => _74.id]), () => ( null));
4395
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _72 => _72(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _73 => _73.id]), () => ( null));
4396
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _74 => _74(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _75 => _75.id]), () => ( null));
4376
4397
  if (!message2.deletedAt || prev || next) {
4377
4398
  const node = {
4378
4399
  ...message2,
@@ -4438,7 +4459,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4438
4459
  const latest = pool.sorted.findRight(
4439
4460
  (m) => m.role === "assistant" && !m.deletedAt
4440
4461
  );
4441
- return _optionalChain([latest, 'optionalAccess', _75 => _75.copilotId]);
4462
+ return _optionalChain([latest, 'optionalAccess', _76 => _76.copilotId]);
4442
4463
  }
4443
4464
  return {
4444
4465
  // Readers
@@ -4455,6 +4476,33 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4455
4476
  failAllPending,
4456
4477
  markMine(messageId) {
4457
4478
  myMessages.add(messageId);
4479
+ },
4480
+ /**
4481
+ * Iterates over all my auto-executing messages.
4482
+ *
4483
+ * These are messages that match all these conditions:
4484
+ * - The message is an assistant message
4485
+ * - The message is owned by this client ("mine")
4486
+ * - The message is currently in "awaiting-tool" status
4487
+ * - The message has at least one tool invocation in "executing" stage
4488
+ * - The tool invocation has an execute() function defined
4489
+ */
4490
+ *getAutoExecutingMessageIds() {
4491
+ for (const messageId of myMessages) {
4492
+ const message = getMessageById(messageId);
4493
+ if (_optionalChain([message, 'optionalAccess', _77 => _77.role]) === "assistant" && message.status === "awaiting-tool") {
4494
+ const isAutoExecuting = message.contentSoFar.some((part) => {
4495
+ if (part.type === "tool-invocation" && part.stage === "executing") {
4496
+ const tool = toolsStore.getTool\u03A3(part.name, message.chatId).get();
4497
+ return typeof _optionalChain([tool, 'optionalAccess', _78 => _78.execute]) === "function";
4498
+ }
4499
+ return false;
4500
+ });
4501
+ if (isAutoExecuting) {
4502
+ yield message.id;
4503
+ }
4504
+ }
4505
+ }
4458
4506
  }
4459
4507
  };
4460
4508
  }
@@ -4591,7 +4639,7 @@ function createAi(config) {
4591
4639
  flushPendingDeltas();
4592
4640
  switch (msg.event) {
4593
4641
  case "cmd-failed":
4594
- _optionalChain([pendingCmd, 'optionalAccess', _76 => _76.reject, 'call', _77 => _77(new Error(msg.error))]);
4642
+ _optionalChain([pendingCmd, 'optionalAccess', _79 => _79.reject, 'call', _80 => _80(new Error(msg.error))]);
4595
4643
  break;
4596
4644
  case "settle": {
4597
4645
  context.messagesStore.upsert(msg.message);
@@ -4668,7 +4716,7 @@ function createAi(config) {
4668
4716
  return assertNever(msg, "Unhandled case");
4669
4717
  }
4670
4718
  }
4671
- _optionalChain([pendingCmd, 'optionalAccess', _78 => _78.resolve, 'call', _79 => _79(msg)]);
4719
+ _optionalChain([pendingCmd, 'optionalAccess', _81 => _81.resolve, 'call', _82 => _82(msg)]);
4672
4720
  }
4673
4721
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4674
4722
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4753,9 +4801,9 @@ function createAi(config) {
4753
4801
  invocationId,
4754
4802
  result,
4755
4803
  generationOptions: {
4756
- copilotId: _optionalChain([options, 'optionalAccess', _80 => _80.copilotId]),
4757
- stream: _optionalChain([options, 'optionalAccess', _81 => _81.stream]),
4758
- timeout: _optionalChain([options, 'optionalAccess', _82 => _82.timeout]),
4804
+ copilotId: _optionalChain([options, 'optionalAccess', _83 => _83.copilotId]),
4805
+ stream: _optionalChain([options, 'optionalAccess', _84 => _84.stream]),
4806
+ timeout: _optionalChain([options, 'optionalAccess', _85 => _85.timeout]),
4759
4807
  // Knowledge and tools aren't coming from the options, but retrieved
4760
4808
  // from the global context
4761
4809
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4766,6 +4814,14 @@ function createAi(config) {
4766
4814
  messagesStore.markMine(resp.message.id);
4767
4815
  }
4768
4816
  }
4817
+ function handleBeforeUnload() {
4818
+ for (const messageId of context.messagesStore.getAutoExecutingMessageIds()) {
4819
+ sendClientMsgWithResponse({ cmd: "abort-ai", messageId }).catch(() => {
4820
+ });
4821
+ }
4822
+ }
4823
+ const win = typeof window !== "undefined" ? window : void 0;
4824
+ _optionalChain([win, 'optionalAccess', _86 => _86.addEventListener, 'call', _87 => _87("beforeunload", handleBeforeUnload, { once: true })]);
4769
4825
  return Object.defineProperty(
4770
4826
  {
4771
4827
  [kInternal]: {
@@ -4784,7 +4840,7 @@ function createAi(config) {
4784
4840
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4785
4841
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4786
4842
  const globalKnowledge = context.knowledge.get();
4787
- const requestKnowledge = _optionalChain([options, 'optionalAccess', _83 => _83.knowledge]) || [];
4843
+ const requestKnowledge = _optionalChain([options, 'optionalAccess', _88 => _88.knowledge]) || [];
4788
4844
  const combinedKnowledge = [...globalKnowledge, ...requestKnowledge];
4789
4845
  const tools = context.toolsStore.getToolDescriptions(chatId);
4790
4846
  messagesStore.markMine(targetMessageId);
@@ -4794,9 +4850,9 @@ function createAi(config) {
4794
4850
  sourceMessage: userMessage,
4795
4851
  targetMessageId,
4796
4852
  generationOptions: {
4797
- copilotId: _optionalChain([options, 'optionalAccess', _84 => _84.copilotId]),
4798
- stream: _optionalChain([options, 'optionalAccess', _85 => _85.stream]),
4799
- timeout: _optionalChain([options, 'optionalAccess', _86 => _86.timeout]),
4853
+ copilotId: _optionalChain([options, 'optionalAccess', _89 => _89.copilotId]),
4854
+ stream: _optionalChain([options, 'optionalAccess', _90 => _90.stream]),
4855
+ timeout: _optionalChain([options, 'optionalAccess', _91 => _91.timeout]),
4800
4856
  // Combine global knowledge with request-specific knowledge
4801
4857
  knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
4802
4858
  tools: tools.length > 0 ? tools : void 0
@@ -4833,7 +4889,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
4833
4889
  }
4834
4890
  const url2 = new URL(baseUrl);
4835
4891
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
4836
- url2.pathname = "/ai/v5";
4892
+ url2.pathname = "/ai/v6";
4837
4893
  if (authValue.type === "secret") {
4838
4894
  url2.searchParams.set("tok", authValue.token.raw);
4839
4895
  } else if (authValue.type === "public") {
@@ -4897,7 +4953,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4897
4953
  return void 0;
4898
4954
  }
4899
4955
  async function makeAuthRequest(options) {
4900
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _87 => _87.polyfills, 'optionalAccess', _88 => _88.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4956
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _92 => _92.polyfills, 'optionalAccess', _93 => _93.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4901
4957
  if (authentication.type === "private") {
4902
4958
  if (fetcher === void 0) {
4903
4959
  throw new StopRetrying(
@@ -4913,7 +4969,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4913
4969
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
4914
4970
  );
4915
4971
  }
4916
- _optionalChain([onAuthenticate, 'optionalCall', _89 => _89(parsed.parsed)]);
4972
+ _optionalChain([onAuthenticate, 'optionalCall', _94 => _94(parsed.parsed)]);
4917
4973
  return parsed;
4918
4974
  }
4919
4975
  if (authentication.type === "custom") {
@@ -4921,7 +4977,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4921
4977
  if (response && typeof response === "object") {
4922
4978
  if (typeof response.token === "string") {
4923
4979
  const parsed = parseAuthToken(response.token);
4924
- _optionalChain([onAuthenticate, 'optionalCall', _90 => _90(parsed.parsed)]);
4980
+ _optionalChain([onAuthenticate, 'optionalCall', _95 => _95(parsed.parsed)]);
4925
4981
  return parsed;
4926
4982
  } else if (typeof response.error === "string") {
4927
4983
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -5079,7 +5135,7 @@ function sendToPanel(message, options) {
5079
5135
  ...message,
5080
5136
  source: "liveblocks-devtools-client"
5081
5137
  };
5082
- if (!(_optionalChain([options, 'optionalAccess', _91 => _91.force]) || _bridgeActive)) {
5138
+ if (!(_optionalChain([options, 'optionalAccess', _96 => _96.force]) || _bridgeActive)) {
5083
5139
  return;
5084
5140
  }
5085
5141
  window.postMessage(fullMsg, "*");
@@ -5087,7 +5143,7 @@ function sendToPanel(message, options) {
5087
5143
  var eventSource = makeEventSource();
5088
5144
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
5089
5145
  window.addEventListener("message", (event) => {
5090
- if (event.source === window && _optionalChain([event, 'access', _92 => _92.data, 'optionalAccess', _93 => _93.source]) === "liveblocks-devtools-panel") {
5146
+ if (event.source === window && _optionalChain([event, 'access', _97 => _97.data, 'optionalAccess', _98 => _98.source]) === "liveblocks-devtools-panel") {
5091
5147
  eventSource.notify(event.data);
5092
5148
  } else {
5093
5149
  }
@@ -5229,7 +5285,7 @@ function fullSync(room) {
5229
5285
  msg: "room::sync::full",
5230
5286
  roomId: room.id,
5231
5287
  status: room.getStatus(),
5232
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _94 => _94.toTreeNode, 'call', _95 => _95("root"), 'access', _96 => _96.payload]), () => ( null)),
5288
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _99 => _99.toTreeNode, 'call', _100 => _100("root"), 'access', _101 => _101.payload]), () => ( null)),
5233
5289
  me,
5234
5290
  others
5235
5291
  });
@@ -5520,7 +5576,7 @@ function createManagedPool(roomId, options) {
5520
5576
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5521
5577
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5522
5578
  dispatch(ops, reverse, storageUpdates) {
5523
- _optionalChain([onDispatch, 'optionalCall', _97 => _97(ops, reverse, storageUpdates)]);
5579
+ _optionalChain([onDispatch, 'optionalCall', _102 => _102(ops, reverse, storageUpdates)]);
5524
5580
  },
5525
5581
  assertStorageIsWritable: () => {
5526
5582
  if (!isStorageWritable()) {
@@ -5747,7 +5803,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5747
5803
  return [
5748
5804
  {
5749
5805
  type: 8 /* CREATE_REGISTER */,
5750
- opId: _optionalChain([pool, 'optionalAccess', _98 => _98.generateOpId, 'call', _99 => _99()]),
5806
+ opId: _optionalChain([pool, 'optionalAccess', _103 => _103.generateOpId, 'call', _104 => _104()]),
5751
5807
  id: this._id,
5752
5808
  parentId,
5753
5809
  parentKey,
@@ -5853,7 +5909,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5853
5909
  const ops = [];
5854
5910
  const op = {
5855
5911
  id: this._id,
5856
- opId: _optionalChain([pool, 'optionalAccess', _100 => _100.generateOpId, 'call', _101 => _101()]),
5912
+ opId: _optionalChain([pool, 'optionalAccess', _105 => _105.generateOpId, 'call', _106 => _106()]),
5857
5913
  type: 2 /* CREATE_LIST */,
5858
5914
  parentId,
5859
5915
  parentKey
@@ -6124,7 +6180,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6124
6180
  #applyInsertUndoRedo(op) {
6125
6181
  const { id, parentKey: key } = op;
6126
6182
  const child = creationOpToLiveNode(op);
6127
- if (_optionalChain([this, 'access', _102 => _102._pool, 'optionalAccess', _103 => _103.getNode, 'call', _104 => _104(id)]) !== void 0) {
6183
+ if (_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.getNode, 'call', _109 => _109(id)]) !== void 0) {
6128
6184
  return { modified: false };
6129
6185
  }
6130
6186
  child._attach(id, nn(this._pool));
@@ -6132,8 +6188,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6132
6188
  const existingItemIndex = this._indexOfPosition(key);
6133
6189
  let newKey = key;
6134
6190
  if (existingItemIndex !== -1) {
6135
- const before2 = _optionalChain([this, 'access', _105 => _105.#items, 'access', _106 => _106[existingItemIndex], 'optionalAccess', _107 => _107._parentPos]);
6136
- const after2 = _optionalChain([this, 'access', _108 => _108.#items, 'access', _109 => _109[existingItemIndex + 1], 'optionalAccess', _110 => _110._parentPos]);
6191
+ const before2 = _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[existingItemIndex], 'optionalAccess', _112 => _112._parentPos]);
6192
+ const after2 = _optionalChain([this, 'access', _113 => _113.#items, 'access', _114 => _114[existingItemIndex + 1], 'optionalAccess', _115 => _115._parentPos]);
6137
6193
  newKey = makePosition(before2, after2);
6138
6194
  child._setParentLink(this, newKey);
6139
6195
  }
@@ -6147,7 +6203,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6147
6203
  #applySetUndoRedo(op) {
6148
6204
  const { id, parentKey: key } = op;
6149
6205
  const child = creationOpToLiveNode(op);
6150
- if (_optionalChain([this, 'access', _111 => _111._pool, 'optionalAccess', _112 => _112.getNode, 'call', _113 => _113(id)]) !== void 0) {
6206
+ if (_optionalChain([this, 'access', _116 => _116._pool, 'optionalAccess', _117 => _117.getNode, 'call', _118 => _118(id)]) !== void 0) {
6151
6207
  return { modified: false };
6152
6208
  }
6153
6209
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -6268,7 +6324,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6268
6324
  } else {
6269
6325
  this.#items[existingItemIndex]._setParentLink(
6270
6326
  this,
6271
- makePosition(newKey, _optionalChain([this, 'access', _114 => _114.#items, 'access', _115 => _115[existingItemIndex + 1], 'optionalAccess', _116 => _116._parentPos]))
6327
+ makePosition(newKey, _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120[existingItemIndex + 1], 'optionalAccess', _121 => _121._parentPos]))
6272
6328
  );
6273
6329
  const previousIndex = this.#items.indexOf(child);
6274
6330
  child._setParentLink(this, newKey);
@@ -6293,7 +6349,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6293
6349
  if (existingItemIndex !== -1) {
6294
6350
  this.#items[existingItemIndex]._setParentLink(
6295
6351
  this,
6296
- makePosition(newKey, _optionalChain([this, 'access', _117 => _117.#items, 'access', _118 => _118[existingItemIndex + 1], 'optionalAccess', _119 => _119._parentPos]))
6352
+ makePosition(newKey, _optionalChain([this, 'access', _122 => _122.#items, 'access', _123 => _123[existingItemIndex + 1], 'optionalAccess', _124 => _124._parentPos]))
6297
6353
  );
6298
6354
  }
6299
6355
  child._setParentLink(this, newKey);
@@ -6312,7 +6368,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6312
6368
  if (existingItemIndex !== -1) {
6313
6369
  this.#items[existingItemIndex]._setParentLink(
6314
6370
  this,
6315
- makePosition(newKey, _optionalChain([this, 'access', _120 => _120.#items, 'access', _121 => _121[existingItemIndex + 1], 'optionalAccess', _122 => _122._parentPos]))
6371
+ makePosition(newKey, _optionalChain([this, 'access', _125 => _125.#items, 'access', _126 => _126[existingItemIndex + 1], 'optionalAccess', _127 => _127._parentPos]))
6316
6372
  );
6317
6373
  }
6318
6374
  child._setParentLink(this, newKey);
@@ -6336,13 +6392,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
6336
6392
  const previousKey = nn(child._parentKey);
6337
6393
  const previousIndex = this.#items.indexOf(child);
6338
6394
  const existingItemIndex = this._indexOfPosition(newKey);
6395
+ let actualNewKey = newKey;
6339
6396
  if (existingItemIndex !== -1) {
6340
- this.#items[existingItemIndex]._setParentLink(
6341
- this,
6342
- makePosition(newKey, _optionalChain([this, 'access', _123 => _123.#items, 'access', _124 => _124[existingItemIndex + 1], 'optionalAccess', _125 => _125._parentPos]))
6397
+ actualNewKey = makePosition(
6398
+ newKey,
6399
+ _optionalChain([this, 'access', _128 => _128.#items, 'access', _129 => _129[existingItemIndex + 1], 'optionalAccess', _130 => _130._parentPos])
6343
6400
  );
6344
6401
  }
6345
- child._setParentLink(this, newKey);
6402
+ child._setParentLink(this, actualNewKey);
6346
6403
  this._sortItems();
6347
6404
  const newIndex = this.#items.indexOf(child);
6348
6405
  if (previousIndex === newIndex) {
@@ -6397,7 +6454,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6397
6454
  * @param element The element to add to the end of the LiveList.
6398
6455
  */
6399
6456
  push(element) {
6400
- _optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.assertStorageIsWritable, 'call', _128 => _128()]);
6457
+ _optionalChain([this, 'access', _131 => _131._pool, 'optionalAccess', _132 => _132.assertStorageIsWritable, 'call', _133 => _133()]);
6401
6458
  return this.insert(element, this.length);
6402
6459
  }
6403
6460
  /**
@@ -6406,7 +6463,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6406
6463
  * @param index The index at which you want to insert the element.
6407
6464
  */
6408
6465
  insert(element, index) {
6409
- _optionalChain([this, 'access', _129 => _129._pool, 'optionalAccess', _130 => _130.assertStorageIsWritable, 'call', _131 => _131()]);
6466
+ _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6410
6467
  if (index < 0 || index > this.#items.length) {
6411
6468
  throw new Error(
6412
6469
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6436,7 +6493,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6436
6493
  * @param targetIndex The index where the element should be after moving.
6437
6494
  */
6438
6495
  move(index, targetIndex) {
6439
- _optionalChain([this, 'access', _132 => _132._pool, 'optionalAccess', _133 => _133.assertStorageIsWritable, 'call', _134 => _134()]);
6496
+ _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6440
6497
  if (targetIndex < 0) {
6441
6498
  throw new Error("targetIndex cannot be less than 0");
6442
6499
  }
@@ -6494,7 +6551,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6494
6551
  * @param index The index of the element to delete
6495
6552
  */
6496
6553
  delete(index) {
6497
- _optionalChain([this, 'access', _135 => _135._pool, 'optionalAccess', _136 => _136.assertStorageIsWritable, 'call', _137 => _137()]);
6554
+ _optionalChain([this, 'access', _140 => _140._pool, 'optionalAccess', _141 => _141.assertStorageIsWritable, 'call', _142 => _142()]);
6498
6555
  if (index < 0 || index >= this.#items.length) {
6499
6556
  throw new Error(
6500
6557
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6527,7 +6584,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6527
6584
  }
6528
6585
  }
6529
6586
  clear() {
6530
- _optionalChain([this, 'access', _138 => _138._pool, 'optionalAccess', _139 => _139.assertStorageIsWritable, 'call', _140 => _140()]);
6587
+ _optionalChain([this, 'access', _143 => _143._pool, 'optionalAccess', _144 => _144.assertStorageIsWritable, 'call', _145 => _145()]);
6531
6588
  if (this._pool) {
6532
6589
  const ops = [];
6533
6590
  const reverseOps = [];
@@ -6561,7 +6618,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6561
6618
  }
6562
6619
  }
6563
6620
  set(index, item) {
6564
- _optionalChain([this, 'access', _141 => _141._pool, 'optionalAccess', _142 => _142.assertStorageIsWritable, 'call', _143 => _143()]);
6621
+ _optionalChain([this, 'access', _146 => _146._pool, 'optionalAccess', _147 => _147.assertStorageIsWritable, 'call', _148 => _148()]);
6565
6622
  if (index < 0 || index >= this.#items.length) {
6566
6623
  throw new Error(
6567
6624
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6707,7 +6764,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6707
6764
  #shiftItemPosition(index, key) {
6708
6765
  const shiftedPosition = makePosition(
6709
6766
  key,
6710
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _144 => _144.#items, 'access', _145 => _145[index + 1], 'optionalAccess', _146 => _146._parentPos]) : void 0
6767
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _149 => _149.#items, 'access', _150 => _150[index + 1], 'optionalAccess', _151 => _151._parentPos]) : void 0
6711
6768
  );
6712
6769
  this.#items[index]._setParentLink(this, shiftedPosition);
6713
6770
  }
@@ -6832,7 +6889,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6832
6889
  const ops = [];
6833
6890
  const op = {
6834
6891
  id: this._id,
6835
- opId: _optionalChain([pool, 'optionalAccess', _147 => _147.generateOpId, 'call', _148 => _148()]),
6892
+ opId: _optionalChain([pool, 'optionalAccess', _152 => _152.generateOpId, 'call', _153 => _153()]),
6836
6893
  type: 7 /* CREATE_MAP */,
6837
6894
  parentId,
6838
6895
  parentKey
@@ -6967,7 +7024,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6967
7024
  * @param value The value of the element to add. Should be serializable to JSON.
6968
7025
  */
6969
7026
  set(key, value) {
6970
- _optionalChain([this, 'access', _149 => _149._pool, 'optionalAccess', _150 => _150.assertStorageIsWritable, 'call', _151 => _151()]);
7027
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
6971
7028
  const oldValue = this.#map.get(key);
6972
7029
  if (oldValue) {
6973
7030
  oldValue._detach();
@@ -7013,7 +7070,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7013
7070
  * @returns true if an element existed and has been removed, or false if the element does not exist.
7014
7071
  */
7015
7072
  delete(key) {
7016
- _optionalChain([this, 'access', _152 => _152._pool, 'optionalAccess', _153 => _153.assertStorageIsWritable, 'call', _154 => _154()]);
7073
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
7017
7074
  const item = this.#map.get(key);
7018
7075
  if (item === void 0) {
7019
7076
  return false;
@@ -7203,7 +7260,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7203
7260
  if (this._id === void 0) {
7204
7261
  throw new Error("Cannot serialize item is not attached");
7205
7262
  }
7206
- const opId = _optionalChain([pool, 'optionalAccess', _155 => _155.generateOpId, 'call', _156 => _156()]);
7263
+ const opId = _optionalChain([pool, 'optionalAccess', _160 => _160.generateOpId, 'call', _161 => _161()]);
7207
7264
  const ops = [];
7208
7265
  const op = {
7209
7266
  type: 4 /* CREATE_OBJECT */,
@@ -7475,7 +7532,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7475
7532
  * @param value The value of the property to add
7476
7533
  */
7477
7534
  set(key, value) {
7478
- _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
7535
+ _optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.assertStorageIsWritable, 'call', _164 => _164()]);
7479
7536
  this.update({ [key]: value });
7480
7537
  }
7481
7538
  /**
@@ -7490,7 +7547,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7490
7547
  * @param key The key of the property to delete
7491
7548
  */
7492
7549
  delete(key) {
7493
- _optionalChain([this, 'access', _160 => _160._pool, 'optionalAccess', _161 => _161.assertStorageIsWritable, 'call', _162 => _162()]);
7550
+ _optionalChain([this, 'access', _165 => _165._pool, 'optionalAccess', _166 => _166.assertStorageIsWritable, 'call', _167 => _167()]);
7494
7551
  const keyAsString = key;
7495
7552
  const oldValue = this.#map.get(keyAsString);
7496
7553
  if (oldValue === void 0) {
@@ -7543,7 +7600,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7543
7600
  * @param patch The object used to overrides properties
7544
7601
  */
7545
7602
  update(patch) {
7546
- _optionalChain([this, 'access', _163 => _163._pool, 'optionalAccess', _164 => _164.assertStorageIsWritable, 'call', _165 => _165()]);
7603
+ _optionalChain([this, 'access', _168 => _168._pool, 'optionalAccess', _169 => _169.assertStorageIsWritable, 'call', _170 => _170()]);
7547
7604
  if (_LiveObject.detectLargeObjects) {
7548
7605
  const data = {};
7549
7606
  for (const [key, value] of this.#map) {
@@ -8291,15 +8348,15 @@ function installBackgroundTabSpy() {
8291
8348
  const doc = typeof document !== "undefined" ? document : void 0;
8292
8349
  const inBackgroundSince = { current: null };
8293
8350
  function onVisibilityChange() {
8294
- if (_optionalChain([doc, 'optionalAccess', _166 => _166.visibilityState]) === "hidden") {
8351
+ if (_optionalChain([doc, 'optionalAccess', _171 => _171.visibilityState]) === "hidden") {
8295
8352
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
8296
8353
  } else {
8297
8354
  inBackgroundSince.current = null;
8298
8355
  }
8299
8356
  }
8300
- _optionalChain([doc, 'optionalAccess', _167 => _167.addEventListener, 'call', _168 => _168("visibilitychange", onVisibilityChange)]);
8357
+ _optionalChain([doc, 'optionalAccess', _172 => _172.addEventListener, 'call', _173 => _173("visibilitychange", onVisibilityChange)]);
8301
8358
  const unsub = () => {
8302
- _optionalChain([doc, 'optionalAccess', _169 => _169.removeEventListener, 'call', _170 => _170("visibilitychange", onVisibilityChange)]);
8359
+ _optionalChain([doc, 'optionalAccess', _174 => _174.removeEventListener, 'call', _175 => _175("visibilitychange", onVisibilityChange)]);
8303
8360
  };
8304
8361
  return [inBackgroundSince, unsub];
8305
8362
  }
@@ -8479,7 +8536,7 @@ function createRoom(options, config) {
8479
8536
  }
8480
8537
  }
8481
8538
  function isStorageWritable() {
8482
- const scopes = _optionalChain([context, 'access', _171 => _171.dynamicSessionInfoSig, 'access', _172 => _172.get, 'call', _173 => _173(), 'optionalAccess', _174 => _174.scopes]);
8539
+ const scopes = _optionalChain([context, 'access', _176 => _176.dynamicSessionInfoSig, 'access', _177 => _177.get, 'call', _178 => _178(), 'optionalAccess', _179 => _179.scopes]);
8483
8540
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8484
8541
  }
8485
8542
  const eventHub = {
@@ -8605,7 +8662,7 @@ function createRoom(options, config) {
8605
8662
  }
8606
8663
  case "experimental-fallback-to-http": {
8607
8664
  warn("Message is too large for websockets, so sending over HTTP instead");
8608
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _175 => _175.dynamicSessionInfoSig, 'access', _176 => _176.get, 'call', _177 => _177(), 'optionalAccess', _178 => _178.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8665
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _180 => _180.dynamicSessionInfoSig, 'access', _181 => _181.get, 'call', _182 => _182(), 'optionalAccess', _183 => _183.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8609
8666
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8610
8667
  if (!resp.ok && resp.status === 403) {
8611
8668
  managedSocket.reconnect();
@@ -8656,7 +8713,7 @@ function createRoom(options, config) {
8656
8713
  } else {
8657
8714
  context.root = LiveObject._fromItems(message.items, context.pool);
8658
8715
  }
8659
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _179 => _179.get, 'call', _180 => _180(), 'optionalAccess', _181 => _181.canWrite]), () => ( true));
8716
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _184 => _184.get, 'call', _185 => _185(), 'optionalAccess', _186 => _186.canWrite]), () => ( true));
8660
8717
  const stackSizeBefore = context.undoStack.length;
8661
8718
  for (const key in context.initialStorage) {
8662
8719
  if (context.root.get(key) === void 0) {
@@ -8859,7 +8916,7 @@ function createRoom(options, config) {
8859
8916
  }
8860
8917
  context.myPresence.patch(patch);
8861
8918
  if (context.activeBatch) {
8862
- if (_optionalChain([options2, 'optionalAccess', _182 => _182.addToHistory])) {
8919
+ if (_optionalChain([options2, 'optionalAccess', _187 => _187.addToHistory])) {
8863
8920
  context.activeBatch.reverseOps.pushLeft({
8864
8921
  type: "presence",
8865
8922
  data: oldValues
@@ -8868,7 +8925,7 @@ function createRoom(options, config) {
8868
8925
  context.activeBatch.updates.presence = true;
8869
8926
  } else {
8870
8927
  flushNowOrSoon();
8871
- if (_optionalChain([options2, 'optionalAccess', _183 => _183.addToHistory])) {
8928
+ if (_optionalChain([options2, 'optionalAccess', _188 => _188.addToHistory])) {
8872
8929
  addToUndoStack([{ type: "presence", data: oldValues }]);
8873
8930
  }
8874
8931
  notify({ presence: true });
@@ -9065,7 +9122,7 @@ function createRoom(options, config) {
9065
9122
  if (process.env.NODE_ENV !== "production") {
9066
9123
  const traces = /* @__PURE__ */ new Set();
9067
9124
  for (const opId of message.opIds) {
9068
- const trace = _optionalChain([context, 'access', _184 => _184.opStackTraces, 'optionalAccess', _185 => _185.get, 'call', _186 => _186(opId)]);
9125
+ const trace = _optionalChain([context, 'access', _189 => _189.opStackTraces, 'optionalAccess', _190 => _190.get, 'call', _191 => _191(opId)]);
9069
9126
  if (trace) {
9070
9127
  traces.add(trace);
9071
9128
  }
@@ -9199,7 +9256,7 @@ ${Array.from(traces).join("\n\n")}`
9199
9256
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
9200
9257
  createOrUpdateRootFromMessage(message);
9201
9258
  applyAndSendOps(unacknowledgedOps);
9202
- _optionalChain([_resolveStoragePromise, 'optionalCall', _187 => _187()]);
9259
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _192 => _192()]);
9203
9260
  notifyStorageStatus();
9204
9261
  eventHub.storageDidLoad.notify();
9205
9262
  }
@@ -9420,8 +9477,8 @@ ${Array.from(traces).join("\n\n")}`
9420
9477
  async function getThreads(options2) {
9421
9478
  return httpClient.getThreads({
9422
9479
  roomId,
9423
- query: _optionalChain([options2, 'optionalAccess', _188 => _188.query]),
9424
- cursor: _optionalChain([options2, 'optionalAccess', _189 => _189.cursor])
9480
+ query: _optionalChain([options2, 'optionalAccess', _193 => _193.query]),
9481
+ cursor: _optionalChain([options2, 'optionalAccess', _194 => _194.cursor])
9425
9482
  });
9426
9483
  }
9427
9484
  async function getThread(threadId) {
@@ -9528,7 +9585,7 @@ ${Array.from(traces).join("\n\n")}`
9528
9585
  function getSubscriptionSettings(options2) {
9529
9586
  return httpClient.getSubscriptionSettings({
9530
9587
  roomId,
9531
- signal: _optionalChain([options2, 'optionalAccess', _190 => _190.signal])
9588
+ signal: _optionalChain([options2, 'optionalAccess', _195 => _195.signal])
9532
9589
  });
9533
9590
  }
9534
9591
  function updateSubscriptionSettings(settings) {
@@ -9550,7 +9607,7 @@ ${Array.from(traces).join("\n\n")}`
9550
9607
  {
9551
9608
  [kInternal]: {
9552
9609
  get presenceBuffer() {
9553
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _191 => _191.buffer, 'access', _192 => _192.presenceUpdates, 'optionalAccess', _193 => _193.data]), () => ( null)));
9610
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _196 => _196.buffer, 'access', _197 => _197.presenceUpdates, 'optionalAccess', _198 => _198.data]), () => ( null)));
9554
9611
  },
9555
9612
  // prettier-ignore
9556
9613
  get undoStack() {
@@ -9565,9 +9622,9 @@ ${Array.from(traces).join("\n\n")}`
9565
9622
  return context.yjsProvider;
9566
9623
  },
9567
9624
  setYjsProvider(newProvider) {
9568
- _optionalChain([context, 'access', _194 => _194.yjsProvider, 'optionalAccess', _195 => _195.off, 'call', _196 => _196("status", yjsStatusDidChange)]);
9625
+ _optionalChain([context, 'access', _199 => _199.yjsProvider, 'optionalAccess', _200 => _200.off, 'call', _201 => _201("status", yjsStatusDidChange)]);
9569
9626
  context.yjsProvider = newProvider;
9570
- _optionalChain([newProvider, 'optionalAccess', _197 => _197.on, 'call', _198 => _198("status", yjsStatusDidChange)]);
9627
+ _optionalChain([newProvider, 'optionalAccess', _202 => _202.on, 'call', _203 => _203("status", yjsStatusDidChange)]);
9571
9628
  context.yjsProviderDidChange.notify();
9572
9629
  },
9573
9630
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9613,7 +9670,7 @@ ${Array.from(traces).join("\n\n")}`
9613
9670
  source.dispose();
9614
9671
  }
9615
9672
  eventHub.roomWillDestroy.notify();
9616
- _optionalChain([context, 'access', _199 => _199.yjsProvider, 'optionalAccess', _200 => _200.off, 'call', _201 => _201("status", yjsStatusDidChange)]);
9673
+ _optionalChain([context, 'access', _204 => _204.yjsProvider, 'optionalAccess', _205 => _205.off, 'call', _206 => _206("status", yjsStatusDidChange)]);
9617
9674
  syncSourceForStorage.destroy();
9618
9675
  syncSourceForYjs.destroy();
9619
9676
  uninstallBgTabSpy();
@@ -9763,7 +9820,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9763
9820
  }
9764
9821
  if (isLiveNode(first)) {
9765
9822
  const node = first;
9766
- if (_optionalChain([options, 'optionalAccess', _202 => _202.isDeep])) {
9823
+ if (_optionalChain([options, 'optionalAccess', _207 => _207.isDeep])) {
9767
9824
  const storageCallback = second;
9768
9825
  return subscribeToLiveStructureDeeply(node, storageCallback);
9769
9826
  } else {
@@ -9829,7 +9886,7 @@ function getBaseUrl(baseUrl) {
9829
9886
  }
9830
9887
  function createClient(options) {
9831
9888
  const clientOptions = options;
9832
- const throttleDelay = getThrottle(_nullishCoalesce(clientOptions.throttle, () => ( DEFAULT_THROTTLE)));
9889
+ const throttleDelay = process.env.NODE_ENV !== "production" && clientOptions.__DANGEROUSLY_disableThrottling ? 0 : getThrottle(_nullishCoalesce(clientOptions.throttle, () => ( DEFAULT_THROTTLE)));
9833
9890
  const lostConnectionTimeout = getLostConnectionTimeout(
9834
9891
  _nullishCoalesce(clientOptions.lostConnectionTimeout, () => ( DEFAULT_LOST_CONNECTION_TIMEOUT))
9835
9892
  );
@@ -9842,8 +9899,8 @@ function createClient(options) {
9842
9899
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9843
9900
  currentUserId.set(() => userId);
9844
9901
  });
9845
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _203 => _203.polyfills, 'optionalAccess', _204 => _204.fetch]) || /* istanbul ignore next */
9846
- _optionalChain([globalThis, 'access', _205 => _205.fetch, 'optionalAccess', _206 => _206.bind, 'call', _207 => _207(globalThis)]);
9902
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.fetch]) || /* istanbul ignore next */
9903
+ _optionalChain([globalThis, 'access', _210 => _210.fetch, 'optionalAccess', _211 => _211.bind, 'call', _212 => _212(globalThis)]);
9847
9904
  const httpClient = createApiClient({
9848
9905
  baseUrl,
9849
9906
  fetchPolyfill,
@@ -9861,7 +9918,7 @@ function createClient(options) {
9861
9918
  delegates: {
9862
9919
  createSocket: makeCreateSocketDelegateForAi(
9863
9920
  baseUrl,
9864
- _optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.WebSocket])
9921
+ _optionalChain([clientOptions, 'access', _213 => _213.polyfills, 'optionalAccess', _214 => _214.WebSocket])
9865
9922
  ),
9866
9923
  authenticate: async () => {
9867
9924
  const resp = await authManager.getAuthValue({
@@ -9929,7 +9986,7 @@ function createClient(options) {
9929
9986
  createSocket: makeCreateSocketDelegateForRoom(
9930
9987
  roomId,
9931
9988
  baseUrl,
9932
- _optionalChain([clientOptions, 'access', _210 => _210.polyfills, 'optionalAccess', _211 => _211.WebSocket])
9989
+ _optionalChain([clientOptions, 'access', _215 => _215.polyfills, 'optionalAccess', _216 => _216.WebSocket])
9933
9990
  ),
9934
9991
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
9935
9992
  })),
@@ -9952,7 +10009,7 @@ function createClient(options) {
9952
10009
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
9953
10010
  if (shouldConnect) {
9954
10011
  if (typeof atob === "undefined") {
9955
- if (_optionalChain([clientOptions, 'access', _212 => _212.polyfills, 'optionalAccess', _213 => _213.atob]) === void 0) {
10012
+ if (_optionalChain([clientOptions, 'access', _217 => _217.polyfills, 'optionalAccess', _218 => _218.atob]) === void 0) {
9956
10013
  throw new Error(
9957
10014
  "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"
9958
10015
  );
@@ -9964,7 +10021,7 @@ function createClient(options) {
9964
10021
  return leaseRoom(newRoomDetails);
9965
10022
  }
9966
10023
  function getRoom(roomId) {
9967
- const room = _optionalChain([roomsById, 'access', _214 => _214.get, 'call', _215 => _215(roomId), 'optionalAccess', _216 => _216.room]);
10024
+ const room = _optionalChain([roomsById, 'access', _219 => _219.get, 'call', _220 => _220(roomId), 'optionalAccess', _221 => _221.room]);
9968
10025
  return room ? room : null;
9969
10026
  }
9970
10027
  function logout() {
@@ -9984,7 +10041,7 @@ function createClient(options) {
9984
10041
  const batchedResolveUsers = new Batch(
9985
10042
  async (batchedUserIds) => {
9986
10043
  const userIds = batchedUserIds.flat();
9987
- const users = await _optionalChain([resolveUsers, 'optionalCall', _217 => _217({ userIds })]);
10044
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _222 => _222({ userIds })]);
9988
10045
  warnIfNoResolveUsers();
9989
10046
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
9990
10047
  },
@@ -10002,7 +10059,7 @@ function createClient(options) {
10002
10059
  const batchedResolveRoomsInfo = new Batch(
10003
10060
  async (batchedRoomIds) => {
10004
10061
  const roomIds = batchedRoomIds.flat();
10005
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _218 => _218({ roomIds })]);
10062
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _223 => _223({ roomIds })]);
10006
10063
  warnIfNoResolveRoomsInfo();
10007
10064
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
10008
10065
  },
@@ -10055,7 +10112,7 @@ function createClient(options) {
10055
10112
  }
10056
10113
  };
10057
10114
  const win = typeof window !== "undefined" ? window : void 0;
10058
- _optionalChain([win, 'optionalAccess', _219 => _219.addEventListener, 'call', _220 => _220("beforeunload", maybePreventClose)]);
10115
+ _optionalChain([win, 'optionalAccess', _224 => _224.addEventListener, 'call', _225 => _225("beforeunload", maybePreventClose)]);
10059
10116
  }
10060
10117
  async function getNotificationSettings(options2) {
10061
10118
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -10194,7 +10251,7 @@ var commentBodyElementsTypes = {
10194
10251
  mention: "inline"
10195
10252
  };
10196
10253
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10197
- if (!body || !_optionalChain([body, 'optionalAccess', _221 => _221.content])) {
10254
+ if (!body || !_optionalChain([body, 'optionalAccess', _226 => _226.content])) {
10198
10255
  return;
10199
10256
  }
10200
10257
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -10204,13 +10261,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10204
10261
  for (const block of body.content) {
10205
10262
  if (type === "all" || type === "block") {
10206
10263
  if (guard(block)) {
10207
- _optionalChain([visitor, 'optionalCall', _222 => _222(block)]);
10264
+ _optionalChain([visitor, 'optionalCall', _227 => _227(block)]);
10208
10265
  }
10209
10266
  }
10210
10267
  if (type === "all" || type === "inline") {
10211
10268
  for (const inline of block.children) {
10212
10269
  if (guard(inline)) {
10213
- _optionalChain([visitor, 'optionalCall', _223 => _223(inline)]);
10270
+ _optionalChain([visitor, 'optionalCall', _228 => _228(inline)]);
10214
10271
  }
10215
10272
  }
10216
10273
  }
@@ -10244,7 +10301,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
10244
10301
  userIds
10245
10302
  });
10246
10303
  for (const [index, userId] of userIds.entries()) {
10247
- const user = _optionalChain([users, 'optionalAccess', _224 => _224[index]]);
10304
+ const user = _optionalChain([users, 'optionalAccess', _229 => _229[index]]);
10248
10305
  if (user) {
10249
10306
  resolvedUsers.set(userId, user);
10250
10307
  }
@@ -10363,7 +10420,7 @@ var stringifyCommentBodyPlainElements = {
10363
10420
  text: ({ element }) => element.text,
10364
10421
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
10365
10422
  mention: ({ element, user }) => {
10366
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _225 => _225.name]), () => ( element.id))}`;
10423
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _230 => _230.name]), () => ( element.id))}`;
10367
10424
  }
10368
10425
  };
10369
10426
  var stringifyCommentBodyHtmlElements = {
@@ -10393,7 +10450,7 @@ var stringifyCommentBodyHtmlElements = {
10393
10450
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10394
10451
  },
10395
10452
  mention: ({ element, user }) => {
10396
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _226 => _226.name]) ? html`${_optionalChain([user, 'optionalAccess', _227 => _227.name])}` : element.id}</span>`;
10453
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _231 => _231.name]) ? html`${_optionalChain([user, 'optionalAccess', _232 => _232.name])}` : element.id}</span>`;
10397
10454
  }
10398
10455
  };
10399
10456
  var stringifyCommentBodyMarkdownElements = {
@@ -10423,19 +10480,19 @@ var stringifyCommentBodyMarkdownElements = {
10423
10480
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10424
10481
  },
10425
10482
  mention: ({ element, user }) => {
10426
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _228 => _228.name]), () => ( element.id))}`;
10483
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _233 => _233.name]), () => ( element.id))}`;
10427
10484
  }
10428
10485
  };
10429
10486
  async function stringifyCommentBody(body, options) {
10430
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _229 => _229.format]), () => ( "plain"));
10431
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _230 => _230.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10487
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _234 => _234.format]), () => ( "plain"));
10488
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _235 => _235.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10432
10489
  const elements = {
10433
10490
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10434
- ..._optionalChain([options, 'optionalAccess', _231 => _231.elements])
10491
+ ..._optionalChain([options, 'optionalAccess', _236 => _236.elements])
10435
10492
  };
10436
10493
  const resolvedUsers = await resolveUsersInCommentBody(
10437
10494
  body,
10438
- _optionalChain([options, 'optionalAccess', _232 => _232.resolveUsers])
10495
+ _optionalChain([options, 'optionalAccess', _237 => _237.resolveUsers])
10439
10496
  );
10440
10497
  const blocks = body.content.flatMap((block, blockIndex) => {
10441
10498
  switch (block.type) {
@@ -10721,12 +10778,12 @@ function legacy_patchImmutableNode(state, path, update) {
10721
10778
  }
10722
10779
  const newState = Object.assign({}, state);
10723
10780
  for (const key in update.updates) {
10724
- if (_optionalChain([update, 'access', _233 => _233.updates, 'access', _234 => _234[key], 'optionalAccess', _235 => _235.type]) === "update") {
10781
+ if (_optionalChain([update, 'access', _238 => _238.updates, 'access', _239 => _239[key], 'optionalAccess', _240 => _240.type]) === "update") {
10725
10782
  const val = update.node.get(key);
10726
10783
  if (val !== void 0) {
10727
10784
  newState[key] = lsonToJson(val);
10728
10785
  }
10729
- } else if (_optionalChain([update, 'access', _236 => _236.updates, 'access', _237 => _237[key], 'optionalAccess', _238 => _238.type]) === "delete") {
10786
+ } else if (_optionalChain([update, 'access', _241 => _241.updates, 'access', _242 => _242[key], 'optionalAccess', _243 => _243.type]) === "delete") {
10730
10787
  delete newState[key];
10731
10788
  }
10732
10789
  }
@@ -10787,12 +10844,12 @@ function legacy_patchImmutableNode(state, path, update) {
10787
10844
  }
10788
10845
  const newState = Object.assign({}, state);
10789
10846
  for (const key in update.updates) {
10790
- if (_optionalChain([update, 'access', _239 => _239.updates, 'access', _240 => _240[key], 'optionalAccess', _241 => _241.type]) === "update") {
10847
+ if (_optionalChain([update, 'access', _244 => _244.updates, 'access', _245 => _245[key], 'optionalAccess', _246 => _246.type]) === "update") {
10791
10848
  const value = update.node.get(key);
10792
10849
  if (value !== void 0) {
10793
10850
  newState[key] = lsonToJson(value);
10794
10851
  }
10795
- } else if (_optionalChain([update, 'access', _242 => _242.updates, 'access', _243 => _243[key], 'optionalAccess', _244 => _244.type]) === "delete") {
10852
+ } else if (_optionalChain([update, 'access', _247 => _247.updates, 'access', _248 => _248[key], 'optionalAccess', _249 => _249.type]) === "delete") {
10796
10853
  delete newState[key];
10797
10854
  }
10798
10855
  }
@@ -10872,9 +10929,9 @@ function makePoller(callback, intervalMs, options) {
10872
10929
  const startTime = performance.now();
10873
10930
  const doc = typeof document !== "undefined" ? document : void 0;
10874
10931
  const win = typeof window !== "undefined" ? window : void 0;
10875
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _245 => _245.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10932
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _250 => _250.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10876
10933
  const context = {
10877
- inForeground: _optionalChain([doc, 'optionalAccess', _246 => _246.visibilityState]) !== "hidden",
10934
+ inForeground: _optionalChain([doc, 'optionalAccess', _251 => _251.visibilityState]) !== "hidden",
10878
10935
  lastSuccessfulPollAt: startTime,
10879
10936
  count: 0,
10880
10937
  backoff: 0
@@ -10955,11 +11012,11 @@ function makePoller(callback, intervalMs, options) {
10955
11012
  pollNowIfStale();
10956
11013
  }
10957
11014
  function onVisibilityChange() {
10958
- setInForeground(_optionalChain([doc, 'optionalAccess', _247 => _247.visibilityState]) !== "hidden");
11015
+ setInForeground(_optionalChain([doc, 'optionalAccess', _252 => _252.visibilityState]) !== "hidden");
10959
11016
  }
10960
- _optionalChain([doc, 'optionalAccess', _248 => _248.addEventListener, 'call', _249 => _249("visibilitychange", onVisibilityChange)]);
10961
- _optionalChain([win, 'optionalAccess', _250 => _250.addEventListener, 'call', _251 => _251("online", onVisibilityChange)]);
10962
- _optionalChain([win, 'optionalAccess', _252 => _252.addEventListener, 'call', _253 => _253("focus", pollNowIfStale)]);
11017
+ _optionalChain([doc, 'optionalAccess', _253 => _253.addEventListener, 'call', _254 => _254("visibilitychange", onVisibilityChange)]);
11018
+ _optionalChain([win, 'optionalAccess', _255 => _255.addEventListener, 'call', _256 => _256("online", onVisibilityChange)]);
11019
+ _optionalChain([win, 'optionalAccess', _257 => _257.addEventListener, 'call', _258 => _258("focus", pollNowIfStale)]);
10963
11020
  fsm.start();
10964
11021
  return {
10965
11022
  inc,