@liveblocks/core 3.5.1 → 3.5.3

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.5.1";
9
+ var PKG_VERSION = "3.5.3";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -3817,163 +3817,266 @@ function parseAuthToken(rawTokenString) {
3817
3817
  };
3818
3818
  }
3819
3819
 
3820
- // src/lib/parsePartialJsonObject.ts
3821
- function parsePartialJsonObject(partial) {
3822
- partial = partial.trimStart();
3823
- if (partial.charAt(0) !== "{") {
3824
- return {};
3825
- }
3826
- if (partial.trimEnd().endsWith("}")) {
3827
- const quickCheck = tryParseJson(partial);
3828
- if (quickCheck) {
3829
- return quickCheck;
3830
- }
3831
- }
3832
- let result = partial;
3833
- let quoteCount = 0;
3834
- let escaped = false;
3835
- for (let i = 0; i < result.length; i++) {
3836
- const char = result[i];
3837
- if (escaped) {
3838
- escaped = false;
3839
- } else if (char === "\\") {
3840
- escaped = true;
3841
- } else if (char === '"') {
3842
- quoteCount++;
3843
- }
3844
- }
3845
- if (quoteCount % 2 === 1) {
3846
- result += '"';
3847
- }
3848
- result = result.trimEnd();
3849
- if (result.endsWith(",")) {
3850
- result = result.slice(0, -1);
3851
- }
3852
- if (result.endsWith(".")) {
3853
- result = result.slice(0, -1);
3854
- }
3855
- const stack = [];
3856
- let inString = false;
3857
- escaped = false;
3858
- for (let i = 0; i < result.length; i++) {
3859
- const char = result[i];
3860
- if (inString) {
3861
- if (escaped) {
3862
- escaped = false;
3863
- } else if (char === "\\") {
3864
- escaped = true;
3865
- } else if (char === '"') {
3866
- inString = false;
3867
- }
3868
- } else {
3869
- if (char === '"') {
3870
- inString = true;
3871
- } else if (char === "{") {
3872
- stack.push("}");
3873
- } else if (char === "[") {
3874
- stack.push("]");
3875
- } else if (char === "}" && stack.length > 0 && stack[stack.length - 1] === "}") {
3876
- stack.pop();
3877
- } else if (char === "]" && stack.length > 0 && stack[stack.length - 1] === "]") {
3878
- stack.pop();
3820
+ // src/lib/IncrementalJsonParser.ts
3821
+ var EMPTY_OBJECT = Object.freeze({});
3822
+ var NULL_KEYWORD_CHARS = Array.from(new Set("null"));
3823
+ var TRUE_KEYWORD_CHARS = Array.from(new Set("true"));
3824
+ var FALSE_KEYWORD_CHARS = Array.from(new Set("false"));
3825
+ var ALL_KEYWORD_CHARS = Array.from(new Set("nulltruefalse"));
3826
+ function stripChar(str, chars) {
3827
+ const lastChar = str[str.length - 1];
3828
+ if (chars.includes(lastChar)) {
3829
+ return str.slice(0, -1);
3830
+ }
3831
+ return str;
3832
+ }
3833
+ var IncrementalJsonParser = class {
3834
+ // Input
3835
+ #sourceText = "";
3836
+ // Output
3837
+ #cachedJson;
3838
+ /** How much we've already parsed */
3839
+ #scanIndex = 0;
3840
+ /** Whether the last char processed was a backslash */
3841
+ #escaped = false;
3842
+ /**
3843
+ * Start position of the last unterminated string, -1 if we're not inside
3844
+ * a string currently.
3845
+ *
3846
+ * Example: '{"a": "foo'
3847
+ * ^
3848
+ */
3849
+ #lastUnterminatedString = -1;
3850
+ /**
3851
+ * Start position of the last fully terminated string we've seen.
3852
+ *
3853
+ * Example: '{"a": "foo'
3854
+ * ^
3855
+ */
3856
+ #lastTerminatedString = -1;
3857
+ /** The bracket stack of expected closing chars. For input '{"a": ["foo', the stack would be ['}', ']']. */
3858
+ #stack = [];
3859
+ constructor(text = "") {
3860
+ this.append(text);
3861
+ }
3862
+ get source() {
3863
+ return this.#sourceText;
3864
+ }
3865
+ get json() {
3866
+ if (this.#cachedJson === void 0) {
3867
+ this.#cachedJson = this.#parse();
3868
+ }
3869
+ return this.#cachedJson;
3870
+ }
3871
+ /** Whether we're currently inside an unterminated string, e.g. '{"hello' */
3872
+ get #inString() {
3873
+ return this.#lastUnterminatedString >= 0;
3874
+ }
3875
+ append(delta) {
3876
+ if (delta) {
3877
+ if (this.#sourceText === "") {
3878
+ delta = delta.trimStart();
3879
3879
  }
3880
+ this.#sourceText += delta;
3881
+ this.#cachedJson = void 0;
3880
3882
  }
3881
3883
  }
3882
- const suffix = stack.reverse().join("");
3883
- {
3884
- const attempt = tryParseJson(result + suffix);
3885
- if (attempt) {
3886
- return attempt;
3887
- }
3888
- }
3889
- if (result.endsWith(":")) {
3890
- result = result.slice(0, -1);
3891
- }
3892
- if (result.endsWith('"')) {
3893
- let pos = result.length - 2;
3894
- escaped = false;
3895
- while (pos >= 0) {
3896
- if (escaped) {
3897
- escaped = false;
3898
- } else if (result[pos] === "\\") {
3899
- escaped = true;
3900
- } else if (result[pos] === '"') {
3901
- result = result.slice(0, pos);
3902
- break;
3884
+ #autocompleteTail(output) {
3885
+ if (this.#inString) {
3886
+ return "";
3887
+ }
3888
+ const lastChar = output.charAt(output.length - 1);
3889
+ if (lastChar === "") return "";
3890
+ if (lastChar === "-") {
3891
+ return "0";
3892
+ }
3893
+ if (!ALL_KEYWORD_CHARS.includes(lastChar)) return "";
3894
+ if (NULL_KEYWORD_CHARS.includes(lastChar)) {
3895
+ if (output.endsWith("nul")) return "l";
3896
+ if (output.endsWith("nu")) return "ll";
3897
+ if (output.endsWith("n")) return "ull";
3898
+ }
3899
+ if (TRUE_KEYWORD_CHARS.includes(lastChar)) {
3900
+ if (output.endsWith("tru")) return "e";
3901
+ if (output.endsWith("tr")) return "ue";
3902
+ if (output.endsWith("t")) return "rue";
3903
+ }
3904
+ if (FALSE_KEYWORD_CHARS.includes(lastChar)) {
3905
+ if (output.endsWith("fals")) return "e";
3906
+ if (output.endsWith("fal")) return "se";
3907
+ if (output.endsWith("fa")) return "lse";
3908
+ if (output.endsWith("f")) return "alse";
3909
+ }
3910
+ return "";
3911
+ }
3912
+ /**
3913
+ * Updates the internal parsing state by processing any new content
3914
+ * that has been appended since the last parse. This updates the state with
3915
+ * facts only. Any interpretation is left to the #parse() method.
3916
+ */
3917
+ #catchup() {
3918
+ const newContent = this.#sourceText.slice(this.#scanIndex);
3919
+ for (let i = 0; i < newContent.length; i++) {
3920
+ const ch = newContent[i];
3921
+ const absolutePos = this.#scanIndex + i;
3922
+ if (this.#inString) {
3923
+ if (this.#escaped) {
3924
+ this.#escaped = false;
3925
+ } else if (ch === "\\") {
3926
+ this.#escaped = true;
3927
+ } else if (ch === '"') {
3928
+ this.#lastTerminatedString = this.#lastUnterminatedString;
3929
+ this.#lastUnterminatedString = -1;
3930
+ }
3931
+ } else {
3932
+ if (ch === '"') {
3933
+ this.#lastUnterminatedString = absolutePos;
3934
+ } else if (ch === "{") {
3935
+ this.#stack.push("}");
3936
+ } else if (ch === "[") {
3937
+ this.#stack.push("]");
3938
+ } else if (ch === "}" && this.#stack.length > 0 && this.#stack[this.#stack.length - 1] === "}") {
3939
+ this.#stack.pop();
3940
+ } else if (ch === "]" && this.#stack.length > 0 && this.#stack[this.#stack.length - 1] === "]") {
3941
+ this.#stack.pop();
3942
+ }
3903
3943
  }
3904
- pos--;
3905
3944
  }
3945
+ this.#scanIndex = this.#sourceText.length;
3906
3946
  }
3907
- if (result.endsWith(",")) {
3908
- result = result.slice(0, -1);
3947
+ #parse() {
3948
+ this.#catchup();
3949
+ let result = this.#sourceText;
3950
+ if (result.charAt(0) !== "{") {
3951
+ return EMPTY_OBJECT;
3952
+ }
3953
+ if (result.endsWith("}")) {
3954
+ const quickCheck = tryParseJson(result);
3955
+ if (quickCheck) {
3956
+ return quickCheck;
3957
+ }
3958
+ }
3959
+ if (this.#inString) {
3960
+ if (this.#escaped) {
3961
+ result = result.slice(0, -1);
3962
+ }
3963
+ result += '"';
3964
+ }
3965
+ result = result.trimEnd();
3966
+ result = stripChar(result, ",.");
3967
+ result = result + this.#autocompleteTail(result);
3968
+ const suffix = this.#stack.reduceRight((acc, ch) => acc + ch, "");
3969
+ {
3970
+ const attempt = tryParseJson(result + suffix);
3971
+ if (attempt) {
3972
+ return attempt;
3973
+ }
3974
+ }
3975
+ if (this.#inString) {
3976
+ result = result.slice(0, this.#lastUnterminatedString);
3977
+ } else {
3978
+ result = stripChar(result, ":");
3979
+ if (result.endsWith('"')) {
3980
+ result = result.slice(0, this.#lastTerminatedString);
3981
+ }
3982
+ }
3983
+ result = stripChar(result, ",");
3984
+ result += suffix;
3985
+ return _nullishCoalesce(tryParseJson(result), () => ( EMPTY_OBJECT));
3909
3986
  }
3910
- result += suffix;
3911
- return _nullishCoalesce(tryParseJson(result), () => ( {}));
3912
- }
3987
+ };
3913
3988
 
3914
3989
  // src/types/ai.ts
3990
+ function replaceOrAppend(content, newItem, keyFn, now2) {
3991
+ const existingIndex = findLastIndex(
3992
+ content,
3993
+ (item) => item.type === newItem.type && keyFn(item) === keyFn(newItem)
3994
+ );
3995
+ if (existingIndex > -1) {
3996
+ content[existingIndex] = newItem;
3997
+ } else {
3998
+ closePart(content[content.length - 1], now2);
3999
+ content.push(newItem);
4000
+ }
4001
+ }
4002
+ function closePart(prevPart, endedAt) {
4003
+ if (_optionalChain([prevPart, 'optionalAccess', _55 => _55.type]) === "reasoning") {
4004
+ prevPart.endedAt ??= endedAt;
4005
+ }
4006
+ }
3915
4007
  function patchContentWithDelta(content, delta) {
4008
+ if (delta === null)
4009
+ return;
4010
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
3916
4011
  const lastPart = content[content.length - 1];
3917
4012
  switch (delta.type) {
3918
4013
  case "text-delta":
3919
- if (_optionalChain([lastPart, 'optionalAccess', _55 => _55.type]) === "text") {
4014
+ if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "text") {
3920
4015
  lastPart.text += delta.textDelta;
3921
4016
  } else {
4017
+ closePart(lastPart, now2);
3922
4018
  content.push({ type: "text", text: delta.textDelta });
3923
4019
  }
3924
4020
  break;
3925
4021
  case "reasoning-delta":
3926
- if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "reasoning") {
4022
+ if (_optionalChain([lastPart, 'optionalAccess', _57 => _57.type]) === "reasoning") {
3927
4023
  lastPart.text += delta.textDelta;
3928
4024
  } else {
4025
+ closePart(lastPart, now2);
3929
4026
  content.push({
3930
4027
  type: "reasoning",
3931
- text: _nullishCoalesce(delta.textDelta, () => ( ""))
4028
+ text: _nullishCoalesce(delta.textDelta, () => ( "")),
4029
+ startedAt: now2
3932
4030
  });
3933
4031
  }
3934
4032
  break;
3935
4033
  case "tool-stream": {
3936
- let _cacheKey = "";
3937
- let _cachedArgs = {};
3938
- const toolInvocation = {
3939
- type: "tool-invocation",
3940
- stage: "receiving",
3941
- invocationId: delta.invocationId,
3942
- name: delta.name,
3943
- partialArgsText: "",
3944
- get partialArgs() {
3945
- if (this.partialArgsText !== _cacheKey) {
3946
- _cachedArgs = parsePartialJsonObject(this.partialArgsText);
3947
- _cacheKey = this.partialArgsText;
3948
- }
3949
- return _cachedArgs;
3950
- }
3951
- };
4034
+ const toolInvocation = createReceivingToolInvocation(
4035
+ delta.invocationId,
4036
+ delta.name
4037
+ );
3952
4038
  content.push(toolInvocation);
3953
4039
  break;
3954
4040
  }
3955
4041
  case "tool-delta": {
3956
- if (_optionalChain([lastPart, 'optionalAccess', _57 => _57.type]) === "tool-invocation" && lastPart.stage === "receiving") {
3957
- lastPart.partialArgsText += delta.delta;
4042
+ if (_optionalChain([lastPart, 'optionalAccess', _58 => _58.type]) === "tool-invocation" && lastPart.stage === "receiving") {
4043
+ _optionalChain([lastPart, 'access', _59 => _59.__appendDelta, 'optionalCall', _60 => _60(delta.delta)]);
3958
4044
  }
3959
4045
  break;
3960
4046
  }
3961
- case "tool-invocation": {
3962
- const existingIndex = findLastIndex(
3963
- content,
3964
- (part) => part.type === "tool-invocation" && part.invocationId === delta.invocationId
3965
- );
3966
- if (existingIndex > -1) {
3967
- content[existingIndex] = delta;
3968
- } else {
3969
- content.push(delta);
3970
- }
4047
+ case "tool-invocation":
4048
+ replaceOrAppend(content, delta, (x) => x.invocationId, now2);
4049
+ break;
4050
+ case "retrieval":
4051
+ replaceOrAppend(content, delta, (x) => x.id, now2);
3971
4052
  break;
3972
- }
3973
4053
  default:
3974
4054
  return assertNever(delta, "Unhandled case");
3975
4055
  }
3976
4056
  }
4057
+ function createReceivingToolInvocation(invocationId, name, partialArgsText = "") {
4058
+ const parser = new IncrementalJsonParser(partialArgsText);
4059
+ return {
4060
+ type: "tool-invocation",
4061
+ stage: "receiving",
4062
+ invocationId,
4063
+ name,
4064
+ // --- Alternative implementation for FRONTEND only ------------------------
4065
+ get partialArgsText() {
4066
+ return parser.source;
4067
+ },
4068
+ // prettier-ignore
4069
+ get partialArgs() {
4070
+ return parser.json;
4071
+ },
4072
+ // prettier-ignore
4073
+ __appendDelta(delta) {
4074
+ parser.append(delta);
4075
+ }
4076
+ // prettier-ignore
4077
+ // ------------------------------------------------------------------------
4078
+ };
4079
+ }
3977
4080
 
3978
4081
  // src/ai.ts
3979
4082
  var DEFAULT_REQUEST_TIMEOUT = 4e3;
@@ -4056,7 +4159,7 @@ function createStore_forTools() {
4056
4159
  return DerivedSignal.from(() => {
4057
4160
  return (
4058
4161
  // A tool that's registered and scoped to a specific chat ID...
4059
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _58 => _58.get, 'call', _59 => _59()]), () => ( // ...or a globally registered tool
4162
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _61 => _61.get, 'call', _62 => _62()]), () => ( // ...or a globally registered tool
4060
4163
  toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
4061
4164
  );
4062
4165
  });
@@ -4086,8 +4189,8 @@ function createStore_forTools() {
4086
4189
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
4087
4190
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
4088
4191
  return Array.from([
4089
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _60 => _60.entries, 'call', _61 => _61()]), () => ( [])),
4090
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _62 => _62.entries, 'call', _63 => _63()]), () => ( []))
4192
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _63 => _63.entries, 'call', _64 => _64()]), () => ( [])),
4193
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _65 => _65.entries, 'call', _66 => _66()]), () => ( []))
4091
4194
  ]).flatMap(([name, tool\u03A3]) => {
4092
4195
  const tool = tool\u03A3.get();
4093
4196
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -4190,7 +4293,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4190
4293
  } else {
4191
4294
  continue;
4192
4295
  }
4193
- const executeFn = _optionalChain([toolsStore, 'access', _64 => _64.getTool\u03A3, 'call', _65 => _65(toolInvocation.name, message.chatId), 'access', _66 => _66.get, 'call', _67 => _67(), 'optionalAccess', _68 => _68.execute]);
4296
+ const executeFn = _optionalChain([toolsStore, 'access', _67 => _67.getTool\u03A3, 'call', _68 => _68(toolInvocation.name, message.chatId), 'access', _69 => _69.get, 'call', _70 => _70(), 'optionalAccess', _71 => _71.execute]);
4194
4297
  if (executeFn) {
4195
4298
  (async () => {
4196
4299
  const result = await executeFn(toolInvocation.args, {
@@ -4289,8 +4392,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4289
4392
  const spine = [];
4290
4393
  let lastVisitedMessage = null;
4291
4394
  for (const message2 of pool.walkUp(leaf.id)) {
4292
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _69 => _69(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _70 => _70.id]), () => ( null));
4293
- const next = _nullishCoalesce(_optionalChain([first, 'call', _71 => _71(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _72 => _72.id]), () => ( null));
4395
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _72 => _72(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _73 => _73.id]), () => ( null));
4396
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _74 => _74(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _75 => _75.id]), () => ( null));
4294
4397
  if (!message2.deletedAt || prev || next) {
4295
4398
  const node = {
4296
4399
  ...message2,
@@ -4356,7 +4459,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4356
4459
  const latest = pool.sorted.findRight(
4357
4460
  (m) => m.role === "assistant" && !m.deletedAt
4358
4461
  );
4359
- return _optionalChain([latest, 'optionalAccess', _73 => _73.copilotId]);
4462
+ return _optionalChain([latest, 'optionalAccess', _76 => _76.copilotId]);
4360
4463
  }
4361
4464
  return {
4362
4465
  // Readers
@@ -4373,6 +4476,33 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4373
4476
  failAllPending,
4374
4477
  markMine(messageId) {
4375
4478
  myMessages.add(messageId);
4479
+ },
4480
+ /**
4481
+ * Iterates over all my auto-executing messages.
4482
+ *
4483
+ * These are messages that match all these conditions:
4484
+ * - The message is an assistant message
4485
+ * - The message is owned by this client ("mine")
4486
+ * - The message is currently in "awaiting-tool" status
4487
+ * - The message has at least one tool invocation in "executing" stage
4488
+ * - The tool invocation has an execute() function defined
4489
+ */
4490
+ *getAutoExecutingMessageIds() {
4491
+ for (const messageId of myMessages) {
4492
+ const message = getMessageById(messageId);
4493
+ if (_optionalChain([message, 'optionalAccess', _77 => _77.role]) === "assistant" && message.status === "awaiting-tool") {
4494
+ const isAutoExecuting = message.contentSoFar.some((part) => {
4495
+ if (part.type === "tool-invocation" && part.stage === "executing") {
4496
+ const tool = toolsStore.getTool\u03A3(part.name, message.chatId).get();
4497
+ return typeof _optionalChain([tool, 'optionalAccess', _78 => _78.execute]) === "function";
4498
+ }
4499
+ return false;
4500
+ });
4501
+ if (isAutoExecuting) {
4502
+ yield message.id;
4503
+ }
4504
+ }
4505
+ }
4376
4506
  }
4377
4507
  };
4378
4508
  }
@@ -4425,6 +4555,28 @@ function createAi(config) {
4425
4555
  toolsStore,
4426
4556
  knowledge: new KnowledgeStack()
4427
4557
  };
4558
+ const DELTA_THROTTLE = 25;
4559
+ let pendingDeltas = [];
4560
+ let deltaBatchTimer = null;
4561
+ function flushPendingDeltas() {
4562
+ const currentQueue = pendingDeltas;
4563
+ pendingDeltas = [];
4564
+ if (deltaBatchTimer !== null) {
4565
+ clearTimeout(deltaBatchTimer);
4566
+ deltaBatchTimer = null;
4567
+ }
4568
+ batch(() => {
4569
+ for (const { id, delta } of currentQueue) {
4570
+ context.messagesStore.addDelta(id, delta);
4571
+ }
4572
+ });
4573
+ }
4574
+ function enqueueDelta(id, delta) {
4575
+ pendingDeltas.push({ id, delta });
4576
+ if (deltaBatchTimer === null) {
4577
+ deltaBatchTimer = setTimeout(flushPendingDeltas, DELTA_THROTTLE);
4578
+ }
4579
+ }
4428
4580
  let lastTokenKey;
4429
4581
  function onStatusDidChange(_newStatus) {
4430
4582
  const authValue = managedSocket.authValue;
@@ -4464,6 +4616,7 @@ function createAi(config) {
4464
4616
  function onDidConnect() {
4465
4617
  }
4466
4618
  function onDidDisconnect() {
4619
+ flushPendingDeltas();
4467
4620
  }
4468
4621
  function handleServerMessage(event) {
4469
4622
  if (typeof event.data !== "string")
@@ -4478,50 +4631,51 @@ function createAi(config) {
4478
4631
  return;
4479
4632
  }
4480
4633
  if ("event" in msg) {
4481
- switch (msg.event) {
4482
- case "cmd-failed":
4483
- _optionalChain([pendingCmd, 'optionalAccess', _74 => _74.reject, 'call', _75 => _75(new Error(msg.error))]);
4484
- break;
4485
- case "delta": {
4486
- const { id, delta } = msg;
4487
- context.messagesStore.addDelta(id, delta);
4488
- break;
4489
- }
4490
- case "settle": {
4491
- context.messagesStore.upsert(msg.message);
4492
- break;
4493
- }
4494
- case "warning":
4495
- warn(msg.message);
4496
- break;
4497
- case "error":
4498
- error2(msg.error);
4499
- break;
4500
- case "rebooted":
4501
- context.messagesStore.failAllPending();
4502
- break;
4503
- case "sync":
4504
- batch(() => {
4505
- for (const m of _nullishCoalesce(msg["-messages"], () => ( []))) {
4506
- context.messagesStore.remove(m.chatId, m.id);
4507
- }
4508
- for (const chatId of _nullishCoalesce(msg["-chats"], () => ( []))) {
4509
- context.chatsStore.markDeleted(chatId);
4510
- context.messagesStore.removeByChatId(chatId);
4511
- }
4512
- for (const chatId of _nullishCoalesce(msg.clear, () => ( []))) {
4513
- context.messagesStore.removeByChatId(chatId);
4514
- }
4515
- if (msg.chats) {
4516
- context.chatsStore.upsertMany(msg.chats);
4517
- }
4518
- if (msg.messages) {
4519
- context.messagesStore.upsertMany(msg.messages);
4634
+ if (msg.event === "delta") {
4635
+ const { id, delta } = msg;
4636
+ enqueueDelta(id, delta);
4637
+ } else {
4638
+ batch(() => {
4639
+ flushPendingDeltas();
4640
+ switch (msg.event) {
4641
+ case "cmd-failed":
4642
+ _optionalChain([pendingCmd, 'optionalAccess', _79 => _79.reject, 'call', _80 => _80(new Error(msg.error))]);
4643
+ break;
4644
+ case "settle": {
4645
+ context.messagesStore.upsert(msg.message);
4646
+ break;
4520
4647
  }
4521
- });
4522
- break;
4523
- default:
4524
- return assertNever(msg, "Unhandled case");
4648
+ case "warning":
4649
+ warn(msg.message);
4650
+ break;
4651
+ case "error":
4652
+ error2(msg.error);
4653
+ break;
4654
+ case "rebooted":
4655
+ context.messagesStore.failAllPending();
4656
+ break;
4657
+ case "sync":
4658
+ for (const m of _nullishCoalesce(msg["-messages"], () => ( []))) {
4659
+ context.messagesStore.remove(m.chatId, m.id);
4660
+ }
4661
+ for (const chatId of _nullishCoalesce(msg["-chats"], () => ( []))) {
4662
+ context.chatsStore.markDeleted(chatId);
4663
+ context.messagesStore.removeByChatId(chatId);
4664
+ }
4665
+ for (const chatId of _nullishCoalesce(msg.clear, () => ( []))) {
4666
+ context.messagesStore.removeByChatId(chatId);
4667
+ }
4668
+ if (msg.chats) {
4669
+ context.chatsStore.upsertMany(msg.chats);
4670
+ }
4671
+ if (msg.messages) {
4672
+ context.messagesStore.upsertMany(msg.messages);
4673
+ }
4674
+ break;
4675
+ default:
4676
+ return assertNever(msg, "Unhandled case");
4677
+ }
4678
+ });
4525
4679
  }
4526
4680
  } else {
4527
4681
  switch (msg.cmd) {
@@ -4562,7 +4716,7 @@ function createAi(config) {
4562
4716
  return assertNever(msg, "Unhandled case");
4563
4717
  }
4564
4718
  }
4565
- _optionalChain([pendingCmd, 'optionalAccess', _76 => _76.resolve, 'call', _77 => _77(msg)]);
4719
+ _optionalChain([pendingCmd, 'optionalAccess', _81 => _81.resolve, 'call', _82 => _82(msg)]);
4566
4720
  }
4567
4721
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4568
4722
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4647,9 +4801,9 @@ function createAi(config) {
4647
4801
  invocationId,
4648
4802
  result,
4649
4803
  generationOptions: {
4650
- copilotId: _optionalChain([options, 'optionalAccess', _78 => _78.copilotId]),
4651
- stream: _optionalChain([options, 'optionalAccess', _79 => _79.stream]),
4652
- timeout: _optionalChain([options, 'optionalAccess', _80 => _80.timeout]),
4804
+ copilotId: _optionalChain([options, 'optionalAccess', _83 => _83.copilotId]),
4805
+ stream: _optionalChain([options, 'optionalAccess', _84 => _84.stream]),
4806
+ timeout: _optionalChain([options, 'optionalAccess', _85 => _85.timeout]),
4653
4807
  // Knowledge and tools aren't coming from the options, but retrieved
4654
4808
  // from the global context
4655
4809
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4660,6 +4814,14 @@ function createAi(config) {
4660
4814
  messagesStore.markMine(resp.message.id);
4661
4815
  }
4662
4816
  }
4817
+ function handleBeforeUnload() {
4818
+ for (const messageId of context.messagesStore.getAutoExecutingMessageIds()) {
4819
+ sendClientMsgWithResponse({ cmd: "abort-ai", messageId }).catch(() => {
4820
+ });
4821
+ }
4822
+ }
4823
+ const win = typeof window !== "undefined" ? window : void 0;
4824
+ _optionalChain([win, 'optionalAccess', _86 => _86.addEventListener, 'call', _87 => _87("beforeunload", handleBeforeUnload, { once: true })]);
4663
4825
  return Object.defineProperty(
4664
4826
  {
4665
4827
  [kInternal]: {
@@ -4678,7 +4840,7 @@ function createAi(config) {
4678
4840
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4679
4841
  askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4680
4842
  const globalKnowledge = context.knowledge.get();
4681
- const requestKnowledge = _optionalChain([options, 'optionalAccess', _81 => _81.knowledge]) || [];
4843
+ const requestKnowledge = _optionalChain([options, 'optionalAccess', _88 => _88.knowledge]) || [];
4682
4844
  const combinedKnowledge = [...globalKnowledge, ...requestKnowledge];
4683
4845
  const tools = context.toolsStore.getToolDescriptions(chatId);
4684
4846
  messagesStore.markMine(targetMessageId);
@@ -4688,9 +4850,9 @@ function createAi(config) {
4688
4850
  sourceMessage: userMessage,
4689
4851
  targetMessageId,
4690
4852
  generationOptions: {
4691
- copilotId: _optionalChain([options, 'optionalAccess', _82 => _82.copilotId]),
4692
- stream: _optionalChain([options, 'optionalAccess', _83 => _83.stream]),
4693
- timeout: _optionalChain([options, 'optionalAccess', _84 => _84.timeout]),
4853
+ copilotId: _optionalChain([options, 'optionalAccess', _89 => _89.copilotId]),
4854
+ stream: _optionalChain([options, 'optionalAccess', _90 => _90.stream]),
4855
+ timeout: _optionalChain([options, 'optionalAccess', _91 => _91.timeout]),
4694
4856
  // Combine global knowledge with request-specific knowledge
4695
4857
  knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
4696
4858
  tools: tools.length > 0 ? tools : void 0
@@ -4727,7 +4889,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
4727
4889
  }
4728
4890
  const url2 = new URL(baseUrl);
4729
4891
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
4730
- url2.pathname = "/ai/v5";
4892
+ url2.pathname = "/ai/v6";
4731
4893
  if (authValue.type === "secret") {
4732
4894
  url2.searchParams.set("tok", authValue.token.raw);
4733
4895
  } else if (authValue.type === "public") {
@@ -4791,7 +4953,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4791
4953
  return void 0;
4792
4954
  }
4793
4955
  async function makeAuthRequest(options) {
4794
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _85 => _85.polyfills, 'optionalAccess', _86 => _86.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4956
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _92 => _92.polyfills, 'optionalAccess', _93 => _93.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4795
4957
  if (authentication.type === "private") {
4796
4958
  if (fetcher === void 0) {
4797
4959
  throw new StopRetrying(
@@ -4807,7 +4969,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4807
4969
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
4808
4970
  );
4809
4971
  }
4810
- _optionalChain([onAuthenticate, 'optionalCall', _87 => _87(parsed.parsed)]);
4972
+ _optionalChain([onAuthenticate, 'optionalCall', _94 => _94(parsed.parsed)]);
4811
4973
  return parsed;
4812
4974
  }
4813
4975
  if (authentication.type === "custom") {
@@ -4815,7 +4977,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4815
4977
  if (response && typeof response === "object") {
4816
4978
  if (typeof response.token === "string") {
4817
4979
  const parsed = parseAuthToken(response.token);
4818
- _optionalChain([onAuthenticate, 'optionalCall', _88 => _88(parsed.parsed)]);
4980
+ _optionalChain([onAuthenticate, 'optionalCall', _95 => _95(parsed.parsed)]);
4819
4981
  return parsed;
4820
4982
  } else if (typeof response.error === "string") {
4821
4983
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -4973,7 +5135,7 @@ function sendToPanel(message, options) {
4973
5135
  ...message,
4974
5136
  source: "liveblocks-devtools-client"
4975
5137
  };
4976
- if (!(_optionalChain([options, 'optionalAccess', _89 => _89.force]) || _bridgeActive)) {
5138
+ if (!(_optionalChain([options, 'optionalAccess', _96 => _96.force]) || _bridgeActive)) {
4977
5139
  return;
4978
5140
  }
4979
5141
  window.postMessage(fullMsg, "*");
@@ -4981,7 +5143,7 @@ function sendToPanel(message, options) {
4981
5143
  var eventSource = makeEventSource();
4982
5144
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
4983
5145
  window.addEventListener("message", (event) => {
4984
- if (event.source === window && _optionalChain([event, 'access', _90 => _90.data, 'optionalAccess', _91 => _91.source]) === "liveblocks-devtools-panel") {
5146
+ if (event.source === window && _optionalChain([event, 'access', _97 => _97.data, 'optionalAccess', _98 => _98.source]) === "liveblocks-devtools-panel") {
4985
5147
  eventSource.notify(event.data);
4986
5148
  } else {
4987
5149
  }
@@ -5123,7 +5285,7 @@ function fullSync(room) {
5123
5285
  msg: "room::sync::full",
5124
5286
  roomId: room.id,
5125
5287
  status: room.getStatus(),
5126
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _92 => _92.toTreeNode, 'call', _93 => _93("root"), 'access', _94 => _94.payload]), () => ( null)),
5288
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _99 => _99.toTreeNode, 'call', _100 => _100("root"), 'access', _101 => _101.payload]), () => ( null)),
5127
5289
  me,
5128
5290
  others
5129
5291
  });
@@ -5414,7 +5576,7 @@ function createManagedPool(roomId, options) {
5414
5576
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5415
5577
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5416
5578
  dispatch(ops, reverse, storageUpdates) {
5417
- _optionalChain([onDispatch, 'optionalCall', _95 => _95(ops, reverse, storageUpdates)]);
5579
+ _optionalChain([onDispatch, 'optionalCall', _102 => _102(ops, reverse, storageUpdates)]);
5418
5580
  },
5419
5581
  assertStorageIsWritable: () => {
5420
5582
  if (!isStorageWritable()) {
@@ -5641,7 +5803,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5641
5803
  return [
5642
5804
  {
5643
5805
  type: 8 /* CREATE_REGISTER */,
5644
- opId: _optionalChain([pool, 'optionalAccess', _96 => _96.generateOpId, 'call', _97 => _97()]),
5806
+ opId: _optionalChain([pool, 'optionalAccess', _103 => _103.generateOpId, 'call', _104 => _104()]),
5645
5807
  id: this._id,
5646
5808
  parentId,
5647
5809
  parentKey,
@@ -5747,7 +5909,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5747
5909
  const ops = [];
5748
5910
  const op = {
5749
5911
  id: this._id,
5750
- opId: _optionalChain([pool, 'optionalAccess', _98 => _98.generateOpId, 'call', _99 => _99()]),
5912
+ opId: _optionalChain([pool, 'optionalAccess', _105 => _105.generateOpId, 'call', _106 => _106()]),
5751
5913
  type: 2 /* CREATE_LIST */,
5752
5914
  parentId,
5753
5915
  parentKey
@@ -6018,7 +6180,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6018
6180
  #applyInsertUndoRedo(op) {
6019
6181
  const { id, parentKey: key } = op;
6020
6182
  const child = creationOpToLiveNode(op);
6021
- if (_optionalChain([this, 'access', _100 => _100._pool, 'optionalAccess', _101 => _101.getNode, 'call', _102 => _102(id)]) !== void 0) {
6183
+ if (_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.getNode, 'call', _109 => _109(id)]) !== void 0) {
6022
6184
  return { modified: false };
6023
6185
  }
6024
6186
  child._attach(id, nn(this._pool));
@@ -6026,8 +6188,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6026
6188
  const existingItemIndex = this._indexOfPosition(key);
6027
6189
  let newKey = key;
6028
6190
  if (existingItemIndex !== -1) {
6029
- const before2 = _optionalChain([this, 'access', _103 => _103.#items, 'access', _104 => _104[existingItemIndex], 'optionalAccess', _105 => _105._parentPos]);
6030
- const after2 = _optionalChain([this, 'access', _106 => _106.#items, 'access', _107 => _107[existingItemIndex + 1], 'optionalAccess', _108 => _108._parentPos]);
6191
+ const before2 = _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[existingItemIndex], 'optionalAccess', _112 => _112._parentPos]);
6192
+ const after2 = _optionalChain([this, 'access', _113 => _113.#items, 'access', _114 => _114[existingItemIndex + 1], 'optionalAccess', _115 => _115._parentPos]);
6031
6193
  newKey = makePosition(before2, after2);
6032
6194
  child._setParentLink(this, newKey);
6033
6195
  }
@@ -6041,7 +6203,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6041
6203
  #applySetUndoRedo(op) {
6042
6204
  const { id, parentKey: key } = op;
6043
6205
  const child = creationOpToLiveNode(op);
6044
- if (_optionalChain([this, 'access', _109 => _109._pool, 'optionalAccess', _110 => _110.getNode, 'call', _111 => _111(id)]) !== void 0) {
6206
+ if (_optionalChain([this, 'access', _116 => _116._pool, 'optionalAccess', _117 => _117.getNode, 'call', _118 => _118(id)]) !== void 0) {
6045
6207
  return { modified: false };
6046
6208
  }
6047
6209
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -6162,7 +6324,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6162
6324
  } else {
6163
6325
  this.#items[existingItemIndex]._setParentLink(
6164
6326
  this,
6165
- makePosition(newKey, _optionalChain([this, 'access', _112 => _112.#items, 'access', _113 => _113[existingItemIndex + 1], 'optionalAccess', _114 => _114._parentPos]))
6327
+ makePosition(newKey, _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120[existingItemIndex + 1], 'optionalAccess', _121 => _121._parentPos]))
6166
6328
  );
6167
6329
  const previousIndex = this.#items.indexOf(child);
6168
6330
  child._setParentLink(this, newKey);
@@ -6187,7 +6349,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6187
6349
  if (existingItemIndex !== -1) {
6188
6350
  this.#items[existingItemIndex]._setParentLink(
6189
6351
  this,
6190
- makePosition(newKey, _optionalChain([this, 'access', _115 => _115.#items, 'access', _116 => _116[existingItemIndex + 1], 'optionalAccess', _117 => _117._parentPos]))
6352
+ makePosition(newKey, _optionalChain([this, 'access', _122 => _122.#items, 'access', _123 => _123[existingItemIndex + 1], 'optionalAccess', _124 => _124._parentPos]))
6191
6353
  );
6192
6354
  }
6193
6355
  child._setParentLink(this, newKey);
@@ -6206,7 +6368,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6206
6368
  if (existingItemIndex !== -1) {
6207
6369
  this.#items[existingItemIndex]._setParentLink(
6208
6370
  this,
6209
- makePosition(newKey, _optionalChain([this, 'access', _118 => _118.#items, 'access', _119 => _119[existingItemIndex + 1], 'optionalAccess', _120 => _120._parentPos]))
6371
+ makePosition(newKey, _optionalChain([this, 'access', _125 => _125.#items, 'access', _126 => _126[existingItemIndex + 1], 'optionalAccess', _127 => _127._parentPos]))
6210
6372
  );
6211
6373
  }
6212
6374
  child._setParentLink(this, newKey);
@@ -6233,7 +6395,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6233
6395
  if (existingItemIndex !== -1) {
6234
6396
  this.#items[existingItemIndex]._setParentLink(
6235
6397
  this,
6236
- makePosition(newKey, _optionalChain([this, 'access', _121 => _121.#items, 'access', _122 => _122[existingItemIndex + 1], 'optionalAccess', _123 => _123._parentPos]))
6398
+ makePosition(newKey, _optionalChain([this, 'access', _128 => _128.#items, 'access', _129 => _129[existingItemIndex + 1], 'optionalAccess', _130 => _130._parentPos]))
6237
6399
  );
6238
6400
  }
6239
6401
  child._setParentLink(this, newKey);
@@ -6291,7 +6453,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6291
6453
  * @param element The element to add to the end of the LiveList.
6292
6454
  */
6293
6455
  push(element) {
6294
- _optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.assertStorageIsWritable, 'call', _126 => _126()]);
6456
+ _optionalChain([this, 'access', _131 => _131._pool, 'optionalAccess', _132 => _132.assertStorageIsWritable, 'call', _133 => _133()]);
6295
6457
  return this.insert(element, this.length);
6296
6458
  }
6297
6459
  /**
@@ -6300,7 +6462,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6300
6462
  * @param index The index at which you want to insert the element.
6301
6463
  */
6302
6464
  insert(element, index) {
6303
- _optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.assertStorageIsWritable, 'call', _129 => _129()]);
6465
+ _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6304
6466
  if (index < 0 || index > this.#items.length) {
6305
6467
  throw new Error(
6306
6468
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6330,7 +6492,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6330
6492
  * @param targetIndex The index where the element should be after moving.
6331
6493
  */
6332
6494
  move(index, targetIndex) {
6333
- _optionalChain([this, 'access', _130 => _130._pool, 'optionalAccess', _131 => _131.assertStorageIsWritable, 'call', _132 => _132()]);
6495
+ _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6334
6496
  if (targetIndex < 0) {
6335
6497
  throw new Error("targetIndex cannot be less than 0");
6336
6498
  }
@@ -6388,7 +6550,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6388
6550
  * @param index The index of the element to delete
6389
6551
  */
6390
6552
  delete(index) {
6391
- _optionalChain([this, 'access', _133 => _133._pool, 'optionalAccess', _134 => _134.assertStorageIsWritable, 'call', _135 => _135()]);
6553
+ _optionalChain([this, 'access', _140 => _140._pool, 'optionalAccess', _141 => _141.assertStorageIsWritable, 'call', _142 => _142()]);
6392
6554
  if (index < 0 || index >= this.#items.length) {
6393
6555
  throw new Error(
6394
6556
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6421,7 +6583,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6421
6583
  }
6422
6584
  }
6423
6585
  clear() {
6424
- _optionalChain([this, 'access', _136 => _136._pool, 'optionalAccess', _137 => _137.assertStorageIsWritable, 'call', _138 => _138()]);
6586
+ _optionalChain([this, 'access', _143 => _143._pool, 'optionalAccess', _144 => _144.assertStorageIsWritable, 'call', _145 => _145()]);
6425
6587
  if (this._pool) {
6426
6588
  const ops = [];
6427
6589
  const reverseOps = [];
@@ -6455,7 +6617,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6455
6617
  }
6456
6618
  }
6457
6619
  set(index, item) {
6458
- _optionalChain([this, 'access', _139 => _139._pool, 'optionalAccess', _140 => _140.assertStorageIsWritable, 'call', _141 => _141()]);
6620
+ _optionalChain([this, 'access', _146 => _146._pool, 'optionalAccess', _147 => _147.assertStorageIsWritable, 'call', _148 => _148()]);
6459
6621
  if (index < 0 || index >= this.#items.length) {
6460
6622
  throw new Error(
6461
6623
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6601,7 +6763,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6601
6763
  #shiftItemPosition(index, key) {
6602
6764
  const shiftedPosition = makePosition(
6603
6765
  key,
6604
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _142 => _142.#items, 'access', _143 => _143[index + 1], 'optionalAccess', _144 => _144._parentPos]) : void 0
6766
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _149 => _149.#items, 'access', _150 => _150[index + 1], 'optionalAccess', _151 => _151._parentPos]) : void 0
6605
6767
  );
6606
6768
  this.#items[index]._setParentLink(this, shiftedPosition);
6607
6769
  }
@@ -6726,7 +6888,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6726
6888
  const ops = [];
6727
6889
  const op = {
6728
6890
  id: this._id,
6729
- opId: _optionalChain([pool, 'optionalAccess', _145 => _145.generateOpId, 'call', _146 => _146()]),
6891
+ opId: _optionalChain([pool, 'optionalAccess', _152 => _152.generateOpId, 'call', _153 => _153()]),
6730
6892
  type: 7 /* CREATE_MAP */,
6731
6893
  parentId,
6732
6894
  parentKey
@@ -6861,7 +7023,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6861
7023
  * @param value The value of the element to add. Should be serializable to JSON.
6862
7024
  */
6863
7025
  set(key, value) {
6864
- _optionalChain([this, 'access', _147 => _147._pool, 'optionalAccess', _148 => _148.assertStorageIsWritable, 'call', _149 => _149()]);
7026
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
6865
7027
  const oldValue = this.#map.get(key);
6866
7028
  if (oldValue) {
6867
7029
  oldValue._detach();
@@ -6907,7 +7069,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6907
7069
  * @returns true if an element existed and has been removed, or false if the element does not exist.
6908
7070
  */
6909
7071
  delete(key) {
6910
- _optionalChain([this, 'access', _150 => _150._pool, 'optionalAccess', _151 => _151.assertStorageIsWritable, 'call', _152 => _152()]);
7072
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
6911
7073
  const item = this.#map.get(key);
6912
7074
  if (item === void 0) {
6913
7075
  return false;
@@ -7097,7 +7259,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7097
7259
  if (this._id === void 0) {
7098
7260
  throw new Error("Cannot serialize item is not attached");
7099
7261
  }
7100
- const opId = _optionalChain([pool, 'optionalAccess', _153 => _153.generateOpId, 'call', _154 => _154()]);
7262
+ const opId = _optionalChain([pool, 'optionalAccess', _160 => _160.generateOpId, 'call', _161 => _161()]);
7101
7263
  const ops = [];
7102
7264
  const op = {
7103
7265
  type: 4 /* CREATE_OBJECT */,
@@ -7369,7 +7531,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7369
7531
  * @param value The value of the property to add
7370
7532
  */
7371
7533
  set(key, value) {
7372
- _optionalChain([this, 'access', _155 => _155._pool, 'optionalAccess', _156 => _156.assertStorageIsWritable, 'call', _157 => _157()]);
7534
+ _optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.assertStorageIsWritable, 'call', _164 => _164()]);
7373
7535
  this.update({ [key]: value });
7374
7536
  }
7375
7537
  /**
@@ -7384,7 +7546,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7384
7546
  * @param key The key of the property to delete
7385
7547
  */
7386
7548
  delete(key) {
7387
- _optionalChain([this, 'access', _158 => _158._pool, 'optionalAccess', _159 => _159.assertStorageIsWritable, 'call', _160 => _160()]);
7549
+ _optionalChain([this, 'access', _165 => _165._pool, 'optionalAccess', _166 => _166.assertStorageIsWritable, 'call', _167 => _167()]);
7388
7550
  const keyAsString = key;
7389
7551
  const oldValue = this.#map.get(keyAsString);
7390
7552
  if (oldValue === void 0) {
@@ -7437,7 +7599,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7437
7599
  * @param patch The object used to overrides properties
7438
7600
  */
7439
7601
  update(patch) {
7440
- _optionalChain([this, 'access', _161 => _161._pool, 'optionalAccess', _162 => _162.assertStorageIsWritable, 'call', _163 => _163()]);
7602
+ _optionalChain([this, 'access', _168 => _168._pool, 'optionalAccess', _169 => _169.assertStorageIsWritable, 'call', _170 => _170()]);
7441
7603
  if (_LiveObject.detectLargeObjects) {
7442
7604
  const data = {};
7443
7605
  for (const [key, value] of this.#map) {
@@ -8185,15 +8347,15 @@ function installBackgroundTabSpy() {
8185
8347
  const doc = typeof document !== "undefined" ? document : void 0;
8186
8348
  const inBackgroundSince = { current: null };
8187
8349
  function onVisibilityChange() {
8188
- if (_optionalChain([doc, 'optionalAccess', _164 => _164.visibilityState]) === "hidden") {
8350
+ if (_optionalChain([doc, 'optionalAccess', _171 => _171.visibilityState]) === "hidden") {
8189
8351
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
8190
8352
  } else {
8191
8353
  inBackgroundSince.current = null;
8192
8354
  }
8193
8355
  }
8194
- _optionalChain([doc, 'optionalAccess', _165 => _165.addEventListener, 'call', _166 => _166("visibilitychange", onVisibilityChange)]);
8356
+ _optionalChain([doc, 'optionalAccess', _172 => _172.addEventListener, 'call', _173 => _173("visibilitychange", onVisibilityChange)]);
8195
8357
  const unsub = () => {
8196
- _optionalChain([doc, 'optionalAccess', _167 => _167.removeEventListener, 'call', _168 => _168("visibilitychange", onVisibilityChange)]);
8358
+ _optionalChain([doc, 'optionalAccess', _174 => _174.removeEventListener, 'call', _175 => _175("visibilitychange", onVisibilityChange)]);
8197
8359
  };
8198
8360
  return [inBackgroundSince, unsub];
8199
8361
  }
@@ -8373,7 +8535,7 @@ function createRoom(options, config) {
8373
8535
  }
8374
8536
  }
8375
8537
  function isStorageWritable() {
8376
- const scopes = _optionalChain([context, 'access', _169 => _169.dynamicSessionInfoSig, 'access', _170 => _170.get, 'call', _171 => _171(), 'optionalAccess', _172 => _172.scopes]);
8538
+ const scopes = _optionalChain([context, 'access', _176 => _176.dynamicSessionInfoSig, 'access', _177 => _177.get, 'call', _178 => _178(), 'optionalAccess', _179 => _179.scopes]);
8377
8539
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8378
8540
  }
8379
8541
  const eventHub = {
@@ -8499,7 +8661,7 @@ function createRoom(options, config) {
8499
8661
  }
8500
8662
  case "experimental-fallback-to-http": {
8501
8663
  warn("Message is too large for websockets, so sending over HTTP instead");
8502
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _173 => _173.dynamicSessionInfoSig, 'access', _174 => _174.get, 'call', _175 => _175(), 'optionalAccess', _176 => _176.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8664
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _180 => _180.dynamicSessionInfoSig, 'access', _181 => _181.get, 'call', _182 => _182(), 'optionalAccess', _183 => _183.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8503
8665
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8504
8666
  if (!resp.ok && resp.status === 403) {
8505
8667
  managedSocket.reconnect();
@@ -8550,7 +8712,7 @@ function createRoom(options, config) {
8550
8712
  } else {
8551
8713
  context.root = LiveObject._fromItems(message.items, context.pool);
8552
8714
  }
8553
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _177 => _177.get, 'call', _178 => _178(), 'optionalAccess', _179 => _179.canWrite]), () => ( true));
8715
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _184 => _184.get, 'call', _185 => _185(), 'optionalAccess', _186 => _186.canWrite]), () => ( true));
8554
8716
  const stackSizeBefore = context.undoStack.length;
8555
8717
  for (const key in context.initialStorage) {
8556
8718
  if (context.root.get(key) === void 0) {
@@ -8753,7 +8915,7 @@ function createRoom(options, config) {
8753
8915
  }
8754
8916
  context.myPresence.patch(patch);
8755
8917
  if (context.activeBatch) {
8756
- if (_optionalChain([options2, 'optionalAccess', _180 => _180.addToHistory])) {
8918
+ if (_optionalChain([options2, 'optionalAccess', _187 => _187.addToHistory])) {
8757
8919
  context.activeBatch.reverseOps.pushLeft({
8758
8920
  type: "presence",
8759
8921
  data: oldValues
@@ -8762,7 +8924,7 @@ function createRoom(options, config) {
8762
8924
  context.activeBatch.updates.presence = true;
8763
8925
  } else {
8764
8926
  flushNowOrSoon();
8765
- if (_optionalChain([options2, 'optionalAccess', _181 => _181.addToHistory])) {
8927
+ if (_optionalChain([options2, 'optionalAccess', _188 => _188.addToHistory])) {
8766
8928
  addToUndoStack([{ type: "presence", data: oldValues }]);
8767
8929
  }
8768
8930
  notify({ presence: true });
@@ -8959,7 +9121,7 @@ function createRoom(options, config) {
8959
9121
  if (process.env.NODE_ENV !== "production") {
8960
9122
  const traces = /* @__PURE__ */ new Set();
8961
9123
  for (const opId of message.opIds) {
8962
- const trace = _optionalChain([context, 'access', _182 => _182.opStackTraces, 'optionalAccess', _183 => _183.get, 'call', _184 => _184(opId)]);
9124
+ const trace = _optionalChain([context, 'access', _189 => _189.opStackTraces, 'optionalAccess', _190 => _190.get, 'call', _191 => _191(opId)]);
8963
9125
  if (trace) {
8964
9126
  traces.add(trace);
8965
9127
  }
@@ -9093,7 +9255,7 @@ ${Array.from(traces).join("\n\n")}`
9093
9255
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
9094
9256
  createOrUpdateRootFromMessage(message);
9095
9257
  applyAndSendOps(unacknowledgedOps);
9096
- _optionalChain([_resolveStoragePromise, 'optionalCall', _185 => _185()]);
9258
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _192 => _192()]);
9097
9259
  notifyStorageStatus();
9098
9260
  eventHub.storageDidLoad.notify();
9099
9261
  }
@@ -9314,8 +9476,8 @@ ${Array.from(traces).join("\n\n")}`
9314
9476
  async function getThreads(options2) {
9315
9477
  return httpClient.getThreads({
9316
9478
  roomId,
9317
- query: _optionalChain([options2, 'optionalAccess', _186 => _186.query]),
9318
- cursor: _optionalChain([options2, 'optionalAccess', _187 => _187.cursor])
9479
+ query: _optionalChain([options2, 'optionalAccess', _193 => _193.query]),
9480
+ cursor: _optionalChain([options2, 'optionalAccess', _194 => _194.cursor])
9319
9481
  });
9320
9482
  }
9321
9483
  async function getThread(threadId) {
@@ -9422,7 +9584,7 @@ ${Array.from(traces).join("\n\n")}`
9422
9584
  function getSubscriptionSettings(options2) {
9423
9585
  return httpClient.getSubscriptionSettings({
9424
9586
  roomId,
9425
- signal: _optionalChain([options2, 'optionalAccess', _188 => _188.signal])
9587
+ signal: _optionalChain([options2, 'optionalAccess', _195 => _195.signal])
9426
9588
  });
9427
9589
  }
9428
9590
  function updateSubscriptionSettings(settings) {
@@ -9444,7 +9606,7 @@ ${Array.from(traces).join("\n\n")}`
9444
9606
  {
9445
9607
  [kInternal]: {
9446
9608
  get presenceBuffer() {
9447
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _189 => _189.buffer, 'access', _190 => _190.presenceUpdates, 'optionalAccess', _191 => _191.data]), () => ( null)));
9609
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _196 => _196.buffer, 'access', _197 => _197.presenceUpdates, 'optionalAccess', _198 => _198.data]), () => ( null)));
9448
9610
  },
9449
9611
  // prettier-ignore
9450
9612
  get undoStack() {
@@ -9459,9 +9621,9 @@ ${Array.from(traces).join("\n\n")}`
9459
9621
  return context.yjsProvider;
9460
9622
  },
9461
9623
  setYjsProvider(newProvider) {
9462
- _optionalChain([context, 'access', _192 => _192.yjsProvider, 'optionalAccess', _193 => _193.off, 'call', _194 => _194("status", yjsStatusDidChange)]);
9624
+ _optionalChain([context, 'access', _199 => _199.yjsProvider, 'optionalAccess', _200 => _200.off, 'call', _201 => _201("status", yjsStatusDidChange)]);
9463
9625
  context.yjsProvider = newProvider;
9464
- _optionalChain([newProvider, 'optionalAccess', _195 => _195.on, 'call', _196 => _196("status", yjsStatusDidChange)]);
9626
+ _optionalChain([newProvider, 'optionalAccess', _202 => _202.on, 'call', _203 => _203("status", yjsStatusDidChange)]);
9465
9627
  context.yjsProviderDidChange.notify();
9466
9628
  },
9467
9629
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9507,7 +9669,7 @@ ${Array.from(traces).join("\n\n")}`
9507
9669
  source.dispose();
9508
9670
  }
9509
9671
  eventHub.roomWillDestroy.notify();
9510
- _optionalChain([context, 'access', _197 => _197.yjsProvider, 'optionalAccess', _198 => _198.off, 'call', _199 => _199("status", yjsStatusDidChange)]);
9672
+ _optionalChain([context, 'access', _204 => _204.yjsProvider, 'optionalAccess', _205 => _205.off, 'call', _206 => _206("status", yjsStatusDidChange)]);
9511
9673
  syncSourceForStorage.destroy();
9512
9674
  syncSourceForYjs.destroy();
9513
9675
  uninstallBgTabSpy();
@@ -9657,7 +9819,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9657
9819
  }
9658
9820
  if (isLiveNode(first)) {
9659
9821
  const node = first;
9660
- if (_optionalChain([options, 'optionalAccess', _200 => _200.isDeep])) {
9822
+ if (_optionalChain([options, 'optionalAccess', _207 => _207.isDeep])) {
9661
9823
  const storageCallback = second;
9662
9824
  return subscribeToLiveStructureDeeply(node, storageCallback);
9663
9825
  } else {
@@ -9736,8 +9898,8 @@ function createClient(options) {
9736
9898
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9737
9899
  currentUserId.set(() => userId);
9738
9900
  });
9739
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _201 => _201.polyfills, 'optionalAccess', _202 => _202.fetch]) || /* istanbul ignore next */
9740
- _optionalChain([globalThis, 'access', _203 => _203.fetch, 'optionalAccess', _204 => _204.bind, 'call', _205 => _205(globalThis)]);
9901
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.fetch]) || /* istanbul ignore next */
9902
+ _optionalChain([globalThis, 'access', _210 => _210.fetch, 'optionalAccess', _211 => _211.bind, 'call', _212 => _212(globalThis)]);
9741
9903
  const httpClient = createApiClient({
9742
9904
  baseUrl,
9743
9905
  fetchPolyfill,
@@ -9755,7 +9917,7 @@ function createClient(options) {
9755
9917
  delegates: {
9756
9918
  createSocket: makeCreateSocketDelegateForAi(
9757
9919
  baseUrl,
9758
- _optionalChain([clientOptions, 'access', _206 => _206.polyfills, 'optionalAccess', _207 => _207.WebSocket])
9920
+ _optionalChain([clientOptions, 'access', _213 => _213.polyfills, 'optionalAccess', _214 => _214.WebSocket])
9759
9921
  ),
9760
9922
  authenticate: async () => {
9761
9923
  const resp = await authManager.getAuthValue({
@@ -9823,7 +9985,7 @@ function createClient(options) {
9823
9985
  createSocket: makeCreateSocketDelegateForRoom(
9824
9986
  roomId,
9825
9987
  baseUrl,
9826
- _optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.WebSocket])
9988
+ _optionalChain([clientOptions, 'access', _215 => _215.polyfills, 'optionalAccess', _216 => _216.WebSocket])
9827
9989
  ),
9828
9990
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
9829
9991
  })),
@@ -9846,7 +10008,7 @@ function createClient(options) {
9846
10008
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
9847
10009
  if (shouldConnect) {
9848
10010
  if (typeof atob === "undefined") {
9849
- if (_optionalChain([clientOptions, 'access', _210 => _210.polyfills, 'optionalAccess', _211 => _211.atob]) === void 0) {
10011
+ if (_optionalChain([clientOptions, 'access', _217 => _217.polyfills, 'optionalAccess', _218 => _218.atob]) === void 0) {
9850
10012
  throw new Error(
9851
10013
  "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"
9852
10014
  );
@@ -9858,7 +10020,7 @@ function createClient(options) {
9858
10020
  return leaseRoom(newRoomDetails);
9859
10021
  }
9860
10022
  function getRoom(roomId) {
9861
- const room = _optionalChain([roomsById, 'access', _212 => _212.get, 'call', _213 => _213(roomId), 'optionalAccess', _214 => _214.room]);
10023
+ const room = _optionalChain([roomsById, 'access', _219 => _219.get, 'call', _220 => _220(roomId), 'optionalAccess', _221 => _221.room]);
9862
10024
  return room ? room : null;
9863
10025
  }
9864
10026
  function logout() {
@@ -9878,7 +10040,7 @@ function createClient(options) {
9878
10040
  const batchedResolveUsers = new Batch(
9879
10041
  async (batchedUserIds) => {
9880
10042
  const userIds = batchedUserIds.flat();
9881
- const users = await _optionalChain([resolveUsers, 'optionalCall', _215 => _215({ userIds })]);
10043
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _222 => _222({ userIds })]);
9882
10044
  warnIfNoResolveUsers();
9883
10045
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
9884
10046
  },
@@ -9896,7 +10058,7 @@ function createClient(options) {
9896
10058
  const batchedResolveRoomsInfo = new Batch(
9897
10059
  async (batchedRoomIds) => {
9898
10060
  const roomIds = batchedRoomIds.flat();
9899
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _216 => _216({ roomIds })]);
10061
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _223 => _223({ roomIds })]);
9900
10062
  warnIfNoResolveRoomsInfo();
9901
10063
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
9902
10064
  },
@@ -9949,7 +10111,7 @@ function createClient(options) {
9949
10111
  }
9950
10112
  };
9951
10113
  const win = typeof window !== "undefined" ? window : void 0;
9952
- _optionalChain([win, 'optionalAccess', _217 => _217.addEventListener, 'call', _218 => _218("beforeunload", maybePreventClose)]);
10114
+ _optionalChain([win, 'optionalAccess', _224 => _224.addEventListener, 'call', _225 => _225("beforeunload", maybePreventClose)]);
9953
10115
  }
9954
10116
  async function getNotificationSettings(options2) {
9955
10117
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -10088,7 +10250,7 @@ var commentBodyElementsTypes = {
10088
10250
  mention: "inline"
10089
10251
  };
10090
10252
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10091
- if (!body || !_optionalChain([body, 'optionalAccess', _219 => _219.content])) {
10253
+ if (!body || !_optionalChain([body, 'optionalAccess', _226 => _226.content])) {
10092
10254
  return;
10093
10255
  }
10094
10256
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -10098,13 +10260,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10098
10260
  for (const block of body.content) {
10099
10261
  if (type === "all" || type === "block") {
10100
10262
  if (guard(block)) {
10101
- _optionalChain([visitor, 'optionalCall', _220 => _220(block)]);
10263
+ _optionalChain([visitor, 'optionalCall', _227 => _227(block)]);
10102
10264
  }
10103
10265
  }
10104
10266
  if (type === "all" || type === "inline") {
10105
10267
  for (const inline of block.children) {
10106
10268
  if (guard(inline)) {
10107
- _optionalChain([visitor, 'optionalCall', _221 => _221(inline)]);
10269
+ _optionalChain([visitor, 'optionalCall', _228 => _228(inline)]);
10108
10270
  }
10109
10271
  }
10110
10272
  }
@@ -10138,7 +10300,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
10138
10300
  userIds
10139
10301
  });
10140
10302
  for (const [index, userId] of userIds.entries()) {
10141
- const user = _optionalChain([users, 'optionalAccess', _222 => _222[index]]);
10303
+ const user = _optionalChain([users, 'optionalAccess', _229 => _229[index]]);
10142
10304
  if (user) {
10143
10305
  resolvedUsers.set(userId, user);
10144
10306
  }
@@ -10257,7 +10419,7 @@ var stringifyCommentBodyPlainElements = {
10257
10419
  text: ({ element }) => element.text,
10258
10420
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
10259
10421
  mention: ({ element, user }) => {
10260
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _223 => _223.name]), () => ( element.id))}`;
10422
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _230 => _230.name]), () => ( element.id))}`;
10261
10423
  }
10262
10424
  };
10263
10425
  var stringifyCommentBodyHtmlElements = {
@@ -10287,7 +10449,7 @@ var stringifyCommentBodyHtmlElements = {
10287
10449
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10288
10450
  },
10289
10451
  mention: ({ element, user }) => {
10290
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _224 => _224.name]) ? html`${_optionalChain([user, 'optionalAccess', _225 => _225.name])}` : element.id}</span>`;
10452
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _231 => _231.name]) ? html`${_optionalChain([user, 'optionalAccess', _232 => _232.name])}` : element.id}</span>`;
10291
10453
  }
10292
10454
  };
10293
10455
  var stringifyCommentBodyMarkdownElements = {
@@ -10317,19 +10479,19 @@ var stringifyCommentBodyMarkdownElements = {
10317
10479
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10318
10480
  },
10319
10481
  mention: ({ element, user }) => {
10320
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _226 => _226.name]), () => ( element.id))}`;
10482
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _233 => _233.name]), () => ( element.id))}`;
10321
10483
  }
10322
10484
  };
10323
10485
  async function stringifyCommentBody(body, options) {
10324
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _227 => _227.format]), () => ( "plain"));
10325
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _228 => _228.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10486
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _234 => _234.format]), () => ( "plain"));
10487
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _235 => _235.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10326
10488
  const elements = {
10327
10489
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10328
- ..._optionalChain([options, 'optionalAccess', _229 => _229.elements])
10490
+ ..._optionalChain([options, 'optionalAccess', _236 => _236.elements])
10329
10491
  };
10330
10492
  const resolvedUsers = await resolveUsersInCommentBody(
10331
10493
  body,
10332
- _optionalChain([options, 'optionalAccess', _230 => _230.resolveUsers])
10494
+ _optionalChain([options, 'optionalAccess', _237 => _237.resolveUsers])
10333
10495
  );
10334
10496
  const blocks = body.content.flatMap((block, blockIndex) => {
10335
10497
  switch (block.type) {
@@ -10615,12 +10777,12 @@ function legacy_patchImmutableNode(state, path, update) {
10615
10777
  }
10616
10778
  const newState = Object.assign({}, state);
10617
10779
  for (const key in update.updates) {
10618
- if (_optionalChain([update, 'access', _231 => _231.updates, 'access', _232 => _232[key], 'optionalAccess', _233 => _233.type]) === "update") {
10780
+ if (_optionalChain([update, 'access', _238 => _238.updates, 'access', _239 => _239[key], 'optionalAccess', _240 => _240.type]) === "update") {
10619
10781
  const val = update.node.get(key);
10620
10782
  if (val !== void 0) {
10621
10783
  newState[key] = lsonToJson(val);
10622
10784
  }
10623
- } else if (_optionalChain([update, 'access', _234 => _234.updates, 'access', _235 => _235[key], 'optionalAccess', _236 => _236.type]) === "delete") {
10785
+ } else if (_optionalChain([update, 'access', _241 => _241.updates, 'access', _242 => _242[key], 'optionalAccess', _243 => _243.type]) === "delete") {
10624
10786
  delete newState[key];
10625
10787
  }
10626
10788
  }
@@ -10681,12 +10843,12 @@ function legacy_patchImmutableNode(state, path, update) {
10681
10843
  }
10682
10844
  const newState = Object.assign({}, state);
10683
10845
  for (const key in update.updates) {
10684
- if (_optionalChain([update, 'access', _237 => _237.updates, 'access', _238 => _238[key], 'optionalAccess', _239 => _239.type]) === "update") {
10846
+ if (_optionalChain([update, 'access', _244 => _244.updates, 'access', _245 => _245[key], 'optionalAccess', _246 => _246.type]) === "update") {
10685
10847
  const value = update.node.get(key);
10686
10848
  if (value !== void 0) {
10687
10849
  newState[key] = lsonToJson(value);
10688
10850
  }
10689
- } else if (_optionalChain([update, 'access', _240 => _240.updates, 'access', _241 => _241[key], 'optionalAccess', _242 => _242.type]) === "delete") {
10851
+ } else if (_optionalChain([update, 'access', _247 => _247.updates, 'access', _248 => _248[key], 'optionalAccess', _249 => _249.type]) === "delete") {
10690
10852
  delete newState[key];
10691
10853
  }
10692
10854
  }
@@ -10766,9 +10928,9 @@ function makePoller(callback, intervalMs, options) {
10766
10928
  const startTime = performance.now();
10767
10929
  const doc = typeof document !== "undefined" ? document : void 0;
10768
10930
  const win = typeof window !== "undefined" ? window : void 0;
10769
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _243 => _243.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10931
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _250 => _250.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10770
10932
  const context = {
10771
- inForeground: _optionalChain([doc, 'optionalAccess', _244 => _244.visibilityState]) !== "hidden",
10933
+ inForeground: _optionalChain([doc, 'optionalAccess', _251 => _251.visibilityState]) !== "hidden",
10772
10934
  lastSuccessfulPollAt: startTime,
10773
10935
  count: 0,
10774
10936
  backoff: 0
@@ -10849,11 +11011,11 @@ function makePoller(callback, intervalMs, options) {
10849
11011
  pollNowIfStale();
10850
11012
  }
10851
11013
  function onVisibilityChange() {
10852
- setInForeground(_optionalChain([doc, 'optionalAccess', _245 => _245.visibilityState]) !== "hidden");
11014
+ setInForeground(_optionalChain([doc, 'optionalAccess', _252 => _252.visibilityState]) !== "hidden");
10853
11015
  }
10854
- _optionalChain([doc, 'optionalAccess', _246 => _246.addEventListener, 'call', _247 => _247("visibilitychange", onVisibilityChange)]);
10855
- _optionalChain([win, 'optionalAccess', _248 => _248.addEventListener, 'call', _249 => _249("online", onVisibilityChange)]);
10856
- _optionalChain([win, 'optionalAccess', _250 => _250.addEventListener, 'call', _251 => _251("focus", pollNowIfStale)]);
11016
+ _optionalChain([doc, 'optionalAccess', _253 => _253.addEventListener, 'call', _254 => _254("visibilitychange", onVisibilityChange)]);
11017
+ _optionalChain([win, 'optionalAccess', _255 => _255.addEventListener, 'call', _256 => _256("online", onVisibilityChange)]);
11018
+ _optionalChain([win, 'optionalAccess', _257 => _257.addEventListener, 'call', _258 => _258("focus", pollNowIfStale)]);
10857
11019
  fsm.start();
10858
11020
  return {
10859
11021
  inc,