@liveblocks/core 2.25.0-aiprivatebeta5 → 2.25.0-aiprivatebeta7
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 +154 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -53
- package/dist/index.d.ts +58 -53
- package/dist/index.js +69 -80
- 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 = "2.25.0-
|
|
9
|
+
var PKG_VERSION = "2.25.0-aiprivatebeta7";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3781,7 +3781,8 @@ function createStore_forChatMessages() {
|
|
|
3781
3781
|
role,
|
|
3782
3782
|
parentId,
|
|
3783
3783
|
createdAt,
|
|
3784
|
-
content
|
|
3784
|
+
content,
|
|
3785
|
+
_optimistic: true
|
|
3785
3786
|
});
|
|
3786
3787
|
} else {
|
|
3787
3788
|
upsert({
|
|
@@ -3791,7 +3792,8 @@ function createStore_forChatMessages() {
|
|
|
3791
3792
|
parentId,
|
|
3792
3793
|
createdAt,
|
|
3793
3794
|
status: "pending",
|
|
3794
|
-
contentSoFar: []
|
|
3795
|
+
contentSoFar: [],
|
|
3796
|
+
_optimistic: true
|
|
3795
3797
|
});
|
|
3796
3798
|
}
|
|
3797
3799
|
return id;
|
|
@@ -3846,7 +3848,7 @@ function createStore_forChatMessages() {
|
|
|
3846
3848
|
function* iterPendingMessages() {
|
|
3847
3849
|
for (const chatMsgs\u03A3 of messagePoolByChatId\u03A3.values()) {
|
|
3848
3850
|
for (const m of chatMsgs\u03A3.get()) {
|
|
3849
|
-
if (m.role === "assistant" && m.status === "pending") {
|
|
3851
|
+
if (m.role === "assistant" && m.status === "pending" && !m._optimistic) {
|
|
3850
3852
|
yield m;
|
|
3851
3853
|
}
|
|
3852
3854
|
}
|
|
@@ -3854,7 +3856,16 @@ function createStore_forChatMessages() {
|
|
|
3854
3856
|
}
|
|
3855
3857
|
function failAllPending() {
|
|
3856
3858
|
batch(() => {
|
|
3857
|
-
pendingMessages\u03A3.mutate((lut) =>
|
|
3859
|
+
pendingMessages\u03A3.mutate((lut) => {
|
|
3860
|
+
let deleted = false;
|
|
3861
|
+
for (const [k, v] of lut) {
|
|
3862
|
+
if (!v._optimistic) {
|
|
3863
|
+
lut.delete(k);
|
|
3864
|
+
deleted = true;
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
return deleted;
|
|
3868
|
+
});
|
|
3858
3869
|
upsertMany(
|
|
3859
3870
|
Array.from(iterPendingMessages()).map(
|
|
3860
3871
|
(message) => ({
|
|
@@ -3988,7 +3999,7 @@ function createStore_forUserAiChats() {
|
|
|
3988
3999
|
SortedList.with((x, y) => y.createdAt < x.createdAt)
|
|
3989
4000
|
);
|
|
3990
4001
|
const chats\u03A3 = DerivedSignal.from(
|
|
3991
|
-
() => Array.from(mutable\u03A3.get()).filter((c) => !c.
|
|
4002
|
+
() => Array.from(mutable\u03A3.get()).filter((c) => !c.deletedAt)
|
|
3992
4003
|
);
|
|
3993
4004
|
function upsertMany(chats) {
|
|
3994
4005
|
mutable\u03A3.mutate((list) => {
|
|
@@ -4030,7 +4041,7 @@ function createAi(config) {
|
|
|
4030
4041
|
chatsStore,
|
|
4031
4042
|
messagesStore,
|
|
4032
4043
|
toolsStore,
|
|
4033
|
-
|
|
4044
|
+
knowledgeByChatId: /* @__PURE__ */ new Map()
|
|
4034
4045
|
};
|
|
4035
4046
|
let lastTokenKey;
|
|
4036
4047
|
function onStatusDidChange(_newStatus) {
|
|
@@ -4132,7 +4143,7 @@ function createAi(config) {
|
|
|
4132
4143
|
case "get-chats":
|
|
4133
4144
|
context.chatsStore.upsertMany(msg.chats);
|
|
4134
4145
|
break;
|
|
4135
|
-
case "create-chat":
|
|
4146
|
+
case "get-or-create-chat":
|
|
4136
4147
|
context.chatsStore.upsert(msg.chat);
|
|
4137
4148
|
break;
|
|
4138
4149
|
case "delete-chat":
|
|
@@ -4143,20 +4154,17 @@ function createAi(config) {
|
|
|
4143
4154
|
context.chatsStore.upsert(msg.chat);
|
|
4144
4155
|
context.messagesStore.upsertMany(msg.messages);
|
|
4145
4156
|
break;
|
|
4146
|
-
case "add-user-message":
|
|
4147
|
-
context.messagesStore.upsert(msg.message);
|
|
4148
|
-
break;
|
|
4149
4157
|
case "delete-message":
|
|
4150
4158
|
context.messagesStore.remove(msg.chatId, msg.messageId);
|
|
4151
4159
|
break;
|
|
4152
4160
|
case "clear-chat":
|
|
4153
4161
|
context.messagesStore.removeByChatId(msg.chatId);
|
|
4154
4162
|
break;
|
|
4155
|
-
case "ask-
|
|
4156
|
-
if (msg.
|
|
4157
|
-
context.messagesStore.upsert(msg.
|
|
4158
|
-
} else {
|
|
4163
|
+
case "ask-in-chat":
|
|
4164
|
+
if (msg.sourceMessage) {
|
|
4165
|
+
context.messagesStore.upsert(msg.sourceMessage);
|
|
4159
4166
|
}
|
|
4167
|
+
context.messagesStore.upsert(msg.targetMessage);
|
|
4160
4168
|
break;
|
|
4161
4169
|
case "abort-ai":
|
|
4162
4170
|
break;
|
|
@@ -4210,13 +4218,14 @@ function createAi(config) {
|
|
|
4210
4218
|
cursor: options.cursor
|
|
4211
4219
|
});
|
|
4212
4220
|
}
|
|
4213
|
-
function
|
|
4221
|
+
function getOrCreateChat(id, title, options) {
|
|
4214
4222
|
return sendClientMsgWithResponse({
|
|
4215
|
-
cmd: "create-chat",
|
|
4223
|
+
cmd: "get-or-create-chat",
|
|
4216
4224
|
id,
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4225
|
+
options: {
|
|
4226
|
+
title,
|
|
4227
|
+
metadata: options?.metadata
|
|
4228
|
+
}
|
|
4220
4229
|
});
|
|
4221
4230
|
}
|
|
4222
4231
|
function getMessageTree(chatId) {
|
|
@@ -4225,19 +4234,19 @@ function createAi(config) {
|
|
|
4225
4234
|
chatId
|
|
4226
4235
|
});
|
|
4227
4236
|
}
|
|
4228
|
-
function
|
|
4229
|
-
const
|
|
4230
|
-
if (
|
|
4231
|
-
context.
|
|
4237
|
+
function registerKnowledgeSource(chatId, data) {
|
|
4238
|
+
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4239
|
+
if (knowledge === void 0) {
|
|
4240
|
+
context.knowledgeByChatId.set(chatId, /* @__PURE__ */ new Set([data]));
|
|
4232
4241
|
} else {
|
|
4233
|
-
|
|
4242
|
+
knowledge.add(data);
|
|
4234
4243
|
}
|
|
4235
4244
|
return () => {
|
|
4236
|
-
const
|
|
4237
|
-
if (
|
|
4238
|
-
|
|
4239
|
-
if (
|
|
4240
|
-
context.
|
|
4245
|
+
const knowledge2 = context.knowledgeByChatId.get(chatId);
|
|
4246
|
+
if (knowledge2 !== void 0) {
|
|
4247
|
+
knowledge2.delete(data);
|
|
4248
|
+
if (knowledge2.size === 0) {
|
|
4249
|
+
context.knowledgeByChatId.delete(chatId);
|
|
4241
4250
|
}
|
|
4242
4251
|
}
|
|
4243
4252
|
};
|
|
@@ -4251,22 +4260,24 @@ function createAi(config) {
|
|
|
4251
4260
|
const copilotId = options?.copilotId;
|
|
4252
4261
|
const stream = options?.stream ?? false;
|
|
4253
4262
|
const timeout = options?.timeout ?? DEFAULT_AI_TIMEOUT;
|
|
4254
|
-
const
|
|
4263
|
+
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4255
4264
|
return sendClientMsgWithResponse({
|
|
4256
|
-
cmd: "ask-
|
|
4265
|
+
cmd: "ask-in-chat",
|
|
4257
4266
|
chatId,
|
|
4258
|
-
|
|
4267
|
+
sourceMessage: messageId,
|
|
4259
4268
|
targetMessageId,
|
|
4260
|
-
copilotId,
|
|
4261
4269
|
clientId,
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
+
generationOptions: {
|
|
4271
|
+
copilotId,
|
|
4272
|
+
stream,
|
|
4273
|
+
knowledge: knowledge ? Array.from(knowledge) : void 0,
|
|
4274
|
+
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4275
|
+
name: tool.name,
|
|
4276
|
+
description: tool.definition.description,
|
|
4277
|
+
parameters: tool.definition.parameters
|
|
4278
|
+
})),
|
|
4279
|
+
timeout
|
|
4280
|
+
}
|
|
4270
4281
|
});
|
|
4271
4282
|
}
|
|
4272
4283
|
return Object.defineProperty(
|
|
@@ -4278,7 +4289,7 @@ function createAi(config) {
|
|
|
4278
4289
|
reconnect: () => managedSocket.reconnect(),
|
|
4279
4290
|
disconnect: () => managedSocket.disconnect(),
|
|
4280
4291
|
getChats,
|
|
4281
|
-
|
|
4292
|
+
getOrCreateChat,
|
|
4282
4293
|
deleteChat: (chatId) => {
|
|
4283
4294
|
return sendClientMsgWithResponse({
|
|
4284
4295
|
cmd: "delete-chat",
|
|
@@ -4288,23 +4299,6 @@ function createAi(config) {
|
|
|
4288
4299
|
getMessageTree,
|
|
4289
4300
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4290
4301
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4291
|
-
addUserMessage: (chatId, parentMessageId, message) => {
|
|
4292
|
-
const content = [{ type: "text", text: message }];
|
|
4293
|
-
const newMessageId = context.messagesStore.createOptimistically(
|
|
4294
|
-
chatId,
|
|
4295
|
-
"user",
|
|
4296
|
-
parentMessageId,
|
|
4297
|
-
content
|
|
4298
|
-
);
|
|
4299
|
-
return sendClientMsgWithResponse({
|
|
4300
|
-
cmd: "add-user-message",
|
|
4301
|
-
id: newMessageId,
|
|
4302
|
-
chatId,
|
|
4303
|
-
parentMessageId,
|
|
4304
|
-
content
|
|
4305
|
-
});
|
|
4306
|
-
},
|
|
4307
|
-
ask,
|
|
4308
4302
|
regenerateMessage: (chatId, messageId, options) => {
|
|
4309
4303
|
const parentUserMessageId = context.messagesStore.getLatestUserMessageAncestor(chatId, messageId);
|
|
4310
4304
|
if (parentUserMessageId === null) {
|
|
@@ -4327,32 +4321,27 @@ function createAi(config) {
|
|
|
4327
4321
|
"assistant",
|
|
4328
4322
|
newMessageId
|
|
4329
4323
|
);
|
|
4330
|
-
await sendClientMsgWithResponse({
|
|
4331
|
-
cmd: "add-user-message",
|
|
4332
|
-
id: newMessageId,
|
|
4333
|
-
chatId,
|
|
4334
|
-
parentMessageId,
|
|
4335
|
-
content
|
|
4336
|
-
});
|
|
4337
4324
|
const copilotId = options?.copilotId;
|
|
4338
4325
|
const stream = options?.stream ?? false;
|
|
4339
4326
|
const timeout = options?.timeout ?? DEFAULT_AI_TIMEOUT;
|
|
4340
|
-
const
|
|
4327
|
+
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4341
4328
|
return sendClientMsgWithResponse({
|
|
4342
|
-
cmd: "ask-
|
|
4329
|
+
cmd: "ask-in-chat",
|
|
4343
4330
|
chatId,
|
|
4344
|
-
|
|
4331
|
+
sourceMessage: { id: newMessageId, parentMessageId, content },
|
|
4345
4332
|
targetMessageId,
|
|
4346
|
-
copilotId,
|
|
4347
4333
|
clientId,
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4334
|
+
generationOptions: {
|
|
4335
|
+
copilotId,
|
|
4336
|
+
stream,
|
|
4337
|
+
knowledge: knowledge ? Array.from(knowledge) : void 0,
|
|
4338
|
+
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4339
|
+
name: tool.name,
|
|
4340
|
+
description: tool.definition.description,
|
|
4341
|
+
parameters: tool.definition.parameters
|
|
4342
|
+
})),
|
|
4343
|
+
timeout
|
|
4344
|
+
}
|
|
4356
4345
|
});
|
|
4357
4346
|
},
|
|
4358
4347
|
abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
|
|
@@ -4363,7 +4352,7 @@ function createAi(config) {
|
|
|
4363
4352
|
getToolDefinition\u03A3: context.toolsStore.getToolCallByName\u03A3,
|
|
4364
4353
|
getMessagesForChat\u03A3: context.messagesStore.getMessagesForChat\u03A3
|
|
4365
4354
|
},
|
|
4366
|
-
|
|
4355
|
+
registerKnowledgeSource,
|
|
4367
4356
|
registerChatTool: context.toolsStore.addToolDefinition,
|
|
4368
4357
|
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4369
4358
|
},
|