@blocknote/xl-ai 0.32.0 → 0.33.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.
@@ -1,33 +1,33 @@
1
1
  var et = Object.defineProperty;
2
2
  var tt = (e, t, o) => t in e ? et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
- var j = (e, t, o) => tt(e, typeof t != "symbol" ? t + "" : t, o);
3
+ var $ = (e, t, o) => tt(e, typeof t != "symbol" ? t + "" : t, o);
4
4
  import { getPmSchema as ot, UnreachableCaseError as Pe, getNodeById as rt, updateBlockTr as nt, insertBlocks as st, trackPosition as se, removeAndInsertBlocks as it, getBlock as Oe, defaultProps as Me, isStyledTextInlineContent as at, isLinkInlineContent as ct, BlockNoteExtension as lt, filterSuggestionItems as ut, mergeCSSClasses as dt } from "@blocknote/core";
5
- import { applySuggestions as Be, suggestChanges as pt, revertSuggestions as ie } from "@blocknote/prosemirror-suggest-changes";
6
- import { jsonSchema as xe, streamObject as mt, generateObject as ft, APICallError as ht, RetryError as yt } from "ai";
5
+ import { applySuggestions as Be, suggestChanges as mt, revertSuggestions as ie } from "@blocknote/prosemirror-suggest-changes";
6
+ import { jsonSchema as xe, streamObject as ft, generateObject as pt, APICallError as ht, RetryError as yt } from "ai";
7
7
  import { TextSelection as gt, Plugin as Le, PluginKey as _e } from "prosemirror-state";
8
8
  import { fixTablesKey as kt } from "prosemirror-tables";
9
9
  import bt from "lodash.isequal";
10
10
  import { Slice as Y, Fragment as ae } from "prosemirror-model";
11
- import { Transform as N, Mapping as Ee, ReplaceStep as L, ReplaceAroundStep as St } from "prosemirror-transform";
11
+ import { Transform as A, Mapping as Ie, ReplaceStep as _, ReplaceAroundStep as St } from "prosemirror-transform";
12
12
  import { ChangeSet as ce, simplifyChanges as wt } from "prosemirror-changeset";
13
13
  import { DecorationSet as le, Decoration as ue } from "prosemirror-view";
14
14
  import { defaultSelectionBuilder as Tt } from "y-prosemirror";
15
15
  import { jsxs as vt, jsx as y } from "react/jsx-runtime";
16
16
  import { useBlockNoteContext as Ct, useComponentsContext as G, useSuggestionMenuKeyboardHandler as Pt, useBlockNoteEditor as K, useUIElementPositioning as Ot } from "@blocknote/react";
17
- import B, { useState as Ie, useCallback as D, useMemo as E, useEffect as Ne } from "react";
17
+ import B, { useState as Ee, useCallback as D, useMemo as E, useEffect as Ne } from "react";
18
18
  import { useStore as Ae } from "zustand";
19
19
  import { offset as Mt, size as Bt, autoUpdate as xt } from "@floating-ui/react";
20
20
  const de = (e) => {
21
21
  let t;
22
- const o = /* @__PURE__ */ new Set(), r = (u, m) => {
22
+ const o = /* @__PURE__ */ new Set(), r = (u, f) => {
23
23
  const l = typeof u == "function" ? u(t) : u;
24
24
  if (!Object.is(l, t)) {
25
- const f = t;
26
- t = m ?? (typeof l != "object" || l === null) ? l : Object.assign({}, t, l), o.forEach((p) => p(t, f));
25
+ const p = t;
26
+ t = f ?? (typeof l != "object" || l === null) ? l : Object.assign({}, t, l), o.forEach((m) => m(t, p));
27
27
  }
28
- }, n = () => t, s = { setState: r, getState: n, getInitialState: () => c, subscribe: (u) => (o.add(u), () => o.delete(u)) }, c = t = e(r, n, s);
29
- return s;
30
- }, pe = (e) => e ? de(e) : de;
28
+ }, n = () => t, i = { setState: r, getState: n, getInitialState: () => c, subscribe: (u) => (o.add(u), () => o.delete(u)) }, c = t = e(r, n, i);
29
+ return i;
30
+ }, me = (e) => e ? de(e) : de;
31
31
  function Lt(e) {
32
32
  const { properties: t, required: o, $defs: r, ...n } = e.parameters;
33
33
  return {
@@ -84,7 +84,7 @@ function _t(e) {
84
84
  }
85
85
  });
86
86
  }
87
- function I(e) {
87
+ function N(e) {
88
88
  if (e.locked)
89
89
  throw new Error(
90
90
  "Stream (source) is already locked and cannot be iterated."
@@ -102,23 +102,23 @@ function I(e) {
102
102
  };
103
103
  }, t;
104
104
  }
105
- function De(e) {
106
- return I(_t(e));
105
+ function $e(e) {
106
+ return N(_t(e));
107
107
  }
108
- async function* Et(e) {
108
+ async function* It(e) {
109
109
  var n;
110
110
  let t = 0, o = !0, r;
111
- for await (const i of e)
112
- if ((n = i.operations) != null && n.length) {
113
- for (let a = t; a < i.operations.length; a++) {
114
- const s = i.operations[a];
115
- r = s, yield {
116
- partialOperation: s,
111
+ for await (const s of e)
112
+ if ((n = s.operations) != null && n.length) {
113
+ for (let a = t; a < s.operations.length; a++) {
114
+ const i = s.operations[a];
115
+ r = i, yield {
116
+ partialOperation: i,
117
117
  isUpdateToPreviousOperation: a === t && !o,
118
- isPossiblyPartial: a === i.operations.length - 1
118
+ isPossiblyPartial: a === s.operations.length - 1
119
119
  }, o = !1;
120
120
  }
121
- t = i.operations.length - 1;
121
+ t = s.operations.length - 1;
122
122
  }
123
123
  if (!r)
124
124
  throw new Error("No operations seen");
@@ -128,7 +128,7 @@ async function* Et(e) {
128
128
  isPossiblyPartial: !1
129
129
  };
130
130
  }
131
- async function* $e(e, t) {
131
+ async function* De(e, t) {
132
132
  let o = !1;
133
133
  for await (const r of e) {
134
134
  const n = r.operation;
@@ -145,7 +145,7 @@ async function* $e(e, t) {
145
145
  async function* Re(e, t) {
146
146
  for await (const o of e) {
147
147
  const r = t.find(
148
- (i) => i.name === o.partialOperation.type
148
+ (s) => s.name === o.partialOperation.type
149
149
  );
150
150
  if (!r) {
151
151
  yield {
@@ -165,12 +165,12 @@ async function* Re(e, t) {
165
165
  };
166
166
  }
167
167
  }
168
- async function* It(e, t) {
168
+ async function* Et(e, t) {
169
169
  const o = Re(
170
170
  e,
171
171
  t
172
172
  );
173
- yield* $e(
173
+ yield* De(
174
174
  o,
175
175
  (n) => {
176
176
  if (!n.isPossiblyPartial)
@@ -183,7 +183,7 @@ async function* Nt(e, t) {
183
183
  e,
184
184
  t
185
185
  );
186
- yield* $e(
186
+ yield* De(
187
187
  o,
188
188
  (n) => {
189
189
  throw new Error("invalid operation: " + n.operation.error);
@@ -196,30 +196,31 @@ async function At(e, t) {
196
196
  throw new Error(
197
197
  "Cannot provide output or schema in _generateObjectOptions"
198
198
  );
199
- const i = {
199
+ const s = {
200
200
  // non-overridable options for streamObject
201
201
  output: "object",
202
202
  schema: xe(je(e)),
203
203
  // configurable options for streamObject
204
204
  // - optional, with defaults
205
205
  // mistral somehow needs "auto", while groq/llama needs "tool"
206
+ // google needs "auto" because https://github.com/vercel/ai/issues/6959
206
207
  // TODO: further research this and / or make configurable
207
208
  // for now stick to "tool" by default as this has been tested mostly
208
- mode: r.model.provider === "mistral.chat" ? "auto" : "tool",
209
+ mode: r.model.provider === "mistral.chat" || r.model.provider === "google.generative-ai" ? "auto" : "tool",
209
210
  // - mandatory ones:
210
211
  ...r,
211
212
  // extra options for streamObject
212
213
  ...o ?? {}
213
- }, a = await ft(i), s = jt(a.object);
214
- if (!s.ok)
215
- throw new Error(s.error);
214
+ }, a = await pt(s), i = jt(a.object);
215
+ if (!i.ok)
216
+ throw new Error(i.error);
216
217
  let c;
217
218
  return {
218
219
  streamObjectResult: void 0,
219
220
  generateObjectResult: a,
220
221
  get operationsSource() {
221
- return c || (c = De(
222
- Nt(s.value, e)
222
+ return c || (c = $e(
223
+ Nt(i.value, e)
223
224
  )), c;
224
225
  },
225
226
  async getGeneratedOperations() {
@@ -247,7 +248,7 @@ function jt(e) {
247
248
  value: o()
248
249
  };
249
250
  }
250
- async function Dt(e, t, o = () => {
251
+ async function $t(e, t, o = () => {
251
252
  }) {
252
253
  const { _streamObjectOptions: r, ...n } = t;
253
254
  if (r && ("output" in r || "schema" in r))
@@ -259,36 +260,37 @@ async function Dt(e, t, o = () => {
259
260
  // configurable options for streamObject
260
261
  // - optional, with defaults
261
262
  // mistral somehow needs "auto", while groq/llama needs "tool"
263
+ // google needs "auto" because https://github.com/vercel/ai/issues/6959
262
264
  // TODO: further research this and / or make configurable
263
265
  // for now stick to "tool" by default as this has been tested mostly
264
- mode: n.model.provider === "mistral.chat" ? "auto" : "tool",
266
+ mode: n.model.provider === "mistral.chat" || n.model.provider === "google.generative-ai" ? "auto" : "tool",
265
267
  // - mandatory ones:
266
268
  ...n,
267
269
  // extra options for streamObject
268
270
  ...t._streamObjectOptions ?? {}
269
- }, s = mt(a);
271
+ }, i = ft(a);
270
272
  let c;
271
- const [u, m] = s.fullStream.tee(), l = (async () => {
272
- let f = {
273
+ const [u, f] = i.fullStream.tee(), l = (async () => {
274
+ let p = {
273
275
  operations: []
274
276
  };
275
- const p = I(
276
- Ht(m)
277
+ const m = N(
278
+ Ht(f)
277
279
  );
278
- for await (const h of p)
279
- h && typeof h == "object" && "operations" in h && (f = h);
280
- return f;
280
+ for await (const h of m)
281
+ h && typeof h == "object" && "operations" in h && (p = h);
282
+ return p;
281
283
  })();
282
284
  return {
283
- streamObjectResult: s,
285
+ streamObjectResult: i,
284
286
  generateObjectResult: void 0,
285
287
  get operationsSource() {
286
- return c || (c = De(
287
- It(
288
- Et(
289
- $t(
288
+ return c || (c = $e(
289
+ Et(
290
+ It(
291
+ Dt(
290
292
  Rt(
291
- I(u)
293
+ N(u)
292
294
  ),
293
295
  o
294
296
  )
@@ -302,13 +304,13 @@ async function Dt(e, t, o = () => {
302
304
  }
303
305
  };
304
306
  }
305
- async function* $t(e, t) {
307
+ async function* Dt(e, t) {
306
308
  let o = !0;
307
309
  for await (const r of e)
308
310
  o && (t(), o = !1), yield r;
309
311
  }
310
312
  function Rt(e) {
311
- return I(
313
+ return N(
312
314
  e.pipeThrough(
313
315
  new TransformStream({
314
316
  transform(t, o) {
@@ -333,7 +335,7 @@ function Rt(e) {
333
335
  );
334
336
  }
335
337
  function Ht(e) {
336
- return I(
338
+ return N(
337
339
  e.pipeThrough(
338
340
  new TransformStream({
339
341
  transform(t, o) {
@@ -394,14 +396,32 @@ class qt {
394
396
  console.log(JSON.stringify(t, null, 2));
395
397
  }
396
398
  }
397
- function z(e, t) {
399
+ function Ut(e, t, o = !0, r = !0) {
400
+ let n = 0, s = e.length;
401
+ if (o)
402
+ for (; n < s && t(e[n]); )
403
+ n++;
404
+ if (r)
405
+ for (; s > n && t(e[s - 1]); )
406
+ s--;
407
+ return e.slice(n, s);
408
+ }
409
+ function x(e, t) {
410
+ return Ut(
411
+ e,
412
+ (r) => X(r) && (t == null ? void 0 : t.cursorBlockId) !== r.id,
413
+ (t == null ? void 0 : t.trimStart) ?? !1,
414
+ (t == null ? void 0 : t.trimEnd) ?? !0
415
+ );
416
+ }
417
+ function F(e, t) {
398
418
  const o = e.getTextCursorPosition(), r = [];
399
419
  for (const n of t) {
400
- const i = n.id === o.block.id;
420
+ const s = n.id === o.block.id;
401
421
  r.push({
402
422
  id: n.id,
403
423
  block: n.block
404
- }), i && r.push({
424
+ }), s && r.push({
405
425
  cursor: !0
406
426
  });
407
427
  }
@@ -422,39 +442,23 @@ function T(e) {
422
442
  ...T(t.children)
423
443
  ]);
424
444
  }
425
- function x(e) {
445
+ function L(e) {
426
446
  return e.map((t) => typeof t == "object" && t && "id" in t ? {
427
447
  ...t,
428
448
  id: `${t.id}$`
429
449
  } : t);
430
450
  }
431
- function Ut(e, t, o = !0, r = !0) {
432
- let n = 0, i = e.length;
433
- if (o)
434
- for (; n < i && t(e[n]); )
435
- n++;
436
- if (r)
437
- for (; i > n && t(e[i - 1]); )
438
- i--;
439
- return e.slice(n, i);
440
- }
441
- function F(e, t) {
442
- return e.length === 1 ? e : Ut(
443
- e,
444
- (r) => X(r),
445
- (t == null ? void 0 : t.trimStart) ?? !1,
446
- (t == null ? void 0 : t.trimEnd) ?? !0
447
- );
448
- }
449
451
  async function He(e, t) {
450
- const o = F(e.document), r = await C(
451
- T(o),
452
- async (s) => e.blocksToHTMLLossy([s])
453
- ), i = z(e, r).filter(
454
- (s) => "cursor" in s || !(t.excludeBlockIds || []).includes(s.id)
452
+ const o = e.getTextCursorPosition().block.id, r = x(e.document, {
453
+ cursorBlockId: o
454
+ }), n = await C(
455
+ T(r),
456
+ async (c) => e.blocksToHTMLLossy([c])
457
+ ), a = F(e, n).filter(
458
+ (c) => "cursor" in c || !(t.excludeBlockIds || []).includes(c.id)
455
459
  );
456
460
  return {
457
- htmlBlocks: x(i)
461
+ htmlBlocks: L(a)
458
462
  };
459
463
  }
460
464
  async function qe(e, t) {
@@ -463,7 +467,7 @@ async function qe(e, t) {
463
467
  async (n) => e.blocksToHTMLLossy([n])
464
468
  );
465
469
  return {
466
- htmlSelectedBlocks: x(o),
470
+ htmlSelectedBlocks: L(o),
467
471
  htmlDocument: (await C(T(e.document), async (n) => e.blocksToHTMLLossy([n]))).map(({ block: n }) => ({ block: n }))
468
472
  // strip ids so LLM can't accidentally issue updates to ids not in selection
469
473
  };
@@ -521,8 +525,9 @@ function Ft(e) {
521
525
  ];
522
526
  }
523
527
  const Jt = async (e, t) => {
528
+ const o = x(e.document).length === 0;
524
529
  if (t.selectedBlocks) {
525
- const o = await qe(e, {
530
+ const r = await qe(e, {
526
531
  selectedBlocks: t.selectedBlocks
527
532
  });
528
533
  return t.previousMessages ? [
@@ -534,7 +539,7 @@ const Jt = async (e, t) => {
534
539
  },
535
540
  {
536
541
  role: "system",
537
- content: JSON.stringify(o.htmlSelectedBlocks)
542
+ content: JSON.stringify(r.htmlSelectedBlocks)
538
543
  },
539
544
  {
540
545
  role: "system",
@@ -542,7 +547,7 @@ const Jt = async (e, t) => {
542
547
  },
543
548
  {
544
549
  role: "system",
545
- content: JSON.stringify(o.htmlDocument)
550
+ content: JSON.stringify(r.htmlDocument)
546
551
  },
547
552
  {
548
553
  role: "system",
@@ -556,12 +561,11 @@ const Jt = async (e, t) => {
556
561
  content: t.userPrompt
557
562
  }
558
563
  ] : zt({
559
- ...o,
560
- userPrompt: t.userPrompt,
561
- isEmptyDocument: e.isEmpty
564
+ ...r,
565
+ userPrompt: t.userPrompt
562
566
  });
563
567
  } else {
564
- const o = await He(e, t);
568
+ const r = await He(e, t);
565
569
  return t.previousMessages ? [
566
570
  ...t.previousMessages,
567
571
  {
@@ -571,7 +575,7 @@ const Jt = async (e, t) => {
571
575
  },
572
576
  {
573
577
  role: "system",
574
- content: JSON.stringify(o.htmlBlocks)
578
+ content: JSON.stringify(r.htmlBlocks)
575
579
  },
576
580
  {
577
581
  role: "system",
@@ -585,9 +589,9 @@ const Jt = async (e, t) => {
585
589
  content: t.userPrompt
586
590
  }
587
591
  ] : Ft({
588
- ...o,
592
+ ...r,
589
593
  userPrompt: t.userPrompt,
590
- isEmptyDocument: e.isEmpty
594
+ isEmptyDocument: o
591
595
  });
592
596
  }
593
597
  };
@@ -595,36 +599,36 @@ function Vt(e) {
595
599
  let t, o = !1;
596
600
  return e.descendants((r, n) => o ? !1 : (r.isText && (o = !0, t = n), !0)), t;
597
601
  }
598
- function $(e) {
599
- var i;
600
- const t = ot(e), { modification: o } = t.marks, r = [], n = new N(e.before);
602
+ function R(e) {
603
+ var s;
604
+ const t = ot(e), { modification: o } = t.marks, r = [], n = new A(e.before);
601
605
  for (let a = 0; a < e.steps.length; a++) {
602
- const s = e.steps[a], c = new Ee(e.mapping.maps.slice(0, a)).invert();
603
- if (s.structure) {
604
- if (s instanceof L) {
605
- if (s.to !== s.from + 1 || s.slice.openStart !== 0 || s.slice.openEnd !== 1 || s.slice.content.size !== 2)
606
+ const i = e.steps[a], c = new Ie(e.mapping.maps.slice(0, a)).invert();
607
+ if (i.structure) {
608
+ if (i instanceof _) {
609
+ if (i.to !== i.from + 1 || i.slice.openStart !== 0 || i.slice.openEnd !== 1 || i.slice.content.size !== 2)
606
610
  throw new Error(
607
611
  "Structure change is not in expected format (ReplaceStep)"
608
612
  );
609
- } else if (s instanceof St) {
610
- if (s.insert !== 1 || s.slice.size !== 2 || s.gapTo !== s.to - 1 || s.gapFrom !== s.from + 1)
613
+ } else if (i instanceof St) {
614
+ if (i.insert !== 1 || i.slice.size !== 2 || i.gapTo !== i.to - 1 || i.gapFrom !== i.from + 1)
611
615
  throw new Error(
612
616
  "Structure change is not in expected format (ReplaceAroundStep)"
613
617
  );
614
618
  } else
615
619
  throw new Error("Step is not a ReplaceStep or ReplaceAroundStep");
616
- const b = c.map(s.from), g = s.slice.content.firstChild, k = n.doc.resolve(n.mapping.map(b)).nodeAfter;
620
+ const b = c.map(i.from), g = i.slice.content.firstChild, k = n.doc.resolve(n.mapping.map(b)).nodeAfter;
617
621
  let w = g.marks || [];
618
622
  g.type !== k.type && (w = o.create({
619
623
  type: "nodeType",
620
624
  previousValue: k.type.name,
621
625
  newValue: g.type.name
622
626
  }).addToSet(w));
623
- const A = /* @__PURE__ */ new Set([
627
+ const j = /* @__PURE__ */ new Set([
624
628
  ...Object.keys(g.attrs),
625
629
  ...Object.keys(k.attrs)
626
630
  ]);
627
- for (const P of A)
631
+ for (const P of j)
628
632
  g.attrs[P] !== k.attrs[P] && (w = o.create({
629
633
  type: "attr",
630
634
  attrName: P,
@@ -644,10 +648,10 @@ function $(e) {
644
648
  });
645
649
  continue;
646
650
  }
647
- if (!(s instanceof L))
651
+ if (!(i instanceof _))
648
652
  throw new Error("Step is not a ReplaceStep");
649
- const u = c.map(s.from), m = c.map(s.to);
650
- if (s.slice.openStart > 0 || s.slice.openEnd > 0)
653
+ const u = c.map(i.from), f = c.map(i.to);
654
+ if (i.slice.openStart > 0 || i.slice.openEnd > 0)
651
655
  throw new Error(
652
656
  "Slice has openStart or openEnd > 0, but structure=false"
653
657
  );
@@ -655,32 +659,32 @@ function $(e) {
655
659
  prosemirrorSteps: [],
656
660
  selection: {
657
661
  anchor: n.mapping.map(u),
658
- head: n.mapping.map(m)
662
+ head: n.mapping.map(f)
659
663
  },
660
664
  type: "select"
661
665
  });
662
- const l = s.slice.content.textBetween(0, s.slice.size), f = l === n.doc.textBetween(n.mapping.map(u), n.mapping.map(m));
663
- let p;
664
- if (f)
665
- p = s.slice.content.size;
666
+ const l = i.slice.content.textBetween(0, i.slice.size), p = l === n.doc.textBetween(n.mapping.map(u), n.mapping.map(f));
667
+ let m;
668
+ if (p)
669
+ m = i.slice.content.size;
666
670
  else if (l.length === 0)
667
- p = s.slice.content.size;
671
+ m = i.slice.content.size;
668
672
  else {
669
- const b = Vt(s.slice.content);
673
+ const b = Vt(i.slice.content);
670
674
  if (b === void 0)
671
675
  throw new Error("unexpected: no first character found");
672
- p = b + 1;
676
+ m = b + 1;
673
677
  }
674
- let h = n.mapping.map(m);
675
- const d = n.mapping.map(m);
678
+ let h = n.mapping.map(f);
679
+ const d = n.mapping.map(f);
676
680
  let S = !0;
677
- for (let b = p; b <= s.slice.content.size; b++) {
678
- const g = S && u !== m, k = n.steps.length;
681
+ for (let b = m; b <= i.slice.content.size; b++) {
682
+ const g = S && u !== f, k = n.steps.length;
679
683
  if (g) {
680
684
  const M = n.doc.resolve(n.mapping.map(u));
681
- (i = M.nodeAfter) != null && i.isBlock && n.addNodeMark(M.pos, t.mark("deletion", {})), n.addMark(M.pos, h, t.mark("deletion", {})), h = n.mapping.map(m);
685
+ (s = M.nodeAfter) != null && s.isBlock && n.addNodeMark(M.pos, t.mark("deletion", {})), n.addMark(M.pos, h, t.mark("deletion", {})), h = n.mapping.map(f);
682
686
  }
683
- const w = new Y(s.slice.content.cut(0, b), 0, 0);
687
+ const w = new Y(i.slice.content.cut(0, b), 0, 0);
684
688
  n.replace(d, h, w).addMark(
685
689
  d,
686
690
  d + w.content.size,
@@ -690,15 +694,15 @@ function $(e) {
690
694
  d + w.content.size,
691
695
  (M, P) => P < d || P > d + w.content.size ? !0 : (M.isBlock && n.addNodeMark(P, t.mark("insertion", {})), !1)
692
696
  ), h = n.mapping.slice(k).map(h);
693
- const A = gt.near(
697
+ const j = gt.near(
694
698
  n.doc.resolve(d + w.content.size),
695
699
  -1
696
700
  );
697
701
  r.push({
698
702
  prosemirrorSteps: n.steps.slice(k),
699
703
  selection: {
700
- anchor: A.from,
701
- head: A.from
704
+ anchor: j.from,
705
+ head: j.from
702
706
  },
703
707
  type: g ? "replace" : "insert"
704
708
  // 3. Insert the replacement character by character
@@ -731,52 +735,52 @@ function ee(e, t) {
731
735
  return e;
732
736
  }
733
737
  function Zt(e, t, o) {
734
- const r = new N(t);
738
+ const r = new A(t);
735
739
  for (const a of e) {
736
- const s = new L(
740
+ const i = new _(
737
741
  r.mapping.map(a.fromA),
738
742
  r.mapping.map(a.toA),
739
743
  o.slice(a.fromB, a.toB)
740
744
  );
741
- r.step(s);
745
+ r.step(i);
742
746
  }
743
747
  const n = r.mapping.invert();
744
- let i = r.doc.content.findDiffStart(o.content);
745
- for (; i !== null; ) {
746
- const a = o.resolve(i).nodeAfter, s = r.doc.resolve(i).nodeAfter;
747
- if (!a || !s)
748
+ let s = r.doc.content.findDiffStart(o.content);
749
+ for (; s !== null; ) {
750
+ const a = o.resolve(s).nodeAfter, i = r.doc.resolve(s).nodeAfter;
751
+ if (!a || !i)
748
752
  throw new Error("diffNode not found");
749
- const c = !a.isLeaf && a.content.eq(s.content), u = c ? 1 : Math.min(a.nodeSize, s.nodeSize), m = i + u, l = n.map(i), f = n.map(m);
750
- let p = e.length;
753
+ const c = !a.isLeaf && a.content.eq(i.content), u = c ? 1 : Math.min(a.nodeSize, i.nodeSize), f = s + u, l = n.map(s), p = n.map(f);
754
+ let m = e.length;
751
755
  for (let d = 0; d < e.length; d++)
752
- if (e[d].fromA >= f) {
753
- p = d;
756
+ if (e[d].fromA >= p) {
757
+ m = d;
754
758
  break;
755
759
  }
756
- e.splice(p, 0, {
760
+ e.splice(m, 0, {
757
761
  fromA: l,
758
- toA: f,
759
- fromB: i,
760
- toB: m,
762
+ toA: p,
763
+ fromB: s,
764
+ toB: f,
761
765
  deleted: [],
762
766
  inserted: [],
763
767
  type: c ? "node-type-or-attr-update" : "mark-update"
764
768
  }), r.step(
765
- new L(
766
- i,
767
- m,
768
- o.slice(i, m),
769
+ new _(
770
+ s,
771
+ f,
772
+ o.slice(s, f),
769
773
  c
770
774
  )
771
775
  );
772
776
  const h = r.doc.content.findDiffStart(o.content);
773
- if (h === i)
777
+ if (h === s)
774
778
  throw new Error("diffStart not moving");
775
- i = h;
779
+ s = h;
776
780
  }
777
781
  return e;
778
782
  }
779
- const me = (e, t) => {
783
+ const fe = (e, t) => {
780
784
  const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
781
785
  e.descendants((a) => {
782
786
  a.type.name === "tableCell" && o.add(JSON.stringify(a.toJSON()));
@@ -790,90 +794,90 @@ const me = (e, t) => {
790
794
  encodeCharacter: (a) => a,
791
795
  encodeNodeStart: (a) => {
792
796
  if (a.type.name === "tableCell") {
793
- const s = JSON.stringify(a.toJSON());
794
- return n.has(s) ? s : a.type.name;
797
+ const i = JSON.stringify(a.toJSON());
798
+ return n.has(i) ? i : a.type.name;
795
799
  }
796
800
  return a.type.name;
797
801
  },
798
802
  encodeNodeEnd: (a) => {
799
803
  if (a.type.name === "tableCell") {
800
- const s = JSON.stringify(a.toJSON());
801
- return n.has(s) ? s : -1;
804
+ const i = JSON.stringify(a.toJSON());
805
+ return n.has(i) ? i : -1;
802
806
  }
803
807
  return -1;
804
808
  },
805
- compareTokens: (a, s) => a === s
809
+ compareTokens: (a, i) => a === i
806
810
  };
807
811
  };
808
812
  function J(e, t, o = !1, r, n) {
809
- const i = rt(e.id, t), a = new N(t);
813
+ const s = rt(e.id, t), a = new A(t);
810
814
  nt(
811
815
  a,
812
- i.posBeforeNode,
816
+ s.posBeforeNode,
813
817
  e.block,
814
818
  r,
815
819
  n
816
820
  );
817
- let s = a.doc, c = ce.create(
821
+ let i = a.doc, c = ce.create(
818
822
  t,
819
823
  void 0,
820
- me(t, s)
824
+ fe(t, i)
821
825
  );
822
- if (c = c.addSteps(s, a.mapping.maps, 0), o && c.changes.length > 0) {
823
- const l = c.changes[c.changes.length - 1], f = l.toA - l.fromA, p = l.toB - l.fromB;
824
- if (f > p) {
826
+ if (c = c.addSteps(i, a.mapping.maps, 0), o && c.changes.length > 0) {
827
+ const l = c.changes[c.changes.length - 1], p = l.toA - l.fromA, m = l.toB - l.fromB;
828
+ if (p > m) {
825
829
  const h = t.slice(
826
- l.fromA + p,
830
+ l.fromA + m,
827
831
  l.toA
828
832
  );
829
833
  a.step(
830
- new L(l.toB, l.toB, h)
831
- ), s = a.doc, c = ce.create(
834
+ new _(l.toB, l.toB, h)
835
+ ), i = a.doc, c = ce.create(
832
836
  c.startDoc,
833
837
  void 0,
834
- me(c.startDoc, s)
835
- ), c = c.addSteps(s, a.mapping.maps, 0);
838
+ fe(c.startDoc, i)
839
+ ), c = c.addSteps(i, a.mapping.maps, 0);
836
840
  }
837
841
  }
838
- const u = [], m = wt(
842
+ const u = [], f = wt(
839
843
  c.changes,
840
- s
844
+ i
841
845
  );
842
- for (let l = 0; l < m.length; l++) {
843
- const f = m[l], p = s.slice(f.fromB, f.toB);
844
- if (p.openEnd === 1 && p.openStart === 0 && (f.type = "node-type-or-attr-update", p.size > 2)) {
846
+ for (let l = 0; l < f.length; l++) {
847
+ const p = f[l], m = i.slice(p.fromB, p.toB);
848
+ if (m.openEnd === 1 && m.openStart === 0 && (p.type = "node-type-or-attr-update", m.size > 2)) {
845
849
  const h = {
846
- fromA: f.fromA,
847
- toA: f.fromA + 1,
848
- fromB: f.fromB,
849
- toB: f.fromB + 1,
850
+ fromA: p.fromA,
851
+ toA: p.fromA + 1,
852
+ fromB: p.fromB,
853
+ toB: p.fromB + 1,
850
854
  deleted: [],
851
855
  inserted: [],
852
856
  type: "node-type-or-attr-update"
853
857
  }, d = {
854
- fromA: f.fromA + 1,
855
- toA: f.toA,
856
- fromB: f.fromB + 1,
857
- toB: f.toB,
858
+ fromA: p.fromA + 1,
859
+ toA: p.toA,
860
+ fromB: p.fromB + 1,
861
+ toB: p.toB,
858
862
  deleted: [],
859
863
  inserted: []
860
864
  };
861
- m.splice(l, 1, h, d), l++;
865
+ f.splice(l, 1, h, d), l++;
862
866
  }
863
867
  }
864
- Zt(m, t, s);
865
- for (let l = 0; l < m.length; l++) {
866
- const f = m[l], p = s.slice(f.fromB, f.toB);
867
- if (p.openEnd > 0 && p.size > 1)
868
+ Zt(f, t, i);
869
+ for (let l = 0; l < f.length; l++) {
870
+ const p = f[l], m = i.slice(p.fromB, p.toB);
871
+ if (m.openEnd > 0 && m.size > 1)
868
872
  throw new Error(
869
873
  "unexpected, openEnd > 0 and size > 1, this should have been split into two steps"
870
874
  );
871
- l === m.length - 1 && o && f.type === "mark-update" || u.push(
872
- new L(
873
- f.fromA,
874
- f.toA,
875
- p,
876
- f.type === "node-type-or-attr-update"
875
+ l === f.length - 1 && o && p.type === "mark-update" || u.push(
876
+ new _(
877
+ p.fromA,
878
+ p.toA,
879
+ m,
880
+ p.type === "node-type-or-attr-update"
877
881
  )
878
882
  );
879
883
  }
@@ -942,83 +946,83 @@ function te(e) {
942
946
  ok: !1,
943
947
  error: "referenceId and blocks are required"
944
948
  };
945
- let i = n.referenceId;
949
+ let s = n.referenceId;
946
950
  if (o.idsSuffixed) {
947
- if (!(i != null && i.endsWith("$")))
951
+ if (!(s != null && s.endsWith("$")))
948
952
  return {
949
953
  ok: !1,
950
954
  error: "referenceId must end with $"
951
955
  };
952
- i = i.slice(0, -1);
956
+ s = s.slice(0, -1);
953
957
  }
954
- if (!t.getBlock(i))
958
+ if (!t.getBlock(s))
955
959
  return {
956
960
  ok: !1,
957
961
  error: "referenceId not found"
958
962
  };
959
- const s = Wt(
963
+ const i = Wt(
960
964
  n.blocks,
961
965
  (c) => e.validateBlock(c, t)
962
966
  );
963
- return s.ok ? {
967
+ return i.ok ? {
964
968
  ok: !0,
965
969
  value: {
966
970
  type: n.type,
967
- referenceId: i,
971
+ referenceId: s,
968
972
  position: n.position,
969
- blocks: s.value
973
+ blocks: i.value
970
974
  }
971
- } : s;
975
+ } : i;
972
976
  },
973
977
  // Note: functionality mostly tested in jsontools.test.ts
974
978
  // would be nicer to add a direct unit test
975
979
  execute: async function* (n) {
976
- var s;
977
- let i = [];
980
+ var i;
981
+ let s = [];
978
982
  const a = {};
979
983
  for await (const c of n) {
980
- if (c.isUpdateToPreviousOperation || (i = []), c.operation.type !== "add") {
984
+ if (c.isUpdateToPreviousOperation || (s = []), c.operation.type !== "add") {
981
985
  yield c;
982
986
  continue;
983
987
  }
984
- const u = c.operation, m = await e.toJSONToolCall(t, {
988
+ const u = c.operation, f = await e.toJSONToolCall(t, {
985
989
  ...c,
986
990
  operation: u
987
991
  });
988
- if (m && !(c.isPossiblyPartial && X(
989
- m.blocks[m.blocks.length - 1]
992
+ if (f && !(c.isPossiblyPartial && X(
993
+ f.blocks[f.blocks.length - 1]
990
994
  ))) {
991
- for (let l = 0; l < m.blocks.length; l++) {
992
- const f = m.blocks[l], p = t.prosemirrorState.tr;
995
+ for (let l = 0; l < f.blocks.length; l++) {
996
+ const p = f.blocks[l], m = t.prosemirrorState.tr;
993
997
  let h = [];
994
- if (l < i.length) {
995
- const d = await e.rebaseTool(i[l], t), b = J(
998
+ if (l < s.length) {
999
+ const d = await e.rebaseTool(s[l], t), b = J(
996
1000
  {
997
- id: i[l],
998
- block: f
1001
+ id: s[l],
1002
+ block: p
999
1003
  },
1000
1004
  d.doc,
1001
1005
  !1
1002
1006
  ).map((g) => g.map(d.invertMap));
1003
1007
  for (const g of b)
1004
- p.step(g.map(p.mapping));
1005
- h = $(p), h = h.filter((g) => g.type !== "select");
1008
+ m.step(g.map(m.mapping));
1009
+ h = R(m), h = h.filter((g) => g.type !== "select");
1006
1010
  } else {
1007
1011
  const d = u.position === "after" ? a[u.referenceId] : void 0, S = st(
1008
- p,
1009
- [f],
1010
- l > 0 ? i[l - 1] : d || u.referenceId,
1012
+ m,
1013
+ [p],
1014
+ l > 0 ? s[l - 1] : d || u.referenceId,
1011
1015
  l > 0 ? "after" : u.position
1012
1016
  );
1013
- i.push(...S.map((b) => b.id)), h = $(p);
1017
+ s.push(...S.map((b) => b.id)), h = R(m);
1014
1018
  }
1015
1019
  h.find((d) => d.type === "replace");
1016
1020
  for (const d of h)
1017
1021
  o.withDelays && await Q(d), t.transact((S) => {
1018
1022
  ee(S, d);
1019
- }), (s = o.onBlockUpdate) == null || s.call(o, i[l]);
1023
+ }), (i = o.onBlockUpdate) == null || i.call(o, s[l]);
1020
1024
  }
1021
- c.isPossiblyPartial || u.position === "after" && (a[u.referenceId] = i[i.length - 1]);
1025
+ c.isPossiblyPartial || u.position === "after" && (a[u.referenceId] = s[s.length - 1]);
1022
1026
  }
1023
1027
  }
1024
1028
  }
@@ -1054,42 +1058,42 @@ function oe(e) {
1054
1058
  ok: !1,
1055
1059
  error: "id is required"
1056
1060
  };
1057
- let i = n.id;
1061
+ let s = n.id;
1058
1062
  if (o.idsSuffixed) {
1059
- if (!(i != null && i.endsWith("$")))
1063
+ if (!(s != null && s.endsWith("$")))
1060
1064
  return {
1061
1065
  ok: !1,
1062
1066
  error: "id must end with $"
1063
1067
  };
1064
- i = i.slice(0, -1);
1068
+ s = s.slice(0, -1);
1065
1069
  }
1066
1070
  if (!n.block)
1067
1071
  return {
1068
1072
  ok: !1,
1069
1073
  error: "block is required"
1070
1074
  };
1071
- const a = t.getBlock(i);
1075
+ const a = t.getBlock(s);
1072
1076
  if (!a)
1073
- return console.error("BLOCK NOT FOUND", i), {
1077
+ return console.error("BLOCK NOT FOUND", s), {
1074
1078
  ok: !1,
1075
1079
  error: "block not found"
1076
1080
  };
1077
- const s = e.validateBlock(n.block, t, a.type);
1078
- return s.ok ? {
1081
+ const i = e.validateBlock(n.block, t, a.type);
1082
+ return i.ok ? {
1079
1083
  ok: !0,
1080
1084
  value: {
1081
1085
  type: n.type,
1082
- id: i,
1083
- block: s.value
1086
+ id: s,
1087
+ block: i.value
1084
1088
  }
1085
- } : s;
1089
+ } : i;
1086
1090
  },
1087
1091
  // Note: functionality mostly tested in jsontools.test.ts
1088
1092
  // would be nicer to add a direct unit test
1089
1093
  execute: async function* (n) {
1090
1094
  var c;
1091
1095
  let a = 50;
1092
- const s = o.updateSelection ? {
1096
+ const i = o.updateSelection ? {
1093
1097
  from: se(t, o.updateSelection.from),
1094
1098
  to: se(t, o.updateSelection.to)
1095
1099
  } : void 0;
@@ -1098,34 +1102,34 @@ function oe(e) {
1098
1102
  yield u;
1099
1103
  continue;
1100
1104
  }
1101
- const m = u.operation;
1105
+ const f = u.operation;
1102
1106
  if (u.isPossiblyPartial) {
1103
- const k = JSON.stringify(m.block).length;
1107
+ const k = JSON.stringify(f.block).length;
1104
1108
  if (k < a)
1105
1109
  continue;
1106
1110
  a = k + 50;
1107
1111
  } else
1108
1112
  a = 50;
1109
- const l = await e.rebaseTool(m.id, t), f = s ? l.invertMap.invert().map(s.from()) : void 0, p = s ? l.invertMap.invert().map(s.to()) : void 0, h = await e.toJSONToolCall(t, u);
1113
+ const l = await e.rebaseTool(f.id, t), p = i ? l.invertMap.invert().map(i.from()) : void 0, m = i ? l.invertMap.invert().map(i.to()) : void 0, h = await e.toJSONToolCall(t, u);
1110
1114
  if (!h)
1111
1115
  continue;
1112
1116
  const d = J(
1113
1117
  h,
1114
1118
  l.doc,
1115
1119
  u.isPossiblyPartial,
1116
- f,
1117
- p
1120
+ p,
1121
+ m
1118
1122
  );
1119
1123
  if (d.length === 1 && u.isPossiblyPartial)
1120
1124
  continue;
1121
- const S = d.map((k) => k.map(l.invertMap)), b = new N(t.prosemirrorState.doc);
1125
+ const S = d.map((k) => k.map(l.invertMap)), b = new A(t.prosemirrorState.doc);
1122
1126
  for (const k of S)
1123
1127
  b.step(k.map(b.mapping));
1124
- const g = $(b);
1128
+ const g = R(b);
1125
1129
  for (const k of g)
1126
1130
  o.withDelays && await Q(k), t.transact((w) => {
1127
1131
  ee(w, k);
1128
- }), (c = o.onBlockUpdate) == null || c.call(o, m.id);
1132
+ }), (c = o.onBlockUpdate) == null || c.call(o, f.id);
1129
1133
  }
1130
1134
  }
1131
1135
  };
@@ -1184,17 +1188,17 @@ const re = (e, t) => ({
1184
1188
  yield n;
1185
1189
  continue;
1186
1190
  }
1187
- const i = n.operation, a = e.prosemirrorState.tr;
1188
- it(a, [i.id], []);
1189
- const s = $(a);
1190
- for (const c of s)
1191
+ const s = n.operation, a = e.prosemirrorState.tr;
1192
+ it(a, [s.id], []);
1193
+ const i = R(a);
1194
+ for (const c of i)
1191
1195
  t.withDelays && await Q(c), e.transact((u) => {
1192
1196
  ee(u, c);
1193
- }), (r = t.onBlockUpdate) == null || r.call(t, i.id);
1197
+ }), (r = t.onBlockUpdate) == null || r.call(t, s.id);
1194
1198
  }
1195
1199
  }
1196
1200
  });
1197
- function fe(e) {
1201
+ function pe(e) {
1198
1202
  const t = e.lastIndexOf("<"), o = e.lastIndexOf(">");
1199
1203
  let r = e;
1200
1204
  if (t > o && (r = e.substring(0, t), !r.trim()))
@@ -1204,13 +1208,13 @@ function fe(e) {
1204
1208
  0,
1205
1209
  r.length - n[0].length
1206
1210
  ));
1207
- const s = new DOMParser().parseFromString(
1211
+ const i = new DOMParser().parseFromString(
1208
1212
  `<div>${r}</div>`,
1209
1213
  "text/html"
1210
1214
  ).body.firstChild;
1211
- return s ? s.innerHTML : "";
1215
+ return i ? i.innerHTML : "";
1212
1216
  }
1213
- function R(e) {
1217
+ function H(e) {
1214
1218
  let t;
1215
1219
  if (Be(e.prosemirrorState, (o) => {
1216
1220
  t = o;
@@ -1218,7 +1222,7 @@ function R(e) {
1218
1222
  throw new Error("applySuggestionsTr is not set");
1219
1223
  return t;
1220
1224
  }
1221
- function H(e, t) {
1225
+ function q(e, t) {
1222
1226
  const o = t.mapping.invert();
1223
1227
  return {
1224
1228
  doc: t.doc,
@@ -1226,7 +1230,7 @@ function H(e, t) {
1226
1230
  * Return a new transform that has the projection applied.
1227
1231
  * You can add new operations to this transform and later rebase those on the original document with `rebaseTr`
1228
1232
  */
1229
- tr: () => new N(t.doc),
1233
+ tr: () => new A(t.doc),
1230
1234
  /**
1231
1235
  * Invert map created by the projection.
1232
1236
  * You can use this to map positions on the "clean" document (the projection) to positions on the original document
@@ -1240,8 +1244,8 @@ function H(e, t) {
1240
1244
  if (r.steps.length === 0)
1241
1245
  throw new Error("No steps to apply");
1242
1246
  let n = e.prosemirrorState.tr;
1243
- for (const i of r.steps) {
1244
- const a = i.map(o);
1247
+ for (const s of r.steps) {
1248
+ const a = s.map(o);
1245
1249
  if (!a)
1246
1250
  throw new Error("Step is not mapped");
1247
1251
  n = n.step(a);
@@ -1252,7 +1256,7 @@ function H(e, t) {
1252
1256
  }
1253
1257
  async function he(e, t) {
1254
1258
  var u;
1255
- const o = R(t), r = Oe(o.doc, e);
1259
+ const o = H(t), r = Oe(o.doc, e);
1256
1260
  if (!r)
1257
1261
  throw new Error("block not found");
1258
1262
  const n = await t.blocksToHTMLLossy([
@@ -1260,19 +1264,19 @@ async function he(e, t) {
1260
1264
  ...r,
1261
1265
  children: []
1262
1266
  }
1263
- ]), i = (u = window.__TEST_OPTIONS) == null ? void 0 : u.mockID, a = await t.tryParseHTMLToBlocks(n);
1264
- if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = i), a.length !== 1)
1267
+ ]), s = (u = window.__TEST_OPTIONS) == null ? void 0 : u.mockID, a = await t.tryParseHTMLToBlocks(n);
1268
+ if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = s), a.length !== 1)
1265
1269
  throw new Error("html diff invalid block count");
1266
- const s = a[0];
1267
- if (s.id = e, J(
1270
+ const i = a[0];
1271
+ if (i.id = e, J(
1268
1272
  {
1269
1273
  id: e,
1270
- block: s
1274
+ block: i
1271
1275
  },
1272
1276
  o.doc
1273
1277
  ).length)
1274
1278
  throw new Error("html diff");
1275
- return H(t, o);
1279
+ return q(t, o);
1276
1280
  }
1277
1281
  function ye(e) {
1278
1282
  return typeof e != "string" ? {
@@ -1302,10 +1306,10 @@ const V = {
1302
1306
  toJSONToolCall: async (e, t) => {
1303
1307
  var n;
1304
1308
  const o = (n = window.__TEST_OPTIONS) == null ? void 0 : n.mockID, r = (await Promise.all(
1305
- t.operation.blocks.map(async (i) => {
1306
- const a = t.isPossiblyPartial ? fe(i) : i;
1309
+ t.operation.blocks.map(async (s) => {
1310
+ const a = t.isPossiblyPartial ? pe(s) : s;
1307
1311
  return a ? (await e.tryParseHTMLToBlocks(a)).map(
1308
- (s) => (delete s.id, s)
1312
+ (i) => (delete i.id, i)
1309
1313
  ) : [];
1310
1314
  })
1311
1315
  )).flat();
@@ -1332,7 +1336,7 @@ const V = {
1332
1336
  validateBlock: ye,
1333
1337
  rebaseTool: he,
1334
1338
  toJSONToolCall: async (e, t) => {
1335
- const o = t.isPossiblyPartial ? fe(t.operation.block) : t.operation.block;
1339
+ const o = t.isPossiblyPartial ? pe(t.operation.block) : t.operation.block;
1336
1340
  if (!o)
1337
1341
  return;
1338
1342
  const r = (await e.tryParseHTMLToBlocks(o))[0];
@@ -1345,14 +1349,14 @@ const V = {
1345
1349
  delete: re
1346
1350
  };
1347
1351
  function Yt(e, t, o, r, n) {
1348
- const i = {
1352
+ const s = {
1349
1353
  add: !0,
1350
1354
  update: !0,
1351
1355
  delete: !0,
1352
1356
  ...o
1353
1357
  };
1354
1358
  return [
1355
- ...i.update ? [
1359
+ ...s.update ? [
1356
1360
  V.update(e, {
1357
1361
  idsSuffixed: !0,
1358
1362
  withDelays: t,
@@ -1360,8 +1364,8 @@ function Yt(e, t, o, r, n) {
1360
1364
  onBlockUpdate: n
1361
1365
  })
1362
1366
  ] : [],
1363
- ...i.add ? [V.add(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : [],
1364
- ...i.delete ? [V.delete(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : []
1367
+ ...s.add ? [V.add(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : [],
1368
+ ...s.delete ? [V.delete(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : []
1365
1369
  ];
1366
1370
  }
1367
1371
  const Ue = {
@@ -1387,12 +1391,12 @@ async function Gt(e, t) {
1387
1391
  userPrompt: o,
1388
1392
  useSelection: r,
1389
1393
  deleteEmptyCursorBlock: n,
1390
- stream: i,
1394
+ stream: s,
1391
1395
  onStart: a,
1392
- withDelays: s,
1396
+ withDelays: i,
1393
1397
  dataFormat: c,
1394
1398
  previousResponse: u,
1395
- ...m
1399
+ ...f
1396
1400
  } = {
1397
1401
  maxRetries: 2,
1398
1402
  deleteEmptyCursorBlock: !0,
@@ -1400,14 +1404,15 @@ async function Gt(e, t) {
1400
1404
  withDelays: !0,
1401
1405
  dataFormat: Ue,
1402
1406
  ...t
1403
- }, l = t.promptBuilder ?? c.defaultPromptBuilder, f = c.getStreamTools, p = r ? void 0 : e.getTextCursorPosition().block, h = p && n && X(p) && e.document.length > 1 ? p.id : void 0, d = r ? e.getSelectionCutBlocks() : void 0;
1407
+ }, l = t.promptBuilder ?? c.defaultPromptBuilder, p = c.getStreamTools, m = r ? void 0 : e.getTextCursorPosition().block, h = m && n && X(m) && x(e.document).length > 0 ? m.id : void 0, d = r ? e.getSelectionCutBlocks() : void 0;
1404
1408
  let S;
1405
1409
  u && (S = u.messages.map((w) => w.role === "user" && typeof w.content == "string" ? {
1406
1410
  role: "system",
1407
1411
  content: `USER_MESSAGE: ${w.content}`
1408
1412
  } : w), S.push({
1409
- role: "assistant",
1410
- content: `These are the operations returned by a previous LLM call:
1413
+ role: "system",
1414
+ // using "assistant" here doesn't work with gemini because we can't mix system / assistant messages
1415
+ content: `ASSISTANT_MESSAGE: These are the operations returned by a previous LLM call:
1411
1416
  ` + JSON.stringify(
1412
1417
  await u.llmResult.getGeneratedOperations()
1413
1418
  )
@@ -1417,40 +1422,42 @@ async function Gt(e, t) {
1417
1422
  userPrompt: o,
1418
1423
  excludeBlockIds: h ? [h] : void 0,
1419
1424
  previousMessages: S
1420
- }), g = f(
1425
+ }), g = p(
1421
1426
  e,
1422
- s,
1427
+ i,
1423
1428
  t.defaultStreamTools,
1424
1429
  d ? { from: d._meta.startPos, to: d._meta.endPos } : void 0,
1425
1430
  t.onBlockUpdate
1426
1431
  );
1427
1432
  let k;
1428
- return i ? k = await Dt(
1433
+ return s ? k = await $t(
1429
1434
  g,
1430
1435
  {
1431
1436
  messages: b,
1432
- ...m
1437
+ ...f
1433
1438
  },
1434
1439
  () => {
1435
1440
  h && e.removeBlocks([h]), a == null || a();
1436
1441
  }
1437
1442
  ) : (k = await At(g, {
1438
1443
  messages: b,
1439
- ...m
1444
+ ...f
1440
1445
  }), h && e.removeBlocks([h]), a == null || a()), new qt(b, k, g);
1441
1446
  }
1442
1447
  async function ze(e, t) {
1443
- const o = F(e.document), r = await C(
1444
- T(o),
1445
- async (s) => ({
1446
- ...s,
1448
+ const o = e.getTextCursorPosition().block.id, r = x(e.document, {
1449
+ cursorBlockId: o
1450
+ }), n = await C(
1451
+ T(r),
1452
+ async (c) => ({
1453
+ ...c,
1447
1454
  children: void 0
1448
1455
  })
1449
- ), i = z(e, r).filter(
1450
- (s) => "cursor" in s || !(t.excludeBlockIds || []).includes(s.id)
1456
+ ), a = F(e, n).filter(
1457
+ (c) => "cursor" in c || !(t.excludeBlockIds || []).includes(c.id)
1451
1458
  );
1452
1459
  return {
1453
- jsonBlocks: x(i)
1460
+ jsonBlocks: L(a)
1454
1461
  };
1455
1462
  }
1456
1463
  async function Fe(e, t) {
@@ -1459,7 +1466,7 @@ async function Fe(e, t) {
1459
1466
  async (n) => n
1460
1467
  );
1461
1468
  return {
1462
- jsonSelectedBlocks: x(o),
1469
+ jsonSelectedBlocks: L(o),
1463
1470
  jsonDocument: (await C(T(e.document), async (n) => ({
1464
1471
  ...n,
1465
1472
  id: void 0,
@@ -1558,37 +1565,37 @@ function Xt(e) {
1558
1565
  ];
1559
1566
  }
1560
1567
  const Qt = async (e, t) => {
1568
+ const o = x(e.document).length === 0;
1561
1569
  if (t.selectedBlocks) {
1562
- const o = await Fe(e, {
1570
+ const r = await Fe(e, {
1563
1571
  selectedBlocks: t.selectedBlocks
1564
1572
  });
1565
1573
  return Kt({
1566
- ...o,
1567
- userPrompt: t.userPrompt,
1568
- isEmptyDocument: e.isEmpty
1574
+ ...r,
1575
+ userPrompt: t.userPrompt
1569
1576
  });
1570
1577
  } else {
1571
- const o = await ze(e, t);
1578
+ const r = await ze(e, t);
1572
1579
  return Xt({
1573
- ...o,
1580
+ ...r,
1574
1581
  userPrompt: t.userPrompt,
1575
- isEmptyDocument: e.isEmpty
1582
+ isEmptyDocument: o
1576
1583
  });
1577
1584
  }
1578
1585
  };
1579
1586
  function eo(e) {
1580
1587
  const t = {}, o = {};
1581
1588
  return e.forEach((n) => {
1582
- const { type: i, ...a } = n.properties, s = JSON.stringify(a);
1583
- t[s] ? t[s].push(i.enum[0]) : (t[s] = [i.enum[0]], o[s] = n);
1589
+ const { type: s, ...a } = n.properties, i = JSON.stringify(a);
1590
+ t[i] ? t[i].push(s.enum[0]) : (t[i] = [s.enum[0]], o[i] = n);
1584
1591
  }), Object.keys(
1585
1592
  t
1586
1593
  ).map((n) => {
1587
- const i = o[n];
1594
+ const s = o[n];
1588
1595
  return {
1589
- ...i,
1596
+ ...s,
1590
1597
  properties: {
1591
- ...i.properties,
1598
+ ...s.properties,
1592
1599
  type: {
1593
1600
  type: "string",
1594
1601
  enum: t[n]
@@ -1798,7 +1805,7 @@ function ke(e, t, o) {
1798
1805
  ok: !0,
1799
1806
  value: e
1800
1807
  };
1801
- if (!e.content.every((i) => Ve(i, t)))
1808
+ if (!e.content.every((s) => Ve(s, t)))
1802
1809
  return {
1803
1810
  ok: !1,
1804
1811
  error: "block content must be an array of inline content"
@@ -1819,7 +1826,7 @@ const Z = {
1819
1826
  ...ge(e.schema)
1820
1827
  }),
1821
1828
  validateBlock: ke,
1822
- rebaseTool: async (e, t) => H(t, R(t)),
1829
+ rebaseTool: async (e, t) => q(t, H(t)),
1823
1830
  toJSONToolCall: async (e, t) => t.operation
1824
1831
  }),
1825
1832
  update: oe({
@@ -1831,7 +1838,7 @@ const Z = {
1831
1838
  ...ge(e.schema)
1832
1839
  }),
1833
1840
  validateBlock: ke,
1834
- rebaseTool: async (e, t) => H(t, R(t)),
1841
+ rebaseTool: async (e, t) => q(t, H(t)),
1835
1842
  toJSONToolCall: async (e, t) => {
1836
1843
  const o = Object.fromEntries(
1837
1844
  Object.entries(Me).map(([r, n]) => [r, n.default])
@@ -1888,14 +1895,16 @@ const ao = {
1888
1895
  }
1889
1896
  };
1890
1897
  async function Ze(e, t) {
1891
- const o = F(e.document), r = await C(
1892
- T(o),
1893
- async (s) => e.blocksToMarkdownLossy([s])
1894
- ), i = z(e, r).filter(
1895
- (s) => "cursor" in s || !(t.excludeBlockIds || []).includes(s.id)
1898
+ const o = e.getTextCursorPosition().block.id, r = x(e.document, {
1899
+ cursorBlockId: o
1900
+ }), n = await C(
1901
+ T(r),
1902
+ async (c) => e.blocksToMarkdownLossy([c])
1903
+ ), a = F(e, n).filter(
1904
+ (c) => "cursor" in c || !(t.excludeBlockIds || []).includes(c.id)
1896
1905
  );
1897
1906
  return {
1898
- markdownBlocks: x(i)
1907
+ markdownBlocks: L(a)
1899
1908
  };
1900
1909
  }
1901
1910
  async function We(e, t) {
@@ -1904,7 +1913,7 @@ async function We(e, t) {
1904
1913
  async (n) => e.blocksToMarkdownLossy([n])
1905
1914
  );
1906
1915
  return {
1907
- markdownSelectedBlocks: x(o),
1916
+ markdownSelectedBlocks: L(o),
1908
1917
  markdownDocument: (await C(T(e.document), async (n) => e.blocksToMarkdownLossy([n]))).map(({ block: n }) => ({ block: n }))
1909
1918
  // strip ids so LLM can't accidentally issue updates to ids not in selection
1910
1919
  };
@@ -1983,20 +1992,20 @@ const uo = async (e, t) => {
1983
1992
  }
1984
1993
  };
1985
1994
  async function be(e, t) {
1986
- const o = R(t), r = await t.blocksToMarkdownLossy([Oe(o.doc, e)]), n = await t.tryParseMarkdownToBlocks(r), i = J(
1995
+ const o = H(t), r = await t.blocksToMarkdownLossy([Oe(o.doc, e)]), n = await t.tryParseMarkdownToBlocks(r), s = J(
1987
1996
  {
1988
1997
  id: e,
1989
1998
  block: n[0]
1990
1999
  },
1991
2000
  o.doc
1992
- ), a = new Ee();
1993
- for (const s of i) {
1994
- const c = s.map(a);
2001
+ ), a = new Ie();
2002
+ for (const i of s) {
2003
+ const c = i.map(a);
1995
2004
  if (!c)
1996
2005
  throw new Error("Failed to map step");
1997
2006
  o.step(c), a.appendMap(c.getMap());
1998
2007
  }
1999
- return H(t, o);
2008
+ return q(t, o);
2000
2009
  }
2001
2010
  function Se(e) {
2002
2011
  return typeof e != "string" ? {
@@ -2055,7 +2064,7 @@ const W = {
2055
2064
  }),
2056
2065
  delete: re
2057
2066
  };
2058
- function po(e, t, o, r) {
2067
+ function mo(e, t, o, r) {
2059
2068
  const n = {
2060
2069
  add: !0,
2061
2070
  update: !0,
@@ -2074,11 +2083,11 @@ function po(e, t, o, r) {
2074
2083
  ...n.delete ? [W.delete(e, { idsSuffixed: !0, withDelays: t })] : []
2075
2084
  ];
2076
2085
  }
2077
- const mo = {
2086
+ const fo = {
2078
2087
  /**
2079
2088
  * Function to get the stream tools that can apply BlockNote Markdown block updates to the editor
2080
2089
  */
2081
- getStreamTools: po,
2090
+ getStreamTools: mo,
2082
2091
  /**
2083
2092
  * The default PromptBuilder that determines how a userPrompt is converted to an array of
2084
2093
  * LLM Messages (CoreMessage[])
@@ -2092,14 +2101,14 @@ const mo = {
2092
2101
  getDataForPromptWithSelection: We
2093
2102
  }
2094
2103
  }, ir = {
2095
- addCursorPosition: z,
2104
+ addCursorPosition: F,
2096
2105
  flattenBlocks: T,
2097
- suffixIDs: x,
2098
- trimEmptyBlocks: F,
2106
+ suffixIDs: L,
2107
+ trimEmptyBlocks: x,
2099
2108
  convertBlocks: C
2100
- }, fo = {
2109
+ }, po = {
2101
2110
  _experimental_json: ao,
2102
- _experimental_markdown: mo,
2111
+ _experimental_markdown: fo,
2103
2112
  html: Ue
2104
2113
  }, we = new _e("blocknote-agent-cursor");
2105
2114
  function ho(e) {
@@ -2130,9 +2139,9 @@ function ho(e) {
2130
2139
  side: 10
2131
2140
  })
2132
2141
  );
2133
- const i = Math.min(r.anchor, r.head), a = Math.max(r.anchor, r.head);
2142
+ const s = Math.min(r.anchor, r.head), a = Math.max(r.anchor, r.head);
2134
2143
  return n.push(
2135
- ue.inline(i, a, Tt(e), {
2144
+ ue.inline(s, a, Tt(e), {
2136
2145
  inclusiveEnd: !0,
2137
2146
  inclusiveStart: !1
2138
2147
  })
@@ -2155,18 +2164,18 @@ class Ye extends lt {
2155
2164
  */
2156
2165
  constructor(o, r) {
2157
2166
  super();
2158
- j(this, "previousRequestOptions");
2167
+ $(this, "previousRequestOptions");
2159
2168
  // internal store including setters
2160
- j(this, "_store", pe()((o) => ({
2169
+ $(this, "_store", me()((o) => ({
2161
2170
  aiMenuState: "closed"
2162
2171
  })));
2163
2172
  /**
2164
2173
  * Returns a zustand store with the global configuration of the AI Extension.
2165
2174
  * These options are used by default across all LLM calls when calling {@link doLLMRequest}
2166
2175
  */
2167
- j(this, "options");
2168
- this.editor = o, this.options = pe()((n) => ({
2169
- dataFormat: fo.html,
2176
+ $(this, "options");
2177
+ this.editor = o, this.options = me()((n) => ({
2178
+ dataFormat: po.html,
2170
2179
  stream: !0,
2171
2180
  ...r
2172
2181
  })), this.addProsemirrorPlugin(
@@ -2174,11 +2183,11 @@ class Ye extends lt {
2174
2183
  key: go,
2175
2184
  filterTransaction: (n) => {
2176
2185
  var a;
2177
- const i = this.store.getState().aiMenuState;
2178
- return !(i !== "closed" && i.status === "ai-writing" && (a = n.getMeta(kt)) != null && a.fixTables);
2186
+ const s = this.store.getState().aiMenuState;
2187
+ return !(s !== "closed" && s.status === "ai-writing" && (a = n.getMeta(kt)) != null && a.fixTables);
2179
2188
  }
2180
2189
  })
2181
- ), this.addProsemirrorPlugin(pt()), this.addProsemirrorPlugin(
2190
+ ), this.addProsemirrorPlugin(mt()), this.addProsemirrorPlugin(
2182
2191
  ho(
2183
2192
  r.agentCursor || { name: "AI", color: "#8bc6ff" }
2184
2193
  )
@@ -2219,18 +2228,18 @@ class Ye extends lt {
2219
2228
  acceptChanges() {
2220
2229
  var r;
2221
2230
  const o = this.editor.prosemirrorState.doc;
2222
- this.editor.exec((n, i) => ie(n, (a) => {
2223
- i == null || i(a.setMeta("addToHistory", !1));
2224
- })), this.editor.exec((n, i) => {
2231
+ this.editor.exec((n, s) => ie(n, (a) => {
2232
+ s == null || s(a.setMeta("addToHistory", !1));
2233
+ })), this.editor.exec((n, s) => {
2225
2234
  const a = n.tr;
2226
2235
  a.replace(
2227
2236
  0,
2228
2237
  a.doc.content.size,
2229
2238
  new Y(ae.from(o), 0, 0)
2230
2239
  );
2231
- const s = n.apply(a);
2232
- return Be(s, (c) => {
2233
- i == null || i(
2240
+ const i = n.apply(a);
2241
+ return Be(i, (c) => {
2242
+ s == null || s(
2234
2243
  a.replace(
2235
2244
  0,
2236
2245
  a.doc.content.size,
@@ -2245,8 +2254,8 @@ class Ye extends lt {
2245
2254
  */
2246
2255
  rejectChanges() {
2247
2256
  var o;
2248
- this.editor.exec((r, n) => ie(r, (i) => {
2249
- n == null || n(i.setMeta("addToHistory", !1));
2257
+ this.editor.exec((r, n) => ie(r, (s) => {
2258
+ n == null || n(s.setMeta("addToHistory", !1));
2250
2259
  })), (o = this.editor.forkYDocPlugin) == null || o.merge({ keepChanges: !1 }), this.closeAIMenu();
2251
2260
  }
2252
2261
  /**
@@ -2304,34 +2313,34 @@ class Ye extends lt {
2304
2313
  this.setAIResponseStatus("thinking"), (n = this.editor.forkYDocPlugin) == null || n.fork();
2305
2314
  let r;
2306
2315
  try {
2307
- const i = {
2316
+ const s = {
2308
2317
  ...this.options.getState(),
2309
2318
  ...o,
2310
2319
  previousResponse: this.store.getState().llmResponse
2311
2320
  };
2312
- this.previousRequestOptions = i, r = await Gt(this.editor, {
2313
- ...i,
2321
+ this.previousRequestOptions = s, r = await Gt(this.editor, {
2322
+ ...s,
2314
2323
  onStart: () => {
2315
2324
  var a;
2316
2325
  this.setAIResponseStatus("ai-writing"), (a = o.onStart) == null || a.call(o);
2317
2326
  },
2318
2327
  onBlockUpdate: (a) => {
2319
- var s;
2328
+ var i;
2320
2329
  this._store.setState({
2321
2330
  aiMenuState: {
2322
2331
  blockId: a,
2323
2332
  status: "ai-writing"
2324
2333
  }
2325
- }), (s = o.onBlockUpdate) == null || s.call(o, a);
2334
+ }), (i = o.onBlockUpdate) == null || i.call(o, a);
2326
2335
  }
2327
2336
  }), this._store.setState({
2328
2337
  llmResponse: r
2329
2338
  }), await r.execute(), this.setAIResponseStatus("user-reviewing");
2330
- } catch (i) {
2339
+ } catch (s) {
2331
2340
  this.setAIResponseStatus({
2332
2341
  status: "error",
2333
- error: i
2334
- }), console.warn("Error calling LLM", i);
2342
+ error: s
2343
+ }), console.warn("Error calling LLM", s);
2335
2344
  }
2336
2345
  return r;
2337
2346
  }
@@ -2343,7 +2352,7 @@ function O(e) {
2343
2352
  return e.extension(Ye);
2344
2353
  }
2345
2354
  const ko = (e, t) => async (o, r) => {
2346
- const n = new Request(o, r), i = new Request(
2355
+ const n = new Request(o, r), s = new Request(
2347
2356
  `${e}?provider=${encodeURIComponent(
2348
2357
  t
2349
2358
  )}&url=${encodeURIComponent(n.url)}`,
@@ -2357,7 +2366,7 @@ const ko = (e, t) => async (o, r) => {
2357
2366
  }
2358
2367
  );
2359
2368
  try {
2360
- return await fetch(i);
2369
+ return await fetch(s);
2361
2370
  } catch (a) {
2362
2371
  throw new TypeError("fetch failed", {
2363
2372
  cause: a
@@ -2396,9 +2405,9 @@ function So(e, t) {
2396
2405
  if (e == null) return {};
2397
2406
  var o = wo(e, t), r, n;
2398
2407
  if (Object.getOwnPropertySymbols) {
2399
- var i = Object.getOwnPropertySymbols(e);
2400
- for (n = 0; n < i.length; n++)
2401
- r = i[n], !(t.indexOf(r) >= 0) && Object.prototype.propertyIsEnumerable.call(e, r) && (o[r] = e[r]);
2408
+ var s = Object.getOwnPropertySymbols(e);
2409
+ for (n = 0; n < s.length; n++)
2410
+ r = s[n], !(t.indexOf(r) >= 0) && Object.prototype.propertyIsEnumerable.call(e, r) && (o[r] = e[r]);
2402
2411
  }
2403
2412
  return o;
2404
2413
  }
@@ -2412,15 +2421,15 @@ function wo(e, t) {
2412
2421
  }
2413
2422
  return o;
2414
2423
  }
2415
- function q() {
2416
- return q = Object.assign ? Object.assign.bind() : function(e) {
2424
+ function U() {
2425
+ return U = Object.assign ? Object.assign.bind() : function(e) {
2417
2426
  for (var t = 1; t < arguments.length; t++) {
2418
2427
  var o = arguments[t];
2419
2428
  for (var r in o)
2420
2429
  Object.prototype.hasOwnProperty.call(o, r) && (e[r] = o[r]);
2421
2430
  }
2422
2431
  return e;
2423
- }, q.apply(this, arguments);
2432
+ }, U.apply(this, arguments);
2424
2433
  }
2425
2434
  function ve(e, t) {
2426
2435
  var o = Object.keys(e);
@@ -2432,7 +2441,7 @@ function ve(e, t) {
2432
2441
  }
2433
2442
  return o;
2434
2443
  }
2435
- function U(e) {
2444
+ function z(e) {
2436
2445
  for (var t = 1; t < arguments.length; t++) {
2437
2446
  var o = arguments[t] != null ? arguments[t] : {};
2438
2447
  t % 2 ? ve(Object(o), !0).forEach(function(r) {
@@ -2461,13 +2470,13 @@ function Co(e, t) {
2461
2470
  return (t === "string" ? String : Number)(e);
2462
2471
  }
2463
2472
  function Ke(e) {
2464
- return e && e.map((t, o) => /* @__PURE__ */ B.createElement(t.tag, U({
2473
+ return e && e.map((t, o) => /* @__PURE__ */ B.createElement(t.tag, z({
2465
2474
  key: o
2466
2475
  }, t.attr), Ke(t.child)));
2467
2476
  }
2468
2477
  function v(e) {
2469
- return (t) => /* @__PURE__ */ B.createElement(Po, q({
2470
- attr: U({}, e.attr)
2478
+ return (t) => /* @__PURE__ */ B.createElement(Po, U({
2479
+ attr: z({}, e.attr)
2471
2480
  }, t), Ke(e.child));
2472
2481
  }
2473
2482
  function Po(e) {
@@ -2475,21 +2484,21 @@ function Po(e) {
2475
2484
  var {
2476
2485
  attr: r,
2477
2486
  size: n,
2478
- title: i
2479
- } = e, a = So(e, bo), s = n || o.size || "1em", c;
2480
- return o.className && (c = o.className), e.className && (c = (c ? c + " " : "") + e.className), /* @__PURE__ */ B.createElement("svg", q({
2487
+ title: s
2488
+ } = e, a = So(e, bo), i = n || o.size || "1em", c;
2489
+ return o.className && (c = o.className), e.className && (c = (c ? c + " " : "") + e.className), /* @__PURE__ */ B.createElement("svg", U({
2481
2490
  stroke: "currentColor",
2482
2491
  fill: "currentColor",
2483
2492
  strokeWidth: "0"
2484
2493
  }, o.attr, r, a, {
2485
2494
  className: c,
2486
- style: U(U({
2495
+ style: z(z({
2487
2496
  color: e.color || o.color
2488
2497
  }, o.style), e.style),
2489
- height: s,
2490
- width: s,
2498
+ height: i,
2499
+ width: i,
2491
2500
  xmlns: "http://www.w3.org/2000/svg"
2492
- }), i && /* @__PURE__ */ B.createElement("title", null, i), e.children);
2501
+ }), s && /* @__PURE__ */ B.createElement("title", null, s), e.children);
2493
2502
  };
2494
2503
  return Te !== void 0 ? /* @__PURE__ */ B.createElement(Te.Consumer, null, (o) => t(o)) : t(Ge);
2495
2504
  }
@@ -2517,45 +2526,45 @@ function Lo(e) {
2517
2526
  function _o(e) {
2518
2527
  return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z" }, child: [] }] })(e);
2519
2528
  }
2520
- function Eo(e) {
2529
+ function Io(e) {
2521
2530
  return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z" }, child: [] }] })(e);
2522
2531
  }
2523
- function Io(e) {
2532
+ function Eo(e) {
2524
2533
  return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M12 4C9.4095 4 7.10606 5.23053 5.64274 7.14274L8 9.5H2V3.5L4.21863 5.71863C6.05061 3.452 8.85558 2 12 2 17.5228 2 22 6.47715 22 12H20C20 7.58172 16.4183 4 12 4ZM4 12C4 16.4183 7.58172 20 12 20 14.5905 20 16.894 18.7695 18.3573 16.8573L16 14.5 22 14.5V20.5L19.7814 18.2814C17.9494 20.548 15.1444 22 12 22 6.47715 22 2 17.5228 2 12H4Z" }, child: [] }] })(e);
2525
2534
  }
2526
2535
  function ne(e) {
2527
2536
  return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M17.0007 1.20825 18.3195 3.68108 20.7923 4.99992 18.3195 6.31876 17.0007 8.79159 15.6818 6.31876 13.209 4.99992 15.6818 3.68108 17.0007 1.20825ZM8.00065 4.33325 10.6673 9.33325 15.6673 11.9999 10.6673 14.6666 8.00065 19.6666 5.33398 14.6666.333984 11.9999 5.33398 9.33325 8.00065 4.33325ZM19.6673 16.3333 18.0007 13.2083 16.334 16.3333 13.209 17.9999 16.334 19.6666 18.0007 22.7916 19.6673 19.6666 22.7923 17.9999 19.6673 16.3333Z" }, child: [] }] })(e);
2528
2537
  }
2529
- function _(e) {
2538
+ function I(e) {
2530
2539
  if (!e.dictionary.ai)
2531
2540
  throw new Error("AI dictionary not found");
2532
2541
  return e.dictionary.ai;
2533
2542
  }
2534
2543
  function Qe() {
2535
2544
  const e = Ct();
2536
- return _(e.editor);
2545
+ return I(e.editor);
2537
2546
  }
2538
2547
  const No = (e) => {
2539
- const t = G(), { onManualPromptSubmit: o, promptText: r, onPromptTextChange: n } = e, [i, a] = Ie(""), s = r || i, c = D(
2548
+ const t = G(), { onManualPromptSubmit: o, promptText: r, onPromptTextChange: n } = e, [s, a] = Ee(""), i = r || s, c = D(
2540
2549
  async (d) => {
2541
- d.key === "Enter" && o(s);
2550
+ d.key === "Enter" && o(i);
2542
2551
  },
2543
- [s, o]
2552
+ [i, o]
2544
2553
  ), u = D(
2545
2554
  (d) => {
2546
2555
  const S = d.currentTarget.value;
2547
2556
  n && n(S), r === void 0 && a(S);
2548
2557
  },
2549
2558
  [n, a, r]
2550
- ), m = E(() => ut(e.items, s), [s, e.items]), { selectedIndex: l, setSelectedIndex: f, handler: p } = Pt(m, (d) => d.onItemClick()), h = D(
2559
+ ), f = E(() => ut(e.items, i), [i, e.items]), { selectedIndex: l, setSelectedIndex: p, handler: m } = Pt(f, (d) => d.onItemClick()), h = D(
2551
2560
  (d) => {
2552
- d.key === "Enter" ? m.length > 0 ? p(d) : c(d) : p(d);
2561
+ d.key === "Enter" ? f.length > 0 ? m(d) : c(d) : m(d);
2553
2562
  },
2554
- [c, p, m.length]
2563
+ [c, m, f.length]
2555
2564
  );
2556
2565
  return Ne(() => {
2557
- f(0);
2558
- }, [s, f]), /* @__PURE__ */ vt("div", { className: "bn-combobox", children: [
2566
+ p(0);
2567
+ }, [i, p]), /* @__PURE__ */ vt("div", { className: "bn-combobox", children: [
2559
2568
  /* @__PURE__ */ y(t.Generic.Form.Root, { children: /* @__PURE__ */ y(
2560
2569
  t.Generic.Form.TextInput,
2561
2570
  {
@@ -2563,7 +2572,7 @@ const No = (e) => {
2563
2572
  name: "ai-prompt",
2564
2573
  variant: "large",
2565
2574
  icon: e.icon,
2566
- value: s || "",
2575
+ value: i || "",
2567
2576
  autoFocus: !0,
2568
2577
  placeholder: e.placeholder,
2569
2578
  disabled: e.disabled,
@@ -2579,7 +2588,7 @@ const No = (e) => {
2579
2588
  {
2580
2589
  className: "bn-combobox-items",
2581
2590
  id: "ai-suggestion-menu",
2582
- children: m.map((d, S) => /* @__PURE__ */ y(
2591
+ children: f.map((d, S) => /* @__PURE__ */ y(
2583
2592
  t.SuggestionMenu.Item,
2584
2593
  {
2585
2594
  className: dt(
@@ -2598,7 +2607,7 @@ const No = (e) => {
2598
2607
  ] });
2599
2608
  };
2600
2609
  function Ao(e) {
2601
- const t = _(e), o = O(e);
2610
+ const t = I(e), o = O(e);
2602
2611
  return [
2603
2612
  {
2604
2613
  key: "continue_writing",
@@ -2607,7 +2616,7 @@ function Ao(e) {
2607
2616
  icon: /* @__PURE__ */ y(Ce, { size: 18 }),
2608
2617
  onItemClick: async () => {
2609
2618
  await o.callLLM({
2610
- userPrompt: "Continue writing: write more text at the current cursor position related to the previous text",
2619
+ userPrompt: "Continue writing at the current cursor position related to the previous text. Add multiple blocks if needed. If the document looks like a template / draft, follow the template. Be extensive if needed.",
2611
2620
  // By default, LLM will be able to add / update / delete blocks. For "continue writing", we only want to allow adding new blocks.
2612
2621
  defaultStreamTools: {
2613
2622
  add: !0,
@@ -2667,7 +2676,7 @@ function Ao(e) {
2667
2676
  ];
2668
2677
  }
2669
2678
  function jo(e) {
2670
- const t = _(e), o = O(e);
2679
+ const t = I(e), o = O(e);
2671
2680
  return [
2672
2681
  {
2673
2682
  key: "improve_writing",
@@ -2692,7 +2701,7 @@ function jo(e) {
2692
2701
  key: "fix_spelling",
2693
2702
  title: t.ai_default_commands.fix_spelling.title,
2694
2703
  aliases: t.ai_default_commands.fix_spelling.aliases,
2695
- icon: /* @__PURE__ */ y(Eo, { size: 18 }),
2704
+ icon: /* @__PURE__ */ y(Io, { size: 18 }),
2696
2705
  onItemClick: async () => {
2697
2706
  await o.callLLM({
2698
2707
  useSelection: !0,
@@ -2738,8 +2747,8 @@ function jo(e) {
2738
2747
  }
2739
2748
  ];
2740
2749
  }
2741
- function Do(e) {
2742
- const t = _(e), o = O(e);
2750
+ function $o(e) {
2751
+ const t = I(e), o = O(e);
2743
2752
  return [
2744
2753
  {
2745
2754
  key: "accept",
@@ -2763,14 +2772,14 @@ function Do(e) {
2763
2772
  }
2764
2773
  ];
2765
2774
  }
2766
- function $o(e) {
2767
- const t = _(e), o = O(e);
2775
+ function Do(e) {
2776
+ const t = I(e), o = O(e);
2768
2777
  return [
2769
2778
  {
2770
2779
  key: "retry",
2771
2780
  title: t.ai_menu.actions.retry.title,
2772
2781
  aliases: t.ai_menu.actions.retry.aliases,
2773
- icon: /* @__PURE__ */ y(Io, { size: 18 }),
2782
+ icon: /* @__PURE__ */ y(Eo, { size: 18 }),
2774
2783
  onItemClick: async () => {
2775
2784
  await o.retry();
2776
2785
  },
@@ -2789,41 +2798,41 @@ function $o(e) {
2789
2798
  ];
2790
2799
  }
2791
2800
  function Ro(e, t) {
2792
- return t === "user-input" ? e.getSelection() ? jo(e) : Ao(e) : t === "user-reviewing" ? Do(e) : t === "error" ? $o(e) : [];
2801
+ return t === "user-input" ? e.getSelection() ? jo(e) : Ao(e) : t === "user-reviewing" ? $o(e) : t === "error" ? Do(e) : [];
2793
2802
  }
2794
2803
  const Ho = (e) => {
2795
- const t = K(), [o, r] = Ie(""), n = Qe(), i = G(), a = O(t), s = Ae(
2804
+ const t = K(), [o, r] = Ee(""), n = Qe(), s = G(), a = O(t), i = Ae(
2796
2805
  a.store,
2797
- (p) => p.aiMenuState !== "closed" ? p.aiMenuState.status : "closed"
2806
+ (m) => m.aiMenuState !== "closed" ? m.aiMenuState.status : "closed"
2798
2807
  ), { items: c } = e, u = E(() => {
2799
- let p = [];
2800
- return c ? p = c(t, s) : p = Ro(t, s), p.map((h) => ({
2808
+ let m = [];
2809
+ return c ? m = c(t, i) : m = Ro(t, i), m.map((h) => ({
2801
2810
  ...h,
2802
2811
  onItemClick: () => {
2803
2812
  h.onItemClick(r);
2804
2813
  }
2805
2814
  }));
2806
- }, [c, s, t]), m = D(
2807
- async (p) => {
2815
+ }, [c, i, t]), f = D(
2816
+ async (m) => {
2808
2817
  await a.callLLM({
2809
- userPrompt: p,
2818
+ userPrompt: m,
2810
2819
  useSelection: t.getSelection() !== void 0
2811
2820
  });
2812
2821
  },
2813
2822
  [a, t]
2814
2823
  );
2815
2824
  Ne(() => {
2816
- (s === "user-reviewing" || s === "error") && r("");
2817
- }, [s]);
2818
- const l = E(() => s === "thinking" ? n.ai_menu.status.thinking : s === "ai-writing" ? n.ai_menu.status.editing : s === "error" ? n.ai_menu.status.error : n.ai_menu.input_placeholder, [s, n]), f = E(() => {
2819
- if (s === "thinking" || s === "ai-writing")
2825
+ (i === "user-reviewing" || i === "error") && r("");
2826
+ }, [i]);
2827
+ const l = E(() => i === "thinking" ? n.ai_menu.status.thinking : i === "ai-writing" ? n.ai_menu.status.editing : i === "error" ? n.ai_menu.status.error : n.ai_menu.input_placeholder, [i, n]), p = E(() => {
2828
+ if (i === "thinking" || i === "ai-writing")
2820
2829
  return /* @__PURE__ */ y(
2821
- i.SuggestionMenu.Loader,
2830
+ s.SuggestionMenu.Loader,
2822
2831
  {
2823
2832
  className: "bn-suggestion-menu-loader bn-combobox-right-section"
2824
2833
  }
2825
2834
  );
2826
- if (s === "error")
2835
+ if (i === "error")
2827
2836
  return /* @__PURE__ */ y("div", { className: "bn-combobox-right-section bn-combobox-error", children: /* @__PURE__ */ y(
2828
2837
  "svg",
2829
2838
  {
@@ -2835,25 +2844,25 @@ const Ho = (e) => {
2835
2844
  children: /* @__PURE__ */ y("path", { d: "M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm0-160q17 0 28.5-11.5T520-480v-160q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640v160q0 17 11.5 28.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" })
2836
2845
  }
2837
2846
  ) });
2838
- }, [i, s]);
2847
+ }, [s, i]);
2839
2848
  return /* @__PURE__ */ y(
2840
2849
  No,
2841
2850
  {
2842
- onManualPromptSubmit: e.onManualPromptSubmit || m,
2851
+ onManualPromptSubmit: e.onManualPromptSubmit || f,
2843
2852
  items: u,
2844
2853
  promptText: o,
2845
2854
  onPromptTextChange: r,
2846
2855
  placeholder: l,
2847
- disabled: s === "thinking" || s === "ai-writing",
2856
+ disabled: i === "thinking" || i === "ai-writing",
2848
2857
  icon: /* @__PURE__ */ y("div", { className: "bn-combobox-icon", children: /* @__PURE__ */ y(ne, {}) }),
2849
- rightSection: f
2858
+ rightSection: p
2850
2859
  }
2851
2860
  );
2852
2861
  }, qo = (e) => {
2853
2862
  const t = e.blockID ? document.querySelector(`[data-id="${e.blockID}"]`) : void 0, o = E(() => t ? {
2854
2863
  getBoundingClientRect: () => t.getBoundingClientRect(),
2855
2864
  contextElement: t
2856
- } : null, [t]), { isMounted: r, ref: n, style: i, getFloatingProps: a, isPositioned: s } = Ot(!!t, o, 3e3, {
2865
+ } : null, [t]), { isMounted: r, ref: n, style: s, getFloatingProps: a, isPositioned: i } = Ot(!!t, o, 3e3, {
2857
2866
  canDismiss: {
2858
2867
  enabled: !0,
2859
2868
  escapeKey: !0,
@@ -2872,23 +2881,24 @@ const Ho = (e) => {
2872
2881
  })
2873
2882
  ],
2874
2883
  onOpenChange: e.onOpenChange,
2875
- whileElementsMounted: (c, u, m) => xt(c, u, m, {
2884
+ whileElementsMounted: (c, u, f) => xt(c, u, f, {
2876
2885
  animationFrame: !0
2877
- })
2886
+ }),
2887
+ ...e.floatingOptions
2878
2888
  });
2879
2889
  return r ? /* @__PURE__ */ y(
2880
2890
  "div",
2881
2891
  {
2882
2892
  ref: n,
2883
2893
  style: {
2884
- ...i
2894
+ ...s
2885
2895
  },
2886
2896
  ...a(),
2887
- children: s && e.children
2897
+ children: i && e.children
2888
2898
  }
2889
2899
  ) : null;
2890
2900
  }, lr = (e) => {
2891
- const t = K(), o = O(t), r = Ae(o.store, (a) => a.aiMenuState), n = r === "closed" ? void 0 : r.blockId, i = e.aiMenu || Ho;
2901
+ const t = K(), o = O(t), r = Ae(o.store, (a) => a.aiMenuState), n = r === "closed" ? void 0 : r.blockId, s = e.aiMenu || Ho;
2892
2902
  return /* @__PURE__ */ y(
2893
2903
  qo,
2894
2904
  {
@@ -2897,16 +2907,16 @@ const Ho = (e) => {
2897
2907
  onOpenChange: (a) => {
2898
2908
  a || r === "closed" || (r.status === "user-input" ? o.closeAIMenu() : (r.status === "user-reviewing" || r.status === "error") && o.rejectChanges());
2899
2909
  },
2900
- children: /* @__PURE__ */ y(i, {})
2910
+ children: /* @__PURE__ */ y(s, {})
2901
2911
  }
2902
2912
  );
2903
2913
  }, ur = () => {
2904
2914
  const e = Qe(), t = G(), o = K(), r = O(o), n = () => {
2905
2915
  o.formattingToolbar.closeMenu();
2906
- const i = o.getSelection();
2907
- if (!i)
2916
+ const s = o.getSelection();
2917
+ if (!s)
2908
2918
  throw new Error("No selection");
2909
- const a = i.blocks[i.blocks.length - 1].id;
2919
+ const a = s.blocks[s.blocks.length - 1].id;
2910
2920
  r.openAIMenuAtBlock(a);
2911
2921
  };
2912
2922
  return o.isEditable ? /* @__PURE__ */ y(
@@ -2932,7 +2942,7 @@ function dr(e) {
2932
2942
  r.block.content && Array.isArray(r.block.content) && // isarray check not ideal
2933
2943
  r.block.content.length === 0 && r.prevBlock ? t.openAIMenuAtBlock(r.prevBlock.id) : t.openAIMenuAtBlock(r.block.id);
2934
2944
  },
2935
- ..._(e).slash_menu.ai,
2945
+ ...I(e).slash_menu.ai,
2936
2946
  icon: /* @__PURE__ */ y(Uo.AI, {})
2937
2947
  }
2938
2948
  ];
@@ -2947,11 +2957,11 @@ export {
2947
2957
  Gt as callLLM,
2948
2958
  ar as createAIExtension,
2949
2959
  cr as createBlockNoteAIClient,
2950
- _ as getAIDictionary,
2960
+ I as getAIDictionary,
2951
2961
  O as getAIExtension,
2952
2962
  dr as getAISlashMenuItems,
2953
2963
  Ro as getDefaultAIMenuItems,
2954
- fo as llmFormats,
2964
+ po as llmFormats,
2955
2965
  ir as promptHelpers
2956
2966
  };
2957
2967
  //# sourceMappingURL=blocknote-xl-ai.js.map