@blocknote/xl-ai 0.44.1 → 0.45.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.
Files changed (62) hide show
  1. package/dist/blocknote-xl-ai.cjs +1 -1
  2. package/dist/blocknote-xl-ai.cjs.map +1 -1
  3. package/dist/blocknote-xl-ai.js +370 -369
  4. package/dist/blocknote-xl-ai.js.map +1 -1
  5. package/dist/{client-C4uaJa77.js → client-B0lU3j7B.js} +60 -29
  6. package/dist/client-B0lU3j7B.js.map +1 -0
  7. package/dist/client-CUJscXD0.cjs +36 -0
  8. package/dist/client-CUJscXD0.cjs.map +1 -0
  9. package/dist/server.cjs +1 -1
  10. package/dist/server.js +1 -1
  11. package/dist/webpack-stats.json +1 -1
  12. package/package.json +9 -9
  13. package/src/AIExtension.ts +6 -2
  14. package/src/api/aiRequest/builder.ts +1 -1
  15. package/src/api/formats/base-tools/createUpdateBlockTool.ts +5 -3
  16. package/src/api/formats/base-tools/delete.ts +5 -1
  17. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add paragraph and update selection_1_ed2eea810db5ab73a8478e981735f2a6.json +15 -0
  18. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add paragraph and update selection_1_9d907341d7a5b18529ccaf20cacbbe6f.json +15 -0
  19. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add paragraph and update selection_1_a7100ba9aeac25c6dbfc977b2325ae74.json +15 -0
  20. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add paragraph and update selection_1_b6c3311e72a434273d25e4a6dc74731a.json +15 -0
  21. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/fix spelling mid-word selection_1_ce6692c22eda2a757e123681118a333d.json +15 -0
  22. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/translate selection_1_1ad7d1a857e525e2d0f5a8c85b645a0e.json +15 -0
  23. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/fix spelling mid-word selection_1_8c47595610a6a2d15e1c5c751528e97a.json +15 -0
  24. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/translate selection_1_59b3c2f2328276dc62dad98af951d63c.json +15 -0
  25. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/fix spelling mid-word selection_1_a6c5e74c3098077445378d6645e2672e.json +15 -0
  26. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/translate selection_1_d51b8ed2dc61e8f8e333a3221be46316.json +15 -0
  27. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/fix spelling mid-word selection_1_d4b4abc5fa45932eec4efcc43bb337bd.json +15 -0
  28. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/translate selection_1_e4b712a415f8af6f2b49382cac85ae77.json +15 -0
  29. package/src/api/formats/html-blocks/htmlBlocks.ts +1 -1
  30. package/src/api/formats/html-blocks/tools/rebaseTool.ts +6 -2
  31. package/src/api/formats/json/json.ts +1 -1
  32. package/src/api/formats/json/tools/jsontools.test.ts +12 -2
  33. package/src/api/formats/markdown-blocks/markdownBlocks.ts +1 -1
  34. package/src/api/formats/tests/validateTestEnvironment.test.ts +1 -0
  35. package/src/prosemirror/__snapshots__/agent.test.ts.snap +7 -0
  36. package/src/prosemirror/__snapshots__/changeset.test.ts.snap +28 -0
  37. package/src/prosemirror/agent.test.ts +14 -2
  38. package/src/prosemirror/changeset.test.ts +8 -2
  39. package/src/prosemirror/rebaseTool.ts +1 -1
  40. package/src/streamTool/filterValidOperations.ts +1 -0
  41. package/src/streamTool/preprocess.test.ts +32 -66
  42. package/src/streamTool/preprocess.ts +8 -38
  43. package/src/streamTool/toValidatedOperations.ts +12 -0
  44. package/src/streamTool/vercelAiSdk/util/chatHandlers.ts +2 -0
  45. package/src/testUtil/cases/combinedOperationsTestCases.ts +1 -1
  46. package/src/testUtil/cases/editors/simpleEditor.ts +15 -0
  47. package/src/testUtil/cases/index.ts +6 -1
  48. package/src/testUtil/cases/updateOperationTestCases.ts +30 -1
  49. package/src/testUtil/suggestChangesTestUtil.ts +1 -1
  50. package/types/src/streamTool/preprocess.d.ts +0 -13
  51. package/types/src/testUtil/cases/editors/simpleEditor.d.ts +268 -0
  52. package/dist/client-C4uaJa77.js.map +0 -1
  53. package/dist/client-DrruPiJu.cjs +0 -36
  54. package/dist/client-DrruPiJu.cjs.map +0 -1
  55. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add paragraph and update selection_1_039451748eb07d71d3d7f96c97950d62.json +0 -15
  56. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add paragraph and update selection_1_a7597ddda3f5117e1572545c53c19414.json +0 -15
  57. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add paragraph and update selection_1_bb81e06e77589983badfe53e3839ab83.json +0 -15
  58. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add paragraph and update selection_1_8b11b2a66564f9985f33774d3862cd8c.json +0 -15
  59. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/translate selection_1_885e9088214dbb6d50dcda19d0056f3c.json +0 -15
  60. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/translate selection_1_1e9c30fa14f61508e6d90cbfa4d9b891.json +0 -15
  61. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/translate selection_1_f82bcc59263074bf367562f7380b9cef.json +0 -15
  62. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/translate selection_1_94c4e51be42ba73c81d7edc503e92b40.json +0 -15
@@ -1,8 +1,8 @@
1
1
  var ke = Object.defineProperty;
2
2
  var we = (t, e, o) => e in t ? ke(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
- var D = (t, e, o) => we(t, typeof e != "symbol" ? e + "" : e, o);
4
- import { jsonSchema as N, parsePartialJson as ue, asSchema as Z, tool as ge, generateObject as Te, convertToModelMessages as L, streamObject as ve, streamText as Pe, isToolUIPart as Oe } from "ai";
5
- import { getErrorMessage as U } from "@ai-sdk/provider-utils";
3
+ var L = (t, e, o) => we(t, typeof e != "symbol" ? e + "" : e, o);
4
+ import { jsonSchema as N, parsePartialJson as ue, asSchema as Z, tool as ge, generateObject as Te, convertToModelMessages as q, streamObject as ve, streamText as Pe, isToolUIPart as Oe } from "ai";
5
+ import { getErrorMessage as $ } from "@ai-sdk/provider-utils";
6
6
  import G from "lodash.merge";
7
7
  import Ee from "lodash.isequal";
8
8
  import { getPmSchema as xe, UnreachableCaseError as Be, getNodeById as Ce, updateBlockTr as Ie, insertBlocks as Ne, trackPosition as K, removeAndInsertBlocks as Me, getBlock as de, defaultProps as pe, isStyledTextInlineContent as _e, isLinkInlineContent as Ae } from "@blocknote/core";
@@ -10,7 +10,7 @@ import { Slice as je } from "prosemirror-model";
10
10
  import { TextSelection as $e } from "prosemirror-state";
11
11
  import { Transform as E, Mapping as fe, ReplaceStep as v, ReplaceAroundStep as De } from "prosemirror-transform";
12
12
  import { ChangeSet as Q, simplifyChanges as Le } from "prosemirror-changeset";
13
- import { applySuggestions as qe } from "@blocknote/prosemirror-suggest-changes";
13
+ import { applySuggestions as qe } from "@handlewithcare/prosemirror-suggest-changes";
14
14
  function J(t) {
15
15
  return (t.type === "paragraph" || !t.type) && !t.content || Array.isArray(t.content) && t.content.length === 0;
16
16
  }
@@ -46,7 +46,7 @@ async function Ut(t) {
46
46
  documentStateBuilder: t.documentStateBuilder ?? le.html.defaultDocumentStateBuilder,
47
47
  onStart: t.onStart ?? (() => {
48
48
  })
49
- }, i = e ? void 0 : t.editor.getTextCursorPosition().block, s = i && o && J(i) && P(t.editor.document).length > 0 ? i.id : void 0, c = e ? t.editor.getSelectionCutBlocks() : void 0, d = r.getStreamTools(
49
+ }, i = e ? void 0 : t.editor.getTextCursorPosition().block, s = i && o && J(i) && P(t.editor.document).length > 0 ? i.id : void 0, c = e ? t.editor.getSelectionCutBlocks(!0) : void 0, d = r.getStreamTools(
50
50
  t.editor,
51
51
  c ? {
52
52
  from: c._meta.startPos,
@@ -121,7 +121,7 @@ function ze(t) {
121
121
  class R extends Error {
122
122
  constructor(o, r, n) {
123
123
  super(o, n);
124
- D(this, "aborted");
124
+ L(this, "aborted");
125
125
  this.chunk = r, this.name = "ChunkExecutionError", this.aborted = (n == null ? void 0 : n.aborted) ?? !1;
126
126
  }
127
127
  }
@@ -131,7 +131,7 @@ class He {
131
131
  * @param abortSignal - Optional AbortSignal to cancel ongoing operations
132
132
  */
133
133
  constructor(e, o) {
134
- D(this, "stream");
134
+ L(this, "stream");
135
135
  this.streamTools = e, this.abortSignal = o, this.stream = this.createStream();
136
136
  }
137
137
  createStream() {
@@ -171,7 +171,7 @@ class He {
171
171
  } catch (c) {
172
172
  r.error(
173
173
  new R(
174
- `Tool execution failed: ${U(c)}`,
174
+ `Tool execution failed: ${$(c)}`,
175
175
  o,
176
176
  {
177
177
  cause: c,
@@ -267,7 +267,7 @@ async function Fe(t, e, o) {
267
267
  metadata: void 0
268
268
  };
269
269
  }
270
- function q(t) {
270
+ function U(t) {
271
271
  return t.flatMap((e) => {
272
272
  var o;
273
273
  if (e.role === "user" && ((o = e.metadata) != null && o.documentState)) {
@@ -360,7 +360,7 @@ function We(t, e) {
360
360
  case "error":
361
361
  n.enqueue({
362
362
  type: "error",
363
- errorText: U(r.error)
363
+ errorText: $(r.error)
364
364
  });
365
365
  break;
366
366
  default: {
@@ -461,7 +461,7 @@ class Jt {
461
461
  model: r,
462
462
  mode: "tool",
463
463
  system: this.opts.systemPrompt,
464
- messages: L(q(e)),
464
+ messages: q(U(e)),
465
465
  ...ee(r),
466
466
  ...n ?? {}
467
467
  });
@@ -482,7 +482,7 @@ class Jt {
482
482
  model: r,
483
483
  mode: "tool",
484
484
  system: this.opts.systemPrompt,
485
- messages: L(q(e)),
485
+ messages: q(U(e)),
486
486
  ...ee(r),
487
487
  ...n ?? {}
488
488
  });
@@ -501,7 +501,7 @@ class Jt {
501
501
  return Pe({
502
502
  model: r,
503
503
  system: this.opts.systemPrompt,
504
- messages: L(q(e)),
504
+ messages: q(U(e)),
505
505
  tools: o,
506
506
  toolChoice: "required",
507
507
  // extra options for streamObject
@@ -641,6 +641,18 @@ async function* tt(t, e) {
641
641
  }
642
642
  async function* ot(t, e) {
643
643
  for await (const o of t) {
644
+ if (!o.partialOperation.type) {
645
+ yield {
646
+ operation: {
647
+ ok: !1,
648
+ error: "The `type` property of an operation is required."
649
+ },
650
+ isUpdateToPreviousOperation: o.isUpdateToPreviousOperation,
651
+ isPossiblyPartial: o.isPossiblyPartial,
652
+ metadata: o.metadata
653
+ };
654
+ continue;
655
+ }
644
656
  const r = e.find(
645
657
  (a) => a.name === o.partialOperation.type
646
658
  );
@@ -673,7 +685,13 @@ async function* rt(t, e) {
673
685
  o,
674
686
  (n) => {
675
687
  if (!n.isPossiblyPartial)
676
- throw new R("invalid operation: " + n.operation.error, n);
688
+ throw new R(
689
+ `Invalid operation. ${$(n.operation.error)}`,
690
+ n,
691
+ {
692
+ cause: n.operation.error
693
+ }
694
+ );
677
695
  }
678
696
  );
679
697
  }
@@ -740,7 +758,7 @@ async function st(t, e, o, r) {
740
758
  toolCallId: m[y].toolCallId,
741
759
  state: "output-error",
742
760
  errorText: JSON.stringify(
743
- h ? { status: "error", error: U(p) } : { status: "not-executed-previous-tool-errored" }
761
+ h ? { status: "error", error: $(p) } : { status: "not-executed-previous-tool-errored" }
744
762
  )
745
763
  }) : e.addToolOutput({
746
764
  state: "output-available",
@@ -1107,7 +1125,7 @@ const te = (t, e) => {
1107
1125
  compareTokens: (i, s) => i === s
1108
1126
  };
1109
1127
  };
1110
- function $(t, e, o = !1, r, n) {
1128
+ function D(t, e, o = !1, r, n) {
1111
1129
  const a = Ce(t.id, e), i = new E(e);
1112
1130
  Ie(
1113
1131
  i,
@@ -1299,7 +1317,7 @@ function V(t) {
1299
1317
  const f = d.blocks[l], p = e.prosemirrorState.tr;
1300
1318
  let b = [];
1301
1319
  if (l < n.length) {
1302
- const m = await t.rebaseTool(n[l], e), y = $(
1320
+ const m = await t.rebaseTool(n[l], e), y = D(
1303
1321
  {
1304
1322
  id: n[l],
1305
1323
  block: f
@@ -1381,9 +1399,13 @@ function Y(t) {
1381
1399
  };
1382
1400
  const i = e.getBlock(a);
1383
1401
  if (!i)
1384
- return console.error("BLOCK NOT FOUND", a), {
1402
+ return {
1385
1403
  ok: !1,
1386
- error: "block not found"
1404
+ error: new Error("Block not found (update)", {
1405
+ cause: {
1406
+ blockId: a
1407
+ }
1408
+ })
1387
1409
  };
1388
1410
  const s = t.validateBlock(n.block, e, i.type);
1389
1411
  return s.ok ? {
@@ -1422,7 +1444,7 @@ function Y(t) {
1422
1444
  });
1423
1445
  if (!p)
1424
1446
  return !0;
1425
- const b = $(
1447
+ const b = D(
1426
1448
  p,
1427
1449
  u.doc,
1428
1450
  s.isPossiblyPartial,
@@ -1490,7 +1512,11 @@ const X = (t, e) => ({
1490
1512
  }
1491
1513
  } : {
1492
1514
  ok: !1,
1493
- error: "block not found"
1515
+ error: new Error("Block not found (delete)", {
1516
+ cause: {
1517
+ blockId: r
1518
+ }
1519
+ })
1494
1520
  };
1495
1521
  },
1496
1522
  // Note: functionality mostly tested in jsontools.test.ts
@@ -1581,14 +1607,19 @@ async function re(t, e) {
1581
1607
  if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = a), i.length !== 1)
1582
1608
  throw new Error("html diff invalid block count");
1583
1609
  const s = i[0];
1584
- if (s.id = t, $(
1610
+ if (s.id = t, D(
1585
1611
  {
1586
1612
  id: t,
1587
1613
  block: s
1588
1614
  },
1589
1615
  o.doc
1590
1616
  ).length)
1591
- throw new Error("html diff");
1617
+ throw new Error("html diff", {
1618
+ cause: {
1619
+ html: n,
1620
+ htmlBlock: s
1621
+ }
1622
+ });
1592
1623
  return j(e, o);
1593
1624
  }
1594
1625
  function ne(t) {
@@ -1653,7 +1684,7 @@ const B = {
1653
1684
  };
1654
1685
  function mt(t, e, o, r, n) {
1655
1686
  if (typeof r == "boolean") {
1656
- const s = r ? t.getSelectionCutBlocks() : void 0;
1687
+ const s = r ? t.getSelectionCutBlocks(!0) : void 0;
1657
1688
  r = s ? {
1658
1689
  from: s._meta.startPos,
1659
1690
  to: s._meta.endPos
@@ -1990,7 +2021,7 @@ const C = {
1990
2021
  };
1991
2022
  function vt(t, e, o, r, n) {
1992
2023
  if (typeof r == "boolean") {
1993
- const s = r ? t.getSelectionCutBlocks() : void 0;
2024
+ const s = r ? t.getSelectionCutBlocks(!0) : void 0;
1994
2025
  r = s ? {
1995
2026
  from: s._meta.startPos,
1996
2027
  to: s._meta.endPos
@@ -2048,7 +2079,7 @@ IF there is no selection active in the latest state, first, determine what part
2048
2079
  )
2049
2080
  };
2050
2081
  async function ie(t, e) {
2051
- const o = A(e), r = await e.blocksToMarkdownLossy([de(o.doc, t)]), n = await e.tryParseMarkdownToBlocks(r), a = $(
2082
+ const o = A(e), r = await e.blocksToMarkdownLossy([de(o.doc, t)]), n = await e.tryParseMarkdownToBlocks(r), a = D(
2052
2083
  {
2053
2084
  id: t,
2054
2085
  block: n[0]
@@ -2122,7 +2153,7 @@ const I = {
2122
2153
  };
2123
2154
  function Et(t, e, o, r, n) {
2124
2155
  if (typeof r == "boolean") {
2125
- const s = r ? t.getSelectionCutBlocks() : void 0;
2156
+ const s = r ? t.getSelectionCutBlocks(!0) : void 0;
2126
2157
  r = s ? {
2127
2158
  from: s._meta.startPos,
2128
2159
  to: s._meta.endPos
@@ -2215,7 +2246,7 @@ export {
2215
2246
  A as g,
2216
2247
  ee as h,
2217
2248
  st as i,
2218
- q as j,
2249
+ U as j,
2219
2250
  We as k,
2220
2251
  Xe as l,
2221
2252
  H as m,
@@ -2225,4 +2256,4 @@ export {
2225
2256
  Rt as s,
2226
2257
  Ye as t
2227
2258
  };
2228
- //# sourceMappingURL=client-C4uaJa77.js.map
2259
+ //# sourceMappingURL=client-B0lU3j7B.js.map