@liveblocks/core 2.25.0-aiprivatebeta4 → 2.25.0-aiprivatebeta6
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 +62 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -45
- package/dist/index.d.ts +53 -45
- package/dist/index.js +62 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
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-aiprivatebeta6";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
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) => ({
|
|
@@ -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) {
|
|
@@ -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,11 +4218,11 @@ function createAi(config) {
|
|
|
4210
4218
|
cursor: options.cursor
|
|
4211
4219
|
});
|
|
4212
4220
|
}
|
|
4213
|
-
function createChat(id,
|
|
4221
|
+
function createChat(id, title, options) {
|
|
4214
4222
|
return sendClientMsgWithResponse({
|
|
4215
4223
|
cmd: "create-chat",
|
|
4216
4224
|
id,
|
|
4217
|
-
|
|
4225
|
+
title,
|
|
4218
4226
|
ephemeral: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _65 => _65.ephemeral]), () => ( false)),
|
|
4219
4227
|
metadata: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.metadata]), () => ( {}))
|
|
4220
4228
|
});
|
|
@@ -4225,19 +4233,19 @@ function createAi(config) {
|
|
|
4225
4233
|
chatId
|
|
4226
4234
|
});
|
|
4227
4235
|
}
|
|
4228
|
-
function
|
|
4229
|
-
const
|
|
4230
|
-
if (
|
|
4231
|
-
context.
|
|
4236
|
+
function registerKnowledgeSource(chatId, data) {
|
|
4237
|
+
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4238
|
+
if (knowledge === void 0) {
|
|
4239
|
+
context.knowledgeByChatId.set(chatId, /* @__PURE__ */ new Set([data]));
|
|
4232
4240
|
} else {
|
|
4233
|
-
|
|
4241
|
+
knowledge.add(data);
|
|
4234
4242
|
}
|
|
4235
4243
|
return () => {
|
|
4236
|
-
const
|
|
4237
|
-
if (
|
|
4238
|
-
|
|
4239
|
-
if (
|
|
4240
|
-
context.
|
|
4244
|
+
const knowledge2 = context.knowledgeByChatId.get(chatId);
|
|
4245
|
+
if (knowledge2 !== void 0) {
|
|
4246
|
+
knowledge2.delete(data);
|
|
4247
|
+
if (knowledge2.size === 0) {
|
|
4248
|
+
context.knowledgeByChatId.delete(chatId);
|
|
4241
4249
|
}
|
|
4242
4250
|
}
|
|
4243
4251
|
};
|
|
@@ -4251,22 +4259,24 @@ function createAi(config) {
|
|
|
4251
4259
|
const copilotId = _optionalChain([options, 'optionalAccess', _67 => _67.copilotId]);
|
|
4252
4260
|
const stream = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.stream]), () => ( false));
|
|
4253
4261
|
const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _69 => _69.timeout]), () => ( DEFAULT_AI_TIMEOUT));
|
|
4254
|
-
const
|
|
4262
|
+
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4255
4263
|
return sendClientMsgWithResponse({
|
|
4256
|
-
cmd: "ask-
|
|
4264
|
+
cmd: "ask-in-chat",
|
|
4257
4265
|
chatId,
|
|
4258
|
-
|
|
4266
|
+
sourceMessage: messageId,
|
|
4259
4267
|
targetMessageId,
|
|
4260
|
-
copilotId,
|
|
4261
4268
|
clientId,
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4269
|
+
generationOptions: {
|
|
4270
|
+
copilotId,
|
|
4271
|
+
stream,
|
|
4272
|
+
knowledge: knowledge ? Array.from(knowledge) : void 0,
|
|
4273
|
+
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4274
|
+
name: tool.name,
|
|
4275
|
+
description: tool.definition.description,
|
|
4276
|
+
parameters: tool.definition.parameters
|
|
4277
|
+
})),
|
|
4278
|
+
timeout
|
|
4279
|
+
}
|
|
4270
4280
|
});
|
|
4271
4281
|
}
|
|
4272
4282
|
return Object.defineProperty(
|
|
@@ -4288,23 +4298,6 @@ function createAi(config) {
|
|
|
4288
4298
|
getMessageTree,
|
|
4289
4299
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4290
4300
|
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
4301
|
regenerateMessage: (chatId, messageId, options) => {
|
|
4309
4302
|
const parentUserMessageId = context.messagesStore.getLatestUserMessageAncestor(chatId, messageId);
|
|
4310
4303
|
if (parentUserMessageId === null) {
|
|
@@ -4327,32 +4320,27 @@ function createAi(config) {
|
|
|
4327
4320
|
"assistant",
|
|
4328
4321
|
newMessageId
|
|
4329
4322
|
);
|
|
4330
|
-
await sendClientMsgWithResponse({
|
|
4331
|
-
cmd: "add-user-message",
|
|
4332
|
-
id: newMessageId,
|
|
4333
|
-
chatId,
|
|
4334
|
-
parentMessageId,
|
|
4335
|
-
content
|
|
4336
|
-
});
|
|
4337
4323
|
const copilotId = _optionalChain([options, 'optionalAccess', _70 => _70.copilotId]);
|
|
4338
4324
|
const stream = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.stream]), () => ( false));
|
|
4339
4325
|
const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.timeout]), () => ( DEFAULT_AI_TIMEOUT));
|
|
4340
|
-
const
|
|
4326
|
+
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4341
4327
|
return sendClientMsgWithResponse({
|
|
4342
|
-
cmd: "ask-
|
|
4328
|
+
cmd: "ask-in-chat",
|
|
4343
4329
|
chatId,
|
|
4344
|
-
|
|
4330
|
+
sourceMessage: { id: newMessageId, parentMessageId, content },
|
|
4345
4331
|
targetMessageId,
|
|
4346
|
-
copilotId,
|
|
4347
4332
|
clientId,
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4333
|
+
generationOptions: {
|
|
4334
|
+
copilotId,
|
|
4335
|
+
stream,
|
|
4336
|
+
knowledge: knowledge ? Array.from(knowledge) : void 0,
|
|
4337
|
+
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4338
|
+
name: tool.name,
|
|
4339
|
+
description: tool.definition.description,
|
|
4340
|
+
parameters: tool.definition.parameters
|
|
4341
|
+
})),
|
|
4342
|
+
timeout
|
|
4343
|
+
}
|
|
4356
4344
|
});
|
|
4357
4345
|
},
|
|
4358
4346
|
abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
|
|
@@ -4363,7 +4351,7 @@ function createAi(config) {
|
|
|
4363
4351
|
getToolDefinition\u03A3: context.toolsStore.getToolCallByName\u03A3,
|
|
4364
4352
|
getMessagesForChat\u03A3: context.messagesStore.getMessagesForChat\u03A3
|
|
4365
4353
|
},
|
|
4366
|
-
|
|
4354
|
+
registerKnowledgeSource,
|
|
4367
4355
|
registerChatTool: context.toolsStore.addToolDefinition,
|
|
4368
4356
|
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4369
4357
|
},
|