@liveblocks/core 2.25.0-aiprivatebeta1 → 2.25.0-aiprivatebeta10
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 +325 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +258 -112
- package/dist/index.d.ts +258 -112
- package/dist/index.js +241 -187
- 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-aiprivatebeta10";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -188,6 +188,9 @@ var warnWithTitle = wrapWithTitle("warn");
|
|
|
188
188
|
var errorWithTitle = wrapWithTitle("error");
|
|
189
189
|
|
|
190
190
|
// src/lib/guards.ts
|
|
191
|
+
function isDefined(value) {
|
|
192
|
+
return value !== null && value !== void 0;
|
|
193
|
+
}
|
|
191
194
|
function isPlainObject(blob) {
|
|
192
195
|
return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
|
|
193
196
|
}
|
|
@@ -3685,11 +3688,6 @@ function parseAuthToken(rawTokenString) {
|
|
|
3685
3688
|
function appendDelta(content, delta) {
|
|
3686
3689
|
const lastPart = content[content.length - 1];
|
|
3687
3690
|
switch (delta.type) {
|
|
3688
|
-
case "reasoning":
|
|
3689
|
-
case "text":
|
|
3690
|
-
case "tool-call":
|
|
3691
|
-
content.push(delta);
|
|
3692
|
-
break;
|
|
3693
3691
|
case "text-delta":
|
|
3694
3692
|
if (_optionalChain([lastPart, 'optionalAccess', _55 => _55.type]) === "text") {
|
|
3695
3693
|
lastPart.text += delta.textDelta;
|
|
@@ -3700,15 +3698,16 @@ function appendDelta(content, delta) {
|
|
|
3700
3698
|
case "reasoning-delta":
|
|
3701
3699
|
if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "reasoning") {
|
|
3702
3700
|
lastPart.text += delta.textDelta;
|
|
3703
|
-
lastPart.signature ??= delta.signature;
|
|
3704
3701
|
} else {
|
|
3705
3702
|
content.push({
|
|
3706
3703
|
type: "reasoning",
|
|
3707
|
-
text: _nullishCoalesce(delta.textDelta, () => ( ""))
|
|
3708
|
-
signature: delta.signature
|
|
3704
|
+
text: _nullishCoalesce(delta.textDelta, () => ( ""))
|
|
3709
3705
|
});
|
|
3710
3706
|
}
|
|
3711
3707
|
break;
|
|
3708
|
+
case "tool-invocation":
|
|
3709
|
+
content.push(delta);
|
|
3710
|
+
break;
|
|
3712
3711
|
default:
|
|
3713
3712
|
return assertNever(delta, "Unhandled case");
|
|
3714
3713
|
}
|
|
@@ -3716,7 +3715,68 @@ function appendDelta(content, delta) {
|
|
|
3716
3715
|
|
|
3717
3716
|
// src/ai.ts
|
|
3718
3717
|
var DEFAULT_REQUEST_TIMEOUT = 4e3;
|
|
3719
|
-
|
|
3718
|
+
function defineAiTool() {
|
|
3719
|
+
return (def) => {
|
|
3720
|
+
return def;
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3723
|
+
var KnowledgeStack = class {
|
|
3724
|
+
#_layers;
|
|
3725
|
+
#stack;
|
|
3726
|
+
// / \
|
|
3727
|
+
// knowledge key "layer" key
|
|
3728
|
+
// (random, or optionally (one entry per mounted component)
|
|
3729
|
+
// set by user)
|
|
3730
|
+
#_cache;
|
|
3731
|
+
constructor() {
|
|
3732
|
+
this.#_layers = /* @__PURE__ */ new Set();
|
|
3733
|
+
this.#stack = new DefaultMap(
|
|
3734
|
+
() => /* @__PURE__ */ new Map()
|
|
3735
|
+
);
|
|
3736
|
+
this.#_cache = void 0;
|
|
3737
|
+
}
|
|
3738
|
+
// Typically a useId()
|
|
3739
|
+
registerLayer(uniqueLayerId) {
|
|
3740
|
+
const layerKey = uniqueLayerId;
|
|
3741
|
+
if (this.#_layers.has(layerKey))
|
|
3742
|
+
raise(`Layer '${layerKey}' already exists, provide a unique layer id`);
|
|
3743
|
+
this.#_layers.add(layerKey);
|
|
3744
|
+
return layerKey;
|
|
3745
|
+
}
|
|
3746
|
+
deregisterLayer(layerKey) {
|
|
3747
|
+
this.#_layers.delete(layerKey);
|
|
3748
|
+
let deleted = false;
|
|
3749
|
+
for (const [key, knowledge] of this.#stack) {
|
|
3750
|
+
if (knowledge.delete(layerKey)) {
|
|
3751
|
+
deleted = true;
|
|
3752
|
+
}
|
|
3753
|
+
if (knowledge.size === 0)
|
|
3754
|
+
this.#stack.delete(key);
|
|
3755
|
+
}
|
|
3756
|
+
if (deleted) {
|
|
3757
|
+
this.invalidate();
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
get() {
|
|
3761
|
+
return this.#_cache ??= this.#recompute();
|
|
3762
|
+
}
|
|
3763
|
+
invalidate() {
|
|
3764
|
+
this.#_cache = void 0;
|
|
3765
|
+
}
|
|
3766
|
+
#recompute() {
|
|
3767
|
+
return Array.from(this.#stack.values()).flatMap(
|
|
3768
|
+
(layer) => (
|
|
3769
|
+
// Return only the last item (returns [] when empty)
|
|
3770
|
+
Array.from(layer.values()).slice(-1).filter(isDefined)
|
|
3771
|
+
)
|
|
3772
|
+
);
|
|
3773
|
+
}
|
|
3774
|
+
updateKnowledge(layerKey, key, data) {
|
|
3775
|
+
if (!this.#_layers.has(layerKey)) raise(`Unknown layer key: ${layerKey}`);
|
|
3776
|
+
this.#stack.getOrCreate(key).set(layerKey, data);
|
|
3777
|
+
this.invalidate();
|
|
3778
|
+
}
|
|
3779
|
+
};
|
|
3720
3780
|
function now() {
|
|
3721
3781
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3722
3782
|
}
|
|
@@ -3730,6 +3790,11 @@ function createStore_forTools() {
|
|
|
3730
3790
|
return toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(toolName);
|
|
3731
3791
|
}
|
|
3732
3792
|
function addToolDefinition(chatId, name, definition) {
|
|
3793
|
+
if (!definition.execute && !definition.render) {
|
|
3794
|
+
throw new Error(
|
|
3795
|
+
"A tool definition must have an execute() function, a render property, or both."
|
|
3796
|
+
);
|
|
3797
|
+
}
|
|
3733
3798
|
toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name).set(definition);
|
|
3734
3799
|
}
|
|
3735
3800
|
function removeToolDefinition(chatId, toolName) {
|
|
@@ -3751,13 +3816,15 @@ function createStore_forTools() {
|
|
|
3751
3816
|
}).filter((tool) => tool !== null);
|
|
3752
3817
|
}
|
|
3753
3818
|
return {
|
|
3754
|
-
|
|
3819
|
+
getToolDefinition\u03A3,
|
|
3755
3820
|
getToolsForChat,
|
|
3756
3821
|
addToolDefinition,
|
|
3757
3822
|
removeToolDefinition
|
|
3758
3823
|
};
|
|
3759
3824
|
}
|
|
3760
|
-
function createStore_forChatMessages() {
|
|
3825
|
+
function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
3826
|
+
const autoExecutableMessages = /* @__PURE__ */ new Set();
|
|
3827
|
+
const seenToolCallIds = /* @__PURE__ */ new Set();
|
|
3761
3828
|
const messagePoolByChatId\u03A3 = new DefaultMap(
|
|
3762
3829
|
(_chatId) => new MutableSignal(
|
|
3763
3830
|
new TreePool(
|
|
@@ -3767,7 +3834,7 @@ function createStore_forChatMessages() {
|
|
|
3767
3834
|
)
|
|
3768
3835
|
)
|
|
3769
3836
|
);
|
|
3770
|
-
const
|
|
3837
|
+
const generatingMessages\u03A3 = new MutableSignal(
|
|
3771
3838
|
/* @__PURE__ */ new Map()
|
|
3772
3839
|
);
|
|
3773
3840
|
function createOptimistically(chatId, role, parentId, third) {
|
|
@@ -3781,7 +3848,8 @@ function createStore_forChatMessages() {
|
|
|
3781
3848
|
role,
|
|
3782
3849
|
parentId,
|
|
3783
3850
|
createdAt,
|
|
3784
|
-
content
|
|
3851
|
+
content,
|
|
3852
|
+
_optimistic: true
|
|
3785
3853
|
});
|
|
3786
3854
|
} else {
|
|
3787
3855
|
upsert({
|
|
@@ -3790,8 +3858,9 @@ function createStore_forChatMessages() {
|
|
|
3790
3858
|
role,
|
|
3791
3859
|
parentId,
|
|
3792
3860
|
createdAt,
|
|
3793
|
-
status: "
|
|
3794
|
-
contentSoFar: []
|
|
3861
|
+
status: "generating",
|
|
3862
|
+
contentSoFar: [],
|
|
3863
|
+
_optimistic: true
|
|
3795
3864
|
});
|
|
3796
3865
|
}
|
|
3797
3866
|
return id;
|
|
@@ -3808,7 +3877,7 @@ function createStore_forChatMessages() {
|
|
|
3808
3877
|
if (!chatMsgs\u03A3) return;
|
|
3809
3878
|
const existing = chatMsgs\u03A3.get().get(messageId);
|
|
3810
3879
|
if (!existing || existing.deletedAt) return;
|
|
3811
|
-
if (existing.role === "assistant" &&
|
|
3880
|
+
if (existing.role === "assistant" && existing.status !== "completed") {
|
|
3812
3881
|
upsert({ ...existing, deletedAt: now(), contentSoFar: [] });
|
|
3813
3882
|
} else {
|
|
3814
3883
|
upsert({ ...existing, deletedAt: now(), content: [] });
|
|
@@ -3823,19 +3892,59 @@ function createStore_forChatMessages() {
|
|
|
3823
3892
|
batch(() => {
|
|
3824
3893
|
const chatMsgs\u03A3 = messagePoolByChatId\u03A3.getOrCreate(message.chatId);
|
|
3825
3894
|
chatMsgs\u03A3.mutate((pool) => pool.upsert(message));
|
|
3826
|
-
if (message.role === "assistant" && message.status === "
|
|
3827
|
-
|
|
3895
|
+
if (message.role === "assistant" && message.status === "generating") {
|
|
3896
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3828
3897
|
lut.set(message.id, structuredClone(message));
|
|
3829
3898
|
});
|
|
3830
3899
|
} else {
|
|
3831
|
-
|
|
3900
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3832
3901
|
lut.delete(message.id);
|
|
3833
3902
|
});
|
|
3834
3903
|
}
|
|
3904
|
+
if (message.role === "assistant" && message.status === "awaiting-tool") {
|
|
3905
|
+
for (const toolCall of message.contentSoFar.filter(
|
|
3906
|
+
(part) => part.type === "tool-invocation" && part.status === "executing"
|
|
3907
|
+
)) {
|
|
3908
|
+
if (seenToolCallIds.has(toolCall.toolCallId)) {
|
|
3909
|
+
continue;
|
|
3910
|
+
}
|
|
3911
|
+
seenToolCallIds.add(toolCall.toolCallId);
|
|
3912
|
+
const toolDef = toolsStore.getToolDefinition\u03A3(message.chatId, toolCall.toolName).get();
|
|
3913
|
+
const respondSync = (result) => {
|
|
3914
|
+
setToolResult(
|
|
3915
|
+
message.chatId,
|
|
3916
|
+
message.id,
|
|
3917
|
+
toolCall.toolCallId,
|
|
3918
|
+
result
|
|
3919
|
+
// TODO Pass in AiGenerationOptions here, or make the backend use the same options
|
|
3920
|
+
).catch((err) => {
|
|
3921
|
+
error2(
|
|
3922
|
+
`Error trying to respond to tool-call: ${String(err)} (in respond())`
|
|
3923
|
+
);
|
|
3924
|
+
});
|
|
3925
|
+
};
|
|
3926
|
+
const executeFn = _optionalChain([toolDef, 'optionalAccess', _57 => _57.execute]);
|
|
3927
|
+
if (executeFn && autoExecutableMessages.has(message.id)) {
|
|
3928
|
+
(async () => {
|
|
3929
|
+
const result = await executeFn(toolCall.args, {
|
|
3930
|
+
toolName: toolCall.toolName,
|
|
3931
|
+
toolCallId: toolCall.toolCallId
|
|
3932
|
+
});
|
|
3933
|
+
respondSync(result);
|
|
3934
|
+
})().catch((err) => {
|
|
3935
|
+
error2(
|
|
3936
|
+
`Error trying to respond to tool-call: ${String(err)} (in execute())`
|
|
3937
|
+
);
|
|
3938
|
+
});
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
} else {
|
|
3942
|
+
autoExecutableMessages.delete(message.id);
|
|
3943
|
+
}
|
|
3835
3944
|
});
|
|
3836
3945
|
}
|
|
3837
3946
|
function addDelta(messageId, delta) {
|
|
3838
|
-
|
|
3947
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3839
3948
|
const message = lut.get(messageId);
|
|
3840
3949
|
if (message === void 0) return false;
|
|
3841
3950
|
appendDelta(message.contentSoFar, delta);
|
|
@@ -3843,10 +3952,10 @@ function createStore_forChatMessages() {
|
|
|
3843
3952
|
return true;
|
|
3844
3953
|
});
|
|
3845
3954
|
}
|
|
3846
|
-
function*
|
|
3955
|
+
function* iterGeneratingMessages() {
|
|
3847
3956
|
for (const chatMsgs\u03A3 of messagePoolByChatId\u03A3.values()) {
|
|
3848
3957
|
for (const m of chatMsgs\u03A3.get()) {
|
|
3849
|
-
if (m.role === "assistant" && m.status === "
|
|
3958
|
+
if (m.role === "assistant" && m.status === "generating" && !m._optimistic) {
|
|
3850
3959
|
yield m;
|
|
3851
3960
|
}
|
|
3852
3961
|
}
|
|
@@ -3854,9 +3963,18 @@ function createStore_forChatMessages() {
|
|
|
3854
3963
|
}
|
|
3855
3964
|
function failAllPending() {
|
|
3856
3965
|
batch(() => {
|
|
3857
|
-
|
|
3966
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3967
|
+
let deleted = false;
|
|
3968
|
+
for (const [k, v] of lut) {
|
|
3969
|
+
if (!v._optimistic) {
|
|
3970
|
+
lut.delete(k);
|
|
3971
|
+
deleted = true;
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
return deleted;
|
|
3975
|
+
});
|
|
3858
3976
|
upsertMany(
|
|
3859
|
-
Array.from(
|
|
3977
|
+
Array.from(iterGeneratingMessages()).map(
|
|
3860
3978
|
(message) => ({
|
|
3861
3979
|
...message,
|
|
3862
3980
|
status: "failed",
|
|
@@ -3891,11 +4009,20 @@ function createStore_forChatMessages() {
|
|
|
3891
4009
|
}
|
|
3892
4010
|
function selectSpine(leaf) {
|
|
3893
4011
|
const spine = [];
|
|
4012
|
+
let lastVisitedMessage = null;
|
|
3894
4013
|
for (const message2 of pool.walkUp(leaf.id)) {
|
|
3895
|
-
const prev = _nullishCoalesce(_optionalChain([first, 'call',
|
|
3896
|
-
const next = _nullishCoalesce(_optionalChain([first, 'call',
|
|
4014
|
+
const prev = _nullishCoalesce(_optionalChain([first, 'call', _58 => _58(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _59 => _59.id]), () => ( null));
|
|
4015
|
+
const next = _nullishCoalesce(_optionalChain([first, 'call', _60 => _60(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _61 => _61.id]), () => ( null));
|
|
3897
4016
|
if (!message2.deletedAt || prev || next) {
|
|
3898
|
-
|
|
4017
|
+
const node = {
|
|
4018
|
+
...message2,
|
|
4019
|
+
navigation: { parent: null, prev, next }
|
|
4020
|
+
};
|
|
4021
|
+
if (lastVisitedMessage !== null) {
|
|
4022
|
+
lastVisitedMessage.navigation.parent = node.id;
|
|
4023
|
+
}
|
|
4024
|
+
lastVisitedMessage = node;
|
|
4025
|
+
spine.push(node);
|
|
3899
4026
|
}
|
|
3900
4027
|
}
|
|
3901
4028
|
return spine.reverse();
|
|
@@ -3921,18 +4048,6 @@ function createStore_forChatMessages() {
|
|
|
3921
4048
|
}
|
|
3922
4049
|
return fallback();
|
|
3923
4050
|
}
|
|
3924
|
-
function getLatestUserMessageAncestor(chatId, messageId) {
|
|
3925
|
-
const pool = messagePoolByChatId\u03A3.getOrCreate(chatId).get();
|
|
3926
|
-
const message = pool.get(messageId);
|
|
3927
|
-
if (!message) return null;
|
|
3928
|
-
if (message.role === "user") return message.id;
|
|
3929
|
-
for (const m of pool.walkUp(message.id)) {
|
|
3930
|
-
if (m.role === "user" && !m.deletedAt) {
|
|
3931
|
-
return m.id;
|
|
3932
|
-
}
|
|
3933
|
-
}
|
|
3934
|
-
return null;
|
|
3935
|
-
}
|
|
3936
4051
|
const immutableMessagesByBranch = new DefaultMap((chatId) => {
|
|
3937
4052
|
return new DefaultMap((branchId) => {
|
|
3938
4053
|
const messages\u03A3 = DerivedSignal.from(() => {
|
|
@@ -3940,16 +4055,16 @@ function createStore_forChatMessages() {
|
|
|
3940
4055
|
return selectBranch(pool, branchId);
|
|
3941
4056
|
}, shallow2);
|
|
3942
4057
|
return DerivedSignal.from(() => {
|
|
3943
|
-
const
|
|
4058
|
+
const generatingMessages = generatingMessages\u03A3.get();
|
|
3944
4059
|
return messages\u03A3.get().map((message) => {
|
|
3945
|
-
if (message.role !== "assistant" || message.status !== "
|
|
4060
|
+
if (message.role !== "assistant" || message.status !== "generating") {
|
|
3946
4061
|
return message;
|
|
3947
4062
|
}
|
|
3948
|
-
const
|
|
3949
|
-
if (
|
|
4063
|
+
const generatingMessage = generatingMessages.get(message.id);
|
|
4064
|
+
if (generatingMessage === void 0) return message;
|
|
3950
4065
|
return {
|
|
3951
4066
|
...message,
|
|
3952
|
-
contentSoFar:
|
|
4067
|
+
contentSoFar: generatingMessage.contentSoFar
|
|
3953
4068
|
};
|
|
3954
4069
|
});
|
|
3955
4070
|
}, shallow);
|
|
@@ -3958,21 +4073,10 @@ function createStore_forChatMessages() {
|
|
|
3958
4073
|
function getChatMessagesForBranch\u03A3(chatId, branch) {
|
|
3959
4074
|
return immutableMessagesByBranch.getOrCreate(chatId).getOrCreate(branch || null);
|
|
3960
4075
|
}
|
|
3961
|
-
const messagesByChatId\u03A3 = new DefaultMap((chatId) => {
|
|
3962
|
-
return DerivedSignal.from(() => {
|
|
3963
|
-
const pool = messagePoolByChatId\u03A3.getOrCreate(chatId).get();
|
|
3964
|
-
return Array.from(pool.sorted);
|
|
3965
|
-
});
|
|
3966
|
-
});
|
|
3967
|
-
function getMessagesForChat\u03A3(chatId) {
|
|
3968
|
-
return messagesByChatId\u03A3.getOrCreate(chatId);
|
|
3969
|
-
}
|
|
3970
4076
|
return {
|
|
3971
4077
|
// Readers
|
|
3972
4078
|
getMessageById,
|
|
3973
4079
|
getChatMessagesForBranch\u03A3,
|
|
3974
|
-
getMessagesForChat\u03A3,
|
|
3975
|
-
getLatestUserMessageAncestor,
|
|
3976
4080
|
// Mutations
|
|
3977
4081
|
createOptimistically,
|
|
3978
4082
|
upsert,
|
|
@@ -3980,7 +4084,10 @@ function createStore_forChatMessages() {
|
|
|
3980
4084
|
remove,
|
|
3981
4085
|
removeByChatId,
|
|
3982
4086
|
addDelta,
|
|
3983
|
-
failAllPending
|
|
4087
|
+
failAllPending,
|
|
4088
|
+
allowAutoExecuteToolCall(messageId) {
|
|
4089
|
+
autoExecutableMessages.add(messageId);
|
|
4090
|
+
}
|
|
3984
4091
|
};
|
|
3985
4092
|
}
|
|
3986
4093
|
function createStore_forUserAiChats() {
|
|
@@ -3988,7 +4095,7 @@ function createStore_forUserAiChats() {
|
|
|
3988
4095
|
SortedList.with((x, y) => y.createdAt < x.createdAt)
|
|
3989
4096
|
);
|
|
3990
4097
|
const chats\u03A3 = DerivedSignal.from(
|
|
3991
|
-
() => Array.from(mutable\u03A3.get()).filter((c) => !c.
|
|
4098
|
+
() => Array.from(mutable\u03A3.get()).filter((c) => !c.deletedAt)
|
|
3992
4099
|
);
|
|
3993
4100
|
function upsertMany(chats) {
|
|
3994
4101
|
mutable\u03A3.mutate((list) => {
|
|
@@ -4004,8 +4111,12 @@ function createStore_forUserAiChats() {
|
|
|
4004
4111
|
function remove(chatId) {
|
|
4005
4112
|
mutable\u03A3.mutate((list) => list.removeBy((c) => c.id === chatId, 1));
|
|
4006
4113
|
}
|
|
4114
|
+
function getChatById(chatId) {
|
|
4115
|
+
return Array.from(mutable\u03A3.get()).find((chat) => chat.id === chatId);
|
|
4116
|
+
}
|
|
4007
4117
|
return {
|
|
4008
4118
|
chats\u03A3,
|
|
4119
|
+
getChatById,
|
|
4009
4120
|
// Mutations
|
|
4010
4121
|
upsert,
|
|
4011
4122
|
upsertMany,
|
|
@@ -4019,10 +4130,9 @@ function createAi(config) {
|
|
|
4019
4130
|
false
|
|
4020
4131
|
// AI doesn't have actors (yet, but it will)
|
|
4021
4132
|
);
|
|
4022
|
-
const clientId = nanoid(7);
|
|
4023
4133
|
const chatsStore = createStore_forUserAiChats();
|
|
4024
|
-
const messagesStore = createStore_forChatMessages();
|
|
4025
4134
|
const toolsStore = createStore_forTools();
|
|
4135
|
+
const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
|
|
4026
4136
|
const context = {
|
|
4027
4137
|
staticSessionInfoSig: new Signal(null),
|
|
4028
4138
|
dynamicSessionInfoSig: new Signal(null),
|
|
@@ -4030,11 +4140,10 @@ function createAi(config) {
|
|
|
4030
4140
|
chatsStore,
|
|
4031
4141
|
messagesStore,
|
|
4032
4142
|
toolsStore,
|
|
4033
|
-
|
|
4143
|
+
knowledge: new KnowledgeStack()
|
|
4034
4144
|
};
|
|
4035
4145
|
let lastTokenKey;
|
|
4036
|
-
function onStatusDidChange(
|
|
4037
|
-
warn("onStatusDidChange", newStatus);
|
|
4146
|
+
function onStatusDidChange(_newStatus) {
|
|
4038
4147
|
const authValue = managedSocket.authValue;
|
|
4039
4148
|
if (authValue !== null) {
|
|
4040
4149
|
const tokenKey = getBearerTokenFromAuthValue(authValue);
|
|
@@ -4070,7 +4179,6 @@ function createAi(config) {
|
|
|
4070
4179
|
}
|
|
4071
4180
|
}
|
|
4072
4181
|
function onDidConnect() {
|
|
4073
|
-
warn("onDidConnect");
|
|
4074
4182
|
}
|
|
4075
4183
|
function onDidDisconnect() {
|
|
4076
4184
|
warn("onDidDisconnect");
|
|
@@ -4090,7 +4198,7 @@ function createAi(config) {
|
|
|
4090
4198
|
if ("event" in msg) {
|
|
4091
4199
|
switch (msg.event) {
|
|
4092
4200
|
case "cmd-failed":
|
|
4093
|
-
_optionalChain([pendingCmd, 'optionalAccess',
|
|
4201
|
+
_optionalChain([pendingCmd, 'optionalAccess', _62 => _62.reject, 'call', _63 => _63(new Error(msg.error))]);
|
|
4094
4202
|
break;
|
|
4095
4203
|
case "delta": {
|
|
4096
4204
|
const { id, delta } = msg;
|
|
@@ -4134,7 +4242,7 @@ function createAi(config) {
|
|
|
4134
4242
|
case "get-chats":
|
|
4135
4243
|
context.chatsStore.upsertMany(msg.chats);
|
|
4136
4244
|
break;
|
|
4137
|
-
case "create-chat":
|
|
4245
|
+
case "get-or-create-chat":
|
|
4138
4246
|
context.chatsStore.upsert(msg.chat);
|
|
4139
4247
|
break;
|
|
4140
4248
|
case "delete-chat":
|
|
@@ -4145,28 +4253,30 @@ function createAi(config) {
|
|
|
4145
4253
|
context.chatsStore.upsert(msg.chat);
|
|
4146
4254
|
context.messagesStore.upsertMany(msg.messages);
|
|
4147
4255
|
break;
|
|
4148
|
-
case "add-user-message":
|
|
4149
|
-
context.messagesStore.upsert(msg.message);
|
|
4150
|
-
break;
|
|
4151
4256
|
case "delete-message":
|
|
4152
4257
|
context.messagesStore.remove(msg.chatId, msg.messageId);
|
|
4153
4258
|
break;
|
|
4154
4259
|
case "clear-chat":
|
|
4155
4260
|
context.messagesStore.removeByChatId(msg.chatId);
|
|
4156
4261
|
break;
|
|
4157
|
-
case "ask-
|
|
4158
|
-
if (msg.
|
|
4159
|
-
context.messagesStore.upsert(msg.
|
|
4160
|
-
} else {
|
|
4262
|
+
case "ask-in-chat":
|
|
4263
|
+
if (msg.sourceMessage) {
|
|
4264
|
+
context.messagesStore.upsert(msg.sourceMessage);
|
|
4161
4265
|
}
|
|
4266
|
+
context.messagesStore.upsert(msg.targetMessage);
|
|
4162
4267
|
break;
|
|
4163
4268
|
case "abort-ai":
|
|
4164
4269
|
break;
|
|
4270
|
+
case "set-tool-result":
|
|
4271
|
+
if (msg.ok) {
|
|
4272
|
+
context.messagesStore.upsert(msg.message);
|
|
4273
|
+
}
|
|
4274
|
+
break;
|
|
4165
4275
|
default:
|
|
4166
4276
|
return assertNever(msg, "Unhandled case");
|
|
4167
4277
|
}
|
|
4168
4278
|
}
|
|
4169
|
-
_optionalChain([pendingCmd, 'optionalAccess',
|
|
4279
|
+
_optionalChain([pendingCmd, 'optionalAccess', _64 => _64.resolve, 'call', _65 => _65(msg)]);
|
|
4170
4280
|
}
|
|
4171
4281
|
managedSocket.events.onMessage.subscribe(handleServerMessage);
|
|
4172
4282
|
managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
|
|
@@ -4212,13 +4322,11 @@ function createAi(config) {
|
|
|
4212
4322
|
cursor: options.cursor
|
|
4213
4323
|
});
|
|
4214
4324
|
}
|
|
4215
|
-
function
|
|
4325
|
+
function getOrCreateChat(id, options) {
|
|
4216
4326
|
return sendClientMsgWithResponse({
|
|
4217
|
-
cmd: "create-chat",
|
|
4327
|
+
cmd: "get-or-create-chat",
|
|
4218
4328
|
id,
|
|
4219
|
-
|
|
4220
|
-
ephemeral: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _65 => _65.ephemeral]), () => ( false)),
|
|
4221
|
-
metadata: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.metadata]), () => ( {}))
|
|
4329
|
+
options
|
|
4222
4330
|
});
|
|
4223
4331
|
}
|
|
4224
4332
|
function getMessageTree(chatId) {
|
|
@@ -4227,145 +4335,90 @@ function createAi(config) {
|
|
|
4227
4335
|
chatId
|
|
4228
4336
|
});
|
|
4229
4337
|
}
|
|
4230
|
-
function
|
|
4231
|
-
|
|
4232
|
-
if (chatContext === void 0) {
|
|
4233
|
-
context.contextByChatId.set(chatId, /* @__PURE__ */ new Set([data]));
|
|
4234
|
-
} else {
|
|
4235
|
-
chatContext.add(data);
|
|
4236
|
-
}
|
|
4237
|
-
return () => {
|
|
4238
|
-
const chatContext2 = context.contextByChatId.get(chatId);
|
|
4239
|
-
if (chatContext2 !== void 0) {
|
|
4240
|
-
chatContext2.delete(data);
|
|
4241
|
-
if (chatContext2.size === 0) {
|
|
4242
|
-
context.contextByChatId.delete(chatId);
|
|
4243
|
-
}
|
|
4244
|
-
}
|
|
4245
|
-
};
|
|
4338
|
+
function registerKnowledgeLayer(uniqueLayerId) {
|
|
4339
|
+
return context.knowledge.registerLayer(uniqueLayerId);
|
|
4246
4340
|
}
|
|
4247
|
-
function
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
const
|
|
4255
|
-
const
|
|
4256
|
-
|
|
4257
|
-
return sendClientMsgWithResponse({
|
|
4258
|
-
cmd: "ask-ai",
|
|
4341
|
+
function deregisterKnowledgeLayer(layerKey) {
|
|
4342
|
+
context.knowledge.deregisterLayer(layerKey);
|
|
4343
|
+
}
|
|
4344
|
+
function updateKnowledge(layerKey, data, key = nanoid()) {
|
|
4345
|
+
context.knowledge.updateKnowledge(layerKey, key, data);
|
|
4346
|
+
}
|
|
4347
|
+
async function setToolResult(chatId, messageId, toolCallId, result, options) {
|
|
4348
|
+
const knowledge = context.knowledge.get();
|
|
4349
|
+
const resp = await sendClientMsgWithResponse({
|
|
4350
|
+
cmd: "set-tool-result",
|
|
4259
4351
|
chatId,
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4352
|
+
messageId,
|
|
4353
|
+
toolCallId,
|
|
4354
|
+
result,
|
|
4355
|
+
generationOptions: {
|
|
4356
|
+
copilotId: _optionalChain([options, 'optionalAccess', _66 => _66.copilotId]),
|
|
4357
|
+
stream: _optionalChain([options, 'optionalAccess', _67 => _67.stream]),
|
|
4358
|
+
timeout: _optionalChain([options, 'optionalAccess', _68 => _68.timeout]),
|
|
4359
|
+
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4360
|
+
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4361
|
+
name: tool.name,
|
|
4362
|
+
description: tool.definition.description,
|
|
4363
|
+
parameters: tool.definition.parameters
|
|
4364
|
+
}))
|
|
4365
|
+
}
|
|
4272
4366
|
});
|
|
4367
|
+
if (resp.ok) {
|
|
4368
|
+
messagesStore.allowAutoExecuteToolCall(resp.message.id);
|
|
4369
|
+
}
|
|
4370
|
+
return resp;
|
|
4273
4371
|
}
|
|
4274
4372
|
return Object.defineProperty(
|
|
4275
4373
|
{
|
|
4276
4374
|
[kInternal]: {
|
|
4277
|
-
|
|
4375
|
+
context
|
|
4278
4376
|
},
|
|
4279
4377
|
connect: () => managedSocket.connect(),
|
|
4280
4378
|
reconnect: () => managedSocket.reconnect(),
|
|
4281
4379
|
disconnect: () => managedSocket.disconnect(),
|
|
4282
4380
|
getChats,
|
|
4283
|
-
|
|
4381
|
+
getOrCreateChat,
|
|
4284
4382
|
deleteChat: (chatId) => {
|
|
4285
|
-
return sendClientMsgWithResponse({
|
|
4286
|
-
cmd: "delete-chat",
|
|
4287
|
-
chatId
|
|
4288
|
-
});
|
|
4383
|
+
return sendClientMsgWithResponse({ cmd: "delete-chat", chatId });
|
|
4289
4384
|
},
|
|
4290
4385
|
getMessageTree,
|
|
4291
4386
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4292
4387
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4293
|
-
|
|
4294
|
-
const
|
|
4295
|
-
const
|
|
4296
|
-
|
|
4297
|
-
"user",
|
|
4298
|
-
parentMessageId,
|
|
4299
|
-
content
|
|
4300
|
-
);
|
|
4301
|
-
return sendClientMsgWithResponse({
|
|
4302
|
-
cmd: "add-user-message",
|
|
4303
|
-
id: newMessageId,
|
|
4304
|
-
chatId,
|
|
4305
|
-
parentMessageId,
|
|
4306
|
-
content
|
|
4307
|
-
});
|
|
4308
|
-
},
|
|
4309
|
-
ask,
|
|
4310
|
-
regenerateMessage: (chatId, messageId, options) => {
|
|
4311
|
-
const parentUserMessageId = context.messagesStore.getLatestUserMessageAncestor(chatId, messageId);
|
|
4312
|
-
if (parentUserMessageId === null) {
|
|
4313
|
-
throw new Error(
|
|
4314
|
-
`Unable to find user message ancestor for messageId: ${messageId}`
|
|
4315
|
-
);
|
|
4316
|
-
}
|
|
4317
|
-
return ask(chatId, parentUserMessageId, options);
|
|
4318
|
-
},
|
|
4319
|
-
addUserMessageAndAsk: async (chatId, parentMessageId, message, options) => {
|
|
4320
|
-
const content = [{ type: "text", text: message }];
|
|
4321
|
-
const newMessageId = context.messagesStore.createOptimistically(
|
|
4322
|
-
chatId,
|
|
4323
|
-
"user",
|
|
4324
|
-
parentMessageId,
|
|
4325
|
-
content
|
|
4326
|
-
);
|
|
4327
|
-
const targetMessageId = context.messagesStore.createOptimistically(
|
|
4388
|
+
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4389
|
+
const knowledge = context.knowledge.get();
|
|
4390
|
+
const resp = await sendClientMsgWithResponse({
|
|
4391
|
+
cmd: "ask-in-chat",
|
|
4328
4392
|
chatId,
|
|
4329
|
-
|
|
4330
|
-
newMessageId
|
|
4331
|
-
);
|
|
4332
|
-
await sendClientMsgWithResponse({
|
|
4333
|
-
cmd: "add-user-message",
|
|
4334
|
-
id: newMessageId,
|
|
4335
|
-
chatId,
|
|
4336
|
-
parentMessageId,
|
|
4337
|
-
content
|
|
4338
|
-
});
|
|
4339
|
-
const copilotId = _optionalChain([options, 'optionalAccess', _70 => _70.copilotId]);
|
|
4340
|
-
const stream = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.stream]), () => ( false));
|
|
4341
|
-
const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.timeout]), () => ( DEFAULT_AI_TIMEOUT));
|
|
4342
|
-
const chatContext = context.contextByChatId.get(chatId);
|
|
4343
|
-
return sendClientMsgWithResponse({
|
|
4344
|
-
cmd: "ask-ai",
|
|
4345
|
-
chatId,
|
|
4346
|
-
sourceMessageId: newMessageId,
|
|
4393
|
+
sourceMessage: userMessage,
|
|
4347
4394
|
targetMessageId,
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4395
|
+
generationOptions: {
|
|
4396
|
+
copilotId: _optionalChain([options, 'optionalAccess', _69 => _69.copilotId]),
|
|
4397
|
+
stream: _optionalChain([options, 'optionalAccess', _70 => _70.stream]),
|
|
4398
|
+
timeout: _optionalChain([options, 'optionalAccess', _71 => _71.timeout]),
|
|
4399
|
+
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4400
|
+
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4401
|
+
name: tool.name,
|
|
4402
|
+
description: tool.definition.description,
|
|
4403
|
+
parameters: tool.definition.parameters
|
|
4404
|
+
}))
|
|
4405
|
+
}
|
|
4358
4406
|
});
|
|
4407
|
+
messagesStore.allowAutoExecuteToolCall(resp.targetMessage.id);
|
|
4408
|
+
return resp;
|
|
4359
4409
|
},
|
|
4360
4410
|
abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
|
|
4411
|
+
setToolResult,
|
|
4361
4412
|
getStatus: () => managedSocket.getStatus(),
|
|
4362
4413
|
signals: {
|
|
4363
4414
|
chats\u03A3: context.chatsStore.chats\u03A3,
|
|
4364
4415
|
getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
|
|
4365
|
-
getToolDefinition\u03A3: context.toolsStore.
|
|
4366
|
-
getMessagesForChat\u03A3: context.messagesStore.getMessagesForChat\u03A3
|
|
4416
|
+
getToolDefinition\u03A3: context.toolsStore.getToolDefinition\u03A3
|
|
4367
4417
|
},
|
|
4368
|
-
|
|
4418
|
+
getChatById: context.chatsStore.getChatById,
|
|
4419
|
+
registerKnowledgeLayer,
|
|
4420
|
+
deregisterKnowledgeLayer,
|
|
4421
|
+
updateKnowledge,
|
|
4369
4422
|
registerChatTool: context.toolsStore.addToolDefinition,
|
|
4370
4423
|
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4371
4424
|
},
|
|
@@ -4447,7 +4500,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
4447
4500
|
return void 0;
|
|
4448
4501
|
}
|
|
4449
4502
|
async function makeAuthRequest(options) {
|
|
4450
|
-
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access',
|
|
4503
|
+
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _72 => _72.polyfills, 'optionalAccess', _73 => _73.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
|
|
4451
4504
|
if (authentication.type === "private") {
|
|
4452
4505
|
if (fetcher === void 0) {
|
|
4453
4506
|
throw new StopRetrying(
|
|
@@ -4463,7 +4516,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
4463
4516
|
"The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
|
|
4464
4517
|
);
|
|
4465
4518
|
}
|
|
4466
|
-
_optionalChain([onAuthenticate, 'optionalCall',
|
|
4519
|
+
_optionalChain([onAuthenticate, 'optionalCall', _74 => _74(parsed.parsed)]);
|
|
4467
4520
|
return parsed;
|
|
4468
4521
|
}
|
|
4469
4522
|
if (authentication.type === "custom") {
|
|
@@ -4471,7 +4524,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
4471
4524
|
if (response && typeof response === "object") {
|
|
4472
4525
|
if (typeof response.token === "string") {
|
|
4473
4526
|
const parsed = parseAuthToken(response.token);
|
|
4474
|
-
_optionalChain([onAuthenticate, 'optionalCall',
|
|
4527
|
+
_optionalChain([onAuthenticate, 'optionalCall', _75 => _75(parsed.parsed)]);
|
|
4475
4528
|
return parsed;
|
|
4476
4529
|
} else if (typeof response.error === "string") {
|
|
4477
4530
|
const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
|
|
@@ -4629,7 +4682,7 @@ function sendToPanel(message, options) {
|
|
|
4629
4682
|
...message,
|
|
4630
4683
|
source: "liveblocks-devtools-client"
|
|
4631
4684
|
};
|
|
4632
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
4685
|
+
if (!(_optionalChain([options, 'optionalAccess', _76 => _76.force]) || _bridgeActive)) {
|
|
4633
4686
|
return;
|
|
4634
4687
|
}
|
|
4635
4688
|
window.postMessage(fullMsg, "*");
|
|
@@ -4637,7 +4690,7 @@ function sendToPanel(message, options) {
|
|
|
4637
4690
|
var eventSource = makeEventSource();
|
|
4638
4691
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
4639
4692
|
window.addEventListener("message", (event) => {
|
|
4640
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
4693
|
+
if (event.source === window && _optionalChain([event, 'access', _77 => _77.data, 'optionalAccess', _78 => _78.source]) === "liveblocks-devtools-panel") {
|
|
4641
4694
|
eventSource.notify(event.data);
|
|
4642
4695
|
} else {
|
|
4643
4696
|
}
|
|
@@ -4779,7 +4832,7 @@ function fullSync(room) {
|
|
|
4779
4832
|
msg: "room::sync::full",
|
|
4780
4833
|
roomId: room.id,
|
|
4781
4834
|
status: room.getStatus(),
|
|
4782
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
4835
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _79 => _79.toTreeNode, 'call', _80 => _80("root"), 'access', _81 => _81.payload]), () => ( null)),
|
|
4783
4836
|
me,
|
|
4784
4837
|
others
|
|
4785
4838
|
});
|
|
@@ -5070,7 +5123,7 @@ function createManagedPool(roomId, options) {
|
|
|
5070
5123
|
generateId: () => `${getCurrentConnectionId()}:${clock++}`,
|
|
5071
5124
|
generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
|
|
5072
5125
|
dispatch(ops, reverse, storageUpdates) {
|
|
5073
|
-
_optionalChain([onDispatch, 'optionalCall',
|
|
5126
|
+
_optionalChain([onDispatch, 'optionalCall', _82 => _82(ops, reverse, storageUpdates)]);
|
|
5074
5127
|
},
|
|
5075
5128
|
assertStorageIsWritable: () => {
|
|
5076
5129
|
if (!isStorageWritable()) {
|
|
@@ -5297,7 +5350,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
5297
5350
|
return [
|
|
5298
5351
|
{
|
|
5299
5352
|
type: 8 /* CREATE_REGISTER */,
|
|
5300
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
5353
|
+
opId: _optionalChain([pool, 'optionalAccess', _83 => _83.generateOpId, 'call', _84 => _84()]),
|
|
5301
5354
|
id: this._id,
|
|
5302
5355
|
parentId,
|
|
5303
5356
|
parentKey,
|
|
@@ -5403,7 +5456,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5403
5456
|
const ops = [];
|
|
5404
5457
|
const op = {
|
|
5405
5458
|
id: this._id,
|
|
5406
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
5459
|
+
opId: _optionalChain([pool, 'optionalAccess', _85 => _85.generateOpId, 'call', _86 => _86()]),
|
|
5407
5460
|
type: 2 /* CREATE_LIST */,
|
|
5408
5461
|
parentId,
|
|
5409
5462
|
parentKey
|
|
@@ -5674,7 +5727,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5674
5727
|
#applyInsertUndoRedo(op) {
|
|
5675
5728
|
const { id, parentKey: key } = op;
|
|
5676
5729
|
const child = creationOpToLiveNode(op);
|
|
5677
|
-
if (_optionalChain([this, 'access',
|
|
5730
|
+
if (_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.getNode, 'call', _89 => _89(id)]) !== void 0) {
|
|
5678
5731
|
return { modified: false };
|
|
5679
5732
|
}
|
|
5680
5733
|
child._attach(id, nn(this._pool));
|
|
@@ -5682,8 +5735,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5682
5735
|
const existingItemIndex = this._indexOfPosition(key);
|
|
5683
5736
|
let newKey = key;
|
|
5684
5737
|
if (existingItemIndex !== -1) {
|
|
5685
|
-
const before2 = _optionalChain([this, 'access',
|
|
5686
|
-
const after2 = _optionalChain([this, 'access',
|
|
5738
|
+
const before2 = _optionalChain([this, 'access', _90 => _90.#items, 'access', _91 => _91[existingItemIndex], 'optionalAccess', _92 => _92._parentPos]);
|
|
5739
|
+
const after2 = _optionalChain([this, 'access', _93 => _93.#items, 'access', _94 => _94[existingItemIndex + 1], 'optionalAccess', _95 => _95._parentPos]);
|
|
5687
5740
|
newKey = makePosition(before2, after2);
|
|
5688
5741
|
child._setParentLink(this, newKey);
|
|
5689
5742
|
}
|
|
@@ -5697,7 +5750,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5697
5750
|
#applySetUndoRedo(op) {
|
|
5698
5751
|
const { id, parentKey: key } = op;
|
|
5699
5752
|
const child = creationOpToLiveNode(op);
|
|
5700
|
-
if (_optionalChain([this, 'access',
|
|
5753
|
+
if (_optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.getNode, 'call', _98 => _98(id)]) !== void 0) {
|
|
5701
5754
|
return { modified: false };
|
|
5702
5755
|
}
|
|
5703
5756
|
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -5818,7 +5871,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5818
5871
|
} else {
|
|
5819
5872
|
this.#items[existingItemIndex]._setParentLink(
|
|
5820
5873
|
this,
|
|
5821
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
5874
|
+
makePosition(newKey, _optionalChain([this, 'access', _99 => _99.#items, 'access', _100 => _100[existingItemIndex + 1], 'optionalAccess', _101 => _101._parentPos]))
|
|
5822
5875
|
);
|
|
5823
5876
|
const previousIndex = this.#items.indexOf(child);
|
|
5824
5877
|
child._setParentLink(this, newKey);
|
|
@@ -5843,7 +5896,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5843
5896
|
if (existingItemIndex !== -1) {
|
|
5844
5897
|
this.#items[existingItemIndex]._setParentLink(
|
|
5845
5898
|
this,
|
|
5846
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
5899
|
+
makePosition(newKey, _optionalChain([this, 'access', _102 => _102.#items, 'access', _103 => _103[existingItemIndex + 1], 'optionalAccess', _104 => _104._parentPos]))
|
|
5847
5900
|
);
|
|
5848
5901
|
}
|
|
5849
5902
|
child._setParentLink(this, newKey);
|
|
@@ -5862,7 +5915,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5862
5915
|
if (existingItemIndex !== -1) {
|
|
5863
5916
|
this.#items[existingItemIndex]._setParentLink(
|
|
5864
5917
|
this,
|
|
5865
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
5918
|
+
makePosition(newKey, _optionalChain([this, 'access', _105 => _105.#items, 'access', _106 => _106[existingItemIndex + 1], 'optionalAccess', _107 => _107._parentPos]))
|
|
5866
5919
|
);
|
|
5867
5920
|
}
|
|
5868
5921
|
child._setParentLink(this, newKey);
|
|
@@ -5889,7 +5942,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5889
5942
|
if (existingItemIndex !== -1) {
|
|
5890
5943
|
this.#items[existingItemIndex]._setParentLink(
|
|
5891
5944
|
this,
|
|
5892
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
5945
|
+
makePosition(newKey, _optionalChain([this, 'access', _108 => _108.#items, 'access', _109 => _109[existingItemIndex + 1], 'optionalAccess', _110 => _110._parentPos]))
|
|
5893
5946
|
);
|
|
5894
5947
|
}
|
|
5895
5948
|
child._setParentLink(this, newKey);
|
|
@@ -5947,7 +6000,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5947
6000
|
* @param element The element to add to the end of the LiveList.
|
|
5948
6001
|
*/
|
|
5949
6002
|
push(element) {
|
|
5950
|
-
_optionalChain([this, 'access',
|
|
6003
|
+
_optionalChain([this, 'access', _111 => _111._pool, 'optionalAccess', _112 => _112.assertStorageIsWritable, 'call', _113 => _113()]);
|
|
5951
6004
|
return this.insert(element, this.length);
|
|
5952
6005
|
}
|
|
5953
6006
|
/**
|
|
@@ -5956,7 +6009,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5956
6009
|
* @param index The index at which you want to insert the element.
|
|
5957
6010
|
*/
|
|
5958
6011
|
insert(element, index) {
|
|
5959
|
-
_optionalChain([this, 'access',
|
|
6012
|
+
_optionalChain([this, 'access', _114 => _114._pool, 'optionalAccess', _115 => _115.assertStorageIsWritable, 'call', _116 => _116()]);
|
|
5960
6013
|
if (index < 0 || index > this.#items.length) {
|
|
5961
6014
|
throw new Error(
|
|
5962
6015
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
@@ -5986,7 +6039,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5986
6039
|
* @param targetIndex The index where the element should be after moving.
|
|
5987
6040
|
*/
|
|
5988
6041
|
move(index, targetIndex) {
|
|
5989
|
-
_optionalChain([this, 'access',
|
|
6042
|
+
_optionalChain([this, 'access', _117 => _117._pool, 'optionalAccess', _118 => _118.assertStorageIsWritable, 'call', _119 => _119()]);
|
|
5990
6043
|
if (targetIndex < 0) {
|
|
5991
6044
|
throw new Error("targetIndex cannot be less than 0");
|
|
5992
6045
|
}
|
|
@@ -6044,7 +6097,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6044
6097
|
* @param index The index of the element to delete
|
|
6045
6098
|
*/
|
|
6046
6099
|
delete(index) {
|
|
6047
|
-
_optionalChain([this, 'access',
|
|
6100
|
+
_optionalChain([this, 'access', _120 => _120._pool, 'optionalAccess', _121 => _121.assertStorageIsWritable, 'call', _122 => _122()]);
|
|
6048
6101
|
if (index < 0 || index >= this.#items.length) {
|
|
6049
6102
|
throw new Error(
|
|
6050
6103
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -6077,7 +6130,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6077
6130
|
}
|
|
6078
6131
|
}
|
|
6079
6132
|
clear() {
|
|
6080
|
-
_optionalChain([this, 'access',
|
|
6133
|
+
_optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.assertStorageIsWritable, 'call', _125 => _125()]);
|
|
6081
6134
|
if (this._pool) {
|
|
6082
6135
|
const ops = [];
|
|
6083
6136
|
const reverseOps = [];
|
|
@@ -6111,7 +6164,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6111
6164
|
}
|
|
6112
6165
|
}
|
|
6113
6166
|
set(index, item) {
|
|
6114
|
-
_optionalChain([this, 'access',
|
|
6167
|
+
_optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.assertStorageIsWritable, 'call', _128 => _128()]);
|
|
6115
6168
|
if (index < 0 || index >= this.#items.length) {
|
|
6116
6169
|
throw new Error(
|
|
6117
6170
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -6257,7 +6310,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6257
6310
|
#shiftItemPosition(index, key) {
|
|
6258
6311
|
const shiftedPosition = makePosition(
|
|
6259
6312
|
key,
|
|
6260
|
-
this.#items.length > index + 1 ? _optionalChain([this, 'access',
|
|
6313
|
+
this.#items.length > index + 1 ? _optionalChain([this, 'access', _129 => _129.#items, 'access', _130 => _130[index + 1], 'optionalAccess', _131 => _131._parentPos]) : void 0
|
|
6261
6314
|
);
|
|
6262
6315
|
this.#items[index]._setParentLink(this, shiftedPosition);
|
|
6263
6316
|
}
|
|
@@ -6382,7 +6435,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
6382
6435
|
const ops = [];
|
|
6383
6436
|
const op = {
|
|
6384
6437
|
id: this._id,
|
|
6385
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
6438
|
+
opId: _optionalChain([pool, 'optionalAccess', _132 => _132.generateOpId, 'call', _133 => _133()]),
|
|
6386
6439
|
type: 7 /* CREATE_MAP */,
|
|
6387
6440
|
parentId,
|
|
6388
6441
|
parentKey
|
|
@@ -6517,7 +6570,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
6517
6570
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
6518
6571
|
*/
|
|
6519
6572
|
set(key, value) {
|
|
6520
|
-
_optionalChain([this, 'access',
|
|
6573
|
+
_optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
|
|
6521
6574
|
const oldValue = this.#map.get(key);
|
|
6522
6575
|
if (oldValue) {
|
|
6523
6576
|
oldValue._detach();
|
|
@@ -6563,7 +6616,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
6563
6616
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
6564
6617
|
*/
|
|
6565
6618
|
delete(key) {
|
|
6566
|
-
_optionalChain([this, 'access',
|
|
6619
|
+
_optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
|
|
6567
6620
|
const item = this.#map.get(key);
|
|
6568
6621
|
if (item === void 0) {
|
|
6569
6622
|
return false;
|
|
@@ -6742,7 +6795,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
6742
6795
|
if (this._id === void 0) {
|
|
6743
6796
|
throw new Error("Cannot serialize item is not attached");
|
|
6744
6797
|
}
|
|
6745
|
-
const opId = _optionalChain([pool, 'optionalAccess',
|
|
6798
|
+
const opId = _optionalChain([pool, 'optionalAccess', _140 => _140.generateOpId, 'call', _141 => _141()]);
|
|
6746
6799
|
const ops = [];
|
|
6747
6800
|
const op = {
|
|
6748
6801
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -7014,7 +7067,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7014
7067
|
* @param value The value of the property to add
|
|
7015
7068
|
*/
|
|
7016
7069
|
set(key, value) {
|
|
7017
|
-
_optionalChain([this, 'access',
|
|
7070
|
+
_optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
|
|
7018
7071
|
this.update({ [key]: value });
|
|
7019
7072
|
}
|
|
7020
7073
|
/**
|
|
@@ -7029,7 +7082,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7029
7082
|
* @param key The key of the property to delete
|
|
7030
7083
|
*/
|
|
7031
7084
|
delete(key) {
|
|
7032
|
-
_optionalChain([this, 'access',
|
|
7085
|
+
_optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
|
|
7033
7086
|
const keyAsString = key;
|
|
7034
7087
|
const oldValue = this.#map.get(keyAsString);
|
|
7035
7088
|
if (oldValue === void 0) {
|
|
@@ -7082,7 +7135,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7082
7135
|
* @param patch The object used to overrides properties
|
|
7083
7136
|
*/
|
|
7084
7137
|
update(patch) {
|
|
7085
|
-
_optionalChain([this, 'access',
|
|
7138
|
+
_optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
|
|
7086
7139
|
if (this._pool === void 0 || this._id === void 0) {
|
|
7087
7140
|
for (const key in patch) {
|
|
7088
7141
|
const newValue = patch[key];
|
|
@@ -7805,15 +7858,15 @@ function installBackgroundTabSpy() {
|
|
|
7805
7858
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
7806
7859
|
const inBackgroundSince = { current: null };
|
|
7807
7860
|
function onVisibilityChange() {
|
|
7808
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
7861
|
+
if (_optionalChain([doc, 'optionalAccess', _151 => _151.visibilityState]) === "hidden") {
|
|
7809
7862
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
7810
7863
|
} else {
|
|
7811
7864
|
inBackgroundSince.current = null;
|
|
7812
7865
|
}
|
|
7813
7866
|
}
|
|
7814
|
-
_optionalChain([doc, 'optionalAccess',
|
|
7867
|
+
_optionalChain([doc, 'optionalAccess', _152 => _152.addEventListener, 'call', _153 => _153("visibilitychange", onVisibilityChange)]);
|
|
7815
7868
|
const unsub = () => {
|
|
7816
|
-
_optionalChain([doc, 'optionalAccess',
|
|
7869
|
+
_optionalChain([doc, 'optionalAccess', _154 => _154.removeEventListener, 'call', _155 => _155("visibilitychange", onVisibilityChange)]);
|
|
7817
7870
|
};
|
|
7818
7871
|
return [inBackgroundSince, unsub];
|
|
7819
7872
|
}
|
|
@@ -7993,7 +8046,7 @@ function createRoom(options, config) {
|
|
|
7993
8046
|
}
|
|
7994
8047
|
}
|
|
7995
8048
|
function isStorageWritable() {
|
|
7996
|
-
const scopes = _optionalChain([context, 'access',
|
|
8049
|
+
const scopes = _optionalChain([context, 'access', _156 => _156.dynamicSessionInfoSig, 'access', _157 => _157.get, 'call', _158 => _158(), 'optionalAccess', _159 => _159.scopes]);
|
|
7997
8050
|
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
7998
8051
|
}
|
|
7999
8052
|
const eventHub = {
|
|
@@ -8110,7 +8163,7 @@ function createRoom(options, config) {
|
|
|
8110
8163
|
}
|
|
8111
8164
|
case "experimental-fallback-to-http": {
|
|
8112
8165
|
warn("Message is too large for websockets, so sending over HTTP instead");
|
|
8113
|
-
const nonce = _nullishCoalesce(_optionalChain([context, 'access',
|
|
8166
|
+
const nonce = _nullishCoalesce(_optionalChain([context, 'access', _160 => _160.dynamicSessionInfoSig, 'access', _161 => _161.get, 'call', _162 => _162(), 'optionalAccess', _163 => _163.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
|
|
8114
8167
|
void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
|
|
8115
8168
|
if (!resp.ok && resp.status === 403) {
|
|
8116
8169
|
managedSocket.reconnect();
|
|
@@ -8161,7 +8214,7 @@ function createRoom(options, config) {
|
|
|
8161
8214
|
} else {
|
|
8162
8215
|
context.root = LiveObject._fromItems(message.items, context.pool);
|
|
8163
8216
|
}
|
|
8164
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
8217
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _164 => _164.get, 'call', _165 => _165(), 'optionalAccess', _166 => _166.canWrite]), () => ( true));
|
|
8165
8218
|
const stackSizeBefore = context.undoStack.length;
|
|
8166
8219
|
for (const key in context.initialStorage) {
|
|
8167
8220
|
if (context.root.get(key) === void 0) {
|
|
@@ -8364,7 +8417,7 @@ function createRoom(options, config) {
|
|
|
8364
8417
|
}
|
|
8365
8418
|
context.myPresence.patch(patch);
|
|
8366
8419
|
if (context.activeBatch) {
|
|
8367
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
8420
|
+
if (_optionalChain([options2, 'optionalAccess', _167 => _167.addToHistory])) {
|
|
8368
8421
|
context.activeBatch.reverseOps.pushLeft({
|
|
8369
8422
|
type: "presence",
|
|
8370
8423
|
data: oldValues
|
|
@@ -8373,7 +8426,7 @@ function createRoom(options, config) {
|
|
|
8373
8426
|
context.activeBatch.updates.presence = true;
|
|
8374
8427
|
} else {
|
|
8375
8428
|
flushNowOrSoon();
|
|
8376
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
8429
|
+
if (_optionalChain([options2, 'optionalAccess', _168 => _168.addToHistory])) {
|
|
8377
8430
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
8378
8431
|
}
|
|
8379
8432
|
notify({ presence: true });
|
|
@@ -8570,7 +8623,7 @@ function createRoom(options, config) {
|
|
|
8570
8623
|
if (process.env.NODE_ENV !== "production") {
|
|
8571
8624
|
const traces = /* @__PURE__ */ new Set();
|
|
8572
8625
|
for (const opId of message.opIds) {
|
|
8573
|
-
const trace = _optionalChain([context, 'access',
|
|
8626
|
+
const trace = _optionalChain([context, 'access', _169 => _169.opStackTraces, 'optionalAccess', _170 => _170.get, 'call', _171 => _171(opId)]);
|
|
8574
8627
|
if (trace) {
|
|
8575
8628
|
traces.add(trace);
|
|
8576
8629
|
}
|
|
@@ -8704,7 +8757,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
8704
8757
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
8705
8758
|
createOrUpdateRootFromMessage(message);
|
|
8706
8759
|
applyAndSendOps(unacknowledgedOps);
|
|
8707
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
8760
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _172 => _172()]);
|
|
8708
8761
|
notifyStorageStatus();
|
|
8709
8762
|
eventHub.storageDidLoad.notify();
|
|
8710
8763
|
}
|
|
@@ -8927,8 +8980,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
8927
8980
|
async function getThreads(options2) {
|
|
8928
8981
|
return httpClient.getThreads({
|
|
8929
8982
|
roomId,
|
|
8930
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
8931
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
8983
|
+
query: _optionalChain([options2, 'optionalAccess', _173 => _173.query]),
|
|
8984
|
+
cursor: _optionalChain([options2, 'optionalAccess', _174 => _174.cursor])
|
|
8932
8985
|
});
|
|
8933
8986
|
}
|
|
8934
8987
|
async function getThread(threadId) {
|
|
@@ -9035,7 +9088,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9035
9088
|
function getSubscriptionSettings(options2) {
|
|
9036
9089
|
return httpClient.getSubscriptionSettings({
|
|
9037
9090
|
roomId,
|
|
9038
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
9091
|
+
signal: _optionalChain([options2, 'optionalAccess', _175 => _175.signal])
|
|
9039
9092
|
});
|
|
9040
9093
|
}
|
|
9041
9094
|
function updateSubscriptionSettings(settings) {
|
|
@@ -9057,7 +9110,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9057
9110
|
{
|
|
9058
9111
|
[kInternal]: {
|
|
9059
9112
|
get presenceBuffer() {
|
|
9060
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
9113
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _176 => _176.buffer, 'access', _177 => _177.presenceUpdates, 'optionalAccess', _178 => _178.data]), () => ( null)));
|
|
9061
9114
|
},
|
|
9062
9115
|
// prettier-ignore
|
|
9063
9116
|
get undoStack() {
|
|
@@ -9072,9 +9125,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9072
9125
|
return context.yjsProvider;
|
|
9073
9126
|
},
|
|
9074
9127
|
setYjsProvider(newProvider) {
|
|
9075
|
-
_optionalChain([context, 'access',
|
|
9128
|
+
_optionalChain([context, 'access', _179 => _179.yjsProvider, 'optionalAccess', _180 => _180.off, 'call', _181 => _181("status", yjsStatusDidChange)]);
|
|
9076
9129
|
context.yjsProvider = newProvider;
|
|
9077
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
9130
|
+
_optionalChain([newProvider, 'optionalAccess', _182 => _182.on, 'call', _183 => _183("status", yjsStatusDidChange)]);
|
|
9078
9131
|
context.yjsProviderDidChange.notify();
|
|
9079
9132
|
},
|
|
9080
9133
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -9120,7 +9173,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9120
9173
|
source.dispose();
|
|
9121
9174
|
}
|
|
9122
9175
|
eventHub.roomWillDestroy.notify();
|
|
9123
|
-
_optionalChain([context, 'access',
|
|
9176
|
+
_optionalChain([context, 'access', _184 => _184.yjsProvider, 'optionalAccess', _185 => _185.off, 'call', _186 => _186("status", yjsStatusDidChange)]);
|
|
9124
9177
|
syncSourceForStorage.destroy();
|
|
9125
9178
|
syncSourceForYjs.destroy();
|
|
9126
9179
|
uninstallBgTabSpy();
|
|
@@ -9270,7 +9323,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
9270
9323
|
}
|
|
9271
9324
|
if (isLiveNode(first)) {
|
|
9272
9325
|
const node = first;
|
|
9273
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
9326
|
+
if (_optionalChain([options, 'optionalAccess', _187 => _187.isDeep])) {
|
|
9274
9327
|
const storageCallback = second;
|
|
9275
9328
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
9276
9329
|
} else {
|
|
@@ -9349,8 +9402,8 @@ function createClient(options) {
|
|
|
9349
9402
|
const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
|
|
9350
9403
|
currentUserId.set(() => userId);
|
|
9351
9404
|
});
|
|
9352
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
9353
|
-
_optionalChain([globalThis, 'access',
|
|
9405
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _188 => _188.polyfills, 'optionalAccess', _189 => _189.fetch]) || /* istanbul ignore next */
|
|
9406
|
+
_optionalChain([globalThis, 'access', _190 => _190.fetch, 'optionalAccess', _191 => _191.bind, 'call', _192 => _192(globalThis)]);
|
|
9354
9407
|
const httpClient = createApiClient({
|
|
9355
9408
|
baseUrl,
|
|
9356
9409
|
fetchPolyfill,
|
|
@@ -9368,7 +9421,7 @@ function createClient(options) {
|
|
|
9368
9421
|
delegates: {
|
|
9369
9422
|
createSocket: makeCreateSocketDelegateForAi(
|
|
9370
9423
|
baseUrl,
|
|
9371
|
-
_optionalChain([clientOptions, 'access',
|
|
9424
|
+
_optionalChain([clientOptions, 'access', _193 => _193.polyfills, 'optionalAccess', _194 => _194.WebSocket])
|
|
9372
9425
|
),
|
|
9373
9426
|
authenticate: makeAuthDelegateForRoom("default", authManager),
|
|
9374
9427
|
canZombie: () => true
|
|
@@ -9418,7 +9471,7 @@ function createClient(options) {
|
|
|
9418
9471
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
9419
9472
|
roomId,
|
|
9420
9473
|
baseUrl,
|
|
9421
|
-
_optionalChain([clientOptions, 'access',
|
|
9474
|
+
_optionalChain([clientOptions, 'access', _195 => _195.polyfills, 'optionalAccess', _196 => _196.WebSocket])
|
|
9422
9475
|
),
|
|
9423
9476
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
9424
9477
|
})),
|
|
@@ -9441,7 +9494,7 @@ function createClient(options) {
|
|
|
9441
9494
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
9442
9495
|
if (shouldConnect) {
|
|
9443
9496
|
if (typeof atob === "undefined") {
|
|
9444
|
-
if (_optionalChain([clientOptions, 'access',
|
|
9497
|
+
if (_optionalChain([clientOptions, 'access', _197 => _197.polyfills, 'optionalAccess', _198 => _198.atob]) === void 0) {
|
|
9445
9498
|
throw new Error(
|
|
9446
9499
|
"You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
|
|
9447
9500
|
);
|
|
@@ -9453,7 +9506,7 @@ function createClient(options) {
|
|
|
9453
9506
|
return leaseRoom(newRoomDetails);
|
|
9454
9507
|
}
|
|
9455
9508
|
function getRoom(roomId) {
|
|
9456
|
-
const room = _optionalChain([roomsById, 'access',
|
|
9509
|
+
const room = _optionalChain([roomsById, 'access', _199 => _199.get, 'call', _200 => _200(roomId), 'optionalAccess', _201 => _201.room]);
|
|
9457
9510
|
return room ? room : null;
|
|
9458
9511
|
}
|
|
9459
9512
|
function logout() {
|
|
@@ -9473,7 +9526,7 @@ function createClient(options) {
|
|
|
9473
9526
|
const batchedResolveUsers = new Batch(
|
|
9474
9527
|
async (batchedUserIds) => {
|
|
9475
9528
|
const userIds = batchedUserIds.flat();
|
|
9476
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
9529
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _202 => _202({ userIds })]);
|
|
9477
9530
|
warnIfNoResolveUsers();
|
|
9478
9531
|
return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
|
|
9479
9532
|
},
|
|
@@ -9491,7 +9544,7 @@ function createClient(options) {
|
|
|
9491
9544
|
const batchedResolveRoomsInfo = new Batch(
|
|
9492
9545
|
async (batchedRoomIds) => {
|
|
9493
9546
|
const roomIds = batchedRoomIds.flat();
|
|
9494
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
9547
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _203 => _203({ roomIds })]);
|
|
9495
9548
|
warnIfNoResolveRoomsInfo();
|
|
9496
9549
|
return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
|
|
9497
9550
|
},
|
|
@@ -9544,7 +9597,7 @@ function createClient(options) {
|
|
|
9544
9597
|
}
|
|
9545
9598
|
};
|
|
9546
9599
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
9547
|
-
_optionalChain([win, 'optionalAccess',
|
|
9600
|
+
_optionalChain([win, 'optionalAccess', _204 => _204.addEventListener, 'call', _205 => _205("beforeunload", maybePreventClose)]);
|
|
9548
9601
|
}
|
|
9549
9602
|
async function getNotificationSettings(options2) {
|
|
9550
9603
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -9683,7 +9736,7 @@ var commentBodyElementsTypes = {
|
|
|
9683
9736
|
mention: "inline"
|
|
9684
9737
|
};
|
|
9685
9738
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
9686
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
9739
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _206 => _206.content])) {
|
|
9687
9740
|
return;
|
|
9688
9741
|
}
|
|
9689
9742
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -9693,13 +9746,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
9693
9746
|
for (const block of body.content) {
|
|
9694
9747
|
if (type === "all" || type === "block") {
|
|
9695
9748
|
if (guard(block)) {
|
|
9696
|
-
_optionalChain([visitor, 'optionalCall',
|
|
9749
|
+
_optionalChain([visitor, 'optionalCall', _207 => _207(block)]);
|
|
9697
9750
|
}
|
|
9698
9751
|
}
|
|
9699
9752
|
if (type === "all" || type === "inline") {
|
|
9700
9753
|
for (const inline of block.children) {
|
|
9701
9754
|
if (guard(inline)) {
|
|
9702
|
-
_optionalChain([visitor, 'optionalCall',
|
|
9755
|
+
_optionalChain([visitor, 'optionalCall', _208 => _208(inline)]);
|
|
9703
9756
|
}
|
|
9704
9757
|
}
|
|
9705
9758
|
}
|
|
@@ -9724,7 +9777,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
|
9724
9777
|
userIds
|
|
9725
9778
|
});
|
|
9726
9779
|
for (const [index, userId] of userIds.entries()) {
|
|
9727
|
-
const user = _optionalChain([users, 'optionalAccess',
|
|
9780
|
+
const user = _optionalChain([users, 'optionalAccess', _209 => _209[index]]);
|
|
9728
9781
|
if (user) {
|
|
9729
9782
|
resolvedUsers.set(userId, user);
|
|
9730
9783
|
}
|
|
@@ -9851,7 +9904,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
9851
9904
|
text: ({ element }) => element.text,
|
|
9852
9905
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
9853
9906
|
mention: ({ element, user }) => {
|
|
9854
|
-
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
9907
|
+
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _210 => _210.name]), () => ( element.id))}`;
|
|
9855
9908
|
}
|
|
9856
9909
|
};
|
|
9857
9910
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -9881,7 +9934,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
9881
9934
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
9882
9935
|
},
|
|
9883
9936
|
mention: ({ element, user }) => {
|
|
9884
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
9937
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _211 => _211.name]) ? html`${_optionalChain([user, 'optionalAccess', _212 => _212.name])}` : element.id}</span>`;
|
|
9885
9938
|
}
|
|
9886
9939
|
};
|
|
9887
9940
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -9911,19 +9964,19 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
9911
9964
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
9912
9965
|
},
|
|
9913
9966
|
mention: ({ element, user }) => {
|
|
9914
|
-
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
9967
|
+
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _213 => _213.name]), () => ( element.id))}`;
|
|
9915
9968
|
}
|
|
9916
9969
|
};
|
|
9917
9970
|
async function stringifyCommentBody(body, options) {
|
|
9918
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
9919
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
9971
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _214 => _214.format]), () => ( "plain"));
|
|
9972
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _215 => _215.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
9920
9973
|
const elements = {
|
|
9921
9974
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
9922
|
-
..._optionalChain([options, 'optionalAccess',
|
|
9975
|
+
..._optionalChain([options, 'optionalAccess', _216 => _216.elements])
|
|
9923
9976
|
};
|
|
9924
9977
|
const resolvedUsers = await resolveUsersInCommentBody(
|
|
9925
9978
|
body,
|
|
9926
|
-
_optionalChain([options, 'optionalAccess',
|
|
9979
|
+
_optionalChain([options, 'optionalAccess', _217 => _217.resolveUsers])
|
|
9927
9980
|
);
|
|
9928
9981
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
9929
9982
|
switch (block.type) {
|
|
@@ -10214,12 +10267,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
10214
10267
|
}
|
|
10215
10268
|
const newState = Object.assign({}, state);
|
|
10216
10269
|
for (const key in update.updates) {
|
|
10217
|
-
if (_optionalChain([update, 'access',
|
|
10270
|
+
if (_optionalChain([update, 'access', _218 => _218.updates, 'access', _219 => _219[key], 'optionalAccess', _220 => _220.type]) === "update") {
|
|
10218
10271
|
const val = update.node.get(key);
|
|
10219
10272
|
if (val !== void 0) {
|
|
10220
10273
|
newState[key] = lsonToJson(val);
|
|
10221
10274
|
}
|
|
10222
|
-
} else if (_optionalChain([update, 'access',
|
|
10275
|
+
} else if (_optionalChain([update, 'access', _221 => _221.updates, 'access', _222 => _222[key], 'optionalAccess', _223 => _223.type]) === "delete") {
|
|
10223
10276
|
delete newState[key];
|
|
10224
10277
|
}
|
|
10225
10278
|
}
|
|
@@ -10280,12 +10333,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
10280
10333
|
}
|
|
10281
10334
|
const newState = Object.assign({}, state);
|
|
10282
10335
|
for (const key in update.updates) {
|
|
10283
|
-
if (_optionalChain([update, 'access',
|
|
10336
|
+
if (_optionalChain([update, 'access', _224 => _224.updates, 'access', _225 => _225[key], 'optionalAccess', _226 => _226.type]) === "update") {
|
|
10284
10337
|
const value = update.node.get(key);
|
|
10285
10338
|
if (value !== void 0) {
|
|
10286
10339
|
newState[key] = lsonToJson(value);
|
|
10287
10340
|
}
|
|
10288
|
-
} else if (_optionalChain([update, 'access',
|
|
10341
|
+
} else if (_optionalChain([update, 'access', _227 => _227.updates, 'access', _228 => _228[key], 'optionalAccess', _229 => _229.type]) === "delete") {
|
|
10289
10342
|
delete newState[key];
|
|
10290
10343
|
}
|
|
10291
10344
|
}
|
|
@@ -10365,9 +10418,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
10365
10418
|
const startTime = performance.now();
|
|
10366
10419
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
10367
10420
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
10368
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
10421
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _230 => _230.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
10369
10422
|
const context = {
|
|
10370
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
10423
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _231 => _231.visibilityState]) !== "hidden",
|
|
10371
10424
|
lastSuccessfulPollAt: startTime,
|
|
10372
10425
|
count: 0,
|
|
10373
10426
|
backoff: 0
|
|
@@ -10448,11 +10501,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
10448
10501
|
pollNowIfStale();
|
|
10449
10502
|
}
|
|
10450
10503
|
function onVisibilityChange() {
|
|
10451
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
10504
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _232 => _232.visibilityState]) !== "hidden");
|
|
10452
10505
|
}
|
|
10453
|
-
_optionalChain([doc, 'optionalAccess',
|
|
10454
|
-
_optionalChain([win, 'optionalAccess',
|
|
10455
|
-
_optionalChain([win, 'optionalAccess',
|
|
10506
|
+
_optionalChain([doc, 'optionalAccess', _233 => _233.addEventListener, 'call', _234 => _234("visibilitychange", onVisibilityChange)]);
|
|
10507
|
+
_optionalChain([win, 'optionalAccess', _235 => _235.addEventListener, 'call', _236 => _236("online", onVisibilityChange)]);
|
|
10508
|
+
_optionalChain([win, 'optionalAccess', _237 => _237.addEventListener, 'call', _238 => _238("focus", pollNowIfStale)]);
|
|
10456
10509
|
fsm.start();
|
|
10457
10510
|
return {
|
|
10458
10511
|
inc,
|
|
@@ -10583,5 +10636,6 @@ var NotificationsApiError = HttpError;
|
|
|
10583
10636
|
|
|
10584
10637
|
|
|
10585
10638
|
|
|
10586
|
-
|
|
10639
|
+
|
|
10640
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
|
|
10587
10641
|
//# sourceMappingURL=index.cjs.map
|