@liveblocks/core 3.8.0 → 3.9.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 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 = "3.8.0";
9
+ var PKG_VERSION = "3.9.0";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -703,6 +703,7 @@ var AiChatDB = class {
703
703
  this.signal = new MutableSignal(this);
704
704
  }
705
705
  getEvenIfDeleted(chatId) {
706
+ this.signal.get();
706
707
  return this.#byId.get(chatId);
707
708
  }
708
709
  markDeleted(chatId) {
@@ -2386,6 +2387,14 @@ function createApiClient({
2386
2387
  function getGroup(groupId) {
2387
2388
  return batchedGetGroups.get(groupId);
2388
2389
  }
2390
+ async function getUrlMetadata(_url) {
2391
+ const { metadata } = await httpClient.get(
2392
+ url`/v2/c/urls/metadata`,
2393
+ await authManager.getAuthValue({ requestedScope: "comments:read" }),
2394
+ { url: _url }
2395
+ );
2396
+ return metadata;
2397
+ }
2389
2398
  return {
2390
2399
  // Room threads
2391
2400
  getThreads,
@@ -2443,7 +2452,9 @@ function createApiClient({
2443
2452
  groupsStore,
2444
2453
  getGroup,
2445
2454
  // AI
2446
- executeContextualPrompt
2455
+ executeContextualPrompt,
2456
+ // URL metadata
2457
+ getUrlMetadata
2447
2458
  };
2448
2459
  }
2449
2460
  function getBearerTokenFromAuthValue(authValue) {
@@ -3058,7 +3069,6 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
3058
3069
  ServerMsgCode2[ServerMsgCode2["ROOM_STATE"] = 104] = "ROOM_STATE";
3059
3070
  ServerMsgCode2[ServerMsgCode2["INITIAL_STORAGE_STATE"] = 200] = "INITIAL_STORAGE_STATE";
3060
3071
  ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
3061
- ServerMsgCode2[ServerMsgCode2["REJECT_STORAGE_OP"] = 299] = "REJECT_STORAGE_OP";
3062
3072
  ServerMsgCode2[ServerMsgCode2["UPDATE_YDOC"] = 300] = "UPDATE_YDOC";
3063
3073
  ServerMsgCode2[ServerMsgCode2["THREAD_CREATED"] = 400] = "THREAD_CREATED";
3064
3074
  ServerMsgCode2[ServerMsgCode2["THREAD_DELETED"] = 407] = "THREAD_DELETED";
@@ -3069,6 +3079,7 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
3069
3079
  ServerMsgCode2[ServerMsgCode2["COMMENT_DELETED"] = 404] = "COMMENT_DELETED";
3070
3080
  ServerMsgCode2[ServerMsgCode2["COMMENT_REACTION_ADDED"] = 405] = "COMMENT_REACTION_ADDED";
3071
3081
  ServerMsgCode2[ServerMsgCode2["COMMENT_REACTION_REMOVED"] = 406] = "COMMENT_REACTION_REMOVED";
3082
+ ServerMsgCode2[ServerMsgCode2["REJECT_STORAGE_OP"] = 299] = "REJECT_STORAGE_OP";
3072
3083
  return ServerMsgCode2;
3073
3084
  })(ServerMsgCode || {});
3074
3085
 
@@ -3696,240 +3707,6 @@ var ManagedSocket = class {
3696
3707
  // src/internal.ts
3697
3708
  var kInternal = Symbol();
3698
3709
 
3699
- // src/lib/shallow.ts
3700
- function shallowArray(xs, ys) {
3701
- if (xs.length !== ys.length) {
3702
- return false;
3703
- }
3704
- for (let i = 0; i < xs.length; i++) {
3705
- if (!Object.is(xs[i], ys[i])) {
3706
- return false;
3707
- }
3708
- }
3709
- return true;
3710
- }
3711
- function shallowObj(objA, objB) {
3712
- if (!isPlainObject(objA) || !isPlainObject(objB)) {
3713
- return false;
3714
- }
3715
- const keysA = Object.keys(objA);
3716
- if (keysA.length !== Object.keys(objB).length) {
3717
- return false;
3718
- }
3719
- return keysA.every(
3720
- (key) => Object.prototype.hasOwnProperty.call(objB, key) && Object.is(objA[key], objB[key])
3721
- );
3722
- }
3723
- function shallow(a, b) {
3724
- if (Object.is(a, b)) {
3725
- return true;
3726
- }
3727
- const isArrayA = Array.isArray(a);
3728
- const isArrayB = Array.isArray(b);
3729
- if (isArrayA || isArrayB) {
3730
- if (!isArrayA || !isArrayB) {
3731
- return false;
3732
- }
3733
- return shallowArray(a, b);
3734
- }
3735
- return shallowObj(a, b);
3736
- }
3737
- function shallow2(a, b) {
3738
- if (!isPlainObject(a) || !isPlainObject(b)) {
3739
- return shallow(a, b);
3740
- }
3741
- const keysA = Object.keys(a);
3742
- if (keysA.length !== Object.keys(b).length) {
3743
- return false;
3744
- }
3745
- return keysA.every(
3746
- (key) => Object.prototype.hasOwnProperty.call(b, key) && shallow(a[key], b[key])
3747
- );
3748
- }
3749
-
3750
- // src/lib/TreePool.ts
3751
- var TreePool = class {
3752
- #_items;
3753
- #_childrenOf;
3754
- #_sorted;
3755
- #_primaryKey;
3756
- #_parentKeyFn;
3757
- #_lt;
3758
- constructor(primaryKey, parentKey, lt) {
3759
- this.#_primaryKey = primaryKey;
3760
- this.#_parentKeyFn = parentKey;
3761
- this.#_lt = lt;
3762
- this.#_items = /* @__PURE__ */ new Map();
3763
- this.#_childrenOf = new DefaultMap(() => /* @__PURE__ */ new Set());
3764
- this.#_sorted = SortedList.with(lt);
3765
- }
3766
- get(id) {
3767
- return this.#_items.get(id);
3768
- }
3769
- getOrThrow(id) {
3770
- return _nullishCoalesce(this.get(id), () => ( raise(`Item with id ${id} not found`)));
3771
- }
3772
- get sorted() {
3773
- return this.#_sorted;
3774
- }
3775
- getParentId(id) {
3776
- const item = this.getOrThrow(id);
3777
- return this.#_parentKeyFn(item);
3778
- }
3779
- getParent(id) {
3780
- const parentId = this.getParentId(id);
3781
- return parentId ? this.getOrThrow(parentId) : null;
3782
- }
3783
- getChildren(id) {
3784
- const childIds = this.#_childrenOf.get(id);
3785
- if (!childIds) return [];
3786
- return Array.from(childIds).map(
3787
- (id2) => this.#_items.get(id2)
3788
- // eslint-disable-line no-restricted-syntax
3789
- );
3790
- }
3791
- *walkUp(id, predicate) {
3792
- const includeSelf = true;
3793
- let nodeId = id;
3794
- do {
3795
- const item = this.getOrThrow(nodeId);
3796
- if (includeSelf || nodeId !== id) {
3797
- if (!predicate || predicate(item)) {
3798
- yield item;
3799
- }
3800
- }
3801
- nodeId = this.#_parentKeyFn(item);
3802
- } while (nodeId !== null);
3803
- }
3804
- // XXXX Generalize
3805
- *walkLeft(id, predicate) {
3806
- const self = this.getOrThrow(id);
3807
- const siblings = SortedList.from(this.getSiblings(id), this.#_lt);
3808
- for (const sibling of siblings.iterReversed()) {
3809
- if (this.#_lt(self, sibling)) continue;
3810
- if (!predicate || predicate(sibling)) {
3811
- yield sibling;
3812
- }
3813
- }
3814
- }
3815
- // XXXX Generalize
3816
- *walkRight(id, predicate) {
3817
- const self = this.getOrThrow(id);
3818
- const siblings = SortedList.from(this.getSiblings(id), this.#_lt);
3819
- for (const sibling of siblings) {
3820
- if (this.#_lt(sibling, self)) continue;
3821
- if (!predicate || predicate(sibling)) {
3822
- yield sibling;
3823
- }
3824
- }
3825
- }
3826
- // XXXX Generalize
3827
- *walkDown(id, predicate) {
3828
- const children = SortedList.from(this.getChildren(id), this.#_lt).rawArray;
3829
- for (let i = children.length - 1; i >= 0; i--) {
3830
- const child = children[i];
3831
- yield* this.walkDown(
3832
- this.#_primaryKey(child),
3833
- predicate
3834
- // "depth-first",
3835
- // true
3836
- );
3837
- if (!predicate || predicate(child)) {
3838
- yield child;
3839
- }
3840
- }
3841
- }
3842
- /** Returns all siblings, not including the item itself. */
3843
- getSiblings(id) {
3844
- const self = this.getOrThrow(id);
3845
- const parentId = this.getParentId(id);
3846
- return this.getChildren(parentId).filter((item) => item !== self);
3847
- }
3848
- [Symbol.iterator]() {
3849
- return this.#_sorted[Symbol.iterator]();
3850
- }
3851
- upsert(item) {
3852
- const pk = this.#_primaryKey(item);
3853
- const existing = this.#_items.get(pk);
3854
- if (existing) {
3855
- if (this.#_parentKeyFn(existing) !== this.#_parentKeyFn(item)) {
3856
- throw new Error(
3857
- "Cannot upsert parent ID changes that change the tree structure. Remove the entry first, and recreate it"
3858
- );
3859
- }
3860
- this.#_sorted.remove(existing);
3861
- }
3862
- this.#_items.set(pk, item);
3863
- this.#_sorted.add(item);
3864
- const parentId = this.#_parentKeyFn(item);
3865
- this.#_childrenOf.getOrCreate(parentId).add(pk);
3866
- }
3867
- remove(pk) {
3868
- const item = this.#_items.get(pk);
3869
- if (!item) return false;
3870
- const childIds = this.#_childrenOf.get(pk);
3871
- if (childIds) {
3872
- throw new Error(
3873
- `Cannot remove item '${pk}' while it still has children. Remove children first.`
3874
- );
3875
- }
3876
- const parentId = this.#_parentKeyFn(item);
3877
- const siblings = this.#_childrenOf.get(parentId);
3878
- if (siblings) {
3879
- siblings.delete(pk);
3880
- if (siblings.size === 0) {
3881
- this.#_childrenOf.delete(parentId);
3882
- }
3883
- }
3884
- this.#_sorted.remove(item);
3885
- this.#_childrenOf.delete(pk);
3886
- this.#_items.delete(pk);
3887
- return true;
3888
- }
3889
- clear() {
3890
- if (this.#_items.size === 0) return false;
3891
- this.#_childrenOf.clear();
3892
- this.#_items.clear();
3893
- this.#_sorted.clear();
3894
- return true;
3895
- }
3896
- };
3897
-
3898
- // src/protocol/AuthToken.ts
3899
- var Permission = /* @__PURE__ */ ((Permission2) => {
3900
- Permission2["Read"] = "room:read";
3901
- Permission2["Write"] = "room:write";
3902
- Permission2["PresenceWrite"] = "room:presence:write";
3903
- Permission2["CommentsWrite"] = "comments:write";
3904
- Permission2["CommentsRead"] = "comments:read";
3905
- return Permission2;
3906
- })(Permission || {});
3907
- function canWriteStorage(scopes) {
3908
- return scopes.includes("room:write" /* Write */);
3909
- }
3910
- function canComment(scopes) {
3911
- return scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:write" /* Write */);
3912
- }
3913
- function isValidAuthTokenPayload(data) {
3914
- return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */ || data.k === "sec-legacy" /* SECRET_LEGACY */);
3915
- }
3916
- function parseAuthToken(rawTokenString) {
3917
- const tokenParts = rawTokenString.split(".");
3918
- if (tokenParts.length !== 3) {
3919
- throw new Error("Authentication error: invalid JWT token");
3920
- }
3921
- const payload = tryParseJson(b64decode(tokenParts[1]));
3922
- if (!(payload && isValidAuthTokenPayload(payload))) {
3923
- throw new Error(
3924
- "Authentication error: expected a valid token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
3925
- );
3926
- }
3927
- return {
3928
- raw: rawTokenString,
3929
- parsed: payload
3930
- };
3931
- }
3932
-
3933
3710
  // src/lib/IncrementalJsonParser.ts
3934
3711
  var EMPTY_OBJECT = Object.freeze({});
3935
3712
  var NULL_KEYWORD_CHARS = Array.from(new Set("null"));
@@ -4099,95 +3876,237 @@ var IncrementalJsonParser = class {
4099
3876
  }
4100
3877
  };
4101
3878
 
4102
- // src/types/ai.ts
4103
- function replaceOrAppend(content, newItem, keyFn, now2) {
4104
- const existingIndex = findLastIndex(
4105
- content,
4106
- (item) => item.type === newItem.type && keyFn(item) === keyFn(newItem)
3879
+ // src/lib/shallow.ts
3880
+ function shallowArray(xs, ys) {
3881
+ if (xs.length !== ys.length) {
3882
+ return false;
3883
+ }
3884
+ for (let i = 0; i < xs.length; i++) {
3885
+ if (!Object.is(xs[i], ys[i])) {
3886
+ return false;
3887
+ }
3888
+ }
3889
+ return true;
3890
+ }
3891
+ function shallowObj(objA, objB) {
3892
+ if (!isPlainObject(objA) || !isPlainObject(objB)) {
3893
+ return false;
3894
+ }
3895
+ const keysA = Object.keys(objA);
3896
+ if (keysA.length !== Object.keys(objB).length) {
3897
+ return false;
3898
+ }
3899
+ return keysA.every(
3900
+ (key) => Object.prototype.hasOwnProperty.call(objB, key) && Object.is(objA[key], objB[key])
4107
3901
  );
4108
- if (existingIndex > -1) {
4109
- content[existingIndex] = newItem;
4110
- } else {
4111
- closePart(content[content.length - 1], now2);
4112
- content.push(newItem);
3902
+ }
3903
+ function shallow(a, b) {
3904
+ if (Object.is(a, b)) {
3905
+ return true;
3906
+ }
3907
+ const isArrayA = Array.isArray(a);
3908
+ const isArrayB = Array.isArray(b);
3909
+ if (isArrayA || isArrayB) {
3910
+ if (!isArrayA || !isArrayB) {
3911
+ return false;
3912
+ }
3913
+ return shallowArray(a, b);
3914
+ }
3915
+ return shallowObj(a, b);
3916
+ }
3917
+ function shallow2(a, b) {
3918
+ if (!isPlainObject(a) || !isPlainObject(b)) {
3919
+ return shallow(a, b);
3920
+ }
3921
+ const keysA = Object.keys(a);
3922
+ if (keysA.length !== Object.keys(b).length) {
3923
+ return false;
3924
+ }
3925
+ return keysA.every(
3926
+ (key) => Object.prototype.hasOwnProperty.call(b, key) && shallow(a[key], b[key])
3927
+ );
3928
+ }
3929
+
3930
+ // src/lib/TreePool.ts
3931
+ var TreePool = class {
3932
+ #_items;
3933
+ #_childrenOf;
3934
+ #_sorted;
3935
+ #_primaryKey;
3936
+ #_parentKeyFn;
3937
+ #_lt;
3938
+ constructor(primaryKey, parentKey, lt) {
3939
+ this.#_primaryKey = primaryKey;
3940
+ this.#_parentKeyFn = parentKey;
3941
+ this.#_lt = lt;
3942
+ this.#_items = /* @__PURE__ */ new Map();
3943
+ this.#_childrenOf = new DefaultMap(() => /* @__PURE__ */ new Set());
3944
+ this.#_sorted = SortedList.with(lt);
3945
+ }
3946
+ get(id) {
3947
+ return this.#_items.get(id);
3948
+ }
3949
+ getOrThrow(id) {
3950
+ return _nullishCoalesce(this.get(id), () => ( raise(`Item with id ${id} not found`)));
3951
+ }
3952
+ get sorted() {
3953
+ return this.#_sorted;
3954
+ }
3955
+ getParentId(id) {
3956
+ const item = this.getOrThrow(id);
3957
+ return this.#_parentKeyFn(item);
3958
+ }
3959
+ getParent(id) {
3960
+ const parentId = this.getParentId(id);
3961
+ return parentId ? this.getOrThrow(parentId) : null;
3962
+ }
3963
+ getChildren(id) {
3964
+ const childIds = this.#_childrenOf.get(id);
3965
+ if (!childIds) return [];
3966
+ return Array.from(childIds).map(
3967
+ (id2) => this.#_items.get(id2)
3968
+ // eslint-disable-line no-restricted-syntax
3969
+ );
3970
+ }
3971
+ *walkUp(id, predicate) {
3972
+ const includeSelf = true;
3973
+ let nodeId = id;
3974
+ do {
3975
+ const item = this.getOrThrow(nodeId);
3976
+ if (includeSelf || nodeId !== id) {
3977
+ if (!predicate || predicate(item)) {
3978
+ yield item;
3979
+ }
3980
+ }
3981
+ nodeId = this.#_parentKeyFn(item);
3982
+ } while (nodeId !== null);
3983
+ }
3984
+ // XXXX Generalize
3985
+ *walkLeft(id, predicate) {
3986
+ const self = this.getOrThrow(id);
3987
+ const siblings = SortedList.from(this.getSiblings(id), this.#_lt);
3988
+ for (const sibling of siblings.iterReversed()) {
3989
+ if (this.#_lt(self, sibling)) continue;
3990
+ if (!predicate || predicate(sibling)) {
3991
+ yield sibling;
3992
+ }
3993
+ }
3994
+ }
3995
+ // XXXX Generalize
3996
+ *walkRight(id, predicate) {
3997
+ const self = this.getOrThrow(id);
3998
+ const siblings = SortedList.from(this.getSiblings(id), this.#_lt);
3999
+ for (const sibling of siblings) {
4000
+ if (this.#_lt(sibling, self)) continue;
4001
+ if (!predicate || predicate(sibling)) {
4002
+ yield sibling;
4003
+ }
4004
+ }
4005
+ }
4006
+ // XXXX Generalize
4007
+ *walkDown(id, predicate) {
4008
+ const children = SortedList.from(this.getChildren(id), this.#_lt).rawArray;
4009
+ for (let i = children.length - 1; i >= 0; i--) {
4010
+ const child = children[i];
4011
+ yield* this.walkDown(
4012
+ this.#_primaryKey(child),
4013
+ predicate
4014
+ // "depth-first",
4015
+ // true
4016
+ );
4017
+ if (!predicate || predicate(child)) {
4018
+ yield child;
4019
+ }
4020
+ }
4021
+ }
4022
+ /** Returns all siblings, not including the item itself. */
4023
+ getSiblings(id) {
4024
+ const self = this.getOrThrow(id);
4025
+ const parentId = this.getParentId(id);
4026
+ return this.getChildren(parentId).filter((item) => item !== self);
4113
4027
  }
4114
- }
4115
- function closePart(prevPart, endedAt) {
4116
- if (_optionalChain([prevPart, 'optionalAccess', _62 => _62.type]) === "reasoning") {
4117
- prevPart.endedAt ??= endedAt;
4028
+ [Symbol.iterator]() {
4029
+ return this.#_sorted[Symbol.iterator]();
4118
4030
  }
4119
- }
4120
- function patchContentWithDelta(content, delta) {
4121
- if (delta === null)
4122
- return;
4123
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
4124
- const lastPart = content[content.length - 1];
4125
- switch (delta.type) {
4126
- case "text-delta":
4127
- if (_optionalChain([lastPart, 'optionalAccess', _63 => _63.type]) === "text") {
4128
- lastPart.text += delta.textDelta;
4129
- } else {
4130
- closePart(lastPart, now2);
4131
- content.push({ type: "text", text: delta.textDelta });
4132
- }
4133
- break;
4134
- case "reasoning-delta":
4135
- if (_optionalChain([lastPart, 'optionalAccess', _64 => _64.type]) === "reasoning") {
4136
- lastPart.text += delta.textDelta;
4137
- } else {
4138
- closePart(lastPart, now2);
4139
- content.push({
4140
- type: "reasoning",
4141
- text: delta.textDelta,
4142
- startedAt: now2
4143
- });
4031
+ upsert(item) {
4032
+ const pk = this.#_primaryKey(item);
4033
+ const existing = this.#_items.get(pk);
4034
+ if (existing) {
4035
+ if (this.#_parentKeyFn(existing) !== this.#_parentKeyFn(item)) {
4036
+ throw new Error(
4037
+ "Cannot upsert parent ID changes that change the tree structure. Remove the entry first, and recreate it"
4038
+ );
4144
4039
  }
4145
- break;
4146
- case "tool-stream": {
4147
- const toolInvocation = createReceivingToolInvocation(
4148
- delta.invocationId,
4149
- delta.name
4040
+ this.#_sorted.remove(existing);
4041
+ }
4042
+ this.#_items.set(pk, item);
4043
+ this.#_sorted.add(item);
4044
+ const parentId = this.#_parentKeyFn(item);
4045
+ this.#_childrenOf.getOrCreate(parentId).add(pk);
4046
+ }
4047
+ remove(pk) {
4048
+ const item = this.#_items.get(pk);
4049
+ if (!item) return false;
4050
+ const childIds = this.#_childrenOf.get(pk);
4051
+ if (childIds) {
4052
+ throw new Error(
4053
+ `Cannot remove item '${pk}' while it still has children. Remove children first.`
4150
4054
  );
4151
- content.push(toolInvocation);
4152
- break;
4153
4055
  }
4154
- case "tool-delta": {
4155
- if (_optionalChain([lastPart, 'optionalAccess', _65 => _65.type]) === "tool-invocation" && lastPart.stage === "receiving") {
4156
- _optionalChain([lastPart, 'access', _66 => _66.__appendDelta, 'optionalCall', _67 => _67(delta.delta)]);
4056
+ const parentId = this.#_parentKeyFn(item);
4057
+ const siblings = this.#_childrenOf.get(parentId);
4058
+ if (siblings) {
4059
+ siblings.delete(pk);
4060
+ if (siblings.size === 0) {
4061
+ this.#_childrenOf.delete(parentId);
4157
4062
  }
4158
- break;
4159
4063
  }
4160
- case "tool-invocation":
4161
- replaceOrAppend(content, delta, (x) => x.invocationId, now2);
4162
- break;
4163
- case "retrieval":
4164
- replaceOrAppend(content, delta, (x) => x.id, now2);
4165
- break;
4166
- default:
4167
- return assertNever(delta, "Unhandled case");
4064
+ this.#_sorted.remove(item);
4065
+ this.#_childrenOf.delete(pk);
4066
+ this.#_items.delete(pk);
4067
+ return true;
4068
+ }
4069
+ clear() {
4070
+ if (this.#_items.size === 0) return false;
4071
+ this.#_childrenOf.clear();
4072
+ this.#_items.clear();
4073
+ this.#_sorted.clear();
4074
+ return true;
4168
4075
  }
4076
+ };
4077
+
4078
+ // src/protocol/AuthToken.ts
4079
+ var Permission = /* @__PURE__ */ ((Permission2) => {
4080
+ Permission2["Read"] = "room:read";
4081
+ Permission2["Write"] = "room:write";
4082
+ Permission2["PresenceWrite"] = "room:presence:write";
4083
+ Permission2["CommentsWrite"] = "comments:write";
4084
+ Permission2["CommentsRead"] = "comments:read";
4085
+ return Permission2;
4086
+ })(Permission || {});
4087
+ function canWriteStorage(scopes) {
4088
+ return scopes.includes("room:write" /* Write */);
4169
4089
  }
4170
- function createReceivingToolInvocation(invocationId, name, partialArgsText = "") {
4171
- const parser = new IncrementalJsonParser(partialArgsText);
4090
+ function canComment(scopes) {
4091
+ return scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:write" /* Write */);
4092
+ }
4093
+ function isValidAuthTokenPayload(data) {
4094
+ return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */ || data.k === "sec-legacy" /* SECRET_LEGACY */);
4095
+ }
4096
+ function parseAuthToken(rawTokenString) {
4097
+ const tokenParts = rawTokenString.split(".");
4098
+ if (tokenParts.length !== 3) {
4099
+ throw new Error("Authentication error: invalid JWT token");
4100
+ }
4101
+ const payload = tryParseJson(b64decode(tokenParts[1]));
4102
+ if (!(payload && isValidAuthTokenPayload(payload))) {
4103
+ throw new Error(
4104
+ "Authentication error: expected a valid token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
4105
+ );
4106
+ }
4172
4107
  return {
4173
- type: "tool-invocation",
4174
- stage: "receiving",
4175
- invocationId,
4176
- name,
4177
- // --- Alternative implementation for FRONTEND only ------------------------
4178
- get partialArgsText() {
4179
- return parser.source;
4180
- },
4181
- // prettier-ignore
4182
- get partialArgs() {
4183
- return parser.json;
4184
- },
4185
- // prettier-ignore
4186
- __appendDelta(delta) {
4187
- parser.append(delta);
4188
- }
4189
- // prettier-ignore
4190
- // ------------------------------------------------------------------------
4108
+ raw: rawTokenString,
4109
+ parsed: payload
4191
4110
  };
4192
4111
  }
4193
4112
 
@@ -4255,6 +4174,23 @@ var KnowledgeStack = class {
4255
4174
  this.invalidate();
4256
4175
  }
4257
4176
  };
4177
+ function createStore_forKnowledge() {
4178
+ const knowledgeByChatId = new DefaultMap(
4179
+ (_chatId) => new KnowledgeStack()
4180
+ );
4181
+ function getKnowledgeStack(chatId) {
4182
+ return knowledgeByChatId.getOrCreate(_nullishCoalesce(chatId, () => ( kWILDCARD)));
4183
+ }
4184
+ function getKnowledgeForChat(chatId) {
4185
+ const globalKnowledge = knowledgeByChatId.getOrCreate(kWILDCARD).get();
4186
+ const scopedKnowledge = _nullishCoalesce(_optionalChain([knowledgeByChatId, 'access', _62 => _62.get, 'call', _63 => _63(chatId), 'optionalAccess', _64 => _64.get, 'call', _65 => _65()]), () => ( []));
4187
+ return [...globalKnowledge, ...scopedKnowledge];
4188
+ }
4189
+ return {
4190
+ getKnowledgeStack,
4191
+ getKnowledgeForChat
4192
+ };
4193
+ }
4258
4194
  function now() {
4259
4195
  return (/* @__PURE__ */ new Date()).toISOString();
4260
4196
  }
@@ -4272,7 +4208,7 @@ function createStore_forTools() {
4272
4208
  return DerivedSignal.from(() => {
4273
4209
  return (
4274
4210
  // A tool that's registered and scoped to a specific chat ID...
4275
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _68 => _68.get, 'call', _69 => _69()]), () => ( // ...or a globally registered tool
4211
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _66 => _66.get, 'call', _67 => _67()]), () => ( // ...or a globally registered tool
4276
4212
  toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
4277
4213
  );
4278
4214
  });
@@ -4302,8 +4238,8 @@ function createStore_forTools() {
4302
4238
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
4303
4239
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
4304
4240
  return Array.from([
4305
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _70 => _70.entries, 'call', _71 => _71()]), () => ( [])),
4306
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _72 => _72.entries, 'call', _73 => _73()]), () => ( []))
4241
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _68 => _68.entries, 'call', _69 => _69()]), () => ( [])),
4242
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _70 => _70.entries, 'call', _71 => _71()]), () => ( []))
4307
4243
  ]).flatMap(([name, tool\u03A3]) => {
4308
4244
  const tool = tool\u03A3.get();
4309
4245
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -4406,7 +4342,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4406
4342
  } else {
4407
4343
  continue;
4408
4344
  }
4409
- const executeFn = _optionalChain([toolsStore, 'access', _74 => _74.getTool\u03A3, 'call', _75 => _75(toolInvocation.name, message.chatId), 'access', _76 => _76.get, 'call', _77 => _77(), 'optionalAccess', _78 => _78.execute]);
4345
+ const executeFn = _optionalChain([toolsStore, 'access', _72 => _72.getTool\u03A3, 'call', _73 => _73(toolInvocation.name, message.chatId), 'access', _74 => _74.get, 'call', _75 => _75(), 'optionalAccess', _76 => _76.execute]);
4410
4346
  if (executeFn) {
4411
4347
  (async () => {
4412
4348
  const result = await executeFn(toolInvocation.args, {
@@ -4505,8 +4441,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4505
4441
  const spine = [];
4506
4442
  let lastVisitedMessage = null;
4507
4443
  for (const message2 of pool.walkUp(leaf.id)) {
4508
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _79 => _79(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _80 => _80.id]), () => ( null));
4509
- const next = _nullishCoalesce(_optionalChain([first, 'call', _81 => _81(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _82 => _82.id]), () => ( null));
4444
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _77 => _77(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _78 => _78.id]), () => ( null));
4445
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _79 => _79(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _80 => _80.id]), () => ( null));
4510
4446
  if (!message2.deletedAt || prev || next) {
4511
4447
  const node = {
4512
4448
  ...message2,
@@ -4572,7 +4508,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4572
4508
  const latest = pool.sorted.findRight(
4573
4509
  (m) => m.role === "assistant" && !m.deletedAt
4574
4510
  );
4575
- return _optionalChain([latest, 'optionalAccess', _83 => _83.copilotId]);
4511
+ return _optionalChain([latest, 'optionalAccess', _81 => _81.copilotId]);
4576
4512
  }
4577
4513
  return {
4578
4514
  // Readers
@@ -4603,11 +4539,11 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4603
4539
  *getAutoExecutingMessageIds() {
4604
4540
  for (const messageId of myMessages) {
4605
4541
  const message = getMessageById(messageId);
4606
- if (_optionalChain([message, 'optionalAccess', _84 => _84.role]) === "assistant" && message.status === "awaiting-tool") {
4542
+ if (_optionalChain([message, 'optionalAccess', _82 => _82.role]) === "assistant" && message.status === "awaiting-tool") {
4607
4543
  const isAutoExecuting = message.contentSoFar.some((part) => {
4608
4544
  if (part.type === "tool-invocation" && part.stage === "executing") {
4609
4545
  const tool = toolsStore.getTool\u03A3(part.name, message.chatId).get();
4610
- return typeof _optionalChain([tool, 'optionalAccess', _85 => _85.execute]) === "function";
4546
+ return typeof _optionalChain([tool, 'optionalAccess', _83 => _83.execute]) === "function";
4611
4547
  }
4612
4548
  return false;
4613
4549
  });
@@ -4658,6 +4594,7 @@ function createAi(config) {
4658
4594
  );
4659
4595
  const chatsStore = createStore_forUserAiChats();
4660
4596
  const toolsStore = createStore_forTools();
4597
+ const knowledgeStore = createStore_forKnowledge();
4661
4598
  const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
4662
4599
  const context = {
4663
4600
  staticSessionInfoSig: new Signal(null),
@@ -4666,8 +4603,9 @@ function createAi(config) {
4666
4603
  chatsStore,
4667
4604
  messagesStore,
4668
4605
  toolsStore,
4669
- knowledge: new KnowledgeStack()
4606
+ knowledgeStore
4670
4607
  };
4608
+ const status\u03A3 = new Signal("initial");
4671
4609
  const DELTA_THROTTLE = 25;
4672
4610
  let pendingDeltas = [];
4673
4611
  let deltaBatchTimer = null;
@@ -4691,7 +4629,7 @@ function createAi(config) {
4691
4629
  }
4692
4630
  }
4693
4631
  let lastTokenKey;
4694
- function onStatusDidChange(_newStatus) {
4632
+ function onStatusDidChange(newStatus) {
4695
4633
  const authValue = managedSocket.authValue;
4696
4634
  if (authValue !== null) {
4697
4635
  const tokenKey = getBearerTokenFromAuthValue(authValue);
@@ -4711,6 +4649,7 @@ function createAi(config) {
4711
4649
  }
4712
4650
  }
4713
4651
  }
4652
+ status\u03A3.set(newStatus);
4714
4653
  }
4715
4654
  let _connectionLossTimerId;
4716
4655
  let _hasLostConnection = false;
@@ -4752,7 +4691,7 @@ function createAi(config) {
4752
4691
  flushPendingDeltas();
4753
4692
  switch (msg.event) {
4754
4693
  case "cmd-failed":
4755
- _optionalChain([pendingCmd, 'optionalAccess', _86 => _86.reject, 'call', _87 => _87(new Error(msg.error))]);
4694
+ _optionalChain([pendingCmd, 'optionalAccess', _84 => _84.reject, 'call', _85 => _85(new Error(msg.error))]);
4756
4695
  break;
4757
4696
  case "settle": {
4758
4697
  context.messagesStore.upsert(msg.message);
@@ -4829,7 +4768,7 @@ function createAi(config) {
4829
4768
  return assertNever(msg, "Unhandled case");
4830
4769
  }
4831
4770
  }
4832
- _optionalChain([pendingCmd, 'optionalAccess', _88 => _88.resolve, 'call', _89 => _89(msg)]);
4771
+ _optionalChain([pendingCmd, 'optionalAccess', _86 => _86.resolve, 'call', _87 => _87(msg)]);
4833
4772
  }
4834
4773
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4835
4774
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4895,17 +4834,8 @@ function createAi(config) {
4895
4834
  chatId
4896
4835
  });
4897
4836
  }
4898
- function registerKnowledgeLayer(uniqueLayerId) {
4899
- return context.knowledge.registerLayer(uniqueLayerId);
4900
- }
4901
- function deregisterKnowledgeLayer(layerKey) {
4902
- context.knowledge.deregisterLayer(layerKey);
4903
- }
4904
- function updateKnowledge(layerKey, data, key = nanoid()) {
4905
- context.knowledge.updateKnowledge(layerKey, key, data);
4906
- }
4907
4837
  async function setToolResult(chatId, messageId, invocationId, result, options) {
4908
- const knowledge = context.knowledge.get();
4838
+ const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
4909
4839
  const tools = context.toolsStore.getToolDescriptions(chatId);
4910
4840
  const resp = await sendClientMsgWithResponse({
4911
4841
  cmd: "set-tool-result",
@@ -4914,9 +4844,9 @@ function createAi(config) {
4914
4844
  invocationId,
4915
4845
  result,
4916
4846
  generationOptions: {
4917
- copilotId: _optionalChain([options, 'optionalAccess', _90 => _90.copilotId]),
4918
- stream: _optionalChain([options, 'optionalAccess', _91 => _91.stream]),
4919
- timeout: _optionalChain([options, 'optionalAccess', _92 => _92.timeout]),
4847
+ copilotId: _optionalChain([options, 'optionalAccess', _88 => _88.copilotId]),
4848
+ stream: _optionalChain([options, 'optionalAccess', _89 => _89.stream]),
4849
+ timeout: _optionalChain([options, 'optionalAccess', _90 => _90.timeout]),
4920
4850
  // Knowledge and tools aren't coming from the options, but retrieved
4921
4851
  // from the global context
4922
4852
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4934,7 +4864,7 @@ function createAi(config) {
4934
4864
  }
4935
4865
  }
4936
4866
  const win = typeof window !== "undefined" ? window : void 0;
4937
- _optionalChain([win, 'optionalAccess', _93 => _93.addEventListener, 'call', _94 => _94("beforeunload", handleBeforeUnload, { once: true })]);
4867
+ _optionalChain([win, 'optionalAccess', _91 => _91.addEventListener, 'call', _92 => _92("beforeunload", handleBeforeUnload, { once: true })]);
4938
4868
  return Object.defineProperty(
4939
4869
  {
4940
4870
  [kInternal]: {
@@ -4952,9 +4882,9 @@ function createAi(config) {
4952
4882
  deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
4953
4883
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4954
4884
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4955
- const globalKnowledge = context.knowledge.get();
4956
- const requestKnowledge = _optionalChain([options, 'optionalAccess', _95 => _95.knowledge]) || [];
4957
- const combinedKnowledge = [...globalKnowledge, ...requestKnowledge];
4885
+ const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
4886
+ const requestKnowledge = _optionalChain([options, 'optionalAccess', _93 => _93.knowledge]) || [];
4887
+ const combinedKnowledge = [...knowledge, ...requestKnowledge];
4958
4888
  const tools = context.toolsStore.getToolDescriptions(chatId);
4959
4889
  messagesStore.markMine(targetMessageId);
4960
4890
  const resp = await sendClientMsgWithResponse({
@@ -4963,9 +4893,9 @@ function createAi(config) {
4963
4893
  sourceMessage: userMessage,
4964
4894
  targetMessageId,
4965
4895
  generationOptions: {
4966
- copilotId: _optionalChain([options, 'optionalAccess', _96 => _96.copilotId]),
4967
- stream: _optionalChain([options, 'optionalAccess', _97 => _97.stream]),
4968
- timeout: _optionalChain([options, 'optionalAccess', _98 => _98.timeout]),
4896
+ copilotId: _optionalChain([options, 'optionalAccess', _94 => _94.copilotId]),
4897
+ stream: _optionalChain([options, 'optionalAccess', _95 => _95.stream]),
4898
+ timeout: _optionalChain([options, 'optionalAccess', _96 => _96.timeout]),
4969
4899
  // Combine global knowledge with request-specific knowledge
4970
4900
  knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
4971
4901
  tools: tools.length > 0 ? tools : void 0
@@ -4978,14 +4908,24 @@ function createAi(config) {
4978
4908
  getStatus: () => managedSocket.getStatus(),
4979
4909
  signals: {
4980
4910
  getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
4981
- getTool\u03A3: context.toolsStore.getTool\u03A3
4911
+ getTool\u03A3: context.toolsStore.getTool\u03A3,
4912
+ status\u03A3
4982
4913
  },
4983
4914
  getChatById: context.chatsStore.getChatById,
4984
4915
  queryChats: context.chatsStore.findMany,
4985
4916
  getLastUsedCopilotId: context.messagesStore.getLastUsedCopilotId,
4986
- registerKnowledgeLayer,
4987
- deregisterKnowledgeLayer,
4988
- updateKnowledge,
4917
+ registerKnowledgeLayer: (uniqueLayerId, chatId) => {
4918
+ const stack = context.knowledgeStore.getKnowledgeStack(chatId);
4919
+ const layerKey = stack.registerLayer(uniqueLayerId);
4920
+ const deregister = () => stack.deregisterLayer(layerKey);
4921
+ return {
4922
+ layerKey,
4923
+ deregister
4924
+ };
4925
+ },
4926
+ updateKnowledge: (layerKey, data, key, chatId) => {
4927
+ context.knowledgeStore.getKnowledgeStack(chatId).updateKnowledge(layerKey, _nullishCoalesce(key, () => ( nanoid())), data);
4928
+ },
4989
4929
  registerTool: context.toolsStore.registerTool
4990
4930
  },
4991
4931
  kInternal,
@@ -5002,7 +4942,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
5002
4942
  }
5003
4943
  const url2 = new URL(baseUrl);
5004
4944
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
5005
- url2.pathname = "/ai/v6";
4945
+ url2.pathname = "/ai/v7";
5006
4946
  if (authValue.type === "secret") {
5007
4947
  url2.searchParams.set("tok", authValue.token.raw);
5008
4948
  } else if (authValue.type === "public") {
@@ -5014,6 +4954,112 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
5014
4954
  return new ws(url2.toString());
5015
4955
  };
5016
4956
  }
4957
+ function replaceOrAppend(content, newItem, keyFn, now2) {
4958
+ const existingIndex = findLastIndex(
4959
+ content,
4960
+ (item) => item.type === newItem.type && keyFn(item) === keyFn(newItem)
4961
+ );
4962
+ if (existingIndex > -1) {
4963
+ content[existingIndex] = newItem;
4964
+ } else {
4965
+ closePart(content[content.length - 1], now2);
4966
+ content.push(newItem);
4967
+ }
4968
+ }
4969
+ function closePart(prevPart, endedAt) {
4970
+ if (_optionalChain([prevPart, 'optionalAccess', _97 => _97.type]) === "reasoning") {
4971
+ prevPart.endedAt ??= endedAt;
4972
+ }
4973
+ }
4974
+ function patchContentWithDelta(content, delta) {
4975
+ if (delta === null)
4976
+ return;
4977
+ const parts = content.filter(
4978
+ (part) => part.type !== "sources"
4979
+ );
4980
+ const sources = content.filter((part) => part.type === "sources").flatMap((part) => part.sources);
4981
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
4982
+ const lastPart = parts[parts.length - 1];
4983
+ switch (delta.type) {
4984
+ case "text-delta":
4985
+ if (_optionalChain([lastPart, 'optionalAccess', _98 => _98.type]) === "text") {
4986
+ lastPart.text += delta.textDelta;
4987
+ } else {
4988
+ closePart(lastPart, now2);
4989
+ parts.push({ type: "text", text: delta.textDelta });
4990
+ }
4991
+ break;
4992
+ case "reasoning-delta":
4993
+ if (_optionalChain([lastPart, 'optionalAccess', _99 => _99.type]) === "reasoning") {
4994
+ lastPart.text += delta.textDelta;
4995
+ } else {
4996
+ closePart(lastPart, now2);
4997
+ parts.push({
4998
+ type: "reasoning",
4999
+ text: delta.textDelta,
5000
+ startedAt: now2
5001
+ });
5002
+ }
5003
+ break;
5004
+ case "tool-stream": {
5005
+ const toolInvocation = createReceivingToolInvocation(
5006
+ delta.invocationId,
5007
+ delta.name
5008
+ );
5009
+ parts.push(toolInvocation);
5010
+ break;
5011
+ }
5012
+ case "tool-delta": {
5013
+ if (_optionalChain([lastPart, 'optionalAccess', _100 => _100.type]) === "tool-invocation" && lastPart.stage === "receiving") {
5014
+ _optionalChain([lastPart, 'access', _101 => _101.__appendDelta, 'optionalCall', _102 => _102(delta.delta)]);
5015
+ }
5016
+ break;
5017
+ }
5018
+ case "tool-invocation":
5019
+ replaceOrAppend(parts, delta, (x) => x.invocationId, now2);
5020
+ break;
5021
+ case "retrieval":
5022
+ replaceOrAppend(parts, delta, (x) => x.id, now2);
5023
+ break;
5024
+ case "source": {
5025
+ sources.push(delta);
5026
+ break;
5027
+ }
5028
+ default:
5029
+ return assertNever(delta, "Unhandled case");
5030
+ }
5031
+ if (sources.length > 0) {
5032
+ parts.push({
5033
+ type: "sources",
5034
+ sources
5035
+ });
5036
+ }
5037
+ content.length = 0;
5038
+ content.push(...parts);
5039
+ }
5040
+ function createReceivingToolInvocation(invocationId, name, partialArgsText = "") {
5041
+ const parser = new IncrementalJsonParser(partialArgsText);
5042
+ return {
5043
+ type: "tool-invocation",
5044
+ stage: "receiving",
5045
+ invocationId,
5046
+ name,
5047
+ // --- Alternative implementation for FRONTEND only ------------------------
5048
+ get partialArgsText() {
5049
+ return parser.source;
5050
+ },
5051
+ // prettier-ignore
5052
+ get partialArgs() {
5053
+ return parser.json;
5054
+ },
5055
+ // prettier-ignore
5056
+ __appendDelta(delta) {
5057
+ parser.append(delta);
5058
+ }
5059
+ // prettier-ignore
5060
+ // ------------------------------------------------------------------------
5061
+ };
5062
+ }
5017
5063
 
5018
5064
  // src/auth-manager.ts
5019
5065
  function createAuthManager(authOptions, onAuthenticate) {
@@ -5066,7 +5112,7 @@ function createAuthManager(authOptions, onAuthenticate) {
5066
5112
  return void 0;
5067
5113
  }
5068
5114
  async function makeAuthRequest(options) {
5069
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _99 => _99.polyfills, 'optionalAccess', _100 => _100.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
5115
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _103 => _103.polyfills, 'optionalAccess', _104 => _104.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
5070
5116
  if (authentication.type === "private") {
5071
5117
  if (fetcher === void 0) {
5072
5118
  throw new StopRetrying(
@@ -5082,7 +5128,7 @@ function createAuthManager(authOptions, onAuthenticate) {
5082
5128
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
5083
5129
  );
5084
5130
  }
5085
- _optionalChain([onAuthenticate, 'optionalCall', _101 => _101(parsed.parsed)]);
5131
+ _optionalChain([onAuthenticate, 'optionalCall', _105 => _105(parsed.parsed)]);
5086
5132
  return parsed;
5087
5133
  }
5088
5134
  if (authentication.type === "custom") {
@@ -5090,7 +5136,7 @@ function createAuthManager(authOptions, onAuthenticate) {
5090
5136
  if (response && typeof response === "object") {
5091
5137
  if (typeof response.token === "string") {
5092
5138
  const parsed = parseAuthToken(response.token);
5093
- _optionalChain([onAuthenticate, 'optionalCall', _102 => _102(parsed.parsed)]);
5139
+ _optionalChain([onAuthenticate, 'optionalCall', _106 => _106(parsed.parsed)]);
5094
5140
  return parsed;
5095
5141
  } else if (typeof response.error === "string") {
5096
5142
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -5249,7 +5295,7 @@ function sendToPanel(message, options) {
5249
5295
  ...message,
5250
5296
  source: "liveblocks-devtools-client"
5251
5297
  };
5252
- if (!(_optionalChain([options, 'optionalAccess', _103 => _103.force]) || _bridgeActive)) {
5298
+ if (!(_optionalChain([options, 'optionalAccess', _107 => _107.force]) || _bridgeActive)) {
5253
5299
  return;
5254
5300
  }
5255
5301
  window.postMessage(fullMsg, "*");
@@ -5257,7 +5303,7 @@ function sendToPanel(message, options) {
5257
5303
  var eventSource = makeEventSource();
5258
5304
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
5259
5305
  window.addEventListener("message", (event) => {
5260
- if (event.source === window && _optionalChain([event, 'access', _104 => _104.data, 'optionalAccess', _105 => _105.source]) === "liveblocks-devtools-panel") {
5306
+ if (event.source === window && _optionalChain([event, 'access', _108 => _108.data, 'optionalAccess', _109 => _109.source]) === "liveblocks-devtools-panel") {
5261
5307
  eventSource.notify(event.data);
5262
5308
  } else {
5263
5309
  }
@@ -5399,7 +5445,7 @@ function fullSync(room) {
5399
5445
  msg: "room::sync::full",
5400
5446
  roomId: room.id,
5401
5447
  status: room.getStatus(),
5402
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _106 => _106.toTreeNode, 'call', _107 => _107("root"), 'access', _108 => _108.payload]), () => ( null)),
5448
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _110 => _110.toTreeNode, 'call', _111 => _111("root"), 'access', _112 => _112.payload]), () => ( null)),
5403
5449
  me,
5404
5450
  others
5405
5451
  });
@@ -5706,7 +5752,7 @@ function createManagedPool(roomId, options) {
5706
5752
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5707
5753
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5708
5754
  dispatch(ops, reverse, storageUpdates) {
5709
- _optionalChain([onDispatch, 'optionalCall', _109 => _109(ops, reverse, storageUpdates)]);
5755
+ _optionalChain([onDispatch, 'optionalCall', _113 => _113(ops, reverse, storageUpdates)]);
5710
5756
  },
5711
5757
  assertStorageIsWritable: () => {
5712
5758
  if (!isStorageWritable()) {
@@ -5933,7 +5979,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5933
5979
  return [
5934
5980
  {
5935
5981
  type: 8 /* CREATE_REGISTER */,
5936
- opId: _optionalChain([pool, 'optionalAccess', _110 => _110.generateOpId, 'call', _111 => _111()]),
5982
+ opId: _optionalChain([pool, 'optionalAccess', _114 => _114.generateOpId, 'call', _115 => _115()]),
5937
5983
  id: this._id,
5938
5984
  parentId,
5939
5985
  parentKey,
@@ -6039,7 +6085,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6039
6085
  const ops = [];
6040
6086
  const op = {
6041
6087
  id: this._id,
6042
- opId: _optionalChain([pool, 'optionalAccess', _112 => _112.generateOpId, 'call', _113 => _113()]),
6088
+ opId: _optionalChain([pool, 'optionalAccess', _116 => _116.generateOpId, 'call', _117 => _117()]),
6043
6089
  type: 2 /* CREATE_LIST */,
6044
6090
  parentId,
6045
6091
  parentKey
@@ -6310,7 +6356,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6310
6356
  #applyInsertUndoRedo(op) {
6311
6357
  const { id, parentKey: key } = op;
6312
6358
  const child = creationOpToLiveNode(op);
6313
- if (_optionalChain([this, 'access', _114 => _114._pool, 'optionalAccess', _115 => _115.getNode, 'call', _116 => _116(id)]) !== void 0) {
6359
+ if (_optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.getNode, 'call', _120 => _120(id)]) !== void 0) {
6314
6360
  return { modified: false };
6315
6361
  }
6316
6362
  child._attach(id, nn(this._pool));
@@ -6318,8 +6364,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6318
6364
  const existingItemIndex = this._indexOfPosition(key);
6319
6365
  let newKey = key;
6320
6366
  if (existingItemIndex !== -1) {
6321
- const before2 = _optionalChain([this, 'access', _117 => _117.#items, 'access', _118 => _118[existingItemIndex], 'optionalAccess', _119 => _119._parentPos]);
6322
- const after2 = _optionalChain([this, 'access', _120 => _120.#items, 'access', _121 => _121[existingItemIndex + 1], 'optionalAccess', _122 => _122._parentPos]);
6367
+ const before2 = _optionalChain([this, 'access', _121 => _121.#items, 'access', _122 => _122[existingItemIndex], 'optionalAccess', _123 => _123._parentPos]);
6368
+ const after2 = _optionalChain([this, 'access', _124 => _124.#items, 'access', _125 => _125[existingItemIndex + 1], 'optionalAccess', _126 => _126._parentPos]);
6323
6369
  newKey = makePosition(before2, after2);
6324
6370
  child._setParentLink(this, newKey);
6325
6371
  }
@@ -6333,7 +6379,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6333
6379
  #applySetUndoRedo(op) {
6334
6380
  const { id, parentKey: key } = op;
6335
6381
  const child = creationOpToLiveNode(op);
6336
- if (_optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.getNode, 'call', _125 => _125(id)]) !== void 0) {
6382
+ if (_optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.getNode, 'call', _129 => _129(id)]) !== void 0) {
6337
6383
  return { modified: false };
6338
6384
  }
6339
6385
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -6454,7 +6500,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6454
6500
  } else {
6455
6501
  this.#items[existingItemIndex]._setParentLink(
6456
6502
  this,
6457
- makePosition(newKey, _optionalChain([this, 'access', _126 => _126.#items, 'access', _127 => _127[existingItemIndex + 1], 'optionalAccess', _128 => _128._parentPos]))
6503
+ makePosition(newKey, _optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131[existingItemIndex + 1], 'optionalAccess', _132 => _132._parentPos]))
6458
6504
  );
6459
6505
  const previousIndex = this.#items.indexOf(child);
6460
6506
  child._setParentLink(this, newKey);
@@ -6479,7 +6525,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6479
6525
  if (existingItemIndex !== -1) {
6480
6526
  this.#items[existingItemIndex]._setParentLink(
6481
6527
  this,
6482
- makePosition(newKey, _optionalChain([this, 'access', _129 => _129.#items, 'access', _130 => _130[existingItemIndex + 1], 'optionalAccess', _131 => _131._parentPos]))
6528
+ makePosition(newKey, _optionalChain([this, 'access', _133 => _133.#items, 'access', _134 => _134[existingItemIndex + 1], 'optionalAccess', _135 => _135._parentPos]))
6483
6529
  );
6484
6530
  }
6485
6531
  child._setParentLink(this, newKey);
@@ -6498,7 +6544,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6498
6544
  if (existingItemIndex !== -1) {
6499
6545
  this.#items[existingItemIndex]._setParentLink(
6500
6546
  this,
6501
- makePosition(newKey, _optionalChain([this, 'access', _132 => _132.#items, 'access', _133 => _133[existingItemIndex + 1], 'optionalAccess', _134 => _134._parentPos]))
6547
+ makePosition(newKey, _optionalChain([this, 'access', _136 => _136.#items, 'access', _137 => _137[existingItemIndex + 1], 'optionalAccess', _138 => _138._parentPos]))
6502
6548
  );
6503
6549
  }
6504
6550
  child._setParentLink(this, newKey);
@@ -6526,7 +6572,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6526
6572
  if (existingItemIndex !== -1) {
6527
6573
  actualNewKey = makePosition(
6528
6574
  newKey,
6529
- _optionalChain([this, 'access', _135 => _135.#items, 'access', _136 => _136[existingItemIndex + 1], 'optionalAccess', _137 => _137._parentPos])
6575
+ _optionalChain([this, 'access', _139 => _139.#items, 'access', _140 => _140[existingItemIndex + 1], 'optionalAccess', _141 => _141._parentPos])
6530
6576
  );
6531
6577
  }
6532
6578
  child._setParentLink(this, actualNewKey);
@@ -6584,7 +6630,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6584
6630
  * @param element The element to add to the end of the LiveList.
6585
6631
  */
6586
6632
  push(element) {
6587
- _optionalChain([this, 'access', _138 => _138._pool, 'optionalAccess', _139 => _139.assertStorageIsWritable, 'call', _140 => _140()]);
6633
+ _optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
6588
6634
  return this.insert(element, this.length);
6589
6635
  }
6590
6636
  /**
@@ -6593,7 +6639,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6593
6639
  * @param index The index at which you want to insert the element.
6594
6640
  */
6595
6641
  insert(element, index) {
6596
- _optionalChain([this, 'access', _141 => _141._pool, 'optionalAccess', _142 => _142.assertStorageIsWritable, 'call', _143 => _143()]);
6642
+ _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
6597
6643
  if (index < 0 || index > this.#items.length) {
6598
6644
  throw new Error(
6599
6645
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6623,7 +6669,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6623
6669
  * @param targetIndex The index where the element should be after moving.
6624
6670
  */
6625
6671
  move(index, targetIndex) {
6626
- _optionalChain([this, 'access', _144 => _144._pool, 'optionalAccess', _145 => _145.assertStorageIsWritable, 'call', _146 => _146()]);
6672
+ _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
6627
6673
  if (targetIndex < 0) {
6628
6674
  throw new Error("targetIndex cannot be less than 0");
6629
6675
  }
@@ -6681,7 +6727,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6681
6727
  * @param index The index of the element to delete
6682
6728
  */
6683
6729
  delete(index) {
6684
- _optionalChain([this, 'access', _147 => _147._pool, 'optionalAccess', _148 => _148.assertStorageIsWritable, 'call', _149 => _149()]);
6730
+ _optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.assertStorageIsWritable, 'call', _153 => _153()]);
6685
6731
  if (index < 0 || index >= this.#items.length) {
6686
6732
  throw new Error(
6687
6733
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6714,7 +6760,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6714
6760
  }
6715
6761
  }
6716
6762
  clear() {
6717
- _optionalChain([this, 'access', _150 => _150._pool, 'optionalAccess', _151 => _151.assertStorageIsWritable, 'call', _152 => _152()]);
6763
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
6718
6764
  if (this._pool) {
6719
6765
  const ops = [];
6720
6766
  const reverseOps = [];
@@ -6748,7 +6794,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6748
6794
  }
6749
6795
  }
6750
6796
  set(index, item) {
6751
- _optionalChain([this, 'access', _153 => _153._pool, 'optionalAccess', _154 => _154.assertStorageIsWritable, 'call', _155 => _155()]);
6797
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
6752
6798
  if (index < 0 || index >= this.#items.length) {
6753
6799
  throw new Error(
6754
6800
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6894,7 +6940,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6894
6940
  #shiftItemPosition(index, key) {
6895
6941
  const shiftedPosition = makePosition(
6896
6942
  key,
6897
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _156 => _156.#items, 'access', _157 => _157[index + 1], 'optionalAccess', _158 => _158._parentPos]) : void 0
6943
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _160 => _160.#items, 'access', _161 => _161[index + 1], 'optionalAccess', _162 => _162._parentPos]) : void 0
6898
6944
  );
6899
6945
  this.#items[index]._setParentLink(this, shiftedPosition);
6900
6946
  }
@@ -7019,7 +7065,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7019
7065
  const ops = [];
7020
7066
  const op = {
7021
7067
  id: this._id,
7022
- opId: _optionalChain([pool, 'optionalAccess', _159 => _159.generateOpId, 'call', _160 => _160()]),
7068
+ opId: _optionalChain([pool, 'optionalAccess', _163 => _163.generateOpId, 'call', _164 => _164()]),
7023
7069
  type: 7 /* CREATE_MAP */,
7024
7070
  parentId,
7025
7071
  parentKey
@@ -7159,7 +7205,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7159
7205
  * @param value The value of the element to add. Should be serializable to JSON.
7160
7206
  */
7161
7207
  set(key, value) {
7162
- _optionalChain([this, 'access', _161 => _161._pool, 'optionalAccess', _162 => _162.assertStorageIsWritable, 'call', _163 => _163()]);
7208
+ _optionalChain([this, 'access', _165 => _165._pool, 'optionalAccess', _166 => _166.assertStorageIsWritable, 'call', _167 => _167()]);
7163
7209
  const oldValue = this.#map.get(key);
7164
7210
  if (oldValue) {
7165
7211
  oldValue._detach();
@@ -7205,7 +7251,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7205
7251
  * @returns true if an element existed and has been removed, or false if the element does not exist.
7206
7252
  */
7207
7253
  delete(key) {
7208
- _optionalChain([this, 'access', _164 => _164._pool, 'optionalAccess', _165 => _165.assertStorageIsWritable, 'call', _166 => _166()]);
7254
+ _optionalChain([this, 'access', _168 => _168._pool, 'optionalAccess', _169 => _169.assertStorageIsWritable, 'call', _170 => _170()]);
7209
7255
  const item = this.#map.get(key);
7210
7256
  if (item === void 0) {
7211
7257
  return false;
@@ -7400,7 +7446,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7400
7446
  if (this._id === void 0) {
7401
7447
  throw new Error("Cannot serialize item is not attached");
7402
7448
  }
7403
- const opId = _optionalChain([pool, 'optionalAccess', _167 => _167.generateOpId, 'call', _168 => _168()]);
7449
+ const opId = _optionalChain([pool, 'optionalAccess', _171 => _171.generateOpId, 'call', _172 => _172()]);
7404
7450
  const ops = [];
7405
7451
  const op = {
7406
7452
  type: 4 /* CREATE_OBJECT */,
@@ -7674,7 +7720,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7674
7720
  * @param value The value of the property to add
7675
7721
  */
7676
7722
  set(key, value) {
7677
- _optionalChain([this, 'access', _169 => _169._pool, 'optionalAccess', _170 => _170.assertStorageIsWritable, 'call', _171 => _171()]);
7723
+ _optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
7678
7724
  this.update({ [key]: value });
7679
7725
  }
7680
7726
  /**
@@ -7689,7 +7735,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7689
7735
  * @param key The key of the property to delete
7690
7736
  */
7691
7737
  delete(key) {
7692
- _optionalChain([this, 'access', _172 => _172._pool, 'optionalAccess', _173 => _173.assertStorageIsWritable, 'call', _174 => _174()]);
7738
+ _optionalChain([this, 'access', _176 => _176._pool, 'optionalAccess', _177 => _177.assertStorageIsWritable, 'call', _178 => _178()]);
7693
7739
  const keyAsString = key;
7694
7740
  const oldValue = this.#map.get(keyAsString);
7695
7741
  if (oldValue === void 0) {
@@ -7744,7 +7790,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7744
7790
  * @param patch The object used to overrides properties
7745
7791
  */
7746
7792
  update(patch) {
7747
- _optionalChain([this, 'access', _175 => _175._pool, 'optionalAccess', _176 => _176.assertStorageIsWritable, 'call', _177 => _177()]);
7793
+ _optionalChain([this, 'access', _179 => _179._pool, 'optionalAccess', _180 => _180.assertStorageIsWritable, 'call', _181 => _181()]);
7748
7794
  if (_LiveObject.detectLargeObjects) {
7749
7795
  const data = {};
7750
7796
  for (const [key, value] of this.#map) {
@@ -8142,16 +8188,6 @@ function findNonSerializableValue(value, path = "") {
8142
8188
  return false;
8143
8189
  }
8144
8190
 
8145
- // src/lib/debug.ts
8146
- function captureStackTrace(msg, traceRoot) {
8147
- const errorLike = { name: msg };
8148
- if (typeof Error.captureStackTrace !== "function") {
8149
- return void 0;
8150
- }
8151
- Error.captureStackTrace(errorLike, traceRoot);
8152
- return errorLike.stack;
8153
- }
8154
-
8155
8191
  // src/lib/Deque.ts
8156
8192
  var Deque = class {
8157
8193
  #data;
@@ -8492,15 +8528,15 @@ function installBackgroundTabSpy() {
8492
8528
  const doc = typeof document !== "undefined" ? document : void 0;
8493
8529
  const inBackgroundSince = { current: null };
8494
8530
  function onVisibilityChange() {
8495
- if (_optionalChain([doc, 'optionalAccess', _178 => _178.visibilityState]) === "hidden") {
8531
+ if (_optionalChain([doc, 'optionalAccess', _182 => _182.visibilityState]) === "hidden") {
8496
8532
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
8497
8533
  } else {
8498
8534
  inBackgroundSince.current = null;
8499
8535
  }
8500
8536
  }
8501
- _optionalChain([doc, 'optionalAccess', _179 => _179.addEventListener, 'call', _180 => _180("visibilitychange", onVisibilityChange)]);
8537
+ _optionalChain([doc, 'optionalAccess', _183 => _183.addEventListener, 'call', _184 => _184("visibilitychange", onVisibilityChange)]);
8502
8538
  const unsub = () => {
8503
- _optionalChain([doc, 'optionalAccess', _181 => _181.removeEventListener, 'call', _182 => _182("visibilitychange", onVisibilityChange)]);
8539
+ _optionalChain([doc, 'optionalAccess', _185 => _185.removeEventListener, 'call', _186 => _186("visibilitychange", onVisibilityChange)]);
8504
8540
  };
8505
8541
  return [inBackgroundSince, unsub];
8506
8542
  }
@@ -8562,9 +8598,7 @@ function createRoom(options, config) {
8562
8598
  redoStack: [],
8563
8599
  pausedHistory: null,
8564
8600
  activeBatch: null,
8565
- unacknowledgedOps: /* @__PURE__ */ new Map(),
8566
- // Debug
8567
- opStackTraces: process.env.NODE_ENV !== "production" ? /* @__PURE__ */ new Map() : void 0
8601
+ unacknowledgedOps: /* @__PURE__ */ new Map()
8568
8602
  };
8569
8603
  let lastTokenKey;
8570
8604
  function onStatusDidChange(newStatus) {
@@ -8648,16 +8682,6 @@ function createRoom(options, config) {
8648
8682
  }
8649
8683
  });
8650
8684
  function onDispatch(ops, reverse, storageUpdates) {
8651
- if (process.env.NODE_ENV !== "production") {
8652
- const stackTrace = captureStackTrace("Storage mutation", onDispatch);
8653
- if (stackTrace) {
8654
- for (const op of ops) {
8655
- if (op.opId) {
8656
- nn(context.opStackTraces).set(op.opId, stackTrace);
8657
- }
8658
- }
8659
- }
8660
- }
8661
8685
  if (context.activeBatch) {
8662
8686
  for (const op of ops) {
8663
8687
  context.activeBatch.ops.push(op);
@@ -8680,7 +8704,7 @@ function createRoom(options, config) {
8680
8704
  }
8681
8705
  }
8682
8706
  function isStorageWritable() {
8683
- const scopes = _optionalChain([context, 'access', _183 => _183.dynamicSessionInfoSig, 'access', _184 => _184.get, 'call', _185 => _185(), 'optionalAccess', _186 => _186.scopes]);
8707
+ const scopes = _optionalChain([context, 'access', _187 => _187.dynamicSessionInfoSig, 'access', _188 => _188.get, 'call', _189 => _189(), 'optionalAccess', _190 => _190.scopes]);
8684
8708
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8685
8709
  }
8686
8710
  const eventHub = {
@@ -8811,7 +8835,7 @@ function createRoom(options, config) {
8811
8835
  // be stuck in "synchronizing" forever).
8812
8836
  case "experimental-fallback-to-http": {
8813
8837
  warn("Message is too large for websockets, so sending over HTTP instead");
8814
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _187 => _187.dynamicSessionInfoSig, 'access', _188 => _188.get, 'call', _189 => _189(), 'optionalAccess', _190 => _190.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8838
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _191 => _191.dynamicSessionInfoSig, 'access', _192 => _192.get, 'call', _193 => _193(), 'optionalAccess', _194 => _194.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8815
8839
  void httpClient.sendMessagesOverHTTP({ roomId, nonce, messages }).then((resp) => {
8816
8840
  if (!resp.ok && resp.status === 403) {
8817
8841
  managedSocket.reconnect();
@@ -8866,7 +8890,7 @@ function createRoom(options, config) {
8866
8890
  } else {
8867
8891
  context.root = LiveObject._fromItems(message.items, context.pool);
8868
8892
  }
8869
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _191 => _191.get, 'call', _192 => _192(), 'optionalAccess', _193 => _193.canWrite]), () => ( true));
8893
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _195 => _195.get, 'call', _196 => _196(), 'optionalAccess', _197 => _197.canWrite]), () => ( true));
8870
8894
  const stackSizeBefore = context.undoStack.length;
8871
8895
  for (const key in context.initialStorage) {
8872
8896
  if (context.root.get(key) === void 0) {
@@ -8974,9 +8998,6 @@ function createRoom(options, config) {
8974
8998
  source = 0 /* UNDOREDO_RECONNECT */;
8975
8999
  } else {
8976
9000
  const opId = nn(op.opId);
8977
- if (process.env.NODE_ENV !== "production") {
8978
- nn(context.opStackTraces).delete(opId);
8979
- }
8980
9001
  const deleted = context.unacknowledgedOps.delete(opId);
8981
9002
  source = deleted ? 2 /* ACK */ : 1 /* REMOTE */;
8982
9003
  }
@@ -9069,7 +9090,7 @@ function createRoom(options, config) {
9069
9090
  }
9070
9091
  context.myPresence.patch(patch);
9071
9092
  if (context.activeBatch) {
9072
- if (_optionalChain([options2, 'optionalAccess', _194 => _194.addToHistory])) {
9093
+ if (_optionalChain([options2, 'optionalAccess', _198 => _198.addToHistory])) {
9073
9094
  context.activeBatch.reverseOps.pushLeft({
9074
9095
  type: "presence",
9075
9096
  data: oldValues
@@ -9078,7 +9099,7 @@ function createRoom(options, config) {
9078
9099
  context.activeBatch.updates.presence = true;
9079
9100
  } else {
9080
9101
  flushNowOrSoon();
9081
- if (_optionalChain([options2, 'optionalAccess', _195 => _195.addToHistory])) {
9102
+ if (_optionalChain([options2, 'optionalAccess', _199 => _199.addToHistory])) {
9082
9103
  addToUndoStack([{ type: "presence", data: oldValues }]);
9083
9104
  }
9084
9105
  notify({ presence: true });
@@ -9262,38 +9283,6 @@ function createRoom(options, config) {
9262
9283
  }
9263
9284
  break;
9264
9285
  }
9265
- // Receiving a RejectedOps message in the client means that the server is no
9266
- // longer in sync with the client. Trying to synchronize the client again by
9267
- // rolling back particular Ops may be hard/impossible. It's fine to not try and
9268
- // accept the out-of-sync reality and throw an error. We look at this kind of bug
9269
- // as a developer-owned bug. In production, these errors are not expected to happen.
9270
- case 299 /* REJECT_STORAGE_OP */: {
9271
- errorWithTitle(
9272
- "Storage mutation rejection error",
9273
- message.reason
9274
- );
9275
- if (process.env.NODE_ENV !== "production") {
9276
- const traces = /* @__PURE__ */ new Set();
9277
- for (const opId of message.opIds) {
9278
- const trace = _optionalChain([context, 'access', _196 => _196.opStackTraces, 'optionalAccess', _197 => _197.get, 'call', _198 => _198(opId)]);
9279
- if (trace) {
9280
- traces.add(trace);
9281
- }
9282
- }
9283
- if (traces.size > 0) {
9284
- warnWithTitle(
9285
- "The following function calls caused the rejected storage mutations:",
9286
- `
9287
-
9288
- ${Array.from(traces).join("\n\n")}`
9289
- );
9290
- }
9291
- throw new Error(
9292
- `Storage mutations rejected by server: ${message.reason}`
9293
- );
9294
- }
9295
- break;
9296
- }
9297
9286
  case 400 /* THREAD_CREATED */:
9298
9287
  case 407 /* THREAD_DELETED */:
9299
9288
  case 401 /* THREAD_METADATA_UPDATED */:
@@ -9306,6 +9295,8 @@ ${Array.from(traces).join("\n\n")}`
9306
9295
  eventHub.comments.notify(message);
9307
9296
  break;
9308
9297
  }
9298
+ default:
9299
+ break;
9309
9300
  }
9310
9301
  }
9311
9302
  notify(updates);
@@ -9409,7 +9400,7 @@ ${Array.from(traces).join("\n\n")}`
9409
9400
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
9410
9401
  createOrUpdateRootFromMessage(message);
9411
9402
  applyAndSendOps(unacknowledgedOps);
9412
- _optionalChain([_resolveStoragePromise, 'optionalCall', _199 => _199()]);
9403
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _200 => _200()]);
9413
9404
  notifyStorageStatus();
9414
9405
  eventHub.storageDidLoad.notify();
9415
9406
  }
@@ -9630,8 +9621,8 @@ ${Array.from(traces).join("\n\n")}`
9630
9621
  async function getThreads(options2) {
9631
9622
  return httpClient.getThreads({
9632
9623
  roomId,
9633
- query: _optionalChain([options2, 'optionalAccess', _200 => _200.query]),
9634
- cursor: _optionalChain([options2, 'optionalAccess', _201 => _201.cursor])
9624
+ query: _optionalChain([options2, 'optionalAccess', _201 => _201.query]),
9625
+ cursor: _optionalChain([options2, 'optionalAccess', _202 => _202.cursor])
9635
9626
  });
9636
9627
  }
9637
9628
  async function getThread(threadId) {
@@ -9738,7 +9729,7 @@ ${Array.from(traces).join("\n\n")}`
9738
9729
  function getSubscriptionSettings(options2) {
9739
9730
  return httpClient.getSubscriptionSettings({
9740
9731
  roomId,
9741
- signal: _optionalChain([options2, 'optionalAccess', _202 => _202.signal])
9732
+ signal: _optionalChain([options2, 'optionalAccess', _203 => _203.signal])
9742
9733
  });
9743
9734
  }
9744
9735
  function updateSubscriptionSettings(settings) {
@@ -9760,7 +9751,7 @@ ${Array.from(traces).join("\n\n")}`
9760
9751
  {
9761
9752
  [kInternal]: {
9762
9753
  get presenceBuffer() {
9763
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _203 => _203.buffer, 'access', _204 => _204.presenceUpdates, 'optionalAccess', _205 => _205.data]), () => ( null)));
9754
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _204 => _204.buffer, 'access', _205 => _205.presenceUpdates, 'optionalAccess', _206 => _206.data]), () => ( null)));
9764
9755
  },
9765
9756
  // prettier-ignore
9766
9757
  get undoStack() {
@@ -9775,9 +9766,9 @@ ${Array.from(traces).join("\n\n")}`
9775
9766
  return context.yjsProvider;
9776
9767
  },
9777
9768
  setYjsProvider(newProvider) {
9778
- _optionalChain([context, 'access', _206 => _206.yjsProvider, 'optionalAccess', _207 => _207.off, 'call', _208 => _208("status", yjsStatusDidChange)]);
9769
+ _optionalChain([context, 'access', _207 => _207.yjsProvider, 'optionalAccess', _208 => _208.off, 'call', _209 => _209("status", yjsStatusDidChange)]);
9779
9770
  context.yjsProvider = newProvider;
9780
- _optionalChain([newProvider, 'optionalAccess', _209 => _209.on, 'call', _210 => _210("status", yjsStatusDidChange)]);
9771
+ _optionalChain([newProvider, 'optionalAccess', _210 => _210.on, 'call', _211 => _211("status", yjsStatusDidChange)]);
9781
9772
  context.yjsProviderDidChange.notify();
9782
9773
  },
9783
9774
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9823,7 +9814,7 @@ ${Array.from(traces).join("\n\n")}`
9823
9814
  source.dispose();
9824
9815
  }
9825
9816
  eventHub.roomWillDestroy.notify();
9826
- _optionalChain([context, 'access', _211 => _211.yjsProvider, 'optionalAccess', _212 => _212.off, 'call', _213 => _213("status", yjsStatusDidChange)]);
9817
+ _optionalChain([context, 'access', _212 => _212.yjsProvider, 'optionalAccess', _213 => _213.off, 'call', _214 => _214("status", yjsStatusDidChange)]);
9827
9818
  syncSourceForStorage.destroy();
9828
9819
  syncSourceForYjs.destroy();
9829
9820
  uninstallBgTabSpy();
@@ -9973,7 +9964,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9973
9964
  }
9974
9965
  if (isLiveNode(first)) {
9975
9966
  const node = first;
9976
- if (_optionalChain([options, 'optionalAccess', _214 => _214.isDeep])) {
9967
+ if (_optionalChain([options, 'optionalAccess', _215 => _215.isDeep])) {
9977
9968
  const storageCallback = second;
9978
9969
  return subscribeToLiveStructureDeeply(node, storageCallback);
9979
9970
  } else {
@@ -10053,8 +10044,8 @@ function createClient(options) {
10053
10044
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
10054
10045
  currentUserId.set(() => userId);
10055
10046
  });
10056
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _215 => _215.polyfills, 'optionalAccess', _216 => _216.fetch]) || /* istanbul ignore next */
10057
- _optionalChain([globalThis, 'access', _217 => _217.fetch, 'optionalAccess', _218 => _218.bind, 'call', _219 => _219(globalThis)]);
10047
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _216 => _216.polyfills, 'optionalAccess', _217 => _217.fetch]) || /* istanbul ignore next */
10048
+ _optionalChain([globalThis, 'access', _218 => _218.fetch, 'optionalAccess', _219 => _219.bind, 'call', _220 => _220(globalThis)]);
10058
10049
  const httpClient = createApiClient({
10059
10050
  baseUrl,
10060
10051
  fetchPolyfill,
@@ -10072,7 +10063,7 @@ function createClient(options) {
10072
10063
  delegates: {
10073
10064
  createSocket: makeCreateSocketDelegateForAi(
10074
10065
  baseUrl,
10075
- _optionalChain([clientOptions, 'access', _220 => _220.polyfills, 'optionalAccess', _221 => _221.WebSocket])
10066
+ _optionalChain([clientOptions, 'access', _221 => _221.polyfills, 'optionalAccess', _222 => _222.WebSocket])
10076
10067
  ),
10077
10068
  authenticate: async () => {
10078
10069
  const resp = await authManager.getAuthValue({
@@ -10134,7 +10125,7 @@ function createClient(options) {
10134
10125
  createSocket: makeCreateSocketDelegateForRoom(
10135
10126
  roomId,
10136
10127
  baseUrl,
10137
- _optionalChain([clientOptions, 'access', _222 => _222.polyfills, 'optionalAccess', _223 => _223.WebSocket])
10128
+ _optionalChain([clientOptions, 'access', _223 => _223.polyfills, 'optionalAccess', _224 => _224.WebSocket])
10138
10129
  ),
10139
10130
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
10140
10131
  })),
@@ -10157,7 +10148,7 @@ function createClient(options) {
10157
10148
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
10158
10149
  if (shouldConnect) {
10159
10150
  if (typeof atob === "undefined") {
10160
- if (_optionalChain([clientOptions, 'access', _224 => _224.polyfills, 'optionalAccess', _225 => _225.atob]) === void 0) {
10151
+ if (_optionalChain([clientOptions, 'access', _225 => _225.polyfills, 'optionalAccess', _226 => _226.atob]) === void 0) {
10161
10152
  throw new Error(
10162
10153
  "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"
10163
10154
  );
@@ -10169,7 +10160,7 @@ function createClient(options) {
10169
10160
  return leaseRoom(newRoomDetails);
10170
10161
  }
10171
10162
  function getRoom(roomId) {
10172
- const room = _optionalChain([roomsById, 'access', _226 => _226.get, 'call', _227 => _227(roomId), 'optionalAccess', _228 => _228.room]);
10163
+ const room = _optionalChain([roomsById, 'access', _227 => _227.get, 'call', _228 => _228(roomId), 'optionalAccess', _229 => _229.room]);
10173
10164
  return room ? room : null;
10174
10165
  }
10175
10166
  function logout() {
@@ -10185,7 +10176,7 @@ function createClient(options) {
10185
10176
  const batchedResolveUsers = new Batch(
10186
10177
  async (batchedUserIds) => {
10187
10178
  const userIds = batchedUserIds.flat();
10188
- const users = await _optionalChain([resolveUsers, 'optionalCall', _229 => _229({ userIds })]);
10179
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _230 => _230({ userIds })]);
10189
10180
  warnOnceIf(
10190
10181
  !resolveUsers,
10191
10182
  "Set the resolveUsers option in createClient to specify user info."
@@ -10202,7 +10193,7 @@ function createClient(options) {
10202
10193
  const batchedResolveRoomsInfo = new Batch(
10203
10194
  async (batchedRoomIds) => {
10204
10195
  const roomIds = batchedRoomIds.flat();
10205
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _230 => _230({ roomIds })]);
10196
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _231 => _231({ roomIds })]);
10206
10197
  warnOnceIf(
10207
10198
  !resolveRoomsInfo,
10208
10199
  "Set the resolveRoomsInfo option in createClient to specify room info."
@@ -10219,7 +10210,7 @@ function createClient(options) {
10219
10210
  const batchedResolveGroupsInfo = new Batch(
10220
10211
  async (batchedGroupIds) => {
10221
10212
  const groupIds = batchedGroupIds.flat();
10222
- const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _231 => _231({ groupIds })]);
10213
+ const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _232 => _232({ groupIds })]);
10223
10214
  warnOnceIf(
10224
10215
  !resolveGroupsInfo,
10225
10216
  "Set the resolveGroupsInfo option in createClient to specify group info."
@@ -10275,7 +10266,7 @@ function createClient(options) {
10275
10266
  }
10276
10267
  };
10277
10268
  const win = typeof window !== "undefined" ? window : void 0;
10278
- _optionalChain([win, 'optionalAccess', _232 => _232.addEventListener, 'call', _233 => _233("beforeunload", maybePreventClose)]);
10269
+ _optionalChain([win, 'optionalAccess', _233 => _233.addEventListener, 'call', _234 => _234("beforeunload", maybePreventClose)]);
10279
10270
  }
10280
10271
  async function getNotificationSettings(options2) {
10281
10272
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -10402,7 +10393,7 @@ var commentBodyElementsTypes = {
10402
10393
  mention: "inline"
10403
10394
  };
10404
10395
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10405
- if (!body || !_optionalChain([body, 'optionalAccess', _234 => _234.content])) {
10396
+ if (!body || !_optionalChain([body, 'optionalAccess', _235 => _235.content])) {
10406
10397
  return;
10407
10398
  }
10408
10399
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -10412,13 +10403,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10412
10403
  for (const block of body.content) {
10413
10404
  if (type === "all" || type === "block") {
10414
10405
  if (guard(block)) {
10415
- _optionalChain([visitor, 'optionalCall', _235 => _235(block)]);
10406
+ _optionalChain([visitor, 'optionalCall', _236 => _236(block)]);
10416
10407
  }
10417
10408
  }
10418
10409
  if (type === "all" || type === "inline") {
10419
10410
  for (const inline of block.children) {
10420
10411
  if (guard(inline)) {
10421
- _optionalChain([visitor, 'optionalCall', _236 => _236(inline)]);
10412
+ _optionalChain([visitor, 'optionalCall', _237 => _237(inline)]);
10422
10413
  }
10423
10414
  }
10424
10415
  }
@@ -10588,7 +10579,7 @@ var stringifyCommentBodyPlainElements = {
10588
10579
  text: ({ element }) => element.text,
10589
10580
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
10590
10581
  mention: ({ element, user, group }) => {
10591
- return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _237 => _237.name]), () => ( _optionalChain([group, 'optionalAccess', _238 => _238.name]))), () => ( element.id))}`;
10582
+ return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _238 => _238.name]), () => ( _optionalChain([group, 'optionalAccess', _239 => _239.name]))), () => ( element.id))}`;
10592
10583
  }
10593
10584
  };
10594
10585
  var stringifyCommentBodyHtmlElements = {
@@ -10618,7 +10609,7 @@ var stringifyCommentBodyHtmlElements = {
10618
10609
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10619
10610
  },
10620
10611
  mention: ({ element, user, group }) => {
10621
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _239 => _239.name]) ? html`${_optionalChain([user, 'optionalAccess', _240 => _240.name])}` : _optionalChain([group, 'optionalAccess', _241 => _241.name]) ? html`${_optionalChain([group, 'optionalAccess', _242 => _242.name])}` : element.id}</span>`;
10612
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _240 => _240.name]) ? html`${_optionalChain([user, 'optionalAccess', _241 => _241.name])}` : _optionalChain([group, 'optionalAccess', _242 => _242.name]) ? html`${_optionalChain([group, 'optionalAccess', _243 => _243.name])}` : element.id}</span>`;
10622
10613
  }
10623
10614
  };
10624
10615
  var stringifyCommentBodyMarkdownElements = {
@@ -10648,20 +10639,20 @@ var stringifyCommentBodyMarkdownElements = {
10648
10639
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10649
10640
  },
10650
10641
  mention: ({ element, user, group }) => {
10651
- return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _243 => _243.name]), () => ( _optionalChain([group, 'optionalAccess', _244 => _244.name]))), () => ( element.id))}`;
10642
+ return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _244 => _244.name]), () => ( _optionalChain([group, 'optionalAccess', _245 => _245.name]))), () => ( element.id))}`;
10652
10643
  }
10653
10644
  };
10654
10645
  async function stringifyCommentBody(body, options) {
10655
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _245 => _245.format]), () => ( "plain"));
10656
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _246 => _246.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10646
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _246 => _246.format]), () => ( "plain"));
10647
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _247 => _247.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10657
10648
  const elements = {
10658
10649
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10659
- ..._optionalChain([options, 'optionalAccess', _247 => _247.elements])
10650
+ ..._optionalChain([options, 'optionalAccess', _248 => _248.elements])
10660
10651
  };
10661
10652
  const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
10662
10653
  body,
10663
- _optionalChain([options, 'optionalAccess', _248 => _248.resolveUsers]),
10664
- _optionalChain([options, 'optionalAccess', _249 => _249.resolveGroupsInfo])
10654
+ _optionalChain([options, 'optionalAccess', _249 => _249.resolveUsers]),
10655
+ _optionalChain([options, 'optionalAccess', _250 => _250.resolveGroupsInfo])
10665
10656
  );
10666
10657
  const blocks = body.content.flatMap((block, blockIndex) => {
10667
10658
  switch (block.type) {
@@ -10948,12 +10939,12 @@ function legacy_patchImmutableNode(state, path, update) {
10948
10939
  }
10949
10940
  const newState = Object.assign({}, state);
10950
10941
  for (const key in update.updates) {
10951
- if (_optionalChain([update, 'access', _250 => _250.updates, 'access', _251 => _251[key], 'optionalAccess', _252 => _252.type]) === "update") {
10942
+ if (_optionalChain([update, 'access', _251 => _251.updates, 'access', _252 => _252[key], 'optionalAccess', _253 => _253.type]) === "update") {
10952
10943
  const val = update.node.get(key);
10953
10944
  if (val !== void 0) {
10954
10945
  newState[key] = lsonToJson(val);
10955
10946
  }
10956
- } else if (_optionalChain([update, 'access', _253 => _253.updates, 'access', _254 => _254[key], 'optionalAccess', _255 => _255.type]) === "delete") {
10947
+ } else if (_optionalChain([update, 'access', _254 => _254.updates, 'access', _255 => _255[key], 'optionalAccess', _256 => _256.type]) === "delete") {
10957
10948
  delete newState[key];
10958
10949
  }
10959
10950
  }
@@ -11014,12 +11005,12 @@ function legacy_patchImmutableNode(state, path, update) {
11014
11005
  }
11015
11006
  const newState = Object.assign({}, state);
11016
11007
  for (const key in update.updates) {
11017
- if (_optionalChain([update, 'access', _256 => _256.updates, 'access', _257 => _257[key], 'optionalAccess', _258 => _258.type]) === "update") {
11008
+ if (_optionalChain([update, 'access', _257 => _257.updates, 'access', _258 => _258[key], 'optionalAccess', _259 => _259.type]) === "update") {
11018
11009
  const value = update.node.get(key);
11019
11010
  if (value !== void 0) {
11020
11011
  newState[key] = lsonToJson(value);
11021
11012
  }
11022
- } else if (_optionalChain([update, 'access', _259 => _259.updates, 'access', _260 => _260[key], 'optionalAccess', _261 => _261.type]) === "delete") {
11013
+ } else if (_optionalChain([update, 'access', _260 => _260.updates, 'access', _261 => _261[key], 'optionalAccess', _262 => _262.type]) === "delete") {
11023
11014
  delete newState[key];
11024
11015
  }
11025
11016
  }
@@ -11099,9 +11090,9 @@ function makePoller(callback, intervalMs, options) {
11099
11090
  const startTime = performance.now();
11100
11091
  const doc = typeof document !== "undefined" ? document : void 0;
11101
11092
  const win = typeof window !== "undefined" ? window : void 0;
11102
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _262 => _262.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11093
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _263 => _263.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11103
11094
  const context = {
11104
- inForeground: _optionalChain([doc, 'optionalAccess', _263 => _263.visibilityState]) !== "hidden",
11095
+ inForeground: _optionalChain([doc, 'optionalAccess', _264 => _264.visibilityState]) !== "hidden",
11105
11096
  lastSuccessfulPollAt: startTime,
11106
11097
  count: 0,
11107
11098
  backoff: 0
@@ -11182,11 +11173,11 @@ function makePoller(callback, intervalMs, options) {
11182
11173
  pollNowIfStale();
11183
11174
  }
11184
11175
  function onVisibilityChange() {
11185
- setInForeground(_optionalChain([doc, 'optionalAccess', _264 => _264.visibilityState]) !== "hidden");
11176
+ setInForeground(_optionalChain([doc, 'optionalAccess', _265 => _265.visibilityState]) !== "hidden");
11186
11177
  }
11187
- _optionalChain([doc, 'optionalAccess', _265 => _265.addEventListener, 'call', _266 => _266("visibilitychange", onVisibilityChange)]);
11188
- _optionalChain([win, 'optionalAccess', _267 => _267.addEventListener, 'call', _268 => _268("online", onVisibilityChange)]);
11189
- _optionalChain([win, 'optionalAccess', _269 => _269.addEventListener, 'call', _270 => _270("focus", pollNowIfStale)]);
11178
+ _optionalChain([doc, 'optionalAccess', _266 => _266.addEventListener, 'call', _267 => _267("visibilitychange", onVisibilityChange)]);
11179
+ _optionalChain([win, 'optionalAccess', _268 => _268.addEventListener, 'call', _269 => _269("online", onVisibilityChange)]);
11180
+ _optionalChain([win, 'optionalAccess', _270 => _270.addEventListener, 'call', _271 => _271("focus", pollNowIfStale)]);
11190
11181
  fsm.start();
11191
11182
  return {
11192
11183
  inc,