@liveblocks/core 2.17.0-usrnotsettings3 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.17.0-usrnotsettings3";
9
+ var PKG_VERSION = "2.17.0";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -181,12 +181,6 @@ function raise(msg) {
181
181
  function entries(obj) {
182
182
  return Object.entries(obj);
183
183
  }
184
- function keys(obj) {
185
- return Object.keys(obj);
186
- }
187
- function values(obj) {
188
- return Object.values(obj);
189
- }
190
184
  function mapValues(obj, mapFn) {
191
185
  const result = {};
192
186
  for (const pair of Object.entries(obj)) {
@@ -1064,9 +1058,9 @@ function urljoin(baseUrl, path, params) {
1064
1058
  }
1065
1059
  return url2.toString();
1066
1060
  }
1067
- function url(strings, ...values2) {
1061
+ function url(strings, ...values) {
1068
1062
  return strings.reduce(
1069
- (result, str, i) => result + encodeURIComponent(values2[i - 1] ?? "") + str
1063
+ (result, str, i) => result + encodeURIComponent(values[i - 1] ?? "") + str
1070
1064
  );
1071
1065
  }
1072
1066
 
@@ -1562,6 +1556,29 @@ function createApiClient({
1562
1556
  }
1563
1557
  );
1564
1558
  }
1559
+ async function executeContextualPrompt(options) {
1560
+ const result = await httpClient.post(
1561
+ url`/v2/c/rooms/${options.roomId}/ai/contextual-prompt`,
1562
+ await authManager.getAuthValue({
1563
+ requestedScope: "room:read",
1564
+ roomId: options.roomId
1565
+ }),
1566
+ {
1567
+ prompt: options.prompt,
1568
+ context: {
1569
+ beforeSelection: options.context.beforeSelection,
1570
+ selection: options.context.selection,
1571
+ afterSelection: options.context.afterSelection
1572
+ },
1573
+ previous: options.previous
1574
+ },
1575
+ { signal: options.signal }
1576
+ );
1577
+ if (!result || result.content.length === 0) {
1578
+ throw new Error("No content returned from server");
1579
+ }
1580
+ return result.content[0].text;
1581
+ }
1565
1582
  async function listTextVersions(options) {
1566
1583
  const result = await httpClient.get(
1567
1584
  url`/v2/c/rooms/${options.roomId}/versions`,
@@ -1711,21 +1728,6 @@ function createApiClient({
1711
1728
  await authManager.getAuthValue({ requestedScope: "comments:read" })
1712
1729
  );
1713
1730
  }
1714
- async function getUserNotificationSettings(options) {
1715
- return httpClient.get(
1716
- url`/v2/c/notification-settings`,
1717
- await authManager.getAuthValue({ requestedScope: "comments:read" }),
1718
- void 0,
1719
- { signal: options?.signal }
1720
- );
1721
- }
1722
- async function updateUserNotificationSettings(settings) {
1723
- return httpClient.post(
1724
- url`/v2/c/notification-settings`,
1725
- await authManager.getAuthValue({ requestedScope: "comments:read" }),
1726
- settings
1727
- );
1728
- }
1729
1731
  async function getUserThreads_experimental(options) {
1730
1732
  let query;
1731
1733
  if (options?.query) {
@@ -1788,10 +1790,10 @@ function createApiClient({
1788
1790
  removeReaction,
1789
1791
  markThreadAsResolved,
1790
1792
  markThreadAsUnresolved,
1791
- markRoomInboxNotificationAsRead,
1792
1793
  // Room notifications
1793
- getNotificationSettings,
1794
+ markRoomInboxNotificationAsRead,
1794
1795
  updateNotificationSettings,
1796
+ getNotificationSettings,
1795
1797
  // Room text editor
1796
1798
  createTextMention,
1797
1799
  deleteTextMention,
@@ -1815,11 +1817,11 @@ function createApiClient({
1815
1817
  markInboxNotificationAsRead,
1816
1818
  deleteAllInboxNotifications,
1817
1819
  deleteInboxNotification,
1818
- getUserNotificationSettings,
1819
- updateUserNotificationSettings,
1820
1820
  // User threads
1821
1821
  getUserThreads_experimental,
1822
- getUserThreadsSince_experimental
1822
+ getUserThreadsSince_experimental,
1823
+ // AI
1824
+ executeContextualPrompt
1823
1825
  };
1824
1826
  }
1825
1827
  function getBearerTokenFromAuthValue(authValue) {
@@ -6337,15 +6339,13 @@ function defaultMessageFromContext(context) {
6337
6339
  return "Could not delete all inbox notifications";
6338
6340
  case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
6339
6341
  return "Could not update notification settings";
6340
- case "UPDATE_USER_NOTIFICATION_SETTINGS_ERROR":
6341
- return "Could not update user notification settings";
6342
6342
  default:
6343
6343
  return assertNever(context, "Unhandled case");
6344
6344
  }
6345
6345
  }
6346
6346
 
6347
6347
  // src/room.ts
6348
- var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 1024;
6348
+ var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 512;
6349
6349
  function makeIdFactory(connectionId) {
6350
6350
  let count = 0;
6351
6351
  return () => `${connectionId}:${count++}`;
@@ -6614,24 +6614,88 @@ function createRoom(options, config) {
6614
6614
  async function createTextVersion() {
6615
6615
  return httpClient.createTextVersion({ roomId });
6616
6616
  }
6617
+ async function executeContextualPrompt(options2) {
6618
+ return httpClient.executeContextualPrompt({
6619
+ roomId,
6620
+ ...options2
6621
+ });
6622
+ }
6623
+ function* chunkOps(msg) {
6624
+ const { ops, ...rest } = msg;
6625
+ if (ops.length < 2) {
6626
+ throw new Error("Cannot split ops into smaller chunks");
6627
+ }
6628
+ const mid = Math.floor(ops.length / 2);
6629
+ const firstHalf = ops.slice(0, mid);
6630
+ const secondHalf = ops.slice(mid);
6631
+ for (const halfOps of [firstHalf, secondHalf]) {
6632
+ const half = { ops: halfOps, ...rest };
6633
+ const text = JSON.stringify([half]);
6634
+ if (!isTooBigForWebSocket(text)) {
6635
+ yield text;
6636
+ } else {
6637
+ yield* chunkOps(half);
6638
+ }
6639
+ }
6640
+ }
6641
+ function* chunkMessages(messages) {
6642
+ if (messages.length < 2) {
6643
+ if (messages[0].type === 201 /* UPDATE_STORAGE */) {
6644
+ yield* chunkOps(messages[0]);
6645
+ return;
6646
+ } else {
6647
+ throw new Error(
6648
+ "Cannot split into chunks smaller than the allowed message size"
6649
+ );
6650
+ }
6651
+ }
6652
+ const mid = Math.floor(messages.length / 2);
6653
+ const firstHalf = messages.slice(0, mid);
6654
+ const secondHalf = messages.slice(mid);
6655
+ for (const half of [firstHalf, secondHalf]) {
6656
+ const text = JSON.stringify(half);
6657
+ if (!isTooBigForWebSocket(text)) {
6658
+ yield text;
6659
+ } else {
6660
+ yield* chunkMessages(half);
6661
+ }
6662
+ }
6663
+ }
6664
+ function isTooBigForWebSocket(text) {
6665
+ if (text.length * 4 < MAX_SOCKET_MESSAGE_SIZE) {
6666
+ return false;
6667
+ }
6668
+ return new TextEncoder().encode(text).length >= MAX_SOCKET_MESSAGE_SIZE;
6669
+ }
6617
6670
  function sendMessages(messages) {
6618
- const serializedPayload = JSON.stringify(messages);
6619
- const nonce = context.dynamicSessionInfoSig.get()?.nonce;
6620
- if (config.unstable_fallbackToHTTP && nonce) {
6621
- const size = new TextEncoder().encode(serializedPayload).length;
6622
- if (size > MAX_SOCKET_MESSAGE_SIZE) {
6671
+ const strategy = config.largeMessageStrategy ?? "default";
6672
+ const text = JSON.stringify(messages);
6673
+ if (!isTooBigForWebSocket(text)) {
6674
+ return managedSocket.send(text);
6675
+ }
6676
+ switch (strategy) {
6677
+ case "default": {
6678
+ error2("Message is too large for websockets, not sending. Configure largeMessageStrategy option to deal with this.");
6679
+ return;
6680
+ }
6681
+ case "split": {
6682
+ warn("Message is too large for websockets, splitting into smaller chunks");
6683
+ for (const chunk2 of chunkMessages(messages)) {
6684
+ managedSocket.send(chunk2);
6685
+ }
6686
+ return;
6687
+ }
6688
+ case "experimental-fallback-to-http": {
6689
+ warn("Message is too large for websockets, so sending over HTTP instead");
6690
+ const nonce = context.dynamicSessionInfoSig.get()?.nonce ?? raise("Session is not authorized to send message over HTTP");
6623
6691
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
6624
6692
  if (!resp.ok && resp.status === 403) {
6625
6693
  managedSocket.reconnect();
6626
6694
  }
6627
6695
  });
6628
- warn(
6629
- "Message was too large for websockets and sent over HTTP instead"
6630
- );
6631
6696
  return;
6632
6697
  }
6633
6698
  }
6634
- managedSocket.send(serializedPayload);
6635
6699
  }
6636
6700
  const self = DerivedSignal.from(
6637
6701
  context.staticSessionInfoSig,
@@ -7598,6 +7662,8 @@ ${Array.from(traces).join("\n\n")}`
7598
7662
  getTextVersion,
7599
7663
  // create a version
7600
7664
  createTextVersion,
7665
+ // execute a contextual prompt
7666
+ executeContextualPrompt,
7601
7667
  // Support for the Liveblocks browser extension
7602
7668
  getSelf_forDevTools: () => selfAsTreeNode.get(),
7603
7669
  getOthers_forDevTools: () => others_forDevTools.get(),
@@ -7902,7 +7968,7 @@ function createClient(options) {
7902
7968
  enableDebugLogging: clientOptions.enableDebugLogging,
7903
7969
  baseUrl,
7904
7970
  errorEventSource: liveblocksErrorSource,
7905
- unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
7971
+ largeMessageStrategy: clientOptions.largeMessageStrategy ?? (clientOptions.unstable_fallbackToHTTP ? "experimental-fallback-to-http" : void 0),
7906
7972
  unstable_streamData: !!clientOptions.unstable_streamData,
7907
7973
  roomHttpClient: httpClient,
7908
7974
  createSyncSource
@@ -8036,9 +8102,6 @@ function createClient(options) {
8036
8102
  markInboxNotificationAsRead: httpClient.markInboxNotificationAsRead,
8037
8103
  deleteAllInboxNotifications: httpClient.deleteAllInboxNotifications,
8038
8104
  deleteInboxNotification: httpClient.deleteInboxNotification,
8039
- // Public channel notification settings API
8040
- getNotificationSettings: httpClient.getUserNotificationSettings,
8041
- updateNotificationSettings: httpClient.updateUserNotificationSettings,
8042
8105
  // Advanced resolvers APIs
8043
8106
  resolvers: {
8044
8107
  invalidateUsers: invalidateResolvedUsers,
@@ -8235,9 +8298,9 @@ function escapeHtml(value) {
8235
8298
  var HtmlSafeString = class {
8236
8299
  #strings;
8237
8300
  #values;
8238
- constructor(strings, values2) {
8301
+ constructor(strings, values) {
8239
8302
  this.#strings = strings;
8240
- this.#values = values2;
8303
+ this.#values = values;
8241
8304
  }
8242
8305
  toString() {
8243
8306
  return this.#strings.reduce((result, str, i) => {
@@ -8245,8 +8308,8 @@ var HtmlSafeString = class {
8245
8308
  });
8246
8309
  }
8247
8310
  };
8248
- function html(strings, ...values2) {
8249
- return new HtmlSafeString(strings, values2);
8311
+ function html(strings, ...values) {
8312
+ return new HtmlSafeString(strings, values);
8250
8313
  }
8251
8314
  var markdownEscapables = {
8252
8315
  _: "\\_",
@@ -8291,9 +8354,9 @@ function escapeMarkdown(value) {
8291
8354
  var MarkdownSafeString = class {
8292
8355
  #strings;
8293
8356
  #values;
8294
- constructor(strings, values2) {
8357
+ constructor(strings, values) {
8295
8358
  this.#strings = strings;
8296
- this.#values = values2;
8359
+ this.#values = values;
8297
8360
  }
8298
8361
  toString() {
8299
8362
  return this.#strings.reduce((result, str, i) => {
@@ -8301,8 +8364,8 @@ var MarkdownSafeString = class {
8301
8364
  });
8302
8365
  }
8303
8366
  };
8304
- function markdown(strings, ...values2) {
8305
- return new MarkdownSafeString(strings, values2);
8367
+ function markdown(strings, ...values) {
8368
+ return new MarkdownSafeString(strings, values);
8306
8369
  }
8307
8370
  function toAbsoluteUrl(url2) {
8308
8371
  if (url2.startsWith("http://") || url2.startsWith("https://")) {
@@ -9028,11 +9091,6 @@ var SortedList = class _SortedList {
9028
9091
  }
9029
9092
  };
9030
9093
 
9031
- // src/protocol/UserNotificationSettings.ts
9032
- function isNotificationChannelEnabled(settings) {
9033
- return values(settings).every((enabled) => enabled === true);
9034
- }
9035
-
9036
9094
  // src/types/Others.ts
9037
9095
  var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
9038
9096
  TextEditorType2["Lexical"] = "lexical";
@@ -9088,7 +9146,6 @@ export {
9088
9146
  deprecate,
9089
9147
  deprecateIf,
9090
9148
  detectDupes,
9091
- entries,
9092
9149
  errorIf,
9093
9150
  freeze,
9094
9151
  generateCommentUrl,
@@ -9103,12 +9160,10 @@ export {
9103
9160
  isJsonObject,
9104
9161
  isJsonScalar,
9105
9162
  isLiveNode,
9106
- isNotificationChannelEnabled,
9107
9163
  isPlainObject,
9108
9164
  isRootCrdt,
9109
9165
  isStartsWithOperator,
9110
9166
  kInternal,
9111
- keys,
9112
9167
  legacy_patchImmutableObject,
9113
9168
  lsonToJson,
9114
9169
  makeEventSource,