@liveblocks/core 2.25.0-aiprivatebeta8 → 3.0.0

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-aiprivatebeta8";
9
+ var PKG_VERSION = "3.0.0";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -3715,6 +3715,11 @@ function appendDelta(content, delta) {
3715
3715
 
3716
3716
  // src/ai.ts
3717
3717
  var DEFAULT_REQUEST_TIMEOUT = 4e3;
3718
+ function defineAiTool() {
3719
+ return (def) => {
3720
+ return def;
3721
+ };
3722
+ }
3718
3723
  var KnowledgeStack = class {
3719
3724
  #_layers;
3720
3725
  #stack;
@@ -3775,50 +3780,66 @@ var KnowledgeStack = class {
3775
3780
  function now() {
3776
3781
  return (/* @__PURE__ */ new Date()).toISOString();
3777
3782
  }
3783
+ var kWILDCARD = Symbol("*");
3778
3784
  function createStore_forTools() {
3779
- const toolsByChatId\u03A3 = new DefaultMap((_chatId) => {
3780
- return new DefaultMap((_toolName) => {
3781
- return new Signal(void 0);
3785
+ const toolsByChatId\u03A3 = new DefaultMap(
3786
+ (_chatId) => {
3787
+ return new DefaultMap((_name) => {
3788
+ return new Signal(void 0);
3789
+ });
3790
+ }
3791
+ );
3792
+ const globalOrScopedTool\u03A3 = new DefaultMap((nameAndChat) => {
3793
+ const [name, chatId] = tryParseJson(nameAndChat);
3794
+ return DerivedSignal.from(() => {
3795
+ return (
3796
+ // A tool that's registered and scoped to a specific chat ID...
3797
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? _optionalChain([toolsByChatId\u03A3, 'access', _57 => _57.get, 'call', _58 => _58(chatId), 'optionalAccess', _59 => _59.get, 'call', _60 => _60(name)]) : void 0), 'optionalAccess', _61 => _61.get, 'call', _62 => _62()]), () => ( // ...or a globally registered tool
3798
+ _optionalChain([toolsByChatId\u03A3, 'access', _63 => _63.getOrCreate, 'call', _64 => _64(kWILDCARD), 'access', _65 => _65.get, 'call', _66 => _66(name), 'optionalAccess', _67 => _67.get, 'call', _68 => _68()])))
3799
+ );
3782
3800
  });
3783
3801
  });
3784
- function getToolDefinition\u03A3(chatId, toolName) {
3785
- return toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(toolName);
3802
+ function getTool\u03A3(name, chatId) {
3803
+ const key = JSON.stringify(chatId !== void 0 ? [name, chatId] : [name]);
3804
+ return globalOrScopedTool\u03A3.getOrCreate(key);
3786
3805
  }
3787
- function addToolDefinition(chatId, name, definition) {
3788
- if (!definition.execute && !definition.render) {
3806
+ function registerTool(name, tool, chatId) {
3807
+ if (!tool.execute && !tool.render) {
3789
3808
  throw new Error(
3790
- "A tool definition must have an execute() function, a render property, or both."
3809
+ "A tool definition must have an execute() function, a render() function, or both."
3791
3810
  );
3792
3811
  }
3793
- toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name).set(definition);
3812
+ const key = _nullishCoalesce(chatId, () => ( kWILDCARD));
3813
+ toolsByChatId\u03A3.getOrCreate(key).getOrCreate(name).set(tool);
3814
+ return () => unregisterTool(key, name);
3794
3815
  }
3795
- function removeToolDefinition(chatId, toolName) {
3816
+ function unregisterTool(chatId, name) {
3796
3817
  const tools = toolsByChatId\u03A3.get(chatId);
3797
3818
  if (tools === void 0) return;
3798
- const tool = tools.get(toolName);
3819
+ const tool = tools.get(name);
3799
3820
  if (tool === void 0) return;
3800
3821
  tool.set(void 0);
3801
3822
  }
3802
- function getToolsForChat(chatId) {
3803
- const tools = toolsByChatId\u03A3.get(chatId);
3804
- if (tools === void 0) return [];
3805
- return Array.from(tools.entries()).map(([name, tool]) => {
3806
- if (tool.get() === void 0) return null;
3807
- return {
3808
- name,
3809
- definition: tool.get()
3810
- };
3811
- }).filter((tool) => tool !== null);
3823
+ function getToolDescriptions(chatId) {
3824
+ const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
3825
+ const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
3826
+ return Array.from([
3827
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _69 => _69.entries, 'call', _70 => _70()]), () => ( [])),
3828
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _71 => _71.entries, 'call', _72 => _72()]), () => ( []))
3829
+ ]).flatMap(([name, tool\u03A3]) => {
3830
+ const tool = tool\u03A3.get();
3831
+ return tool ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
3832
+ });
3812
3833
  }
3813
3834
  return {
3814
- getToolDefinition\u03A3,
3815
- getToolsForChat,
3816
- addToolDefinition,
3817
- removeToolDefinition
3835
+ getToolDescriptions,
3836
+ getTool\u03A3,
3837
+ registerTool
3818
3838
  };
3819
3839
  }
3820
- function createStore_forChatMessages(toolsStore, setToolResult) {
3821
- const seenToolCallIds = /* @__PURE__ */ new Set();
3840
+ function createStore_forChatMessages(toolsStore, setToolResultFn) {
3841
+ const myMessages = /* @__PURE__ */ new Set();
3842
+ const handledInvocations = /* @__PURE__ */ new Set();
3822
3843
  const messagePoolByChatId\u03A3 = new DefaultMap(
3823
3844
  (_chatId) => new MutableSignal(
3824
3845
  new TreePool(
@@ -3896,39 +3917,39 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
3896
3917
  });
3897
3918
  }
3898
3919
  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
- });
3920
+ if (myMessages.has(message.id)) {
3921
+ for (const toolInvocation of message.contentSoFar.filter(
3922
+ (part) => part.type === "tool-invocation" && part.stage === "executing"
3923
+ )) {
3924
+ if (!handledInvocations.has(toolInvocation.invocationId)) {
3925
+ handledInvocations.add(toolInvocation.invocationId);
3926
+ } else {
3927
+ continue;
3928
+ }
3929
+ const executeFn = _optionalChain([toolsStore, 'access', _73 => _73.getTool\u03A3, 'call', _74 => _74(toolInvocation.name, message.chatId), 'access', _75 => _75.get, 'call', _76 => _76(), 'optionalAccess', _77 => _77.execute]);
3930
+ if (executeFn) {
3931
+ (async () => {
3932
+ const result = await executeFn(toolInvocation.args, {
3933
+ name: toolInvocation.name,
3934
+ invocationId: toolInvocation.invocationId
3935
+ });
3936
+ return await setToolResultFn(
3937
+ message.chatId,
3938
+ message.id,
3939
+ toolInvocation.invocationId,
3940
+ _nullishCoalesce(result, () => ( { data: {} }))
3941
+ // TODO Pass in AiGenerationOptions here, or make the backend use the same options
3942
+ );
3943
+ })().catch((err) => {
3944
+ error2(
3945
+ `Error trying to respond to tool-call: ${String(err)} (in execute())`
3946
+ );
3947
+ });
3948
+ }
3930
3949
  }
3931
3950
  }
3951
+ } else {
3952
+ myMessages.delete(message.id);
3932
3953
  }
3933
3954
  });
3934
3955
  }
@@ -4000,8 +4021,8 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
4000
4021
  const spine = [];
4001
4022
  let lastVisitedMessage = null;
4002
4023
  for (const message2 of pool.walkUp(leaf.id)) {
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));
4024
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _78 => _78(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _79 => _79.id]), () => ( null));
4025
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _80 => _80(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _81 => _81.id]), () => ( null));
4005
4026
  if (!message2.deletedAt || prev || next) {
4006
4027
  const node = {
4007
4028
  ...message2,
@@ -4073,20 +4094,23 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
4073
4094
  remove,
4074
4095
  removeByChatId,
4075
4096
  addDelta,
4076
- failAllPending
4097
+ failAllPending,
4098
+ markMine(messageId) {
4099
+ myMessages.add(messageId);
4100
+ }
4077
4101
  };
4078
4102
  }
4079
4103
  function createStore_forUserAiChats() {
4080
- const mutable\u03A3 = new MutableSignal(
4104
+ const allChatsInclDeleted\u03A3 = new MutableSignal(
4081
4105
  SortedList.with((x, y) => y.createdAt < x.createdAt)
4082
4106
  );
4083
- const chats\u03A3 = DerivedSignal.from(
4084
- () => Array.from(mutable\u03A3.get()).filter((c) => !c.deletedAt)
4107
+ const nonDeletedChats\u03A3 = DerivedSignal.from(
4108
+ () => Array.from(allChatsInclDeleted\u03A3.get()).filter((c) => !c.deletedAt)
4085
4109
  );
4086
4110
  function upsertMany(chats) {
4087
- mutable\u03A3.mutate((list) => {
4111
+ allChatsInclDeleted\u03A3.mutate((list) => {
4088
4112
  for (const chat of chats) {
4089
- remove(chat.id);
4113
+ list.removeBy((c) => c.id === chat.id, 1);
4090
4114
  list.add(chat);
4091
4115
  }
4092
4116
  });
@@ -4094,19 +4118,26 @@ function createStore_forUserAiChats() {
4094
4118
  function upsert(chat) {
4095
4119
  upsertMany([chat]);
4096
4120
  }
4097
- function remove(chatId) {
4098
- mutable\u03A3.mutate((list) => list.removeBy((c) => c.id === chatId, 1));
4121
+ function markDeleted(chatId) {
4122
+ allChatsInclDeleted\u03A3.mutate((list) => {
4123
+ const chat = list.find((c) => c.id === chatId);
4124
+ if (!chat) return false;
4125
+ upsert({ ...chat, deletedAt: now() });
4126
+ return void 0;
4127
+ });
4099
4128
  }
4100
4129
  function getChatById(chatId) {
4101
- return Array.from(mutable\u03A3.get()).find((chat) => chat.id === chatId);
4130
+ return Array.from(allChatsInclDeleted\u03A3.get()).find(
4131
+ (chat) => chat.id === chatId
4132
+ );
4102
4133
  }
4103
4134
  return {
4104
- chats\u03A3,
4135
+ chats\u03A3: nonDeletedChats\u03A3,
4105
4136
  getChatById,
4106
4137
  // Mutations
4107
4138
  upsert,
4108
4139
  upsertMany,
4109
- remove
4140
+ markDeleted
4110
4141
  };
4111
4142
  }
4112
4143
  function createAi(config) {
@@ -4116,7 +4147,6 @@ function createAi(config) {
4116
4147
  false
4117
4148
  // AI doesn't have actors (yet, but it will)
4118
4149
  );
4119
- const clientId = nanoid(7);
4120
4150
  const chatsStore = createStore_forUserAiChats();
4121
4151
  const toolsStore = createStore_forTools();
4122
4152
  const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
@@ -4185,7 +4215,7 @@ function createAi(config) {
4185
4215
  if ("event" in msg) {
4186
4216
  switch (msg.event) {
4187
4217
  case "cmd-failed":
4188
- _optionalChain([pendingCmd, 'optionalAccess', _62 => _62.reject, 'call', _63 => _63(new Error(msg.error))]);
4218
+ _optionalChain([pendingCmd, 'optionalAccess', _82 => _82.reject, 'call', _83 => _83(new Error(msg.error))]);
4189
4219
  break;
4190
4220
  case "delta": {
4191
4221
  const { id, delta } = msg;
@@ -4196,7 +4226,11 @@ function createAi(config) {
4196
4226
  context.messagesStore.upsert(msg.message);
4197
4227
  break;
4198
4228
  }
4229
+ case "warning":
4230
+ warn(msg.message);
4231
+ break;
4199
4232
  case "error":
4233
+ error2(msg.error);
4200
4234
  break;
4201
4235
  case "rebooted":
4202
4236
  context.messagesStore.failAllPending();
@@ -4207,7 +4241,7 @@ function createAi(config) {
4207
4241
  context.messagesStore.remove(m.chatId, m.id);
4208
4242
  }
4209
4243
  for (const chatId of _nullishCoalesce(msg["-chats"], () => ( []))) {
4210
- context.chatsStore.remove(chatId);
4244
+ context.chatsStore.markDeleted(chatId);
4211
4245
  context.messagesStore.removeByChatId(chatId);
4212
4246
  }
4213
4247
  for (const chatId of _nullishCoalesce(msg.clear, () => ( []))) {
@@ -4233,7 +4267,7 @@ function createAi(config) {
4233
4267
  context.chatsStore.upsert(msg.chat);
4234
4268
  break;
4235
4269
  case "delete-chat":
4236
- context.chatsStore.remove(msg.chatId);
4270
+ context.chatsStore.markDeleted(msg.chatId);
4237
4271
  context.messagesStore.removeByChatId(msg.chatId);
4238
4272
  break;
4239
4273
  case "get-message-tree":
@@ -4263,7 +4297,7 @@ function createAi(config) {
4263
4297
  return assertNever(msg, "Unhandled case");
4264
4298
  }
4265
4299
  }
4266
- _optionalChain([pendingCmd, 'optionalAccess', _64 => _64.resolve, 'call', _65 => _65(msg)]);
4300
+ _optionalChain([pendingCmd, 'optionalAccess', _84 => _84.resolve, 'call', _85 => _85(msg)]);
4267
4301
  }
4268
4302
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4269
4303
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4277,7 +4311,13 @@ function createAi(config) {
4277
4311
  );
4278
4312
  }
4279
4313
  });
4314
+ function connectInitially() {
4315
+ if (managedSocket.getStatus() === "initial") {
4316
+ managedSocket.connect();
4317
+ }
4318
+ }
4280
4319
  async function sendClientMsgWithResponse(msg) {
4320
+ connectInitially();
4281
4321
  if (managedSocket.getStatus() !== "connected") {
4282
4322
  await managedSocket.events.didConnect.waitUntil();
4283
4323
  }
@@ -4331,70 +4371,65 @@ function createAi(config) {
4331
4371
  function updateKnowledge(layerKey, data, key = nanoid()) {
4332
4372
  context.knowledge.updateKnowledge(layerKey, key, data);
4333
4373
  }
4334
- function debug_getAllKnowledge() {
4335
- return context.knowledge.get();
4336
- }
4337
- async function setToolResult(chatId, messageId, toolCallId, result, options) {
4374
+ async function setToolResult(chatId, messageId, invocationId, result, options) {
4338
4375
  const knowledge = context.knowledge.get();
4339
- return sendClientMsgWithResponse({
4376
+ const tools = context.toolsStore.getToolDescriptions(chatId);
4377
+ const resp = await sendClientMsgWithResponse({
4340
4378
  cmd: "set-tool-result",
4341
4379
  chatId,
4342
4380
  messageId,
4343
- toolCallId,
4344
- clientId,
4381
+ invocationId,
4345
4382
  result,
4346
4383
  generationOptions: {
4347
- copilotId: _optionalChain([options, 'optionalAccess', _66 => _66.copilotId]),
4348
- stream: _optionalChain([options, 'optionalAccess', _67 => _67.stream]),
4349
- timeout: _optionalChain([options, 'optionalAccess', _68 => _68.timeout]),
4384
+ copilotId: _optionalChain([options, 'optionalAccess', _86 => _86.copilotId]),
4385
+ stream: _optionalChain([options, 'optionalAccess', _87 => _87.stream]),
4386
+ timeout: _optionalChain([options, 'optionalAccess', _88 => _88.timeout]),
4387
+ // Knowledge and tools aren't coming from the options, but retrieved
4388
+ // from the global context
4350
4389
  knowledge: knowledge.length > 0 ? knowledge : void 0,
4351
- tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
4352
- name: tool.name,
4353
- description: tool.definition.description,
4354
- parameters: tool.definition.parameters
4355
- }))
4390
+ tools: tools.length > 0 ? tools : void 0
4356
4391
  }
4357
4392
  });
4393
+ if (resp.ok) {
4394
+ messagesStore.markMine(resp.message.id);
4395
+ }
4358
4396
  }
4359
4397
  return Object.defineProperty(
4360
4398
  {
4361
4399
  [kInternal]: {
4362
4400
  context
4363
4401
  },
4364
- connect: () => managedSocket.connect(),
4365
- reconnect: () => managedSocket.reconnect(),
4402
+ connectInitially,
4403
+ // reconnect: () => managedSocket.reconnect(),
4366
4404
  disconnect: () => managedSocket.disconnect(),
4367
4405
  getChats,
4368
4406
  getOrCreateChat,
4369
4407
  deleteChat: (chatId) => {
4370
- return sendClientMsgWithResponse({
4371
- cmd: "delete-chat",
4372
- chatId
4373
- });
4408
+ return sendClientMsgWithResponse({ cmd: "delete-chat", chatId });
4374
4409
  },
4375
4410
  getMessageTree,
4376
4411
  deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
4377
4412
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4378
4413
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4379
4414
  const knowledge = context.knowledge.get();
4380
- return sendClientMsgWithResponse({
4415
+ const tools = context.toolsStore.getToolDescriptions(chatId);
4416
+ const resp = await sendClientMsgWithResponse({
4381
4417
  cmd: "ask-in-chat",
4382
4418
  chatId,
4383
4419
  sourceMessage: userMessage,
4384
4420
  targetMessageId,
4385
- clientId,
4386
4421
  generationOptions: {
4387
- copilotId: _optionalChain([options, 'optionalAccess', _69 => _69.copilotId]),
4388
- stream: _optionalChain([options, 'optionalAccess', _70 => _70.stream]),
4389
- timeout: _optionalChain([options, 'optionalAccess', _71 => _71.timeout]),
4422
+ copilotId: _optionalChain([options, 'optionalAccess', _89 => _89.copilotId]),
4423
+ stream: _optionalChain([options, 'optionalAccess', _90 => _90.stream]),
4424
+ timeout: _optionalChain([options, 'optionalAccess', _91 => _91.timeout]),
4425
+ // Knowledge and tools aren't coming from the options, but retrieved
4426
+ // from the global context
4390
4427
  knowledge: knowledge.length > 0 ? knowledge : void 0,
4391
- tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
4392
- name: tool.name,
4393
- description: tool.definition.description,
4394
- parameters: tool.definition.parameters
4395
- }))
4428
+ tools: tools.length > 0 ? tools : void 0
4396
4429
  }
4397
4430
  });
4431
+ messagesStore.markMine(resp.targetMessage.id);
4432
+ return resp;
4398
4433
  },
4399
4434
  abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
4400
4435
  setToolResult,
@@ -4402,15 +4437,13 @@ function createAi(config) {
4402
4437
  signals: {
4403
4438
  chats\u03A3: context.chatsStore.chats\u03A3,
4404
4439
  getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
4405
- getChatById: context.chatsStore.getChatById,
4406
- getToolDefinition\u03A3: context.toolsStore.getToolDefinition\u03A3
4440
+ getTool\u03A3: context.toolsStore.getTool\u03A3
4407
4441
  },
4442
+ getChatById: context.chatsStore.getChatById,
4408
4443
  registerKnowledgeLayer,
4409
4444
  deregisterKnowledgeLayer,
4410
4445
  updateKnowledge,
4411
- debug_getAllKnowledge,
4412
- registerChatTool: context.toolsStore.addToolDefinition,
4413
- unregisterChatTool: context.toolsStore.removeToolDefinition
4446
+ registerTool: context.toolsStore.registerTool
4414
4447
  },
4415
4448
  kInternal,
4416
4449
  { enumerable: false }
@@ -4426,7 +4459,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
4426
4459
  }
4427
4460
  const url2 = new URL(baseUrl);
4428
4461
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
4429
- url2.pathname = "/ai/v1";
4462
+ url2.pathname = "/ai/v4";
4430
4463
  if (authValue.type === "secret") {
4431
4464
  url2.searchParams.set("tok", authValue.token.raw);
4432
4465
  } else if (authValue.type === "public") {
@@ -4490,7 +4523,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4490
4523
  return void 0;
4491
4524
  }
4492
4525
  async function makeAuthRequest(options) {
4493
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _72 => _72.polyfills, 'optionalAccess', _73 => _73.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4526
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _92 => _92.polyfills, 'optionalAccess', _93 => _93.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4494
4527
  if (authentication.type === "private") {
4495
4528
  if (fetcher === void 0) {
4496
4529
  throw new StopRetrying(
@@ -4506,7 +4539,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4506
4539
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
4507
4540
  );
4508
4541
  }
4509
- _optionalChain([onAuthenticate, 'optionalCall', _74 => _74(parsed.parsed)]);
4542
+ _optionalChain([onAuthenticate, 'optionalCall', _94 => _94(parsed.parsed)]);
4510
4543
  return parsed;
4511
4544
  }
4512
4545
  if (authentication.type === "custom") {
@@ -4514,7 +4547,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4514
4547
  if (response && typeof response === "object") {
4515
4548
  if (typeof response.token === "string") {
4516
4549
  const parsed = parseAuthToken(response.token);
4517
- _optionalChain([onAuthenticate, 'optionalCall', _75 => _75(parsed.parsed)]);
4550
+ _optionalChain([onAuthenticate, 'optionalCall', _95 => _95(parsed.parsed)]);
4518
4551
  return parsed;
4519
4552
  } else if (typeof response.error === "string") {
4520
4553
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -4672,7 +4705,7 @@ function sendToPanel(message, options) {
4672
4705
  ...message,
4673
4706
  source: "liveblocks-devtools-client"
4674
4707
  };
4675
- if (!(_optionalChain([options, 'optionalAccess', _76 => _76.force]) || _bridgeActive)) {
4708
+ if (!(_optionalChain([options, 'optionalAccess', _96 => _96.force]) || _bridgeActive)) {
4676
4709
  return;
4677
4710
  }
4678
4711
  window.postMessage(fullMsg, "*");
@@ -4680,7 +4713,7 @@ function sendToPanel(message, options) {
4680
4713
  var eventSource = makeEventSource();
4681
4714
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
4682
4715
  window.addEventListener("message", (event) => {
4683
- if (event.source === window && _optionalChain([event, 'access', _77 => _77.data, 'optionalAccess', _78 => _78.source]) === "liveblocks-devtools-panel") {
4716
+ if (event.source === window && _optionalChain([event, 'access', _97 => _97.data, 'optionalAccess', _98 => _98.source]) === "liveblocks-devtools-panel") {
4684
4717
  eventSource.notify(event.data);
4685
4718
  } else {
4686
4719
  }
@@ -4822,7 +4855,7 @@ function fullSync(room) {
4822
4855
  msg: "room::sync::full",
4823
4856
  roomId: room.id,
4824
4857
  status: room.getStatus(),
4825
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _79 => _79.toTreeNode, 'call', _80 => _80("root"), 'access', _81 => _81.payload]), () => ( null)),
4858
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _99 => _99.toTreeNode, 'call', _100 => _100("root"), 'access', _101 => _101.payload]), () => ( null)),
4826
4859
  me,
4827
4860
  others
4828
4861
  });
@@ -5113,7 +5146,7 @@ function createManagedPool(roomId, options) {
5113
5146
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5114
5147
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5115
5148
  dispatch(ops, reverse, storageUpdates) {
5116
- _optionalChain([onDispatch, 'optionalCall', _82 => _82(ops, reverse, storageUpdates)]);
5149
+ _optionalChain([onDispatch, 'optionalCall', _102 => _102(ops, reverse, storageUpdates)]);
5117
5150
  },
5118
5151
  assertStorageIsWritable: () => {
5119
5152
  if (!isStorageWritable()) {
@@ -5340,7 +5373,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5340
5373
  return [
5341
5374
  {
5342
5375
  type: 8 /* CREATE_REGISTER */,
5343
- opId: _optionalChain([pool, 'optionalAccess', _83 => _83.generateOpId, 'call', _84 => _84()]),
5376
+ opId: _optionalChain([pool, 'optionalAccess', _103 => _103.generateOpId, 'call', _104 => _104()]),
5344
5377
  id: this._id,
5345
5378
  parentId,
5346
5379
  parentKey,
@@ -5446,7 +5479,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5446
5479
  const ops = [];
5447
5480
  const op = {
5448
5481
  id: this._id,
5449
- opId: _optionalChain([pool, 'optionalAccess', _85 => _85.generateOpId, 'call', _86 => _86()]),
5482
+ opId: _optionalChain([pool, 'optionalAccess', _105 => _105.generateOpId, 'call', _106 => _106()]),
5450
5483
  type: 2 /* CREATE_LIST */,
5451
5484
  parentId,
5452
5485
  parentKey
@@ -5717,7 +5750,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5717
5750
  #applyInsertUndoRedo(op) {
5718
5751
  const { id, parentKey: key } = op;
5719
5752
  const child = creationOpToLiveNode(op);
5720
- if (_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.getNode, 'call', _89 => _89(id)]) !== void 0) {
5753
+ if (_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.getNode, 'call', _109 => _109(id)]) !== void 0) {
5721
5754
  return { modified: false };
5722
5755
  }
5723
5756
  child._attach(id, nn(this._pool));
@@ -5725,8 +5758,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
5725
5758
  const existingItemIndex = this._indexOfPosition(key);
5726
5759
  let newKey = key;
5727
5760
  if (existingItemIndex !== -1) {
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]);
5761
+ const before2 = _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[existingItemIndex], 'optionalAccess', _112 => _112._parentPos]);
5762
+ const after2 = _optionalChain([this, 'access', _113 => _113.#items, 'access', _114 => _114[existingItemIndex + 1], 'optionalAccess', _115 => _115._parentPos]);
5730
5763
  newKey = makePosition(before2, after2);
5731
5764
  child._setParentLink(this, newKey);
5732
5765
  }
@@ -5740,7 +5773,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5740
5773
  #applySetUndoRedo(op) {
5741
5774
  const { id, parentKey: key } = op;
5742
5775
  const child = creationOpToLiveNode(op);
5743
- if (_optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.getNode, 'call', _98 => _98(id)]) !== void 0) {
5776
+ if (_optionalChain([this, 'access', _116 => _116._pool, 'optionalAccess', _117 => _117.getNode, 'call', _118 => _118(id)]) !== void 0) {
5744
5777
  return { modified: false };
5745
5778
  }
5746
5779
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -5861,7 +5894,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5861
5894
  } else {
5862
5895
  this.#items[existingItemIndex]._setParentLink(
5863
5896
  this,
5864
- makePosition(newKey, _optionalChain([this, 'access', _99 => _99.#items, 'access', _100 => _100[existingItemIndex + 1], 'optionalAccess', _101 => _101._parentPos]))
5897
+ makePosition(newKey, _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120[existingItemIndex + 1], 'optionalAccess', _121 => _121._parentPos]))
5865
5898
  );
5866
5899
  const previousIndex = this.#items.indexOf(child);
5867
5900
  child._setParentLink(this, newKey);
@@ -5886,7 +5919,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5886
5919
  if (existingItemIndex !== -1) {
5887
5920
  this.#items[existingItemIndex]._setParentLink(
5888
5921
  this,
5889
- makePosition(newKey, _optionalChain([this, 'access', _102 => _102.#items, 'access', _103 => _103[existingItemIndex + 1], 'optionalAccess', _104 => _104._parentPos]))
5922
+ makePosition(newKey, _optionalChain([this, 'access', _122 => _122.#items, 'access', _123 => _123[existingItemIndex + 1], 'optionalAccess', _124 => _124._parentPos]))
5890
5923
  );
5891
5924
  }
5892
5925
  child._setParentLink(this, newKey);
@@ -5905,7 +5938,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5905
5938
  if (existingItemIndex !== -1) {
5906
5939
  this.#items[existingItemIndex]._setParentLink(
5907
5940
  this,
5908
- makePosition(newKey, _optionalChain([this, 'access', _105 => _105.#items, 'access', _106 => _106[existingItemIndex + 1], 'optionalAccess', _107 => _107._parentPos]))
5941
+ makePosition(newKey, _optionalChain([this, 'access', _125 => _125.#items, 'access', _126 => _126[existingItemIndex + 1], 'optionalAccess', _127 => _127._parentPos]))
5909
5942
  );
5910
5943
  }
5911
5944
  child._setParentLink(this, newKey);
@@ -5932,7 +5965,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5932
5965
  if (existingItemIndex !== -1) {
5933
5966
  this.#items[existingItemIndex]._setParentLink(
5934
5967
  this,
5935
- makePosition(newKey, _optionalChain([this, 'access', _108 => _108.#items, 'access', _109 => _109[existingItemIndex + 1], 'optionalAccess', _110 => _110._parentPos]))
5968
+ makePosition(newKey, _optionalChain([this, 'access', _128 => _128.#items, 'access', _129 => _129[existingItemIndex + 1], 'optionalAccess', _130 => _130._parentPos]))
5936
5969
  );
5937
5970
  }
5938
5971
  child._setParentLink(this, newKey);
@@ -5990,7 +6023,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5990
6023
  * @param element The element to add to the end of the LiveList.
5991
6024
  */
5992
6025
  push(element) {
5993
- _optionalChain([this, 'access', _111 => _111._pool, 'optionalAccess', _112 => _112.assertStorageIsWritable, 'call', _113 => _113()]);
6026
+ _optionalChain([this, 'access', _131 => _131._pool, 'optionalAccess', _132 => _132.assertStorageIsWritable, 'call', _133 => _133()]);
5994
6027
  return this.insert(element, this.length);
5995
6028
  }
5996
6029
  /**
@@ -5999,7 +6032,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5999
6032
  * @param index The index at which you want to insert the element.
6000
6033
  */
6001
6034
  insert(element, index) {
6002
- _optionalChain([this, 'access', _114 => _114._pool, 'optionalAccess', _115 => _115.assertStorageIsWritable, 'call', _116 => _116()]);
6035
+ _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6003
6036
  if (index < 0 || index > this.#items.length) {
6004
6037
  throw new Error(
6005
6038
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6029,7 +6062,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6029
6062
  * @param targetIndex The index where the element should be after moving.
6030
6063
  */
6031
6064
  move(index, targetIndex) {
6032
- _optionalChain([this, 'access', _117 => _117._pool, 'optionalAccess', _118 => _118.assertStorageIsWritable, 'call', _119 => _119()]);
6065
+ _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6033
6066
  if (targetIndex < 0) {
6034
6067
  throw new Error("targetIndex cannot be less than 0");
6035
6068
  }
@@ -6087,7 +6120,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6087
6120
  * @param index The index of the element to delete
6088
6121
  */
6089
6122
  delete(index) {
6090
- _optionalChain([this, 'access', _120 => _120._pool, 'optionalAccess', _121 => _121.assertStorageIsWritable, 'call', _122 => _122()]);
6123
+ _optionalChain([this, 'access', _140 => _140._pool, 'optionalAccess', _141 => _141.assertStorageIsWritable, 'call', _142 => _142()]);
6091
6124
  if (index < 0 || index >= this.#items.length) {
6092
6125
  throw new Error(
6093
6126
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6120,7 +6153,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6120
6153
  }
6121
6154
  }
6122
6155
  clear() {
6123
- _optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.assertStorageIsWritable, 'call', _125 => _125()]);
6156
+ _optionalChain([this, 'access', _143 => _143._pool, 'optionalAccess', _144 => _144.assertStorageIsWritable, 'call', _145 => _145()]);
6124
6157
  if (this._pool) {
6125
6158
  const ops = [];
6126
6159
  const reverseOps = [];
@@ -6154,7 +6187,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6154
6187
  }
6155
6188
  }
6156
6189
  set(index, item) {
6157
- _optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.assertStorageIsWritable, 'call', _128 => _128()]);
6190
+ _optionalChain([this, 'access', _146 => _146._pool, 'optionalAccess', _147 => _147.assertStorageIsWritable, 'call', _148 => _148()]);
6158
6191
  if (index < 0 || index >= this.#items.length) {
6159
6192
  throw new Error(
6160
6193
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6300,7 +6333,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6300
6333
  #shiftItemPosition(index, key) {
6301
6334
  const shiftedPosition = makePosition(
6302
6335
  key,
6303
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _129 => _129.#items, 'access', _130 => _130[index + 1], 'optionalAccess', _131 => _131._parentPos]) : void 0
6336
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _149 => _149.#items, 'access', _150 => _150[index + 1], 'optionalAccess', _151 => _151._parentPos]) : void 0
6304
6337
  );
6305
6338
  this.#items[index]._setParentLink(this, shiftedPosition);
6306
6339
  }
@@ -6425,7 +6458,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6425
6458
  const ops = [];
6426
6459
  const op = {
6427
6460
  id: this._id,
6428
- opId: _optionalChain([pool, 'optionalAccess', _132 => _132.generateOpId, 'call', _133 => _133()]),
6461
+ opId: _optionalChain([pool, 'optionalAccess', _152 => _152.generateOpId, 'call', _153 => _153()]),
6429
6462
  type: 7 /* CREATE_MAP */,
6430
6463
  parentId,
6431
6464
  parentKey
@@ -6560,7 +6593,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6560
6593
  * @param value The value of the element to add. Should be serializable to JSON.
6561
6594
  */
6562
6595
  set(key, value) {
6563
- _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6596
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
6564
6597
  const oldValue = this.#map.get(key);
6565
6598
  if (oldValue) {
6566
6599
  oldValue._detach();
@@ -6606,7 +6639,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6606
6639
  * @returns true if an element existed and has been removed, or false if the element does not exist.
6607
6640
  */
6608
6641
  delete(key) {
6609
- _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6642
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
6610
6643
  const item = this.#map.get(key);
6611
6644
  if (item === void 0) {
6612
6645
  return false;
@@ -6785,7 +6818,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
6785
6818
  if (this._id === void 0) {
6786
6819
  throw new Error("Cannot serialize item is not attached");
6787
6820
  }
6788
- const opId = _optionalChain([pool, 'optionalAccess', _140 => _140.generateOpId, 'call', _141 => _141()]);
6821
+ const opId = _optionalChain([pool, 'optionalAccess', _160 => _160.generateOpId, 'call', _161 => _161()]);
6789
6822
  const ops = [];
6790
6823
  const op = {
6791
6824
  type: 4 /* CREATE_OBJECT */,
@@ -7057,7 +7090,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7057
7090
  * @param value The value of the property to add
7058
7091
  */
7059
7092
  set(key, value) {
7060
- _optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
7093
+ _optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.assertStorageIsWritable, 'call', _164 => _164()]);
7061
7094
  this.update({ [key]: value });
7062
7095
  }
7063
7096
  /**
@@ -7072,7 +7105,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7072
7105
  * @param key The key of the property to delete
7073
7106
  */
7074
7107
  delete(key) {
7075
- _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
7108
+ _optionalChain([this, 'access', _165 => _165._pool, 'optionalAccess', _166 => _166.assertStorageIsWritable, 'call', _167 => _167()]);
7076
7109
  const keyAsString = key;
7077
7110
  const oldValue = this.#map.get(keyAsString);
7078
7111
  if (oldValue === void 0) {
@@ -7125,7 +7158,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7125
7158
  * @param patch The object used to overrides properties
7126
7159
  */
7127
7160
  update(patch) {
7128
- _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
7161
+ _optionalChain([this, 'access', _168 => _168._pool, 'optionalAccess', _169 => _169.assertStorageIsWritable, 'call', _170 => _170()]);
7129
7162
  if (this._pool === void 0 || this._id === void 0) {
7130
7163
  for (const key in patch) {
7131
7164
  const newValue = patch[key];
@@ -7743,7 +7776,7 @@ var LiveblocksError = class _LiveblocksError extends Error {
7743
7776
  get roomId() {
7744
7777
  return this.context.roomId;
7745
7778
  }
7746
- /** @deprecated Prefer using `context.code` instead, to enable type narrowing */
7779
+ /** @internal Use `context.code` instead, to enable type narrowing */
7747
7780
  get code() {
7748
7781
  return this.context.code;
7749
7782
  }
@@ -7813,11 +7846,9 @@ function defaultMessageFromContext(context) {
7813
7846
  return "Could not mark all inbox notifications as read";
7814
7847
  case "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR":
7815
7848
  return "Could not delete all inbox notifications";
7816
- case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
7817
- return "Could not update notification settings";
7818
7849
  case "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR":
7819
7850
  return "Could not update room subscription settings";
7820
- case "UPDATE_USER_NOTIFICATION_SETTINGS_ERROR":
7851
+ case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
7821
7852
  return "Could not update notification settings";
7822
7853
  default:
7823
7854
  return assertNever(context, "Unhandled case");
@@ -7848,15 +7879,15 @@ function installBackgroundTabSpy() {
7848
7879
  const doc = typeof document !== "undefined" ? document : void 0;
7849
7880
  const inBackgroundSince = { current: null };
7850
7881
  function onVisibilityChange() {
7851
- if (_optionalChain([doc, 'optionalAccess', _151 => _151.visibilityState]) === "hidden") {
7882
+ if (_optionalChain([doc, 'optionalAccess', _171 => _171.visibilityState]) === "hidden") {
7852
7883
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
7853
7884
  } else {
7854
7885
  inBackgroundSince.current = null;
7855
7886
  }
7856
7887
  }
7857
- _optionalChain([doc, 'optionalAccess', _152 => _152.addEventListener, 'call', _153 => _153("visibilitychange", onVisibilityChange)]);
7888
+ _optionalChain([doc, 'optionalAccess', _172 => _172.addEventListener, 'call', _173 => _173("visibilitychange", onVisibilityChange)]);
7858
7889
  const unsub = () => {
7859
- _optionalChain([doc, 'optionalAccess', _154 => _154.removeEventListener, 'call', _155 => _155("visibilitychange", onVisibilityChange)]);
7890
+ _optionalChain([doc, 'optionalAccess', _174 => _174.removeEventListener, 'call', _175 => _175("visibilitychange", onVisibilityChange)]);
7860
7891
  };
7861
7892
  return [inBackgroundSince, unsub];
7862
7893
  }
@@ -8036,7 +8067,7 @@ function createRoom(options, config) {
8036
8067
  }
8037
8068
  }
8038
8069
  function isStorageWritable() {
8039
- const scopes = _optionalChain([context, 'access', _156 => _156.dynamicSessionInfoSig, 'access', _157 => _157.get, 'call', _158 => _158(), 'optionalAccess', _159 => _159.scopes]);
8070
+ const scopes = _optionalChain([context, 'access', _176 => _176.dynamicSessionInfoSig, 'access', _177 => _177.get, 'call', _178 => _178(), 'optionalAccess', _179 => _179.scopes]);
8040
8071
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8041
8072
  }
8042
8073
  const eventHub = {
@@ -8153,7 +8184,7 @@ function createRoom(options, config) {
8153
8184
  }
8154
8185
  case "experimental-fallback-to-http": {
8155
8186
  warn("Message is too large for websockets, so sending over HTTP instead");
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")));
8187
+ 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")));
8157
8188
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8158
8189
  if (!resp.ok && resp.status === 403) {
8159
8190
  managedSocket.reconnect();
@@ -8204,7 +8235,7 @@ function createRoom(options, config) {
8204
8235
  } else {
8205
8236
  context.root = LiveObject._fromItems(message.items, context.pool);
8206
8237
  }
8207
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _164 => _164.get, 'call', _165 => _165(), 'optionalAccess', _166 => _166.canWrite]), () => ( true));
8238
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _184 => _184.get, 'call', _185 => _185(), 'optionalAccess', _186 => _186.canWrite]), () => ( true));
8208
8239
  const stackSizeBefore = context.undoStack.length;
8209
8240
  for (const key in context.initialStorage) {
8210
8241
  if (context.root.get(key) === void 0) {
@@ -8407,7 +8438,7 @@ function createRoom(options, config) {
8407
8438
  }
8408
8439
  context.myPresence.patch(patch);
8409
8440
  if (context.activeBatch) {
8410
- if (_optionalChain([options2, 'optionalAccess', _167 => _167.addToHistory])) {
8441
+ if (_optionalChain([options2, 'optionalAccess', _187 => _187.addToHistory])) {
8411
8442
  context.activeBatch.reverseOps.pushLeft({
8412
8443
  type: "presence",
8413
8444
  data: oldValues
@@ -8416,7 +8447,7 @@ function createRoom(options, config) {
8416
8447
  context.activeBatch.updates.presence = true;
8417
8448
  } else {
8418
8449
  flushNowOrSoon();
8419
- if (_optionalChain([options2, 'optionalAccess', _168 => _168.addToHistory])) {
8450
+ if (_optionalChain([options2, 'optionalAccess', _188 => _188.addToHistory])) {
8420
8451
  addToUndoStack([{ type: "presence", data: oldValues }]);
8421
8452
  }
8422
8453
  notify({ presence: true });
@@ -8613,7 +8644,7 @@ function createRoom(options, config) {
8613
8644
  if (process.env.NODE_ENV !== "production") {
8614
8645
  const traces = /* @__PURE__ */ new Set();
8615
8646
  for (const opId of message.opIds) {
8616
- const trace = _optionalChain([context, 'access', _169 => _169.opStackTraces, 'optionalAccess', _170 => _170.get, 'call', _171 => _171(opId)]);
8647
+ const trace = _optionalChain([context, 'access', _189 => _189.opStackTraces, 'optionalAccess', _190 => _190.get, 'call', _191 => _191(opId)]);
8617
8648
  if (trace) {
8618
8649
  traces.add(trace);
8619
8650
  }
@@ -8747,7 +8778,7 @@ ${Array.from(traces).join("\n\n")}`
8747
8778
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
8748
8779
  createOrUpdateRootFromMessage(message);
8749
8780
  applyAndSendOps(unacknowledgedOps);
8750
- _optionalChain([_resolveStoragePromise, 'optionalCall', _172 => _172()]);
8781
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _192 => _192()]);
8751
8782
  notifyStorageStatus();
8752
8783
  eventHub.storageDidLoad.notify();
8753
8784
  }
@@ -8950,8 +8981,6 @@ ${Array.from(traces).join("\n\n")}`
8950
8981
  others: eventHub.others.observable,
8951
8982
  self: eventHub.self.observable,
8952
8983
  myPresence: eventHub.myPresence.observable,
8953
- /** @deprecated */
8954
- storage: eventHub.storageBatch.observable,
8955
8984
  storageBatch: eventHub.storageBatch.observable,
8956
8985
  history: eventHub.history.observable,
8957
8986
  storageDidLoad: eventHub.storageDidLoad.observable,
@@ -8970,8 +8999,8 @@ ${Array.from(traces).join("\n\n")}`
8970
8999
  async function getThreads(options2) {
8971
9000
  return httpClient.getThreads({
8972
9001
  roomId,
8973
- query: _optionalChain([options2, 'optionalAccess', _173 => _173.query]),
8974
- cursor: _optionalChain([options2, 'optionalAccess', _174 => _174.cursor])
9002
+ query: _optionalChain([options2, 'optionalAccess', _193 => _193.query]),
9003
+ cursor: _optionalChain([options2, 'optionalAccess', _194 => _194.cursor])
8975
9004
  });
8976
9005
  }
8977
9006
  async function getThread(threadId) {
@@ -9078,7 +9107,7 @@ ${Array.from(traces).join("\n\n")}`
9078
9107
  function getSubscriptionSettings(options2) {
9079
9108
  return httpClient.getSubscriptionSettings({
9080
9109
  roomId,
9081
- signal: _optionalChain([options2, 'optionalAccess', _175 => _175.signal])
9110
+ signal: _optionalChain([options2, 'optionalAccess', _195 => _195.signal])
9082
9111
  });
9083
9112
  }
9084
9113
  function updateSubscriptionSettings(settings) {
@@ -9100,7 +9129,7 @@ ${Array.from(traces).join("\n\n")}`
9100
9129
  {
9101
9130
  [kInternal]: {
9102
9131
  get presenceBuffer() {
9103
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _176 => _176.buffer, 'access', _177 => _177.presenceUpdates, 'optionalAccess', _178 => _178.data]), () => ( null)));
9132
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _196 => _196.buffer, 'access', _197 => _197.presenceUpdates, 'optionalAccess', _198 => _198.data]), () => ( null)));
9104
9133
  },
9105
9134
  // prettier-ignore
9106
9135
  get undoStack() {
@@ -9115,9 +9144,9 @@ ${Array.from(traces).join("\n\n")}`
9115
9144
  return context.yjsProvider;
9116
9145
  },
9117
9146
  setYjsProvider(newProvider) {
9118
- _optionalChain([context, 'access', _179 => _179.yjsProvider, 'optionalAccess', _180 => _180.off, 'call', _181 => _181("status", yjsStatusDidChange)]);
9147
+ _optionalChain([context, 'access', _199 => _199.yjsProvider, 'optionalAccess', _200 => _200.off, 'call', _201 => _201("status", yjsStatusDidChange)]);
9119
9148
  context.yjsProvider = newProvider;
9120
- _optionalChain([newProvider, 'optionalAccess', _182 => _182.on, 'call', _183 => _183("status", yjsStatusDidChange)]);
9149
+ _optionalChain([newProvider, 'optionalAccess', _202 => _202.on, 'call', _203 => _203("status", yjsStatusDidChange)]);
9121
9150
  context.yjsProviderDidChange.notify();
9122
9151
  },
9123
9152
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9163,7 +9192,7 @@ ${Array.from(traces).join("\n\n")}`
9163
9192
  source.dispose();
9164
9193
  }
9165
9194
  eventHub.roomWillDestroy.notify();
9166
- _optionalChain([context, 'access', _184 => _184.yjsProvider, 'optionalAccess', _185 => _185.off, 'call', _186 => _186("status", yjsStatusDidChange)]);
9195
+ _optionalChain([context, 'access', _204 => _204.yjsProvider, 'optionalAccess', _205 => _205.off, 'call', _206 => _206("status", yjsStatusDidChange)]);
9167
9196
  syncSourceForStorage.destroy();
9168
9197
  syncSourceForYjs.destroy();
9169
9198
  uninstallBgTabSpy();
@@ -9313,7 +9342,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9313
9342
  }
9314
9343
  if (isLiveNode(first)) {
9315
9344
  const node = first;
9316
- if (_optionalChain([options, 'optionalAccess', _187 => _187.isDeep])) {
9345
+ if (_optionalChain([options, 'optionalAccess', _207 => _207.isDeep])) {
9317
9346
  const storageCallback = second;
9318
9347
  return subscribeToLiveStructureDeeply(node, storageCallback);
9319
9348
  } else {
@@ -9392,8 +9421,8 @@ function createClient(options) {
9392
9421
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9393
9422
  currentUserId.set(() => userId);
9394
9423
  });
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)]);
9424
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.fetch]) || /* istanbul ignore next */
9425
+ _optionalChain([globalThis, 'access', _210 => _210.fetch, 'optionalAccess', _211 => _211.bind, 'call', _212 => _212(globalThis)]);
9397
9426
  const httpClient = createApiClient({
9398
9427
  baseUrl,
9399
9428
  fetchPolyfill,
@@ -9411,10 +9440,28 @@ function createClient(options) {
9411
9440
  delegates: {
9412
9441
  createSocket: makeCreateSocketDelegateForAi(
9413
9442
  baseUrl,
9414
- _optionalChain([clientOptions, 'access', _193 => _193.polyfills, 'optionalAccess', _194 => _194.WebSocket])
9443
+ _optionalChain([clientOptions, 'access', _213 => _213.polyfills, 'optionalAccess', _214 => _214.WebSocket])
9415
9444
  ),
9416
- authenticate: makeAuthDelegateForRoom("default", authManager),
9417
- canZombie: () => true
9445
+ authenticate: async () => {
9446
+ const resp = await authManager.getAuthValue({
9447
+ requestedScope: "room:read"
9448
+ });
9449
+ if (resp.type === "public") {
9450
+ throw new StopRetrying(
9451
+ "Cannot use AI Copilots with a public API key"
9452
+ );
9453
+ } else if (resp.token.parsed.k === "sec-legacy" /* SECRET_LEGACY */) {
9454
+ throw new StopRetrying("AI Copilots requires an ID or Access token");
9455
+ } else {
9456
+ if (!resp.token.parsed.ai) {
9457
+ throw new StopRetrying(
9458
+ "AI Copilots is not yet enabled for this account. To get started, see https://liveblocks.io/docs/get-started/ai-copilots#Quickstart"
9459
+ );
9460
+ }
9461
+ }
9462
+ return resp;
9463
+ },
9464
+ canZombie: () => false
9418
9465
  }
9419
9466
  });
9420
9467
  function teardownRoom(room) {
@@ -9461,14 +9508,14 @@ function createClient(options) {
9461
9508
  createSocket: makeCreateSocketDelegateForRoom(
9462
9509
  roomId,
9463
9510
  baseUrl,
9464
- _optionalChain([clientOptions, 'access', _195 => _195.polyfills, 'optionalAccess', _196 => _196.WebSocket])
9511
+ _optionalChain([clientOptions, 'access', _215 => _215.polyfills, 'optionalAccess', _216 => _216.WebSocket])
9465
9512
  ),
9466
9513
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
9467
9514
  })),
9468
9515
  enableDebugLogging: clientOptions.enableDebugLogging,
9469
9516
  baseUrl,
9470
9517
  errorEventSource: liveblocksErrorSource,
9471
- largeMessageStrategy: _nullishCoalesce(clientOptions.largeMessageStrategy, () => ( (clientOptions.unstable_fallbackToHTTP ? "experimental-fallback-to-http" : void 0))),
9518
+ largeMessageStrategy: clientOptions.largeMessageStrategy,
9472
9519
  unstable_streamData: !!clientOptions.unstable_streamData,
9473
9520
  roomHttpClient: httpClient,
9474
9521
  createSyncSource
@@ -9484,7 +9531,7 @@ function createClient(options) {
9484
9531
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
9485
9532
  if (shouldConnect) {
9486
9533
  if (typeof atob === "undefined") {
9487
- if (_optionalChain([clientOptions, 'access', _197 => _197.polyfills, 'optionalAccess', _198 => _198.atob]) === void 0) {
9534
+ if (_optionalChain([clientOptions, 'access', _217 => _217.polyfills, 'optionalAccess', _218 => _218.atob]) === void 0) {
9488
9535
  throw new Error(
9489
9536
  "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"
9490
9537
  );
@@ -9496,7 +9543,7 @@ function createClient(options) {
9496
9543
  return leaseRoom(newRoomDetails);
9497
9544
  }
9498
9545
  function getRoom(roomId) {
9499
- const room = _optionalChain([roomsById, 'access', _199 => _199.get, 'call', _200 => _200(roomId), 'optionalAccess', _201 => _201.room]);
9546
+ const room = _optionalChain([roomsById, 'access', _219 => _219.get, 'call', _220 => _220(roomId), 'optionalAccess', _221 => _221.room]);
9500
9547
  return room ? room : null;
9501
9548
  }
9502
9549
  function logout() {
@@ -9516,7 +9563,7 @@ function createClient(options) {
9516
9563
  const batchedResolveUsers = new Batch(
9517
9564
  async (batchedUserIds) => {
9518
9565
  const userIds = batchedUserIds.flat();
9519
- const users = await _optionalChain([resolveUsers, 'optionalCall', _202 => _202({ userIds })]);
9566
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _222 => _222({ userIds })]);
9520
9567
  warnIfNoResolveUsers();
9521
9568
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
9522
9569
  },
@@ -9534,7 +9581,7 @@ function createClient(options) {
9534
9581
  const batchedResolveRoomsInfo = new Batch(
9535
9582
  async (batchedRoomIds) => {
9536
9583
  const roomIds = batchedRoomIds.flat();
9537
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _203 => _203({ roomIds })]);
9584
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _223 => _223({ roomIds })]);
9538
9585
  warnIfNoResolveRoomsInfo();
9539
9586
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
9540
9587
  },
@@ -9587,7 +9634,7 @@ function createClient(options) {
9587
9634
  }
9588
9635
  };
9589
9636
  const win = typeof window !== "undefined" ? window : void 0;
9590
- _optionalChain([win, 'optionalAccess', _204 => _204.addEventListener, 'call', _205 => _205("beforeunload", maybePreventClose)]);
9637
+ _optionalChain([win, 'optionalAccess', _224 => _224.addEventListener, 'call', _225 => _225("beforeunload", maybePreventClose)]);
9591
9638
  }
9592
9639
  async function getNotificationSettings(options2) {
9593
9640
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -9726,7 +9773,7 @@ var commentBodyElementsTypes = {
9726
9773
  mention: "inline"
9727
9774
  };
9728
9775
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9729
- if (!body || !_optionalChain([body, 'optionalAccess', _206 => _206.content])) {
9776
+ if (!body || !_optionalChain([body, 'optionalAccess', _226 => _226.content])) {
9730
9777
  return;
9731
9778
  }
9732
9779
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -9736,38 +9783,47 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9736
9783
  for (const block of body.content) {
9737
9784
  if (type === "all" || type === "block") {
9738
9785
  if (guard(block)) {
9739
- _optionalChain([visitor, 'optionalCall', _207 => _207(block)]);
9786
+ _optionalChain([visitor, 'optionalCall', _227 => _227(block)]);
9740
9787
  }
9741
9788
  }
9742
9789
  if (type === "all" || type === "inline") {
9743
9790
  for (const inline of block.children) {
9744
9791
  if (guard(inline)) {
9745
- _optionalChain([visitor, 'optionalCall', _208 => _208(inline)]);
9792
+ _optionalChain([visitor, 'optionalCall', _228 => _228(inline)]);
9746
9793
  }
9747
9794
  }
9748
9795
  }
9749
9796
  }
9750
9797
  }
9751
- function getMentionedIdsFromCommentBody(body) {
9752
- const mentionedIds = /* @__PURE__ */ new Set();
9753
- traverseCommentBody(
9754
- body,
9755
- "mention",
9756
- (mention) => mentionedIds.add(mention.id)
9757
- );
9758
- return Array.from(mentionedIds);
9798
+ function getMentionsFromCommentBody(body, predicate) {
9799
+ const mentionIds = /* @__PURE__ */ new Set();
9800
+ const mentions = [];
9801
+ traverseCommentBody(body, "mention", (mention) => {
9802
+ if (
9803
+ // If this mention isn't already in the list
9804
+ !mentionIds.has(mention.id) && // And the provided predicate is true
9805
+ (predicate ? predicate(mention) : true)
9806
+ ) {
9807
+ mentionIds.add(mention.id);
9808
+ mentions.push(mention);
9809
+ }
9810
+ });
9811
+ return mentions;
9759
9812
  }
9760
9813
  async function resolveUsersInCommentBody(body, resolveUsers) {
9761
9814
  const resolvedUsers = /* @__PURE__ */ new Map();
9762
9815
  if (!resolveUsers) {
9763
9816
  return resolvedUsers;
9764
9817
  }
9765
- const userIds = getMentionedIdsFromCommentBody(body);
9818
+ const userIds = getMentionsFromCommentBody(
9819
+ body,
9820
+ (mention) => mention.kind === "user"
9821
+ ).map((mention) => mention.id);
9766
9822
  const users = await resolveUsers({
9767
9823
  userIds
9768
9824
  });
9769
9825
  for (const [index, userId] of userIds.entries()) {
9770
- const user = _optionalChain([users, 'optionalAccess', _209 => _209[index]]);
9826
+ const user = _optionalChain([users, 'optionalAccess', _229 => _229[index]]);
9771
9827
  if (user) {
9772
9828
  resolvedUsers.set(userId, user);
9773
9829
  }
@@ -9894,7 +9950,7 @@ var stringifyCommentBodyPlainElements = {
9894
9950
  text: ({ element }) => element.text,
9895
9951
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
9896
9952
  mention: ({ element, user }) => {
9897
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _210 => _210.name]), () => ( element.id))}`;
9953
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _230 => _230.name]), () => ( element.id))}`;
9898
9954
  }
9899
9955
  };
9900
9956
  var stringifyCommentBodyHtmlElements = {
@@ -9924,7 +9980,7 @@ var stringifyCommentBodyHtmlElements = {
9924
9980
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
9925
9981
  },
9926
9982
  mention: ({ element, user }) => {
9927
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _211 => _211.name]) ? html`${_optionalChain([user, 'optionalAccess', _212 => _212.name])}` : element.id}</span>`;
9983
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _231 => _231.name]) ? html`${_optionalChain([user, 'optionalAccess', _232 => _232.name])}` : element.id}</span>`;
9928
9984
  }
9929
9985
  };
9930
9986
  var stringifyCommentBodyMarkdownElements = {
@@ -9954,19 +10010,19 @@ var stringifyCommentBodyMarkdownElements = {
9954
10010
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
9955
10011
  },
9956
10012
  mention: ({ element, user }) => {
9957
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _213 => _213.name]), () => ( element.id))}`;
10013
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _233 => _233.name]), () => ( element.id))}`;
9958
10014
  }
9959
10015
  };
9960
10016
  async function stringifyCommentBody(body, options) {
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")));
10017
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _234 => _234.format]), () => ( "plain"));
10018
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _235 => _235.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
9963
10019
  const elements = {
9964
10020
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
9965
- ..._optionalChain([options, 'optionalAccess', _216 => _216.elements])
10021
+ ..._optionalChain([options, 'optionalAccess', _236 => _236.elements])
9966
10022
  };
9967
10023
  const resolvedUsers = await resolveUsersInCommentBody(
9968
10024
  body,
9969
- _optionalChain([options, 'optionalAccess', _217 => _217.resolveUsers])
10025
+ _optionalChain([options, 'optionalAccess', _237 => _237.resolveUsers])
9970
10026
  );
9971
10027
  const blocks = body.content.flatMap((block, blockIndex) => {
9972
10028
  switch (block.type) {
@@ -10257,12 +10313,12 @@ function legacy_patchImmutableNode(state, path, update) {
10257
10313
  }
10258
10314
  const newState = Object.assign({}, state);
10259
10315
  for (const key in update.updates) {
10260
- if (_optionalChain([update, 'access', _218 => _218.updates, 'access', _219 => _219[key], 'optionalAccess', _220 => _220.type]) === "update") {
10316
+ if (_optionalChain([update, 'access', _238 => _238.updates, 'access', _239 => _239[key], 'optionalAccess', _240 => _240.type]) === "update") {
10261
10317
  const val = update.node.get(key);
10262
10318
  if (val !== void 0) {
10263
10319
  newState[key] = lsonToJson(val);
10264
10320
  }
10265
- } else if (_optionalChain([update, 'access', _221 => _221.updates, 'access', _222 => _222[key], 'optionalAccess', _223 => _223.type]) === "delete") {
10321
+ } else if (_optionalChain([update, 'access', _241 => _241.updates, 'access', _242 => _242[key], 'optionalAccess', _243 => _243.type]) === "delete") {
10266
10322
  delete newState[key];
10267
10323
  }
10268
10324
  }
@@ -10323,12 +10379,12 @@ function legacy_patchImmutableNode(state, path, update) {
10323
10379
  }
10324
10380
  const newState = Object.assign({}, state);
10325
10381
  for (const key in update.updates) {
10326
- if (_optionalChain([update, 'access', _224 => _224.updates, 'access', _225 => _225[key], 'optionalAccess', _226 => _226.type]) === "update") {
10382
+ if (_optionalChain([update, 'access', _244 => _244.updates, 'access', _245 => _245[key], 'optionalAccess', _246 => _246.type]) === "update") {
10327
10383
  const value = update.node.get(key);
10328
10384
  if (value !== void 0) {
10329
10385
  newState[key] = lsonToJson(value);
10330
10386
  }
10331
- } else if (_optionalChain([update, 'access', _227 => _227.updates, 'access', _228 => _228[key], 'optionalAccess', _229 => _229.type]) === "delete") {
10387
+ } else if (_optionalChain([update, 'access', _247 => _247.updates, 'access', _248 => _248[key], 'optionalAccess', _249 => _249.type]) === "delete") {
10332
10388
  delete newState[key];
10333
10389
  }
10334
10390
  }
@@ -10408,9 +10464,9 @@ function makePoller(callback, intervalMs, options) {
10408
10464
  const startTime = performance.now();
10409
10465
  const doc = typeof document !== "undefined" ? document : void 0;
10410
10466
  const win = typeof window !== "undefined" ? window : void 0;
10411
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _230 => _230.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10467
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _250 => _250.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10412
10468
  const context = {
10413
- inForeground: _optionalChain([doc, 'optionalAccess', _231 => _231.visibilityState]) !== "hidden",
10469
+ inForeground: _optionalChain([doc, 'optionalAccess', _251 => _251.visibilityState]) !== "hidden",
10414
10470
  lastSuccessfulPollAt: startTime,
10415
10471
  count: 0,
10416
10472
  backoff: 0
@@ -10491,11 +10547,11 @@ function makePoller(callback, intervalMs, options) {
10491
10547
  pollNowIfStale();
10492
10548
  }
10493
10549
  function onVisibilityChange() {
10494
- setInForeground(_optionalChain([doc, 'optionalAccess', _232 => _232.visibilityState]) !== "hidden");
10550
+ setInForeground(_optionalChain([doc, 'optionalAccess', _252 => _252.visibilityState]) !== "hidden");
10495
10551
  }
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)]);
10552
+ _optionalChain([doc, 'optionalAccess', _253 => _253.addEventListener, 'call', _254 => _254("visibilitychange", onVisibilityChange)]);
10553
+ _optionalChain([win, 'optionalAccess', _255 => _255.addEventListener, 'call', _256 => _256("online", onVisibilityChange)]);
10554
+ _optionalChain([win, 'optionalAccess', _257 => _257.addEventListener, 'call', _258 => _258("focus", pollNowIfStale)]);
10499
10555
  fsm.start();
10500
10556
  return {
10501
10557
  inc,
@@ -10525,9 +10581,6 @@ var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
10525
10581
 
10526
10582
  // src/index.ts
10527
10583
  detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
10528
- var CommentsApiError = HttpError;
10529
- var NotificationsApiError = HttpError;
10530
-
10531
10584
 
10532
10585
 
10533
10586
 
@@ -10626,5 +10679,5 @@ var NotificationsApiError = HttpError;
10626
10679
 
10627
10680
 
10628
10681
 
10629
- exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
10682
+ exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
10630
10683
  //# sourceMappingURL=index.cjs.map