@liveblocks/core 2.25.0-aiprivatebeta8 → 3.0.0
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 +268 -215
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +215 -172
- package/dist/index.d.ts +215 -172
- package/dist/index.js +180 -127
- 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.0.0";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3715,6 +3715,11 @@ function appendDelta(content, delta) {
|
|
|
3715
3715
|
|
|
3716
3716
|
// src/ai.ts
|
|
3717
3717
|
var DEFAULT_REQUEST_TIMEOUT = 4e3;
|
|
3718
|
+
function defineAiTool() {
|
|
3719
|
+
return (def) => {
|
|
3720
|
+
return def;
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3718
3723
|
var KnowledgeStack = class {
|
|
3719
3724
|
#_layers;
|
|
3720
3725
|
#stack;
|
|
@@ -3775,50 +3780,66 @@ var KnowledgeStack = class {
|
|
|
3775
3780
|
function now() {
|
|
3776
3781
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3777
3782
|
}
|
|
3783
|
+
var kWILDCARD = Symbol("*");
|
|
3778
3784
|
function createStore_forTools() {
|
|
3779
|
-
const toolsByChatId\u03A3 = new DefaultMap(
|
|
3780
|
-
|
|
3781
|
-
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
|
+
);
|
|
3782
3800
|
});
|
|
3783
3801
|
});
|
|
3784
|
-
function
|
|
3785
|
-
|
|
3802
|
+
function getTool\u03A3(name, chatId) {
|
|
3803
|
+
const key = JSON.stringify(chatId !== void 0 ? [name, chatId] : [name]);
|
|
3804
|
+
return globalOrScopedTool\u03A3.getOrCreate(key);
|
|
3786
3805
|
}
|
|
3787
|
-
function
|
|
3788
|
-
if (!
|
|
3806
|
+
function registerTool(name, tool, chatId) {
|
|
3807
|
+
if (!tool.execute && !tool.render) {
|
|
3789
3808
|
throw new Error(
|
|
3790
|
-
"A tool definition must have an execute() function, a render
|
|
3809
|
+
"A tool definition must have an execute() function, a render() function, or both."
|
|
3791
3810
|
);
|
|
3792
3811
|
}
|
|
3793
|
-
|
|
3812
|
+
const key = chatId ?? kWILDCARD;
|
|
3813
|
+
toolsByChatId\u03A3.getOrCreate(key).getOrCreate(name).set(tool);
|
|
3814
|
+
return () => unregisterTool(key, name);
|
|
3794
3815
|
}
|
|
3795
|
-
function
|
|
3816
|
+
function unregisterTool(chatId, name) {
|
|
3796
3817
|
const tools = toolsByChatId\u03A3.get(chatId);
|
|
3797
3818
|
if (tools === void 0) return;
|
|
3798
|
-
const tool = tools.get(
|
|
3819
|
+
const tool = tools.get(name);
|
|
3799
3820
|
if (tool === void 0) return;
|
|
3800
3821
|
tool.set(void 0);
|
|
3801
3822
|
}
|
|
3802
|
-
function
|
|
3803
|
-
const
|
|
3804
|
-
|
|
3805
|
-
return Array.from(
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
};
|
|
3811
|
-
})
|
|
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 ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
|
|
3832
|
+
});
|
|
3812
3833
|
}
|
|
3813
3834
|
return {
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
removeToolDefinition
|
|
3835
|
+
getToolDescriptions,
|
|
3836
|
+
getTool\u03A3,
|
|
3837
|
+
registerTool
|
|
3818
3838
|
};
|
|
3819
3839
|
}
|
|
3820
|
-
function createStore_forChatMessages(toolsStore,
|
|
3821
|
-
const
|
|
3840
|
+
function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
3841
|
+
const myMessages = /* @__PURE__ */ new Set();
|
|
3842
|
+
const handledInvocations = /* @__PURE__ */ new Set();
|
|
3822
3843
|
const messagePoolByChatId\u03A3 = new DefaultMap(
|
|
3823
3844
|
(_chatId) => new MutableSignal(
|
|
3824
3845
|
new TreePool(
|
|
@@ -3896,39 +3917,39 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
|
3896
3917
|
});
|
|
3897
3918
|
}
|
|
3898
3919
|
if (message.role === "assistant" && message.status === "awaiting-tool") {
|
|
3899
|
-
|
|
3900
|
-
(
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
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
|
-
});
|
|
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
|
+
);
|
|
3947
|
+
});
|
|
3948
|
+
}
|
|
3930
3949
|
}
|
|
3931
3950
|
}
|
|
3951
|
+
} else {
|
|
3952
|
+
myMessages.delete(message.id);
|
|
3932
3953
|
}
|
|
3933
3954
|
});
|
|
3934
3955
|
}
|
|
@@ -4073,20 +4094,23 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
|
4073
4094
|
remove,
|
|
4074
4095
|
removeByChatId,
|
|
4075
4096
|
addDelta,
|
|
4076
|
-
failAllPending
|
|
4097
|
+
failAllPending,
|
|
4098
|
+
markMine(messageId) {
|
|
4099
|
+
myMessages.add(messageId);
|
|
4100
|
+
}
|
|
4077
4101
|
};
|
|
4078
4102
|
}
|
|
4079
4103
|
function createStore_forUserAiChats() {
|
|
4080
|
-
const
|
|
4104
|
+
const allChatsInclDeleted\u03A3 = new MutableSignal(
|
|
4081
4105
|
SortedList.with((x, y) => y.createdAt < x.createdAt)
|
|
4082
4106
|
);
|
|
4083
|
-
const
|
|
4084
|
-
() => Array.from(
|
|
4107
|
+
const nonDeletedChats\u03A3 = DerivedSignal.from(
|
|
4108
|
+
() => Array.from(allChatsInclDeleted\u03A3.get()).filter((c) => !c.deletedAt)
|
|
4085
4109
|
);
|
|
4086
4110
|
function upsertMany(chats) {
|
|
4087
|
-
|
|
4111
|
+
allChatsInclDeleted\u03A3.mutate((list) => {
|
|
4088
4112
|
for (const chat of chats) {
|
|
4089
|
-
|
|
4113
|
+
list.removeBy((c) => c.id === chat.id, 1);
|
|
4090
4114
|
list.add(chat);
|
|
4091
4115
|
}
|
|
4092
4116
|
});
|
|
@@ -4094,19 +4118,26 @@ function createStore_forUserAiChats() {
|
|
|
4094
4118
|
function upsert(chat) {
|
|
4095
4119
|
upsertMany([chat]);
|
|
4096
4120
|
}
|
|
4097
|
-
function
|
|
4098
|
-
|
|
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
|
+
});
|
|
4099
4128
|
}
|
|
4100
4129
|
function getChatById(chatId) {
|
|
4101
|
-
return Array.from(
|
|
4130
|
+
return Array.from(allChatsInclDeleted\u03A3.get()).find(
|
|
4131
|
+
(chat) => chat.id === chatId
|
|
4132
|
+
);
|
|
4102
4133
|
}
|
|
4103
4134
|
return {
|
|
4104
|
-
chats\u03A3,
|
|
4135
|
+
chats\u03A3: nonDeletedChats\u03A3,
|
|
4105
4136
|
getChatById,
|
|
4106
4137
|
// Mutations
|
|
4107
4138
|
upsert,
|
|
4108
4139
|
upsertMany,
|
|
4109
|
-
|
|
4140
|
+
markDeleted
|
|
4110
4141
|
};
|
|
4111
4142
|
}
|
|
4112
4143
|
function createAi(config) {
|
|
@@ -4116,7 +4147,6 @@ function createAi(config) {
|
|
|
4116
4147
|
false
|
|
4117
4148
|
// AI doesn't have actors (yet, but it will)
|
|
4118
4149
|
);
|
|
4119
|
-
const clientId = nanoid(7);
|
|
4120
4150
|
const chatsStore = createStore_forUserAiChats();
|
|
4121
4151
|
const toolsStore = createStore_forTools();
|
|
4122
4152
|
const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
|
|
@@ -4196,7 +4226,11 @@ function createAi(config) {
|
|
|
4196
4226
|
context.messagesStore.upsert(msg.message);
|
|
4197
4227
|
break;
|
|
4198
4228
|
}
|
|
4229
|
+
case "warning":
|
|
4230
|
+
warn(msg.message);
|
|
4231
|
+
break;
|
|
4199
4232
|
case "error":
|
|
4233
|
+
error2(msg.error);
|
|
4200
4234
|
break;
|
|
4201
4235
|
case "rebooted":
|
|
4202
4236
|
context.messagesStore.failAllPending();
|
|
@@ -4207,7 +4241,7 @@ function createAi(config) {
|
|
|
4207
4241
|
context.messagesStore.remove(m.chatId, m.id);
|
|
4208
4242
|
}
|
|
4209
4243
|
for (const chatId of msg["-chats"] ?? []) {
|
|
4210
|
-
context.chatsStore.
|
|
4244
|
+
context.chatsStore.markDeleted(chatId);
|
|
4211
4245
|
context.messagesStore.removeByChatId(chatId);
|
|
4212
4246
|
}
|
|
4213
4247
|
for (const chatId of msg.clear ?? []) {
|
|
@@ -4233,7 +4267,7 @@ function createAi(config) {
|
|
|
4233
4267
|
context.chatsStore.upsert(msg.chat);
|
|
4234
4268
|
break;
|
|
4235
4269
|
case "delete-chat":
|
|
4236
|
-
context.chatsStore.
|
|
4270
|
+
context.chatsStore.markDeleted(msg.chatId);
|
|
4237
4271
|
context.messagesStore.removeByChatId(msg.chatId);
|
|
4238
4272
|
break;
|
|
4239
4273
|
case "get-message-tree":
|
|
@@ -4277,7 +4311,13 @@ function createAi(config) {
|
|
|
4277
4311
|
);
|
|
4278
4312
|
}
|
|
4279
4313
|
});
|
|
4314
|
+
function connectInitially() {
|
|
4315
|
+
if (managedSocket.getStatus() === "initial") {
|
|
4316
|
+
managedSocket.connect();
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4280
4319
|
async function sendClientMsgWithResponse(msg) {
|
|
4320
|
+
connectInitially();
|
|
4281
4321
|
if (managedSocket.getStatus() !== "connected") {
|
|
4282
4322
|
await managedSocket.events.didConnect.waitUntil();
|
|
4283
4323
|
}
|
|
@@ -4331,70 +4371,65 @@ function createAi(config) {
|
|
|
4331
4371
|
function updateKnowledge(layerKey, data, key = nanoid()) {
|
|
4332
4372
|
context.knowledge.updateKnowledge(layerKey, key, data);
|
|
4333
4373
|
}
|
|
4334
|
-
function
|
|
4335
|
-
return context.knowledge.get();
|
|
4336
|
-
}
|
|
4337
|
-
async function setToolResult(chatId, messageId, toolCallId, result, options) {
|
|
4374
|
+
async function setToolResult(chatId, messageId, invocationId, result, options) {
|
|
4338
4375
|
const knowledge = context.knowledge.get();
|
|
4339
|
-
|
|
4376
|
+
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4377
|
+
const resp = await sendClientMsgWithResponse({
|
|
4340
4378
|
cmd: "set-tool-result",
|
|
4341
4379
|
chatId,
|
|
4342
4380
|
messageId,
|
|
4343
|
-
|
|
4344
|
-
clientId,
|
|
4381
|
+
invocationId,
|
|
4345
4382
|
result,
|
|
4346
4383
|
generationOptions: {
|
|
4347
4384
|
copilotId: options?.copilotId,
|
|
4348
4385
|
stream: options?.stream,
|
|
4349
4386
|
timeout: options?.timeout,
|
|
4387
|
+
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4388
|
+
// from the global context
|
|
4350
4389
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4351
|
-
tools:
|
|
4352
|
-
name: tool.name,
|
|
4353
|
-
description: tool.definition.description,
|
|
4354
|
-
parameters: tool.definition.parameters
|
|
4355
|
-
}))
|
|
4390
|
+
tools: tools.length > 0 ? tools : void 0
|
|
4356
4391
|
}
|
|
4357
4392
|
});
|
|
4393
|
+
if (resp.ok) {
|
|
4394
|
+
messagesStore.markMine(resp.message.id);
|
|
4395
|
+
}
|
|
4358
4396
|
}
|
|
4359
4397
|
return Object.defineProperty(
|
|
4360
4398
|
{
|
|
4361
4399
|
[kInternal]: {
|
|
4362
4400
|
context
|
|
4363
4401
|
},
|
|
4364
|
-
|
|
4365
|
-
reconnect: () => managedSocket.reconnect(),
|
|
4402
|
+
connectInitially,
|
|
4403
|
+
// reconnect: () => managedSocket.reconnect(),
|
|
4366
4404
|
disconnect: () => managedSocket.disconnect(),
|
|
4367
4405
|
getChats,
|
|
4368
4406
|
getOrCreateChat,
|
|
4369
4407
|
deleteChat: (chatId) => {
|
|
4370
|
-
return sendClientMsgWithResponse({
|
|
4371
|
-
cmd: "delete-chat",
|
|
4372
|
-
chatId
|
|
4373
|
-
});
|
|
4408
|
+
return sendClientMsgWithResponse({ cmd: "delete-chat", chatId });
|
|
4374
4409
|
},
|
|
4375
4410
|
getMessageTree,
|
|
4376
4411
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4377
4412
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4378
4413
|
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4379
4414
|
const knowledge = context.knowledge.get();
|
|
4380
|
-
|
|
4415
|
+
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4416
|
+
const resp = await sendClientMsgWithResponse({
|
|
4381
4417
|
cmd: "ask-in-chat",
|
|
4382
4418
|
chatId,
|
|
4383
4419
|
sourceMessage: userMessage,
|
|
4384
4420
|
targetMessageId,
|
|
4385
|
-
clientId,
|
|
4386
4421
|
generationOptions: {
|
|
4387
4422
|
copilotId: options?.copilotId,
|
|
4388
4423
|
stream: options?.stream,
|
|
4389
4424
|
timeout: options?.timeout,
|
|
4425
|
+
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4426
|
+
// from the global context
|
|
4390
4427
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4391
|
-
tools:
|
|
4392
|
-
name: tool.name,
|
|
4393
|
-
description: tool.definition.description,
|
|
4394
|
-
parameters: tool.definition.parameters
|
|
4395
|
-
}))
|
|
4428
|
+
tools: tools.length > 0 ? tools : void 0
|
|
4396
4429
|
}
|
|
4397
4430
|
});
|
|
4431
|
+
messagesStore.markMine(resp.targetMessage.id);
|
|
4432
|
+
return resp;
|
|
4398
4433
|
},
|
|
4399
4434
|
abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
|
|
4400
4435
|
setToolResult,
|
|
@@ -4402,15 +4437,13 @@ function createAi(config) {
|
|
|
4402
4437
|
signals: {
|
|
4403
4438
|
chats\u03A3: context.chatsStore.chats\u03A3,
|
|
4404
4439
|
getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
|
|
4405
|
-
|
|
4406
|
-
getToolDefinition\u03A3: context.toolsStore.getToolDefinition\u03A3
|
|
4440
|
+
getTool\u03A3: context.toolsStore.getTool\u03A3
|
|
4407
4441
|
},
|
|
4442
|
+
getChatById: context.chatsStore.getChatById,
|
|
4408
4443
|
registerKnowledgeLayer,
|
|
4409
4444
|
deregisterKnowledgeLayer,
|
|
4410
4445
|
updateKnowledge,
|
|
4411
|
-
|
|
4412
|
-
registerChatTool: context.toolsStore.addToolDefinition,
|
|
4413
|
-
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4446
|
+
registerTool: context.toolsStore.registerTool
|
|
4414
4447
|
},
|
|
4415
4448
|
kInternal,
|
|
4416
4449
|
{ enumerable: false }
|
|
@@ -4426,7 +4459,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
|
|
|
4426
4459
|
}
|
|
4427
4460
|
const url2 = new URL(baseUrl);
|
|
4428
4461
|
url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
|
|
4429
|
-
url2.pathname = "/ai/
|
|
4462
|
+
url2.pathname = "/ai/v4";
|
|
4430
4463
|
if (authValue.type === "secret") {
|
|
4431
4464
|
url2.searchParams.set("tok", authValue.token.raw);
|
|
4432
4465
|
} else if (authValue.type === "public") {
|
|
@@ -7743,7 +7776,7 @@ var LiveblocksError = class _LiveblocksError extends Error {
|
|
|
7743
7776
|
get roomId() {
|
|
7744
7777
|
return this.context.roomId;
|
|
7745
7778
|
}
|
|
7746
|
-
/** @
|
|
7779
|
+
/** @internal Use `context.code` instead, to enable type narrowing */
|
|
7747
7780
|
get code() {
|
|
7748
7781
|
return this.context.code;
|
|
7749
7782
|
}
|
|
@@ -7813,11 +7846,9 @@ function defaultMessageFromContext(context) {
|
|
|
7813
7846
|
return "Could not mark all inbox notifications as read";
|
|
7814
7847
|
case "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR":
|
|
7815
7848
|
return "Could not delete all inbox notifications";
|
|
7816
|
-
case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
|
|
7817
|
-
return "Could not update notification settings";
|
|
7818
7849
|
case "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR":
|
|
7819
7850
|
return "Could not update room subscription settings";
|
|
7820
|
-
case "
|
|
7851
|
+
case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
|
|
7821
7852
|
return "Could not update notification settings";
|
|
7822
7853
|
default:
|
|
7823
7854
|
return assertNever(context, "Unhandled case");
|
|
@@ -8950,8 +8981,6 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
8950
8981
|
others: eventHub.others.observable,
|
|
8951
8982
|
self: eventHub.self.observable,
|
|
8952
8983
|
myPresence: eventHub.myPresence.observable,
|
|
8953
|
-
/** @deprecated */
|
|
8954
|
-
storage: eventHub.storageBatch.observable,
|
|
8955
8984
|
storageBatch: eventHub.storageBatch.observable,
|
|
8956
8985
|
history: eventHub.history.observable,
|
|
8957
8986
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
@@ -9413,8 +9442,26 @@ function createClient(options) {
|
|
|
9413
9442
|
baseUrl,
|
|
9414
9443
|
clientOptions.polyfills?.WebSocket
|
|
9415
9444
|
),
|
|
9416
|
-
authenticate:
|
|
9417
|
-
|
|
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
|
|
9418
9465
|
}
|
|
9419
9466
|
});
|
|
9420
9467
|
function teardownRoom(room) {
|
|
@@ -9468,7 +9515,7 @@ function createClient(options) {
|
|
|
9468
9515
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
9469
9516
|
baseUrl,
|
|
9470
9517
|
errorEventSource: liveblocksErrorSource,
|
|
9471
|
-
largeMessageStrategy: clientOptions.largeMessageStrategy
|
|
9518
|
+
largeMessageStrategy: clientOptions.largeMessageStrategy,
|
|
9472
9519
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
9473
9520
|
roomHttpClient: httpClient,
|
|
9474
9521
|
createSyncSource
|
|
@@ -9748,21 +9795,30 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
9748
9795
|
}
|
|
9749
9796
|
}
|
|
9750
9797
|
}
|
|
9751
|
-
function
|
|
9752
|
-
const
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
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;
|
|
9759
9812
|
}
|
|
9760
9813
|
async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
9761
9814
|
const resolvedUsers = /* @__PURE__ */ new Map();
|
|
9762
9815
|
if (!resolveUsers) {
|
|
9763
9816
|
return resolvedUsers;
|
|
9764
9817
|
}
|
|
9765
|
-
const userIds =
|
|
9818
|
+
const userIds = getMentionsFromCommentBody(
|
|
9819
|
+
body,
|
|
9820
|
+
(mention) => mention.kind === "user"
|
|
9821
|
+
).map((mention) => mention.id);
|
|
9766
9822
|
const users = await resolveUsers({
|
|
9767
9823
|
userIds
|
|
9768
9824
|
});
|
|
@@ -10525,11 +10581,8 @@ var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
|
|
|
10525
10581
|
|
|
10526
10582
|
// src/index.ts
|
|
10527
10583
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
10528
|
-
var CommentsApiError = HttpError;
|
|
10529
|
-
var NotificationsApiError = HttpError;
|
|
10530
10584
|
export {
|
|
10531
10585
|
ClientMsgCode,
|
|
10532
|
-
CommentsApiError,
|
|
10533
10586
|
CrdtType,
|
|
10534
10587
|
DefaultMap,
|
|
10535
10588
|
Deque,
|
|
@@ -10540,7 +10593,6 @@ export {
|
|
|
10540
10593
|
LiveObject,
|
|
10541
10594
|
LiveblocksError,
|
|
10542
10595
|
MutableSignal,
|
|
10543
|
-
NotificationsApiError,
|
|
10544
10596
|
OpCode,
|
|
10545
10597
|
Permission,
|
|
10546
10598
|
Promise_withResolvers,
|
|
@@ -10574,6 +10626,7 @@ export {
|
|
|
10574
10626
|
createManagedPool,
|
|
10575
10627
|
createNotificationSettings,
|
|
10576
10628
|
createThreadId,
|
|
10629
|
+
defineAiTool,
|
|
10577
10630
|
deprecate,
|
|
10578
10631
|
deprecateIf,
|
|
10579
10632
|
detectDupes,
|
|
@@ -10581,7 +10634,7 @@ export {
|
|
|
10581
10634
|
errorIf,
|
|
10582
10635
|
freeze,
|
|
10583
10636
|
generateCommentUrl,
|
|
10584
|
-
|
|
10637
|
+
getMentionsFromCommentBody,
|
|
10585
10638
|
getSubscriptionKey,
|
|
10586
10639
|
html,
|
|
10587
10640
|
htmlSafe,
|