@liveblocks/core 2.25.0-aiprivatebeta6 → 2.25.0-aiprivatebeta8

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 = "2.25.0-aiprivatebeta6";
9
+ var PKG_VERSION = "2.25.0-aiprivatebeta8";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -188,6 +188,9 @@ var warnWithTitle = wrapWithTitle("warn");
188
188
  var errorWithTitle = wrapWithTitle("error");
189
189
 
190
190
  // src/lib/guards.ts
191
+ function isDefined(value) {
192
+ return value !== null && value !== void 0;
193
+ }
191
194
  function isPlainObject(blob) {
192
195
  return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
193
196
  }
@@ -3685,11 +3688,6 @@ function parseAuthToken(rawTokenString) {
3685
3688
  function appendDelta(content, delta) {
3686
3689
  const lastPart = content[content.length - 1];
3687
3690
  switch (delta.type) {
3688
- case "reasoning":
3689
- case "text":
3690
- case "tool-call":
3691
- content.push(delta);
3692
- break;
3693
3691
  case "text-delta":
3694
3692
  if (_optionalChain([lastPart, 'optionalAccess', _55 => _55.type]) === "text") {
3695
3693
  lastPart.text += delta.textDelta;
@@ -3700,15 +3698,16 @@ function appendDelta(content, delta) {
3700
3698
  case "reasoning-delta":
3701
3699
  if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "reasoning") {
3702
3700
  lastPart.text += delta.textDelta;
3703
- lastPart.signature ??= delta.signature;
3704
3701
  } else {
3705
3702
  content.push({
3706
3703
  type: "reasoning",
3707
- text: _nullishCoalesce(delta.textDelta, () => ( "")),
3708
- signature: delta.signature
3704
+ text: _nullishCoalesce(delta.textDelta, () => ( ""))
3709
3705
  });
3710
3706
  }
3711
3707
  break;
3708
+ case "tool-invocation":
3709
+ content.push(delta);
3710
+ break;
3712
3711
  default:
3713
3712
  return assertNever(delta, "Unhandled case");
3714
3713
  }
@@ -3716,7 +3715,63 @@ function appendDelta(content, delta) {
3716
3715
 
3717
3716
  // src/ai.ts
3718
3717
  var DEFAULT_REQUEST_TIMEOUT = 4e3;
3719
- var DEFAULT_AI_TIMEOUT = 3e4;
3718
+ var KnowledgeStack = class {
3719
+ #_layers;
3720
+ #stack;
3721
+ // / \
3722
+ // knowledge key "layer" key
3723
+ // (random, or optionally (one entry per mounted component)
3724
+ // set by user)
3725
+ #_cache;
3726
+ constructor() {
3727
+ this.#_layers = /* @__PURE__ */ new Set();
3728
+ this.#stack = new DefaultMap(
3729
+ () => /* @__PURE__ */ new Map()
3730
+ );
3731
+ this.#_cache = void 0;
3732
+ }
3733
+ // Typically a useId()
3734
+ registerLayer(uniqueLayerId) {
3735
+ const layerKey = uniqueLayerId;
3736
+ if (this.#_layers.has(layerKey))
3737
+ raise(`Layer '${layerKey}' already exists, provide a unique layer id`);
3738
+ this.#_layers.add(layerKey);
3739
+ return layerKey;
3740
+ }
3741
+ deregisterLayer(layerKey) {
3742
+ this.#_layers.delete(layerKey);
3743
+ let deleted = false;
3744
+ for (const [key, knowledge] of this.#stack) {
3745
+ if (knowledge.delete(layerKey)) {
3746
+ deleted = true;
3747
+ }
3748
+ if (knowledge.size === 0)
3749
+ this.#stack.delete(key);
3750
+ }
3751
+ if (deleted) {
3752
+ this.invalidate();
3753
+ }
3754
+ }
3755
+ get() {
3756
+ return this.#_cache ??= this.#recompute();
3757
+ }
3758
+ invalidate() {
3759
+ this.#_cache = void 0;
3760
+ }
3761
+ #recompute() {
3762
+ return Array.from(this.#stack.values()).flatMap(
3763
+ (layer) => (
3764
+ // Return only the last item (returns [] when empty)
3765
+ Array.from(layer.values()).slice(-1).filter(isDefined)
3766
+ )
3767
+ );
3768
+ }
3769
+ updateKnowledge(layerKey, key, data) {
3770
+ if (!this.#_layers.has(layerKey)) raise(`Unknown layer key: ${layerKey}`);
3771
+ this.#stack.getOrCreate(key).set(layerKey, data);
3772
+ this.invalidate();
3773
+ }
3774
+ };
3720
3775
  function now() {
3721
3776
  return (/* @__PURE__ */ new Date()).toISOString();
3722
3777
  }
@@ -3730,6 +3785,11 @@ function createStore_forTools() {
3730
3785
  return toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(toolName);
3731
3786
  }
3732
3787
  function addToolDefinition(chatId, name, definition) {
3788
+ if (!definition.execute && !definition.render) {
3789
+ throw new Error(
3790
+ "A tool definition must have an execute() function, a render property, or both."
3791
+ );
3792
+ }
3733
3793
  toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name).set(definition);
3734
3794
  }
3735
3795
  function removeToolDefinition(chatId, toolName) {
@@ -3751,13 +3811,14 @@ function createStore_forTools() {
3751
3811
  }).filter((tool) => tool !== null);
3752
3812
  }
3753
3813
  return {
3754
- getToolCallByName\u03A3: getToolDefinition\u03A3,
3814
+ getToolDefinition\u03A3,
3755
3815
  getToolsForChat,
3756
3816
  addToolDefinition,
3757
3817
  removeToolDefinition
3758
3818
  };
3759
3819
  }
3760
- function createStore_forChatMessages() {
3820
+ function createStore_forChatMessages(toolsStore, setToolResult) {
3821
+ const seenToolCallIds = /* @__PURE__ */ new Set();
3761
3822
  const messagePoolByChatId\u03A3 = new DefaultMap(
3762
3823
  (_chatId) => new MutableSignal(
3763
3824
  new TreePool(
@@ -3767,7 +3828,7 @@ function createStore_forChatMessages() {
3767
3828
  )
3768
3829
  )
3769
3830
  );
3770
- const pendingMessages\u03A3 = new MutableSignal(
3831
+ const generatingMessages\u03A3 = new MutableSignal(
3771
3832
  /* @__PURE__ */ new Map()
3772
3833
  );
3773
3834
  function createOptimistically(chatId, role, parentId, third) {
@@ -3791,7 +3852,7 @@ function createStore_forChatMessages() {
3791
3852
  role,
3792
3853
  parentId,
3793
3854
  createdAt,
3794
- status: "pending",
3855
+ status: "generating",
3795
3856
  contentSoFar: [],
3796
3857
  _optimistic: true
3797
3858
  });
@@ -3810,7 +3871,7 @@ function createStore_forChatMessages() {
3810
3871
  if (!chatMsgs\u03A3) return;
3811
3872
  const existing = chatMsgs\u03A3.get().get(messageId);
3812
3873
  if (!existing || existing.deletedAt) return;
3813
- if (existing.role === "assistant" && (existing.status === "pending" || existing.status === "failed")) {
3874
+ if (existing.role === "assistant" && existing.status !== "completed") {
3814
3875
  upsert({ ...existing, deletedAt: now(), contentSoFar: [] });
3815
3876
  } else {
3816
3877
  upsert({ ...existing, deletedAt: now(), content: [] });
@@ -3825,19 +3886,54 @@ function createStore_forChatMessages() {
3825
3886
  batch(() => {
3826
3887
  const chatMsgs\u03A3 = messagePoolByChatId\u03A3.getOrCreate(message.chatId);
3827
3888
  chatMsgs\u03A3.mutate((pool) => pool.upsert(message));
3828
- if (message.role === "assistant" && message.status === "pending") {
3829
- pendingMessages\u03A3.mutate((lut) => {
3889
+ if (message.role === "assistant" && message.status === "generating") {
3890
+ generatingMessages\u03A3.mutate((lut) => {
3830
3891
  lut.set(message.id, structuredClone(message));
3831
3892
  });
3832
3893
  } else {
3833
- pendingMessages\u03A3.mutate((lut) => {
3894
+ generatingMessages\u03A3.mutate((lut) => {
3834
3895
  lut.delete(message.id);
3835
3896
  });
3836
3897
  }
3898
+ if (message.role === "assistant" && message.status === "awaiting-tool") {
3899
+ for (const toolCall of message.contentSoFar.filter(
3900
+ (part) => part.type === "tool-invocation" && part.status === "executing"
3901
+ )) {
3902
+ if (seenToolCallIds.has(toolCall.toolCallId)) {
3903
+ continue;
3904
+ }
3905
+ seenToolCallIds.add(toolCall.toolCallId);
3906
+ const toolDef = toolsStore.getToolDefinition\u03A3(message.chatId, toolCall.toolName).get();
3907
+ const respondSync = (result) => {
3908
+ setToolResult(
3909
+ message.chatId,
3910
+ message.id,
3911
+ toolCall.toolCallId,
3912
+ result
3913
+ // TODO Pass in AiGenerationOptions here, or make the backend use the same options
3914
+ ).catch((err) => {
3915
+ error2(
3916
+ `Error trying to respond to tool-call: ${String(err)} (in respond())`
3917
+ );
3918
+ });
3919
+ };
3920
+ const executeFn = _optionalChain([toolDef, 'optionalAccess', _57 => _57.execute]);
3921
+ if (executeFn) {
3922
+ (async () => {
3923
+ const result = await executeFn(toolCall.args);
3924
+ respondSync(result);
3925
+ })().catch((err) => {
3926
+ error2(
3927
+ `Error trying to respond to tool-call: ${String(err)} (in execute())`
3928
+ );
3929
+ });
3930
+ }
3931
+ }
3932
+ }
3837
3933
  });
3838
3934
  }
3839
3935
  function addDelta(messageId, delta) {
3840
- pendingMessages\u03A3.mutate((lut) => {
3936
+ generatingMessages\u03A3.mutate((lut) => {
3841
3937
  const message = lut.get(messageId);
3842
3938
  if (message === void 0) return false;
3843
3939
  appendDelta(message.contentSoFar, delta);
@@ -3845,10 +3941,10 @@ function createStore_forChatMessages() {
3845
3941
  return true;
3846
3942
  });
3847
3943
  }
3848
- function* iterPendingMessages() {
3944
+ function* iterGeneratingMessages() {
3849
3945
  for (const chatMsgs\u03A3 of messagePoolByChatId\u03A3.values()) {
3850
3946
  for (const m of chatMsgs\u03A3.get()) {
3851
- if (m.role === "assistant" && m.status === "pending" && !m._optimistic) {
3947
+ if (m.role === "assistant" && m.status === "generating" && !m._optimistic) {
3852
3948
  yield m;
3853
3949
  }
3854
3950
  }
@@ -3856,7 +3952,7 @@ function createStore_forChatMessages() {
3856
3952
  }
3857
3953
  function failAllPending() {
3858
3954
  batch(() => {
3859
- pendingMessages\u03A3.mutate((lut) => {
3955
+ generatingMessages\u03A3.mutate((lut) => {
3860
3956
  let deleted = false;
3861
3957
  for (const [k, v] of lut) {
3862
3958
  if (!v._optimistic) {
@@ -3867,7 +3963,7 @@ function createStore_forChatMessages() {
3867
3963
  return deleted;
3868
3964
  });
3869
3965
  upsertMany(
3870
- Array.from(iterPendingMessages()).map(
3966
+ Array.from(iterGeneratingMessages()).map(
3871
3967
  (message) => ({
3872
3968
  ...message,
3873
3969
  status: "failed",
@@ -3902,11 +3998,20 @@ function createStore_forChatMessages() {
3902
3998
  }
3903
3999
  function selectSpine(leaf) {
3904
4000
  const spine = [];
4001
+ let lastVisitedMessage = null;
3905
4002
  for (const message2 of pool.walkUp(leaf.id)) {
3906
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _57 => _57(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _58 => _58.id]), () => ( null));
3907
- const next = _nullishCoalesce(_optionalChain([first, 'call', _59 => _59(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _60 => _60.id]), () => ( null));
4003
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _58 => _58(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _59 => _59.id]), () => ( null));
4004
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _60 => _60(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _61 => _61.id]), () => ( null));
3908
4005
  if (!message2.deletedAt || prev || next) {
3909
- spine.push({ ...message2, prev, next });
4006
+ const node = {
4007
+ ...message2,
4008
+ navigation: { parent: null, prev, next }
4009
+ };
4010
+ if (lastVisitedMessage !== null) {
4011
+ lastVisitedMessage.navigation.parent = node.id;
4012
+ }
4013
+ lastVisitedMessage = node;
4014
+ spine.push(node);
3910
4015
  }
3911
4016
  }
3912
4017
  return spine.reverse();
@@ -3932,18 +4037,6 @@ function createStore_forChatMessages() {
3932
4037
  }
3933
4038
  return fallback();
3934
4039
  }
3935
- function getLatestUserMessageAncestor(chatId, messageId) {
3936
- const pool = messagePoolByChatId\u03A3.getOrCreate(chatId).get();
3937
- const message = pool.get(messageId);
3938
- if (!message) return null;
3939
- if (message.role === "user") return message.id;
3940
- for (const m of pool.walkUp(message.id)) {
3941
- if (m.role === "user" && !m.deletedAt) {
3942
- return m.id;
3943
- }
3944
- }
3945
- return null;
3946
- }
3947
4040
  const immutableMessagesByBranch = new DefaultMap((chatId) => {
3948
4041
  return new DefaultMap((branchId) => {
3949
4042
  const messages\u03A3 = DerivedSignal.from(() => {
@@ -3951,16 +4044,16 @@ function createStore_forChatMessages() {
3951
4044
  return selectBranch(pool, branchId);
3952
4045
  }, shallow2);
3953
4046
  return DerivedSignal.from(() => {
3954
- const pendingMessages = pendingMessages\u03A3.get();
4047
+ const generatingMessages = generatingMessages\u03A3.get();
3955
4048
  return messages\u03A3.get().map((message) => {
3956
- if (message.role !== "assistant" || message.status !== "pending") {
4049
+ if (message.role !== "assistant" || message.status !== "generating") {
3957
4050
  return message;
3958
4051
  }
3959
- const pendingMessage = pendingMessages.get(message.id);
3960
- if (pendingMessage === void 0) return message;
4052
+ const generatingMessage = generatingMessages.get(message.id);
4053
+ if (generatingMessage === void 0) return message;
3961
4054
  return {
3962
4055
  ...message,
3963
- contentSoFar: pendingMessage.contentSoFar
4056
+ contentSoFar: generatingMessage.contentSoFar
3964
4057
  };
3965
4058
  });
3966
4059
  }, shallow);
@@ -3969,21 +4062,10 @@ function createStore_forChatMessages() {
3969
4062
  function getChatMessagesForBranch\u03A3(chatId, branch) {
3970
4063
  return immutableMessagesByBranch.getOrCreate(chatId).getOrCreate(branch || null);
3971
4064
  }
3972
- const messagesByChatId\u03A3 = new DefaultMap((chatId) => {
3973
- return DerivedSignal.from(() => {
3974
- const pool = messagePoolByChatId\u03A3.getOrCreate(chatId).get();
3975
- return Array.from(pool.sorted);
3976
- });
3977
- });
3978
- function getMessagesForChat\u03A3(chatId) {
3979
- return messagesByChatId\u03A3.getOrCreate(chatId);
3980
- }
3981
4065
  return {
3982
4066
  // Readers
3983
4067
  getMessageById,
3984
4068
  getChatMessagesForBranch\u03A3,
3985
- getMessagesForChat\u03A3,
3986
- getLatestUserMessageAncestor,
3987
4069
  // Mutations
3988
4070
  createOptimistically,
3989
4071
  upsert,
@@ -3999,7 +4081,7 @@ function createStore_forUserAiChats() {
3999
4081
  SortedList.with((x, y) => y.createdAt < x.createdAt)
4000
4082
  );
4001
4083
  const chats\u03A3 = DerivedSignal.from(
4002
- () => Array.from(mutable\u03A3.get()).filter((c) => !c.ephemeral && !c.deletedAt)
4084
+ () => Array.from(mutable\u03A3.get()).filter((c) => !c.deletedAt)
4003
4085
  );
4004
4086
  function upsertMany(chats) {
4005
4087
  mutable\u03A3.mutate((list) => {
@@ -4015,8 +4097,12 @@ function createStore_forUserAiChats() {
4015
4097
  function remove(chatId) {
4016
4098
  mutable\u03A3.mutate((list) => list.removeBy((c) => c.id === chatId, 1));
4017
4099
  }
4100
+ function getChatById(chatId) {
4101
+ return Array.from(mutable\u03A3.get()).find((chat) => chat.id === chatId);
4102
+ }
4018
4103
  return {
4019
4104
  chats\u03A3,
4105
+ getChatById,
4020
4106
  // Mutations
4021
4107
  upsert,
4022
4108
  upsertMany,
@@ -4032,8 +4118,8 @@ function createAi(config) {
4032
4118
  );
4033
4119
  const clientId = nanoid(7);
4034
4120
  const chatsStore = createStore_forUserAiChats();
4035
- const messagesStore = createStore_forChatMessages();
4036
4121
  const toolsStore = createStore_forTools();
4122
+ const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
4037
4123
  const context = {
4038
4124
  staticSessionInfoSig: new Signal(null),
4039
4125
  dynamicSessionInfoSig: new Signal(null),
@@ -4041,7 +4127,7 @@ function createAi(config) {
4041
4127
  chatsStore,
4042
4128
  messagesStore,
4043
4129
  toolsStore,
4044
- knowledgeByChatId: /* @__PURE__ */ new Map()
4130
+ knowledge: new KnowledgeStack()
4045
4131
  };
4046
4132
  let lastTokenKey;
4047
4133
  function onStatusDidChange(_newStatus) {
@@ -4099,7 +4185,7 @@ function createAi(config) {
4099
4185
  if ("event" in msg) {
4100
4186
  switch (msg.event) {
4101
4187
  case "cmd-failed":
4102
- _optionalChain([pendingCmd, 'optionalAccess', _61 => _61.reject, 'call', _62 => _62(new Error(msg.error))]);
4188
+ _optionalChain([pendingCmd, 'optionalAccess', _62 => _62.reject, 'call', _63 => _63(new Error(msg.error))]);
4103
4189
  break;
4104
4190
  case "delta": {
4105
4191
  const { id, delta } = msg;
@@ -4143,7 +4229,7 @@ function createAi(config) {
4143
4229
  case "get-chats":
4144
4230
  context.chatsStore.upsertMany(msg.chats);
4145
4231
  break;
4146
- case "create-chat":
4232
+ case "get-or-create-chat":
4147
4233
  context.chatsStore.upsert(msg.chat);
4148
4234
  break;
4149
4235
  case "delete-chat":
@@ -4168,11 +4254,16 @@ function createAi(config) {
4168
4254
  break;
4169
4255
  case "abort-ai":
4170
4256
  break;
4257
+ case "set-tool-result":
4258
+ if (msg.ok) {
4259
+ context.messagesStore.upsert(msg.message);
4260
+ }
4261
+ break;
4171
4262
  default:
4172
4263
  return assertNever(msg, "Unhandled case");
4173
4264
  }
4174
4265
  }
4175
- _optionalChain([pendingCmd, 'optionalAccess', _63 => _63.resolve, 'call', _64 => _64(msg)]);
4266
+ _optionalChain([pendingCmd, 'optionalAccess', _64 => _64.resolve, 'call', _65 => _65(msg)]);
4176
4267
  }
4177
4268
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4178
4269
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4218,13 +4309,11 @@ function createAi(config) {
4218
4309
  cursor: options.cursor
4219
4310
  });
4220
4311
  }
4221
- function createChat(id, title, options) {
4312
+ function getOrCreateChat(id, options) {
4222
4313
  return sendClientMsgWithResponse({
4223
- cmd: "create-chat",
4314
+ cmd: "get-or-create-chat",
4224
4315
  id,
4225
- title,
4226
- ephemeral: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _65 => _65.ephemeral]), () => ( false)),
4227
- metadata: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.metadata]), () => ( {}))
4316
+ options
4228
4317
  });
4229
4318
  }
4230
4319
  function getMessageTree(chatId) {
@@ -4233,62 +4322,50 @@ function createAi(config) {
4233
4322
  chatId
4234
4323
  });
4235
4324
  }
4236
- function registerKnowledgeSource(chatId, data) {
4237
- const knowledge = context.knowledgeByChatId.get(chatId);
4238
- if (knowledge === void 0) {
4239
- context.knowledgeByChatId.set(chatId, /* @__PURE__ */ new Set([data]));
4240
- } else {
4241
- knowledge.add(data);
4242
- }
4243
- return () => {
4244
- const knowledge2 = context.knowledgeByChatId.get(chatId);
4245
- if (knowledge2 !== void 0) {
4246
- knowledge2.delete(data);
4247
- if (knowledge2.size === 0) {
4248
- context.knowledgeByChatId.delete(chatId);
4249
- }
4250
- }
4251
- };
4325
+ function registerKnowledgeLayer(uniqueLayerId) {
4326
+ return context.knowledge.registerLayer(uniqueLayerId);
4252
4327
  }
4253
- function ask(chatId, messageId, options) {
4254
- const targetMessageId = context.messagesStore.createOptimistically(
4255
- chatId,
4256
- "assistant",
4257
- messageId
4258
- );
4259
- const copilotId = _optionalChain([options, 'optionalAccess', _67 => _67.copilotId]);
4260
- const stream = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.stream]), () => ( false));
4261
- const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _69 => _69.timeout]), () => ( DEFAULT_AI_TIMEOUT));
4262
- const knowledge = context.knowledgeByChatId.get(chatId);
4328
+ function deregisterKnowledgeLayer(layerKey) {
4329
+ context.knowledge.deregisterLayer(layerKey);
4330
+ }
4331
+ function updateKnowledge(layerKey, data, key = nanoid()) {
4332
+ context.knowledge.updateKnowledge(layerKey, key, data);
4333
+ }
4334
+ function debug_getAllKnowledge() {
4335
+ return context.knowledge.get();
4336
+ }
4337
+ async function setToolResult(chatId, messageId, toolCallId, result, options) {
4338
+ const knowledge = context.knowledge.get();
4263
4339
  return sendClientMsgWithResponse({
4264
- cmd: "ask-in-chat",
4340
+ cmd: "set-tool-result",
4265
4341
  chatId,
4266
- sourceMessage: messageId,
4267
- targetMessageId,
4342
+ messageId,
4343
+ toolCallId,
4268
4344
  clientId,
4345
+ result,
4269
4346
  generationOptions: {
4270
- copilotId,
4271
- stream,
4272
- knowledge: knowledge ? Array.from(knowledge) : void 0,
4347
+ copilotId: _optionalChain([options, 'optionalAccess', _66 => _66.copilotId]),
4348
+ stream: _optionalChain([options, 'optionalAccess', _67 => _67.stream]),
4349
+ timeout: _optionalChain([options, 'optionalAccess', _68 => _68.timeout]),
4350
+ knowledge: knowledge.length > 0 ? knowledge : void 0,
4273
4351
  tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
4274
4352
  name: tool.name,
4275
4353
  description: tool.definition.description,
4276
4354
  parameters: tool.definition.parameters
4277
- })),
4278
- timeout
4355
+ }))
4279
4356
  }
4280
4357
  });
4281
4358
  }
4282
4359
  return Object.defineProperty(
4283
4360
  {
4284
4361
  [kInternal]: {
4285
- debugContext: () => context
4362
+ context
4286
4363
  },
4287
4364
  connect: () => managedSocket.connect(),
4288
4365
  reconnect: () => managedSocket.reconnect(),
4289
4366
  disconnect: () => managedSocket.disconnect(),
4290
4367
  getChats,
4291
- createChat,
4368
+ getOrCreateChat,
4292
4369
  deleteChat: (chatId) => {
4293
4370
  return sendClientMsgWithResponse({
4294
4371
  cmd: "delete-chat",
@@ -4298,60 +4375,40 @@ function createAi(config) {
4298
4375
  getMessageTree,
4299
4376
  deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
4300
4377
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4301
- regenerateMessage: (chatId, messageId, options) => {
4302
- const parentUserMessageId = context.messagesStore.getLatestUserMessageAncestor(chatId, messageId);
4303
- if (parentUserMessageId === null) {
4304
- throw new Error(
4305
- `Unable to find user message ancestor for messageId: ${messageId}`
4306
- );
4307
- }
4308
- return ask(chatId, parentUserMessageId, options);
4309
- },
4310
- addUserMessageAndAsk: async (chatId, parentMessageId, message, options) => {
4311
- const content = [{ type: "text", text: message }];
4312
- const newMessageId = context.messagesStore.createOptimistically(
4313
- chatId,
4314
- "user",
4315
- parentMessageId,
4316
- content
4317
- );
4318
- const targetMessageId = context.messagesStore.createOptimistically(
4319
- chatId,
4320
- "assistant",
4321
- newMessageId
4322
- );
4323
- const copilotId = _optionalChain([options, 'optionalAccess', _70 => _70.copilotId]);
4324
- const stream = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.stream]), () => ( false));
4325
- const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.timeout]), () => ( DEFAULT_AI_TIMEOUT));
4326
- const knowledge = context.knowledgeByChatId.get(chatId);
4378
+ askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4379
+ const knowledge = context.knowledge.get();
4327
4380
  return sendClientMsgWithResponse({
4328
4381
  cmd: "ask-in-chat",
4329
4382
  chatId,
4330
- sourceMessage: { id: newMessageId, parentMessageId, content },
4383
+ sourceMessage: userMessage,
4331
4384
  targetMessageId,
4332
4385
  clientId,
4333
4386
  generationOptions: {
4334
- copilotId,
4335
- stream,
4336
- knowledge: knowledge ? Array.from(knowledge) : void 0,
4387
+ copilotId: _optionalChain([options, 'optionalAccess', _69 => _69.copilotId]),
4388
+ stream: _optionalChain([options, 'optionalAccess', _70 => _70.stream]),
4389
+ timeout: _optionalChain([options, 'optionalAccess', _71 => _71.timeout]),
4390
+ knowledge: knowledge.length > 0 ? knowledge : void 0,
4337
4391
  tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
4338
4392
  name: tool.name,
4339
4393
  description: tool.definition.description,
4340
4394
  parameters: tool.definition.parameters
4341
- })),
4342
- timeout
4395
+ }))
4343
4396
  }
4344
4397
  });
4345
4398
  },
4346
4399
  abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
4400
+ setToolResult,
4347
4401
  getStatus: () => managedSocket.getStatus(),
4348
4402
  signals: {
4349
4403
  chats\u03A3: context.chatsStore.chats\u03A3,
4350
4404
  getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
4351
- getToolDefinition\u03A3: context.toolsStore.getToolCallByName\u03A3,
4352
- getMessagesForChat\u03A3: context.messagesStore.getMessagesForChat\u03A3
4405
+ getChatById: context.chatsStore.getChatById,
4406
+ getToolDefinition\u03A3: context.toolsStore.getToolDefinition\u03A3
4353
4407
  },
4354
- registerKnowledgeSource,
4408
+ registerKnowledgeLayer,
4409
+ deregisterKnowledgeLayer,
4410
+ updateKnowledge,
4411
+ debug_getAllKnowledge,
4355
4412
  registerChatTool: context.toolsStore.addToolDefinition,
4356
4413
  unregisterChatTool: context.toolsStore.removeToolDefinition
4357
4414
  },
@@ -4433,7 +4490,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4433
4490
  return void 0;
4434
4491
  }
4435
4492
  async function makeAuthRequest(options) {
4436
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _73 => _73.polyfills, 'optionalAccess', _74 => _74.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4493
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _72 => _72.polyfills, 'optionalAccess', _73 => _73.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4437
4494
  if (authentication.type === "private") {
4438
4495
  if (fetcher === void 0) {
4439
4496
  throw new StopRetrying(
@@ -4449,7 +4506,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4449
4506
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
4450
4507
  );
4451
4508
  }
4452
- _optionalChain([onAuthenticate, 'optionalCall', _75 => _75(parsed.parsed)]);
4509
+ _optionalChain([onAuthenticate, 'optionalCall', _74 => _74(parsed.parsed)]);
4453
4510
  return parsed;
4454
4511
  }
4455
4512
  if (authentication.type === "custom") {
@@ -4457,7 +4514,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4457
4514
  if (response && typeof response === "object") {
4458
4515
  if (typeof response.token === "string") {
4459
4516
  const parsed = parseAuthToken(response.token);
4460
- _optionalChain([onAuthenticate, 'optionalCall', _76 => _76(parsed.parsed)]);
4517
+ _optionalChain([onAuthenticate, 'optionalCall', _75 => _75(parsed.parsed)]);
4461
4518
  return parsed;
4462
4519
  } else if (typeof response.error === "string") {
4463
4520
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -4615,7 +4672,7 @@ function sendToPanel(message, options) {
4615
4672
  ...message,
4616
4673
  source: "liveblocks-devtools-client"
4617
4674
  };
4618
- if (!(_optionalChain([options, 'optionalAccess', _77 => _77.force]) || _bridgeActive)) {
4675
+ if (!(_optionalChain([options, 'optionalAccess', _76 => _76.force]) || _bridgeActive)) {
4619
4676
  return;
4620
4677
  }
4621
4678
  window.postMessage(fullMsg, "*");
@@ -4623,7 +4680,7 @@ function sendToPanel(message, options) {
4623
4680
  var eventSource = makeEventSource();
4624
4681
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
4625
4682
  window.addEventListener("message", (event) => {
4626
- if (event.source === window && _optionalChain([event, 'access', _78 => _78.data, 'optionalAccess', _79 => _79.source]) === "liveblocks-devtools-panel") {
4683
+ if (event.source === window && _optionalChain([event, 'access', _77 => _77.data, 'optionalAccess', _78 => _78.source]) === "liveblocks-devtools-panel") {
4627
4684
  eventSource.notify(event.data);
4628
4685
  } else {
4629
4686
  }
@@ -4765,7 +4822,7 @@ function fullSync(room) {
4765
4822
  msg: "room::sync::full",
4766
4823
  roomId: room.id,
4767
4824
  status: room.getStatus(),
4768
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _80 => _80.toTreeNode, 'call', _81 => _81("root"), 'access', _82 => _82.payload]), () => ( null)),
4825
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _79 => _79.toTreeNode, 'call', _80 => _80("root"), 'access', _81 => _81.payload]), () => ( null)),
4769
4826
  me,
4770
4827
  others
4771
4828
  });
@@ -5056,7 +5113,7 @@ function createManagedPool(roomId, options) {
5056
5113
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5057
5114
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5058
5115
  dispatch(ops, reverse, storageUpdates) {
5059
- _optionalChain([onDispatch, 'optionalCall', _83 => _83(ops, reverse, storageUpdates)]);
5116
+ _optionalChain([onDispatch, 'optionalCall', _82 => _82(ops, reverse, storageUpdates)]);
5060
5117
  },
5061
5118
  assertStorageIsWritable: () => {
5062
5119
  if (!isStorageWritable()) {
@@ -5283,7 +5340,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5283
5340
  return [
5284
5341
  {
5285
5342
  type: 8 /* CREATE_REGISTER */,
5286
- opId: _optionalChain([pool, 'optionalAccess', _84 => _84.generateOpId, 'call', _85 => _85()]),
5343
+ opId: _optionalChain([pool, 'optionalAccess', _83 => _83.generateOpId, 'call', _84 => _84()]),
5287
5344
  id: this._id,
5288
5345
  parentId,
5289
5346
  parentKey,
@@ -5389,7 +5446,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5389
5446
  const ops = [];
5390
5447
  const op = {
5391
5448
  id: this._id,
5392
- opId: _optionalChain([pool, 'optionalAccess', _86 => _86.generateOpId, 'call', _87 => _87()]),
5449
+ opId: _optionalChain([pool, 'optionalAccess', _85 => _85.generateOpId, 'call', _86 => _86()]),
5393
5450
  type: 2 /* CREATE_LIST */,
5394
5451
  parentId,
5395
5452
  parentKey
@@ -5660,7 +5717,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5660
5717
  #applyInsertUndoRedo(op) {
5661
5718
  const { id, parentKey: key } = op;
5662
5719
  const child = creationOpToLiveNode(op);
5663
- if (_optionalChain([this, 'access', _88 => _88._pool, 'optionalAccess', _89 => _89.getNode, 'call', _90 => _90(id)]) !== void 0) {
5720
+ if (_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.getNode, 'call', _89 => _89(id)]) !== void 0) {
5664
5721
  return { modified: false };
5665
5722
  }
5666
5723
  child._attach(id, nn(this._pool));
@@ -5668,8 +5725,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
5668
5725
  const existingItemIndex = this._indexOfPosition(key);
5669
5726
  let newKey = key;
5670
5727
  if (existingItemIndex !== -1) {
5671
- const before2 = _optionalChain([this, 'access', _91 => _91.#items, 'access', _92 => _92[existingItemIndex], 'optionalAccess', _93 => _93._parentPos]);
5672
- const after2 = _optionalChain([this, 'access', _94 => _94.#items, 'access', _95 => _95[existingItemIndex + 1], 'optionalAccess', _96 => _96._parentPos]);
5728
+ const before2 = _optionalChain([this, 'access', _90 => _90.#items, 'access', _91 => _91[existingItemIndex], 'optionalAccess', _92 => _92._parentPos]);
5729
+ const after2 = _optionalChain([this, 'access', _93 => _93.#items, 'access', _94 => _94[existingItemIndex + 1], 'optionalAccess', _95 => _95._parentPos]);
5673
5730
  newKey = makePosition(before2, after2);
5674
5731
  child._setParentLink(this, newKey);
5675
5732
  }
@@ -5683,7 +5740,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5683
5740
  #applySetUndoRedo(op) {
5684
5741
  const { id, parentKey: key } = op;
5685
5742
  const child = creationOpToLiveNode(op);
5686
- if (_optionalChain([this, 'access', _97 => _97._pool, 'optionalAccess', _98 => _98.getNode, 'call', _99 => _99(id)]) !== void 0) {
5743
+ if (_optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.getNode, 'call', _98 => _98(id)]) !== void 0) {
5687
5744
  return { modified: false };
5688
5745
  }
5689
5746
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -5804,7 +5861,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5804
5861
  } else {
5805
5862
  this.#items[existingItemIndex]._setParentLink(
5806
5863
  this,
5807
- makePosition(newKey, _optionalChain([this, 'access', _100 => _100.#items, 'access', _101 => _101[existingItemIndex + 1], 'optionalAccess', _102 => _102._parentPos]))
5864
+ makePosition(newKey, _optionalChain([this, 'access', _99 => _99.#items, 'access', _100 => _100[existingItemIndex + 1], 'optionalAccess', _101 => _101._parentPos]))
5808
5865
  );
5809
5866
  const previousIndex = this.#items.indexOf(child);
5810
5867
  child._setParentLink(this, newKey);
@@ -5829,7 +5886,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5829
5886
  if (existingItemIndex !== -1) {
5830
5887
  this.#items[existingItemIndex]._setParentLink(
5831
5888
  this,
5832
- makePosition(newKey, _optionalChain([this, 'access', _103 => _103.#items, 'access', _104 => _104[existingItemIndex + 1], 'optionalAccess', _105 => _105._parentPos]))
5889
+ makePosition(newKey, _optionalChain([this, 'access', _102 => _102.#items, 'access', _103 => _103[existingItemIndex + 1], 'optionalAccess', _104 => _104._parentPos]))
5833
5890
  );
5834
5891
  }
5835
5892
  child._setParentLink(this, newKey);
@@ -5848,7 +5905,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5848
5905
  if (existingItemIndex !== -1) {
5849
5906
  this.#items[existingItemIndex]._setParentLink(
5850
5907
  this,
5851
- makePosition(newKey, _optionalChain([this, 'access', _106 => _106.#items, 'access', _107 => _107[existingItemIndex + 1], 'optionalAccess', _108 => _108._parentPos]))
5908
+ makePosition(newKey, _optionalChain([this, 'access', _105 => _105.#items, 'access', _106 => _106[existingItemIndex + 1], 'optionalAccess', _107 => _107._parentPos]))
5852
5909
  );
5853
5910
  }
5854
5911
  child._setParentLink(this, newKey);
@@ -5875,7 +5932,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5875
5932
  if (existingItemIndex !== -1) {
5876
5933
  this.#items[existingItemIndex]._setParentLink(
5877
5934
  this,
5878
- makePosition(newKey, _optionalChain([this, 'access', _109 => _109.#items, 'access', _110 => _110[existingItemIndex + 1], 'optionalAccess', _111 => _111._parentPos]))
5935
+ makePosition(newKey, _optionalChain([this, 'access', _108 => _108.#items, 'access', _109 => _109[existingItemIndex + 1], 'optionalAccess', _110 => _110._parentPos]))
5879
5936
  );
5880
5937
  }
5881
5938
  child._setParentLink(this, newKey);
@@ -5933,7 +5990,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5933
5990
  * @param element The element to add to the end of the LiveList.
5934
5991
  */
5935
5992
  push(element) {
5936
- _optionalChain([this, 'access', _112 => _112._pool, 'optionalAccess', _113 => _113.assertStorageIsWritable, 'call', _114 => _114()]);
5993
+ _optionalChain([this, 'access', _111 => _111._pool, 'optionalAccess', _112 => _112.assertStorageIsWritable, 'call', _113 => _113()]);
5937
5994
  return this.insert(element, this.length);
5938
5995
  }
5939
5996
  /**
@@ -5942,7 +5999,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5942
5999
  * @param index The index at which you want to insert the element.
5943
6000
  */
5944
6001
  insert(element, index) {
5945
- _optionalChain([this, 'access', _115 => _115._pool, 'optionalAccess', _116 => _116.assertStorageIsWritable, 'call', _117 => _117()]);
6002
+ _optionalChain([this, 'access', _114 => _114._pool, 'optionalAccess', _115 => _115.assertStorageIsWritable, 'call', _116 => _116()]);
5946
6003
  if (index < 0 || index > this.#items.length) {
5947
6004
  throw new Error(
5948
6005
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -5972,7 +6029,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5972
6029
  * @param targetIndex The index where the element should be after moving.
5973
6030
  */
5974
6031
  move(index, targetIndex) {
5975
- _optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.assertStorageIsWritable, 'call', _120 => _120()]);
6032
+ _optionalChain([this, 'access', _117 => _117._pool, 'optionalAccess', _118 => _118.assertStorageIsWritable, 'call', _119 => _119()]);
5976
6033
  if (targetIndex < 0) {
5977
6034
  throw new Error("targetIndex cannot be less than 0");
5978
6035
  }
@@ -6030,7 +6087,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6030
6087
  * @param index The index of the element to delete
6031
6088
  */
6032
6089
  delete(index) {
6033
- _optionalChain([this, 'access', _121 => _121._pool, 'optionalAccess', _122 => _122.assertStorageIsWritable, 'call', _123 => _123()]);
6090
+ _optionalChain([this, 'access', _120 => _120._pool, 'optionalAccess', _121 => _121.assertStorageIsWritable, 'call', _122 => _122()]);
6034
6091
  if (index < 0 || index >= this.#items.length) {
6035
6092
  throw new Error(
6036
6093
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6063,7 +6120,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6063
6120
  }
6064
6121
  }
6065
6122
  clear() {
6066
- _optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.assertStorageIsWritable, 'call', _126 => _126()]);
6123
+ _optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.assertStorageIsWritable, 'call', _125 => _125()]);
6067
6124
  if (this._pool) {
6068
6125
  const ops = [];
6069
6126
  const reverseOps = [];
@@ -6097,7 +6154,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6097
6154
  }
6098
6155
  }
6099
6156
  set(index, item) {
6100
- _optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.assertStorageIsWritable, 'call', _129 => _129()]);
6157
+ _optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.assertStorageIsWritable, 'call', _128 => _128()]);
6101
6158
  if (index < 0 || index >= this.#items.length) {
6102
6159
  throw new Error(
6103
6160
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6243,7 +6300,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6243
6300
  #shiftItemPosition(index, key) {
6244
6301
  const shiftedPosition = makePosition(
6245
6302
  key,
6246
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131[index + 1], 'optionalAccess', _132 => _132._parentPos]) : void 0
6303
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _129 => _129.#items, 'access', _130 => _130[index + 1], 'optionalAccess', _131 => _131._parentPos]) : void 0
6247
6304
  );
6248
6305
  this.#items[index]._setParentLink(this, shiftedPosition);
6249
6306
  }
@@ -6368,7 +6425,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6368
6425
  const ops = [];
6369
6426
  const op = {
6370
6427
  id: this._id,
6371
- opId: _optionalChain([pool, 'optionalAccess', _133 => _133.generateOpId, 'call', _134 => _134()]),
6428
+ opId: _optionalChain([pool, 'optionalAccess', _132 => _132.generateOpId, 'call', _133 => _133()]),
6372
6429
  type: 7 /* CREATE_MAP */,
6373
6430
  parentId,
6374
6431
  parentKey
@@ -6503,7 +6560,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6503
6560
  * @param value The value of the element to add. Should be serializable to JSON.
6504
6561
  */
6505
6562
  set(key, value) {
6506
- _optionalChain([this, 'access', _135 => _135._pool, 'optionalAccess', _136 => _136.assertStorageIsWritable, 'call', _137 => _137()]);
6563
+ _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6507
6564
  const oldValue = this.#map.get(key);
6508
6565
  if (oldValue) {
6509
6566
  oldValue._detach();
@@ -6549,7 +6606,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6549
6606
  * @returns true if an element existed and has been removed, or false if the element does not exist.
6550
6607
  */
6551
6608
  delete(key) {
6552
- _optionalChain([this, 'access', _138 => _138._pool, 'optionalAccess', _139 => _139.assertStorageIsWritable, 'call', _140 => _140()]);
6609
+ _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6553
6610
  const item = this.#map.get(key);
6554
6611
  if (item === void 0) {
6555
6612
  return false;
@@ -6728,7 +6785,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
6728
6785
  if (this._id === void 0) {
6729
6786
  throw new Error("Cannot serialize item is not attached");
6730
6787
  }
6731
- const opId = _optionalChain([pool, 'optionalAccess', _141 => _141.generateOpId, 'call', _142 => _142()]);
6788
+ const opId = _optionalChain([pool, 'optionalAccess', _140 => _140.generateOpId, 'call', _141 => _141()]);
6732
6789
  const ops = [];
6733
6790
  const op = {
6734
6791
  type: 4 /* CREATE_OBJECT */,
@@ -7000,7 +7057,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7000
7057
  * @param value The value of the property to add
7001
7058
  */
7002
7059
  set(key, value) {
7003
- _optionalChain([this, 'access', _143 => _143._pool, 'optionalAccess', _144 => _144.assertStorageIsWritable, 'call', _145 => _145()]);
7060
+ _optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
7004
7061
  this.update({ [key]: value });
7005
7062
  }
7006
7063
  /**
@@ -7015,7 +7072,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7015
7072
  * @param key The key of the property to delete
7016
7073
  */
7017
7074
  delete(key) {
7018
- _optionalChain([this, 'access', _146 => _146._pool, 'optionalAccess', _147 => _147.assertStorageIsWritable, 'call', _148 => _148()]);
7075
+ _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
7019
7076
  const keyAsString = key;
7020
7077
  const oldValue = this.#map.get(keyAsString);
7021
7078
  if (oldValue === void 0) {
@@ -7068,7 +7125,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7068
7125
  * @param patch The object used to overrides properties
7069
7126
  */
7070
7127
  update(patch) {
7071
- _optionalChain([this, 'access', _149 => _149._pool, 'optionalAccess', _150 => _150.assertStorageIsWritable, 'call', _151 => _151()]);
7128
+ _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
7072
7129
  if (this._pool === void 0 || this._id === void 0) {
7073
7130
  for (const key in patch) {
7074
7131
  const newValue = patch[key];
@@ -7791,15 +7848,15 @@ function installBackgroundTabSpy() {
7791
7848
  const doc = typeof document !== "undefined" ? document : void 0;
7792
7849
  const inBackgroundSince = { current: null };
7793
7850
  function onVisibilityChange() {
7794
- if (_optionalChain([doc, 'optionalAccess', _152 => _152.visibilityState]) === "hidden") {
7851
+ if (_optionalChain([doc, 'optionalAccess', _151 => _151.visibilityState]) === "hidden") {
7795
7852
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
7796
7853
  } else {
7797
7854
  inBackgroundSince.current = null;
7798
7855
  }
7799
7856
  }
7800
- _optionalChain([doc, 'optionalAccess', _153 => _153.addEventListener, 'call', _154 => _154("visibilitychange", onVisibilityChange)]);
7857
+ _optionalChain([doc, 'optionalAccess', _152 => _152.addEventListener, 'call', _153 => _153("visibilitychange", onVisibilityChange)]);
7801
7858
  const unsub = () => {
7802
- _optionalChain([doc, 'optionalAccess', _155 => _155.removeEventListener, 'call', _156 => _156("visibilitychange", onVisibilityChange)]);
7859
+ _optionalChain([doc, 'optionalAccess', _154 => _154.removeEventListener, 'call', _155 => _155("visibilitychange", onVisibilityChange)]);
7803
7860
  };
7804
7861
  return [inBackgroundSince, unsub];
7805
7862
  }
@@ -7979,7 +8036,7 @@ function createRoom(options, config) {
7979
8036
  }
7980
8037
  }
7981
8038
  function isStorageWritable() {
7982
- const scopes = _optionalChain([context, 'access', _157 => _157.dynamicSessionInfoSig, 'access', _158 => _158.get, 'call', _159 => _159(), 'optionalAccess', _160 => _160.scopes]);
8039
+ const scopes = _optionalChain([context, 'access', _156 => _156.dynamicSessionInfoSig, 'access', _157 => _157.get, 'call', _158 => _158(), 'optionalAccess', _159 => _159.scopes]);
7983
8040
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
7984
8041
  }
7985
8042
  const eventHub = {
@@ -8096,7 +8153,7 @@ function createRoom(options, config) {
8096
8153
  }
8097
8154
  case "experimental-fallback-to-http": {
8098
8155
  warn("Message is too large for websockets, so sending over HTTP instead");
8099
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _161 => _161.dynamicSessionInfoSig, 'access', _162 => _162.get, 'call', _163 => _163(), 'optionalAccess', _164 => _164.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8156
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _160 => _160.dynamicSessionInfoSig, 'access', _161 => _161.get, 'call', _162 => _162(), 'optionalAccess', _163 => _163.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8100
8157
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8101
8158
  if (!resp.ok && resp.status === 403) {
8102
8159
  managedSocket.reconnect();
@@ -8147,7 +8204,7 @@ function createRoom(options, config) {
8147
8204
  } else {
8148
8205
  context.root = LiveObject._fromItems(message.items, context.pool);
8149
8206
  }
8150
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _165 => _165.get, 'call', _166 => _166(), 'optionalAccess', _167 => _167.canWrite]), () => ( true));
8207
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _164 => _164.get, 'call', _165 => _165(), 'optionalAccess', _166 => _166.canWrite]), () => ( true));
8151
8208
  const stackSizeBefore = context.undoStack.length;
8152
8209
  for (const key in context.initialStorage) {
8153
8210
  if (context.root.get(key) === void 0) {
@@ -8350,7 +8407,7 @@ function createRoom(options, config) {
8350
8407
  }
8351
8408
  context.myPresence.patch(patch);
8352
8409
  if (context.activeBatch) {
8353
- if (_optionalChain([options2, 'optionalAccess', _168 => _168.addToHistory])) {
8410
+ if (_optionalChain([options2, 'optionalAccess', _167 => _167.addToHistory])) {
8354
8411
  context.activeBatch.reverseOps.pushLeft({
8355
8412
  type: "presence",
8356
8413
  data: oldValues
@@ -8359,7 +8416,7 @@ function createRoom(options, config) {
8359
8416
  context.activeBatch.updates.presence = true;
8360
8417
  } else {
8361
8418
  flushNowOrSoon();
8362
- if (_optionalChain([options2, 'optionalAccess', _169 => _169.addToHistory])) {
8419
+ if (_optionalChain([options2, 'optionalAccess', _168 => _168.addToHistory])) {
8363
8420
  addToUndoStack([{ type: "presence", data: oldValues }]);
8364
8421
  }
8365
8422
  notify({ presence: true });
@@ -8556,7 +8613,7 @@ function createRoom(options, config) {
8556
8613
  if (process.env.NODE_ENV !== "production") {
8557
8614
  const traces = /* @__PURE__ */ new Set();
8558
8615
  for (const opId of message.opIds) {
8559
- const trace = _optionalChain([context, 'access', _170 => _170.opStackTraces, 'optionalAccess', _171 => _171.get, 'call', _172 => _172(opId)]);
8616
+ const trace = _optionalChain([context, 'access', _169 => _169.opStackTraces, 'optionalAccess', _170 => _170.get, 'call', _171 => _171(opId)]);
8560
8617
  if (trace) {
8561
8618
  traces.add(trace);
8562
8619
  }
@@ -8690,7 +8747,7 @@ ${Array.from(traces).join("\n\n")}`
8690
8747
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
8691
8748
  createOrUpdateRootFromMessage(message);
8692
8749
  applyAndSendOps(unacknowledgedOps);
8693
- _optionalChain([_resolveStoragePromise, 'optionalCall', _173 => _173()]);
8750
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _172 => _172()]);
8694
8751
  notifyStorageStatus();
8695
8752
  eventHub.storageDidLoad.notify();
8696
8753
  }
@@ -8913,8 +8970,8 @@ ${Array.from(traces).join("\n\n")}`
8913
8970
  async function getThreads(options2) {
8914
8971
  return httpClient.getThreads({
8915
8972
  roomId,
8916
- query: _optionalChain([options2, 'optionalAccess', _174 => _174.query]),
8917
- cursor: _optionalChain([options2, 'optionalAccess', _175 => _175.cursor])
8973
+ query: _optionalChain([options2, 'optionalAccess', _173 => _173.query]),
8974
+ cursor: _optionalChain([options2, 'optionalAccess', _174 => _174.cursor])
8918
8975
  });
8919
8976
  }
8920
8977
  async function getThread(threadId) {
@@ -9021,7 +9078,7 @@ ${Array.from(traces).join("\n\n")}`
9021
9078
  function getSubscriptionSettings(options2) {
9022
9079
  return httpClient.getSubscriptionSettings({
9023
9080
  roomId,
9024
- signal: _optionalChain([options2, 'optionalAccess', _176 => _176.signal])
9081
+ signal: _optionalChain([options2, 'optionalAccess', _175 => _175.signal])
9025
9082
  });
9026
9083
  }
9027
9084
  function updateSubscriptionSettings(settings) {
@@ -9043,7 +9100,7 @@ ${Array.from(traces).join("\n\n")}`
9043
9100
  {
9044
9101
  [kInternal]: {
9045
9102
  get presenceBuffer() {
9046
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _177 => _177.buffer, 'access', _178 => _178.presenceUpdates, 'optionalAccess', _179 => _179.data]), () => ( null)));
9103
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _176 => _176.buffer, 'access', _177 => _177.presenceUpdates, 'optionalAccess', _178 => _178.data]), () => ( null)));
9047
9104
  },
9048
9105
  // prettier-ignore
9049
9106
  get undoStack() {
@@ -9058,9 +9115,9 @@ ${Array.from(traces).join("\n\n")}`
9058
9115
  return context.yjsProvider;
9059
9116
  },
9060
9117
  setYjsProvider(newProvider) {
9061
- _optionalChain([context, 'access', _180 => _180.yjsProvider, 'optionalAccess', _181 => _181.off, 'call', _182 => _182("status", yjsStatusDidChange)]);
9118
+ _optionalChain([context, 'access', _179 => _179.yjsProvider, 'optionalAccess', _180 => _180.off, 'call', _181 => _181("status", yjsStatusDidChange)]);
9062
9119
  context.yjsProvider = newProvider;
9063
- _optionalChain([newProvider, 'optionalAccess', _183 => _183.on, 'call', _184 => _184("status", yjsStatusDidChange)]);
9120
+ _optionalChain([newProvider, 'optionalAccess', _182 => _182.on, 'call', _183 => _183("status", yjsStatusDidChange)]);
9064
9121
  context.yjsProviderDidChange.notify();
9065
9122
  },
9066
9123
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9106,7 +9163,7 @@ ${Array.from(traces).join("\n\n")}`
9106
9163
  source.dispose();
9107
9164
  }
9108
9165
  eventHub.roomWillDestroy.notify();
9109
- _optionalChain([context, 'access', _185 => _185.yjsProvider, 'optionalAccess', _186 => _186.off, 'call', _187 => _187("status", yjsStatusDidChange)]);
9166
+ _optionalChain([context, 'access', _184 => _184.yjsProvider, 'optionalAccess', _185 => _185.off, 'call', _186 => _186("status", yjsStatusDidChange)]);
9110
9167
  syncSourceForStorage.destroy();
9111
9168
  syncSourceForYjs.destroy();
9112
9169
  uninstallBgTabSpy();
@@ -9256,7 +9313,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9256
9313
  }
9257
9314
  if (isLiveNode(first)) {
9258
9315
  const node = first;
9259
- if (_optionalChain([options, 'optionalAccess', _188 => _188.isDeep])) {
9316
+ if (_optionalChain([options, 'optionalAccess', _187 => _187.isDeep])) {
9260
9317
  const storageCallback = second;
9261
9318
  return subscribeToLiveStructureDeeply(node, storageCallback);
9262
9319
  } else {
@@ -9335,8 +9392,8 @@ function createClient(options) {
9335
9392
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9336
9393
  currentUserId.set(() => userId);
9337
9394
  });
9338
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _189 => _189.polyfills, 'optionalAccess', _190 => _190.fetch]) || /* istanbul ignore next */
9339
- _optionalChain([globalThis, 'access', _191 => _191.fetch, 'optionalAccess', _192 => _192.bind, 'call', _193 => _193(globalThis)]);
9395
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _188 => _188.polyfills, 'optionalAccess', _189 => _189.fetch]) || /* istanbul ignore next */
9396
+ _optionalChain([globalThis, 'access', _190 => _190.fetch, 'optionalAccess', _191 => _191.bind, 'call', _192 => _192(globalThis)]);
9340
9397
  const httpClient = createApiClient({
9341
9398
  baseUrl,
9342
9399
  fetchPolyfill,
@@ -9354,7 +9411,7 @@ function createClient(options) {
9354
9411
  delegates: {
9355
9412
  createSocket: makeCreateSocketDelegateForAi(
9356
9413
  baseUrl,
9357
- _optionalChain([clientOptions, 'access', _194 => _194.polyfills, 'optionalAccess', _195 => _195.WebSocket])
9414
+ _optionalChain([clientOptions, 'access', _193 => _193.polyfills, 'optionalAccess', _194 => _194.WebSocket])
9358
9415
  ),
9359
9416
  authenticate: makeAuthDelegateForRoom("default", authManager),
9360
9417
  canZombie: () => true
@@ -9404,7 +9461,7 @@ function createClient(options) {
9404
9461
  createSocket: makeCreateSocketDelegateForRoom(
9405
9462
  roomId,
9406
9463
  baseUrl,
9407
- _optionalChain([clientOptions, 'access', _196 => _196.polyfills, 'optionalAccess', _197 => _197.WebSocket])
9464
+ _optionalChain([clientOptions, 'access', _195 => _195.polyfills, 'optionalAccess', _196 => _196.WebSocket])
9408
9465
  ),
9409
9466
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
9410
9467
  })),
@@ -9427,7 +9484,7 @@ function createClient(options) {
9427
9484
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
9428
9485
  if (shouldConnect) {
9429
9486
  if (typeof atob === "undefined") {
9430
- if (_optionalChain([clientOptions, 'access', _198 => _198.polyfills, 'optionalAccess', _199 => _199.atob]) === void 0) {
9487
+ if (_optionalChain([clientOptions, 'access', _197 => _197.polyfills, 'optionalAccess', _198 => _198.atob]) === void 0) {
9431
9488
  throw new Error(
9432
9489
  "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"
9433
9490
  );
@@ -9439,7 +9496,7 @@ function createClient(options) {
9439
9496
  return leaseRoom(newRoomDetails);
9440
9497
  }
9441
9498
  function getRoom(roomId) {
9442
- const room = _optionalChain([roomsById, 'access', _200 => _200.get, 'call', _201 => _201(roomId), 'optionalAccess', _202 => _202.room]);
9499
+ const room = _optionalChain([roomsById, 'access', _199 => _199.get, 'call', _200 => _200(roomId), 'optionalAccess', _201 => _201.room]);
9443
9500
  return room ? room : null;
9444
9501
  }
9445
9502
  function logout() {
@@ -9459,7 +9516,7 @@ function createClient(options) {
9459
9516
  const batchedResolveUsers = new Batch(
9460
9517
  async (batchedUserIds) => {
9461
9518
  const userIds = batchedUserIds.flat();
9462
- const users = await _optionalChain([resolveUsers, 'optionalCall', _203 => _203({ userIds })]);
9519
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _202 => _202({ userIds })]);
9463
9520
  warnIfNoResolveUsers();
9464
9521
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
9465
9522
  },
@@ -9477,7 +9534,7 @@ function createClient(options) {
9477
9534
  const batchedResolveRoomsInfo = new Batch(
9478
9535
  async (batchedRoomIds) => {
9479
9536
  const roomIds = batchedRoomIds.flat();
9480
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _204 => _204({ roomIds })]);
9537
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _203 => _203({ roomIds })]);
9481
9538
  warnIfNoResolveRoomsInfo();
9482
9539
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
9483
9540
  },
@@ -9530,7 +9587,7 @@ function createClient(options) {
9530
9587
  }
9531
9588
  };
9532
9589
  const win = typeof window !== "undefined" ? window : void 0;
9533
- _optionalChain([win, 'optionalAccess', _205 => _205.addEventListener, 'call', _206 => _206("beforeunload", maybePreventClose)]);
9590
+ _optionalChain([win, 'optionalAccess', _204 => _204.addEventListener, 'call', _205 => _205("beforeunload", maybePreventClose)]);
9534
9591
  }
9535
9592
  async function getNotificationSettings(options2) {
9536
9593
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -9669,7 +9726,7 @@ var commentBodyElementsTypes = {
9669
9726
  mention: "inline"
9670
9727
  };
9671
9728
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9672
- if (!body || !_optionalChain([body, 'optionalAccess', _207 => _207.content])) {
9729
+ if (!body || !_optionalChain([body, 'optionalAccess', _206 => _206.content])) {
9673
9730
  return;
9674
9731
  }
9675
9732
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -9679,13 +9736,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9679
9736
  for (const block of body.content) {
9680
9737
  if (type === "all" || type === "block") {
9681
9738
  if (guard(block)) {
9682
- _optionalChain([visitor, 'optionalCall', _208 => _208(block)]);
9739
+ _optionalChain([visitor, 'optionalCall', _207 => _207(block)]);
9683
9740
  }
9684
9741
  }
9685
9742
  if (type === "all" || type === "inline") {
9686
9743
  for (const inline of block.children) {
9687
9744
  if (guard(inline)) {
9688
- _optionalChain([visitor, 'optionalCall', _209 => _209(inline)]);
9745
+ _optionalChain([visitor, 'optionalCall', _208 => _208(inline)]);
9689
9746
  }
9690
9747
  }
9691
9748
  }
@@ -9710,7 +9767,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
9710
9767
  userIds
9711
9768
  });
9712
9769
  for (const [index, userId] of userIds.entries()) {
9713
- const user = _optionalChain([users, 'optionalAccess', _210 => _210[index]]);
9770
+ const user = _optionalChain([users, 'optionalAccess', _209 => _209[index]]);
9714
9771
  if (user) {
9715
9772
  resolvedUsers.set(userId, user);
9716
9773
  }
@@ -9837,7 +9894,7 @@ var stringifyCommentBodyPlainElements = {
9837
9894
  text: ({ element }) => element.text,
9838
9895
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
9839
9896
  mention: ({ element, user }) => {
9840
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _211 => _211.name]), () => ( element.id))}`;
9897
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _210 => _210.name]), () => ( element.id))}`;
9841
9898
  }
9842
9899
  };
9843
9900
  var stringifyCommentBodyHtmlElements = {
@@ -9867,7 +9924,7 @@ var stringifyCommentBodyHtmlElements = {
9867
9924
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
9868
9925
  },
9869
9926
  mention: ({ element, user }) => {
9870
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _212 => _212.name]) ? html`${_optionalChain([user, 'optionalAccess', _213 => _213.name])}` : element.id}</span>`;
9927
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _211 => _211.name]) ? html`${_optionalChain([user, 'optionalAccess', _212 => _212.name])}` : element.id}</span>`;
9871
9928
  }
9872
9929
  };
9873
9930
  var stringifyCommentBodyMarkdownElements = {
@@ -9897,19 +9954,19 @@ var stringifyCommentBodyMarkdownElements = {
9897
9954
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
9898
9955
  },
9899
9956
  mention: ({ element, user }) => {
9900
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _214 => _214.name]), () => ( element.id))}`;
9957
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _213 => _213.name]), () => ( element.id))}`;
9901
9958
  }
9902
9959
  };
9903
9960
  async function stringifyCommentBody(body, options) {
9904
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _215 => _215.format]), () => ( "plain"));
9905
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _216 => _216.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
9961
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _214 => _214.format]), () => ( "plain"));
9962
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _215 => _215.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
9906
9963
  const elements = {
9907
9964
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
9908
- ..._optionalChain([options, 'optionalAccess', _217 => _217.elements])
9965
+ ..._optionalChain([options, 'optionalAccess', _216 => _216.elements])
9909
9966
  };
9910
9967
  const resolvedUsers = await resolveUsersInCommentBody(
9911
9968
  body,
9912
- _optionalChain([options, 'optionalAccess', _218 => _218.resolveUsers])
9969
+ _optionalChain([options, 'optionalAccess', _217 => _217.resolveUsers])
9913
9970
  );
9914
9971
  const blocks = body.content.flatMap((block, blockIndex) => {
9915
9972
  switch (block.type) {
@@ -10200,12 +10257,12 @@ function legacy_patchImmutableNode(state, path, update) {
10200
10257
  }
10201
10258
  const newState = Object.assign({}, state);
10202
10259
  for (const key in update.updates) {
10203
- if (_optionalChain([update, 'access', _219 => _219.updates, 'access', _220 => _220[key], 'optionalAccess', _221 => _221.type]) === "update") {
10260
+ if (_optionalChain([update, 'access', _218 => _218.updates, 'access', _219 => _219[key], 'optionalAccess', _220 => _220.type]) === "update") {
10204
10261
  const val = update.node.get(key);
10205
10262
  if (val !== void 0) {
10206
10263
  newState[key] = lsonToJson(val);
10207
10264
  }
10208
- } else if (_optionalChain([update, 'access', _222 => _222.updates, 'access', _223 => _223[key], 'optionalAccess', _224 => _224.type]) === "delete") {
10265
+ } else if (_optionalChain([update, 'access', _221 => _221.updates, 'access', _222 => _222[key], 'optionalAccess', _223 => _223.type]) === "delete") {
10209
10266
  delete newState[key];
10210
10267
  }
10211
10268
  }
@@ -10266,12 +10323,12 @@ function legacy_patchImmutableNode(state, path, update) {
10266
10323
  }
10267
10324
  const newState = Object.assign({}, state);
10268
10325
  for (const key in update.updates) {
10269
- if (_optionalChain([update, 'access', _225 => _225.updates, 'access', _226 => _226[key], 'optionalAccess', _227 => _227.type]) === "update") {
10326
+ if (_optionalChain([update, 'access', _224 => _224.updates, 'access', _225 => _225[key], 'optionalAccess', _226 => _226.type]) === "update") {
10270
10327
  const value = update.node.get(key);
10271
10328
  if (value !== void 0) {
10272
10329
  newState[key] = lsonToJson(value);
10273
10330
  }
10274
- } else if (_optionalChain([update, 'access', _228 => _228.updates, 'access', _229 => _229[key], 'optionalAccess', _230 => _230.type]) === "delete") {
10331
+ } else if (_optionalChain([update, 'access', _227 => _227.updates, 'access', _228 => _228[key], 'optionalAccess', _229 => _229.type]) === "delete") {
10275
10332
  delete newState[key];
10276
10333
  }
10277
10334
  }
@@ -10351,9 +10408,9 @@ function makePoller(callback, intervalMs, options) {
10351
10408
  const startTime = performance.now();
10352
10409
  const doc = typeof document !== "undefined" ? document : void 0;
10353
10410
  const win = typeof window !== "undefined" ? window : void 0;
10354
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _231 => _231.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10411
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _230 => _230.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10355
10412
  const context = {
10356
- inForeground: _optionalChain([doc, 'optionalAccess', _232 => _232.visibilityState]) !== "hidden",
10413
+ inForeground: _optionalChain([doc, 'optionalAccess', _231 => _231.visibilityState]) !== "hidden",
10357
10414
  lastSuccessfulPollAt: startTime,
10358
10415
  count: 0,
10359
10416
  backoff: 0
@@ -10434,11 +10491,11 @@ function makePoller(callback, intervalMs, options) {
10434
10491
  pollNowIfStale();
10435
10492
  }
10436
10493
  function onVisibilityChange() {
10437
- setInForeground(_optionalChain([doc, 'optionalAccess', _233 => _233.visibilityState]) !== "hidden");
10494
+ setInForeground(_optionalChain([doc, 'optionalAccess', _232 => _232.visibilityState]) !== "hidden");
10438
10495
  }
10439
- _optionalChain([doc, 'optionalAccess', _234 => _234.addEventListener, 'call', _235 => _235("visibilitychange", onVisibilityChange)]);
10440
- _optionalChain([win, 'optionalAccess', _236 => _236.addEventListener, 'call', _237 => _237("online", onVisibilityChange)]);
10441
- _optionalChain([win, 'optionalAccess', _238 => _238.addEventListener, 'call', _239 => _239("focus", pollNowIfStale)]);
10496
+ _optionalChain([doc, 'optionalAccess', _233 => _233.addEventListener, 'call', _234 => _234("visibilitychange", onVisibilityChange)]);
10497
+ _optionalChain([win, 'optionalAccess', _235 => _235.addEventListener, 'call', _236 => _236("online", onVisibilityChange)]);
10498
+ _optionalChain([win, 'optionalAccess', _237 => _237.addEventListener, 'call', _238 => _238("focus", pollNowIfStale)]);
10442
10499
  fsm.start();
10443
10500
  return {
10444
10501
  inc,