@liveblocks/core 2.17.0-usrnotsettings2 → 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.d.mts +45 -92
- package/dist/index.d.ts +45 -92
- package/dist/index.js +211 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
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, ...
|
|
1061
|
+
function url(strings, ...values) {
|
|
1068
1062
|
return strings.reduce(
|
|
1069
|
-
(result, str, i) => result + encodeURIComponent(
|
|
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
|
-
|
|
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) {
|
|
@@ -6343,7 +6345,7 @@ function defaultMessageFromContext(context) {
|
|
|
6343
6345
|
}
|
|
6344
6346
|
|
|
6345
6347
|
// src/room.ts
|
|
6346
|
-
var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 -
|
|
6348
|
+
var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 512;
|
|
6347
6349
|
function makeIdFactory(connectionId) {
|
|
6348
6350
|
let count = 0;
|
|
6349
6351
|
return () => `${connectionId}:${count++}`;
|
|
@@ -6612,24 +6614,88 @@ function createRoom(options, config) {
|
|
|
6612
6614
|
async function createTextVersion() {
|
|
6613
6615
|
return httpClient.createTextVersion({ roomId });
|
|
6614
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
|
+
}
|
|
6615
6670
|
function sendMessages(messages) {
|
|
6616
|
-
const
|
|
6617
|
-
const
|
|
6618
|
-
if (
|
|
6619
|
-
|
|
6620
|
-
|
|
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");
|
|
6621
6691
|
void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
|
|
6622
6692
|
if (!resp.ok && resp.status === 403) {
|
|
6623
6693
|
managedSocket.reconnect();
|
|
6624
6694
|
}
|
|
6625
6695
|
});
|
|
6626
|
-
warn(
|
|
6627
|
-
"Message was too large for websockets and sent over HTTP instead"
|
|
6628
|
-
);
|
|
6629
6696
|
return;
|
|
6630
6697
|
}
|
|
6631
6698
|
}
|
|
6632
|
-
managedSocket.send(serializedPayload);
|
|
6633
6699
|
}
|
|
6634
6700
|
const self = DerivedSignal.from(
|
|
6635
6701
|
context.staticSessionInfoSig,
|
|
@@ -7596,6 +7662,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7596
7662
|
getTextVersion,
|
|
7597
7663
|
// create a version
|
|
7598
7664
|
createTextVersion,
|
|
7665
|
+
// execute a contextual prompt
|
|
7666
|
+
executeContextualPrompt,
|
|
7599
7667
|
// Support for the Liveblocks browser extension
|
|
7600
7668
|
getSelf_forDevTools: () => selfAsTreeNode.get(),
|
|
7601
7669
|
getOthers_forDevTools: () => others_forDevTools.get(),
|
|
@@ -7900,7 +7968,7 @@ function createClient(options) {
|
|
|
7900
7968
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
7901
7969
|
baseUrl,
|
|
7902
7970
|
errorEventSource: liveblocksErrorSource,
|
|
7903
|
-
|
|
7971
|
+
largeMessageStrategy: clientOptions.largeMessageStrategy ?? (clientOptions.unstable_fallbackToHTTP ? "experimental-fallback-to-http" : void 0),
|
|
7904
7972
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
7905
7973
|
roomHttpClient: httpClient,
|
|
7906
7974
|
createSyncSource
|
|
@@ -8034,9 +8102,6 @@ function createClient(options) {
|
|
|
8034
8102
|
markInboxNotificationAsRead: httpClient.markInboxNotificationAsRead,
|
|
8035
8103
|
deleteAllInboxNotifications: httpClient.deleteAllInboxNotifications,
|
|
8036
8104
|
deleteInboxNotification: httpClient.deleteInboxNotification,
|
|
8037
|
-
// Public channel notification settings API
|
|
8038
|
-
getNotificationSettings: httpClient.getUserNotificationSettings,
|
|
8039
|
-
updateNotificationSettings: httpClient.updateUserNotificationSettings,
|
|
8040
8105
|
// Advanced resolvers APIs
|
|
8041
8106
|
resolvers: {
|
|
8042
8107
|
invalidateUsers: invalidateResolvedUsers,
|
|
@@ -8233,9 +8298,9 @@ function escapeHtml(value) {
|
|
|
8233
8298
|
var HtmlSafeString = class {
|
|
8234
8299
|
#strings;
|
|
8235
8300
|
#values;
|
|
8236
|
-
constructor(strings,
|
|
8301
|
+
constructor(strings, values) {
|
|
8237
8302
|
this.#strings = strings;
|
|
8238
|
-
this.#values =
|
|
8303
|
+
this.#values = values;
|
|
8239
8304
|
}
|
|
8240
8305
|
toString() {
|
|
8241
8306
|
return this.#strings.reduce((result, str, i) => {
|
|
@@ -8243,8 +8308,8 @@ var HtmlSafeString = class {
|
|
|
8243
8308
|
});
|
|
8244
8309
|
}
|
|
8245
8310
|
};
|
|
8246
|
-
function html(strings, ...
|
|
8247
|
-
return new HtmlSafeString(strings,
|
|
8311
|
+
function html(strings, ...values) {
|
|
8312
|
+
return new HtmlSafeString(strings, values);
|
|
8248
8313
|
}
|
|
8249
8314
|
var markdownEscapables = {
|
|
8250
8315
|
_: "\\_",
|
|
@@ -8289,9 +8354,9 @@ function escapeMarkdown(value) {
|
|
|
8289
8354
|
var MarkdownSafeString = class {
|
|
8290
8355
|
#strings;
|
|
8291
8356
|
#values;
|
|
8292
|
-
constructor(strings,
|
|
8357
|
+
constructor(strings, values) {
|
|
8293
8358
|
this.#strings = strings;
|
|
8294
|
-
this.#values =
|
|
8359
|
+
this.#values = values;
|
|
8295
8360
|
}
|
|
8296
8361
|
toString() {
|
|
8297
8362
|
return this.#strings.reduce((result, str, i) => {
|
|
@@ -8299,8 +8364,8 @@ var MarkdownSafeString = class {
|
|
|
8299
8364
|
});
|
|
8300
8365
|
}
|
|
8301
8366
|
};
|
|
8302
|
-
function markdown(strings, ...
|
|
8303
|
-
return new MarkdownSafeString(strings,
|
|
8367
|
+
function markdown(strings, ...values) {
|
|
8368
|
+
return new MarkdownSafeString(strings, values);
|
|
8304
8369
|
}
|
|
8305
8370
|
function toAbsoluteUrl(url2) {
|
|
8306
8371
|
if (url2.startsWith("http://") || url2.startsWith("https://")) {
|
|
@@ -9026,11 +9091,6 @@ var SortedList = class _SortedList {
|
|
|
9026
9091
|
}
|
|
9027
9092
|
};
|
|
9028
9093
|
|
|
9029
|
-
// src/protocol/UserNotificationSettings.ts
|
|
9030
|
-
function isNotificationChannelEnabled(settings) {
|
|
9031
|
-
return values(settings).every((enabled) => enabled === true);
|
|
9032
|
-
}
|
|
9033
|
-
|
|
9034
9094
|
// src/types/Others.ts
|
|
9035
9095
|
var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
|
|
9036
9096
|
TextEditorType2["Lexical"] = "lexical";
|
|
@@ -9086,7 +9146,6 @@ export {
|
|
|
9086
9146
|
deprecate,
|
|
9087
9147
|
deprecateIf,
|
|
9088
9148
|
detectDupes,
|
|
9089
|
-
entries,
|
|
9090
9149
|
errorIf,
|
|
9091
9150
|
freeze,
|
|
9092
9151
|
generateCommentUrl,
|
|
@@ -9101,12 +9160,10 @@ export {
|
|
|
9101
9160
|
isJsonObject,
|
|
9102
9161
|
isJsonScalar,
|
|
9103
9162
|
isLiveNode,
|
|
9104
|
-
isNotificationChannelEnabled,
|
|
9105
9163
|
isPlainObject,
|
|
9106
9164
|
isRootCrdt,
|
|
9107
9165
|
isStartsWithOperator,
|
|
9108
9166
|
kInternal,
|
|
9109
|
-
keys,
|
|
9110
9167
|
legacy_patchImmutableObject,
|
|
9111
9168
|
lsonToJson,
|
|
9112
9169
|
makeEventSource,
|