@liveblocks/core 3.13.0 → 3.13.1-hackathon

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.13.0";
9
+ var PKG_VERSION = "3.13.1-hackathon";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -3132,6 +3132,9 @@ var ServerMsgCode = Object.freeze({
3132
3132
  COMMENT_REACTION_ADDED: 405,
3133
3133
  COMMENT_REACTION_REMOVED: 406,
3134
3134
  COMMENT_METADATA_UPDATED: 409,
3135
+ // For Agent Sessions
3136
+ AGENT_SESSIONS: 501,
3137
+ AGENT_MESSAGES: 503,
3135
3138
  // Error codes
3136
3139
  REJECT_STORAGE_OP: 299
3137
3140
  // Sent if a mutation was not allowed on the server (i.e. due to permissions, limit exceeded, etc)
@@ -8507,7 +8510,10 @@ var ClientMsgCode = Object.freeze({
8507
8510
  UPDATE_STORAGE: 201,
8508
8511
  // For Yjs support
8509
8512
  FETCH_YDOC: 300,
8510
- UPDATE_YDOC: 301
8513
+ UPDATE_YDOC: 301,
8514
+ // For Agent Sessions
8515
+ FETCH_AGENT_SESSIONS: 500,
8516
+ FETCH_AGENT_MESSAGES: 502
8511
8517
  });
8512
8518
 
8513
8519
  // src/refs/ManagedOthers.ts
@@ -8965,6 +8971,7 @@ function createRoom(options, config) {
8965
8971
  storageStatus: makeEventSource(),
8966
8972
  ydoc: makeEventSource(),
8967
8973
  comments: makeEventSource(),
8974
+ agentSessions: makeEventSource(),
8968
8975
  roomWillDestroy: makeEventSource()
8969
8976
  };
8970
8977
  async function createTextMention(mentionId, mention) {
@@ -9575,6 +9582,45 @@ function createRoom(options, config) {
9575
9582
  eventHub.comments.notify(message);
9576
9583
  break;
9577
9584
  }
9585
+ case ServerMsgCode.AGENT_SESSIONS: {
9586
+ const agentSessionsMsg = message;
9587
+ if (agentSessionsMsg.operation === "list") {
9588
+ for (const [
9589
+ requestId,
9590
+ { resolve }
9591
+ ] of pendingAgentSessionsRequests) {
9592
+ resolve({
9593
+ sessions: agentSessionsMsg.sessions,
9594
+ nextCursor: agentSessionsMsg.nextCursor
9595
+ });
9596
+ pendingAgentSessionsRequests.delete(requestId);
9597
+ break;
9598
+ }
9599
+ }
9600
+ eventHub.agentSessions.notify(agentSessionsMsg);
9601
+ break;
9602
+ }
9603
+ case ServerMsgCode.AGENT_MESSAGES: {
9604
+ const agentMessagesMsg = message;
9605
+ if (agentMessagesMsg.operation === "list") {
9606
+ for (const [
9607
+ requestId,
9608
+ { resolve }
9609
+ ] of pendingAgentMessagesRequests) {
9610
+ const parsedRequestId = JSON.parse(requestId);
9611
+ if (parsedRequestId.sessionId === agentMessagesMsg.sessionId) {
9612
+ resolve({
9613
+ messages: agentMessagesMsg.messages,
9614
+ nextCursor: agentMessagesMsg.nextCursor
9615
+ });
9616
+ pendingAgentMessagesRequests.delete(requestId);
9617
+ break;
9618
+ }
9619
+ }
9620
+ }
9621
+ eventHub.agentSessions.notify(agentMessagesMsg);
9622
+ break;
9623
+ }
9578
9624
  default:
9579
9625
  break;
9580
9626
  }
@@ -9676,6 +9722,8 @@ function createRoom(options, config) {
9676
9722
  }
9677
9723
  let _getStorage$ = null;
9678
9724
  let _resolveStoragePromise = null;
9725
+ const pendingAgentSessionsRequests = /* @__PURE__ */ new Map();
9726
+ const pendingAgentMessagesRequests = /* @__PURE__ */ new Map();
9679
9727
  function processInitialStorage(message) {
9680
9728
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
9681
9729
  createOrUpdateRootFromMessage(message);
@@ -9743,6 +9791,65 @@ function createRoom(options, config) {
9743
9791
  }
9744
9792
  flushNowOrSoon();
9745
9793
  }
9794
+ async function fetchAgentSessions(options2) {
9795
+ const requestId = JSON.stringify({
9796
+ cursor: _optionalChain([options2, 'optionalAccess', _194 => _194.cursor]),
9797
+ since: _optionalChain([options2, 'optionalAccess', _195 => _195.since]),
9798
+ limit: _optionalChain([options2, 'optionalAccess', _196 => _196.limit]),
9799
+ metadata: _optionalChain([options2, 'optionalAccess', _197 => _197.metadata])
9800
+ });
9801
+ const { promise, resolve, reject } = Promise_withResolvers();
9802
+ pendingAgentSessionsRequests.set(requestId, { resolve, reject });
9803
+ const message = {
9804
+ type: ClientMsgCode.FETCH_AGENT_SESSIONS,
9805
+ cursor: _optionalChain([options2, 'optionalAccess', _198 => _198.cursor]),
9806
+ since: _optionalChain([options2, 'optionalAccess', _199 => _199.since]),
9807
+ limit: _optionalChain([options2, 'optionalAccess', _200 => _200.limit]),
9808
+ metadata: _optionalChain([options2, 'optionalAccess', _201 => _201.metadata])
9809
+ };
9810
+ context.buffer.messages.push(message);
9811
+ flushNowOrSoon();
9812
+ setTimeout(() => {
9813
+ if (pendingAgentSessionsRequests.has(requestId)) {
9814
+ pendingAgentSessionsRequests.delete(requestId);
9815
+ reject(new Error("Agent sessions fetch timeout"));
9816
+ }
9817
+ }, 3e4);
9818
+ return promise;
9819
+ }
9820
+ async function fetchAgentMessages(sessionId, options2) {
9821
+ const requestId = JSON.stringify({
9822
+ sessionId,
9823
+ cursor: _optionalChain([options2, 'optionalAccess', _202 => _202.cursor]),
9824
+ since: _optionalChain([options2, 'optionalAccess', _203 => _203.since]),
9825
+ limit: _optionalChain([options2, 'optionalAccess', _204 => _204.limit])
9826
+ });
9827
+ const existingRequest = pendingAgentMessagesRequests.get(requestId);
9828
+ if (existingRequest) {
9829
+ return new Promise((resolve2, reject2) => {
9830
+ existingRequest.resolve = resolve2;
9831
+ existingRequest.reject = reject2;
9832
+ });
9833
+ }
9834
+ const { promise, resolve, reject } = Promise_withResolvers();
9835
+ pendingAgentMessagesRequests.set(requestId, { resolve, reject });
9836
+ const message = {
9837
+ type: ClientMsgCode.FETCH_AGENT_MESSAGES,
9838
+ sessionId,
9839
+ cursor: _optionalChain([options2, 'optionalAccess', _205 => _205.cursor]),
9840
+ since: _optionalChain([options2, 'optionalAccess', _206 => _206.since]),
9841
+ limit: _optionalChain([options2, 'optionalAccess', _207 => _207.limit])
9842
+ };
9843
+ context.buffer.messages.push(message);
9844
+ flushNowOrSoon();
9845
+ setTimeout(() => {
9846
+ if (pendingAgentMessagesRequests.has(requestId)) {
9847
+ pendingAgentMessagesRequests.delete(requestId);
9848
+ reject(new Error("Agent messages fetch timeout"));
9849
+ }
9850
+ }, 3e4);
9851
+ return promise;
9852
+ }
9746
9853
  function undo() {
9747
9854
  if (context.activeBatch) {
9748
9855
  throw new Error("undo is not allowed during a batch");
@@ -9885,6 +9992,7 @@ function createRoom(options, config) {
9885
9992
  storageStatus: eventHub.storageStatus.observable,
9886
9993
  ydoc: eventHub.ydoc.observable,
9887
9994
  comments: eventHub.comments.observable,
9995
+ agentSessions: eventHub.agentSessions.observable,
9888
9996
  roomWillDestroy: eventHub.roomWillDestroy.observable
9889
9997
  };
9890
9998
  async function getThreadsSince(options2) {
@@ -9897,8 +10005,8 @@ function createRoom(options, config) {
9897
10005
  async function getThreads(options2) {
9898
10006
  return httpClient.getThreads({
9899
10007
  roomId,
9900
- query: _optionalChain([options2, 'optionalAccess', _194 => _194.query]),
9901
- cursor: _optionalChain([options2, 'optionalAccess', _195 => _195.cursor])
10008
+ query: _optionalChain([options2, 'optionalAccess', _208 => _208.query]),
10009
+ cursor: _optionalChain([options2, 'optionalAccess', _209 => _209.cursor])
9902
10010
  });
9903
10011
  }
9904
10012
  async function getThread(threadId) {
@@ -10020,7 +10128,7 @@ function createRoom(options, config) {
10020
10128
  function getSubscriptionSettings(options2) {
10021
10129
  return httpClient.getSubscriptionSettings({
10022
10130
  roomId,
10023
- signal: _optionalChain([options2, 'optionalAccess', _196 => _196.signal])
10131
+ signal: _optionalChain([options2, 'optionalAccess', _210 => _210.signal])
10024
10132
  });
10025
10133
  }
10026
10134
  function updateSubscriptionSettings(settings) {
@@ -10042,7 +10150,7 @@ function createRoom(options, config) {
10042
10150
  {
10043
10151
  [kInternal]: {
10044
10152
  get presenceBuffer() {
10045
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _197 => _197.buffer, 'access', _198 => _198.presenceUpdates, 'optionalAccess', _199 => _199.data]), () => ( null)));
10153
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _211 => _211.buffer, 'access', _212 => _212.presenceUpdates, 'optionalAccess', _213 => _213.data]), () => ( null)));
10046
10154
  },
10047
10155
  // prettier-ignore
10048
10156
  get undoStack() {
@@ -10057,9 +10165,9 @@ function createRoom(options, config) {
10057
10165
  return context.yjsProvider;
10058
10166
  },
10059
10167
  setYjsProvider(newProvider) {
10060
- _optionalChain([context, 'access', _200 => _200.yjsProvider, 'optionalAccess', _201 => _201.off, 'call', _202 => _202("status", yjsStatusDidChange)]);
10168
+ _optionalChain([context, 'access', _214 => _214.yjsProvider, 'optionalAccess', _215 => _215.off, 'call', _216 => _216("status", yjsStatusDidChange)]);
10061
10169
  context.yjsProvider = newProvider;
10062
- _optionalChain([newProvider, 'optionalAccess', _203 => _203.on, 'call', _204 => _204("status", yjsStatusDidChange)]);
10170
+ _optionalChain([newProvider, 'optionalAccess', _217 => _217.on, 'call', _218 => _218("status", yjsStatusDidChange)]);
10063
10171
  context.yjsProviderDidChange.notify();
10064
10172
  },
10065
10173
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -10093,7 +10201,7 @@ function createRoom(options, config) {
10093
10201
  id: roomId,
10094
10202
  subscribe: makeClassicSubscribeFn(
10095
10203
  roomId,
10096
- events,
10204
+ eventHub,
10097
10205
  config.errorEventSource
10098
10206
  ),
10099
10207
  connect: () => managedSocket.connect(),
@@ -10105,7 +10213,7 @@ function createRoom(options, config) {
10105
10213
  source.dispose();
10106
10214
  }
10107
10215
  eventHub.roomWillDestroy.notify();
10108
- _optionalChain([context, 'access', _205 => _205.yjsProvider, 'optionalAccess', _206 => _206.off, 'call', _207 => _207("status", yjsStatusDidChange)]);
10216
+ _optionalChain([context, 'access', _219 => _219.yjsProvider, 'optionalAccess', _220 => _220.off, 'call', _221 => _221("status", yjsStatusDidChange)]);
10109
10217
  syncSourceForStorage.destroy();
10110
10218
  syncSourceForYjs.destroy();
10111
10219
  uninstallBgTabSpy();
@@ -10128,6 +10236,8 @@ function createRoom(options, config) {
10128
10236
  resume: resumeHistory
10129
10237
  },
10130
10238
  fetchYDoc,
10239
+ fetchAgentSessions,
10240
+ fetchAgentMessages,
10131
10241
  getStorage,
10132
10242
  getStorageSnapshot,
10133
10243
  getStorageStatus,
@@ -10256,7 +10366,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
10256
10366
  }
10257
10367
  if (isLiveNode(first)) {
10258
10368
  const node = first;
10259
- if (_optionalChain([options, 'optionalAccess', _208 => _208.isDeep])) {
10369
+ if (_optionalChain([options, 'optionalAccess', _222 => _222.isDeep])) {
10260
10370
  const storageCallback = second;
10261
10371
  return subscribeToLiveStructureDeeply(node, storageCallback);
10262
10372
  } else {
@@ -10339,8 +10449,8 @@ function createClient(options) {
10339
10449
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
10340
10450
  currentUserId.set(() => userId);
10341
10451
  });
10342
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _209 => _209.polyfills, 'optionalAccess', _210 => _210.fetch]) || /* istanbul ignore next */
10343
- _optionalChain([globalThis, 'access', _211 => _211.fetch, 'optionalAccess', _212 => _212.bind, 'call', _213 => _213(globalThis)]);
10452
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _223 => _223.polyfills, 'optionalAccess', _224 => _224.fetch]) || /* istanbul ignore next */
10453
+ _optionalChain([globalThis, 'access', _225 => _225.fetch, 'optionalAccess', _226 => _226.bind, 'call', _227 => _227(globalThis)]);
10344
10454
  const httpClient = createApiClient({
10345
10455
  baseUrl,
10346
10456
  fetchPolyfill,
@@ -10358,7 +10468,7 @@ function createClient(options) {
10358
10468
  delegates: {
10359
10469
  createSocket: makeCreateSocketDelegateForAi(
10360
10470
  baseUrl,
10361
- _optionalChain([clientOptions, 'access', _214 => _214.polyfills, 'optionalAccess', _215 => _215.WebSocket])
10471
+ _optionalChain([clientOptions, 'access', _228 => _228.polyfills, 'optionalAccess', _229 => _229.WebSocket])
10362
10472
  ),
10363
10473
  authenticate: async () => {
10364
10474
  const resp = await authManager.getAuthValue({
@@ -10420,7 +10530,7 @@ function createClient(options) {
10420
10530
  createSocket: makeCreateSocketDelegateForRoom(
10421
10531
  roomId,
10422
10532
  baseUrl,
10423
- _optionalChain([clientOptions, 'access', _216 => _216.polyfills, 'optionalAccess', _217 => _217.WebSocket]),
10533
+ _optionalChain([clientOptions, 'access', _230 => _230.polyfills, 'optionalAccess', _231 => _231.WebSocket]),
10424
10534
  options2.engine
10425
10535
  ),
10426
10536
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
@@ -10445,7 +10555,7 @@ function createClient(options) {
10445
10555
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
10446
10556
  if (shouldConnect) {
10447
10557
  if (typeof atob === "undefined") {
10448
- if (_optionalChain([clientOptions, 'access', _218 => _218.polyfills, 'optionalAccess', _219 => _219.atob]) === void 0) {
10558
+ if (_optionalChain([clientOptions, 'access', _232 => _232.polyfills, 'optionalAccess', _233 => _233.atob]) === void 0) {
10449
10559
  throw new Error(
10450
10560
  "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"
10451
10561
  );
@@ -10457,7 +10567,7 @@ function createClient(options) {
10457
10567
  return leaseRoom(newRoomDetails);
10458
10568
  }
10459
10569
  function getRoom(roomId) {
10460
- const room = _optionalChain([roomsById, 'access', _220 => _220.get, 'call', _221 => _221(roomId), 'optionalAccess', _222 => _222.room]);
10570
+ const room = _optionalChain([roomsById, 'access', _234 => _234.get, 'call', _235 => _235(roomId), 'optionalAccess', _236 => _236.room]);
10461
10571
  return room ? room : null;
10462
10572
  }
10463
10573
  function logout() {
@@ -10473,7 +10583,7 @@ function createClient(options) {
10473
10583
  const batchedResolveUsers = new Batch(
10474
10584
  async (batchedUserIds) => {
10475
10585
  const userIds = batchedUserIds.flat();
10476
- const users = await _optionalChain([resolveUsers, 'optionalCall', _223 => _223({ userIds })]);
10586
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _237 => _237({ userIds })]);
10477
10587
  warnOnceIf(
10478
10588
  !resolveUsers,
10479
10589
  "Set the resolveUsers option in createClient to specify user info."
@@ -10490,7 +10600,7 @@ function createClient(options) {
10490
10600
  const batchedResolveRoomsInfo = new Batch(
10491
10601
  async (batchedRoomIds) => {
10492
10602
  const roomIds = batchedRoomIds.flat();
10493
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _224 => _224({ roomIds })]);
10603
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _238 => _238({ roomIds })]);
10494
10604
  warnOnceIf(
10495
10605
  !resolveRoomsInfo,
10496
10606
  "Set the resolveRoomsInfo option in createClient to specify room info."
@@ -10507,7 +10617,7 @@ function createClient(options) {
10507
10617
  const batchedResolveGroupsInfo = new Batch(
10508
10618
  async (batchedGroupIds) => {
10509
10619
  const groupIds = batchedGroupIds.flat();
10510
- const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _225 => _225({ groupIds })]);
10620
+ const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _239 => _239({ groupIds })]);
10511
10621
  warnOnceIf(
10512
10622
  !resolveGroupsInfo,
10513
10623
  "Set the resolveGroupsInfo option in createClient to specify group info."
@@ -10563,7 +10673,7 @@ function createClient(options) {
10563
10673
  }
10564
10674
  };
10565
10675
  const win = typeof window !== "undefined" ? window : void 0;
10566
- _optionalChain([win, 'optionalAccess', _226 => _226.addEventListener, 'call', _227 => _227("beforeunload", maybePreventClose)]);
10676
+ _optionalChain([win, 'optionalAccess', _240 => _240.addEventListener, 'call', _241 => _241("beforeunload", maybePreventClose)]);
10567
10677
  }
10568
10678
  async function getNotificationSettings(options2) {
10569
10679
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -10690,7 +10800,7 @@ var commentBodyElementsTypes = {
10690
10800
  mention: "inline"
10691
10801
  };
10692
10802
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10693
- if (!body || !_optionalChain([body, 'optionalAccess', _228 => _228.content])) {
10803
+ if (!body || !_optionalChain([body, 'optionalAccess', _242 => _242.content])) {
10694
10804
  return;
10695
10805
  }
10696
10806
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -10700,13 +10810,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10700
10810
  for (const block of body.content) {
10701
10811
  if (type === "all" || type === "block") {
10702
10812
  if (guard(block)) {
10703
- _optionalChain([visitor, 'optionalCall', _229 => _229(block)]);
10813
+ _optionalChain([visitor, 'optionalCall', _243 => _243(block)]);
10704
10814
  }
10705
10815
  }
10706
10816
  if (type === "all" || type === "inline") {
10707
10817
  for (const inline of block.children) {
10708
10818
  if (guard(inline)) {
10709
- _optionalChain([visitor, 'optionalCall', _230 => _230(inline)]);
10819
+ _optionalChain([visitor, 'optionalCall', _244 => _244(inline)]);
10710
10820
  }
10711
10821
  }
10712
10822
  }
@@ -10876,7 +10986,7 @@ var stringifyCommentBodyPlainElements = {
10876
10986
  text: ({ element }) => element.text,
10877
10987
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
10878
10988
  mention: ({ element, user, group }) => {
10879
- return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _231 => _231.name]), () => ( _optionalChain([group, 'optionalAccess', _232 => _232.name]))), () => ( element.id))}`;
10989
+ return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _245 => _245.name]), () => ( _optionalChain([group, 'optionalAccess', _246 => _246.name]))), () => ( element.id))}`;
10880
10990
  }
10881
10991
  };
10882
10992
  var stringifyCommentBodyHtmlElements = {
@@ -10906,7 +11016,7 @@ var stringifyCommentBodyHtmlElements = {
10906
11016
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10907
11017
  },
10908
11018
  mention: ({ element, user, group }) => {
10909
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _233 => _233.name]) ? html`${_optionalChain([user, 'optionalAccess', _234 => _234.name])}` : _optionalChain([group, 'optionalAccess', _235 => _235.name]) ? html`${_optionalChain([group, 'optionalAccess', _236 => _236.name])}` : element.id}</span>`;
11019
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _247 => _247.name]) ? html`${_optionalChain([user, 'optionalAccess', _248 => _248.name])}` : _optionalChain([group, 'optionalAccess', _249 => _249.name]) ? html`${_optionalChain([group, 'optionalAccess', _250 => _250.name])}` : element.id}</span>`;
10910
11020
  }
10911
11021
  };
10912
11022
  var stringifyCommentBodyMarkdownElements = {
@@ -10936,20 +11046,20 @@ var stringifyCommentBodyMarkdownElements = {
10936
11046
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10937
11047
  },
10938
11048
  mention: ({ element, user, group }) => {
10939
- return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _237 => _237.name]), () => ( _optionalChain([group, 'optionalAccess', _238 => _238.name]))), () => ( element.id))}`;
11049
+ return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _251 => _251.name]), () => ( _optionalChain([group, 'optionalAccess', _252 => _252.name]))), () => ( element.id))}`;
10940
11050
  }
10941
11051
  };
10942
11052
  async function stringifyCommentBody(body, options) {
10943
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _239 => _239.format]), () => ( "plain"));
10944
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _240 => _240.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
11053
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _253 => _253.format]), () => ( "plain"));
11054
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _254 => _254.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10945
11055
  const elements = {
10946
11056
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10947
- ..._optionalChain([options, 'optionalAccess', _241 => _241.elements])
11057
+ ..._optionalChain([options, 'optionalAccess', _255 => _255.elements])
10948
11058
  };
10949
11059
  const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
10950
11060
  body,
10951
- _optionalChain([options, 'optionalAccess', _242 => _242.resolveUsers]),
10952
- _optionalChain([options, 'optionalAccess', _243 => _243.resolveGroupsInfo])
11061
+ _optionalChain([options, 'optionalAccess', _256 => _256.resolveUsers]),
11062
+ _optionalChain([options, 'optionalAccess', _257 => _257.resolveGroupsInfo])
10953
11063
  );
10954
11064
  const blocks = body.content.flatMap((block, blockIndex) => {
10955
11065
  switch (block.type) {
@@ -11080,9 +11190,9 @@ function lsonToJson(value) {
11080
11190
  }
11081
11191
  return value;
11082
11192
  }
11083
- function deepLiveify(value) {
11193
+ function _deepLiveify(value) {
11084
11194
  if (Array.isArray(value)) {
11085
- return new LiveList(value.map(deepLiveify));
11195
+ return new LiveList(value.map(_deepLiveify));
11086
11196
  } else if (isPlainObject(value)) {
11087
11197
  const init = {};
11088
11198
  for (const key in value) {
@@ -11090,7 +11200,7 @@ function deepLiveify(value) {
11090
11200
  if (val === void 0) {
11091
11201
  continue;
11092
11202
  }
11093
- init[key] = deepLiveify(val);
11203
+ init[key] = _deepLiveify(val);
11094
11204
  }
11095
11205
  return new LiveObject(init);
11096
11206
  } else {
@@ -11127,7 +11237,7 @@ function patchLiveList(liveList, prev, next) {
11127
11237
  if (i > prevEnd) {
11128
11238
  if (i <= nextEnd) {
11129
11239
  while (i <= nextEnd) {
11130
- liveList.insert(deepLiveify(next[i]), i);
11240
+ liveList.insert(_deepLiveify(next[i]), i);
11131
11241
  i++;
11132
11242
  }
11133
11243
  }
@@ -11145,12 +11255,12 @@ function patchLiveList(liveList, prev, next) {
11145
11255
  if (isLiveObject(liveListNode) && isPlainObject(prevNode) && isPlainObject(nextNode)) {
11146
11256
  patchLiveObject(liveListNode, prevNode, nextNode);
11147
11257
  } else {
11148
- liveList.set(i, deepLiveify(nextNode));
11258
+ liveList.set(i, _deepLiveify(nextNode));
11149
11259
  }
11150
11260
  i++;
11151
11261
  }
11152
11262
  while (i <= nextEnd) {
11153
- liveList.insert(deepLiveify(next[i]), i);
11263
+ liveList.insert(_deepLiveify(next[i]), i);
11154
11264
  i++;
11155
11265
  }
11156
11266
  let localI = i;
@@ -11177,7 +11287,7 @@ Only serializable value can be synced with Liveblocks.`
11177
11287
  if (next === void 0) {
11178
11288
  liveObject.delete(key);
11179
11289
  } else if (value === void 0) {
11180
- liveObject.set(key, deepLiveify(next));
11290
+ liveObject.set(key, _deepLiveify(next));
11181
11291
  } else if (prev === next) {
11182
11292
  return;
11183
11293
  } else if (isLiveList(value) && Array.isArray(prev) && Array.isArray(next)) {
@@ -11185,7 +11295,7 @@ Only serializable value can be synced with Liveblocks.`
11185
11295
  } else if (isLiveObject(value) && isPlainObject(prev) && isPlainObject(next)) {
11186
11296
  patchLiveObject(value, prev, next);
11187
11297
  } else {
11188
- liveObject.set(key, deepLiveify(next));
11298
+ liveObject.set(key, _deepLiveify(next));
11189
11299
  }
11190
11300
  }
11191
11301
  function patchLiveObject(root, prev, next) {
@@ -11236,12 +11346,12 @@ function legacy_patchImmutableNode(state, path, update) {
11236
11346
  }
11237
11347
  const newState = Object.assign({}, state);
11238
11348
  for (const key in update.updates) {
11239
- if (_optionalChain([update, 'access', _244 => _244.updates, 'access', _245 => _245[key], 'optionalAccess', _246 => _246.type]) === "update") {
11349
+ if (_optionalChain([update, 'access', _258 => _258.updates, 'access', _259 => _259[key], 'optionalAccess', _260 => _260.type]) === "update") {
11240
11350
  const val = update.node.get(key);
11241
11351
  if (val !== void 0) {
11242
11352
  newState[key] = lsonToJson(val);
11243
11353
  }
11244
- } else if (_optionalChain([update, 'access', _247 => _247.updates, 'access', _248 => _248[key], 'optionalAccess', _249 => _249.type]) === "delete") {
11354
+ } else if (_optionalChain([update, 'access', _261 => _261.updates, 'access', _262 => _262[key], 'optionalAccess', _263 => _263.type]) === "delete") {
11245
11355
  delete newState[key];
11246
11356
  }
11247
11357
  }
@@ -11302,12 +11412,12 @@ function legacy_patchImmutableNode(state, path, update) {
11302
11412
  }
11303
11413
  const newState = Object.assign({}, state);
11304
11414
  for (const key in update.updates) {
11305
- if (_optionalChain([update, 'access', _250 => _250.updates, 'access', _251 => _251[key], 'optionalAccess', _252 => _252.type]) === "update") {
11415
+ if (_optionalChain([update, 'access', _264 => _264.updates, 'access', _265 => _265[key], 'optionalAccess', _266 => _266.type]) === "update") {
11306
11416
  const value = update.node.get(key);
11307
11417
  if (value !== void 0) {
11308
11418
  newState[key] = lsonToJson(value);
11309
11419
  }
11310
- } else if (_optionalChain([update, 'access', _253 => _253.updates, 'access', _254 => _254[key], 'optionalAccess', _255 => _255.type]) === "delete") {
11420
+ } else if (_optionalChain([update, 'access', _267 => _267.updates, 'access', _268 => _268[key], 'optionalAccess', _269 => _269.type]) === "delete") {
11311
11421
  delete newState[key];
11312
11422
  }
11313
11423
  }
@@ -11387,9 +11497,9 @@ function makePoller(callback, intervalMs, options) {
11387
11497
  const startTime = performance.now();
11388
11498
  const doc = typeof document !== "undefined" ? document : void 0;
11389
11499
  const win = typeof window !== "undefined" ? window : void 0;
11390
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _256 => _256.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11500
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _270 => _270.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11391
11501
  const context = {
11392
- inForeground: _optionalChain([doc, 'optionalAccess', _257 => _257.visibilityState]) !== "hidden",
11502
+ inForeground: _optionalChain([doc, 'optionalAccess', _271 => _271.visibilityState]) !== "hidden",
11393
11503
  lastSuccessfulPollAt: startTime,
11394
11504
  count: 0,
11395
11505
  backoff: 0
@@ -11470,11 +11580,11 @@ function makePoller(callback, intervalMs, options) {
11470
11580
  pollNowIfStale();
11471
11581
  }
11472
11582
  function onVisibilityChange() {
11473
- setInForeground(_optionalChain([doc, 'optionalAccess', _258 => _258.visibilityState]) !== "hidden");
11583
+ setInForeground(_optionalChain([doc, 'optionalAccess', _272 => _272.visibilityState]) !== "hidden");
11474
11584
  }
11475
- _optionalChain([doc, 'optionalAccess', _259 => _259.addEventListener, 'call', _260 => _260("visibilitychange", onVisibilityChange)]);
11476
- _optionalChain([win, 'optionalAccess', _261 => _261.addEventListener, 'call', _262 => _262("online", onVisibilityChange)]);
11477
- _optionalChain([win, 'optionalAccess', _263 => _263.addEventListener, 'call', _264 => _264("focus", pollNowIfStale)]);
11585
+ _optionalChain([doc, 'optionalAccess', _273 => _273.addEventListener, 'call', _274 => _274("visibilitychange", onVisibilityChange)]);
11586
+ _optionalChain([win, 'optionalAccess', _275 => _275.addEventListener, 'call', _276 => _276("online", onVisibilityChange)]);
11587
+ _optionalChain([win, 'optionalAccess', _277 => _277.addEventListener, 'call', _278 => _278("focus", pollNowIfStale)]);
11478
11588
  fsm.start();
11479
11589
  return {
11480
11590
  inc,
@@ -11486,6 +11596,90 @@ function makePoller(callback, intervalMs, options) {
11486
11596
  };
11487
11597
  }
11488
11598
 
11599
+ // src/mutations.ts
11600
+ function generateOpsFromJson(nodes, mutation, actorId = 1) {
11601
+ const capturedOps = [];
11602
+ const pool = createManagedPool("mutation-temp", {
11603
+ getCurrentConnectionId: () => actorId,
11604
+ onDispatch: (ops) => {
11605
+ capturedOps.push(...ops);
11606
+ }
11607
+ });
11608
+ const root = LiveObject._fromItems(nodes, pool);
11609
+ if (isPlainObject(mutation)) {
11610
+ applyMutationToLiveObject(root, mutation);
11611
+ } else {
11612
+ throw new Error(
11613
+ "Root mutation must be an object. Use a nested key to update specific values."
11614
+ );
11615
+ }
11616
+ return capturedOps;
11617
+ }
11618
+ function applyMutationToLiveObject(target, mutation) {
11619
+ for (const key in mutation) {
11620
+ const mutationValue = mutation[key];
11621
+ if (mutationValue === void 0) {
11622
+ continue;
11623
+ }
11624
+ const existingValue = target.get(key);
11625
+ if (isLiveNode(mutationValue)) {
11626
+ target.set(key, mutationValue);
11627
+ continue;
11628
+ }
11629
+ if (isLiveObject(existingValue) && isPlainObject(mutationValue)) {
11630
+ applyMutationToLiveObject(
11631
+ existingValue,
11632
+ mutationValue
11633
+ );
11634
+ } else if (isLiveMap(existingValue) && isPlainObject(mutationValue)) {
11635
+ applyMutationToLiveMap(existingValue, mutationValue);
11636
+ } else if (isLiveList(existingValue) && Array.isArray(mutationValue)) {
11637
+ applyMutationToLiveList(existingValue, mutationValue);
11638
+ } else if (existingValue === void 0 && isPlainObject(mutationValue)) {
11639
+ const convertedValue = _deepLiveify(mutationValue);
11640
+ target.set(key, convertedValue);
11641
+ } else {
11642
+ target.set(key, mutationValue);
11643
+ }
11644
+ }
11645
+ }
11646
+ function applyMutationToLiveMap(target, mutation) {
11647
+ for (const key in mutation) {
11648
+ const mutationValue = mutation[key];
11649
+ if (mutationValue === void 0) {
11650
+ continue;
11651
+ }
11652
+ const existingValue = target.get(key);
11653
+ if (isLiveNode(mutationValue)) {
11654
+ target.set(key, mutationValue);
11655
+ continue;
11656
+ }
11657
+ if (isLiveObject(existingValue) && isPlainObject(mutationValue)) {
11658
+ applyMutationToLiveObject(
11659
+ existingValue,
11660
+ mutationValue
11661
+ );
11662
+ } else if (isLiveMap(existingValue) && isPlainObject(mutationValue)) {
11663
+ applyMutationToLiveMap(existingValue, mutationValue);
11664
+ } else if (isLiveList(existingValue) && Array.isArray(mutationValue)) {
11665
+ applyMutationToLiveList(existingValue, mutationValue);
11666
+ } else if (existingValue === void 0 && isPlainObject(mutationValue)) {
11667
+ const convertedValue = _deepLiveify(mutationValue);
11668
+ target.set(key, convertedValue);
11669
+ } else {
11670
+ const newValue = isLiveNode(mutationValue) ? mutationValue : mutationValue;
11671
+ target.set(key, newValue);
11672
+ }
11673
+ }
11674
+ }
11675
+ function applyMutationToLiveList(target, mutation) {
11676
+ target.clear();
11677
+ for (const item of mutation) {
11678
+ const liveItem = isLiveNode(item) ? item : item;
11679
+ target.push(liveItem);
11680
+ }
11681
+ }
11682
+
11489
11683
  // src/protocol/Subscriptions.ts
11490
11684
  function getSubscriptionKey(subscription, subjectId) {
11491
11685
  if (typeof subscription === "string") {
@@ -11606,5 +11800,6 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
11606
11800
 
11607
11801
 
11608
11802
 
11609
- 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.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.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.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;
11803
+
11804
+ 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.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.generateOpsFromJson = generateOpsFromJson; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; 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.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;
11610
11805
  //# sourceMappingURL=index.cjs.map