@liveblocks/core 2.17.0-usrnotsettings3 → 2.18.0-yjsfactory
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 +51 -7
- package/dist/index.d.ts +51 -7
- package/dist/index.js +115 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -16
- 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.
|
|
9
|
+
var PKG_VERSION = "2.18.0-yjsfactory";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -1562,6 +1562,29 @@ function createApiClient({
|
|
|
1562
1562
|
}
|
|
1563
1563
|
);
|
|
1564
1564
|
}
|
|
1565
|
+
async function executeContextualPrompt(options) {
|
|
1566
|
+
const result = await httpClient.post(
|
|
1567
|
+
url`/v2/c/rooms/${options.roomId}/ai/contextual-prompt`,
|
|
1568
|
+
await authManager.getAuthValue({
|
|
1569
|
+
requestedScope: "room:read",
|
|
1570
|
+
roomId: options.roomId
|
|
1571
|
+
}),
|
|
1572
|
+
{
|
|
1573
|
+
prompt: options.prompt,
|
|
1574
|
+
context: {
|
|
1575
|
+
beforeSelection: options.context.beforeSelection,
|
|
1576
|
+
selection: options.context.selection,
|
|
1577
|
+
afterSelection: options.context.afterSelection
|
|
1578
|
+
},
|
|
1579
|
+
previous: options.previous
|
|
1580
|
+
},
|
|
1581
|
+
{ signal: options.signal }
|
|
1582
|
+
);
|
|
1583
|
+
if (!result || result.content.length === 0) {
|
|
1584
|
+
throw new Error("No content returned from server");
|
|
1585
|
+
}
|
|
1586
|
+
return result.content[0].text;
|
|
1587
|
+
}
|
|
1565
1588
|
async function listTextVersions(options) {
|
|
1566
1589
|
const result = await httpClient.get(
|
|
1567
1590
|
url`/v2/c/rooms/${options.roomId}/versions`,
|
|
@@ -1819,7 +1842,9 @@ function createApiClient({
|
|
|
1819
1842
|
updateUserNotificationSettings,
|
|
1820
1843
|
// User threads
|
|
1821
1844
|
getUserThreads_experimental,
|
|
1822
|
-
getUserThreadsSince_experimental
|
|
1845
|
+
getUserThreadsSince_experimental,
|
|
1846
|
+
// AI
|
|
1847
|
+
executeContextualPrompt
|
|
1823
1848
|
};
|
|
1824
1849
|
}
|
|
1825
1850
|
function getBearerTokenFromAuthValue(authValue) {
|
|
@@ -6345,7 +6370,7 @@ function defaultMessageFromContext(context) {
|
|
|
6345
6370
|
}
|
|
6346
6371
|
|
|
6347
6372
|
// src/room.ts
|
|
6348
|
-
var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 -
|
|
6373
|
+
var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 512;
|
|
6349
6374
|
function makeIdFactory(connectionId) {
|
|
6350
6375
|
let count = 0;
|
|
6351
6376
|
return () => `${connectionId}:${count++}`;
|
|
@@ -6586,7 +6611,8 @@ function createRoom(options, config) {
|
|
|
6586
6611
|
storageDidLoad: makeEventSource(),
|
|
6587
6612
|
storageStatus: makeEventSource(),
|
|
6588
6613
|
ydoc: makeEventSource(),
|
|
6589
|
-
comments: makeEventSource()
|
|
6614
|
+
comments: makeEventSource(),
|
|
6615
|
+
roomWillDestroy: makeEventSource()
|
|
6590
6616
|
};
|
|
6591
6617
|
const roomId = config.roomId;
|
|
6592
6618
|
async function createTextMention(userId, mentionId) {
|
|
@@ -6614,24 +6640,88 @@ function createRoom(options, config) {
|
|
|
6614
6640
|
async function createTextVersion() {
|
|
6615
6641
|
return httpClient.createTextVersion({ roomId });
|
|
6616
6642
|
}
|
|
6643
|
+
async function executeContextualPrompt(options2) {
|
|
6644
|
+
return httpClient.executeContextualPrompt({
|
|
6645
|
+
roomId,
|
|
6646
|
+
...options2
|
|
6647
|
+
});
|
|
6648
|
+
}
|
|
6649
|
+
function* chunkOps(msg) {
|
|
6650
|
+
const { ops, ...rest } = msg;
|
|
6651
|
+
if (ops.length < 2) {
|
|
6652
|
+
throw new Error("Cannot split ops into smaller chunks");
|
|
6653
|
+
}
|
|
6654
|
+
const mid = Math.floor(ops.length / 2);
|
|
6655
|
+
const firstHalf = ops.slice(0, mid);
|
|
6656
|
+
const secondHalf = ops.slice(mid);
|
|
6657
|
+
for (const halfOps of [firstHalf, secondHalf]) {
|
|
6658
|
+
const half = { ops: halfOps, ...rest };
|
|
6659
|
+
const text = JSON.stringify([half]);
|
|
6660
|
+
if (!isTooBigForWebSocket(text)) {
|
|
6661
|
+
yield text;
|
|
6662
|
+
} else {
|
|
6663
|
+
yield* chunkOps(half);
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
}
|
|
6667
|
+
function* chunkMessages(messages) {
|
|
6668
|
+
if (messages.length < 2) {
|
|
6669
|
+
if (messages[0].type === 201 /* UPDATE_STORAGE */) {
|
|
6670
|
+
yield* chunkOps(messages[0]);
|
|
6671
|
+
return;
|
|
6672
|
+
} else {
|
|
6673
|
+
throw new Error(
|
|
6674
|
+
"Cannot split into chunks smaller than the allowed message size"
|
|
6675
|
+
);
|
|
6676
|
+
}
|
|
6677
|
+
}
|
|
6678
|
+
const mid = Math.floor(messages.length / 2);
|
|
6679
|
+
const firstHalf = messages.slice(0, mid);
|
|
6680
|
+
const secondHalf = messages.slice(mid);
|
|
6681
|
+
for (const half of [firstHalf, secondHalf]) {
|
|
6682
|
+
const text = JSON.stringify(half);
|
|
6683
|
+
if (!isTooBigForWebSocket(text)) {
|
|
6684
|
+
yield text;
|
|
6685
|
+
} else {
|
|
6686
|
+
yield* chunkMessages(half);
|
|
6687
|
+
}
|
|
6688
|
+
}
|
|
6689
|
+
}
|
|
6690
|
+
function isTooBigForWebSocket(text) {
|
|
6691
|
+
if (text.length * 4 < MAX_SOCKET_MESSAGE_SIZE) {
|
|
6692
|
+
return false;
|
|
6693
|
+
}
|
|
6694
|
+
return new TextEncoder().encode(text).length >= MAX_SOCKET_MESSAGE_SIZE;
|
|
6695
|
+
}
|
|
6617
6696
|
function sendMessages(messages) {
|
|
6618
|
-
const
|
|
6619
|
-
const
|
|
6620
|
-
if (
|
|
6621
|
-
|
|
6622
|
-
|
|
6697
|
+
const strategy = config.largeMessageStrategy ?? "default";
|
|
6698
|
+
const text = JSON.stringify(messages);
|
|
6699
|
+
if (!isTooBigForWebSocket(text)) {
|
|
6700
|
+
return managedSocket.send(text);
|
|
6701
|
+
}
|
|
6702
|
+
switch (strategy) {
|
|
6703
|
+
case "default": {
|
|
6704
|
+
error2("Message is too large for websockets, not sending. Configure largeMessageStrategy option to deal with this.");
|
|
6705
|
+
return;
|
|
6706
|
+
}
|
|
6707
|
+
case "split": {
|
|
6708
|
+
warn("Message is too large for websockets, splitting into smaller chunks");
|
|
6709
|
+
for (const chunk2 of chunkMessages(messages)) {
|
|
6710
|
+
managedSocket.send(chunk2);
|
|
6711
|
+
}
|
|
6712
|
+
return;
|
|
6713
|
+
}
|
|
6714
|
+
case "experimental-fallback-to-http": {
|
|
6715
|
+
warn("Message is too large for websockets, so sending over HTTP instead");
|
|
6716
|
+
const nonce = context.dynamicSessionInfoSig.get()?.nonce ?? raise("Session is not authorized to send message over HTTP");
|
|
6623
6717
|
void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
|
|
6624
6718
|
if (!resp.ok && resp.status === 403) {
|
|
6625
6719
|
managedSocket.reconnect();
|
|
6626
6720
|
}
|
|
6627
6721
|
});
|
|
6628
|
-
warn(
|
|
6629
|
-
"Message was too large for websockets and sent over HTTP instead"
|
|
6630
|
-
);
|
|
6631
6722
|
return;
|
|
6632
6723
|
}
|
|
6633
6724
|
}
|
|
6634
|
-
managedSocket.send(serializedPayload);
|
|
6635
6725
|
}
|
|
6636
6726
|
const self = DerivedSignal.from(
|
|
6637
6727
|
context.staticSessionInfoSig,
|
|
@@ -7427,7 +7517,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7427
7517
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
7428
7518
|
storageStatus: eventHub.storageStatus.observable,
|
|
7429
7519
|
ydoc: eventHub.ydoc.observable,
|
|
7430
|
-
comments: eventHub.comments.observable
|
|
7520
|
+
comments: eventHub.comments.observable,
|
|
7521
|
+
roomWillDestroy: eventHub.roomWillDestroy.observable
|
|
7431
7522
|
};
|
|
7432
7523
|
async function getThreadsSince(options2) {
|
|
7433
7524
|
return httpClient.getThreadsSince({
|
|
@@ -7598,6 +7689,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7598
7689
|
getTextVersion,
|
|
7599
7690
|
// create a version
|
|
7600
7691
|
createTextVersion,
|
|
7692
|
+
// execute a contextual prompt
|
|
7693
|
+
executeContextualPrompt,
|
|
7601
7694
|
// Support for the Liveblocks browser extension
|
|
7602
7695
|
getSelf_forDevTools: () => selfAsTreeNode.get(),
|
|
7603
7696
|
getOthers_forDevTools: () => others_forDevTools.get(),
|
|
@@ -7619,11 +7712,17 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7619
7712
|
reconnect: () => managedSocket.reconnect(),
|
|
7620
7713
|
disconnect: () => managedSocket.disconnect(),
|
|
7621
7714
|
destroy: () => {
|
|
7622
|
-
|
|
7715
|
+
const { roomWillDestroy, ...eventsExceptDestroy } = eventHub;
|
|
7716
|
+
for (const source of Object.values(eventsExceptDestroy)) {
|
|
7717
|
+
source[Symbol.dispose]();
|
|
7718
|
+
}
|
|
7719
|
+
eventHub.roomWillDestroy.notify();
|
|
7623
7720
|
context.yjsProvider?.off("status", yjsStatusDidChange);
|
|
7721
|
+
syncSourceForStorage.destroy();
|
|
7624
7722
|
syncSourceForYjs.destroy();
|
|
7625
7723
|
uninstallBgTabSpy();
|
|
7626
7724
|
managedSocket.destroy();
|
|
7725
|
+
roomWillDestroy[Symbol.dispose]();
|
|
7627
7726
|
},
|
|
7628
7727
|
// Presence
|
|
7629
7728
|
updatePresence,
|
|
@@ -7902,7 +8001,7 @@ function createClient(options) {
|
|
|
7902
8001
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
7903
8002
|
baseUrl,
|
|
7904
8003
|
errorEventSource: liveblocksErrorSource,
|
|
7905
|
-
|
|
8004
|
+
largeMessageStrategy: clientOptions.largeMessageStrategy ?? (clientOptions.unstable_fallbackToHTTP ? "experimental-fallback-to-http" : void 0),
|
|
7906
8005
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
7907
8006
|
roomHttpClient: httpClient,
|
|
7908
8007
|
createSyncSource
|