@liveblocks/core 2.25.0-aiprivatebeta9 → 3.1.0-alpha1
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 +261 -217
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +166 -175
- package/dist/index.d.ts +166 -175
- package/dist/index.js +172 -128
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
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 = "
|
|
9
|
+
var PKG_VERSION = "3.1.0-alpha1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3780,50 +3780,66 @@ var KnowledgeStack = class {
|
|
|
3780
3780
|
function now() {
|
|
3781
3781
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3782
3782
|
}
|
|
3783
|
+
var kWILDCARD = Symbol("*");
|
|
3783
3784
|
function createStore_forTools() {
|
|
3784
|
-
const toolsByChatId\u03A3 = new DefaultMap(
|
|
3785
|
-
|
|
3786
|
-
return new
|
|
3785
|
+
const toolsByChatId\u03A3 = new DefaultMap(
|
|
3786
|
+
(_chatId) => {
|
|
3787
|
+
return new DefaultMap((_name) => {
|
|
3788
|
+
return new Signal(void 0);
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3791
|
+
);
|
|
3792
|
+
const globalOrScopedTool\u03A3 = new DefaultMap((nameAndChat) => {
|
|
3793
|
+
const [name, chatId] = tryParseJson(nameAndChat);
|
|
3794
|
+
return DerivedSignal.from(() => {
|
|
3795
|
+
return (
|
|
3796
|
+
// A tool that's registered and scoped to a specific chat ID...
|
|
3797
|
+
(chatId !== void 0 ? toolsByChatId\u03A3.get(chatId)?.get(name) : void 0)?.get() ?? // ...or a globally registered tool
|
|
3798
|
+
toolsByChatId\u03A3.getOrCreate(kWILDCARD).get(name)?.get()
|
|
3799
|
+
);
|
|
3787
3800
|
});
|
|
3788
3801
|
});
|
|
3789
|
-
function
|
|
3790
|
-
|
|
3802
|
+
function getTool\u03A3(name, chatId) {
|
|
3803
|
+
const key = JSON.stringify(chatId !== void 0 ? [name, chatId] : [name]);
|
|
3804
|
+
return globalOrScopedTool\u03A3.getOrCreate(key);
|
|
3791
3805
|
}
|
|
3792
|
-
function
|
|
3793
|
-
if (!
|
|
3806
|
+
function registerTool(name, tool, chatId) {
|
|
3807
|
+
if (!tool.execute && !tool.render) {
|
|
3794
3808
|
throw new Error(
|
|
3795
|
-
"A tool definition must have an execute() function, a render
|
|
3809
|
+
"A tool definition must have an execute() function, a render() function, or both."
|
|
3796
3810
|
);
|
|
3797
3811
|
}
|
|
3798
|
-
|
|
3812
|
+
const key = chatId ?? kWILDCARD;
|
|
3813
|
+
toolsByChatId\u03A3.getOrCreate(key).getOrCreate(name).set(tool);
|
|
3814
|
+
return () => unregisterTool(key, name);
|
|
3799
3815
|
}
|
|
3800
|
-
function
|
|
3816
|
+
function unregisterTool(chatId, name) {
|
|
3801
3817
|
const tools = toolsByChatId\u03A3.get(chatId);
|
|
3802
3818
|
if (tools === void 0) return;
|
|
3803
|
-
const tool = tools.get(
|
|
3819
|
+
const tool = tools.get(name);
|
|
3804
3820
|
if (tool === void 0) return;
|
|
3805
3821
|
tool.set(void 0);
|
|
3806
3822
|
}
|
|
3807
|
-
function
|
|
3808
|
-
const
|
|
3809
|
-
|
|
3810
|
-
return Array.from(
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
};
|
|
3816
|
-
})
|
|
3823
|
+
function getToolDescriptions(chatId) {
|
|
3824
|
+
const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
|
|
3825
|
+
const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
|
|
3826
|
+
return Array.from([
|
|
3827
|
+
...globalTools\u03A3?.entries() ?? [],
|
|
3828
|
+
...scopedTools\u03A3?.entries() ?? []
|
|
3829
|
+
]).flatMap(([name, tool\u03A3]) => {
|
|
3830
|
+
const tool = tool\u03A3.get();
|
|
3831
|
+
return tool && (tool.enabled ?? true) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
|
|
3832
|
+
});
|
|
3817
3833
|
}
|
|
3818
3834
|
return {
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
removeToolDefinition
|
|
3835
|
+
getToolDescriptions,
|
|
3836
|
+
getTool\u03A3,
|
|
3837
|
+
registerTool
|
|
3823
3838
|
};
|
|
3824
3839
|
}
|
|
3825
|
-
function createStore_forChatMessages(toolsStore,
|
|
3826
|
-
const
|
|
3840
|
+
function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
3841
|
+
const myMessages = /* @__PURE__ */ new Set();
|
|
3842
|
+
const handledInvocations = /* @__PURE__ */ new Set();
|
|
3827
3843
|
const messagePoolByChatId\u03A3 = new DefaultMap(
|
|
3828
3844
|
(_chatId) => new MutableSignal(
|
|
3829
3845
|
new TreePool(
|
|
@@ -3901,42 +3917,39 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
|
3901
3917
|
});
|
|
3902
3918
|
}
|
|
3903
3919
|
if (message.role === "assistant" && message.status === "awaiting-tool") {
|
|
3904
|
-
|
|
3905
|
-
(
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3920
|
+
if (myMessages.has(message.id)) {
|
|
3921
|
+
for (const toolInvocation of message.contentSoFar.filter(
|
|
3922
|
+
(part) => part.type === "tool-invocation" && part.stage === "executing"
|
|
3923
|
+
)) {
|
|
3924
|
+
if (!handledInvocations.has(toolInvocation.invocationId)) {
|
|
3925
|
+
handledInvocations.add(toolInvocation.invocationId);
|
|
3926
|
+
} else {
|
|
3927
|
+
continue;
|
|
3928
|
+
}
|
|
3929
|
+
const executeFn = toolsStore.getTool\u03A3(toolInvocation.name, message.chatId).get()?.execute;
|
|
3930
|
+
if (executeFn) {
|
|
3931
|
+
(async () => {
|
|
3932
|
+
const result = await executeFn(toolInvocation.args, {
|
|
3933
|
+
name: toolInvocation.name,
|
|
3934
|
+
invocationId: toolInvocation.invocationId
|
|
3935
|
+
});
|
|
3936
|
+
return await setToolResultFn(
|
|
3937
|
+
message.chatId,
|
|
3938
|
+
message.id,
|
|
3939
|
+
toolInvocation.invocationId,
|
|
3940
|
+
result ?? { data: {} }
|
|
3941
|
+
// TODO Pass in AiGenerationOptions here, or make the backend use the same options
|
|
3942
|
+
);
|
|
3943
|
+
})().catch((err) => {
|
|
3944
|
+
error2(
|
|
3945
|
+
`Error trying to respond to tool-call: ${String(err)} (in execute())`
|
|
3946
|
+
);
|
|
3931
3947
|
});
|
|
3932
|
-
|
|
3933
|
-
})().catch((err) => {
|
|
3934
|
-
error2(
|
|
3935
|
-
`Error trying to respond to tool-call: ${String(err)} (in execute())`
|
|
3936
|
-
);
|
|
3937
|
-
});
|
|
3948
|
+
}
|
|
3938
3949
|
}
|
|
3939
3950
|
}
|
|
3951
|
+
} else {
|
|
3952
|
+
myMessages.delete(message.id);
|
|
3940
3953
|
}
|
|
3941
3954
|
});
|
|
3942
3955
|
}
|
|
@@ -4081,20 +4094,23 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
|
4081
4094
|
remove,
|
|
4082
4095
|
removeByChatId,
|
|
4083
4096
|
addDelta,
|
|
4084
|
-
failAllPending
|
|
4097
|
+
failAllPending,
|
|
4098
|
+
markMine(messageId) {
|
|
4099
|
+
myMessages.add(messageId);
|
|
4100
|
+
}
|
|
4085
4101
|
};
|
|
4086
4102
|
}
|
|
4087
4103
|
function createStore_forUserAiChats() {
|
|
4088
|
-
const
|
|
4104
|
+
const allChatsInclDeleted\u03A3 = new MutableSignal(
|
|
4089
4105
|
SortedList.with((x, y) => y.createdAt < x.createdAt)
|
|
4090
4106
|
);
|
|
4091
|
-
const
|
|
4092
|
-
() => Array.from(
|
|
4107
|
+
const nonDeletedChats\u03A3 = DerivedSignal.from(
|
|
4108
|
+
() => Array.from(allChatsInclDeleted\u03A3.get()).filter((c) => !c.deletedAt)
|
|
4093
4109
|
);
|
|
4094
4110
|
function upsertMany(chats) {
|
|
4095
|
-
|
|
4111
|
+
allChatsInclDeleted\u03A3.mutate((list) => {
|
|
4096
4112
|
for (const chat of chats) {
|
|
4097
|
-
|
|
4113
|
+
list.removeBy((c) => c.id === chat.id, 1);
|
|
4098
4114
|
list.add(chat);
|
|
4099
4115
|
}
|
|
4100
4116
|
});
|
|
@@ -4102,19 +4118,26 @@ function createStore_forUserAiChats() {
|
|
|
4102
4118
|
function upsert(chat) {
|
|
4103
4119
|
upsertMany([chat]);
|
|
4104
4120
|
}
|
|
4105
|
-
function
|
|
4106
|
-
|
|
4121
|
+
function markDeleted(chatId) {
|
|
4122
|
+
allChatsInclDeleted\u03A3.mutate((list) => {
|
|
4123
|
+
const chat = list.find((c) => c.id === chatId);
|
|
4124
|
+
if (!chat) return false;
|
|
4125
|
+
upsert({ ...chat, deletedAt: now() });
|
|
4126
|
+
return void 0;
|
|
4127
|
+
});
|
|
4107
4128
|
}
|
|
4108
4129
|
function getChatById(chatId) {
|
|
4109
|
-
return Array.from(
|
|
4130
|
+
return Array.from(allChatsInclDeleted\u03A3.get()).find(
|
|
4131
|
+
(chat) => chat.id === chatId
|
|
4132
|
+
);
|
|
4110
4133
|
}
|
|
4111
4134
|
return {
|
|
4112
|
-
chats\u03A3,
|
|
4135
|
+
chats\u03A3: nonDeletedChats\u03A3,
|
|
4113
4136
|
getChatById,
|
|
4114
4137
|
// Mutations
|
|
4115
4138
|
upsert,
|
|
4116
4139
|
upsertMany,
|
|
4117
|
-
|
|
4140
|
+
markDeleted
|
|
4118
4141
|
};
|
|
4119
4142
|
}
|
|
4120
4143
|
function createAi(config) {
|
|
@@ -4124,7 +4147,6 @@ function createAi(config) {
|
|
|
4124
4147
|
false
|
|
4125
4148
|
// AI doesn't have actors (yet, but it will)
|
|
4126
4149
|
);
|
|
4127
|
-
const clientId = nanoid(7);
|
|
4128
4150
|
const chatsStore = createStore_forUserAiChats();
|
|
4129
4151
|
const toolsStore = createStore_forTools();
|
|
4130
4152
|
const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
|
|
@@ -4204,7 +4226,11 @@ function createAi(config) {
|
|
|
4204
4226
|
context.messagesStore.upsert(msg.message);
|
|
4205
4227
|
break;
|
|
4206
4228
|
}
|
|
4229
|
+
case "warning":
|
|
4230
|
+
warn(msg.message);
|
|
4231
|
+
break;
|
|
4207
4232
|
case "error":
|
|
4233
|
+
error2(msg.error);
|
|
4208
4234
|
break;
|
|
4209
4235
|
case "rebooted":
|
|
4210
4236
|
context.messagesStore.failAllPending();
|
|
@@ -4215,7 +4241,7 @@ function createAi(config) {
|
|
|
4215
4241
|
context.messagesStore.remove(m.chatId, m.id);
|
|
4216
4242
|
}
|
|
4217
4243
|
for (const chatId of msg["-chats"] ?? []) {
|
|
4218
|
-
context.chatsStore.
|
|
4244
|
+
context.chatsStore.markDeleted(chatId);
|
|
4219
4245
|
context.messagesStore.removeByChatId(chatId);
|
|
4220
4246
|
}
|
|
4221
4247
|
for (const chatId of msg.clear ?? []) {
|
|
@@ -4241,7 +4267,7 @@ function createAi(config) {
|
|
|
4241
4267
|
context.chatsStore.upsert(msg.chat);
|
|
4242
4268
|
break;
|
|
4243
4269
|
case "delete-chat":
|
|
4244
|
-
context.chatsStore.
|
|
4270
|
+
context.chatsStore.markDeleted(msg.chatId);
|
|
4245
4271
|
context.messagesStore.removeByChatId(msg.chatId);
|
|
4246
4272
|
break;
|
|
4247
4273
|
case "get-message-tree":
|
|
@@ -4285,7 +4311,13 @@ function createAi(config) {
|
|
|
4285
4311
|
);
|
|
4286
4312
|
}
|
|
4287
4313
|
});
|
|
4314
|
+
function connectInitially() {
|
|
4315
|
+
if (managedSocket.getStatus() === "initial") {
|
|
4316
|
+
managedSocket.connect();
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4288
4319
|
async function sendClientMsgWithResponse(msg) {
|
|
4320
|
+
connectInitially();
|
|
4289
4321
|
if (managedSocket.getStatus() !== "connected") {
|
|
4290
4322
|
await managedSocket.events.didConnect.waitUntil();
|
|
4291
4323
|
}
|
|
@@ -4339,70 +4371,65 @@ function createAi(config) {
|
|
|
4339
4371
|
function updateKnowledge(layerKey, data, key = nanoid()) {
|
|
4340
4372
|
context.knowledge.updateKnowledge(layerKey, key, data);
|
|
4341
4373
|
}
|
|
4342
|
-
function
|
|
4343
|
-
return context.knowledge.get();
|
|
4344
|
-
}
|
|
4345
|
-
async function setToolResult(chatId, messageId, toolCallId, result, options) {
|
|
4374
|
+
async function setToolResult(chatId, messageId, invocationId, result, options) {
|
|
4346
4375
|
const knowledge = context.knowledge.get();
|
|
4347
|
-
|
|
4376
|
+
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4377
|
+
const resp = await sendClientMsgWithResponse({
|
|
4348
4378
|
cmd: "set-tool-result",
|
|
4349
4379
|
chatId,
|
|
4350
4380
|
messageId,
|
|
4351
|
-
|
|
4352
|
-
clientId,
|
|
4381
|
+
invocationId,
|
|
4353
4382
|
result,
|
|
4354
4383
|
generationOptions: {
|
|
4355
4384
|
copilotId: options?.copilotId,
|
|
4356
4385
|
stream: options?.stream,
|
|
4357
4386
|
timeout: options?.timeout,
|
|
4387
|
+
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4388
|
+
// from the global context
|
|
4358
4389
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4359
|
-
tools:
|
|
4360
|
-
name: tool.name,
|
|
4361
|
-
description: tool.definition.description,
|
|
4362
|
-
parameters: tool.definition.parameters
|
|
4363
|
-
}))
|
|
4390
|
+
tools: tools.length > 0 ? tools : void 0
|
|
4364
4391
|
}
|
|
4365
4392
|
});
|
|
4393
|
+
if (resp.ok) {
|
|
4394
|
+
messagesStore.markMine(resp.message.id);
|
|
4395
|
+
}
|
|
4366
4396
|
}
|
|
4367
4397
|
return Object.defineProperty(
|
|
4368
4398
|
{
|
|
4369
4399
|
[kInternal]: {
|
|
4370
4400
|
context
|
|
4371
4401
|
},
|
|
4372
|
-
|
|
4373
|
-
reconnect: () => managedSocket.reconnect(),
|
|
4402
|
+
connectInitially,
|
|
4403
|
+
// reconnect: () => managedSocket.reconnect(),
|
|
4374
4404
|
disconnect: () => managedSocket.disconnect(),
|
|
4375
4405
|
getChats,
|
|
4376
4406
|
getOrCreateChat,
|
|
4377
4407
|
deleteChat: (chatId) => {
|
|
4378
|
-
return sendClientMsgWithResponse({
|
|
4379
|
-
cmd: "delete-chat",
|
|
4380
|
-
chatId
|
|
4381
|
-
});
|
|
4408
|
+
return sendClientMsgWithResponse({ cmd: "delete-chat", chatId });
|
|
4382
4409
|
},
|
|
4383
4410
|
getMessageTree,
|
|
4384
4411
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4385
4412
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4386
4413
|
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4387
4414
|
const knowledge = context.knowledge.get();
|
|
4388
|
-
|
|
4415
|
+
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4416
|
+
const resp = await sendClientMsgWithResponse({
|
|
4389
4417
|
cmd: "ask-in-chat",
|
|
4390
4418
|
chatId,
|
|
4391
4419
|
sourceMessage: userMessage,
|
|
4392
4420
|
targetMessageId,
|
|
4393
|
-
clientId,
|
|
4394
4421
|
generationOptions: {
|
|
4395
4422
|
copilotId: options?.copilotId,
|
|
4396
4423
|
stream: options?.stream,
|
|
4397
4424
|
timeout: options?.timeout,
|
|
4425
|
+
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4426
|
+
// from the global context
|
|
4398
4427
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4399
|
-
tools:
|
|
4400
|
-
name: tool.name,
|
|
4401
|
-
description: tool.definition.description,
|
|
4402
|
-
parameters: tool.definition.parameters
|
|
4403
|
-
}))
|
|
4428
|
+
tools: tools.length > 0 ? tools : void 0
|
|
4404
4429
|
}
|
|
4405
4430
|
});
|
|
4431
|
+
messagesStore.markMine(resp.targetMessage.id);
|
|
4432
|
+
return resp;
|
|
4406
4433
|
},
|
|
4407
4434
|
abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
|
|
4408
4435
|
setToolResult,
|
|
@@ -4410,15 +4437,13 @@ function createAi(config) {
|
|
|
4410
4437
|
signals: {
|
|
4411
4438
|
chats\u03A3: context.chatsStore.chats\u03A3,
|
|
4412
4439
|
getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
|
|
4413
|
-
|
|
4440
|
+
getTool\u03A3: context.toolsStore.getTool\u03A3
|
|
4414
4441
|
},
|
|
4415
4442
|
getChatById: context.chatsStore.getChatById,
|
|
4416
4443
|
registerKnowledgeLayer,
|
|
4417
4444
|
deregisterKnowledgeLayer,
|
|
4418
4445
|
updateKnowledge,
|
|
4419
|
-
|
|
4420
|
-
registerChatTool: context.toolsStore.addToolDefinition,
|
|
4421
|
-
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4446
|
+
registerTool: context.toolsStore.registerTool
|
|
4422
4447
|
},
|
|
4423
4448
|
kInternal,
|
|
4424
4449
|
{ enumerable: false }
|
|
@@ -4434,7 +4459,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
|
|
|
4434
4459
|
}
|
|
4435
4460
|
const url2 = new URL(baseUrl);
|
|
4436
4461
|
url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
|
|
4437
|
-
url2.pathname = "/ai/
|
|
4462
|
+
url2.pathname = "/ai/v4";
|
|
4438
4463
|
if (authValue.type === "secret") {
|
|
4439
4464
|
url2.searchParams.set("tok", authValue.token.raw);
|
|
4440
4465
|
} else if (authValue.type === "public") {
|
|
@@ -7751,7 +7776,7 @@ var LiveblocksError = class _LiveblocksError extends Error {
|
|
|
7751
7776
|
get roomId() {
|
|
7752
7777
|
return this.context.roomId;
|
|
7753
7778
|
}
|
|
7754
|
-
/** @
|
|
7779
|
+
/** @internal Use `context.code` instead, to enable type narrowing */
|
|
7755
7780
|
get code() {
|
|
7756
7781
|
return this.context.code;
|
|
7757
7782
|
}
|
|
@@ -7821,11 +7846,9 @@ function defaultMessageFromContext(context) {
|
|
|
7821
7846
|
return "Could not mark all inbox notifications as read";
|
|
7822
7847
|
case "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR":
|
|
7823
7848
|
return "Could not delete all inbox notifications";
|
|
7824
|
-
case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
|
|
7825
|
-
return "Could not update notification settings";
|
|
7826
7849
|
case "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR":
|
|
7827
7850
|
return "Could not update room subscription settings";
|
|
7828
|
-
case "
|
|
7851
|
+
case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
|
|
7829
7852
|
return "Could not update notification settings";
|
|
7830
7853
|
default:
|
|
7831
7854
|
return assertNever(context, "Unhandled case");
|
|
@@ -8958,8 +8981,6 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
8958
8981
|
others: eventHub.others.observable,
|
|
8959
8982
|
self: eventHub.self.observable,
|
|
8960
8983
|
myPresence: eventHub.myPresence.observable,
|
|
8961
|
-
/** @deprecated */
|
|
8962
|
-
storage: eventHub.storageBatch.observable,
|
|
8963
8984
|
storageBatch: eventHub.storageBatch.observable,
|
|
8964
8985
|
history: eventHub.history.observable,
|
|
8965
8986
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
@@ -9421,8 +9442,26 @@ function createClient(options) {
|
|
|
9421
9442
|
baseUrl,
|
|
9422
9443
|
clientOptions.polyfills?.WebSocket
|
|
9423
9444
|
),
|
|
9424
|
-
authenticate:
|
|
9425
|
-
|
|
9445
|
+
authenticate: async () => {
|
|
9446
|
+
const resp = await authManager.getAuthValue({
|
|
9447
|
+
requestedScope: "room:read"
|
|
9448
|
+
});
|
|
9449
|
+
if (resp.type === "public") {
|
|
9450
|
+
throw new StopRetrying(
|
|
9451
|
+
"Cannot use AI Copilots with a public API key"
|
|
9452
|
+
);
|
|
9453
|
+
} else if (resp.token.parsed.k === "sec-legacy" /* SECRET_LEGACY */) {
|
|
9454
|
+
throw new StopRetrying("AI Copilots requires an ID or Access token");
|
|
9455
|
+
} else {
|
|
9456
|
+
if (!resp.token.parsed.ai) {
|
|
9457
|
+
throw new StopRetrying(
|
|
9458
|
+
"AI Copilots is not yet enabled for this account. To get started, see https://liveblocks.io/docs/get-started/ai-copilots#Quickstart"
|
|
9459
|
+
);
|
|
9460
|
+
}
|
|
9461
|
+
}
|
|
9462
|
+
return resp;
|
|
9463
|
+
},
|
|
9464
|
+
canZombie: () => false
|
|
9426
9465
|
}
|
|
9427
9466
|
});
|
|
9428
9467
|
function teardownRoom(room) {
|
|
@@ -9476,7 +9515,7 @@ function createClient(options) {
|
|
|
9476
9515
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
9477
9516
|
baseUrl,
|
|
9478
9517
|
errorEventSource: liveblocksErrorSource,
|
|
9479
|
-
largeMessageStrategy: clientOptions.largeMessageStrategy
|
|
9518
|
+
largeMessageStrategy: clientOptions.largeMessageStrategy,
|
|
9480
9519
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
9481
9520
|
roomHttpClient: httpClient,
|
|
9482
9521
|
createSyncSource
|
|
@@ -9756,21 +9795,30 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
9756
9795
|
}
|
|
9757
9796
|
}
|
|
9758
9797
|
}
|
|
9759
|
-
function
|
|
9760
|
-
const
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9798
|
+
function getMentionsFromCommentBody(body, predicate) {
|
|
9799
|
+
const mentionIds = /* @__PURE__ */ new Set();
|
|
9800
|
+
const mentions = [];
|
|
9801
|
+
traverseCommentBody(body, "mention", (mention) => {
|
|
9802
|
+
if (
|
|
9803
|
+
// If this mention isn't already in the list
|
|
9804
|
+
!mentionIds.has(mention.id) && // And the provided predicate is true
|
|
9805
|
+
(predicate ? predicate(mention) : true)
|
|
9806
|
+
) {
|
|
9807
|
+
mentionIds.add(mention.id);
|
|
9808
|
+
mentions.push(mention);
|
|
9809
|
+
}
|
|
9810
|
+
});
|
|
9811
|
+
return mentions;
|
|
9767
9812
|
}
|
|
9768
9813
|
async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
9769
9814
|
const resolvedUsers = /* @__PURE__ */ new Map();
|
|
9770
9815
|
if (!resolveUsers) {
|
|
9771
9816
|
return resolvedUsers;
|
|
9772
9817
|
}
|
|
9773
|
-
const userIds =
|
|
9818
|
+
const userIds = getMentionsFromCommentBody(
|
|
9819
|
+
body,
|
|
9820
|
+
(mention) => mention.kind === "user"
|
|
9821
|
+
).map((mention) => mention.id);
|
|
9774
9822
|
const users = await resolveUsers({
|
|
9775
9823
|
userIds
|
|
9776
9824
|
});
|
|
@@ -10533,11 +10581,8 @@ var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
|
|
|
10533
10581
|
|
|
10534
10582
|
// src/index.ts
|
|
10535
10583
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
10536
|
-
var CommentsApiError = HttpError;
|
|
10537
|
-
var NotificationsApiError = HttpError;
|
|
10538
10584
|
export {
|
|
10539
10585
|
ClientMsgCode,
|
|
10540
|
-
CommentsApiError,
|
|
10541
10586
|
CrdtType,
|
|
10542
10587
|
DefaultMap,
|
|
10543
10588
|
Deque,
|
|
@@ -10548,7 +10593,6 @@ export {
|
|
|
10548
10593
|
LiveObject,
|
|
10549
10594
|
LiveblocksError,
|
|
10550
10595
|
MutableSignal,
|
|
10551
|
-
NotificationsApiError,
|
|
10552
10596
|
OpCode,
|
|
10553
10597
|
Permission,
|
|
10554
10598
|
Promise_withResolvers,
|
|
@@ -10590,7 +10634,7 @@ export {
|
|
|
10590
10634
|
errorIf,
|
|
10591
10635
|
freeze,
|
|
10592
10636
|
generateCommentUrl,
|
|
10593
|
-
|
|
10637
|
+
getMentionsFromCommentBody,
|
|
10594
10638
|
getSubscriptionKey,
|
|
10595
10639
|
html,
|
|
10596
10640
|
htmlSafe,
|