@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 +234 -160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -11
- package/dist/index.d.ts +59 -11
- package/dist/index.js +110 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
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.
|
|
9
|
+
var PKG_VERSION = "3.8.1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
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
|
|
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 (options?.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: options?.signal }
|
|
2219
2257
|
);
|
|
2220
2258
|
return count;
|
|
2221
2259
|
}
|
|
@@ -2388,7 +2426,7 @@ function createApiClient({
|
|
|
2388
2426
|
getChatAttachmentUrl,
|
|
2389
2427
|
// Room storage
|
|
2390
2428
|
streamStorage,
|
|
2391
|
-
|
|
2429
|
+
sendMessagesOverHTTP,
|
|
2392
2430
|
// Notifications
|
|
2393
2431
|
getInboxNotifications,
|
|
2394
2432
|
getInboxNotificationsSince,
|
|
@@ -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(chatId ?? kWILDCARD);
|
|
4265
|
+
}
|
|
4266
|
+
function getKnowledgeForChat(chatId) {
|
|
4267
|
+
const globalKnowledge = knowledgeByChatId.getOrCreate(kWILDCARD).get();
|
|
4268
|
+
const scopedKnowledge = knowledgeByChatId.get(chatId)?.get() ?? [];
|
|
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
|
}
|
|
@@ -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
|
-
|
|
4688
|
+
knowledgeStore
|
|
4633
4689
|
};
|
|
4634
4690
|
const DELTA_THROTTLE = 25;
|
|
4635
4691
|
let pendingDeltas = [];
|
|
@@ -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.
|
|
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",
|
|
@@ -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
|
|
4965
|
+
const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
|
|
4919
4966
|
const requestKnowledge = options?.knowledge || [];
|
|
4920
|
-
const combinedKnowledge = [...
|
|
4967
|
+
const combinedKnowledge = [...knowledge, ...requestKnowledge];
|
|
4921
4968
|
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4922
4969
|
messagesStore.markMine(targetMessageId);
|
|
4923
4970
|
const resp = await sendClientMsgWithResponse({
|
|
@@ -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
|
-
|
|
4951
|
-
|
|
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, key ?? nanoid(), data);
|
|
5007
|
+
},
|
|
4952
5008
|
registerTool: context.toolsStore.registerTool
|
|
4953
5009
|
},
|
|
4954
5010
|
kInternal,
|
|
@@ -7084,7 +7140,12 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7084
7140
|
const storageUpdate = {
|
|
7085
7141
|
node: this,
|
|
7086
7142
|
type: "LiveMap",
|
|
7087
|
-
updates: {
|
|
7143
|
+
updates: {
|
|
7144
|
+
[parentKey]: {
|
|
7145
|
+
type: "delete",
|
|
7146
|
+
deletedItem: liveNodeToLson(child)
|
|
7147
|
+
}
|
|
7148
|
+
}
|
|
7088
7149
|
};
|
|
7089
7150
|
return { modified: storageUpdate, reverse };
|
|
7090
7151
|
}
|
|
@@ -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: {
|
|
7241
|
+
updates: {
|
|
7242
|
+
[key]: {
|
|
7243
|
+
type: "delete",
|
|
7244
|
+
deletedItem: liveNodeToLson(item)
|
|
7245
|
+
}
|
|
7246
|
+
}
|
|
7181
7247
|
});
|
|
7182
7248
|
this._pool.dispatch(
|
|
7183
7249
|
[
|
|
@@ -7581,13 +7647,13 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7581
7647
|
}
|
|
7582
7648
|
#applyDeleteObjectKey(op, isLocal) {
|
|
7583
7649
|
const key = op.key;
|
|
7584
|
-
|
|
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 = class _LiveObject extends AbstractCrdt {
|
|
|
7608
7674
|
modified: {
|
|
7609
7675
|
node: this,
|
|
7610
7676
|
type: "LiveObject",
|
|
7611
|
-
updates: {
|
|
7677
|
+
updates: {
|
|
7678
|
+
[op.key]: { type: "delete", deletedItem: oldValue }
|
|
7679
|
+
}
|
|
7612
7680
|
},
|
|
7613
7681
|
reverse
|
|
7614
7682
|
};
|
|
@@ -7673,7 +7741,9 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7673
7741
|
storageUpdates.set(this._id, {
|
|
7674
7742
|
node: this,
|
|
7675
7743
|
type: "LiveObject",
|
|
7676
|
-
updates: {
|
|
7744
|
+
updates: {
|
|
7745
|
+
[key]: { type: "delete", deletedItem: oldValue }
|
|
7746
|
+
}
|
|
7677
7747
|
});
|
|
7678
7748
|
this._pool.dispatch(
|
|
7679
7749
|
[
|
|
@@ -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
8833
|
const nonce = context.dynamicSessionInfoSig.get()?.nonce ?? raise("Session is not authorized to send message over HTTP");
|
|
8759
|
-
void httpClient.
|
|
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
|
}
|
|
@@ -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
|
},
|
|
@@ -11231,6 +11304,7 @@ export {
|
|
|
11231
11304
|
isJsonScalar,
|
|
11232
11305
|
isLiveNode,
|
|
11233
11306
|
isNotificationChannelEnabled,
|
|
11307
|
+
isNumberOperator,
|
|
11234
11308
|
isPlainObject,
|
|
11235
11309
|
isRootCrdt,
|
|
11236
11310
|
isStartsWithOperator,
|