@liveblocks/core 3.8.0-tiptap1 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "3.8.0-tiptap1";
9
+ var PKG_VERSION = "3.8.1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -703,6 +703,7 @@ var AiChatDB = class {
703
703
  this.signal = new MutableSignal(this);
704
704
  }
705
705
  getEvenIfDeleted(chatId) {
706
+ this.signal.get();
706
707
  return this.#byId.get(chatId);
707
708
  }
708
709
  markDeleted(chatId) {
@@ -927,6 +928,9 @@ function isPlainObject(blob) {
927
928
  function isStartsWithOperator(blob) {
928
929
  return isPlainObject(blob) && typeof blob.startsWith === "string";
929
930
  }
931
+ function isNumberOperator(blob) {
932
+ return isPlainObject(blob) && (typeof blob.lt === "number" || typeof blob.gt === "number" || typeof blob.lte === "number" || typeof blob.gte === "number");
933
+ }
930
934
 
931
935
  // src/lib/autoRetry.ts
932
936
  var HttpError = class _HttpError extends Error {
@@ -1281,7 +1285,7 @@ function objectToQuery(obj) {
1281
1285
  if (isSimpleValue(value)) {
1282
1286
  keyValuePairs.push([key, value]);
1283
1287
  } else if (isPlainObject(value)) {
1284
- if (isStartsWithOperator(value)) {
1288
+ if (isStartsWithOperator(value) || isNumberOperator(value)) {
1285
1289
  keyValuePairsWithOperator.push([key, value]);
1286
1290
  } else {
1287
1291
  indexedKeys.push([key, value]);
@@ -1302,7 +1306,7 @@ function objectToQuery(obj) {
1302
1306
  }
1303
1307
  if (isSimpleValue(nestedValue)) {
1304
1308
  nKeyValuePairs.push([formatFilterKey(key, nestedKey), nestedValue]);
1305
- } else if (isStartsWithOperator(nestedValue)) {
1309
+ } else if (isStartsWithOperator(nestedValue) || isNumberOperator(nestedValue)) {
1306
1310
  nKeyValuePairsWithOperator.push([
1307
1311
  formatFilterKey(key, nestedKey),
1308
1312
  nestedValue
@@ -1338,6 +1342,34 @@ var getFiltersFromKeyValuePairsWithOperator = (keyValuePairsWithOperator) => {
1338
1342
  value: value.startsWith
1339
1343
  });
1340
1344
  }
1345
+ if ("lt" in value && typeof value.lt === "number") {
1346
+ filters.push({
1347
+ key,
1348
+ operator: "<",
1349
+ value: value.lt
1350
+ });
1351
+ }
1352
+ if ("gt" in value && typeof value.gt === "number") {
1353
+ filters.push({
1354
+ key,
1355
+ operator: ">",
1356
+ value: value.gt
1357
+ });
1358
+ }
1359
+ if ("gte" in value && typeof value.gte === "number") {
1360
+ filters.push({
1361
+ key,
1362
+ operator: ">=",
1363
+ value: value.gte
1364
+ });
1365
+ }
1366
+ if ("lte" in value && typeof value.lte === "number") {
1367
+ filters.push({
1368
+ key,
1369
+ operator: "<=",
1370
+ value: value.lte
1371
+ });
1372
+ }
1341
1373
  });
1342
1374
  return filters;
1343
1375
  };
@@ -2143,7 +2175,7 @@ function createApiClient({
2143
2175
  );
2144
2176
  return await result.json();
2145
2177
  }
2146
- async function sendMessages(options) {
2178
+ async function sendMessagesOverHTTP(options) {
2147
2179
  return httpClient.rawPost(
2148
2180
  url`/v2/c/rooms/${options.roomId}/send-message`,
2149
2181
  await authManager.getAuthValue({
@@ -2212,10 +2244,16 @@ function createApiClient({
2212
2244
  requestedAt: new Date(json.meta.requestedAt)
2213
2245
  };
2214
2246
  }
2215
- async function getUnreadInboxNotificationsCount() {
2247
+ async function getUnreadInboxNotificationsCount(options) {
2248
+ let query;
2249
+ if (_optionalChain([options, 'optionalAccess', _23 => _23.query])) {
2250
+ query = objectToQuery(options.query);
2251
+ }
2216
2252
  const { count } = await httpClient.get(
2217
2253
  url`/v2/c/inbox-notifications/count`,
2218
- await authManager.getAuthValue({ requestedScope: "comments:read" })
2254
+ await authManager.getAuthValue({ requestedScope: "comments:read" }),
2255
+ { query },
2256
+ { signal: _optionalChain([options, 'optionalAccess', _24 => _24.signal]) }
2219
2257
  );
2220
2258
  return count;
2221
2259
  }
@@ -2265,7 +2303,7 @@ function createApiClient({
2265
2303
  url`/v2/c/notification-settings`,
2266
2304
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
2267
2305
  void 0,
2268
- { signal: _optionalChain([options, 'optionalAccess', _23 => _23.signal]) }
2306
+ { signal: _optionalChain([options, 'optionalAccess', _25 => _25.signal]) }
2269
2307
  );
2270
2308
  }
2271
2309
  async function updateNotificationSettings(settings) {
@@ -2277,7 +2315,7 @@ function createApiClient({
2277
2315
  }
2278
2316
  async function getUserThreads_experimental(options) {
2279
2317
  let query;
2280
- if (_optionalChain([options, 'optionalAccess', _24 => _24.query])) {
2318
+ if (_optionalChain([options, 'optionalAccess', _26 => _26.query])) {
2281
2319
  query = objectToQuery(options.query);
2282
2320
  }
2283
2321
  const PAGE_SIZE = 50;
@@ -2285,7 +2323,7 @@ function createApiClient({
2285
2323
  url`/v2/c/threads`,
2286
2324
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
2287
2325
  {
2288
- cursor: _optionalChain([options, 'optionalAccess', _25 => _25.cursor]),
2326
+ cursor: _optionalChain([options, 'optionalAccess', _27 => _27.cursor]),
2289
2327
  query,
2290
2328
  limit: PAGE_SIZE
2291
2329
  }
@@ -2388,7 +2426,7 @@ function createApiClient({
2388
2426
  getChatAttachmentUrl,
2389
2427
  // Room storage
2390
2428
  streamStorage,
2391
- sendMessages,
2429
+ sendMessagesOverHTTP,
2392
2430
  // Notifications
2393
2431
  getInboxNotifications,
2394
2432
  getInboxNotificationsSince,
@@ -2450,7 +2488,7 @@ var HttpClient = class {
2450
2488
  // These headers are default, but can be overriden by custom headers
2451
2489
  "Content-Type": "application/json; charset=utf-8",
2452
2490
  // Possible header overrides
2453
- ..._optionalChain([options, 'optionalAccess', _26 => _26.headers]),
2491
+ ..._optionalChain([options, 'optionalAccess', _28 => _28.headers]),
2454
2492
  // Cannot be overriden by custom headers
2455
2493
  Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
2456
2494
  "X-LB-Client": PKG_VERSION || "dev"
@@ -2907,7 +2945,7 @@ var FSM = class {
2907
2945
  });
2908
2946
  }
2909
2947
  #getTargetFn(eventName) {
2910
- return _optionalChain([this, 'access', _27 => _27.#allowedTransitions, 'access', _28 => _28.get, 'call', _29 => _29(this.currentState), 'optionalAccess', _30 => _30.get, 'call', _31 => _31(eventName)]);
2948
+ return _optionalChain([this, 'access', _29 => _29.#allowedTransitions, 'access', _30 => _30.get, 'call', _31 => _31(this.currentState), 'optionalAccess', _32 => _32.get, 'call', _33 => _33(eventName)]);
2911
2949
  }
2912
2950
  /**
2913
2951
  * Exits the current state, and executes any necessary cleanup functions.
@@ -2924,7 +2962,7 @@ var FSM = class {
2924
2962
  this.#currentContext.allowPatching((patchableContext) => {
2925
2963
  levels = _nullishCoalesce(levels, () => ( this.#cleanupStack.length));
2926
2964
  for (let i = 0; i < levels; i++) {
2927
- _optionalChain([this, 'access', _32 => _32.#cleanupStack, 'access', _33 => _33.pop, 'call', _34 => _34(), 'optionalCall', _35 => _35(patchableContext)]);
2965
+ _optionalChain([this, 'access', _34 => _34.#cleanupStack, 'access', _35 => _35.pop, 'call', _36 => _36(), 'optionalCall', _37 => _37(patchableContext)]);
2928
2966
  }
2929
2967
  });
2930
2968
  }
@@ -2940,7 +2978,7 @@ var FSM = class {
2940
2978
  this.#currentContext.allowPatching((patchableContext) => {
2941
2979
  for (const pattern of enterPatterns) {
2942
2980
  const enterFn = this.#enterFns.get(pattern);
2943
- const cleanupFn = _optionalChain([enterFn, 'optionalCall', _36 => _36(patchableContext)]);
2981
+ const cleanupFn = _optionalChain([enterFn, 'optionalCall', _38 => _38(patchableContext)]);
2944
2982
  if (typeof cleanupFn === "function") {
2945
2983
  this.#cleanupStack.push(cleanupFn);
2946
2984
  } else {
@@ -3334,7 +3372,7 @@ function createConnectionStateMachine(delegates, options) {
3334
3372
  }
3335
3373
  function waitForActorId(event) {
3336
3374
  const serverMsg = tryParseJson(event.data);
3337
- if (_optionalChain([serverMsg, 'optionalAccess', _37 => _37.type]) === 104 /* ROOM_STATE */) {
3375
+ if (_optionalChain([serverMsg, 'optionalAccess', _39 => _39.type]) === 104 /* ROOM_STATE */) {
3338
3376
  didReceiveActor();
3339
3377
  }
3340
3378
  }
@@ -3443,12 +3481,12 @@ function createConnectionStateMachine(delegates, options) {
3443
3481
  const sendHeartbeat = {
3444
3482
  target: "@ok.awaiting-pong",
3445
3483
  effect: (ctx) => {
3446
- _optionalChain([ctx, 'access', _38 => _38.socket, 'optionalAccess', _39 => _39.send, 'call', _40 => _40("ping")]);
3484
+ _optionalChain([ctx, 'access', _40 => _40.socket, 'optionalAccess', _41 => _41.send, 'call', _42 => _42("ping")]);
3447
3485
  }
3448
3486
  };
3449
3487
  const maybeHeartbeat = () => {
3450
3488
  const doc = typeof document !== "undefined" ? document : void 0;
3451
- const canZombie = _optionalChain([doc, 'optionalAccess', _41 => _41.visibilityState]) === "hidden" && delegates.canZombie();
3489
+ const canZombie = _optionalChain([doc, 'optionalAccess', _43 => _43.visibilityState]) === "hidden" && delegates.canZombie();
3452
3490
  return canZombie ? "@idle.zombie" : sendHeartbeat;
3453
3491
  };
3454
3492
  machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
@@ -3487,7 +3525,7 @@ function createConnectionStateMachine(delegates, options) {
3487
3525
  // socket, or not. So always check to see if the socket is still OPEN or
3488
3526
  // not. When still OPEN, don't transition.
3489
3527
  EXPLICIT_SOCKET_ERROR: (_, context) => {
3490
- if (_optionalChain([context, 'access', _42 => _42.socket, 'optionalAccess', _43 => _43.readyState]) === 1) {
3528
+ if (_optionalChain([context, 'access', _44 => _44.socket, 'optionalAccess', _45 => _45.readyState]) === 1) {
3491
3529
  return null;
3492
3530
  }
3493
3531
  return {
@@ -3539,17 +3577,17 @@ function createConnectionStateMachine(delegates, options) {
3539
3577
  machine.send({ type: "NAVIGATOR_ONLINE" });
3540
3578
  }
3541
3579
  function onVisibilityChange() {
3542
- if (_optionalChain([doc, 'optionalAccess', _44 => _44.visibilityState]) === "visible") {
3580
+ if (_optionalChain([doc, 'optionalAccess', _46 => _46.visibilityState]) === "visible") {
3543
3581
  machine.send({ type: "WINDOW_GOT_FOCUS" });
3544
3582
  }
3545
3583
  }
3546
- _optionalChain([win, 'optionalAccess', _45 => _45.addEventListener, 'call', _46 => _46("online", onNetworkBackOnline)]);
3547
- _optionalChain([win, 'optionalAccess', _47 => _47.addEventListener, 'call', _48 => _48("offline", onNetworkOffline)]);
3548
- _optionalChain([root, 'optionalAccess', _49 => _49.addEventListener, 'call', _50 => _50("visibilitychange", onVisibilityChange)]);
3584
+ _optionalChain([win, 'optionalAccess', _47 => _47.addEventListener, 'call', _48 => _48("online", onNetworkBackOnline)]);
3585
+ _optionalChain([win, 'optionalAccess', _49 => _49.addEventListener, 'call', _50 => _50("offline", onNetworkOffline)]);
3586
+ _optionalChain([root, 'optionalAccess', _51 => _51.addEventListener, 'call', _52 => _52("visibilitychange", onVisibilityChange)]);
3549
3587
  return () => {
3550
- _optionalChain([root, 'optionalAccess', _51 => _51.removeEventListener, 'call', _52 => _52("visibilitychange", onVisibilityChange)]);
3551
- _optionalChain([win, 'optionalAccess', _53 => _53.removeEventListener, 'call', _54 => _54("online", onNetworkBackOnline)]);
3552
- _optionalChain([win, 'optionalAccess', _55 => _55.removeEventListener, 'call', _56 => _56("offline", onNetworkOffline)]);
3588
+ _optionalChain([root, 'optionalAccess', _53 => _53.removeEventListener, 'call', _54 => _54("visibilitychange", onVisibilityChange)]);
3589
+ _optionalChain([win, 'optionalAccess', _55 => _55.removeEventListener, 'call', _56 => _56("online", onNetworkBackOnline)]);
3590
+ _optionalChain([win, 'optionalAccess', _57 => _57.removeEventListener, 'call', _58 => _58("offline", onNetworkOffline)]);
3553
3591
  teardownSocket(ctx.socket);
3554
3592
  };
3555
3593
  });
@@ -3638,7 +3676,7 @@ var ManagedSocket = class {
3638
3676
  * message if this is somehow impossible.
3639
3677
  */
3640
3678
  send(data) {
3641
- const socket = _optionalChain([this, 'access', _57 => _57.#machine, 'access', _58 => _58.context, 'optionalAccess', _59 => _59.socket]);
3679
+ const socket = _optionalChain([this, 'access', _59 => _59.#machine, 'access', _60 => _60.context, 'optionalAccess', _61 => _61.socket]);
3642
3680
  if (socket === null) {
3643
3681
  warn("Cannot send: not connected yet", data);
3644
3682
  } else if (socket.readyState !== 1) {
@@ -4076,7 +4114,7 @@ function replaceOrAppend(content, newItem, keyFn, now2) {
4076
4114
  }
4077
4115
  }
4078
4116
  function closePart(prevPart, endedAt) {
4079
- if (_optionalChain([prevPart, 'optionalAccess', _60 => _60.type]) === "reasoning") {
4117
+ if (_optionalChain([prevPart, 'optionalAccess', _62 => _62.type]) === "reasoning") {
4080
4118
  prevPart.endedAt ??= endedAt;
4081
4119
  }
4082
4120
  }
@@ -4087,7 +4125,7 @@ function patchContentWithDelta(content, delta) {
4087
4125
  const lastPart = content[content.length - 1];
4088
4126
  switch (delta.type) {
4089
4127
  case "text-delta":
4090
- if (_optionalChain([lastPart, 'optionalAccess', _61 => _61.type]) === "text") {
4128
+ if (_optionalChain([lastPart, 'optionalAccess', _63 => _63.type]) === "text") {
4091
4129
  lastPart.text += delta.textDelta;
4092
4130
  } else {
4093
4131
  closePart(lastPart, now2);
@@ -4095,7 +4133,7 @@ function patchContentWithDelta(content, delta) {
4095
4133
  }
4096
4134
  break;
4097
4135
  case "reasoning-delta":
4098
- if (_optionalChain([lastPart, 'optionalAccess', _62 => _62.type]) === "reasoning") {
4136
+ if (_optionalChain([lastPart, 'optionalAccess', _64 => _64.type]) === "reasoning") {
4099
4137
  lastPart.text += delta.textDelta;
4100
4138
  } else {
4101
4139
  closePart(lastPart, now2);
@@ -4115,8 +4153,8 @@ function patchContentWithDelta(content, delta) {
4115
4153
  break;
4116
4154
  }
4117
4155
  case "tool-delta": {
4118
- if (_optionalChain([lastPart, 'optionalAccess', _63 => _63.type]) === "tool-invocation" && lastPart.stage === "receiving") {
4119
- _optionalChain([lastPart, 'access', _64 => _64.__appendDelta, 'optionalCall', _65 => _65(delta.delta)]);
4156
+ if (_optionalChain([lastPart, 'optionalAccess', _65 => _65.type]) === "tool-invocation" && lastPart.stage === "receiving") {
4157
+ _optionalChain([lastPart, 'access', _66 => _66.__appendDelta, 'optionalCall', _67 => _67(delta.delta)]);
4120
4158
  }
4121
4159
  break;
4122
4160
  }
@@ -4218,6 +4256,23 @@ var KnowledgeStack = class {
4218
4256
  this.invalidate();
4219
4257
  }
4220
4258
  };
4259
+ function createStore_forKnowledge() {
4260
+ const knowledgeByChatId = new DefaultMap(
4261
+ (_chatId) => new KnowledgeStack()
4262
+ );
4263
+ function getKnowledgeStack(chatId) {
4264
+ return knowledgeByChatId.getOrCreate(_nullishCoalesce(chatId, () => ( kWILDCARD)));
4265
+ }
4266
+ function getKnowledgeForChat(chatId) {
4267
+ const globalKnowledge = knowledgeByChatId.getOrCreate(kWILDCARD).get();
4268
+ const scopedKnowledge = _nullishCoalesce(_optionalChain([knowledgeByChatId, 'access', _68 => _68.get, 'call', _69 => _69(chatId), 'optionalAccess', _70 => _70.get, 'call', _71 => _71()]), () => ( []));
4269
+ return [...globalKnowledge, ...scopedKnowledge];
4270
+ }
4271
+ return {
4272
+ getKnowledgeStack,
4273
+ getKnowledgeForChat
4274
+ };
4275
+ }
4221
4276
  function now() {
4222
4277
  return (/* @__PURE__ */ new Date()).toISOString();
4223
4278
  }
@@ -4235,7 +4290,7 @@ function createStore_forTools() {
4235
4290
  return DerivedSignal.from(() => {
4236
4291
  return (
4237
4292
  // A tool that's registered and scoped to a specific chat ID...
4238
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _66 => _66.get, 'call', _67 => _67()]), () => ( // ...or a globally registered tool
4293
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _72 => _72.get, 'call', _73 => _73()]), () => ( // ...or a globally registered tool
4239
4294
  toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
4240
4295
  );
4241
4296
  });
@@ -4265,8 +4320,8 @@ function createStore_forTools() {
4265
4320
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
4266
4321
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
4267
4322
  return Array.from([
4268
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _68 => _68.entries, 'call', _69 => _69()]), () => ( [])),
4269
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _70 => _70.entries, 'call', _71 => _71()]), () => ( []))
4323
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _74 => _74.entries, 'call', _75 => _75()]), () => ( [])),
4324
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _76 => _76.entries, 'call', _77 => _77()]), () => ( []))
4270
4325
  ]).flatMap(([name, tool\u03A3]) => {
4271
4326
  const tool = tool\u03A3.get();
4272
4327
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -4369,7 +4424,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4369
4424
  } else {
4370
4425
  continue;
4371
4426
  }
4372
- const executeFn = _optionalChain([toolsStore, 'access', _72 => _72.getTool\u03A3, 'call', _73 => _73(toolInvocation.name, message.chatId), 'access', _74 => _74.get, 'call', _75 => _75(), 'optionalAccess', _76 => _76.execute]);
4427
+ const executeFn = _optionalChain([toolsStore, 'access', _78 => _78.getTool\u03A3, 'call', _79 => _79(toolInvocation.name, message.chatId), 'access', _80 => _80.get, 'call', _81 => _81(), 'optionalAccess', _82 => _82.execute]);
4373
4428
  if (executeFn) {
4374
4429
  (async () => {
4375
4430
  const result = await executeFn(toolInvocation.args, {
@@ -4468,8 +4523,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4468
4523
  const spine = [];
4469
4524
  let lastVisitedMessage = null;
4470
4525
  for (const message2 of pool.walkUp(leaf.id)) {
4471
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _77 => _77(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _78 => _78.id]), () => ( null));
4472
- const next = _nullishCoalesce(_optionalChain([first, 'call', _79 => _79(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _80 => _80.id]), () => ( null));
4526
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _83 => _83(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _84 => _84.id]), () => ( null));
4527
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _85 => _85(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _86 => _86.id]), () => ( null));
4473
4528
  if (!message2.deletedAt || prev || next) {
4474
4529
  const node = {
4475
4530
  ...message2,
@@ -4535,7 +4590,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4535
4590
  const latest = pool.sorted.findRight(
4536
4591
  (m) => m.role === "assistant" && !m.deletedAt
4537
4592
  );
4538
- return _optionalChain([latest, 'optionalAccess', _81 => _81.copilotId]);
4593
+ return _optionalChain([latest, 'optionalAccess', _87 => _87.copilotId]);
4539
4594
  }
4540
4595
  return {
4541
4596
  // Readers
@@ -4566,11 +4621,11 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4566
4621
  *getAutoExecutingMessageIds() {
4567
4622
  for (const messageId of myMessages) {
4568
4623
  const message = getMessageById(messageId);
4569
- if (_optionalChain([message, 'optionalAccess', _82 => _82.role]) === "assistant" && message.status === "awaiting-tool") {
4624
+ if (_optionalChain([message, 'optionalAccess', _88 => _88.role]) === "assistant" && message.status === "awaiting-tool") {
4570
4625
  const isAutoExecuting = message.contentSoFar.some((part) => {
4571
4626
  if (part.type === "tool-invocation" && part.stage === "executing") {
4572
4627
  const tool = toolsStore.getTool\u03A3(part.name, message.chatId).get();
4573
- return typeof _optionalChain([tool, 'optionalAccess', _83 => _83.execute]) === "function";
4628
+ return typeof _optionalChain([tool, 'optionalAccess', _89 => _89.execute]) === "function";
4574
4629
  }
4575
4630
  return false;
4576
4631
  });
@@ -4621,6 +4676,7 @@ function createAi(config) {
4621
4676
  );
4622
4677
  const chatsStore = createStore_forUserAiChats();
4623
4678
  const toolsStore = createStore_forTools();
4679
+ const knowledgeStore = createStore_forKnowledge();
4624
4680
  const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
4625
4681
  const context = {
4626
4682
  staticSessionInfoSig: new Signal(null),
@@ -4629,7 +4685,7 @@ function createAi(config) {
4629
4685
  chatsStore,
4630
4686
  messagesStore,
4631
4687
  toolsStore,
4632
- knowledge: new KnowledgeStack()
4688
+ knowledgeStore
4633
4689
  };
4634
4690
  const DELTA_THROTTLE = 25;
4635
4691
  let pendingDeltas = [];
@@ -4715,7 +4771,7 @@ function createAi(config) {
4715
4771
  flushPendingDeltas();
4716
4772
  switch (msg.event) {
4717
4773
  case "cmd-failed":
4718
- _optionalChain([pendingCmd, 'optionalAccess', _84 => _84.reject, 'call', _85 => _85(new Error(msg.error))]);
4774
+ _optionalChain([pendingCmd, 'optionalAccess', _90 => _90.reject, 'call', _91 => _91(new Error(msg.error))]);
4719
4775
  break;
4720
4776
  case "settle": {
4721
4777
  context.messagesStore.upsert(msg.message);
@@ -4792,7 +4848,7 @@ function createAi(config) {
4792
4848
  return assertNever(msg, "Unhandled case");
4793
4849
  }
4794
4850
  }
4795
- _optionalChain([pendingCmd, 'optionalAccess', _86 => _86.resolve, 'call', _87 => _87(msg)]);
4851
+ _optionalChain([pendingCmd, 'optionalAccess', _92 => _92.resolve, 'call', _93 => _93(msg)]);
4796
4852
  }
4797
4853
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4798
4854
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4858,17 +4914,8 @@ function createAi(config) {
4858
4914
  chatId
4859
4915
  });
4860
4916
  }
4861
- function registerKnowledgeLayer(uniqueLayerId) {
4862
- return context.knowledge.registerLayer(uniqueLayerId);
4863
- }
4864
- function deregisterKnowledgeLayer(layerKey) {
4865
- context.knowledge.deregisterLayer(layerKey);
4866
- }
4867
- function updateKnowledge(layerKey, data, key = nanoid()) {
4868
- context.knowledge.updateKnowledge(layerKey, key, data);
4869
- }
4870
4917
  async function setToolResult(chatId, messageId, invocationId, result, options) {
4871
- const knowledge = context.knowledge.get();
4918
+ const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
4872
4919
  const tools = context.toolsStore.getToolDescriptions(chatId);
4873
4920
  const resp = await sendClientMsgWithResponse({
4874
4921
  cmd: "set-tool-result",
@@ -4877,9 +4924,9 @@ function createAi(config) {
4877
4924
  invocationId,
4878
4925
  result,
4879
4926
  generationOptions: {
4880
- copilotId: _optionalChain([options, 'optionalAccess', _88 => _88.copilotId]),
4881
- stream: _optionalChain([options, 'optionalAccess', _89 => _89.stream]),
4882
- timeout: _optionalChain([options, 'optionalAccess', _90 => _90.timeout]),
4927
+ copilotId: _optionalChain([options, 'optionalAccess', _94 => _94.copilotId]),
4928
+ stream: _optionalChain([options, 'optionalAccess', _95 => _95.stream]),
4929
+ timeout: _optionalChain([options, 'optionalAccess', _96 => _96.timeout]),
4883
4930
  // Knowledge and tools aren't coming from the options, but retrieved
4884
4931
  // from the global context
4885
4932
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4897,7 +4944,7 @@ function createAi(config) {
4897
4944
  }
4898
4945
  }
4899
4946
  const win = typeof window !== "undefined" ? window : void 0;
4900
- _optionalChain([win, 'optionalAccess', _91 => _91.addEventListener, 'call', _92 => _92("beforeunload", handleBeforeUnload, { once: true })]);
4947
+ _optionalChain([win, 'optionalAccess', _97 => _97.addEventListener, 'call', _98 => _98("beforeunload", handleBeforeUnload, { once: true })]);
4901
4948
  return Object.defineProperty(
4902
4949
  {
4903
4950
  [kInternal]: {
@@ -4915,9 +4962,9 @@ function createAi(config) {
4915
4962
  deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
4916
4963
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4917
4964
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4918
- const globalKnowledge = context.knowledge.get();
4919
- const requestKnowledge = _optionalChain([options, 'optionalAccess', _93 => _93.knowledge]) || [];
4920
- const combinedKnowledge = [...globalKnowledge, ...requestKnowledge];
4965
+ const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
4966
+ const requestKnowledge = _optionalChain([options, 'optionalAccess', _99 => _99.knowledge]) || [];
4967
+ const combinedKnowledge = [...knowledge, ...requestKnowledge];
4921
4968
  const tools = context.toolsStore.getToolDescriptions(chatId);
4922
4969
  messagesStore.markMine(targetMessageId);
4923
4970
  const resp = await sendClientMsgWithResponse({
@@ -4926,9 +4973,9 @@ function createAi(config) {
4926
4973
  sourceMessage: userMessage,
4927
4974
  targetMessageId,
4928
4975
  generationOptions: {
4929
- copilotId: _optionalChain([options, 'optionalAccess', _94 => _94.copilotId]),
4930
- stream: _optionalChain([options, 'optionalAccess', _95 => _95.stream]),
4931
- timeout: _optionalChain([options, 'optionalAccess', _96 => _96.timeout]),
4976
+ copilotId: _optionalChain([options, 'optionalAccess', _100 => _100.copilotId]),
4977
+ stream: _optionalChain([options, 'optionalAccess', _101 => _101.stream]),
4978
+ timeout: _optionalChain([options, 'optionalAccess', _102 => _102.timeout]),
4932
4979
  // Combine global knowledge with request-specific knowledge
4933
4980
  knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
4934
4981
  tools: tools.length > 0 ? tools : void 0
@@ -4946,9 +4993,18 @@ function createAi(config) {
4946
4993
  getChatById: context.chatsStore.getChatById,
4947
4994
  queryChats: context.chatsStore.findMany,
4948
4995
  getLastUsedCopilotId: context.messagesStore.getLastUsedCopilotId,
4949
- registerKnowledgeLayer,
4950
- deregisterKnowledgeLayer,
4951
- updateKnowledge,
4996
+ registerKnowledgeLayer: (uniqueLayerId, chatId) => {
4997
+ const stack = context.knowledgeStore.getKnowledgeStack(chatId);
4998
+ const layerKey = stack.registerLayer(uniqueLayerId);
4999
+ const deregister = () => stack.deregisterLayer(layerKey);
5000
+ return {
5001
+ layerKey,
5002
+ deregister
5003
+ };
5004
+ },
5005
+ updateKnowledge: (layerKey, data, key, chatId) => {
5006
+ context.knowledgeStore.getKnowledgeStack(chatId).updateKnowledge(layerKey, _nullishCoalesce(key, () => ( nanoid())), data);
5007
+ },
4952
5008
  registerTool: context.toolsStore.registerTool
4953
5009
  },
4954
5010
  kInternal,
@@ -5029,7 +5085,7 @@ function createAuthManager(authOptions, onAuthenticate) {
5029
5085
  return void 0;
5030
5086
  }
5031
5087
  async function makeAuthRequest(options) {
5032
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _97 => _97.polyfills, 'optionalAccess', _98 => _98.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
5088
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _103 => _103.polyfills, 'optionalAccess', _104 => _104.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
5033
5089
  if (authentication.type === "private") {
5034
5090
  if (fetcher === void 0) {
5035
5091
  throw new StopRetrying(
@@ -5045,7 +5101,7 @@ function createAuthManager(authOptions, onAuthenticate) {
5045
5101
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
5046
5102
  );
5047
5103
  }
5048
- _optionalChain([onAuthenticate, 'optionalCall', _99 => _99(parsed.parsed)]);
5104
+ _optionalChain([onAuthenticate, 'optionalCall', _105 => _105(parsed.parsed)]);
5049
5105
  return parsed;
5050
5106
  }
5051
5107
  if (authentication.type === "custom") {
@@ -5053,7 +5109,7 @@ function createAuthManager(authOptions, onAuthenticate) {
5053
5109
  if (response && typeof response === "object") {
5054
5110
  if (typeof response.token === "string") {
5055
5111
  const parsed = parseAuthToken(response.token);
5056
- _optionalChain([onAuthenticate, 'optionalCall', _100 => _100(parsed.parsed)]);
5112
+ _optionalChain([onAuthenticate, 'optionalCall', _106 => _106(parsed.parsed)]);
5057
5113
  return parsed;
5058
5114
  } else if (typeof response.error === "string") {
5059
5115
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -5212,7 +5268,7 @@ function sendToPanel(message, options) {
5212
5268
  ...message,
5213
5269
  source: "liveblocks-devtools-client"
5214
5270
  };
5215
- if (!(_optionalChain([options, 'optionalAccess', _101 => _101.force]) || _bridgeActive)) {
5271
+ if (!(_optionalChain([options, 'optionalAccess', _107 => _107.force]) || _bridgeActive)) {
5216
5272
  return;
5217
5273
  }
5218
5274
  window.postMessage(fullMsg, "*");
@@ -5220,7 +5276,7 @@ function sendToPanel(message, options) {
5220
5276
  var eventSource = makeEventSource();
5221
5277
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
5222
5278
  window.addEventListener("message", (event) => {
5223
- if (event.source === window && _optionalChain([event, 'access', _102 => _102.data, 'optionalAccess', _103 => _103.source]) === "liveblocks-devtools-panel") {
5279
+ if (event.source === window && _optionalChain([event, 'access', _108 => _108.data, 'optionalAccess', _109 => _109.source]) === "liveblocks-devtools-panel") {
5224
5280
  eventSource.notify(event.data);
5225
5281
  } else {
5226
5282
  }
@@ -5362,7 +5418,7 @@ function fullSync(room) {
5362
5418
  msg: "room::sync::full",
5363
5419
  roomId: room.id,
5364
5420
  status: room.getStatus(),
5365
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _104 => _104.toTreeNode, 'call', _105 => _105("root"), 'access', _106 => _106.payload]), () => ( null)),
5421
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _110 => _110.toTreeNode, 'call', _111 => _111("root"), 'access', _112 => _112.payload]), () => ( null)),
5366
5422
  me,
5367
5423
  others
5368
5424
  });
@@ -5669,7 +5725,7 @@ function createManagedPool(roomId, options) {
5669
5725
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5670
5726
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5671
5727
  dispatch(ops, reverse, storageUpdates) {
5672
- _optionalChain([onDispatch, 'optionalCall', _107 => _107(ops, reverse, storageUpdates)]);
5728
+ _optionalChain([onDispatch, 'optionalCall', _113 => _113(ops, reverse, storageUpdates)]);
5673
5729
  },
5674
5730
  assertStorageIsWritable: () => {
5675
5731
  if (!isStorageWritable()) {
@@ -5896,7 +5952,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5896
5952
  return [
5897
5953
  {
5898
5954
  type: 8 /* CREATE_REGISTER */,
5899
- opId: _optionalChain([pool, 'optionalAccess', _108 => _108.generateOpId, 'call', _109 => _109()]),
5955
+ opId: _optionalChain([pool, 'optionalAccess', _114 => _114.generateOpId, 'call', _115 => _115()]),
5900
5956
  id: this._id,
5901
5957
  parentId,
5902
5958
  parentKey,
@@ -6002,7 +6058,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6002
6058
  const ops = [];
6003
6059
  const op = {
6004
6060
  id: this._id,
6005
- opId: _optionalChain([pool, 'optionalAccess', _110 => _110.generateOpId, 'call', _111 => _111()]),
6061
+ opId: _optionalChain([pool, 'optionalAccess', _116 => _116.generateOpId, 'call', _117 => _117()]),
6006
6062
  type: 2 /* CREATE_LIST */,
6007
6063
  parentId,
6008
6064
  parentKey
@@ -6273,7 +6329,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6273
6329
  #applyInsertUndoRedo(op) {
6274
6330
  const { id, parentKey: key } = op;
6275
6331
  const child = creationOpToLiveNode(op);
6276
- if (_optionalChain([this, 'access', _112 => _112._pool, 'optionalAccess', _113 => _113.getNode, 'call', _114 => _114(id)]) !== void 0) {
6332
+ if (_optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.getNode, 'call', _120 => _120(id)]) !== void 0) {
6277
6333
  return { modified: false };
6278
6334
  }
6279
6335
  child._attach(id, nn(this._pool));
@@ -6281,8 +6337,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6281
6337
  const existingItemIndex = this._indexOfPosition(key);
6282
6338
  let newKey = key;
6283
6339
  if (existingItemIndex !== -1) {
6284
- const before2 = _optionalChain([this, 'access', _115 => _115.#items, 'access', _116 => _116[existingItemIndex], 'optionalAccess', _117 => _117._parentPos]);
6285
- const after2 = _optionalChain([this, 'access', _118 => _118.#items, 'access', _119 => _119[existingItemIndex + 1], 'optionalAccess', _120 => _120._parentPos]);
6340
+ const before2 = _optionalChain([this, 'access', _121 => _121.#items, 'access', _122 => _122[existingItemIndex], 'optionalAccess', _123 => _123._parentPos]);
6341
+ const after2 = _optionalChain([this, 'access', _124 => _124.#items, 'access', _125 => _125[existingItemIndex + 1], 'optionalAccess', _126 => _126._parentPos]);
6286
6342
  newKey = makePosition(before2, after2);
6287
6343
  child._setParentLink(this, newKey);
6288
6344
  }
@@ -6296,7 +6352,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6296
6352
  #applySetUndoRedo(op) {
6297
6353
  const { id, parentKey: key } = op;
6298
6354
  const child = creationOpToLiveNode(op);
6299
- if (_optionalChain([this, 'access', _121 => _121._pool, 'optionalAccess', _122 => _122.getNode, 'call', _123 => _123(id)]) !== void 0) {
6355
+ if (_optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.getNode, 'call', _129 => _129(id)]) !== void 0) {
6300
6356
  return { modified: false };
6301
6357
  }
6302
6358
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -6417,7 +6473,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6417
6473
  } else {
6418
6474
  this.#items[existingItemIndex]._setParentLink(
6419
6475
  this,
6420
- makePosition(newKey, _optionalChain([this, 'access', _124 => _124.#items, 'access', _125 => _125[existingItemIndex + 1], 'optionalAccess', _126 => _126._parentPos]))
6476
+ makePosition(newKey, _optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131[existingItemIndex + 1], 'optionalAccess', _132 => _132._parentPos]))
6421
6477
  );
6422
6478
  const previousIndex = this.#items.indexOf(child);
6423
6479
  child._setParentLink(this, newKey);
@@ -6442,7 +6498,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6442
6498
  if (existingItemIndex !== -1) {
6443
6499
  this.#items[existingItemIndex]._setParentLink(
6444
6500
  this,
6445
- makePosition(newKey, _optionalChain([this, 'access', _127 => _127.#items, 'access', _128 => _128[existingItemIndex + 1], 'optionalAccess', _129 => _129._parentPos]))
6501
+ makePosition(newKey, _optionalChain([this, 'access', _133 => _133.#items, 'access', _134 => _134[existingItemIndex + 1], 'optionalAccess', _135 => _135._parentPos]))
6446
6502
  );
6447
6503
  }
6448
6504
  child._setParentLink(this, newKey);
@@ -6461,7 +6517,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6461
6517
  if (existingItemIndex !== -1) {
6462
6518
  this.#items[existingItemIndex]._setParentLink(
6463
6519
  this,
6464
- makePosition(newKey, _optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131[existingItemIndex + 1], 'optionalAccess', _132 => _132._parentPos]))
6520
+ makePosition(newKey, _optionalChain([this, 'access', _136 => _136.#items, 'access', _137 => _137[existingItemIndex + 1], 'optionalAccess', _138 => _138._parentPos]))
6465
6521
  );
6466
6522
  }
6467
6523
  child._setParentLink(this, newKey);
@@ -6489,7 +6545,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6489
6545
  if (existingItemIndex !== -1) {
6490
6546
  actualNewKey = makePosition(
6491
6547
  newKey,
6492
- _optionalChain([this, 'access', _133 => _133.#items, 'access', _134 => _134[existingItemIndex + 1], 'optionalAccess', _135 => _135._parentPos])
6548
+ _optionalChain([this, 'access', _139 => _139.#items, 'access', _140 => _140[existingItemIndex + 1], 'optionalAccess', _141 => _141._parentPos])
6493
6549
  );
6494
6550
  }
6495
6551
  child._setParentLink(this, actualNewKey);
@@ -6547,7 +6603,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6547
6603
  * @param element The element to add to the end of the LiveList.
6548
6604
  */
6549
6605
  push(element) {
6550
- _optionalChain([this, 'access', _136 => _136._pool, 'optionalAccess', _137 => _137.assertStorageIsWritable, 'call', _138 => _138()]);
6606
+ _optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
6551
6607
  return this.insert(element, this.length);
6552
6608
  }
6553
6609
  /**
@@ -6556,7 +6612,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6556
6612
  * @param index The index at which you want to insert the element.
6557
6613
  */
6558
6614
  insert(element, index) {
6559
- _optionalChain([this, 'access', _139 => _139._pool, 'optionalAccess', _140 => _140.assertStorageIsWritable, 'call', _141 => _141()]);
6615
+ _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
6560
6616
  if (index < 0 || index > this.#items.length) {
6561
6617
  throw new Error(
6562
6618
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6586,7 +6642,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6586
6642
  * @param targetIndex The index where the element should be after moving.
6587
6643
  */
6588
6644
  move(index, targetIndex) {
6589
- _optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
6645
+ _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
6590
6646
  if (targetIndex < 0) {
6591
6647
  throw new Error("targetIndex cannot be less than 0");
6592
6648
  }
@@ -6644,7 +6700,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6644
6700
  * @param index The index of the element to delete
6645
6701
  */
6646
6702
  delete(index) {
6647
- _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
6703
+ _optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.assertStorageIsWritable, 'call', _153 => _153()]);
6648
6704
  if (index < 0 || index >= this.#items.length) {
6649
6705
  throw new Error(
6650
6706
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6677,7 +6733,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6677
6733
  }
6678
6734
  }
6679
6735
  clear() {
6680
- _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
6736
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
6681
6737
  if (this._pool) {
6682
6738
  const ops = [];
6683
6739
  const reverseOps = [];
@@ -6711,7 +6767,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6711
6767
  }
6712
6768
  }
6713
6769
  set(index, item) {
6714
- _optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.assertStorageIsWritable, 'call', _153 => _153()]);
6770
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
6715
6771
  if (index < 0 || index >= this.#items.length) {
6716
6772
  throw new Error(
6717
6773
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6857,7 +6913,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6857
6913
  #shiftItemPosition(index, key) {
6858
6914
  const shiftedPosition = makePosition(
6859
6915
  key,
6860
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _154 => _154.#items, 'access', _155 => _155[index + 1], 'optionalAccess', _156 => _156._parentPos]) : void 0
6916
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _160 => _160.#items, 'access', _161 => _161[index + 1], 'optionalAccess', _162 => _162._parentPos]) : void 0
6861
6917
  );
6862
6918
  this.#items[index]._setParentLink(this, shiftedPosition);
6863
6919
  }
@@ -6982,7 +7038,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6982
7038
  const ops = [];
6983
7039
  const op = {
6984
7040
  id: this._id,
6985
- opId: _optionalChain([pool, 'optionalAccess', _157 => _157.generateOpId, 'call', _158 => _158()]),
7041
+ opId: _optionalChain([pool, 'optionalAccess', _163 => _163.generateOpId, 'call', _164 => _164()]),
6986
7042
  type: 7 /* CREATE_MAP */,
6987
7043
  parentId,
6988
7044
  parentKey
@@ -7084,7 +7140,12 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7084
7140
  const storageUpdate = {
7085
7141
  node: this,
7086
7142
  type: "LiveMap",
7087
- updates: { [parentKey]: { type: "delete" } }
7143
+ updates: {
7144
+ [parentKey]: {
7145
+ type: "delete",
7146
+ deletedItem: liveNodeToLson(child)
7147
+ }
7148
+ }
7088
7149
  };
7089
7150
  return { modified: storageUpdate, reverse };
7090
7151
  }
@@ -7117,7 +7178,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7117
7178
  * @param value The value of the element to add. Should be serializable to JSON.
7118
7179
  */
7119
7180
  set(key, value) {
7120
- _optionalChain([this, 'access', _159 => _159._pool, 'optionalAccess', _160 => _160.assertStorageIsWritable, 'call', _161 => _161()]);
7181
+ _optionalChain([this, 'access', _165 => _165._pool, 'optionalAccess', _166 => _166.assertStorageIsWritable, 'call', _167 => _167()]);
7121
7182
  const oldValue = this.#map.get(key);
7122
7183
  if (oldValue) {
7123
7184
  oldValue._detach();
@@ -7163,7 +7224,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7163
7224
  * @returns true if an element existed and has been removed, or false if the element does not exist.
7164
7225
  */
7165
7226
  delete(key) {
7166
- _optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.assertStorageIsWritable, 'call', _164 => _164()]);
7227
+ _optionalChain([this, 'access', _168 => _168._pool, 'optionalAccess', _169 => _169.assertStorageIsWritable, 'call', _170 => _170()]);
7167
7228
  const item = this.#map.get(key);
7168
7229
  if (item === void 0) {
7169
7230
  return false;
@@ -7177,7 +7238,12 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7177
7238
  storageUpdates.set(thisId, {
7178
7239
  node: this,
7179
7240
  type: "LiveMap",
7180
- updates: { [key]: { type: "delete" } }
7241
+ updates: {
7242
+ [key]: {
7243
+ type: "delete",
7244
+ deletedItem: liveNodeToLson(item)
7245
+ }
7246
+ }
7181
7247
  });
7182
7248
  this._pool.dispatch(
7183
7249
  [
@@ -7353,7 +7419,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7353
7419
  if (this._id === void 0) {
7354
7420
  throw new Error("Cannot serialize item is not attached");
7355
7421
  }
7356
- const opId = _optionalChain([pool, 'optionalAccess', _165 => _165.generateOpId, 'call', _166 => _166()]);
7422
+ const opId = _optionalChain([pool, 'optionalAccess', _171 => _171.generateOpId, 'call', _172 => _172()]);
7357
7423
  const ops = [];
7358
7424
  const op = {
7359
7425
  type: 4 /* CREATE_OBJECT */,
@@ -7581,13 +7647,13 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7581
7647
  }
7582
7648
  #applyDeleteObjectKey(op, isLocal) {
7583
7649
  const key = op.key;
7584
- if (this.#map.has(key) === false) {
7650
+ const oldValue = this.#map.get(key);
7651
+ if (oldValue === void 0) {
7585
7652
  return { modified: false };
7586
7653
  }
7587
7654
  if (!isLocal && this.#propToLastUpdate.get(key) !== void 0) {
7588
7655
  return { modified: false };
7589
7656
  }
7590
- const oldValue = this.#map.get(key);
7591
7657
  const id = nn(this._id);
7592
7658
  let reverse = [];
7593
7659
  if (isLiveNode(oldValue)) {
@@ -7608,7 +7674,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7608
7674
  modified: {
7609
7675
  node: this,
7610
7676
  type: "LiveObject",
7611
- updates: { [op.key]: { type: "delete" } }
7677
+ updates: {
7678
+ [op.key]: { type: "delete", deletedItem: oldValue }
7679
+ }
7612
7680
  },
7613
7681
  reverse
7614
7682
  };
@@ -7625,7 +7693,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7625
7693
  * @param value The value of the property to add
7626
7694
  */
7627
7695
  set(key, value) {
7628
- _optionalChain([this, 'access', _167 => _167._pool, 'optionalAccess', _168 => _168.assertStorageIsWritable, 'call', _169 => _169()]);
7696
+ _optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
7629
7697
  this.update({ [key]: value });
7630
7698
  }
7631
7699
  /**
@@ -7640,7 +7708,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7640
7708
  * @param key The key of the property to delete
7641
7709
  */
7642
7710
  delete(key) {
7643
- _optionalChain([this, 'access', _170 => _170._pool, 'optionalAccess', _171 => _171.assertStorageIsWritable, 'call', _172 => _172()]);
7711
+ _optionalChain([this, 'access', _176 => _176._pool, 'optionalAccess', _177 => _177.assertStorageIsWritable, 'call', _178 => _178()]);
7644
7712
  const keyAsString = key;
7645
7713
  const oldValue = this.#map.get(keyAsString);
7646
7714
  if (oldValue === void 0) {
@@ -7673,7 +7741,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7673
7741
  storageUpdates.set(this._id, {
7674
7742
  node: this,
7675
7743
  type: "LiveObject",
7676
- updates: { [key]: { type: "delete" } }
7744
+ updates: {
7745
+ [key]: { type: "delete", deletedItem: oldValue }
7746
+ }
7677
7747
  });
7678
7748
  this._pool.dispatch(
7679
7749
  [
@@ -7693,7 +7763,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7693
7763
  * @param patch The object used to overrides properties
7694
7764
  */
7695
7765
  update(patch) {
7696
- _optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
7766
+ _optionalChain([this, 'access', _179 => _179._pool, 'optionalAccess', _180 => _180.assertStorageIsWritable, 'call', _181 => _181()]);
7697
7767
  if (_LiveObject.detectLargeObjects) {
7698
7768
  const data = {};
7699
7769
  for (const [key, value] of this.#map) {
@@ -8441,15 +8511,15 @@ function installBackgroundTabSpy() {
8441
8511
  const doc = typeof document !== "undefined" ? document : void 0;
8442
8512
  const inBackgroundSince = { current: null };
8443
8513
  function onVisibilityChange() {
8444
- if (_optionalChain([doc, 'optionalAccess', _176 => _176.visibilityState]) === "hidden") {
8514
+ if (_optionalChain([doc, 'optionalAccess', _182 => _182.visibilityState]) === "hidden") {
8445
8515
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
8446
8516
  } else {
8447
8517
  inBackgroundSince.current = null;
8448
8518
  }
8449
8519
  }
8450
- _optionalChain([doc, 'optionalAccess', _177 => _177.addEventListener, 'call', _178 => _178("visibilitychange", onVisibilityChange)]);
8520
+ _optionalChain([doc, 'optionalAccess', _183 => _183.addEventListener, 'call', _184 => _184("visibilitychange", onVisibilityChange)]);
8451
8521
  const unsub = () => {
8452
- _optionalChain([doc, 'optionalAccess', _179 => _179.removeEventListener, 'call', _180 => _180("visibilitychange", onVisibilityChange)]);
8522
+ _optionalChain([doc, 'optionalAccess', _185 => _185.removeEventListener, 'call', _186 => _186("visibilitychange", onVisibilityChange)]);
8453
8523
  };
8454
8524
  return [inBackgroundSince, unsub];
8455
8525
  }
@@ -8629,7 +8699,7 @@ function createRoom(options, config) {
8629
8699
  }
8630
8700
  }
8631
8701
  function isStorageWritable() {
8632
- const scopes = _optionalChain([context, 'access', _181 => _181.dynamicSessionInfoSig, 'access', _182 => _182.get, 'call', _183 => _183(), 'optionalAccess', _184 => _184.scopes]);
8702
+ const scopes = _optionalChain([context, 'access', _187 => _187.dynamicSessionInfoSig, 'access', _188 => _188.get, 'call', _189 => _189(), 'optionalAccess', _190 => _190.scopes]);
8633
8703
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8634
8704
  }
8635
8705
  const eventHub = {
@@ -8753,13 +8823,22 @@ function createRoom(options, config) {
8753
8823
  }
8754
8824
  return;
8755
8825
  }
8826
+ // NOTE: This strategy is experimental as it will not work in all situations.
8827
+ // It should only be used for broadcasting, presence updates, but isn't suitable
8828
+ // for Storage or Yjs updates yet (because through this channel the server does
8829
+ // not respond with acks or rejections, causing the client's reported status to
8830
+ // be stuck in "synchronizing" forever).
8756
8831
  case "experimental-fallback-to-http": {
8757
8832
  warn("Message is too large for websockets, so sending over HTTP instead");
8758
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _185 => _185.dynamicSessionInfoSig, 'access', _186 => _186.get, 'call', _187 => _187(), 'optionalAccess', _188 => _188.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8759
- void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8833
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _191 => _191.dynamicSessionInfoSig, 'access', _192 => _192.get, 'call', _193 => _193(), 'optionalAccess', _194 => _194.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8834
+ void httpClient.sendMessagesOverHTTP({ roomId, nonce, messages }).then((resp) => {
8760
8835
  if (!resp.ok && resp.status === 403) {
8761
8836
  managedSocket.reconnect();
8762
8837
  }
8838
+ }).catch((err) => {
8839
+ error2(
8840
+ `Failed to deliver message over HTTP: ${String(err)}`
8841
+ );
8763
8842
  });
8764
8843
  return;
8765
8844
  }
@@ -8806,7 +8885,7 @@ function createRoom(options, config) {
8806
8885
  } else {
8807
8886
  context.root = LiveObject._fromItems(message.items, context.pool);
8808
8887
  }
8809
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _189 => _189.get, 'call', _190 => _190(), 'optionalAccess', _191 => _191.canWrite]), () => ( true));
8888
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _195 => _195.get, 'call', _196 => _196(), 'optionalAccess', _197 => _197.canWrite]), () => ( true));
8810
8889
  const stackSizeBefore = context.undoStack.length;
8811
8890
  for (const key in context.initialStorage) {
8812
8891
  if (context.root.get(key) === void 0) {
@@ -9009,7 +9088,7 @@ function createRoom(options, config) {
9009
9088
  }
9010
9089
  context.myPresence.patch(patch);
9011
9090
  if (context.activeBatch) {
9012
- if (_optionalChain([options2, 'optionalAccess', _192 => _192.addToHistory])) {
9091
+ if (_optionalChain([options2, 'optionalAccess', _198 => _198.addToHistory])) {
9013
9092
  context.activeBatch.reverseOps.pushLeft({
9014
9093
  type: "presence",
9015
9094
  data: oldValues
@@ -9018,7 +9097,7 @@ function createRoom(options, config) {
9018
9097
  context.activeBatch.updates.presence = true;
9019
9098
  } else {
9020
9099
  flushNowOrSoon();
9021
- if (_optionalChain([options2, 'optionalAccess', _193 => _193.addToHistory])) {
9100
+ if (_optionalChain([options2, 'optionalAccess', _199 => _199.addToHistory])) {
9022
9101
  addToUndoStack([{ type: "presence", data: oldValues }]);
9023
9102
  }
9024
9103
  notify({ presence: true });
@@ -9215,7 +9294,7 @@ function createRoom(options, config) {
9215
9294
  if (process.env.NODE_ENV !== "production") {
9216
9295
  const traces = /* @__PURE__ */ new Set();
9217
9296
  for (const opId of message.opIds) {
9218
- const trace = _optionalChain([context, 'access', _194 => _194.opStackTraces, 'optionalAccess', _195 => _195.get, 'call', _196 => _196(opId)]);
9297
+ const trace = _optionalChain([context, 'access', _200 => _200.opStackTraces, 'optionalAccess', _201 => _201.get, 'call', _202 => _202(opId)]);
9219
9298
  if (trace) {
9220
9299
  traces.add(trace);
9221
9300
  }
@@ -9349,7 +9428,7 @@ ${Array.from(traces).join("\n\n")}`
9349
9428
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
9350
9429
  createOrUpdateRootFromMessage(message);
9351
9430
  applyAndSendOps(unacknowledgedOps);
9352
- _optionalChain([_resolveStoragePromise, 'optionalCall', _197 => _197()]);
9431
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _203 => _203()]);
9353
9432
  notifyStorageStatus();
9354
9433
  eventHub.storageDidLoad.notify();
9355
9434
  }
@@ -9570,8 +9649,8 @@ ${Array.from(traces).join("\n\n")}`
9570
9649
  async function getThreads(options2) {
9571
9650
  return httpClient.getThreads({
9572
9651
  roomId,
9573
- query: _optionalChain([options2, 'optionalAccess', _198 => _198.query]),
9574
- cursor: _optionalChain([options2, 'optionalAccess', _199 => _199.cursor])
9652
+ query: _optionalChain([options2, 'optionalAccess', _204 => _204.query]),
9653
+ cursor: _optionalChain([options2, 'optionalAccess', _205 => _205.cursor])
9575
9654
  });
9576
9655
  }
9577
9656
  async function getThread(threadId) {
@@ -9678,7 +9757,7 @@ ${Array.from(traces).join("\n\n")}`
9678
9757
  function getSubscriptionSettings(options2) {
9679
9758
  return httpClient.getSubscriptionSettings({
9680
9759
  roomId,
9681
- signal: _optionalChain([options2, 'optionalAccess', _200 => _200.signal])
9760
+ signal: _optionalChain([options2, 'optionalAccess', _206 => _206.signal])
9682
9761
  });
9683
9762
  }
9684
9763
  function updateSubscriptionSettings(settings) {
@@ -9700,7 +9779,7 @@ ${Array.from(traces).join("\n\n")}`
9700
9779
  {
9701
9780
  [kInternal]: {
9702
9781
  get presenceBuffer() {
9703
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _201 => _201.buffer, 'access', _202 => _202.presenceUpdates, 'optionalAccess', _203 => _203.data]), () => ( null)));
9782
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _207 => _207.buffer, 'access', _208 => _208.presenceUpdates, 'optionalAccess', _209 => _209.data]), () => ( null)));
9704
9783
  },
9705
9784
  // prettier-ignore
9706
9785
  get undoStack() {
@@ -9715,9 +9794,9 @@ ${Array.from(traces).join("\n\n")}`
9715
9794
  return context.yjsProvider;
9716
9795
  },
9717
9796
  setYjsProvider(newProvider) {
9718
- _optionalChain([context, 'access', _204 => _204.yjsProvider, 'optionalAccess', _205 => _205.off, 'call', _206 => _206("status", yjsStatusDidChange)]);
9797
+ _optionalChain([context, 'access', _210 => _210.yjsProvider, 'optionalAccess', _211 => _211.off, 'call', _212 => _212("status", yjsStatusDidChange)]);
9719
9798
  context.yjsProvider = newProvider;
9720
- _optionalChain([newProvider, 'optionalAccess', _207 => _207.on, 'call', _208 => _208("status", yjsStatusDidChange)]);
9799
+ _optionalChain([newProvider, 'optionalAccess', _213 => _213.on, 'call', _214 => _214("status", yjsStatusDidChange)]);
9721
9800
  context.yjsProviderDidChange.notify();
9722
9801
  },
9723
9802
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9763,7 +9842,7 @@ ${Array.from(traces).join("\n\n")}`
9763
9842
  source.dispose();
9764
9843
  }
9765
9844
  eventHub.roomWillDestroy.notify();
9766
- _optionalChain([context, 'access', _209 => _209.yjsProvider, 'optionalAccess', _210 => _210.off, 'call', _211 => _211("status", yjsStatusDidChange)]);
9845
+ _optionalChain([context, 'access', _215 => _215.yjsProvider, 'optionalAccess', _216 => _216.off, 'call', _217 => _217("status", yjsStatusDidChange)]);
9767
9846
  syncSourceForStorage.destroy();
9768
9847
  syncSourceForYjs.destroy();
9769
9848
  uninstallBgTabSpy();
@@ -9913,7 +9992,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9913
9992
  }
9914
9993
  if (isLiveNode(first)) {
9915
9994
  const node = first;
9916
- if (_optionalChain([options, 'optionalAccess', _212 => _212.isDeep])) {
9995
+ if (_optionalChain([options, 'optionalAccess', _218 => _218.isDeep])) {
9917
9996
  const storageCallback = second;
9918
9997
  return subscribeToLiveStructureDeeply(node, storageCallback);
9919
9998
  } else {
@@ -9993,8 +10072,8 @@ function createClient(options) {
9993
10072
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9994
10073
  currentUserId.set(() => userId);
9995
10074
  });
9996
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _213 => _213.polyfills, 'optionalAccess', _214 => _214.fetch]) || /* istanbul ignore next */
9997
- _optionalChain([globalThis, 'access', _215 => _215.fetch, 'optionalAccess', _216 => _216.bind, 'call', _217 => _217(globalThis)]);
10075
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _219 => _219.polyfills, 'optionalAccess', _220 => _220.fetch]) || /* istanbul ignore next */
10076
+ _optionalChain([globalThis, 'access', _221 => _221.fetch, 'optionalAccess', _222 => _222.bind, 'call', _223 => _223(globalThis)]);
9998
10077
  const httpClient = createApiClient({
9999
10078
  baseUrl,
10000
10079
  fetchPolyfill,
@@ -10012,7 +10091,7 @@ function createClient(options) {
10012
10091
  delegates: {
10013
10092
  createSocket: makeCreateSocketDelegateForAi(
10014
10093
  baseUrl,
10015
- _optionalChain([clientOptions, 'access', _218 => _218.polyfills, 'optionalAccess', _219 => _219.WebSocket])
10094
+ _optionalChain([clientOptions, 'access', _224 => _224.polyfills, 'optionalAccess', _225 => _225.WebSocket])
10016
10095
  ),
10017
10096
  authenticate: async () => {
10018
10097
  const resp = await authManager.getAuthValue({
@@ -10024,12 +10103,6 @@ function createClient(options) {
10024
10103
  );
10025
10104
  } else if (resp.token.parsed.k === "sec-legacy" /* SECRET_LEGACY */) {
10026
10105
  throw new StopRetrying("AI Copilots requires an ID or Access token");
10027
- } else {
10028
- if (!resp.token.parsed.ai) {
10029
- throw new StopRetrying(
10030
- "AI Copilots is not yet enabled for this account. To get started, see https://liveblocks.io/docs/get-started/ai-copilots#Quickstart"
10031
- );
10032
- }
10033
10106
  }
10034
10107
  return resp;
10035
10108
  },
@@ -10080,7 +10153,7 @@ function createClient(options) {
10080
10153
  createSocket: makeCreateSocketDelegateForRoom(
10081
10154
  roomId,
10082
10155
  baseUrl,
10083
- _optionalChain([clientOptions, 'access', _220 => _220.polyfills, 'optionalAccess', _221 => _221.WebSocket])
10156
+ _optionalChain([clientOptions, 'access', _226 => _226.polyfills, 'optionalAccess', _227 => _227.WebSocket])
10084
10157
  ),
10085
10158
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
10086
10159
  })),
@@ -10103,7 +10176,7 @@ function createClient(options) {
10103
10176
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
10104
10177
  if (shouldConnect) {
10105
10178
  if (typeof atob === "undefined") {
10106
- if (_optionalChain([clientOptions, 'access', _222 => _222.polyfills, 'optionalAccess', _223 => _223.atob]) === void 0) {
10179
+ if (_optionalChain([clientOptions, 'access', _228 => _228.polyfills, 'optionalAccess', _229 => _229.atob]) === void 0) {
10107
10180
  throw new Error(
10108
10181
  "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"
10109
10182
  );
@@ -10115,7 +10188,7 @@ function createClient(options) {
10115
10188
  return leaseRoom(newRoomDetails);
10116
10189
  }
10117
10190
  function getRoom(roomId) {
10118
- const room = _optionalChain([roomsById, 'access', _224 => _224.get, 'call', _225 => _225(roomId), 'optionalAccess', _226 => _226.room]);
10191
+ const room = _optionalChain([roomsById, 'access', _230 => _230.get, 'call', _231 => _231(roomId), 'optionalAccess', _232 => _232.room]);
10119
10192
  return room ? room : null;
10120
10193
  }
10121
10194
  function logout() {
@@ -10131,7 +10204,7 @@ function createClient(options) {
10131
10204
  const batchedResolveUsers = new Batch(
10132
10205
  async (batchedUserIds) => {
10133
10206
  const userIds = batchedUserIds.flat();
10134
- const users = await _optionalChain([resolveUsers, 'optionalCall', _227 => _227({ userIds })]);
10207
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _233 => _233({ userIds })]);
10135
10208
  warnOnceIf(
10136
10209
  !resolveUsers,
10137
10210
  "Set the resolveUsers option in createClient to specify user info."
@@ -10148,7 +10221,7 @@ function createClient(options) {
10148
10221
  const batchedResolveRoomsInfo = new Batch(
10149
10222
  async (batchedRoomIds) => {
10150
10223
  const roomIds = batchedRoomIds.flat();
10151
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _228 => _228({ roomIds })]);
10224
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _234 => _234({ roomIds })]);
10152
10225
  warnOnceIf(
10153
10226
  !resolveRoomsInfo,
10154
10227
  "Set the resolveRoomsInfo option in createClient to specify room info."
@@ -10165,7 +10238,7 @@ function createClient(options) {
10165
10238
  const batchedResolveGroupsInfo = new Batch(
10166
10239
  async (batchedGroupIds) => {
10167
10240
  const groupIds = batchedGroupIds.flat();
10168
- const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _229 => _229({ groupIds })]);
10241
+ const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _235 => _235({ groupIds })]);
10169
10242
  warnOnceIf(
10170
10243
  !resolveGroupsInfo,
10171
10244
  "Set the resolveGroupsInfo option in createClient to specify group info."
@@ -10221,7 +10294,7 @@ function createClient(options) {
10221
10294
  }
10222
10295
  };
10223
10296
  const win = typeof window !== "undefined" ? window : void 0;
10224
- _optionalChain([win, 'optionalAccess', _230 => _230.addEventListener, 'call', _231 => _231("beforeunload", maybePreventClose)]);
10297
+ _optionalChain([win, 'optionalAccess', _236 => _236.addEventListener, 'call', _237 => _237("beforeunload", maybePreventClose)]);
10225
10298
  }
10226
10299
  async function getNotificationSettings(options2) {
10227
10300
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -10348,7 +10421,7 @@ var commentBodyElementsTypes = {
10348
10421
  mention: "inline"
10349
10422
  };
10350
10423
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10351
- if (!body || !_optionalChain([body, 'optionalAccess', _232 => _232.content])) {
10424
+ if (!body || !_optionalChain([body, 'optionalAccess', _238 => _238.content])) {
10352
10425
  return;
10353
10426
  }
10354
10427
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -10358,13 +10431,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10358
10431
  for (const block of body.content) {
10359
10432
  if (type === "all" || type === "block") {
10360
10433
  if (guard(block)) {
10361
- _optionalChain([visitor, 'optionalCall', _233 => _233(block)]);
10434
+ _optionalChain([visitor, 'optionalCall', _239 => _239(block)]);
10362
10435
  }
10363
10436
  }
10364
10437
  if (type === "all" || type === "inline") {
10365
10438
  for (const inline of block.children) {
10366
10439
  if (guard(inline)) {
10367
- _optionalChain([visitor, 'optionalCall', _234 => _234(inline)]);
10440
+ _optionalChain([visitor, 'optionalCall', _240 => _240(inline)]);
10368
10441
  }
10369
10442
  }
10370
10443
  }
@@ -10534,7 +10607,7 @@ var stringifyCommentBodyPlainElements = {
10534
10607
  text: ({ element }) => element.text,
10535
10608
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
10536
10609
  mention: ({ element, user, group }) => {
10537
- return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _235 => _235.name]), () => ( _optionalChain([group, 'optionalAccess', _236 => _236.name]))), () => ( element.id))}`;
10610
+ return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _241 => _241.name]), () => ( _optionalChain([group, 'optionalAccess', _242 => _242.name]))), () => ( element.id))}`;
10538
10611
  }
10539
10612
  };
10540
10613
  var stringifyCommentBodyHtmlElements = {
@@ -10564,7 +10637,7 @@ var stringifyCommentBodyHtmlElements = {
10564
10637
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10565
10638
  },
10566
10639
  mention: ({ element, user, group }) => {
10567
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _237 => _237.name]) ? html`${_optionalChain([user, 'optionalAccess', _238 => _238.name])}` : _optionalChain([group, 'optionalAccess', _239 => _239.name]) ? html`${_optionalChain([group, 'optionalAccess', _240 => _240.name])}` : element.id}</span>`;
10640
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _243 => _243.name]) ? html`${_optionalChain([user, 'optionalAccess', _244 => _244.name])}` : _optionalChain([group, 'optionalAccess', _245 => _245.name]) ? html`${_optionalChain([group, 'optionalAccess', _246 => _246.name])}` : element.id}</span>`;
10568
10641
  }
10569
10642
  };
10570
10643
  var stringifyCommentBodyMarkdownElements = {
@@ -10594,20 +10667,20 @@ var stringifyCommentBodyMarkdownElements = {
10594
10667
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10595
10668
  },
10596
10669
  mention: ({ element, user, group }) => {
10597
- return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _241 => _241.name]), () => ( _optionalChain([group, 'optionalAccess', _242 => _242.name]))), () => ( element.id))}`;
10670
+ return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _247 => _247.name]), () => ( _optionalChain([group, 'optionalAccess', _248 => _248.name]))), () => ( element.id))}`;
10598
10671
  }
10599
10672
  };
10600
10673
  async function stringifyCommentBody(body, options) {
10601
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _243 => _243.format]), () => ( "plain"));
10602
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _244 => _244.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10674
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _249 => _249.format]), () => ( "plain"));
10675
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _250 => _250.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10603
10676
  const elements = {
10604
10677
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10605
- ..._optionalChain([options, 'optionalAccess', _245 => _245.elements])
10678
+ ..._optionalChain([options, 'optionalAccess', _251 => _251.elements])
10606
10679
  };
10607
10680
  const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
10608
10681
  body,
10609
- _optionalChain([options, 'optionalAccess', _246 => _246.resolveUsers]),
10610
- _optionalChain([options, 'optionalAccess', _247 => _247.resolveGroupsInfo])
10682
+ _optionalChain([options, 'optionalAccess', _252 => _252.resolveUsers]),
10683
+ _optionalChain([options, 'optionalAccess', _253 => _253.resolveGroupsInfo])
10611
10684
  );
10612
10685
  const blocks = body.content.flatMap((block, blockIndex) => {
10613
10686
  switch (block.type) {
@@ -10894,12 +10967,12 @@ function legacy_patchImmutableNode(state, path, update) {
10894
10967
  }
10895
10968
  const newState = Object.assign({}, state);
10896
10969
  for (const key in update.updates) {
10897
- if (_optionalChain([update, 'access', _248 => _248.updates, 'access', _249 => _249[key], 'optionalAccess', _250 => _250.type]) === "update") {
10970
+ if (_optionalChain([update, 'access', _254 => _254.updates, 'access', _255 => _255[key], 'optionalAccess', _256 => _256.type]) === "update") {
10898
10971
  const val = update.node.get(key);
10899
10972
  if (val !== void 0) {
10900
10973
  newState[key] = lsonToJson(val);
10901
10974
  }
10902
- } else if (_optionalChain([update, 'access', _251 => _251.updates, 'access', _252 => _252[key], 'optionalAccess', _253 => _253.type]) === "delete") {
10975
+ } else if (_optionalChain([update, 'access', _257 => _257.updates, 'access', _258 => _258[key], 'optionalAccess', _259 => _259.type]) === "delete") {
10903
10976
  delete newState[key];
10904
10977
  }
10905
10978
  }
@@ -10960,12 +11033,12 @@ function legacy_patchImmutableNode(state, path, update) {
10960
11033
  }
10961
11034
  const newState = Object.assign({}, state);
10962
11035
  for (const key in update.updates) {
10963
- if (_optionalChain([update, 'access', _254 => _254.updates, 'access', _255 => _255[key], 'optionalAccess', _256 => _256.type]) === "update") {
11036
+ if (_optionalChain([update, 'access', _260 => _260.updates, 'access', _261 => _261[key], 'optionalAccess', _262 => _262.type]) === "update") {
10964
11037
  const value = update.node.get(key);
10965
11038
  if (value !== void 0) {
10966
11039
  newState[key] = lsonToJson(value);
10967
11040
  }
10968
- } else if (_optionalChain([update, 'access', _257 => _257.updates, 'access', _258 => _258[key], 'optionalAccess', _259 => _259.type]) === "delete") {
11041
+ } else if (_optionalChain([update, 'access', _263 => _263.updates, 'access', _264 => _264[key], 'optionalAccess', _265 => _265.type]) === "delete") {
10969
11042
  delete newState[key];
10970
11043
  }
10971
11044
  }
@@ -11045,9 +11118,9 @@ function makePoller(callback, intervalMs, options) {
11045
11118
  const startTime = performance.now();
11046
11119
  const doc = typeof document !== "undefined" ? document : void 0;
11047
11120
  const win = typeof window !== "undefined" ? window : void 0;
11048
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _260 => _260.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11121
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _266 => _266.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11049
11122
  const context = {
11050
- inForeground: _optionalChain([doc, 'optionalAccess', _261 => _261.visibilityState]) !== "hidden",
11123
+ inForeground: _optionalChain([doc, 'optionalAccess', _267 => _267.visibilityState]) !== "hidden",
11051
11124
  lastSuccessfulPollAt: startTime,
11052
11125
  count: 0,
11053
11126
  backoff: 0
@@ -11128,11 +11201,11 @@ function makePoller(callback, intervalMs, options) {
11128
11201
  pollNowIfStale();
11129
11202
  }
11130
11203
  function onVisibilityChange() {
11131
- setInForeground(_optionalChain([doc, 'optionalAccess', _262 => _262.visibilityState]) !== "hidden");
11204
+ setInForeground(_optionalChain([doc, 'optionalAccess', _268 => _268.visibilityState]) !== "hidden");
11132
11205
  }
11133
- _optionalChain([doc, 'optionalAccess', _263 => _263.addEventListener, 'call', _264 => _264("visibilitychange", onVisibilityChange)]);
11134
- _optionalChain([win, 'optionalAccess', _265 => _265.addEventListener, 'call', _266 => _266("online", onVisibilityChange)]);
11135
- _optionalChain([win, 'optionalAccess', _267 => _267.addEventListener, 'call', _268 => _268("focus", pollNowIfStale)]);
11206
+ _optionalChain([doc, 'optionalAccess', _269 => _269.addEventListener, 'call', _270 => _270("visibilitychange", onVisibilityChange)]);
11207
+ _optionalChain([win, 'optionalAccess', _271 => _271.addEventListener, 'call', _272 => _272("online", onVisibilityChange)]);
11208
+ _optionalChain([win, 'optionalAccess', _273 => _273.addEventListener, 'call', _274 => _274("focus", pollNowIfStale)]);
11136
11209
  fsm.start();
11137
11210
  return {
11138
11211
  inc,
@@ -11266,5 +11339,6 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
11266
11339
 
11267
11340
 
11268
11341
 
11269
- 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.MENTION_CHARACTER = MENTION_CHARACTER; 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.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
11342
+
11343
+ 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.MENTION_CHARACTER = MENTION_CHARACTER; 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.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
11270
11344
  //# sourceMappingURL=index.cjs.map